【问题标题】:SK3DNode not rotatingSK3DNode 不旋转
【发布时间】: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


    【解决方案1】:

    修改场景根节点的变换(例如,通过添加动画)没有效果,因为相机由该根节点的子节点持有。球体和相机之间的相对变换保持不变。您应该将动画添加到相机节点或球体节点。

    【讨论】:

    • 谢谢。是的,将动画应用于相机是有效的,我必须在设置结束时进行。如何获取球体节点?
    • 没关系,我猜到了...感谢您的帮助! SCNNode *n = [model.rootNode childNodeWithName:@"Icosphere" 递归:YES];
    猜你喜欢
    • 2017-04-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多