Let us next add geometry to the scene. We can create some basic geometry such as spheres, boxes, cones, tori, and so on in SceneKit with ease. Let us create a sphere first and add it to the scene.
Create a function called addGeometryNode
in the class and add the following code in it:
func addGeometryNode(){ let sphereGeometry = SCNSphere(radius: 1.0) sphereGeometry.firstMaterial?.diffuse.contents = UIColor.orangeColor() let sphereNode = SCNNode(geometry: sphereGeometry) sphereNode.position = SCNVector3Make(0.0, 0.0, 0.0) scene.rootNode.addChildNode(sphereNode) }
For creating geometry, we use the SCNSphere
class to create a sphere shape. We can also call SCNBox
, SCNCone
, SCNTorus
, and so on to create box, cone, or torus shapes respectively.
While creating the sphere, we have to provide the radius as a parameter, which will determine the size of the sphere. Although to place the shape, we have to attach it...