3

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)?

hbk
  • 10,908
  • 11
  • 91
  • 124
  • What do you see? What do you want to see? A screenshot would help. – Hal Mueller Oct 30 '16 at 01:06
  • @HalMueller i see complete object if i pan screen - so mean if I apply standard camera modification (`allowsCameraControl = YES;`), on start i see only part of object - so it's a little bit misalignment with start fov. What i want to see it's scaled out object, or object that can be moved in space if i change hist position, or scale or whatever. But as i describe above i can see only part of obj, on move as noted i see all object. Additional: when i try to pause animation with `pauseAnimationForKey:` methods it's alos has no effect, but with `.presentationNode.paused = YES` - it's works. – hbk Oct 30 '16 at 14:35

1 Answers1

0

I think the key phrase in your request is

I will rotate the camera around the axis to look at object(s) in the selected part of space.

Check SCNLookAtConstraint.

You can assign a constraint to a SCNNode using its constraints property. Change the target node to the object corresponding to the selected part of the space.

Karl Sigiscar
  • 289
  • 1
  • 7
  • I see on AppleDev - "A constraint that orients a node to always point toward a specified other node." Always point, but i need to make scene where user can see only part of object, depend from phone rotation, maybe with use of CoreMotion or something similar option – hbk Oct 28 '16 at 16:02
  • Yes. But you can dynamically change the target of the constraint. So, if as the phone rotates, you change the target of the constraint to a different object, the camera will point to it. – Karl Sigiscar Oct 31 '16 at 16:23
  • the camera will point exactly to obj? I need sometimes points to point between few obj or point to empty space. Is it possible with proposed solution? – hbk Oct 31 '16 at 16:29
  • It will point to any SCNNode you pass it. You could always have empty nodes as targets where necessary (just placeholders, without any geometry attached). But if that's too convoluted for your purpose, then you are going to have to make the calculations for the camera by yourself. – Karl Sigiscar Nov 01 '16 at 09:38