removed unnecessary extra SCNNodes during loading #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During the loading from
glb
intoScenekit
there are excess nodes being added to the SceneKit hierarchy that don't exist in theglb
file. This is a major problem for anyone working with models where you need to target specific children using their names.Within
loadNode
andloadMesh
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 usenode.childNodes.firstChild.geometry
instead ofnode.geometry
.In my proposed update:
I updated
loadNode
to get rid of the extra node, changingscnNode
from alet
to avar
and then instead of creating a new node withmeshNode
I set the return fromloadMesh
directly toscnNode
I remove
primitiveNode
entirely fromloadMesh
and instead assign everything that was assigned toprimitiveNode
tonode
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.