sunag пре 3 година
родитељ
комит
938bfdca9c

+ 7 - 17
examples/jsm/nodes/ShaderNode.js

@@ -201,33 +201,23 @@ export const nodeObject = ( val ) => {
 
 };
 
-export const label = ( node, name = null, nodeType = null ) => {
+export const label = ( node, name ) => {
 
-	if ( node.isVarNode === true ) {
-
-		// node is already a VarNode
-
-		if ( ( node.name !== name ) && ( name !== null ) ) {
+	node = nodeObject( node );
 
-			node.name = name;
-
-		}
-
-		if ( ( node.nodeType !== nodeType ) && ( nodeType !== null ) ) {
-
-			node.nodeType = nodeType;
+	if ( node.isVarNode === true ) {
 
-		}
+		node.name = name;
 
-		return nodeObject( node );
+		return node;
 
 	}
 
-	return nodeObject( new VarNode( nodeObject( node ), name, nodeType ) );
+	return nodeObject( new VarNode( node, name ) );
 
 };
 
-export const temp = ( node, nodeType = null ) => label( node, null, nodeType );
+export const temp = ( node ) => nodeObject( new VarNode( nodeObject( node ), name ) );
 
 const ConvertType = function ( nodeClass, type, valueClass = null, valueComponents = 1 ) {
 

+ 7 - 4
examples/jsm/nodes/core/NodeBuilder.js

@@ -152,12 +152,12 @@ class NodeBuilder {
 
 	}
 
-	// rename to generate
+	// @TODO: rename to .generateConst()
 	getConst( type, value ) {
 
 		if ( type === 'float' ) return toFloat( value );
 		if ( type === 'int' ) return `${ Math.round( value ) }`;
-		if ( type === 'uint' ) return ( value >= 0 ) ? `${ Math.round( value ) }` : '0';
+		if ( type === 'uint' ) return value >= 0 ? `${ Math.round( value ) }` : '0';
 		if ( type === 'bool' ) return value ? 'true' : 'false';
 		if ( type === 'vec2' ) return `${ this.getType( 'vec2' ) }( ${ toFloat( value.x ) }, ${ toFloat( value.y ) } )`;
 		if ( type === 'vec3' ) return `${ this.getType( 'vec3' ) }( ${ toFloat( value.x ) }, ${ toFloat( value.y ) }, ${ toFloat( value.z ) } )`;
@@ -598,7 +598,7 @@ class NodeBuilder {
 		fromType = this.getVectorType( fromType );
 		toType = this.getVectorType( toType );
 
-		if ( ( fromType === toType ) || ( toType === null ) ) {
+		if ( fromType === toType || toType === 'void' || toType === null ) {
 
 			return snippet;
 
@@ -617,7 +617,10 @@ class NodeBuilder {
 
 		if ( toTypeLength === 0 ) { // toType is matrix-like
 
-			return `${ this.getType( toType ) }( ${ snippet } )`;
+			// ignore for now
+			//return `${ this.getType( toType ) }( ${ snippet } )`;
+
+			return snippet;
 
 		}
 

+ 17 - 5
examples/jsm/nodes/math/OperatorNode.js

@@ -46,18 +46,18 @@ class OperatorNode extends TempNode {
 			return typeA;
 
 		} else if ( op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
-			
+
 			return 'int';
-			
+
 		} else if ( op === '==' || op === '&&' || op === '||' || op === '^^' ) {
 
 			return 'bool';
 
-		} else if ( op === '<=' || op === '>=' || op === '<' || op === '>' ) {
+		} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
 
-			const length = builder.getTypeLength( output );
+			const typeLength = builder.getTypeLength( output );
 
-			return length > 1 ? `bvec${ length }` : 'bool';
+			return typeLength > 1 ? `bvec${ typeLength }` : 'bool';
 
 		} else {
 
@@ -112,6 +112,18 @@ class OperatorNode extends TempNode {
 
 				typeB = typeA;
 
+			} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
+
+				if ( builder.isVector( typeA ) ) {
+
+					typeB = typeA;
+
+				} else {
+
+					typeA = typeB = 'float';
+
+				}
+
 			} else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) {
 
 				// matrix x vector