How to Create Virtual 3D Content with SceneKit in Swift 4
I am using this one to create a simple 3D object in a Single View application. In the default configuration, the following code places a 10cm cube 20 centimeters in front of the original camera position.
let cubeNode = SCNNode(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0))
cubeNode.position = SCNVector3(0, 0, -0.2)
sceneView.scene.rootNode.addChildNode(cubeNode)
When plane detection is enabled, ARKit adds and updates bindings for each plane it detects. To add visual content for these anchors, do ARSCNViewDelegate Methods such as:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
let plane = SCNPlane(width: CGFloat(planeAnchor.extent.x), height: CGFloat(planeAnchor.extent.z))
let planeNode = SCNNode(geometry: plane)
planeNode.position = SCNVector3Make(planeAnchor.center.x, 0, planeAnchor.center.z)
planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)
node.addChildNode(planeNode)
}
How can I manipulate a 3D object.
+3
source to share
No one has answered this question yet
Check out similar questions: