-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
66 lines (47 loc) · 1.68 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import logging
from datetime import datetime
from decimal import Decimal, ROUND_HALF_UP
from panda3d.core import LineSegs
from panda3d.core import NodePath
def load_obj(file_path):
vertices = []
faces = []
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
li = [val for val in line.split(' ') if val]
match li[0]:
case 'v':
vertices.append(tuple(float(val) for val in li[1:]))
case 'f':
faces.append(tuple(int(val) - 1 for val in li[1:]))
return vertices, faces
def make_line(from_pt, to_pt, color):
lines = LineSegs()
lines.set_color(color)
lines.move_to(from_pt)
lines.draw_to(to_pt)
lines.set_thickness(2.0)
node = lines.create()
return NodePath(node)
def round(val, digit=2):
p = 10 ** digit
return (val * p * 2 + 1) // 2 / p
def round_float(f, digit='0.01'):
rounded = Decimal(str(f)).quantize(Decimal(digit), rounding=ROUND_HALF_UP)
return float(rounded)
def set_logger():
logger = logging.getLogger('log')
logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s [%(levelname)s] %(filename)s %(message)s')
import sys
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.DEBUG)
stream_handler.setFormatter(fmt)
logger.addHandler(stream_handler)
file_name = f'merge_ball_{datetime.now().strftime("%Y%m%d%H%M%S")}.log'
file_handler = logging.FileHandler(file_name)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(fmt)
logger.addHandler(file_handler)
# logger.info('setting log')