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

Extra Nodes get Created per object in a glb #9

Open
johanos opened this issue Dec 6, 2017 · 6 comments
Open

Extra Nodes get Created per object in a glb #9

johanos opened this issue Dec 6, 2017 · 6 comments

Comments

@johanos
Copy link

johanos commented Dec 6, 2017

image

When models are getting imported their hierarchy is getting created like above.
where the water bottle only defines one submesh called water bottle
image
So instead of loading the gltf like we do know.

WaterBottle
    -WaterBottleEmptyNode
        -WaterBottleMesh

we should do this

WaterBottle
    -WaterBottleMesh

because to access the materials of these nodes, we right now have to do something like

node.childNodes[0].childNodes[0].geometry?.firstMaterial

@magicien
Copy link
Owner

magicien commented Dec 7, 2017

I mapped each node/mesh/primitive onto SCNNode, so WaterBottleEmptyNode is mapped onto mesh.
Actually, mesh SCNNode doesn't have any 3D data. It has only 'name'.
It's possible to omit mesh nodes, but it could be confusing if child nodes and primitive nodes are in the same layer.

How do you think?

@johanos
Copy link
Author

johanos commented Dec 8, 2017

What do you mean exactly?

From what I understand the primitives are part of the mesh object. which point to indices and materials. but mesh[0] defines a mesh with geometry and materials. so I see it more confusing to interpret that as

WaterBottle                     -- start of gltf asset
    -WaterBottleEmptyNode       -- mesh[0] object, but its an empty container
        -WaterBottleMesh        -- primitives of mesh[0], contains Normal, UV, Position, Tangent info

than

WaterBottle                      -- start of gltf asset
    -WaterBottleMesh             -- mesh[0] object, + primitives: UV, Normal, Position, Tangent info.

SCNNode is capable of having the format be this way and it would be less confusing to work with the nodes this way

here's a screenshot of the babylon js inspector ( __root would be what we are calling WaterBottle) and then the only child node is WaterBottle.

image

edit: and the child nodes of these meshes could just be children of the base mesh

WaterBottle                      -- start of gltf asset
    -WaterBottleMesh             -- mesh[0] object, + primitives: UV, Normal, Position, Tangent info.
        -WaterBottleChild1
    -WaterBottleSiblingNode

@magicien
Copy link
Owner

magicien commented Dec 12, 2017

Thank you for your explanation!

Current mapping between glTF and SceneKit looks like this:
gltf_scenekit_map_current

I don't think I can change the mapping into this way because SCNNode can have only one geometry. I'm not sure, but I think if SCNGeometry has 2 or more vertex SCNGeometrySources, SceneKit will use only the first source.
gltf_scenekit_map_new_1

This is possible, but I'm worried about putting primitives and children nodes in the same layer could be confusing.
gltf_scenekit_map_new_2

@ryancrunchi
Copy link

This should be in the readme as technical documentation.

@digitallysavvy
Copy link

digitallysavvy commented Aug 8, 2019

Bump on this issue because I ran into problems with the node hierarchy.

The issue with the extra nodes is the duplication of names and it forces the developer to write a nasty work-around.

The issue really becomes apparent when you use the childNodeWithName because the method returns the first instance of a node with this name, but with the given hierarchy that node is not the one I'm looking for but instead an arbitrary parent. To get the node I am looking for I then have to call childNodeWithName again and then use childNodes.first to get the node with the geometry I wish to affect.

This is a headache for anyone trying to do anything as simple as change a material.

I have opened a PR (#37) that addresses this issue.

@magicien I know you have some reservations about changing this structure so I'd like to find a resolution that works for all because as the current version stands this is a major hinderance to simple traversals for named nodes.

@digitallysavvy
Copy link

Given its been almost a year since this issue has been opened without much response from @magicien ... whomever else is running into this issue, please check out my fork. I fixed the node structure issue. In the fork below, the scene graph in SceneKit is a 1:1 match of the structure of the GLB and doesn't distort the scene hierarchy with arbitrary nodes in the way this library does.

https://github.com/digitallysavvy/GLTFSceneKit

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

No branches or pull requests

4 participants