From 579423d3a009cb1ac65f9b81de5abcd58918fd01 Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Wed, 24 Jul 2024 15:02:13 -0400 Subject: [PATCH] rename `_ComponentContentBuilder` --- .../EntityContentBuilder.swift | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Sources/LiveViewNativeRealityKit/ContentBuilders/EntityContentBuilder.swift b/Sources/LiveViewNativeRealityKit/ContentBuilders/EntityContentBuilder.swift index bdeca33..6132096 100644 --- a/Sources/LiveViewNativeRealityKit/ContentBuilders/EntityContentBuilder.swift +++ b/Sources/LiveViewNativeRealityKit/ContentBuilders/EntityContentBuilder.swift @@ -181,10 +181,19 @@ extension Entity { } if element.attributeBoolean(for: "generateCollisionShapes") { - self.generateCollisionShapes( - recursive: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "recursive")), - static: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "static")) - ) + if element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "convex")) { + // convex mesh collision shapes + self.generateConvexCollisionShapes( + recursive: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "recursive")), + static: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "static")) + ) + } else { + // simple box collision shapes + self.generateCollisionShapes( + recursive: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "recursive")), + static: element.attributeBoolean(for: .init(namespace: "generateCollisionShapes", name: "static")) + ) + } } } @@ -245,3 +254,19 @@ extension Entity { } } } + +extension Entity { + func generateConvexCollisionShapes( + recursive: Bool, + static isStatic: Bool + ) { + if let mesh = self.components[ModelComponent.self]?.mesh { + self.components.set(CollisionComponent(shapes: [.generateConvex(from: mesh)], isStatic: isStatic)) + } + if recursive { + for child in children { + child.generateConvexCollisionShapes(recursive: recursive, static: isStatic) + } + } + } +}