SCeneKit 学习(2)--SCNGeometry、SCNL

2018-09-05  本文已影响135人  acon

SCNLight: 灯光

  1. 概念:游戏框架中的光源,为场景 提供阴影

  2. 灯光的分类(光源分为四种):

    1. 环境光(SCNLightTypeAmbient),这种光没有方向,位置在无穷远处,光均匀的散射在物体上
    2. 点光源(SCNLightTypeOmni):有固定位置,方向360度,可以衰减
    3. 平行方向光(SCNLightTypeDirectional):只有照射的方向,没有位置,不会衰减
    4. 聚焦光源(SNCLightTypeSpot):光有固定位置,也有方向,也有照射区域,可以衰减


      47ccaccd-5532-4244-af4e-e234b30ed6b8.png
  3. 光源的颜色: Color

  4. 光源温度: temperature

  5. 光源强度: intensity: 默认 是 1000

  6. CastsShadow:是否支持投射阴影,这个只有在点光源或者平行方向光源有作用

  7. shadownColor: 阴影颜色

SCNGeometry: 几何对象

  1. SCNGeometry: SCeneKit 游戏框架中的几何对象.将几何对象绑定到节点上,显示到view
  2. 系统包含的,
    正方体,
    平面(SCNPlane),
    金字塔,
    球体,
    圆柱体,
    圆锥体,
    管道,
    环面,
    地板(SCNFloor),
    立体字,
    自定义形状(通过贝塞尔曲线)创建SCNShape
    然后赋值给Node 节点
  3. 代码:
// 1. 球体
SCNSphere *sphere = [SCNSphere sphereWithRadius:0.5];
sphere.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *earthNode = [SCNNode nodeWithGeometry:sphere];
// [scene.rootNode addChildNode:earthNode];
//2. 字体
SCNText *scntext = [SCNText textWithString:@"Lenovo" extrusionDepth:0.3];
scntext.font = [UIFont systemFontOfSize:0.3];
SCNNode *textnode = [SCNNode nodeWithGeometry:scntext];
textnode.position = SCNVector3Make(-1, 0, -2);
// [earthNode addChildNode:textnode];
// 3. 平面
SCNPlane *plane = [SCNPlane planeWithWidth:2 height:2];
plane.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *planeNode = [SCNNode nodeWithGeometry:plane];
// [scene.rootNode addChildNode:planeNode];
// 4. 金字塔
SCNPyramid *pyramid = [SCNPyramid pyramidWithWidth:1 height:1 length:1];
pyramid.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *pyramidNode = [SCNNode nodeWithGeometry:pyramid];
// [scene.rootNode addChildNode:pyramidNode];
//5. 圆柱体
SCNCylinder *cylinder = [SCNCylinder cylinderWithRadius:1 height:1.5];
cylinder.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *cylinderNode = [SCNNode nodeWithGeometry:cylinder];
// [scene.rootNode addChildNode:cylinderNode];
//6. 管道
SCNTube *tube = [SCNTube tubeWithInnerRadius:0.5 outerRadius:0.6 height:1];
tube.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *tubeNode = [SCNNode nodeWithGeometry:tube];
// [scene.rootNode addChildNode:tubeNode];
//6. 管道
SCNTorus *torus = [SCNTorus torusWithRingRadius:1 pipeRadius:0.5 ];
torus.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *torusNode = [SCNNode nodeWithGeometry:torus];
// [scene.rootNode addChildNode:torusNode];
// 7. 地面
SCNFloor *floor = [SCNFloor floor];
floor.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *floorNode = [SCNNode nodeWithGeometry:floor];
// [scene.rootNode addChildNode:floorNode];
SCNShape *customShap = [SCNShape shapeWithPath:[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 1, 1) cornerRadius:0.5] extrusionDepth:3];
customShap.firstMaterial.diffuse.contents = @"earth.jpg";
SCNNode *customShapNode = [SCNNode nodeWithGeometry:customShap];
[scene.rootNode addChildNode:customShapNode];

SCNCamera: 相机

以后用到单独讲解

上一篇下一篇

猜你喜欢

热点阅读