-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobjLoader_trimesh_animal.py
48 lines (42 loc) · 1.7 KB
/
objLoader_trimesh_animal.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
import trimesh
from trimesh.scene.scene import Scene
import logging
logger = logging.getLogger("pywavefront")
logger.setLevel(logging.ERROR)
import numpy as np
import meshio
class trimesh_load_obj_animal(object):
def __init__(self, fileName):
#self.bbox = np.zeros(shape=(2,3))
##
self.vertices = []
self.faces = []
self.bbox = []
objFile = open(fileName, 'r')
for line in objFile:
split = line.split()
#print(split)
#if blank line, skip
if split:
if split[0] == 'f':
a = int(split[1].split('/')[0])-1
b = int(split[2].split('/')[0])-1
c = int(split[3].split('/')[0])-1
# #f 492/1066-1/492 152/259/152 881/2223/881
self.faces.append([a,b,c])
# else:
# print('haha')
# print(split)
# print(split.split(' ')[1])
#
# print(fileName)
#obj_info = trimesh.load(fileName, file_type='obj', process=False,use_embree=False)
meshio_mesh = meshio.read(fileName,file_format="obj")
# print(obj_info)
#self.vertices = obj_info.vertices
self.vertices = meshio_mesh.points #- obj_info.center_mass
self.vertices = np.array(self.vertices).astype("float32")
self.vertices = self.vertices[:,[0,1,2]]
self.faces = np.array(self.faces).astype("int32")
#print(self.faces.shape)
self.bbox = np.array([[np.max(self.vertices[:,0]), np.max(self.vertices[:,1]), np.max(self.vertices[:,2])], [np.min(self.vertices[:,0]), np.min(self.vertices[:,1]), np.min(self.vertices[:,2])]])