【发布时间】:2017-03-11 10:15:03
【问题描述】:
我想在SceneKit 内显示一些放置在一个点周围的对象,例如在球体上,但对象配置有一些问题。
主要的想法是让相机定位在中心 (0,0,0) 并且所有对象都将被配置为使用球坐标系,所以一旦我将对象放在某个图像球系中,我将旋转相机一些轴来查看空间选定部分中的对象。
我开始尝试做的事情 - 我想创建空的 SCNScene,添加灯光,读取 .dae 文件并配置对象。
但现在我无法理解我错在哪里 - 当我尝试更改 SCNNode 的任何属性时 - 实际上没有任何改变。
我还需要将相机的 zFar 设置为奇怪的大值 - 10000 - 才能看到物体(我现在使用 allowsCameraControl 设置为 YES 以便能够旋转 obj)
实际代码:
SCNScene *scene = [SCNScene scene]; //main scene
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.camera.zFar = 10000; //only with this value i can see my obj
cameraNode.position = SCNVector3Make(0, 0, 0); //position in the center
[scene.rootNode addChildNode:cameraNode];
// create and add a light to the scene
SCNNode *lightNode = [SCNNode node];
lightNode.light = [SCNLight light];
lightNode.light.type = SCNLightTypeOmni;
lightNode.position = SCNVector3Make(0, 10, 10);
[scene.rootNode addChildNode:lightNode];
// create and add an ambient light to the scene
SCNNode *ambientLightNode = [SCNNode node];
ambientLightNode.light = [SCNLight light];
ambientLightNode.light.type = SCNLightTypeAmbient;
ambientLightNode.light.color = [UIColor darkGrayColor];
[scene.rootNode addChildNode:ambientLightNode];
SCNScene *objScene = [SCNScene sceneNamed:@"art.scnassets/file.dae"];
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = [UIImage imageNamed:@"art.scnassets/texture.png"];
material.locksAmbientWithDiffuse = true;
SCNNode *node = [objScene.rootNode childNodeWithName:@"obj" recursively:YES];
node.geometry.firstMaterial = material;
//try next:
// node.position = SCNVector3Make(0, 0, 0);
// node.presentationNode.position = SCNVector3Make(0, 0, 0); -> should't be modified as explainde by Apple devs - "The effect of attempting to modify the returned node in any way is undefined"
// node.transform = SCNMatrix4MakeScale(0.5, 0.5, 0.5);
// node.scale = SCNVector3Make(0.1, 0.1, 0.1);
[scene.rootNode addChildNode:node];
有什么建议吗?也许我错过了一些东西 - 对SceneKit 不太熟悉。
附加说明 - 我在 .dae 文件中还有一些基于骨骼的动画。
如何改变 SCNNode 的位置、比例、旋转(改变 SCNNode 的属性实际上什么都没有发生)?
【问题讨论】:
-
你看到了什么?你要看什么?截图会有所帮助。
-
@HalMueller 如果我平移屏幕,我会看到完整的对象 - 这意味着如果我应用标准相机修改 (
allowsCameraControl = YES;),在开始时我只看到对象的一部分 - 所以它与开始有点不一致视野我想看到它是按比例缩小的对象,或者如果我改变历史位置或比例或其他可以在空间中移动的对象。但正如我上面描述的,我只能看到 obj 的一部分,如前所述,在移动时我看到了所有对象。附加:当我尝试使用pauseAnimationForKey:方法暂停动画时,它的 alos 没有效果,但使用.presentationNode.paused = YES- 它有效。
标签: ios scenekit collada scnnode spherical-coordinate