Просмотр исходного кода

TSL: Add missing `label()` rename (#31546)

* add missing `label()` rename

* cleanup

* rename `preferredName` -> `nodeName`
sunag 6 месяцев назад
Родитель
Сommit
15c438aceb

+ 2 - 2
examples/webgpu_tsl_editor.html

@@ -128,7 +128,7 @@ const scaledTime = time.mul( .5 ); // .5 is speed
 const uv0 = uv();
 const animateUv = vec2( uv0.x.add( oscSine( scaledTime ) ), uv0.y );
 
-// label is optional
+// .setName() is optional
 const myMap = texture( samplerTexture, animateUv ).rgb.setName( 'myTexture' );
 const myColor = uniform( new THREE.Color( 0x0066ff ) ).setName( 'myColor' );
 const opacity = .7;
@@ -173,7 +173,7 @@ output = vec4( finalColor, opacity );
 							const AsyncFunction = async function () {}.constructor;
 
 							const tslCode = `let output = null;\n${ editor.getValue() }\nreturn { output };`;
-							const nodes = await ( new AsyncFunction( 'three/webgpu', tslCode )( THREE ) );
+							const nodes = await ( new AsyncFunction( 'THREE', tslCode )( THREE ) );
 
 							mesh.material.fragmentNode = nodes.output;
 							mesh.material.needsUpdate = true;

+ 1 - 0
src/Three.TSL.js

@@ -471,6 +471,7 @@ export const scriptable = TSL.scriptable;
 export const scriptableValue = TSL.scriptableValue;
 export const select = TSL.select;
 export const setCurrentStack = TSL.setCurrentStack;
+export const setName = TSL.setName;
 export const shaderStages = TSL.shaderStages;
 export const shadow = TSL.shadow;
 export const shadowPositionWorld = TSL.shadowPositionWorld;

+ 1 - 1
src/nodes/accessors/ReferenceNode.js

@@ -282,7 +282,7 @@ class ReferenceNode extends Node {
 
 		}
 
-		if ( this.name !== null ) node.label( this.name );
+		if ( this.name !== null ) node.setName( this.name );
 
 		this.node = node.getSelf();
 

+ 20 - 1
src/nodes/core/ContextNode.js

@@ -131,16 +131,35 @@ export default ContextNode;
  */
 export const context = /*@__PURE__*/ nodeProxy( ContextNode ).setParameterLength( 1, 2 );
 
+/**
+ * TSL function for defining a name for the context value for a given node.
+ *
+ * @tsl
+ * @function
+ * @param {Node} node - The node whose context should be modified.
+ * @param {string} name - The name to set.
+ * @returns {ContextNode}
+ */
+export const setName = ( node, name ) => context( node, { nodeName: name } );
+
 /**
  * TSL function for defining a label context value for a given node.
  *
  * @tsl
  * @function
+ * @deprecated
  * @param {Node} node - The node whose context should be modified.
  * @param {string} name - The name/label to set.
  * @returns {ContextNode}
  */
-export const label = ( node, name ) => context( node, { label: name } );
+export function label( node, name ) {
+
+	console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
+
+	return setName( node, name );
+
+}
 
 addMethodChaining( 'context', context );
 addMethodChaining( 'label', label );
+addMethodChaining( 'setName', setName );

+ 2 - 2
src/nodes/core/UniformNode.js

@@ -172,10 +172,10 @@ class UniformNode extends InputNode {
 
 		const sharedNodeType = sharedNode.getInputType( builder );
 
-		const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.label );
+		const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.nodeName );
 		const uniformName = builder.getPropertyName( nodeUniform );
 
-		if ( builder.context.label !== undefined ) delete builder.context.label;
+		if ( builder.context.nodeName !== undefined ) delete builder.context.nodeName;
 
 		//
 

+ 2 - 2
src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

@@ -249,7 +249,7 @@ ${ flowData.code }
 			attribute.pboNode = pbo;
 			attribute.pbo = pbo.value;
 
-			this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
+			this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
 
 		}
 
@@ -293,7 +293,7 @@ ${ flowData.code }
 
 		}
 
-		const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
+		const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
 		const textureName = this.getPropertyName( nodeUniform );
 
 		this.increaseUsage( indexNode ); // force cache generate to be used as index in x,y

粤ICP备19079148号