@@ -46,6 +46,10 @@ def __init__(self, mapData, lightmapData, propLibrarySourcePath, map_scale_facto
4646 self .import_spawn_points = import_spawn_points
4747 self .import_lightmapdata = import_lightmapdata
4848
49+ # Cache for collision meshes, don't cache triangles because they are set using unique vertices
50+ self .collisionPlaneMesh = None
51+ self .collisionBoxMesh = None
52+
4953 self .materials = {}
5054
5155 def importData (self ):
@@ -68,6 +72,19 @@ def importData(self):
6872 # Collision geometry
6973 collisionObjects = []
7074 if self .import_collision_geom :
75+ # Create collision meshes
76+ self .collisionPlaneMesh = bpy .data .meshes .new ("collisionPlane" )
77+ bm = bmesh .new ()
78+ bmesh .ops .create_grid (bm , x_segments = 1 , y_segments = 1 , size = 1.0 )
79+ bm .to_mesh (self .collisionPlaneMesh )
80+ bm .free ()
81+
82+ self .collisionBoxMesh = bpy .data .meshes .new ("collisionBox" )
83+ bm = bmesh .new ()
84+ bmesh .ops .create_cube (bm )
85+ bm .to_mesh (self .collisionBoxMesh )
86+ bm .free ()
87+
7188 # Load collision meshes
7289 collisionTriangles = self .mapData .collisionGeometry .triangles + self .mapData .collisionGeometryOutsideGamingZone .triangles
7390 collisionTriangleObjects = self .createBlenderCollisionTriangles (collisionTriangles )
@@ -242,16 +259,8 @@ def createBlenderCollisionTriangles(self, collisionTriangles):
242259 def createBlenderCollisionPlanes (self , collisionPlanes ):
243260 objects = []
244261 for collisionPlane in collisionPlanes :
245- # Create the mesh
246- me = bpy .data .meshes .new ("collisionPlane" )
247-
248- bm = bmesh .new ()
249- bmesh .ops .create_grid (bm , x_segments = 1 , y_segments = 1 , size = 1.0 )
250- bm .to_mesh (me )
251- bm .free ()
252-
253262 # Create object
254- ob = bpy .data .objects .new ("collisionPlane" , me )
263+ ob = bpy .data .objects .new ("collisionPlane" , self . collisionPlaneMesh )
255264 ob .location = collisionPlane .position
256265 ob .rotation_mode = "XYZ"
257266 ob .rotation_euler = collisionPlane .rotation
@@ -264,16 +273,8 @@ def createBlenderCollisionPlanes(self, collisionPlanes):
264273 def createBlenderCollisionBoxes (self , collisionBoxes ):
265274 objects = []
266275 for collisionBox in collisionBoxes :
267- # Create the mesh
268- me = bpy .data .meshes .new ("collisionBox" )
269-
270- bm = bmesh .new ()
271- bmesh .ops .create_cube (bm )
272- bm .to_mesh (me )
273- bm .free ()
274-
275276 # Create object
276- ob = bpy .data .objects .new ("collisionBox" , me )
277+ ob = bpy .data .objects .new ("collisionBox" , self . collisionBoxMesh )
277278 ob .location = collisionBox .position
278279 ob .rotation_mode = "XYZ"
279280 ob .rotation_euler = collisionBox .rotation
0 commit comments