SceneKit_大神03_navigationbar上的3D文字

让学习成为一种习惯
如果你已经掌握了我前面写的入门教程,从今天开始,你可以提高水平了。
先看效果图:

只要你做就能实现
掌握模型的过渡动画
你要记住的
模型到模型之间的过渡,两个或者多个模型的数据顶点必须相同
先看效果图:
我们先看一下我们的模型文件
1.一个四方形,但是边上有很多顶点

培养学习的兴趣很重要
2.折皱的面

让学习成为一种习惯
接下来,我们让这两个面平滑过渡

8C4C8A7E-BDAE-4AE4-BC51-B13A871FD4C0.png
SCNView *scnView = [[SCNView alloc]initWithFrame:self.view.bounds];
scnView.backgroundColor = [UIColor blackColor];
scnView.scene = [SCNScene scene];
scnView.allowsCameraControl = true;
[self.view addSubview:scnView];SCNNode *cameraNode = [SCNNode node];
cameraNode.position = SCNVector3Make(0, 0, 20);
cameraNode.camera = [SCNCamera camera];
cameraNode.camera.automaticallyAdjustsZRange = true;
[scnView.scene.rootNode addChildNode:cameraNode]; NSURL *url1 = [[NSBundle mainBundle]URLForResource:@"aaa" withExtension:@"dae"];
NSURL *url2 = [[NSBundle mainBundle]URLForResource:@"aaa2" withExtension:@"dae"];
SCNScene *scene1 = [SCNScene sceneWithURL:url1 options:nil error:nil];
SCNScene *scene2 = [SCNScene sceneWithURL:url2 options:nil error:nil];
SCNGeometry *g1 = [scene1.rootNode childNodeWithName:@"plane" recursively:true].geometry;
SCNGeometry *g2 = [scene2.rootNode childNodeWithName:@"plane" recursively:true].geometry;
g1.firstMaterial.diffuse.contents = @"mapImage.png";
g2.firstMaterial.diffuse.contents = @"mapImage.png";SCNNode *planeNode = [SCNNode node];
[scnView.scene.rootNode addChildNode:planeNode];
planeNode.geometry = g1;
[scnView.scene.rootNode addChildNode:planeNode];到这里我们的准备工作已经完成,下面就是我们今天的重点内容
planeNode.morpher = [[SCNMorpher alloc]init];
planeNode.morpher.targets = @[g2]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"morpher.weights[0]"]; // 0 代表过渡目标数组的第一个模型
animation.fromValue = @0.0;
animation.toValue = @1.0;
animation.autoreverses = YES;
animation.repeatCount = INFINITY;
animation.duration = 2;
[planeNode addAnimation:animation forKey:nil];下面叫大家一种简单的方式实现上面的效果,先给看一张图

模型文件截图
我们可以让模型设计师帮我们把过渡到指定的目标几何绑定到我们的文件中
接下来,再看我们的代码怎么写
NSURL *url3 = [[NSBundle mainBundle]URLForResource:@"foldingMap" withExtension:@"dae"];
SCNNode *node1 = [[SCNScene sceneWithURL:url3 options:nil error:nil].rootNode childNodeWithName:@"Map" recursively:true];
node1.geometry.firstMaterial.diffuse.contents = @"1.PNG";
[scnView.scene.rootNode addChildNode:node1];
// 过渡动画和上面的写法一样
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"morpher.weights[0]"];
animation.fromValue = @0.0;
animation.toValue = @1.0;
animation.autoreverses = YES;
animation.repeatCount = INFINITY;
animation.duration = 2;
[node1 addAnimation:animation forKey:nil];我们模型过渡动画内容讲解完毕,你掌握了吗?
代码库,听说经常给人点赞都当老板了!