Flipped faces when manually cloning gltf vertexdata

Hello there!
Got a weird issue that I can’t make sense of. I need to clone a fairly large mesh across scenes which isn’t supported by the standard mesh cloning operations. I only need the mesh geo in the second scene, so to work around this, I’m trying to clone a mesh by manually extracting and then applying the VertexData.

This works fine except on GLTF models. When manually inspecting the vertex data after the clone, everything(indices, positions, normals, etc) seems to be identical, as expected, but for whatever reason, the rendered object has flipped faces and an offset origin.

Playground Repro: https://playground.babylonjs.com/#S66FLG

Gives expected Result:

const sphere = MeshBuilder.CreateSphere("sphere");
const vertexData = VertexData.ExtractFromMesh(sphere);
vertexData.applyToMesh(new Mesh("clone"));

Gives broken Result:

const gltfModel = SceneLoader.ImportMesh(...)
const vertexData = VertexData.ExtractFromMesh(gltfModel);
vertexData.applyToMesh(new Mesh("clone"));

  • Blue: Original GLTF Import
  • Red: Extract > Apply of Blue^
    • This is the primary problem example. Inverted faces. Offset Position.
  • Purple: Extract > Apply > mesh.flipFaces()
  • Yellow: MeshBuilder.CreateSphere()
  • Green: Extract > Apply of Yellow^

Showing Normals:

Hi @jdup and welcome to the forum !

Do you clone the material as well? Might be related to different back face culling property.

Welcome aboard!

What you are missing is the Mesh.overrideMaterialSideOrientation property that the glTF loader is setting at load time. You should copy this value from gltfOriginal to gltfClone:

2 Likes

ugh! I overlooked looked that - thanks!

Any idea on the position change? I’m not seeing that with my assets, however the inconsistency makes me nervous about some future model having this issue.

Currently, only the glTF loader is using this property AFAIK. But it’s safe to copy it even if it is undefined, so you can in all cases simply copy the property from the source object to the destination.