Jose Vicente

Mesh clone and BackFace culling

Recommended Posts

Hello.

I'm having a problem mixing BackFace culling and mesh cloning.

I generate meshes from a server code, and because of my coordinate system (which I can't change) the triangles are not property oriented. This is fixed used instances with a negative scaling and this works.

At some point, after user action, I clone one of the the meshes which has wrong triangles, and then I apply the same transformation that fixes the orientation for the instanced meshes, but the cloned mesh triangles are not property orientated and thus the cloned mesh is not visible.  This code worked for me on Babylon 2.5.

This can be checked here : https://playground.babylonjs.com/indexStable.html#VI428J#3

Mesh named 'test' is not visible because triangles are not property orientated -> OK

Instanced mesh 'testI' is visible because the scaling fixes the orientation -> OK

Cloned Mesh is not visible and I don't know why.

If  backface culling  is disabled, all three meshes are visible.

Any ideas ?

Thanks in advance

Share this post


Link to post
Share on other sites

Hello Jose Vicente !

I don't know why your code doesn't have the expected behaviour.

BUT, to deal with your face orientation issue, I think you should use the flipFaces method on your mesh.

Here is a PG :  https://playground.babylonjs.com/indexStable.html#VI428J#4

Because cloned mesh uses the same vertexData as the "original" mesh it has been cloned from, flipping the faces of the clone will flip the faces of the original mesh as well. The same thing apply for the instanced mesh.
To change the orientation of the cloned mesh only, you should try to use makeGeometryUnique on it to un-link its vertexData and the vertexData of the original mesh.. but it will loose the interest of cloning.
You can comment line 42 to see this behaviour

To apply a change (scaling, rotation or position) in the vertexData directly, then you can use bakeCurrentTransformIntoVertices. Keep in mind that if you call this method on a mesh, all the meshes sharing its geometry (instances and clones) will also be affected.

Hope it will help !
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.