I want to display few objects placed around one point like on sphere within SceneKit
, but have some issue with object configuration.
The main idea is to make camera positioned in the center (0,0,0) and all object will be configured used spherical coordinate system around, so once I put object around in some imagery spherical system, I will rotate camera around some of axis to look at object(s) in selected part of space.
What I try to do for start - I want to create empty SCNScene
, add light, read .dae
file and configure objects.
But for now i cant understand where i'm wrong - when I try to change any of property for SCNNode
- nothin actually changed.
Also I need to put zFar
for camera to strange big value - 10000 - to be able see object (I use allowsCameraControl
setted to YES
for now to be able to rotate obj)
Actually code:
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];
Any suggestion? Maybe I miss something - not very familiar with SceneKit
.
Additional note - I have also some bone based animation in .dae
file.
How to change position, scale, rotation of SCNNode (on change of SCNNode's property actually nothing happens)?