pex-renderer icon indicating copy to clipboard operation
pex-renderer copied to clipboard

Confusion between transform.matrix and transform.position/rotation/scale

Open dmnsgn opened this issue 6 years ago • 5 comments

Currently a transform component is the combination of position/rotation/scale multiplied by matrix if it exists.

Any reason to store this extra matrix component (or vice-versa position/rotation/scale)? The orbiter doesn't account for it. As a result, it is not possible to have only transform.matrix to define an object transformation (eg. a camera) and update it with an orbiter.

Nowhere in pex-renderer codebase the transform.matrix is used if I am correct.

dmnsgn avatar Apr 25 '19 16:04 dmnsgn

Its required for gltf compatibility. We might try matrix decomposition but i had some problems with that in the past.

Are gltf cameras transforms matrices?

vorg avatar Apr 25 '19 17:04 vorg

glTF cameras are nodes like any other, so they can have either translation/rotation/scale or matrix.

I'd be more inclined to have only one set of local transformation information per transform but you're saying the following can cause issues?

const transform = node.matrix
    ? {
      position: [
        node.matrix[12],
        node.matrix[13],
        node.matrix[14]
      ],
      rotation: quat.fromMat4(quat.create(), node.matrix),
      scale: [
        Math.hypot(node.matrix[0], node.matrix[1], node.matrix[2]),
        Math.hypot(node.matrix[4], node.matrix[5], node.matrix[6]),
        Math.hypot(node.matrix[8], node.matrix[9], node.matrix[10])
      ]
    }
    : {
      position: node.translation || [0, 0, 0],
      rotation: node.rotation || [0, 0, 0, 1],
      scale: node.scale || [1, 1, 1]
    }

dmnsgn avatar Apr 26 '19 08:04 dmnsgn

Seems like the glTF2.0 Spec mandates that decomposition is always possible.

Matrices must be decomposable to TRS. This implies that transformation matrices cannot skew or shear.

@damien For the record: where is your code from?

Todo:

  • [ ] implement above change and remove node.matrix
  • [x] check glTF examples

vorg avatar Sep 09 '19 08:09 vorg

Our source: https://github.com/pex-gl/pex-renderer/blob/master/loaders/glTF.js#L529 Reference from: https://github.com/KhronosGroup/glTF-Sample-Viewer/blob/master/src/node.js#L58

Important fix they did: https://github.com/KhronosGroup/glTF-Sample-Viewer/commit/89045ce125d989f55c21a69a06e987730745b3fa

dmnsgn avatar Sep 09 '19 09:09 dmnsgn

Does it mean it's already implemented?

vorg avatar Sep 09 '19 10:09 vorg