我想在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的属性时,实际上什么都没有发生)?
发布于 2016-10-28 15:33:19
我认为你要求的关键是
我将旋转相机围绕轴来观察物体在选定的空间部分。
可以使用约束属性将约束分配给SCNNode。将目标节点更改为与空间的选定部分相对应的对象。
https://stackoverflow.com/questions/40306450
复制相似问题