I use the SceneKit library (Swift, iOS) to show the mesh (.obj file) of a building in my iPhone app. Mesh is, in fact, a 3D model of the entire building. Mesh is one big monolith file. So consider the mesh file contains all elements (walls, floor, rooms).
var myNode: SCNNode?
let myscene = try SCNScene(url: urlToMyOBJFile, options: nil)
if let mesh = myscene.rootNode.childNodes.first {
self.myNode = mesh
self.mainScene.rootNode.addChildNode(self.myNode!)
}
On the "hide" button tapped I run animation to hide the mesh:
let action = SCNAction.fadeOut(duration: 3)
self.myNode?.runAction(action)
During this animation opacity of the mesh changes from 1 to 0.
It creates an effect when, during the animation, walls became semi-transparent, and users can see through them.
I mean, during the animation all mesh became semi-transparent (for example opacity = 0.5 in the middle of the animation), so do walls.
And users can see the parts of the mesh which are located behind walls (aka next room).
How to make mesh fade out without the "x-ray eyes" effect?
screenshots:
1 - wall
2 - wall during SCNAction.fadeOut() animation became semi-transparent, you can see other rooms behind the wall.
more code on how I compose the scene (answer for ZAY's comment):
let sceneView = SCNView()
let mainScene = SCNScene()
override func viewDidLoad() {
super.viewDidLoad()
sceneView.frame = self.view.frame
self.view.addSubview(sceneView)
sceneView.scene = mainScene
let camera = SCNCamera()
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: 0.0, y: 0.0, z: 3.0)
let light = SCNLight()
light.type = SCNLightTypeOmni
let lightNode = SCNNode()
lightNode.light = light
lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)
let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)
scene.rootNode.addChildNode(lightNode)
scene.rootNode.addChildNode(cameraNode)
}