'How to change height width of 3D objects in SceneKit iOS
I am displaying 3D (.obj and .stl) object in my mobile App .
For displaying 3D object i am using SceneKit Framework.
-(void)spriteKitEx
{
sceneView = [[SCNView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 200)];
sceneView.playing = true ;
sceneView.allowsCameraControl = true ;
scene = [SCNScene sceneNamed:@"realship.obj"];
//Try to change color here using Scenlight
SCNLight *light =[[SCNLight alloc] init];
light.type = SCNLightTypeAmbient;
light.color = [UIColor redColor];
SCNNode *lightNode = [[SCNNode alloc] init];
lightNode.light = light ;
lightNode.scale = SCNVector3Make(1.0, 500.0, 2.0);
[scene.rootNode addChildNode:lightNode];
sceneView.scene = scene;
[sceneView setBackgroundColor: [UIColor redColor]];
[self.view addSubview:sceneView];
}
Now my requirement is to change the width and height of 3D object according to user gesture.
I have tried to do this in my SceneView object but I have not been able to change the width and height.
Solution 1:[1]
There are two ways to do this in a 3D scene:
1. Use a camera, and change zoom/lens length and/or dolly it
Zooming is usually described in lens length or field of view. A larger virtual length is zooming in, smaller is zooming out. Conversely, a larger field of view is zooming out and a smaller field of view is zooming in.
Dollying is the process of transposing the position of a camera in terms of distance from its subject; that which it's looking at. The further away the smaller the object appears, the closer the bigger.
2. Scale the object
This is pretty straight forward. But will seem odd for a gesture as only one object will appear to change. If you're making a 3D editing app, this might be what you want. Otherwise you probably want to be moving and/or zooming the camera.
Solution 2:[2]
First, apologies if this comes across as simplistic. I'm writing about how to scale, move, or orient a 3D file without knowing your level of familiarity with Xcode; viewing and manipulating items in the scnassets folder. Last caveat, I don't work with obj files but assume (hope, really) that they can be edited in Xcode just like a dae file.
Open the Project Navigator (?1) and look for the scnassets folder that (hopefully) exists and contains your obj file. From your scnassets folder, select your obj file and your object should appear in the Editor. Open the Scene Graph View and select the node you need to resize for width and height. In the Utilities view's Node Inspector (??3), you'll see several features of the node that you can change, one of which is Scale. Under Scale, you'll see the bounding box dimensions of the node you wish to change.
If you need to rescale several nodes at once, I'd suggest creating a Child Node, using the + sign under the Scene Graph view, and then moving the nodes that need to be rescaled (or moved or reoriented) into the child node and then rescaling that child node to the size you need.
Also, as a precaution, Save after every change or so to your obj file. Xcode 8.2.1 is much more stable, but 8.2 would crash after every change or two to a dae/scn file. Hope all of this helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Confused |
| Solution 2 | Jim Hillhouse |
