Objects coordinates are changed on save. Reproduced in my Project and Sandbox

Summary:

  1. I have a gltf.
  2. I load the gltf.
    Object BoundingBox is
e {x: -0.11130329966545105, y: -0.3582372907549144, z: -0.29034799337387096}
e {x: 0.2866967022418976, y: 0.39776269160211086, z: 0.26465200021630164}
  1. I save the gltf
  2. I load the gltf again.
    Object BB is
e {x: -0.11130329966545105, y: -0.3582372907549144, z: -0.26465200021630164}
e {x: 0.2866967022418976, y: 0.39776269160211086, z: 0.29034799337387096}

Result - objects have different location for the Z. And they are flipped. I can not

Details.

  1. I can not share the gltf currently since it is not my property, but i am trying to reduce it.
  2. I load the gltf with
 loader.Load(baseUrl, file, engine, scene => {

After loading this is the scene

I am debugging the scene with

scene.getNodes().forEach((node) => {
    console.log(node.name)
    console.log(node.getHierarchyBoundingVectors().min)
    console.log(node.getHierarchyBoundingVectors().max)
})

And first object on the scene is

12412602846168467473
e {x: -0.11130329966545105, y: -0.3582372907549144, z: -0.29034799337387096}
e {x: 0.2866967022418976, y: 0.39776269160211086, z: 0.26465200021630164}
  1. I save the gltf with
let options = {
        shouldExportNode: function(/** @type {BABYLON.Node} */ transformNode) {
          if (/light1/.test(transformNode.name) || /light2/.test(transformNode.name)) {
            return false;
          }
          return true;
        }
      };
      BABYLON.GLTF2Export.GLBAsync(this._babylonScene, "scene.glb", options).then(response => {
        response.downloadFiles();
      });
  1. I load the gltf again. This time the scene is:


First node has

12412602846168467473
e {x: -0.11130329966545105, y: -0.3582372907549144, z: -0.26465200021630164}
e {x: 0.2866967022418976, y: 0.39776269160211086, z: 0.29034799337387096}

I decided to load and save with sandbox.babylonjs.com

I am loading my file, then saving the and coordinates flip

Here is initially loaded

Screenshot from 2020-02-05 17-28-42

Here is loaded after the event.

Screenshot from 2020-02-05 17-30-28

What could I do

Adding @Drigax to double check.

@bghgary and I had a pretty intensive debugging session yesterday regarding this.

It seems that we arent properly preserving the coordinate space on export when converting between the left handed coordinate system of Babylon and the Right handed coordinate system of glTF.

You can test this by setting your scene to use right handed coordinates before initialization, the resulting round-tripped scene should be properly perserved, as we don’t do a bunch of coordinate system flips and random rotations for every object in scene to get the resulting scene to look “right”. This is my current understanding of the issue, but I’m in the middle of addressing it now.

3 Likes

Thanks.

  1. Something I could help with?
  2. A way to workaround it for the time being?

Can you test my assumption that the bounding boxes are preserved if you set Scene.useRightHandedSystem = true in your scene (and possibly move/reorient your object in scene to reflect this change)?

Also any debugging Playgrounds would be really valuable for me, I want to minimize any regressions since I expect to change a good amount of our transformations when exporting to glTF

Yes. It solved my issue for this element.

I used

  1. Load
  2. scene.useRightHandedSystem = true
  3. Save
  4. Load again and it is Ok.
1 Like

@drigax Do you have an update here? Should I continue using scene.useRightHandedSystem and rely on it?

No changes yet. Still working on this.

@kmitov I checked in a fix yesterday that should fix this for left handed scenes. Can you verify if the fix worked?

It seems to be working now. Thanks. I was able to load, save and load again and

<script src="https://preview.babylonjs.com/babylon.js"></script>
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>

I think it would be nice if there is a date or last commit in the top of “https://preview.babylonjs.com/babylon.js” to know if it includes the request in question. Because there might be a cached version in browser or in a server and it is difficult to confirm with certainty.

You can see the version manually at runtime via:

ThinEngine.version

Also, the console prints the current babylon.js version as well. The current hosted preview script appears to be version: babylonjs@4.1.0-beta.27

But I’m not sure what the release cadence is currently. @Deltakosh, how often do we increment beta versions?

1 Like

daily until tomorrow

Tomorrow it will be our first RC

No I can’t

ThinEngine.version
VM642:1 Uncaught ReferenceError: ThinEngine is not defined
    at <anonymous>:1:1
(anonymous) @ VM642:1

Also does this mean that I was not able to test with a version that contained your fix? Because I did the same thing as mentioned in the beginning of the thread, but today it worked.

Sorry @kmitov , I forgot that the Babylon classes are scoped under the BABYLON namespace.

Try BABYLON.ThinEngine.Version:
https://www.babylonjs-playground.com/#XCPP9Y#1735

Since the fix was checked in Tuesday, the preview script should contain the fix now.

Looks like the change has been in since beta.25:

2 Likes

Ok. The version is “4.1.0-beta.27” so at least I know it is working because of the fix.

2 Likes