0
votes

on my study project using ARKit and sceneKit I'm facing a strange behaviour when using .dae file.

i have created 2 object a cube and a plane with the following methods (both have physics):

  func loadBox() {
        let ballGeometry = SCNBox(width: 0.2, height: 0.2, length: 0.2, chamferRadius: 0.02)
        let mat = SCNMaterial()
        mat.diffuse.contents = UIImage(named: "ball")
        ballGeometry.materials = [mat]
        //Physic
        let physSchape  = SCNPhysicsShape(geometry: ballGeometry, options: nil)
        let ballPhysic = SCNPhysicsBody(type: .dynamic, shape: physSchape)
        ballPhysic.mass = 100
        ballPhysic.friction = 0.8
        ballPhysic.isAffectedByGravity = true
        let nodeBall = SCNNode(geometry: ballGeometry)
        nodeBall.name = "ball"
        nodeBall.physicsBody = ballPhysic
        
        box = nodeBall
    }


func loadPlane(){
        let geometry = SCNPlane(width: 1, height: 1)
        let material = SCNMaterial()
        material.diffuse.contents = UIImage(named: "texture")
        geometry.materials = [material]
        // physics
        let physSchape  = SCNPhysicsShape(geometry: geometry, options: nil)
        let planePhysic = SCNPhysicsBody(type: .static, shape: physSchape)
        planePhysic.restitution = 0.0
        planePhysic.friction = 1.0
        planePhysic.isAffectedByGravity = true
        let nodo = SCNNode(geometry: geometry)
        nodo.eulerAngles.x = -.pi / 2
        nodo.physicsBody = planePhysic
        plane = nodo
    }

when I place the box over the plane in the scene they are correctly positioned and touching each other as you can see from the following picture:

correct position

Here the problem:

if i use a model downloaded from internet as .dae file of the plane, when insert it in the scene it create a strange space between the box and the plane (see picture)

wrong position

method I use to load the scn file.

  // load the elicopterBase
    func loadElicopterBase(){

        guard let scene = SCNScene(named: "Model.scnassets/base.scn") else {fatalError()}
       
        guard let nodo = scene.rootNode.childNode(withName: "Plane", recursively: true) else {fatalError()}
        // physics
        let physSchape  = SCNPhysicsShape(node: nodo, options: nil)
        let planePhysic = SCNPhysicsBody(type: .static, shape: physSchape)
        planePhysic.restitution = 0.0
        planePhysic.friction = 1.0
        planePhysic.isAffectedByGravity = true
        nodo.physicsBody = planePhysic
        nodo.name = "base"
            DispatchQueue.main.async {
                self.eliporto = nodo
            }
    }

Look like the .dae file have some sort of invisible boundingBox around it. What or where I can look to find a solution to this.

here some picture of the .dae file in Xcode

dae setting 1 dae setting 2

1

1 Answers

1
votes

Make your floor plane of type "concavePolyhedron" like so:

let body = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: yourGeometry, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron]))