Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the double __root__ issue for glb #7257

Closed
wants to merge 1 commit into from
Closed

Fix the double __root__ issue for glb #7257

wants to merge 1 commit into from

Conversation

Bloadrick
Copy link
Contributor

Fix for the the double root issue: #6349

@Bloadrick Bloadrick changed the title fix the double __root__ issue Fix the double __root__ issue for glb Dec 3, 2019
var scene = this._gltf.scenes[indexScene];

// Root node must be unique
if (scene.nodes.length != 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (scene.nodes.length != 1) {
if (scene.nodes.length !== 1) {

if (scene.nodes.length != 1) {
return null;
}
else if(this._gltf.nodes != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if(this._gltf.nodes != null) {
else if(this._gltf.nodes !== null) {

var root = this._gltf.nodes[indexRoot];

// Check rotation and scale
if(root.rotation != undefined && root.scale != undefined){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok...stopping here but please fix all triple equals ;)

}

// Check name
if (root.name != "__root__") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we want to check this one. As long as we have the correct transforms we are fine

if (root.name != "__root__") {
return null;
}
}else{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces


private _createRootNode(nodes : INode[]): INode {

var ExistingRootNode = this._checkForRootNode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no capital first letter


var ExistingRootNode = this._checkForRootNode();
var RootAlreadyImplemented = false;
var INodeToReturn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a type

@bghgary
Copy link
Contributor

bghgary commented Dec 3, 2019

This change is not in the right place. The double root should be removed on export and not on import.

@deltakosh
Copy link
Contributor

Ok I was under the same impression

Closing this PR then

@deltakosh deltakosh closed this Dec 3, 2019
@Bloadrick
Copy link
Contributor Author

Hi, I think we are both right here after thinking about it again.

So 3ds max and maya are right handed, they export in Babylon which is left handed, no root here, we are changing the geometry and the transform.
Then if we export in GLTF we are doing the same operation between Babylon and GLTF.

Current state:

After that if we put a GLTF in the sandbox we need to add a root to put it in left handed coordinates.
For the moment when exporting to GLB we keep the root added previously without adding an other one.
Then if we put this glb in the sandbox, it adds another root which is not needed (that's where I got confused for this issue).

What to do:

When we export in GLB from the sandbox we need to delete that root to keep it right handed.
I think what I did is still usefull for legacy purpose, if a glb has been exported with multiple root it would accept it and format it in the right coordinates.

If you are ok with that I can add the delete of the root node on export and keep this PR with the changes asked implemented.
It would prevent the multiple roots and keep it to one when a GLTF/GLB is loaded.

@deltakosh deltakosh reopened this Dec 4, 2019
@deltakosh deltakosh closed this Dec 4, 2019
@deltakosh
Copy link
Contributor

I agree we should not add a root node if not necessary. But I struggle to convince myself that we will have the cae. When will this happen if we fix the serializer?

@Bloadrick
Copy link
Contributor Author

If a GLB has already been exported, in my test files some of them have up to 4 or 5 root nodes.
I was thinking about someone who already used it and have already a root node in his GLB if not checked in the loader it is going to add a second one.

@deltakosh
Copy link
Contributor

Ok that makes to me
@bghgary ?

@bghgary
Copy link
Contributor

bghgary commented Dec 4, 2019

I don't think the loader should do anything different.

The loader must do something in order to convert the data from right-handed (glTF) to left-handed (Babylon assuming useRightHandedSystem is false). I don't think the loader should muck with the hierarchy of the glTF itself.

If the existing glTF already has a bunch of unnecessary root nodes, then it should be up to the author of the glTF to fix the problem. The main fix is to make sure the exporter does not perpetuate the issue.

@deltakosh
Copy link
Contributor

Yeah you are right. We always have to switch to left...so yeah we only need the serializer part :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants