Recently, we've been collecting data. 3D finally decided to lock the OC frame, find the learning materials and then slowly organize
SceneKit is a OC frame, before you begin, familiarize yourself with the three-dimensional coordinate system of SceneKit:
It is clear that the coordinate system in SceneKit is the right-hand coordinate system (Cartesian coordinate system), if you need to share data with other 3D frames, first understand whether the frame is a right-handed or left-handed coordinate system. In fact, it is also very good transformation, is the z axis of the positive or negative is not the same.
Before you begin your development, be sure to understand the following very important classes
Class/protocol |
Describe |
Scnview &Scnscenerenderer
|
Similar to UIView, used to display the contents of the SceneKit, defines a number of proxy methods that can be added to UIView with the Addsubview method |
Scnscene |
A container for SceneKit content. You can load a scene from a. Dae file generated by the 3D modeling tool, or create one with code and display it on the view |
Scnnode |
A basic building block of a scene where you can attach cameras, lights, and geometry to a node |
Scngeometry |
A three-dimensional object that can be connected to a node. A geometry (sometimes called a model or mesh) defines only the shape of a visible object. To define the surface color pattern of an object, you will need to attach material to the geometry. Then the material is mapped, or colored, and the surface of the geometry is colored, or patterned.
You can load a geometry from a. Dae file generated by the 3D modeling tool, or you can create it in code, SCENEKIT provides several common geometries, which are subclasses of scngeometry such as box, ball, cylindrical ball, etc. We'll write a demo that will give you the official geometry and give you an intuitive feel. Of course, we can also use three-dimensional coordinates, normal vector custom geometry, can also say a 2D pattern into a depth (thickness) of three-dimensional geometry. There should be a special article about using Bezier curves to transform a 2D pattern into a three-dimensional geometry with depth (thickness).
|
Scnmaterial |
The material is also called a material ball because it is spherical in the 3D modeling tool. Color, the map depends on it all. |
Scnlight |
The light source can be attached to the node, providing shading in the rendered scene |
Scncamera |
A virtual camera can be attached to a node, providing a view of the scene. |
To understand the above, let's start with the development, we can create a new Scenekit project in Xcode:
The results are as follows:
This new Scenekit project will have some sample code, and we'll pick some important notes:
[HTML]View PlainCopy
- Scnscene *scene = [Scnscene scenenamed:@ "ART.SCNASSETS/SHIP.SCN"];
Load a scene from an SCN file, or load from a. Dae file
[HTML]View PlainCopy
- Scnnode * Ship= [scene.rootnode childnodewithname:@ ' ship ' recursively:yes];
Get this scene in the plane this node
[HTML]View PlainCopy
- [Ship runaction:[scnaction repeatactionforever:[scnaction rotatebyx:0 y:2 z:0 Duration:1]];
To keep the plane spinning around his y axis.
[HTML]View PlainCopy
- Scnview.allowscameracontrol = YES;
Allows the user to control the camera, with the following sentence to add a gesture code, the user can zoom in, zoom out, 360 degrees to rotate the entire scene
[HTML]View PlainCopy
- Gesturerecognizers AddObjectsFromArray:scnView.gestureRecognizers];
[HTML]View PlainCopy
- Scnview.showsstatistics = YES; Controls whether the statistics bar below is displayed
In the click Gesture:
[HTML]View PlainCopy
- Check what nodes is tapped
- Cgpoint p = [Gesturerecognize Locationinview:scnview];
- Nsarray *hitresults = [Scnview hittest:p options:nil];
Similar to the ray detection, the detection of the two-dimensional point deep infinity, the node on the ray, return an array, can be used to click to select, the first data in the array is generally the node we need.
[HTML]View PlainCopy
- [Scntransaction begin];
- [Scntransaction setanimationduration:0.5];
- On Completion-unhighlight
- [Scntransaction setcompletionblock:^{
- [Scntransaction begin];
- [Scntransaction setanimationduration:0.5];
- material.emission.contents = [Uicolor blackcolor];
- [Scntransaction commit];
- }];
- material.emission.contents = [Uicolor Redcolor];
- [Scntransaction commit];
An animated chunk in SceneKit, similar to an animated chunk in a UIKit.
On iOS SceneKit 3D engine