@@ -181,10 +181,19 @@ extension Entity {
181
181
}
182
182
183
183
if element. attributeBoolean ( for: " generateCollisionShapes " ) {
184
- self . generateCollisionShapes (
185
- recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
186
- static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
187
- )
184
+ if element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " convex " ) ) {
185
+ // convex mesh collision shapes
186
+ self . generateConvexCollisionShapes (
187
+ recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
188
+ static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
189
+ )
190
+ } else {
191
+ // simple box collision shapes
192
+ self . generateCollisionShapes (
193
+ recursive: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " recursive " ) ) ,
194
+ static: element. attributeBoolean ( for: . init( namespace: " generateCollisionShapes " , name: " static " ) )
195
+ )
196
+ }
188
197
}
189
198
}
190
199
@@ -245,3 +254,19 @@ extension Entity {
245
254
}
246
255
}
247
256
}
257
+
258
+ extension Entity {
259
+ func generateConvexCollisionShapes(
260
+ recursive: Bool ,
261
+ static isStatic: Bool
262
+ ) {
263
+ if let mesh = self . components [ ModelComponent . self] ? . mesh {
264
+ self . components. set ( CollisionComponent ( shapes: [ . generateConvex( from: mesh) ] , isStatic: isStatic) )
265
+ }
266
+ if recursive {
267
+ for child in children {
268
+ child. generateConvexCollisionShapes ( recursive: recursive, static: isStatic)
269
+ }
270
+ }
271
+ }
272
+ }
0 commit comments