Skip to content

Commit

Permalink
TSL: Add mat2 support (#30364)
Browse files Browse the repository at this point in the history
* TSL: Add mat2 support

* fix CI

* good
  • Loading branch information
RenaudRohlinger authored Jan 20, 2025
1 parent f70fece commit f4ff275
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
10 changes: 10 additions & 0 deletions src/nodes/core/NodeUtils.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -281,6 +283,10 @@ export function getValueType( value ) {

return 'vec4';

} else if ( value.isMatrix2 === true ) {

return 'mat2';

} else if ( value.isMatrix3 === true ) {

return 'mat3';
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit f4ff275

Please sign in to comment.