instructions
This series of articles is a chronicle of the book 3D Apple Games by Tutorials
Raywenderlich released a collection of back numbers (including ARKit by Tutorials) and its code in 2021
SceneKit series of articles
Series Of articles
-
Hello SceneKit
-
Physics physics
-
Render Loop
-
Particle Systems
-
Touch events in 3D space
-
Scene Editor
-
Cameras camera
-
Towns Lights
-
Basic Collision Detection
-
Materials material
-
Reference Nodes Reference Nodes
-
We knew the shadow
-
Intermediate Collision Detection Intermediate Collision Detection
-
Motion Control
-
Transitions Transitions
-
Actions
-
Audio Audio
-
Mac commonly used 3D tools
-
MagicaVoxel uses 3D voxel mesh modeling
-
Copy fruit ninja mini game Geometry Fighter
-
3D brick Breaker
-
Marble Maze is a 3D balanced ball game
-
Cross-platform games (macOS,tvOS,watchOS)
-
Voxel style road crossing Game Mr. Pig
-
How to make a game like Can Knockdown
-
How do you make a game like Stack
Scenes:SCNScene
We use the scene Gragh to organize the scene. We can add treelike internal nodes to the scene, such as lights, cameras, geometry, etc. Particle emitters are not fed. You need to render it in an instance of SCNView, which is a subclass of NSView in OSX(macOS), which is a subclass of UIView in iOS;
Tree structure on the left
Coordinate system, off-screen is +Z direction, coordinates are represented as vectors, example SCNVector3(x: 0, y: 5, Z: 10)
Nodes:SCNNode
Every element in the game is called a node and stored in a tree called scene Gragh, such as lights, cameras, geometry, and particle emitters. Each scene Graph contains a special base node, the root node, under which you can add other nodes to become its children.
The node added to the scene defaults to (x:0, y:0, z:0), which is relative to the parent node. To adjust the position of a node on its parent, you should adjust local coordinates, not World coordinates.
Note that by default, if nothing changes in a Scene, the Scene Kit will go into the “paused” state. To prevent this, set the playing property to true when creating the SCNView instance
scnView.playing = true
Copy the code
camera
The display range of the camera is controlled. If it is smaller than zNear, it will not be displayed; if it is larger than zFar, it will not be displayed. Adds to the camera property of an empty node
func setupCamera(a) {
// 1. Create an empty node
cameraNode = SCNNode(a)// 2. Create a camera and add it to the node
cameraNode.camera = SCNCamera(a)// 3. Set the position of the camera node
cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)
// 4. Add it to the root node
scnScene.rootNode.addChildNode(cameraNode)
}
Copy the code
The geometry of the primitives
The system comes with a lot of basic geometry that can be added to the geometry properties of an empty node. The first row is from the left :cone, torus, capsule, tube. The second row is from the left :pyramid, box. Sphere, cylinder
SCNView built-in properties
// 1. Display statistics
scnView.showsStatistics = true
// 2. Turn on the camera control
scnView.allowsCameraControl = true
// 3. Automatically enable the default light source
scnView.autoenablesDefaultLighting = true
Copy the code
1. ShowsStatistics displays a real-time statistics bar at the bottom. Click the + sign on the left to expand it. 2. AllowsCameraControl allows simple gesture control of the camera – Single-finger slide: rotate the camera; – Two-finger slide: move the camera; – Kneading with two fingers: Pinch; – Double click: if there are two cameras, switch, one camera will return to the original state; 3. Create a generic omnidirectional autoenablesDefaultLighting light source;
FPS: Frame rate, the number of frames rendered per second
◆: The total number of objects rendered in each frame, the same object will be rendered many times when multiple light sources illuminate the same object
▲: The total number of polygons rendered per frame
✸: Total number of visible light sources (affecting the light sources of objects). Scene Kit recommends not using more than three light sources at the same time