2016-12-01 34 views
1

3D透视应该阻止货架等正确Scnview节点出现半透明

的ScnView的样品图像:

sample ScnView

非常简单。新增了Scnview。添加了Scnnodes(形状和灯光)

使用标准Omni型灯。

为什么前面的物体没有阻挡后面的物体?

下面的代码:

[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]; 
+0

你创建在Interface Builder或代码SCNView?如果是后者,请提供。它看起来像你的场景已禁用深度测试,但我不认为这是默认。 –

+0

全部完成代码...我只添加了IBOutlet SCNView * showTimeView来为Interface Builder提取正确的视图... – Juanra

回答

1

感谢诺亚,

我终于想通了,什么是错的!

将SCNCamera的automaticallyAdjustsZRange属性设置为true,它将确保没有任何内容被剪切,因为设置了错误的zNear或zFar。

感谢您的帮助!

这是固定的:Perfect 3D Perspective

enter image description here