Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Add mat2 Support #30364

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading