@@ -6,14 +6,14 @@ class CTM:
66 """
77 Object that encapsulates a CTM file
88 """
9-
109 def __init__ (self , _vertices , _faces , _normals = None ):
1110 self .vertices = _vertices
1211 self .faces = _faces
1312 self .normals = _normals
1413
1514 def __eq__ (self , other ):
16- return (self .vertices == other .vertices ).all () and (self .faces == other .faces ).all ()
15+ return (self .vertices == other .vertices ).all () and (
16+ self .faces == other .faces ).all ()
1717
1818
1919def import_mesh (_filename ):
@@ -35,8 +35,7 @@ def import_mesh(_filename):
3535 # read faces
3636 face_count = ctmGetInteger (ctm_context , CTM_TRIANGLE_COUNT )
3737 face_ctm = ctmGetIntegerArray (ctm_context , CTM_INDICES )
38- faces = np .fromiter (face_ctm ,
39- dtype = np .int ,
38+ faces = np .fromiter (face_ctm , dtype = np .int ,
4039 count = face_count * 3 ).reshape ((- 1 , 3 ))
4140
4241 # read face normals
@@ -54,37 +53,42 @@ def import_mesh(_filename):
5453
5554def export_mesh (_ctm , _filename ):
5655 ctm_context = ctmNewContext (CTM_EXPORT )
57-
56+
5857 if not str (_filename ).lower ().endswith ('.ctm' ):
5958 _filename += '.ctm'
6059
6160 try :
6261 vertex_count = len (_ctm .vertices )
6362 vertices = _ctm .vertices .reshape ((- 1 , 1 ))
64- p_vertices = ctypes .cast ((CTMfloat * vertex_count * 3 )(), ctypes .POINTER (CTMfloat ))
63+ p_vertices = ctypes .cast ((CTMfloat * vertex_count * 3 )(),
64+ ctypes .POINTER (CTMfloat ))
6565 for i in range (vertex_count * 3 ):
66- p_vertices [i ] = CTMfloat (vertices [i ])
66+ p_vertices [i ] = CTMfloat (vertices [i ]. item () )
6767
6868 face_count = len (_ctm .faces )
6969 faces = _ctm .faces .reshape ((- 1 , 1 ))
70- p_faces = ctypes .cast ((CTMuint * face_count * 3 )(), ctypes .POINTER (CTMuint ))
70+ p_faces = ctypes .cast ((CTMuint * face_count * 3 )(),
71+ ctypes .POINTER (CTMuint ))
7172 for i in range (face_count * 3 ):
72- p_faces [i ] = CTMuint (faces [i ])
73+ p_faces [i ] = CTMuint (faces [i ]. item () )
7374
7475 if _ctm .normals is not None :
7576 normal_count = len (_ctm .normals )
7677 normals = _ctm .normals .reshape ((- 1 , 1 ))
77- p_normals = ctypes .cast ((CTMfloat * normal_count * 3 )(), ctypes .POINTER (CTMfloat ))
78+ p_normals = ctypes .cast ((CTMfloat * normal_count * 3 )(),
79+ ctypes .POINTER (CTMfloat ))
7880 for i in range (normal_count * 3 ):
79- p_normals [i ] = CTMfloat (normals [i ])
81+ p_normals [i ] = CTMfloat (normals [i ]. item () )
8082 else :
8183 p_normals = None
8284
83- ctmDefineMesh (ctm_context , p_vertices , CTMuint (vertex_count ), p_faces , CTMuint (face_count ), p_normals )
85+ ctmDefineMesh (ctm_context , p_vertices , CTMuint (vertex_count ), p_faces ,
86+ CTMuint (face_count ), p_normals )
8487 ctmSave (ctm_context , ctypes .c_char_p (_encode (_filename )))
8588 finally :
8689 ctmFreeContext (ctm_context )
8790
91+
8892def _encode (_filename ):
8993 try :
9094 return str (_filename ).encode ("utf-8" )
@@ -98,4 +102,3 @@ def _encode(_filename):
98102 pass
99103
100104 return str (_filename ).encode ("utf-8" , "surrogateescape" )
101-
0 commit comments