@@ -177,10 +177,19 @@ extension Entity {
177
177
}
178
178
179
179
if element. attributeBoolean ( for: " generateCollisionShapes " ) {
180
- self . generateCollisionShapes (
181
- recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
182
- static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
183
- )
180
+ if element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " convex " ) ) {
181
+ // convex mesh collision shapes
182
+ self . generateConvexCollisionShapes (
183
+ recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
184
+ static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
185
+ )
186
+ } else {
187
+ // simple box collision shapes
188
+ self . generateCollisionShapes (
189
+ recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
190
+ static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
191
+ )
192
+ }
184
193
}
185
194
}
186
195
@@ -241,3 +250,19 @@ extension Entity {
241
250
}
242
251
}
243
252
}
253
+
254
+ extension Entity {
255
+ func generateConvexCollisionShapes(
256
+ recursive: Bool ,
257
+ static isStatic: Bool
258
+ ) {
259
+ if let mesh = self . components [ ModelComponent . self] ? . mesh {
260
+ self . components. set ( CollisionComponent ( shapes: [ . generateConvex( from: mesh) ] , isStatic: isStatic) )
261
+ }
262
+ if recursive {
263
+ for child in children {
264
+ child. generateConvexCollisionShapes ( recursive: recursive, static: isStatic)
265
+ }
266
+ }
267
+ }
268
+ }
0 commit comments