diff --git a/src/engine/components/index.js b/src/engine/components/index.js index 3adbd6c..c2eba73 100644 --- a/src/engine/components/index.js +++ b/src/engine/components/index.js @@ -64,9 +64,6 @@ class Node { // Set translation mat4.translate(matrix, matrix, this.pos) - // Set scale - mat4.scale(matrix, matrix, this.scale) - // Set rotation if (this.rotation[0] !== 0) { mat4.rotateX(matrix, matrix, this.rotation[0]) @@ -80,9 +77,12 @@ class Node { mat4.rotateZ(matrix, matrix, this.rotation[2]) } + // Set scale + mat4.scale(matrix, matrix, this.scale) + // Add parent node's transform if (this.parent) { - mat4.add(matrix, this.parent.transform, matrix) + mat4.mul(matrix, this.parent.transform, matrix) } // Set the matrix @@ -102,6 +102,8 @@ class Node { let rotation = vec3.create() let scale = vec3.create() + mat4.transpose(transform, transform) + mat4.getTranslation(translation, transform) mat4.getScaling(scale, transform) mat4.getRotation(quaternion, transform) @@ -325,7 +327,7 @@ class MeshInstance extends Node { // Invoke children's draw methods for (let i in this.children) { let child = this.children[i] - if (!(child instanceof Mesh)) continue + if (!(child instanceof MeshInstance)) continue child.draw(gl, shader) } }