From f4ff275b36f5abfcf6f167b12bcdc9c349ba619e Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Tue, 21 Jan 2025 05:07:54 +0900 Subject: [PATCH] TSL: Add `mat2` support (#30364) * TSL: Add mat2 support * fix CI * good --- src/nodes/core/NodeBuilder.js | 9 ++++++++- src/nodes/core/NodeUtils.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/nodes/core/NodeBuilder.js b/src/nodes/core/NodeBuilder.js index c2608f5b46e396..c7b1166203aa03 100644 --- a/src/nodes/core/NodeBuilder.js +++ b/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; } diff --git a/src/nodes/core/NodeUtils.js b/src/nodes/core/NodeUtils.js index cc055bbb2750ec..1a7b301e7fc9a9 100644 --- a/src/nodes/core/NodeUtils.js +++ b/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 );