New iPhone simulators |
Everyone can get the source code of Part 3 of SceneKit Tutorial at this link.
You may have seen that I created a box in Part 2. At first of this part, I will show you two types of geometry shapes: Sphere and Pyramid. Similar to box I've shown before, we use SCNSphere and SCNPyramid to create the two types of shapes:
And then put a camera to view the two shapes:
Here we use the default light from scene, so the geometry figures will look like this:
Really Plain Sphere and Pyramid |
Now the program will show something like this:
Sphere and Pyramid with Star |
One thing I want to mention that when assigning materials to a geometry shape, we use a list of materials. Which means we can assign several materials to a shape. But, not all the materials can be shown up. That depends on how many surface a geometry shape could have. For example, if we assign 2 materials to a sphere, because a sphere has only one surface so the second material in the list will be discarded. Here let me try to create another material with a single color and assign two materials to both sphere and pyramid:
Now one side of the pyramid will looks different, but the sphere keeps the same:
After assigning 2 materials to Sphere and Pyramid |
myStar.reflective.contents = UIColor.blueColor()
myBlue.reflective.contents = UIColor.whiteColor()
Now the scene will look like this:
Geometry Shapes with Reflective Materials |
SCNFloor is usually used in a scene as an infinite plain. In a game it usually shows a wall, a background or a land. Objects of SCNFloor has the feature of reflection, so you can see the shadow of the shapes above and beneath the floor. To create a simple floor, here is the code:
Now the scene will looks like this:
Add a Floor to the Scene |
//
// Use reflectivity properties of SCNFloor
//
myFloor.reflectivity = 0.9
myFloor.reflectionResolutionScaleFactor = 1.0
myFloor.reflectionFalloffStart = 2.0
myFloor.reflectionFalloffEnd = 10.0
Here the property reflectivity specifies the contrast of the reflection compared to the original object. If its value equals to 1, the floor looks like a mirror.
The property reflectionResolutionScaleFactor specifies the resolution scale factor of the buffer used to render the reflection, the bigger value will cost more effort to render the reflection.
The property reflectionFalloffStart specifies the distance from the floor where scene contents are reflected at full intensity, and reflectionFalloffEnd specifies the distance from the floor where scene contents are no longer reflected.
By using the values from above code, the result will looks like this:
Effect of a Floor with Reflection Properties |
myFloor.materials = [myStar, myBlue]
It will be:
Set Material to the Floor |
Ah, the floor disappeared seen from the another side of the floor. |
From above code, we initialized an object of SCNText with a string that will be shown in the scene. And set the font of the string in line 5 and the material of the string in line 6. By setting the text's orientation and position, the stuff in the scene will looks like this:
Add Text in the Scene |
This part will end at here. In next part, I will dig into the animation in SceneKit.