Mesh.createInstance doesn’t set the instance parent to the base mesh. The instances made with Mesh.createThinInstance don’t have parent mesh, but the given instance’s matrix is applied after the base mesh’s world matrix when rendered, so you need to multiply the thin instance matrix by the inverse of the base’s world matrix to get it into the same position as a non-thin instance.
I tried Mesh.flipFaces() and that worked for all the instances except the one added with thinInstanceAddSelf, so no I can’t think of a way to cover the edge cases, yet.
There’s a problem because the instances have a world matrix determinant > 0 whereas the world matrix of the base mesh has a determinant < 0 (because of the -Z scaling on its parent). See:
It will work if you parent your instances to the same parent than the base mesh because they will all have the same sign for their determinant:
@Evgeni_Popov
Then how would I make it work for a setup like this?
I was trying to do what you said but no matter what combination of parents I tried to set things to it still left the faces inverted.
This would be a real world example of when I want to do this. The artist has a bunch of negative scaling to reflect the one side of the scenes models to the other. I need to make sure that no matter what the structure is that the glb is in that I can run this process on it.
You will need to loop over all the instances, and sort them according to their world matrix determinant: the negative ones and the positive ones.
If you only have negative or positive instances, then no changes. If you have both, you will have to create an additional base mesh and assign all the negative instances to one base mesh and all the positive to the other. You will also have to clone the material, reverse the sideOrientation property and assign this material to the second base mesh.
Sorry that Im dense af… but following your instructions I can not for the life of me get it to work.
I iterated through all the instances identified if they are negative or positive got two separate lists of them, made a new object with a material that has the inverted prop and assigned them.
Oddly enough as well, if I just do mapping.baseMesh.clone() the object does not get cloned into the scene? So I had to search for the mesh which Im not too sure why that is?
this is just being applied to the brick ground area now.
If you fly under the stage and look up you will see that the inversed Thin instance is there.
The two objects are “CapitolTile.001_skiplm” and “Inverted:CapitolTile.001_skiplm” now.
Changing the material side orientation is seeming to do nothing, the only way I can get it to appear is telling it backfaceCulling = false which does not seem correct.
The main problem was that the glTF loader sets the mesh.overrideMaterialSideOrientation property, which takes precedence over the material.sideOrientation property, meaning the new material side orientation was not taken into account.