Skip to content

Commit f4ff275

Browse files
TSL: Add mat2 support (#30364)
* TSL: Add mat2 support * fix CI * good
1 parent f70fece commit f4ff275

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/nodes/core/NodeBuilder.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,16 @@ class NodeBuilder {
13201320

13211321
if ( length === 1 ) return componentType;
13221322

1323-
const baseType = getTypeFromLength( length );
1323+
let baseType = getTypeFromLength( length );
13241324
const prefix = componentType === 'float' ? '' : componentType[ 0 ];
13251325

1326+
// fix edge case for mat2x2 being same size as vec4
1327+
if ( /mat2/.test( componentType ) === true ) {
1328+
1329+
baseType = baseType.replace( 'vec', 'mat' );
1330+
1331+
}
1332+
13261333
return prefix + baseType;
13271334

13281335
}

src/nodes/core/NodeUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Color } from '../../math/Color.js';
2+
import { Matrix2 } from '../../math/Matrix2.js';
23
import { Matrix3 } from '../../math/Matrix3.js';
34
import { Matrix4 } from '../../math/Matrix4.js';
45
import { Vector2 } from '../../math/Vector2.js';
@@ -229,6 +230,7 @@ export function getLengthFromType( type ) {
229230
if ( /vec2/.test( type ) ) return 2;
230231
if ( /vec3/.test( type ) ) return 3;
231232
if ( /vec4/.test( type ) ) return 4;
233+
if ( /mat2/.test( type ) ) return 4;
232234
if ( /mat3/.test( type ) ) return 9;
233235
if ( /mat4/.test( type ) ) return 16;
234236

@@ -281,6 +283,10 @@ export function getValueType( value ) {
281283

282284
return 'vec4';
283285

286+
} else if ( value.isMatrix2 === true ) {
287+
288+
return 'mat2';
289+
284290
} else if ( value.isMatrix3 === true ) {
285291

286292
return 'mat3';
@@ -339,6 +345,10 @@ export function getValueFromType( type, ...params ) {
339345

340346
return new Vector4( ...params );
341347

348+
} else if ( last4 === 'mat2' ) {
349+
350+
return new Matrix2( ...params );
351+
342352
} else if ( last4 === 'mat3' ) {
343353

344354
return new Matrix3( ...params );

0 commit comments

Comments
 (0)