@@ -203,55 +203,55 @@ def TerrainMeshFromJSON(js_obj, engine_type: EngineType):
203203 return new_mesh
204204
205205
206- def MeshToJSONData (process_obj ):
206+ def MeshToJSONData (mesh ):
207207 mesh_dict = {} # Instances Dictionary
208208
209209 # Get Points
210- np_verts = np .zeros (len (process_obj . data .vertices ) * 3 , dtype = np .float32 )
211- process_obj . data .vertices .foreach_get ('co' , np_verts )
212- np_verts .shape = (len (process_obj . data .vertices ), 3 )
210+ np_verts = np .zeros (len (mesh .vertices ) * 3 , dtype = np .float32 )
211+ mesh .vertices .foreach_get ('co' , np_verts )
212+ np_verts .shape = (len (mesh .vertices ), 3 )
213213 mesh_dict ["Verts" ] = np_verts .tolist ()
214214
215215 # GET MESHES
216216 # MAIN Attributes
217217
218218 # Get Polygons
219- poly_indices = [tuple (poly .vertices ) for poly in process_obj . data .polygons ]
219+ poly_indices = [tuple (poly .vertices ) for poly in mesh .polygons ]
220220 mesh_dict ["PolyIndices" ] = poly_indices
221221
222222 # # Get Polygons Loops
223- # poly_loops = [tuple(poly.loop_indices) for poly in process_obj.data .polygons]
223+ # poly_loops = [tuple(poly.loop_indices) for poly in mesh .polygons]
224224 # mesh_dict["Loops"] = poly_loops
225225
226226 # Get Polygons Loop Start
227- np_loop_start = np .empty (len (process_obj . data .polygons ), dtype = np .int32 )
228- process_obj . data .polygons .foreach_get ("loop_start" , np_loop_start )
227+ np_loop_start = np .empty (len (mesh .polygons ), dtype = np .int32 )
228+ mesh .polygons .foreach_get ("loop_start" , np_loop_start )
229229 mesh_dict ["LoopStart" ] = np_loop_start .tolist ()
230230
231231 # # Get Triangles Only
232- # process_obj.data .calc_loop_triangles()
233- # np_tris = np.zeros(len(process_obj.data .loop_triangles) * 3, dtype=np.int32)
234- # process_obj.data .loop_triangles.foreach_get('vertices', np_tris)
235- # np_tris.shape = (len(process_obj.data .loop_triangles), 3)
232+ # mesh .calc_loop_triangles()
233+ # np_tris = np.zeros(len(mesh .loop_triangles) * 3, dtype=np.int32)
234+ # mesh .loop_triangles.foreach_get('vertices', np_tris)
235+ # np_tris.shape = (len(mesh .loop_triangles), 3)
236236 # mesh_dict["PolyIndices"] = np_tris.tolist()
237237
238238 # # Get Loops of Triangles
239- # np_tris_loops = np.zeros(len(process_obj.data .loop_triangles) * 3, dtype=np.int32)
240- # process_obj.data .loop_triangles.foreach_get('loops', np_tris_loops)
241- # np_tris_loops.shape = (len(process_obj.data .loop_triangles), 3)
239+ # np_tris_loops = np.zeros(len(mesh .loop_triangles) * 3, dtype=np.int32)
240+ # mesh .loop_triangles.foreach_get('loops', np_tris_loops)
241+ # np_tris_loops.shape = (len(mesh .loop_triangles), 3)
242242 # mesh_dict["Loops"] = np_tris_loops.tolist()
243243
244244 # Get Normals
245- if BESettings .BENGINE_NORMAL in process_obj . data .attributes .keys ():
246- if process_obj . data .attributes [BESettings .BENGINE_NORMAL ].domain == 'CORNER' :
247- np_normals = np .zeros (len (process_obj . data .attributes [BESettings .BENGINE_NORMAL ].data ) * 3 , dtype = np .float32 )
248- process_obj . data .attributes [BESettings .BENGINE_NORMAL ].data .foreach_get ('vector' , np_normals )
249- np_normals .shape = (len (process_obj . data .attributes [BESettings .BENGINE_NORMAL ].data ), 3 )
245+ if BESettings .BENGINE_NORMAL in mesh .attributes .keys ():
246+ if mesh .attributes [BESettings .BENGINE_NORMAL ].domain == 'CORNER' :
247+ np_normals = np .zeros (len (mesh .attributes [BESettings .BENGINE_NORMAL ].data ) * 3 , dtype = np .float32 )
248+ mesh .attributes [BESettings .BENGINE_NORMAL ].data .foreach_get ('vector' , np_normals )
249+ np_normals .shape = (len (mesh .attributes [BESettings .BENGINE_NORMAL ].data ), 3 )
250250 else :
251- print ("Attribute " + BESettings .BENGINE_NORMAL + " must have FACECORNER domain!!!" )
252- np_normals = GetMeshNormalsNumpy (process_obj )
251+ print ("Attribute " + BESettings .BENGINE_NORMAL + " must have FACECORNER domain. Taken Default Normals Instead !!!" )
252+ np_normals = GetMeshNormalsNumpy (mesh )
253253 else :
254- np_normals = GetMeshNormalsNumpy (process_obj )
254+ np_normals = GetMeshNormalsNumpy (mesh )
255255
256256 mesh_dict ["Normals" ] = np_normals .tolist ()
257257
@@ -260,25 +260,25 @@ def MeshToJSONData(process_obj):
260260 np_col_attrib = None
261261
262262 # Get Attributes
263- for attrib_name in process_obj . data .attributes .keys ():
263+ for attrib_name in mesh .attributes .keys ():
264264 if attrib_name in BESettings .UV_NAMES :
265265
266- if process_obj . data .attributes [attrib_name ].domain == 'CORNER' :
267- if (len (process_obj . data .attributes [attrib_name ].data ) > 0 ):
266+ if mesh .attributes [attrib_name ].domain == 'CORNER' :
267+ if (len (mesh .attributes [attrib_name ].data ) > 0 ):
268268
269- # if process_obj.data .attributes[attrib_name].data_type == 'FLOAT':
269+ # if mesh .attributes[attrib_name].data_type == 'FLOAT':
270270 # uv_vec_len = 2
271271 # else:
272- uv_vec_len = len (process_obj . data .attributes [attrib_name ].data [0 ].vector )
272+ uv_vec_len = len (mesh .attributes [attrib_name ].data [0 ].vector )
273273
274- np_uv_attrib = np .zeros (len (process_obj . data .attributes [attrib_name ].data ) * uv_vec_len , dtype = np .float32 )
274+ np_uv_attrib = np .zeros (len (mesh .attributes [attrib_name ].data ) * uv_vec_len , dtype = np .float32 )
275275
276- # if process_obj.data .attributes[attrib_name].data_type == 'FLOAT':
277- # process_obj.data .attributes[attrib_name].data.foreach_get('value', np_uv_attrib)
276+ # if mesh .attributes[attrib_name].data_type == 'FLOAT':
277+ # mesh .attributes[attrib_name].data.foreach_get('value', np_uv_attrib)
278278 # else:
279- process_obj . data .attributes [attrib_name ].data .foreach_get ('vector' , np_uv_attrib )
279+ mesh .attributes [attrib_name ].data .foreach_get ('vector' , np_uv_attrib )
280280
281- np_uv_attrib .shape = (len (process_obj . data .attributes [attrib_name ].data ), uv_vec_len )
281+ np_uv_attrib .shape = (len (mesh .attributes [attrib_name ].data ), uv_vec_len )
282282
283283 uvs_dict [attrib_name ] = np_uv_attrib .tolist ()
284284
@@ -287,22 +287,22 @@ def MeshToJSONData(process_obj):
287287
288288 elif attrib_name == BESettings .BENGINE_COLOR :
289289
290- if process_obj . data .attributes [attrib_name ].domain == 'CORNER' :
290+ if mesh .attributes [attrib_name ].domain == 'CORNER' :
291291 # col_attrib = [tuple(uv_attr.color) for uv_attr in process_obj_ev.data.attributes[attrib_name].data]
292292 # mesh_dict["VertexColor"] = col_attrib
293293
294- np_col_attrib = np .zeros (len (process_obj . data .attributes [attrib_name ].data ) * 4 , dtype = np .float32 )
295- process_obj . data .attributes [attrib_name ].data .foreach_get ('color' , np_col_attrib )
296- np_col_attrib .shape = (len (process_obj . data .attributes [attrib_name ].data ), 4 )
294+ np_col_attrib = np .zeros (len (mesh .attributes [attrib_name ].data ) * 4 , dtype = np .float32 )
295+ mesh .attributes [attrib_name ].data .foreach_get ('color' , np_col_attrib )
296+ np_col_attrib .shape = (len (mesh .attributes [attrib_name ].data ), 4 )
297297 mesh_dict ["VertexColors" ] = np_col_attrib .tolist ()
298298 else :
299299 print ("Attribute " + attrib_name + " must have FACECORNER domain!!!" )
300300
301301 # Setup bengine_material Value
302302 elif attrib_name == BESettings .BENGINE_MATERIAL :
303- if process_obj . data .attributes [attrib_name ].domain == 'FACE' :
304- np_mat_attrib = np .zeros (len (process_obj . data .attributes [attrib_name ].data ), dtype = np .uint8 )
305- process_obj . data .attributes [attrib_name ].data .foreach_get ('value' , np_mat_attrib )
303+ if mesh .attributes [attrib_name ].domain == 'FACE' :
304+ np_mat_attrib = np .zeros (len (mesh .attributes [attrib_name ].data ), dtype = np .uint8 )
305+ mesh .attributes [attrib_name ].data .foreach_get ('value' , np_mat_attrib )
306306 mesh_dict ["Materials" ] = np_mat_attrib .tolist ()
307307 else :
308308 print ("Attribute " + attrib_name + " must have FACE domain!!!" )
@@ -313,14 +313,14 @@ def MeshToJSONData(process_obj):
313313 return mesh_dict
314314
315315
316- def GetMeshNormalsNumpy (process_obj ):
316+ def GetMeshNormalsNumpy (mesh ):
317317 # Calc Split Nomrals
318- process_obj . data .calc_normals_split ()
318+ mesh .calc_normals_split ()
319319
320320 # GET NORMALS
321- np_normals = np .zeros (len (process_obj . data .loops ) * 3 , dtype = np .float32 )
322- process_obj . data .loops .foreach_get ("normal" , np_normals )
323- np_normals .shape = (len (process_obj . data .loops ), 3 )
321+ np_normals = np .zeros (len (mesh .loops ) * 3 , dtype = np .float32 )
322+ mesh .loops .foreach_get ("normal" , np_normals )
323+ np_normals .shape = (len (mesh .loops ), 3 )
324324
325325 return np_normals
326326
0 commit comments