zhou junhua
zhou junhua

Reputation: 504

how to create accurate collision for 3d meshes? (ios arkit or realitykit)

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

the red line is model's collision

i'm use arkit and realitykit not scenekit

Upvotes: 2

Views: 1797

Answers (2)

user13686217
user13686217

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

SilentK
SilentK

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

Related Questions