Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Log warnings instead of throwing on redefinitions of Node types #27357

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/jsm/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion examples/jsm/nodes/lighting/LightsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` );

Expand Down
7 changes: 6 additions & 1 deletion examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion examples/jsm/nodes/shadernode/ShaderNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down