'Why 3d object added to scene view scene moves along with camera?
I have added 3d object to scene view scene which is in dae format. But its moving along with camera. How to fix it to a particular position. Same code works with other 3d object but issue is only with this specific object. Below is the code used:
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)
Solution 1:[1]
It seems your model "slides" only at the initial tracking's stage. Then it's standing still. It happens because a scene hasn't been tracked yet. If it's not true (what I'm talking about) – the problem is in hitResult
. I did't see how you got it.
And node's order and hierarchy matters...
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)
Also, it might be an issue with model size (number of polygons).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |