Why does model scaling cause image flipping

My code is as follows:
var knot01 = BABYLON.SceneLoader.ImportMesh("", “model/glTF2.0/”, “jc.glb”, scene, function (newMeshes) { // Set the target of the camera to the first imported mesh
for (let i = 0; i < newMeshes.length; i++) {
newMeshes[i].scaling = new BABYLON.Vector3(10, 10, 10)

Why does model scaling cause image flipping

Off-hand, I’d hazard a guess that the GLB is using a right-handed coordinate and/or has inverted axis. Negative scale factors will cause image reversal like this, and since your scaling is positive, a likely explanation is that the model’s coordinate system isn’t aligned with BabylonJS



I cannot confirm this without playground repro to test it out. But gltf/glb files come with the root node, which is a parent node of all meshes in the scene, and this node is classified as a “mesh”. So when you call newMeshes[i].scaling the newMeshes[0] is most likely root node. Basically, when you export mesh from 3D software, its coordinate system usually does not match the webgl standards, so root node is added during export to “fix” that issue. My guess is that by default scaling of the root node contains negative values, so something like (-1,1,1), and when you iterate through meshes and scale them, you assign them new values (10, 10, 10), and that negative value basically flips.

So some thoughts that you can consider is:

  1. Ignore root during scaling, and scale everything else.
  2. Figure out the scaling of root and consider those values when you scaling.

You can also use the scaleInPlace operation, newMeshes[i].scaling.scaleInPlace(10), I think it should work.

1 Like

Yes,You’re right,I use a right-handed coordinate, My GLB model is exported in 3DMAX

Yup this is exactly as stated above, the -1 required to handled handedness needs to stay in the scale, so you might be better using the scaling functions instead of assigning a new value :slight_smile:

Thanks, using the scaleInPlace operation is OK. but ,If I just want to scale in the Y direction,What should I do

Just access to the Y axys :slight_smile: newMeshes[i].scaling.y *= 10;