I am having trouble retaining the position of a sub node removed and added to the rootNode. Both the parent node and sub node have a pivot translation, which I think is part of the problem. I have tried setting the transform property to the worldtransform property, then removing and reattaching the node to the root. But the position moves slightly. I have tried removing the pivot transform, getting the worldtransform adding to the root node and restoring the pivot. Sometimes I think I've resolved it, then a particular node will jump when reattached as a root node.
我无法保留已删除的子节点的位置并添加到rootNode。父节点和子节点都有一个数据透视转换,我认为这是问题的一部分。我已经尝试将transform属性设置为worldtransform属性,然后删除并重新连接到根节点。但该立场略有变动。我尝试删除数据转换,将worldtransform添加到根节点并恢复数据透视。有时我认为我已经解决了它,然后当一个特定节点作为根节点重新连接时会跳转。
It seems the pivot of the sub node and parent node influences the worldtransform. So taking the parent node out of the equation seems to shift the final position.
似乎子节点和父节点的枢轴影响了世界变换。因此,将父节点排除在等式之外似乎会改变最终位置。
Is there a method to adding a sub node to the root node, while maintaining its physical position/rotation.
是否有方法将子节点添加到根节点,同时保持其物理位置/旋转。
Any pointers would be appreciated.
任何指针将不胜感激。
2 个解决方案
#1
there is not API to do that. But SceneKit exposes conversion utilities such as -[SCNNode convertTransform:toNode:]
and -[SCNNode convertPosition:toNode:]
.
没有API可以做到这一点。但SceneKit公开转换实用程序,如 - [SCNNode convertTransform:toNode:]和 - [SCNNode convertPosition:toNode:]。
The following is probably what you want:
以下可能是您想要的:
node.transform = [node.parentNode convertTranform:node.transform toNode:nil];
[node removeFromParentNode];
[scene.rootNode addChildNode:node];
#2
I also don't get why worldTransforms or worldPosition incorporates the pivot which is kind of insider info to the node.
我也不明白为什么worldTransforms或worldPosition合并了枢轴,这是一种内部信息到节点。
Anyway, my solution:
无论如何,我的解决方案:
MoveNode.transform = [newParentNode convertTransform:MoveNode.transform fromNode:[MoveNode parentNode]];
#1
there is not API to do that. But SceneKit exposes conversion utilities such as -[SCNNode convertTransform:toNode:]
and -[SCNNode convertPosition:toNode:]
.
没有API可以做到这一点。但SceneKit公开转换实用程序,如 - [SCNNode convertTransform:toNode:]和 - [SCNNode convertPosition:toNode:]。
The following is probably what you want:
以下可能是您想要的:
node.transform = [node.parentNode convertTranform:node.transform toNode:nil];
[node removeFromParentNode];
[scene.rootNode addChildNode:node];
#2
I also don't get why worldTransforms or worldPosition incorporates the pivot which is kind of insider info to the node.
我也不明白为什么worldTransforms或worldPosition合并了枢轴,这是一种内部信息到节点。
Anyway, my solution:
无论如何,我的解决方案:
MoveNode.transform = [newParentNode convertTransform:MoveNode.transform fromNode:[MoveNode parentNode]];