7.2 C
New York
Wednesday, October 16, 2024

ios – Why does the strategy worldposition in SCNKit not contemplate the pivot of the guardian’s node?


I want to get the place of a SCNNode (inexperienced coloration) in world coordinates. The SCNNode’s guardian has a pivot utilized to it.

Once I use the strategy worldPosition and place a brand new blue object with the identical world place into the scene then the blue and the inexperienced object’s positions don’t visually match.

Does worldposition not work if a guardian has a pivot utilized to it?

let planeGeometry = SCNPlane(width: 1.0, top: 1.0)
planeGeometry.firstMaterial?.diffuse.contents = UIColor.grey.withAlphaComponent(0.5)

let planeNode = SCNNode(geometry: planeGeometry)
planeNode.place = SCNVector3(0, -0.2, -2)
planeNode.eulerAngles.x = -.pi / 2
planeNode.pivot = SCNMatrix4MakeTranslation(0, 0.2, 0)

sceneView.scene.rootNode.addChildNode(planeNode)

let ballNode = createBallNode(radius: 0.1, coloration: .inexperienced)
planeNode.addChildNode(ballNode)

let debugCube = SCNBox(width: 0.04, top: 0.02, size: 0.7, chamferRadius: 0)
debugCube.firstMaterial?.diffuse.contents = UIColor.blue
let debugNode = SCNNode(geometry: debugCube)

let ballWorldPosition = ballNode.worldPosition
debugNode.worldPosition = ballWorldPosition

sceneView.scene.rootNode.addChildNode(debugNode)
print("Ball World Place: (ballWorldPosition)")
print("Debug Node Place: (debugNode.place)")

The output is

Ball World Place: SCNVector3(x: 0.0, y: -4.0, z: -2.0)
Debug Node Place: SCNVector3(x: 0.0, y: -4.0, z: -2.0)

I’ve tried each of those strategies with out success

let ballWorldPosition = ballNode.worldPosition
let ballWorldPosition = ballNode.convertPosition(ballNode.place, to: nil) 

The check undertaking with the code above will be downloaded right here
https://www.dropbox.com/scl/fi/ufne6qfz4kqayafs4x8dj/testARKit3.zip?rlkey=p4a9bqwpihin3docbdpuwpys4&dl=0

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles