Reputation: 504
i want to use arview.scene.raycast(origin: SIMD3<Float>, direction: SIMD3<Float>
to hit 3d model,
use generateCollisionShapes(recursive: true)
to generate box collision
the problem is : i want to hit model'surface,so is there a way to create accurate collision
i'm use arkit and realitykit not scenekit
Upvotes: 2
Views: 1797
Reputation: 21
if let model = arView.scene.findEntity(named: name) as? ModelEntity {
if let m = model.model {
model.components[CollisionComponent] = CollisionComponent(shapes: [ShapeResource.generateConvex(from: m.mesh)])
}
}
Upvotes: 2
Reputation: 652
Using generateCollisionShapes(recursive: Bool)
generate a very simple box as the CollisionComponent.
In order to create an accurate collision body that represents the chair, you need to use the mesh of the model as its CollisionComponent:
yourModelEntity.collision = CollisionComponent(shapes: [ShapeResource.generateConvex(from: yourModelEntity.model!.mesh)]
An even more efficient approach would be to create a lower poly version of the model and use that as its CollisionComponent.
Upvotes: 8