这是indexloc提供的服务,不要输入任何密码
Skip to content

Object3D.applyMatrix4 uses multiply instead of premultiply (incorrect transform order vs three.js) #115

@vfarafonov

Description

@vfarafonov

In the three_js package, the implementation of Object3D.applyMatrix4 diverges from both three.js and three_dart, resulting in an incorrect transformation order when applying matrices.

Current Behavior (Bug)
In packages/three_js_core/lib/core/object_3d.dart#L230:

this.matrix.multiply(m);

This post-multiplies the object’s current matrix by the input matrix (M = M * m).

As a result, applying a world-space transformation (e.g., translation) ends up being applied in local coordinates, producing unexpected or incorrect transformations — especially noticeable when an object already has rotation.

Expected Behavior

According to the original three.js implementation Object3D.js#L427:

this.matrix.premultiply(matrix);

and three_dart correctly mirrors this: object_3d.dart#L218

That order (M = m * M) ensures the applied matrix operates in world space, matching three.js semantics.

Impact

  • Applying a transformation matrix yields rotated or offset translations.
  • Scene updates depending on applyMatrix4 (e.g., aligning models, placing objects in world space) behave incorrectly.
  • This breaks API parity with both three.js and three_dart.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions