So in order to fix it I created a new material, disabled depthTest and depthWrite, assigned the material to the meshInstances of the gun, created a new layer and moved the gun to that layer which partly fixed the issue. It no longer clips through the walls.
But now the problem is that the gun is made up of multiple materials and the rendering order of these materials is messed up now.
How the gun should look:
How it looks after fixing the clipping:
I couldn’t figure out a way to fix this issue. What would be the best way to solve this?
this is what the rendering should look like with this:
renders the world - this writes world z values to depth buffer
starts rendering your weapon later … clear existing depth buffer
render the weapon mesh, and it should not be clipped against the world as the depth buffer is empty
to check what it does, try settings this to true anywhere in a script at start up app.scene.layers.logRenderActions = true;
this will log the order of rendering into browser console.
and then check the results - it should render in the order as I described and clear depth buffer. Post the section of the log.