pex-renderer
pex-renderer copied to clipboard
Avoid creating parent stack in transform
The following piece of code with array cration in a loop via unshift an for each function could be replaced with a for loop and new mat4.premultiply function
mat4.identity(this.modelMatrix)
var parents = []
var parent = this
while (parent) {
parents.unshift(parent) // TODO: GC
parent = parent.parent
}
parents.forEach((p) => { // TODO: forEach
mat4.mult(this.modelMatrix, p.localModelMatrix)
})
Couldn't we just multiply the local matrix by the parent modelMatrix? Effectively traversing the children instead of the parents?