Skip to content

How To Properly Apply Matrix Of Node When Moving To Another Parent Node #1329

Closed Answered by Jonathynlee
Jonathynlee asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone that happens upon this post.

The answer was to multiply the movedNode.getWorldMatrix() multiplied by inv(newParentNode.getWorldMatrix())

import {mat4} from "gl-matrix"
(newParentNode)=>{ // parent node is within the hierarchy somewhere  
let parentInvOfWorldMat:mat4 = newParentNode.getWorldMatrix(); 
glMatrix.mat4.invert(parentInvOfWorldMat,parentInvOfWorldMat);


const originalNode:Node = refToOriginalNode // Original node is within the hierarchy somewhere else   
let newMatrix = originalNode.getWorldMatrix();
mat4.multiply(newMatrix, parentInvOfWorldMat, newMatrix);

const newNode:Node = document.createNode().copy(originalNode, resolve);   
newNode.setMatrix(newMatrix);   
ne…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Jonathynlee
Comment options

@donmccurdy
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@donmccurdy
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Jonathynlee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants