SceneKit_入门01_旋转人物
SceneKit_入门02_如何创建工程
SceneKit_入门03_节点
SceneKit_入门04_灯光
SceneKit_入门05_照相机
SceneKit_入门06_行为动画
SceneKit_入门07_几何体
SceneKit_入门08_材质
SceneKit_入门09_物理身体
SceneKit_入门10_物理世界
SceneKit_入门11_粒子系统
SceneKit_入门12_物理行为
SceneKit_入门13_骨骼动画
SceneKit_中级01_模型之间的过渡动画
SceneKit_中级02_SCNView 详细讲解
SceneKit_中级03_切换照相机视角
SceneKit_中级04_约束的使用
SceneKit_中级05_力的使用
SceneKit_中级06_场景的切换
SceneKit_中级07_动态修改属性
SceneKit_中级08_阴影详解
SceneKit_中级09_碰撞检测
SceneKit_中级10_滤镜效果制作
SceneKit_中级11_动画事件
SceneKit_高级01_GLSL
SceneKit_高级02_粒子系统深入研究
SceneKit_高级03_自定义力
SceneKit_高级04_自定义场景过渡效果
SceneKit_高级05 检测手势点击到节点
SceneKit_高级06_加载顶点、纹理、法线坐标
SceneKit_高级07_SCNProgram用法探究
SceneKit_高级08_天空盒子制作
SceneKit_高级09_雾效果
SceneKit_大神01_掉落的文字
SceneKit_大神02_弹幕来袭
SceneKit_大神03_navigationbar上的3D文字
学习目标
1.了解SceneKit 游戏框架中系统包含的几何对象.
2.学习如何将几何形状物体绑定的节点上,显示到视图中.
系统提供的几何形状讲解
- 正方体
创建方法
SCNBox *box = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0];
box.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *boxNode = [SCNNode node];
boxNode.position = SCNVector3Make(0, 0, 0);
boxNode.geometry = box;
[scnView.scene.rootNode addChildNode:boxNode];
- 创建平面
创建方法:
SCNPlane *plane =[SCNPlane planeWithWidth:2 height:2];
plane.firstMaterial.diffuse.contents = [UIImage imageNamed:@"2.PNG"];
SCNNode *planeNode = [SCNNode nodeWithGeometry:plane];
planeNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:planeNode];
- 金子塔
SCNPyramid *pyramid = [SCNPyramid pyramidWithWidth:1 height:1 length:1];
pyramid.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *pyramidNode = [SCNNode nodeWithGeometry:pyramid];
pyramidNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:pyramidNode];
- 球体
创建方法:
SCNSphere *sphere = [SCNSphere sphereWithRadius:1];
sphere.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *sphereNode =[SCNNode nodeWithGeometry:sphere];
sphereNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:sphereNode];
- 圆柱体
创建方法:
SCNCylinder *cylinder = [SCNCylinder cylinderWithRadius:1 height:2];
cylinder.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *cylinderNode =[SCNNode nodeWithGeometry:cylinder];
cylinderNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:cylinderNode];
- 圆锥体
创建方法:
SCNCone *cone = [SCNCone coneWithTopRadius:0 bottomRadius:1 height:1];
cone.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *coneNode = [SCNNode nodeWithGeometry:cone];
coneNode.position = SCNVector3Make(0,0, 0);
[scnView.scene.rootNode addChildNode:coneNode];
- 管道
创建方法:
SCNTube *tube = [SCNTube tubeWithInnerRadius:1 outerRadius:1.2 height:2];
tube.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *tubeNode =[SCNNode nodeWithGeometry:tube];
tubeNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:tubeNode];
- 环面
创建方法:
SCNTorus *torus = [SCNTorus torusWithRingRadius:1 pipeRadius:0.5];
torus.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *torusNode = [SCNNode nodeWithGeometry:torus];
torusNode.position = SCNVector3Make(0, 0, 0);
[scnView.scene.rootNode addChildNode:torusNode];
- 地板
创建方法:
SCNFloor *floor = [SCNFloor floor];
floor.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *floorNode = [SCNNode nodeWithGeometry:floor];
floorNode.position = SCNVector3Make(0, -5, 0);
[scnView.scene.rootNode addChildNode:floorNode];
- 立体文字
创建方法:
SCNText *text = [SCNText textWithString:@"好好学习" extrusionDepth:0.5];
text.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
text.font = [UIFont systemFontOfSize:1];
SCNNode *textNode =[SCNNode nodeWithGeometry:text];
textNode.position = SCNVector3Make(-2, 0, 0);
[scnView.scene.rootNode addChildNode:textNode];
- 自定义形状
创建方法:
// 定义贝塞尔曲线
SCNShape *shape = [SCNShape shapeWithPath:[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 1, 1) cornerRadius:0.5] extrusionDepth:3];
shape.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
SCNNode *shapdeNode =[SCNNode nodeWithGeometry:shape];
[scnView.scene.rootNode addChildNode:shapdeNode];
手把手教你写代码
-
创建工程
添加游戏框架
- 添加游戏专用视图SCNView
SCNView *scnView = [[SCNView alloc]initWithFrame:self.view.bounds];
scnView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scnView];
scnView.allowsCameraControl = TRUE;
- 创建游戏场景
scnView.scene = [SCNScene scene];
- 添加照相机
SCNNode *cameraNode =[SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.position = SCNVector3Make(0, 0, 5);
[scnView.scene.rootNode addChildNode:cameraNode];
- 添加节点并且绑定几何形状物体
// 创建几何对象
SCNTorus *torus = [SCNTorus torusWithRingRadius:1 pipeRadius:0.5];
torus.firstMaterial.diffuse.contents = [UIImage imageNamed:@"1.PNG"];
// 绑定到节点上
SCNNode *torusNode = [SCNNode nodeWithGeometry:torus];
// 设置节点的位置
torusNode.position = SCNVector3Make(0, 0, 0);
// 添加到场景中去
[scnView.scene.rootNode addChildNode:torusNode];
运行结果:
问题:有人问我SegmentCount属性到底干了什么事情?
下面举个例子演示
创建一个有切面的正方体
let box = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.5)
设置一下下面属性
box.chamferSegmentCount = 20
应该理解了吧 哈哈
- 友情提示
代码库,听说经常给人点赞都当老板了!