Explorar o código

WebGPURenderer: Reuse LightNode when available (#29480)

* WebGPURenderer: Reuse LightNode when available

* cleanup
Renaud Rohlinger hai 1 ano
pai
achega
12bcf60a59
Modificáronse 1 ficheiros con 16 adicións e 1 borrados
  1. 16 1
      src/nodes/lighting/LightsNode.js

+ 16 - 1
src/nodes/lighting/LightsNode.js

@@ -23,6 +23,8 @@ const getLightNodeById = ( id, lightNodes ) => {
 
 };
 
+const _lightsNodeRef = /*@__PURE__*/ new WeakMap();
+
 class LightsNode extends Node {
 
 	static get type() {
@@ -119,7 +121,20 @@ class LightsNode extends Node {
 
 					}
 
-					lightNodes.push( nodeObject( new lightNodeClass( light ) ) );
+					let lightNode = null;
+
+					if ( ! _lightsNodeRef.has( light ) ) {
+
+						lightNode = new lightNodeClass( light );
+						_lightsNodeRef.set( light, lightNode );
+
+					} else {
+
+						lightNode = _lightsNodeRef.get( light );
+
+					}
+
+					lightNodes.push( lightNode );
 
 				}
 

粤ICP备19079148号