Game Development Reference
In-Depth Information
pyramidNode.geometry?.firstMaterial?.shininess = 1.0
In this game you are going to keep it simple and work with just one material. Scene Kit
provides easy access to this via the firstMaterial object. You set the diffuse contents
to the color blue. You also want this object to be shiny, so you add another blue color ob-
ject to the specular attribute and increase the shininess to 1. You can experiment with
different colors and shininess to see how these attributes affect your PyramidNode .
Next up is your GlobeNode . Listing 12-3 shows you how to add some items to make it
look more like Earth.
Listing 12-3 . GlobeNode Lightening Enhancements
globeNode.geometry?.firstMaterial?.diffuse.contents
= UIImage(named: "earthDiffuse.jpg")
globeNode.geometry?.firstMaterial?.ambient.contents
= UIImage(named: "earthAmbient.jpg")
globeNode.geometry?.firstMaterial?.specular.contents
= UIImage(named: "earthSpecular.jpg")
globeNode.geometry?.firstMaterial?.normal.contents
= UIImage(named: "earthNormal.jpg")
globeNode.geometry?.firstMaterial?.diffuse.mipFilter
= SCNFilterMode.Linear
With the GlobeNode you are expanding on the NSMaterial and creating a more life-
like Earth. If you look at each of the JPG files, you will see how these files affect the out-
put from Scene Kit and NSMaterial . You will notice you added a mipFilter to the
diffuse property. Scene Kit uses this property to improve the performance when ren-
dering a texture image as a smaller size.
You will now add some materials to the BoxNode . Scene Kit allows you to apply an ar-
ray to the materials, and it will apply this to the geometry. With the BoxNode , you will
apply six different materials, so you have six different sides, as you can see in Listing
12-4 .
Listing 12-4 . BoxNode Materials
var materials = [SCNMaterial]()
let boxImage = "boxSide"
Search WWH ::




Custom Search