-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add spliceNode function to reparent an entire scene or subtree #1536
base: main
Are you sure you want to change the base?
Conversation
I'm not sure about the API. In particular, the
but then it's not clear what to do if Also not totally happy with the name of this function. |
It's OK for the function to create a node, I think, as long as the naming is consistent with that expectation. Calling the glTF-Transform/packages/functions/src/list-texture-slots.ts Lines 13 to 16 in 1693ffd
I'd like to make that more obvious at some point, but in the meantime this avoids requiring users to pass in a That said, having the user pass in both nodes would sound OK to me too. |
export function spliceNode(parent: Scene | Node): Node { | ||
const newNode = new Node(parent.getGraph()); | ||
for (const child of parent.listChildren()) { | ||
if (child.getSkin()) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about my recommendation from #1530 (comment) here, and unfortunately it's not as simple as I'd been hoping.
- As mentioned, we will get validation warnings if we put a parent above a skinned mesh. Technically it's valid, these are just 'hints' or 'warnings' at the validator level, because the transform won't do anything to the skinned mesh directly, transforms affect only the joints.
- However, it's possible that the skinned mesh's joints are descendants of the node. In that case, skipping the skinned mesh will cause the transform to not affect the joints as expected, and thus not to affect the skinned mesh.
Probably (2) is the more critical error, as it will change the rendered result.
We could search the child's subtree for any joints, and skip the skinned mesh only if no joints are found. But this might be a more complex and less predictable operation than users are expecting, calling a method like 'spliceNode'. If we skip that special case, then the method body becomes something more like:
const node = Document.fromGraph(parent.getGraph()).createNode();
for (const child of parent.listChildren()) {
node.addChild(child);
}
parent.addChild(newNode);
Here are some passing notes about how I was confused. I'm sure more hacking on this will clear things up:
|
This is inspired by #1530 (comment). In particular, instead of a
transformScene
function, this creates a newNode
to which you can apply transforms.