Skip to content

Commit f7102ac

Browse files
authored
Nodes: Log warnings instead of throwing on redefinitions of Node types (#27357)
This is the same behaviour as three.js itself has when it's imported multiple times.
1 parent c476c0d commit f7102ac

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

examples/jsm/nodes/core/Node.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,12 @@ export default Node;
458458
export function addNodeClass( type, nodeClass ) {
459459

460460
if ( typeof nodeClass !== 'function' || ! type ) throw new Error( `Node class ${ type } is not a class` );
461-
if ( NodeClasses.has( type ) ) throw new Error( `Redefinition of node class ${ type }` );
461+
if ( NodeClasses.has( type ) ) {
462+
463+
console.warn( `Redefinition of node class ${ type }` );
464+
return;
465+
466+
}
462467

463468
NodeClasses.set( type, nodeClass );
464469
nodeClass.type = type;

examples/jsm/nodes/lighting/LightsNode.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ export const lightNodes = nodeProxy( LightsNode );
173173

174174
export function addLightNode( lightClass, lightNodeClass ) {
175175

176-
if ( LightNodes.has( lightClass ) ) throw new Error( `Redefinition of light node ${ lightNodeClass.type }` );
176+
if ( LightNodes.has( lightClass ) ) {
177+
178+
console.warn( `Redefinition of light node ${ lightNodeClass.type }` );
179+
return;
180+
181+
}
182+
177183
if ( typeof lightClass !== 'function' ) throw new Error( `Light ${ lightClass.name } is not a class` );
178184
if ( typeof lightNodeClass !== 'function' || ! lightNodeClass.type ) throw new Error( `Light node ${ lightNodeClass.type } is not a class` );
179185

examples/jsm/nodes/materials/NodeMaterial.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,12 @@ export default NodeMaterial;
541541
export function addNodeMaterial( type, nodeMaterial ) {
542542

543543
if ( typeof nodeMaterial !== 'function' || ! type ) throw new Error( `Node material ${ type } is not a class` );
544-
if ( NodeMaterials.has( type ) ) throw new Error( `Redefinition of node material ${ type }` );
544+
if ( NodeMaterials.has( type ) ) {
545+
546+
console.warn( `Redefinition of node material ${ type }` );
547+
return;
548+
549+
}
545550

546551
NodeMaterials.set( type, nodeMaterial );
547552
nodeMaterial.type = type;

examples/jsm/nodes/shadernode/ShaderNode.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ const NodeElements = new Map(); // @TODO: Currently only a few nodes are added,
1515

1616
export function addNodeElement( name, nodeElement ) {
1717

18-
if ( NodeElements.has( name ) ) throw new Error( `Redefinition of node element ${ name }` );
18+
if ( NodeElements.has( name ) ) {
19+
20+
console.warn( `Redefinition of node element ${ name }` );
21+
return;
22+
23+
}
24+
1925
if ( typeof nodeElement !== 'function' ) throw new Error( `Node element ${ name } is not a function` );
2026

2127
NodeElements.set( name, nodeElement );

0 commit comments

Comments
 (0)