Skip to content

Conversation

@gkjohnson
Copy link
Collaborator

Related issue: --

Description

GLSL, Three.js BufferAttributes, and GLTF accessors support 2x2 matrix types so it may be nice to make a basic Matrix2 class available in three so these types can be used and manipulated more easily. This class was originally created for the 3DTilesRendererJS project (see here) for use with the GLTF EXT_structural_metadata extension so data could be read from mat2 buffer accessors and returned in a format similar to Matrix3 and Matrix4.

Only the functions needed for the initial implementation are included here. More can be added by the community over time as needed.

This contribution is funded by Cesium GIS Ecosystem Grant

@gkjohnson gkjohnson added this to the r167 milestone Jul 20, 2024
@@ -0,0 +1,54 @@
export class Matrix2 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this class to the core instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that up to someone else to decide. With tree shaking I suppose it's not a big deal to move but I'm not sure of what the exact rules are for what belongs in examples vs core.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a case by case decision but since Vector2 is part of the core it seems more consistent to add Matrix2 as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay - I can move it if you'd like!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WestLangley Are you okay with that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great - I've just moved the files to core

@gkjohnson gkjohnson changed the title Examples: Add Matrix2 class Core: Add Matrix2 class Jul 20, 2024
@github-actions
Copy link

github-actions bot commented Jul 20, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
683.7 kB (169.3 kB) 684 kB (169.4 kB) +314 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
460.9 kB (111.2 kB) 460.9 kB (111.2 kB) +0 B

export { Ray } from './math/Ray.js';
export { Matrix4 } from './math/Matrix4.js';
export { Matrix3 } from './math/Matrix3.js';
export { Matrix2 } from './math/Matrix2.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind also adding the entry for Three.WebGPU.js?

Otherwise the WebGPU build won't have this class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also docs. 🙏

@gkjohnson gkjohnson merged commit b59ac41 into mrdoob:dev Jul 21, 2024
@gkjohnson gkjohnson deleted the add-mat2 branch July 21, 2024 11:13
repalash added a commit to repalash/three.js that referenced this pull request Jul 24, 2025
dbuck pushed a commit to matterport/3DTilesRendererJS that referenced this pull request Nov 12, 2025
v167 is when Matrix2 shipped mrdoob/three.js#28923

I noticed while updating a local example build, but wanted to update in the smallest chunk required to test, updating to 166 per the peer deps results in the error below.

```
✘ [ERROR] No matching export in "node_modules/three/build/three.module.js" for import "Matrix2"

    node_modules/3d-tiles-renderer/build/WMSCapabilitiesLoader-j6h8dwK_.js:3:434:
      3 │ ...Triangle as Ht, Vector4 as Ue, Matrix4 as Q, Matrix3 as kn, Matrix2 as jn, WebGLRenderer as zn, WebGLRenderTarget as Ut, Shade...
        ╵
```
dbuck pushed a commit to matterport/3DTilesRendererJS that referenced this pull request Nov 12, 2025
v167 is when Matrix2 shipped mrdoob/three.js#28923

I noticed while updating a local example build, but wanted to update in the smallest chunk required to test, updating to 166 per the peer deps results in the error below.

```
✘ [ERROR] No matching export in "node_modules/three/build/three.module.js" for import "Matrix2"

    node_modules/3d-tiles-renderer/build/WMSCapabilitiesLoader-j6h8dwK_.js:3:434:
      3 │ ...Triangle as Ht, Vector4 as Ue, Matrix4 as Q, Matrix3 as kn, Matrix2 as jn, WebGLRenderer as zn, WebGLRenderTarget as Ut, Shade...
        ╵
```
gkjohnson pushed a commit to NASA-AMMOS/3DTilesRendererJS that referenced this pull request Nov 13, 2025
v167 is when Matrix2 shipped mrdoob/three.js#28923

I noticed while updating a local example build, but wanted to update in the smallest chunk required to test, updating to 166 per the peer deps results in the error below.

```
✘ [ERROR] No matching export in "node_modules/three/build/three.module.js" for import "Matrix2"

    node_modules/3d-tiles-renderer/build/WMSCapabilitiesLoader-j6h8dwK_.js:3:434:
      3 │ ...Triangle as Ht, Vector4 as Ue, Matrix4 as Q, Matrix3 as kn, Matrix2 as jn, WebGLRenderer as zn, WebGLRenderTarget as Ut, Shade...
        ╵
```

Co-authored-by: Dave Buchhofer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants