为什么添加到场景视图场景中的3d对象随相机一起移动?

时间:2019-04-24 09:14:25

标签: ios swift4 augmented-reality arkit xcode10.2

我已将3d对象添加到dae格式的场景视图场景中。但是它随着相机而移动。如何将其固定到特定位置。相同的代码适用于其他3d对象,但问题仅在于该特定对象。下面是使用的代码:

 let scene = SCNScene(named: "Volvo_FE_Crane_2013.dae")!
 craneNode = SCNNode()
 let truckNode = scene.rootNode.childNode(withName: "Volvo_FE_Crane_2013", recursively: true)!
 craneNode.addChildNode(truckNode.clone())
 craneNode.position = SCNVector3Make(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)
 craneNode.light?.intensity = 1000
 craneNode.scale = SCNVector3Make(0.08, 0.08, 0.08)
 sceneView?.scene.rootNode.addChildNode(craneNode)

1 个答案:

答案 0 :(得分:0)

似乎您的模型仅在初始跟踪阶段才“滑动”。然后它静止不动。发生这种情况是因为尚未跟踪场景。如果不正确(我在说什么)–问题出在hitResult中。我不明白你是怎么得到的。

节点的顺序和层次结构很重要...

let scene = SCNScene(named: "Volvo_FE_Crane_2013.dae")!

craneNode = SCNNode()
let truckNode = scene.rootNode.childNode(withName: "Volvo_FE_Crane_2013", 
                                         recursively: true)!

truckNode.position = SCNVector3Make(hitResult.worldTransform.columns.3.x, 
                                    hitResult.worldTransform.columns.3.y, 
                                    hitResult.worldTransform.columns.3.z)

// truckNode.light?.intensity = 1000                  // IT"S NOT A LIGHT

truckNode.scale = SCNVector3Make(0.08, 0.08, 0.08)

craneNode.addChildNode(truckNode.clone())
sceneView?.scene.rootNode.addChildNode(craneNode)

另外,模型尺寸(多边形数量)可能是个问题

相关问题