From f1458152b05d8e4c64655b2573609e84adaa39ee Mon Sep 17 00:00:00 2001 From: hybridherbst Date: Mon, 11 Dec 2023 13:15:43 +0100 Subject: [PATCH] Fix: log warnings instead of throwing on redefinitions of Node types This is the same behaviour as three.js itself has when it's imported multiple times. --- examples/jsm/nodes/core/Node.js | 7 ++++++- examples/jsm/nodes/lighting/LightsNode.js | 8 +++++++- examples/jsm/nodes/materials/NodeMaterial.js | 7 ++++++- examples/jsm/nodes/shadernode/ShaderNode.js | 8 +++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/examples/jsm/nodes/core/Node.js b/examples/jsm/nodes/core/Node.js index e53f26839ac354..74fa2f1fc9a3b6 100644 --- a/examples/jsm/nodes/core/Node.js +++ b/examples/jsm/nodes/core/Node.js @@ -458,7 +458,12 @@ export default Node; export function addNodeClass( type, nodeClass ) { if ( typeof nodeClass !== 'function' || ! type ) throw new Error( `Node class ${ type } is not a class` ); - if ( NodeClasses.has( type ) ) throw new Error( `Redefinition of node class ${ type }` ); + if ( NodeClasses.has( type ) ) { + + console.warn( `Redefinition of node class ${ type }` ); + return; + + } NodeClasses.set( type, nodeClass ); nodeClass.type = type; diff --git a/examples/jsm/nodes/lighting/LightsNode.js b/examples/jsm/nodes/lighting/LightsNode.js index e39bf4082079b0..1e79e5f8d7fb13 100644 --- a/examples/jsm/nodes/lighting/LightsNode.js +++ b/examples/jsm/nodes/lighting/LightsNode.js @@ -173,7 +173,13 @@ export const lightNodes = nodeProxy( LightsNode ); export function addLightNode( lightClass, lightNodeClass ) { - if ( LightNodes.has( lightClass ) ) throw new Error( `Redefinition of light node ${ lightNodeClass.type }` ); + if ( LightNodes.has( lightClass ) ) { + + console.warn( `Redefinition of light node ${ lightNodeClass.type }` ); + return; + + } + if ( typeof lightClass !== 'function' ) throw new Error( `Light ${ lightClass.name } is not a class` ); if ( typeof lightNodeClass !== 'function' || ! lightNodeClass.type ) throw new Error( `Light node ${ lightNodeClass.type } is not a class` ); diff --git a/examples/jsm/nodes/materials/NodeMaterial.js b/examples/jsm/nodes/materials/NodeMaterial.js index e9dbbd92668122..1d60c3ad383ae7 100644 --- a/examples/jsm/nodes/materials/NodeMaterial.js +++ b/examples/jsm/nodes/materials/NodeMaterial.js @@ -541,7 +541,12 @@ export default NodeMaterial; export function addNodeMaterial( type, nodeMaterial ) { if ( typeof nodeMaterial !== 'function' || ! type ) throw new Error( `Node material ${ type } is not a class` ); - if ( NodeMaterials.has( type ) ) throw new Error( `Redefinition of node material ${ type }` ); + if ( NodeMaterials.has( type ) ) { + + console.warn( `Redefinition of node material ${ type }` ); + return; + + } NodeMaterials.set( type, nodeMaterial ); nodeMaterial.type = type; diff --git a/examples/jsm/nodes/shadernode/ShaderNode.js b/examples/jsm/nodes/shadernode/ShaderNode.js index 1034657b969a5a..21db2a4a285071 100644 --- a/examples/jsm/nodes/shadernode/ShaderNode.js +++ b/examples/jsm/nodes/shadernode/ShaderNode.js @@ -15,7 +15,13 @@ const NodeElements = new Map(); // @TODO: Currently only a few nodes are added, export function addNodeElement( name, nodeElement ) { - if ( NodeElements.has( name ) ) throw new Error( `Redefinition of node element ${ name }` ); + if ( NodeElements.has( name ) ) { + + console.warn( `Redefinition of node element ${ name }` ); + return; + + } + if ( typeof nodeElement !== 'function' ) throw new Error( `Node element ${ name } is not a function` ); NodeElements.set( name, nodeElement );