假设我有一个collada文件,其中有一个框,然后将dae文件导入场景。现在,在导入场景之后,我知道dae对象是一个盒子。将场景框添加到场景后,如何在场景包中获取其尺寸
如果将节点作为SCNBox导入,则会收到错误消息,提示SNCBox不是SCNNode的子类型。
floorNode = scene.rootNode.childNodeWithName("floor", recursively: false) as SCNBox
floorNode?.physicsBody = SCNPhysicsBody.staticBody()
floorNode?.physicsBody?.categoryBitMask = 2
let floorGeo: SCNBox = floorNode.geometry! as SCNBox
如果SCNNode是导入节点的唯一方法,如何获得尺寸?
最佳答案
关于如何使用boundingBox
的示例Swift代码:
var min = shipNode.boundingBox.min
var max = shipNode.boundingBox.max
let w = CGFloat(max.x - min.x)
let h = CGFloat(max.y - min.y)
let l = CGFloat(max.z - min.z)
let boxShape = SCNBox (width: w , height: h , length: l, chamferRadius: 0.0)
let shape = SCNPhysicsShape(geometry: boxShape, options: nil)
shipNode.physicsBody!.physicsShape = SCNPhysicsShape(geometry: boxShape, options: nil)
shipNode.physicsBody = SCNPhysicsBody.dynamic()
关于scenekit - 获取dae节点的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28337026/