|
@@ -97,18 +97,14 @@ const ShaderNodeObject = function ( obj, altType = null ) {
|
|
|
|
|
|
return nodeObject;
|
|
|
|
|
|
- } else if ( ( altType === null ) && ( ( type === 'float' ) || ( type === 'boolean' ) ) ) {
|
|
|
+ } else if ( ( altType === null && ( type === 'float' || type === 'boolean' ) ) || ( type && type !== 'shader' && type !== 'string' ) ) {
|
|
|
|
|
|
- return nodeObject( getAutoTypedConstNode( obj ) );
|
|
|
+ return nodeObject( getConstNode( obj, altType ) );
|
|
|
|
|
|
} else if ( type === 'shader' ) {
|
|
|
|
|
|
return shader( obj );
|
|
|
|
|
|
- } else if ( type && type !== 'string' ) {
|
|
|
-
|
|
|
- return nodeObject( new ConstNode( obj, altType ) );
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return obj;
|
|
@@ -241,7 +237,7 @@ const cacheMaps = { bool: boolsCacheMap, uint: uintsCacheMap, ints: intsCacheMap
|
|
|
|
|
|
const constNodesCacheMap = new Map( [ ...boolsCacheMap, ...floatsCacheMap ] );
|
|
|
|
|
|
-const getAutoTypedConstNode = ( value ) => {
|
|
|
+const getConstNode = ( value, type ) => {
|
|
|
|
|
|
if ( constNodesCacheMap.has( value ) ) {
|
|
|
|
|
@@ -253,46 +249,53 @@ const getAutoTypedConstNode = ( value ) => {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- return new ConstNode( value );
|
|
|
+ return new ConstNode( value, type );
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
-const ConvertType = function ( type, cacheMap = null ) {
|
|
|
+const safeGetNodeType = ( node ) => {
|
|
|
|
|
|
- return ( ...params ) => {
|
|
|
+ try {
|
|
|
|
|
|
- if ( params.length === 0 ) {
|
|
|
+ return node.getNodeType();
|
|
|
|
|
|
- return nodeObject( new ConstNode( getValueFromType( type ), type ) );
|
|
|
+ } catch {
|
|
|
|
|
|
- } else {
|
|
|
+ return undefined;
|
|
|
|
|
|
- if ( type === 'color' && params[ 0 ].isNode !== true ) {
|
|
|
+ }
|
|
|
|
|
|
- params = [ getValueFromType( type, ...params ) ];
|
|
|
+};
|
|
|
|
|
|
- }
|
|
|
+const ConvertType = function ( type, cacheMap = null ) {
|
|
|
|
|
|
- if ( params.length === 1 && cacheMap !== null && cacheMap.has( params[ 0 ] ) ) {
|
|
|
+ return ( ...params ) => {
|
|
|
|
|
|
- return cacheMap.get( params[ 0 ] );
|
|
|
+ if ( params.length === 0 || ( ! [ 'bool', 'float', 'int', 'uint' ].includes( type ) && params.every( param => typeof param !== 'object' ) ) ) {
|
|
|
|
|
|
- }
|
|
|
+ params = [ getValueFromType( type, ...params ) ];
|
|
|
|
|
|
- const nodes = params.map( getAutoTypedConstNode );
|
|
|
+ }
|
|
|
|
|
|
- if ( nodes.length === 1 ) {
|
|
|
+ if ( params.length === 1 && cacheMap !== null && cacheMap.has( params[ 0 ] ) ) {
|
|
|
|
|
|
- return nodeObject( nodes[ 0 ].nodeType === type || getValueType( nodes[ 0 ].value ) === type ? nodes[ 0 ] : new ConvertNode( nodes[ 0 ], type ) );
|
|
|
+ return nodeObject( cacheMap.get( params[ 0 ] ) );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( params.length === 1 ) {
|
|
|
|
|
|
- return nodeObject( new JoinNode( nodes, type ) );
|
|
|
+ const node = getConstNode( params[ 0 ], type );
|
|
|
+ if ( safeGetNodeType( node ) === type ) return nodeObject( node );
|
|
|
+ return nodeObject( new ConvertNode( node, type ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
+ const nodes = params.map( param => getConstNode( param ) );
|
|
|
+ return nodeObject( new JoinNode( nodes, type ) );
|
|
|
+
|
|
|
};
|
|
|
|
|
|
};
|