src/object3d/context/matrix.js
/**
 * The Object3DMatrixContext component maps input position, rotation, and scale
 * arguments into a matrix and transform context variables. Default values are
 * used if not provided as input arguments to this component function.
 *
 * Object3DMatrixContext(ctx) -> ScopedContext(ctx) -> (args, scope) -> Any
 *
 * @public
 * @param {Context} ctx
 * @param {?(Object} [initialState = {}]
 * @return {Function}
 * @throws BadArgumentError
 * @throws MissingContextError
 */
The Object3DMatrixContext component maps input position, rotation, and scale
arguments into a matrix and transform context variables. Default values are
used if not provided as input arguments to this component function.

> ScopedContext(ctx) -> (args, scope) -> Any


The Object3DMatrixContext component maps input position rotation and scale arguments into a matrix and transform context variables . Default values are used if not provided as input arguments to this component function . > ScopedContext ( ctx ) - > ( args scope ) - > Any
function Object3DMatrixContext(ctx, initialState = {}) {
  assertComponentArguments('Object3DMatrixContext', ctx, initialState)
  const transformMatrix = mat4.identity(new Float32Array(16))
  const localMatrix = mat4.identity(new Float32Array(16))
  return ScopedContext(ctx, initialState, {
    matrix(ctx, args) {
      const position = pick('position', [args, initialState, defaults])
      const rotation = pick('rotation', [args, initialState, defaults])
      const scale = normalizeScaleVector(pick('scale', [args, initialState, defaults]))
      mat4.identity(localMatrix)
      mat4.fromRotationTranslation(localMatrix, rotation, position)
      mat4.scale(localMatrix, localMatrix, scale)
      return localMatrix
    },
    transform(ctx, args) {
      const {transform: parentTransformMatrix} = ctx
      mat4.copy(transformMatrix, localMatrix)
      if (parentTransformMatrix) {
        mat4.multiply(transformMatrix, parentTransformMatrix, localMatrix)
      }
      return transformMatrix
    },
  })
}
function Object3DMatrixContext ( ctx , initialState = { } ) { assertComponentArguments ( 'Object3DMatrixContext' , ctx , initialState ) const transformMatrix = mat4 . identity ( new Float32Array ( 16 ) ) const localMatrix = mat4 . identity ( new Float32Array ( 16 ) ) return ScopedContext ( ctx , initialState , { matrix ( ctx , args ) { const position = pick ( 'position' , [ args , initialState , defaults ] ) const rotation = pick ( 'rotation' , [ args , initialState , defaults ] ) const scale = normalizeScaleVector ( pick ( 'scale' , [ args , initialState , defaults ] ) ) mat4 . identity ( localMatrix ) mat4 . fromRotationTranslation ( localMatrix , rotation , position ) mat4 . scale ( localMatrix , localMatrix , scale ) return localMatrix } , transform ( ctx , args ) { const { transform : parentTransformMatrix } = ctx mat4 . copy ( transformMatrix , localMatrix ) if ( parentTransformMatrix ) { mat4 . multiply ( transformMatrix , parentTransformMatrix , localMatrix ) } return transformMatrix } , } ) }
The Object3DMatrixContext component maps input position, rotation, and scale
 arguments into a matrix and transform context variables.
The Object3DMatrixContext component maps input position rotation and scale arguments into a matrix and transform context variables .
// M = T * R * S // M' = Mp * M