1
votes

3D Perspective should block shelves etc correctly

Sample Image of the ScnView:

sample ScnView

Very Simple. Added Scnview. Added Scnnodes ( shapes and lights )

Using standard Omni type light.

Why are the objects in front not blocking the objects behind ?

Here's the CODE:

[self.studioView addSubview:showTimeView];

showTimeView.frame = CGRectMake(self.paperView.frame.origin.x,
                                self.paperView.frame.origin.y,
                                self.paperView.frame.size.width,
                                self.paperView.frame.size.height);

SCNView *sceneView = (SCNView *)showTimeView;
sceneView.backgroundColor = [UIColor whiteColor];  

sceneView.scene = [SCNScene scene];
SCNNode *root = sceneView.scene.rootNode;
sceneView.allowsCameraControl           = YES;
sceneView.autoenablesDefaultLighting    = NO;


// Add Camera
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.position = SCNVector3Make(0, 0, 100);
cameraNode.eulerAngles = SCNVector3Make(0, -M_PI/8, 0);
cameraNode.camera.zNear = 0;
cameraNode.camera.zFar  = thisModuleDepth;
cameraNode.camera.xFov  = thisWallWidth;
cameraNode.camera.yFov  = thisModuleHeight;
[root addChildNode:cameraNode];

// Add Cabinet Piece
SCNBox *cubeGeom = [SCNBox boxWithWidth:tW
                                 height:tH
                                 length:tD
                          chamferRadius:0.0];
SCNNode *cubeNode = [SCNNode nodeWithGeometry:cubeGeom];
cubeNode.position = SCNVector3Make(tX, tY, tZ);

// Tag Material
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = [UIImage imageNamed:thisColor];
[material.diffuse.contents setAccessibilityIdentifier:thisColor] ;
[material.diffuse.contents setAccessibilityLabel:thisID] ;
cubeNode.geometry.firstMaterial = material;
cubeNode.geometry.firstMaterial.locksAmbientWithDiffuse = NO;
cubeNode.physicsBody = [SCNPhysicsBody staticBody];
[root addChildNode:cubeNode];

// Add spotlight
SCNLight *spotLight = [SCNLight light];
spotLight.type = SCNLightTypeOmni;
spotLight.color = [UIColor whiteColor];
SCNNode *spotLightNode = [SCNNode node];
spotLightNode.light = spotLight;
spotLightNode.position = SCNVector3Make(thisWallWidth / 2 ,thisModuleHeight, thisModuleDepth *2);
spotLightNode.light.intensity = 1000;
[root addChildNode:spotLightNode];
1
Are you creating the SCNView in Interface Builder or with code? If the latter, please provide that. It looks like your scene has depth testing disabled, but I don’t think that’s the default. - Noah Witherspoon
All done with Code... I only added IBOutlet SCNView *showTimeView for Interface Builder to pick up the proper view... - Juanra

1 Answers

1
votes

Thanks Noah,

I finally figured out what was wrong!!!

Set the automaticallyAdjustsZRange property of your SCNCamera to true and it will ensure that nothing is clipped because of the wrong zNear or zFar being set.

THANKS FOR YOUR HELP !!!

HERE IT IS FIXED: Perfect 3D Perspective

enter image description here