浏览代码

Cleanup ShaderNode (#23820)

* Cleanup ShaderNode

* Change

* Fix
Levi Pesin 3 年之前
父节点
当前提交
0f282227b2

+ 0 - 1
examples/jsm/nodes/Nodes.js

@@ -88,7 +88,6 @@ export * from './functions/BSDFs.js';
 export * from './materials/Materials.js';
 
 // shader node
-export * from './shadernode/ShaderNode.js';
 export * from './shadernode/ShaderNodeElements.js';
 
 const nodeLib = {

+ 2 - 2
examples/jsm/nodes/shadernode/ShaderNode.js

@@ -1,5 +1,5 @@
-import { ShaderNodeScript, NodeHandler } from './ShaderNodeUtils.js';
+import { ShaderNodeScript, shaderNodeHandler } from './ShaderNodeUtils.js';
 
-const ShaderNode = new Proxy( ShaderNodeScript, NodeHandler );
+const ShaderNode = new Proxy( ShaderNodeScript, shaderNodeHandler );
 
 export default ShaderNode;

+ 6 - 6
examples/jsm/nodes/shadernode/ShaderNodeElements.js

@@ -32,8 +32,8 @@ import ColorSpaceNode from '../display/ColorSpaceNode.js';
 import LightContextNode from '../lights/LightContextNode.js';
 
 // utils
-import { nodeObject, nodeObjects, nodeArray, nodeProxy, ConvertType, floatsCacheMap, intsCacheMap, uintsCacheMap, boolsCacheMap } from './ShaderNodeUtils.js';
 import ShaderNode from './ShaderNode.js';
+import { nodeObject, nodeObjects, nodeArray, nodeProxy, ConvertType, cacheMaps } from './ShaderNodeUtils.js';
 
 //
 // Node Material Shader Syntax
@@ -41,13 +41,13 @@ import ShaderNode from './ShaderNode.js';
 
 export { ShaderNode, nodeObject, nodeObjects, nodeArray, nodeProxy };
 
-export const float = new ConvertType( 'float', floatsCacheMap );
-export const int = new ConvertType( 'int', intsCacheMap );
-export const uint = new ConvertType( 'uint', uintsCacheMap );
-export const bool = new ConvertType( 'bool', boolsCacheMap );
-
 export const color = new ConvertType( 'color' );
 
+export const float = new ConvertType( 'float', cacheMaps.float );
+export const int = new ConvertType( 'int', cacheMaps.int );
+export const uint = new ConvertType( 'uint', cacheMaps.uint );
+export const bool = new ConvertType( 'bool', cacheMaps.bool );
+
 export const vec2 = new ConvertType( 'vec2' );
 export const ivec2 = new ConvertType( 'ivec2' );
 export const uvec2 = new ConvertType( 'uvec2' );

+ 8 - 6
examples/jsm/nodes/shadernode/ShaderNodeUtils.js

@@ -5,7 +5,7 @@ import SplitNode from '../utils/SplitNode.js';
 import ConstNode from '../core/ConstNode.js';
 import { getValueFromType } from '../core/NodeUtils.js';
 
-export const NodeHandler = {
+export const shaderNodeHandler = {
 
 	construct( NodeClosure, params ) {
 
@@ -65,7 +65,7 @@ const ShaderNodeObject = function ( obj ) {
 
 			if ( nodeObject === undefined ) {
 
-				nodeObject = new Proxy( obj, NodeHandler );
+				nodeObject = new Proxy( obj, shaderNodeHandler );
 				nodeObjectsCacheMap.set( obj, nodeObject );
 				nodeObjectsCacheMap.set( nodeObject, nodeObject );
 
@@ -161,19 +161,21 @@ const uints = [ 0, 1, 2, 3 ];
 const ints = [ -1, -2 ];
 const floats = [ 0.5, 1.5, 1 / 3, 1e-6, 1e6, Math.PI, Math.PI * 2, 1 / Math.PI, 2 / Math.PI, 1 / ( Math.PI * 2 ), Math.PI / 2 ];
 
-export const boolsCacheMap = new Map();
+const boolsCacheMap = new Map();
 for ( let bool of bools ) boolsCacheMap.set( bool, new ConstNode( bool ) );
 
-export const uintsCacheMap = new Map();
+const uintsCacheMap = new Map();
 for ( let uint of uints ) uintsCacheMap.set( uint, new ConstNode( uint, 'uint' ) );
 
-export const intsCacheMap = new Map( [ ...uintsCacheMap ].map( el => new ConstNode( el.value, 'int' ) ) );
+const intsCacheMap = new Map( [ ...uintsCacheMap ].map( el => new ConstNode( el.value, 'int' ) ) );
 for ( let int of ints ) intsCacheMap.set( int, new ConstNode( int, 'int' ) );
 
-export const floatsCacheMap = new Map( [ ...intsCacheMap ].map( el => new ConstNode( el.value ) ) );
+const floatsCacheMap = new Map( [ ...intsCacheMap ].map( el => new ConstNode( el.value ) ) );
 for ( let float of floats ) floatsCacheMap.set( float, new ConstNode( float ) );
 for ( let float of floats ) floatsCacheMap.set( - float, new ConstNode( - float ) );
 
+export const cacheMaps = { bool: boolsCacheMap, uint: uintsCacheMap, ints: intsCacheMap, float: floatsCacheMap };
+
 const constNodesCacheMap = new Map( [ ...boolsCacheMap, ...floatsCacheMap ] );
 
 const getAutoTypedConstNode = ( value ) => {