Permanently change set of axes

Maybe I’m missing something from skimming this thread. Why are axes being swapped when switching handness? That seems a bit arbitrary.

As far as I can tell, STL doesn’t specify any conventions. We can maybe add a flag for common ways to handle the conventions, but using scene.useRightHandedSystem seems a bit odd to me.

Note: OBJ specifies that the XYZ are right-handed but it doesn’t mention which axis is up.

Yup, I knew we needed @bghgary knowledge on this one :slight_smile: @AlbertoPa would you mind adding a flag to change it as we do in obj so that users can control it instead ?

What is the flag used in OBJ?

@bghgary To clarify, my proposed patch reverts a change to the coordinates forced by babylon to enforce y as the upward direction, which introduces an inconsistency between the input file and the visualization. As you said the STL format does not impose an upward direction (it does define the right-hand rule needs to be used to define normals only), so it is unclear to me why a change is applied in the first place. Why not just acquire coordinates as they are (note: discussed previously in this thread, but no consensus found :slight_smile: )? On the other hand, it would be a breaking change compared to the current behavior.

I was thinking a static property like one of those in the objLoader: Babylon.js/objFileLoader.ts at master · BabylonJS/Babylon.js · GitHub

So ppl can opt in if they want.

Let s see what you agree on with @bghgary on the STL format front.

Since the format doesn’t specify, there isn’t really a right answer. It completely depends on the software writing it out. Whoever wrote the original reader is assuming one particular convention which may be right for some scenarios but not for others. A flag to change the conventions used seems the most reasonable IMO and will make it possible to change the conventions while maintaining backwards compatibility.

1 Like

I’m fine with an additional flag. It was suggested to use “useOriginalCoordinates” in a previous comment. Would that work?

Also, do other loaders (and serializers) need to be updated, so that their behavior is consistent when the flag is used? I have no experience with Babylon serializers so far :sweat_smile:

I would expect the flag to be STL specific.

2 Likes

Sounds good. I will make the change and share. Thanks!

2 Likes

I pushed the change here:

Note: I have not implemented MeshLoadOptions, currentMeshLoadOptions, etc. because I am not sure if it is required. Let me know and I’ll look into it if needed.

I think it is fine but let s pit the default value to how it worked before to prevent breaking changes. You could open a PR for it this might be the simpest :slight_smile:

Yes, the default is false, so the old behavior is preserved and the new behavior is used when the flag is set to true.

Ok. I’ll open a PR. Let me read the rules first, it’s my first PR to Babylon :sweat_smile:.

Congrats, you basically need:

  1. the code
  2. an update to the what s new.md in the preview release folder
  3. an update to the documentation site with a PR to talk about the new feature :slight_smile:
1 Like

Thanks for the help!

PR is here: Added DO_NOT_ALTER_FILE_COORDINATES to STLFileLoader. by AlbertoPa · Pull Request #10553 · BabylonJS/Babylon.js · GitHub
Doc PR: Document DO_NOT_ALTER_FILE_COORDINATES in STL file loader by AlbertoPa · Pull Request #268 · BabylonJS/Documentation · GitHub

1 Like

All merged and it will be in the next nightly later today.

Thanks a ton !!! and Congrats on the first PRs !

2 Likes

Thank you!

Hi everyone,
very nice to see, that there finally is a flag to disable this flipping Y/Z values behavior.
However, i noticed that when I import a mesh like this:
data_formteil_1.zip (44.1 KB)
And enable STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES and use scene.useRightHandedSystem it looks like the faces are oriented the wrong way.

I tried out a few things and when i explicitly flip the Y and Z indices after the import like this:

    // Interchange indices so the faces are oriented correctly
    const indices = mesh.getIndices();

    if (indices !== null) {
        const numberOfIndices = indices.length / 3;

        for (let i = 0; i < numberOfIndices; i++) {

            const currentY = indices[i * 3 + 1];
            const currentZ = indices[i * 3 + 2];

            indices[i * 3 + 1] = currentZ;
            indices[i * 3 + 2] = currentY;
        }

        mesh.setIndices(indices)
    }
    else {
        console.warn("indices are null!")
    }

… the mesh is shown correctly again:

Do you understand what’s going wrong here?
Is this a problem with the STL file or BabylonJS/ the way how i use it?

Edit: I just checked the STL file with Rhino and the mesh normals are all oriented correctly. So there might by some error during the import? @AlbertoPa @sebavan

@bghgary do you know what the issue could be with STL ? or should we flip smthg in the loader to support right handed ?

1 Like

The STL loader probably doesn’t take scene.useRightHandedSystem into account.

@major-mayer can you repro in the playground with Using External Assets In the Playground | Babylon.js Documentation ?

I am happy to fix it as soon as we have a playground setup :slight_smile:

Here you go: Babylon.js Playground