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

removed unnecessary extra SCNNodes during loading #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

digitallysavvy
Copy link

During the loading from glb into Scenekit there are excess nodes being added to the SceneKit hierarchy that don't exist in the glb file. This is a major problem for anyone working with models where you need to target specific children using their names.

Within loadNode and loadMesh there are arbitrary nodes added to the hierarchy which cause there to be duplicate nodes with the same name causing issues with using functions that traverse the scene graph.

For example rootNode.childNode(withName: _) returns the parent to the node you actually are looking for. To work around this distorted hierarchy you have to call the method twice first to get the arbitrary parent and then again on this parent to find the child node you actually want. Or when attempting to set the material on a node that should have geometry you have to use node.childNodes.firstChild.geometry instead of node.geometry.

In my proposed update:

  1. I updated loadNode to get rid of the extra node, changing scnNode from a let to a var and then instead of creating a new node with meshNode I set the return from loadMesh directly to scnNode

  2. I remove primitiveNode entirely from loadMesh and instead assign everything that was assigned to primitiveNode to node

Upon testing it reduces the number of arbitrary parents. For example when querying for a specific node using .childNode(withName: _), the first result is the correct node we want, no longer do we have to search the first result for a child with the same name. Also this solution allows for updating materials without having to get the first child node to find the geometry of the named node.

Note: This is a breaking change for anyone that has written work arounds, but this properly passes the glb hierarchy to the SCN.

@magicien
Copy link
Owner

I need to look into it but it seems not working with rigged models like this
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/CesiumMan

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.

2 participants