Skip to content

Commit 802538c

Browse files
sunagdonmccurdy
authored andcommitted
Nodes: fixes and revision (mrdoob#23647)
1 parent 8dc125d commit 802538c

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

examples/jsm/nodes/ShaderNode.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,23 @@ export const nodeObject = ( val ) => {
201201

202202
};
203203

204-
export const label = ( node, name = null, nodeType = null ) => {
204+
export const label = ( node, name ) => {
205205

206-
if ( node.isVarNode === true ) {
207-
208-
// node is already a VarNode
209-
210-
if ( ( node.name !== name ) && ( name !== null ) ) {
206+
node = nodeObject( node );
211207

212-
node.name = name;
213-
214-
}
215-
216-
if ( ( node.nodeType !== nodeType ) && ( nodeType !== null ) ) {
217-
218-
node.nodeType = nodeType;
208+
if ( node.isVarNode === true ) {
219209

220-
}
210+
node.name = name;
221211

222-
return nodeObject( node );
212+
return node;
223213

224214
}
225215

226-
return nodeObject( new VarNode( nodeObject( node ), name, nodeType ) );
216+
return nodeObject( new VarNode( node, name ) );
227217

228218
};
229219

230-
export const temp = ( node, nodeType = null ) => label( node, null, nodeType );
220+
export const temp = ( node ) => nodeObject( new VarNode( nodeObject( node ), name ) );
231221

232222
const ConvertType = function ( nodeClass, type, valueClass = null, valueComponents = 1 ) {
233223

examples/jsm/nodes/core/NodeBuilder.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ class NodeBuilder {
152152

153153
}
154154

155-
// rename to generate
155+
// @TODO: rename to .generateConst()
156156
getConst( type, value ) {
157157

158158
if ( type === 'float' ) return toFloat( value );
159159
if ( type === 'int' ) return `${ Math.round( value ) }`;
160-
if ( type === 'uint' ) return ( value >= 0 ) ? `${ Math.round( value ) }` : '0';
160+
if ( type === 'uint' ) return value >= 0 ? `${ Math.round( value ) }` : '0';
161161
if ( type === 'bool' ) return value ? 'true' : 'false';
162162
if ( type === 'vec2' ) return `${ this.getType( 'vec2' ) }( ${ toFloat( value.x ) }, ${ toFloat( value.y ) } )`;
163163
if ( type === 'vec3' ) return `${ this.getType( 'vec3' ) }( ${ toFloat( value.x ) }, ${ toFloat( value.y ) }, ${ toFloat( value.z ) } )`;
@@ -598,7 +598,7 @@ class NodeBuilder {
598598
fromType = this.getVectorType( fromType );
599599
toType = this.getVectorType( toType );
600600

601-
if ( ( fromType === toType ) || ( toType === null ) ) {
601+
if ( fromType === toType || toType === 'void' || toType === null ) {
602602

603603
return snippet;
604604

@@ -617,7 +617,10 @@ class NodeBuilder {
617617

618618
if ( toTypeLength === 0 ) { // toType is matrix-like
619619

620-
return `${ this.getType( toType ) }( ${ snippet } )`;
620+
// ignore for now
621+
//return `${ this.getType( toType ) }( ${ snippet } )`;
622+
623+
return snippet;
621624

622625
}
623626

examples/jsm/nodes/math/OperatorNode.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ class OperatorNode extends TempNode {
4646
return typeA;
4747

4848
} else if ( op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
49-
49+
5050
return 'int';
51-
51+
5252
} else if ( op === '==' || op === '&&' || op === '||' || op === '^^' ) {
5353

5454
return 'bool';
5555

56-
} else if ( op === '<=' || op === '>=' || op === '<' || op === '>' ) {
56+
} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
5757

58-
const length = builder.getTypeLength( output );
58+
const typeLength = builder.getTypeLength( output );
5959

60-
return length > 1 ? `bvec${ length }` : 'bool';
60+
return typeLength > 1 ? `bvec${ typeLength }` : 'bool';
6161

6262
} else {
6363

@@ -112,6 +112,18 @@ class OperatorNode extends TempNode {
112112

113113
typeB = typeA;
114114

115+
} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
116+
117+
if ( builder.isVector( typeA ) ) {
118+
119+
typeB = typeA;
120+
121+
} else {
122+
123+
typeA = typeB = 'float';
124+
125+
}
126+
115127
} else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) {
116128

117129
// matrix x vector

0 commit comments

Comments
 (0)