Reputation: 699
I'm trying to apply collision between real-world objects like wall, sofa and ... with a .usdz file imported in the project. I have tried using PhysicsBodyComponent
and CollisionComponent
but without any results. Here is the code for importing the 3D object:
let entityName = objects.objectName
guard let entity = try? Entity.load(named: entityName, in: .main) else {
return
}
// Creating parent ModelEntity
let parentEntity = ModelEntity()
parentEntity.addChild(entity)
// Anchoring the entity and adding it to the scene
// Add entity on horizontal planes if classified as `floor`.
// Minimum bounds is 10x10cm
let anchor = AnchorEntity(.plane(.horizontal, classification: .floor, minimumBounds: [0.1, 0.1]))
anchor.name = entityName
anchor.addChild(parentEntity)
self.arView.scene.addAnchor(anchor)
// Playing availableAnimations on repeat
entity.availableAnimations.forEach { entity.playAnimation($0.repeat()) }
// Add a collision component to the parentEntity with a rough shape and appropriate offset for the model that it contains
parentEntity.generateCollisionShapes(recursive: true)
// Installing gestures for the parentEntity
self.arView.installGestures([.translation, .rotation], for: parentEntity)
Upvotes: 0
Views: 639
Reputation: 591
Virtual objects do not interact with physical objects(wall, sofa, plains etc..) on a collision base.
I can offer you 2 possible solutions:
Upvotes: 0