Jump to content

Mesh clone and BackFace culling

Jose Vicente

Recommended Posts


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

Link to comment
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 !

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...