【发布时间】:2015-11-27 07:25:48
【问题描述】:
我有一个 3D 球体模型保存为 dae 文件并加载到 xcode。
问题是我无法让它旋转/旋转 - 它只是保持静止...我尝试了几种方法,甚至试图让相机在它周围移动。
SCNScene *model = [SCNScene sceneNamed:@"model3.dae"];
SK3DNode *node = [[SK3DNode alloc] initWithViewportSize:CGSizeMake(50, 50)];
//workaround
id s1 = [node valueForKey:@"_scnRenderer"];
NSLog(@"%@", s1);
node.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:node.frame.size.width/2];
node.physicsBody.affectedByGravity = NO;
node.physicsBody.allowsRotation = YES;
node.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[node setScnScene:model];
//THIS IS THE PART! I cannot get it to spin around
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"rotation"];
rotationAnimation.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(1, 2, 3, M_PI * 2)];
rotationAnimation.duration = 1;
rotationAnimation.repeatCount = FLT_MAX;
[model.rootNode addAnimation:rotationAnimation forKey:nil];
//camera
SCNCamera *camera = [SCNCamera camera];
camera.xFov = 0;
camera.yFov = 0;
camera.zNear = 0.0;
camera.zFar = 10.0;
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = camera;
cameraNode.position = SCNVector3Make(0, 0, 5);
[model.rootNode addChildNode:cameraNode];
node.pointOfView = cameraNode;
[world addChild:node];
有什么想法吗?基本上我想尝试让 3D 模型在 SK3DNode 内移动。希望这是有道理的。想想旋转的星球。
提前致谢, 亚历克斯
【问题讨论】:
标签: ios sprite-kit scenekit