Skip to content

Commit 3cf407d

Browse files
authored
TSL: Improve vec* checks and warnings (#30811)
1 parent 96afe95 commit 3cf407d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/nodes/core/NodeBuilder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2614,13 +2614,13 @@ class NodeBuilder {
26142614

26152615
if ( fromTypeLength === 16 && toTypeLength === 9 ) {
26162616

2617-
return `${ this.getType( toType ) }(${ snippet }[0].xyz, ${ snippet }[1].xyz, ${ snippet }[2].xyz)`;
2617+
return `${ this.getType( toType ) }( ${ snippet }[ 0 ].xyz, ${ snippet }[ 1 ].xyz, ${ snippet }[ 2 ].xyz )`;
26182618

26192619
}
26202620

26212621
if ( fromTypeLength === 9 && toTypeLength === 4 ) {
26222622

2623-
return `${ this.getType( toType ) }(${ snippet }[0].xy, ${ snippet }[1].xy)`;
2623+
return `${ this.getType( toType ) }( ${ snippet }[ 0 ].xy, ${ snippet }[ 1 ].xy )`;
26242624

26252625
}
26262626

src/nodes/tsl/TSLCore.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export function addMethodChaining( name, nodeElement ) {
1717

1818
if ( NodeElements.has( name ) ) {
1919

20-
console.warn( `Redefinition of method chaining ${ name }` );
20+
console.warn( `THREE.TSL: Redefinition of method chaining '${ name }'.` );
2121
return;
2222

2323
}
2424

25-
if ( typeof nodeElement !== 'function' ) throw new Error( `Node element ${ name } is not a function` );
25+
if ( typeof nodeElement !== 'function' ) throw new Error( `THREE.TSL: Node element ${ name } is not a function` );
2626

2727
NodeElements.set( name, nodeElement );
2828

src/nodes/utils/JoinNode.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,42 @@ class JoinNode extends TempNode {
5656
generate( builder, output ) {
5757

5858
const type = this.getNodeType( builder );
59+
const maxLength = builder.getTypeLength( type );
60+
5961
const nodes = this.nodes;
6062

6163
const primitiveType = builder.getComponentType( type );
6264

6365
const snippetValues = [];
6466

67+
let length = 0;
68+
6569
for ( const input of nodes ) {
6670

67-
let inputSnippet = input.build( builder );
71+
if ( length >= maxLength ) {
72+
73+
console.error( 'THREE.TSL: Length of parameters exceeds maximum length of function type.' );
74+
break;
75+
76+
}
77+
78+
let inputType = input.getNodeType( builder );
79+
let inputTypeLength = builder.getTypeLength( inputType );
80+
let inputSnippet;
81+
82+
if ( length + inputTypeLength > maxLength ) {
83+
84+
console.error( 'THREE.TSL: Length of joined data exceeds maximum length of output type.' );
85+
86+
inputTypeLength = maxLength - length;
87+
inputType = builder.getTypeFromLength( inputTypeLength );
88+
89+
}
90+
91+
length += inputTypeLength;
92+
inputSnippet = input.build( builder, inputType );
6893

69-
const inputPrimitiveType = builder.getComponentType( input.getNodeType( builder ) );
94+
const inputPrimitiveType = builder.getComponentType( inputType );
7095

7196
if ( inputPrimitiveType !== primitiveType ) {
7297

0 commit comments

Comments
 (0)