Skip to content

Commit 15c438a

Browse files
authored
TSL: Add missing label() rename (#31546)
* add missing `label()` rename * cleanup * rename `preferredName` -> `nodeName`
1 parent 0f24661 commit 15c438a

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

examples/webgpu_tsl_editor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
const uv0 = uv();
129129
const animateUv = vec2( uv0.x.add( oscSine( scaledTime ) ), uv0.y );
130130
131-
// label is optional
131+
// .setName() is optional
132132
const myMap = texture( samplerTexture, animateUv ).rgb.setName( 'myTexture' );
133133
const myColor = uniform( new THREE.Color( 0x0066ff ) ).setName( 'myColor' );
134134
const opacity = .7;
@@ -173,7 +173,7 @@
173173
const AsyncFunction = async function () {}.constructor;
174174

175175
const tslCode = `let output = null;\n${ editor.getValue() }\nreturn { output };`;
176-
const nodes = await ( new AsyncFunction( 'three/webgpu', tslCode )( THREE ) );
176+
const nodes = await ( new AsyncFunction( 'THREE', tslCode )( THREE ) );
177177

178178
mesh.material.fragmentNode = nodes.output;
179179
mesh.material.needsUpdate = true;

src/Three.TSL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ export const scriptable = TSL.scriptable;
471471
export const scriptableValue = TSL.scriptableValue;
472472
export const select = TSL.select;
473473
export const setCurrentStack = TSL.setCurrentStack;
474+
export const setName = TSL.setName;
474475
export const shaderStages = TSL.shaderStages;
475476
export const shadow = TSL.shadow;
476477
export const shadowPositionWorld = TSL.shadowPositionWorld;

src/nodes/accessors/ReferenceNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class ReferenceNode extends Node {
282282

283283
}
284284

285-
if ( this.name !== null ) node.label( this.name );
285+
if ( this.name !== null ) node.setName( this.name );
286286

287287
this.node = node.getSelf();
288288

src/nodes/core/ContextNode.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,35 @@ export default ContextNode;
131131
*/
132132
export const context = /*@__PURE__*/ nodeProxy( ContextNode ).setParameterLength( 1, 2 );
133133

134+
/**
135+
* TSL function for defining a name for the context value for a given node.
136+
*
137+
* @tsl
138+
* @function
139+
* @param {Node} node - The node whose context should be modified.
140+
* @param {string} name - The name to set.
141+
* @returns {ContextNode}
142+
*/
143+
export const setName = ( node, name ) => context( node, { nodeName: name } );
144+
134145
/**
135146
* TSL function for defining a label context value for a given node.
136147
*
137148
* @tsl
138149
* @function
150+
* @deprecated
139151
* @param {Node} node - The node whose context should be modified.
140152
* @param {string} name - The name/label to set.
141153
* @returns {ContextNode}
142154
*/
143-
export const label = ( node, name ) => context( node, { label: name } );
155+
export function label( node, name ) {
156+
157+
console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
158+
159+
return setName( node, name );
160+
161+
}
144162

145163
addMethodChaining( 'context', context );
146164
addMethodChaining( 'label', label );
165+
addMethodChaining( 'setName', setName );

src/nodes/core/UniformNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ class UniformNode extends InputNode {
172172

173173
const sharedNodeType = sharedNode.getInputType( builder );
174174

175-
const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.label );
175+
const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.nodeName );
176176
const uniformName = builder.getPropertyName( nodeUniform );
177177

178-
if ( builder.context.label !== undefined ) delete builder.context.label;
178+
if ( builder.context.nodeName !== undefined ) delete builder.context.nodeName;
179179

180180
//
181181

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ ${ flowData.code }
249249
attribute.pboNode = pbo;
250250
attribute.pbo = pbo.value;
251251

252-
this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
252+
this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
253253

254254
}
255255

@@ -293,7 +293,7 @@ ${ flowData.code }
293293

294294
}
295295

296-
const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
296+
const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.nodeName );
297297
const textureName = this.getPropertyName( nodeUniform );
298298

299299
this.increaseUsage( indexNode ); // force cache generate to be used as index in x,y

0 commit comments

Comments
 (0)