1

我已将 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)
4

1 回答 1

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)

此外,这可能是模型大小(多边形数量)的问题

于 2019-04-24T10:34:05.820 回答