2017-04-01 29 views
1

问题1:复杂 “.DAE” SceneKit自定义形状对象

代码,以使碰撞基本对象 - 管工作不正常:

let tubeGeometry = SCNTube(innerRadius: 2, outerRadius: 2.5, height: 2) 
    let tubeMaterial = SCNMaterial() 
    tubeMaterial.diffuse.contents = UIColor.green 
    tubeGeometry.materials = [tubeMaterial] 

    let tubeNode = SCNNode(geometry: tubeGeometry) 
    tubeNode.position = SCNVector3(0, 0, 0) 

    let tubeShape = SCNPhysicsShape(geometry: tubeGeometry, options: nil) 
    let tubeBody = SCNPhysicsBody(type: .dynamic, shape: tubeShape) 

    tubeNode.physicsBody?.categoryBitMask = collisionTube 
    tubeNode.physicsBody?.collisionBitMask = collsionTarget 
    tubeNode.physicsBody?.mass = 1 
    tubeNode.physicsBody = tubeBody 

    scene.rootNode.addChildNode(tubeNode) 

截图:

TUBE COLLISION

为什么球在物体的顶部?

问题2:

我仔细阅读本手册使用类SCNPhysicsShapeSCNPhysicsBody

强加研究之约束的DAE对象的所有可能的方式。 并得出结论:所有限制都必须在对象的单一物理模型中编程复杂的SCNNodes束。

发现很有意思的答案:

LINK

我真的希望有一种方法来做出类似让DAEShape = SCNPhysicsShape(几何: “* .DAE”) ...,否则设置碰撞复杂的对象可能需要一个月或更长时间的开发。

例如,如何设计复杂管道“DAE”对象的碰撞,如截图中的任何建议? DAE OBJECT - COMPLEX TUBE

的问题不是性能而是要实现复杂的约束,复杂的3D对象的最直接的方式,避免了编程的琐事的能力...

如何使用顶点来设置物理限制,边缘和“DAE”对象的面孔?

我真的希望答案是...... 在此先感谢!

回答

0
let url = Bundle.main.url(forResource: "art.scnassets/half", withExtension: "dae") 
    let sceneSource = SCNSceneSource(url: url!, options: nil) 
    let tubeGeometry = (sceneSource?.entryWithIdentifier("Cube-mesh", withClass: SCNGeometry.self))! as SCNGeometry 

    tubeNode = SCNNode(geometry: tubeGeometry) 
    tubeNode.position = SCNVector3(0, 1, 0) 
    tubeNode.eulerAngles = SCNVector3Make(1.5, 2, 0) 
    tubeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: tubeGeometry, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron])) 
    scene.rootNode.addChildNode(tubeNode)