【发布时间】:2021-05-18 22:47:49
【问题描述】:
在我使用 ARKit 和 sceneKit 的研究项目中,我在使用 .dae 文件时遇到了一个奇怪的行为。
我使用以下方法创建了 2 个对象一个立方体和一个平面(两者都有物理):
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
}
当我将盒子放在场景中的平面上时,它们被正确定位并相互接触,如下图所示:
问题出在这里:
如果我使用从互联网下载的模型作为飞机的 .dae 文件,当将其插入场景时,它会在盒子和飞机之间创建一个奇怪的空间(见图)
我用来加载 scn 文件的方法。
// 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
}
}
看起来 .dae 文件周围有某种不可见的边界框。 我可以通过什么或在哪里找到解决方案。
这里是 Xcode 中 .dae 文件的一些图片
【问题讨论】:
标签: swift xcode scenekit arkit blender