这就是我的模型的样子及其碰撞形状(粉色)。
我的问题是,当我尝试点击模型的最底部(圆圈)时,我无法做到这一点,因为模型的 CollisionShape 的最上部挡住了。
这就是我尝试为我的模型创建准确的碰撞形状的方法:
@objc private func placeObject() {
let entity = try! Entity.load(named: "Laryngeal")
let geom = entity.findEntity(named: "Geom")
for children in geom!.children {
let childModelEntity = children as! ModelEntity
childModelEntity.collision = CollisionComponent(shapes: [ShapeResource.generateConvex(from: childModelEntity.model!.mesh)])
}
let modelEntity = ModelEntity()
modelEntity.addChild(entity)
let anchorEntity = AnchorEntity(plane: .horizontal)
anchorEntity.addChild(modelEntity)
arView.installGestures([.all],for: modelEntity)
arView.scene.addAnchor(anchorEntity)
}
所以我的问题是,如何创建最准确的、完全适合我的模型的碰撞形状?
你可以尝试一件事。在 Reality-composer 中导入您的 .usdz 模型,根据需要应用物理和碰撞。并选择碰撞形状为自动。
之后将模型导出到 .reality 文件中(使用 cmd+E)并观察那里的碰撞形状(这可能很有用)