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
ios swift swift4 arkit


source to share


No one has answered this question yet

Check out similar questions:

928
How do I call Objective-C code from Swift?
902
# pragma in Swift?
870
Swift Beta: Sorting Arrays
641
Split string into array in Swift?
451
How do I create a UIAlertView in Swift?
423
Using Swift 3 @objc inference in Swift 4 mode is deprecated?
2
how do you know if a detected node is a credential or horizontal in ARKit?
2
iOS ARKIT uses UIView as content in SCNNode
0
How do I place an anchor in ARKit relative to the ground using WorldAlignment and not relative to the camera?
0
IBOutlet connection keeps returning nil



All Articles
Loading...
X
Show
Funny
Dev
Pics