1111
1212def CreateEmptyMesh ():
1313 empty_mesh_data = bpy .data .meshes .new ('BESubMesh' )
14- empty_mesh_data .use_auto_smooth = True
14+
15+ # For Blender 4.0-
16+ if bpy .app .version [0 ] < 4 or (bpy .app .version [0 ] == 4 and bpy .app .version [1 ] == 0 ):
17+ empty_mesh_data .use_auto_smooth = True
1518
1619 return empty_mesh_data
1720
@@ -38,7 +41,9 @@ def CreateMesh(polys_len, np_verts, np_poly_indices, np_normals):
3841 np_smooth = np .full (polys_len , 1 , dtype = np .int8 )
3942 mesh .polygons .foreach_set ("use_smooth" , np_smooth )
4043
41- mesh .use_auto_smooth = True
44+ # For Blender 4.0-
45+ if bpy .app .version [0 ] < 4 or (bpy .app .version [0 ] == 4 and bpy .app .version [1 ] == 0 ):
46+ mesh .use_auto_smooth = True
4247
4348 # be_sub_mesh.validate()
4449 mesh .update ()
@@ -335,13 +340,19 @@ def MeshToJSONData(mesh, engine_type: EngineType):
335340
336341
337342def GetMeshNormalsNumpy (mesh ):
338- # Calc Split Nomrals
339- mesh .calc_normals_split ()
340343
341344 # GET NORMALS
342- np_normals = np .empty (len (mesh .loops ) * 3 , dtype = np .float32 )
343- mesh .loops .foreach_get ("normal" , np_normals )
344- # np_normals.shape = (len(mesh.loops), 3)
345+ if bpy .app .version [0 ] < 4 or (bpy .app .version [0 ] == 4 and bpy .app .version [1 ] == 0 ):
346+ # Calc Split Nomrals
347+ mesh .calc_normals_split ()
348+
349+ np_normals = np .empty (len (mesh .loops ) * 3 , dtype = np .float32 )
350+ mesh .loops .foreach_get ("normal" , np_normals )
351+
352+ # Blender 4.1+
353+ else :
354+ np_normals = np .empty (len (mesh .loops ) * 3 , dtype = np .float32 )
355+ mesh .corner_normals .foreach_get ("vector" , np_normals )
345356
346357 return np_normals
347358
0 commit comments