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)
}
@Ihor Kram: based on your comment I beleave the node you wish to fade out is a childNode of your
myNodeobject - at some specific index. Open the object file with the visual editor within Xcode. On the left side you will find the Scene Graph section. This should give you an overview on the different nodes/objects the .obj fle contains. Start counting from the top to the bottom. The element on the top has index 0. Just count until you identify the node you wish to fade out. Then you can run theSCNActionto fade out the specific SCNNode like this:(assuming the Node you wish to fade out is at index 3 - like in this example)
Hope it will work.
In addition you could convert the .obj to a .scn file. The .scn file loads a bit faster to memory compared to other formats like .obj or .dae. .scn also has the advantage that it stores the materials way better if you define them within the visual editor. i.Ex. for .physicallyBased PBR textures.