Jelajahi Sumber

TSL: Add `mat2` support (#30364)

* TSL: Add mat2 support

* fix CI

* good
Renaud Rohlinger 1 tahun lalu
induk
melakukan
f4ff275b36
2 mengubah file dengan 18 tambahan dan 1 penghapusan
  1. 8 1
      src/nodes/core/NodeBuilder.js
  2. 10 0
      src/nodes/core/NodeUtils.js

+ 8 - 1
src/nodes/core/NodeBuilder.js

@@ -1320,9 +1320,16 @@ class NodeBuilder {
 
 		if ( length === 1 ) return componentType;
 
-		const baseType = getTypeFromLength( length );
+		let baseType = getTypeFromLength( length );
 		const prefix = componentType === 'float' ? '' : componentType[ 0 ];
 
+		// fix edge case for mat2x2 being same size as vec4
+		if ( /mat2/.test( componentType ) === true ) {
+
+			baseType = baseType.replace( 'vec', 'mat' );
+
+		}
+
 		return prefix + baseType;
 
 	}

+ 10 - 0
src/nodes/core/NodeUtils.js

@@ -1,4 +1,5 @@
 import { Color } from '../../math/Color.js';
+import { Matrix2 } from '../../math/Matrix2.js';
 import { Matrix3 } from '../../math/Matrix3.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Vector2 } from '../../math/Vector2.js';
@@ -229,6 +230,7 @@ export function getLengthFromType( type ) {
 	if ( /vec2/.test( type ) ) return 2;
 	if ( /vec3/.test( type ) ) return 3;
 	if ( /vec4/.test( type ) ) return 4;
+	if ( /mat2/.test( type ) ) return 4;
 	if ( /mat3/.test( type ) ) return 9;
 	if ( /mat4/.test( type ) ) return 16;
 
@@ -281,6 +283,10 @@ export function getValueType( value ) {
 
 		return 'vec4';
 
+	} else if ( value.isMatrix2 === true ) {
+
+		return 'mat2';
+
 	} else if ( value.isMatrix3 === true ) {
 
 		return 'mat3';
@@ -339,6 +345,10 @@ export function getValueFromType( type, ...params ) {
 
 		return new Vector4( ...params );
 
+	} else if ( last4 === 'mat2' ) {
+
+		return new Matrix2( ...params );
+
 	} else if ( last4 === 'mat3' ) {
 
 		return new Matrix3( ...params );

粤ICP备19079148号