美文网首页iOS 知识收集
IOS 学习AR(3)( 3D引擎 SceneKit SC

IOS 学习AR(3)( 3D引擎 SceneKit SC

作者: 升哥_d84b | 来源:发表于2018-04-23 17:35 被阅读0次

SCNGeometry几何体类型

1.SCNBox 立方体

代码:(下面只介绍几何体创建)

//盒子

SCNBox *box = [SCNBox boxWithWidth:10 height:10 length:10 chamferRadius:0];

//材质(贴图后面章节说贴图)

    SCNMaterial *allMaterial1 = [SCNMaterial new];

    allMaterial1.diffuse.contents =[UIImage imageNamed:@"1"];

    SCNMaterial *allMaterial2 = [SCNMaterial new];

    allMaterial2.diffuse.contents =[UIImage imageNamed:@"2"];

    SCNMaterial *allMaterial3 = [SCNMaterial new];

    allMaterial3.diffuse.contents =[UIImage imageNamed:@"3"];

    SCNMaterial *allMaterial4 = [SCNMaterial new];

    allMaterial4.diffuse.contents =[UIImage imageNamed:@"4"];

    SCNMaterial *allMaterial5 = [SCNMaterial new];

    allMaterial5.diffuse.contents =[UIImage imageNamed:@"5"];

    SCNMaterial *allMaterial6 = [SCNMaterial new];

    allMaterial6.diffuse.contents =[UIImage imageNamed:@"6"];

//贴图位置

    NSArray *array = @[allMaterial1,allMaterial2,allMaterial3,allMaterial4,allMaterial5,allMaterial6];

//    @[front,right,back,left,top,bottom];

    box.materials = array;

//立方体放node

    SCNNode *boxNode = [SCNNode nodeWithGeometry:box];

    boxNode.position = SCNVector3Make(0, 0, -50);

    [self.scnView.scene.rootNode addChildNode:boxNode];

//动画(为更好的体现立体,下一节介绍动画效果)

    SCNAction *action = [SCNAction rotateByAngle:10 aroundAxis:SCNVector3Make(0, 1, 0) duration:6];

    SCNAction *action1 = [SCNAction rotateByAngle:10 aroundAxis:SCNVector3Make(1, 0, 0) duration:4];

    [boxNode runAction:[SCNAction group:@[[SCNAction repeatActionForever:action],[SCNAction repeatActionForever:action1]]]];

2.SCNPlane 平面

    SCNPlane *Plane = [SCNPlane planeWithWidth:10 height:10];

3.SCNPyramid 锥形(金字塔)

    SCNPyramid *Pyramid = [SCNPyramid pyramidWithWidth:10 height:10 length:10];

4.SCNSphere 球体

SCNSphere *Cylinder = [SCNSphere sphereWithRadius:10];

5.SCNCylinder 圆柱

    SCNCylinder *Cylinder = [SCNCylinder cylinderWithRadius:10 height:10];

6.SCNCone 圆锥体

    SCNCone *Cylinder = [SCNCone coneWithTopRadius:10 bottomRadius:6 height:10];

7.SCNTube 圆柱管道

    SCNTube *Cylinder = [SCNTube tubeWithInnerRadius:8 outerRadius:10 height:10];

8.SCNCapsule 胶囊

SCNCapsule *Cylinder = [SCNCapsule capsuleWithCapRadius:1 height:10];

9.SCNTorus 圆环面

SCNTorus *Cylinder = [SCNTorus torusWithRingRadius:10 pipeRadius:3];

10.SCNFloor 地板

    SCNFloor *Cylinder = [SCNFloor floor];

    Cylinder.firstMaterial.diffuse.contents =[UIImage imageNamed:@"1"];

    SCNNode *CylinderNode = [SCNNode nodeWithGeometry:Cylinder];

    CylinderNode.position = SCNVector3Make(0, -5, 0);

    [self.scnView.scene.rootNode addChildNode:CylinderNode];

11.SCNText 字体

SCNText *Cylinder = [SCNText textWithString:@"海贼王" extrusionDepth:10];

12.SCNShape 自定义几何体

//路径 (单位为1m)

     UIBezierPath *path=[UIBezierPath bezierPath];

    [path moveToPoint:CGPointMake(0, 5)];

    [path addLineToPoint:CGPointMake(5, 0)];

    [path addLineToPoint:CGPointMake(10, 2.5)];

    [path addLineToPoint:CGPointMake(10, 7.5)];

    [path addLineToPoint:CGPointMake(5, 10)];

    [path addLineToPoint:CGPointMake(0, 5)];

//添加路径

    SCNShape *Cylinder = [SCNShape shapeWithPath:path extrusionDepth:6];

    Cylinder.chamferMode =SCNChamferModeBoth;

    Cylinder.firstMaterial.diffuse.contents =[UIImage imageNamed:@"1"];

相关文章

网友评论

    本文标题:IOS 学习AR(3)( 3D引擎 SceneKit SC

    本文链接:https://www.haomeiwen.com/subject/vtsekftx.html