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: Introduce NodeBuilder.formatOperation #27954

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/nodes/Nodes.js
Expand Up @@ -38,7 +38,7 @@ import * as NodeUtils from './core/NodeUtils.js';
export { NodeUtils };

// math
export { default as MathNode, PI, PI2, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, lengthSq, negate, oneMinus, dFdx, dFdy, round, reciprocal, trunc, fwidth, bitcast, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward, cbrt, all, any, equals } from './math/MathNode.js';
export { default as MathNode, PI, PI2, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, lengthSq, negate, oneMinus, dFdx, dFdy, round, reciprocal, trunc, fwidth, bitcast, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward, cbrt, all, any } from './math/MathNode.js';

export { default as OperatorNode, add, sub, mul, div, remainder, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, not, xor, bitAnd, bitNot, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
export { default as CondNode, cond } from './math/CondNode.js';
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/accessors/TextureSizeNode.js
Expand Up @@ -20,7 +20,7 @@ class TextureSizeNode extends Node {
const textureProperty = this.textureNode.build( builder, 'property' );
const levelNode = this.levelNode.build( builder, 'int' );

return builder.format( `${builder.getMethod( 'textureDimensions' )}( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
return builder.format( builder.formatOperation( '()', 'textureDimensions', [ textureProperty, levelNode ] ), this.getNodeType( builder ), output );

}

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/code/FunctionCallNode.js
Expand Up @@ -74,8 +74,7 @@ class FunctionCallNode extends TempNode {
}

const functionName = functionNode.build( builder, 'property' );

return `${functionName}( ${params.join( ', ' )} )`;
return builder.formatOperation( '()', functionName, params );

}

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/nodes/core/AssignNode.js
Expand Up @@ -75,15 +75,15 @@ class AssignNode extends TempNode {
const sourceVar = builder.getVarFromNode( this, null, targetType );
const sourceProperty = builder.getPropertyName( sourceVar );

builder.addLineFlowCode( `${ sourceProperty } = ${ source }` );
builder.addLineFlowCode( builder.formatOperation( '=', sourceProperty, source ) );

const targetRoot = targetNode.node.context( { assign: true } ).build( builder );

for ( let i = 0; i < targetNode.components.length; i ++ ) {

const component = targetNode.components[ i ];

builder.addLineFlowCode( `${ targetRoot }.${ component } = ${ sourceProperty }[ ${ i } ]` );
builder.addLineFlowCode( builder.formatOperation( '=', `${ targetRoot }.${ component }`, `${ sourceProperty }[ ${ i } ]` ) );

}

Expand All @@ -95,7 +95,7 @@ class AssignNode extends TempNode {

} else {

snippet = `${ target } = ${ source }`;
snippet = builder.formatOperation( '=', target, source );

if ( output === 'void' || sourceType === 'void' ) {

Expand Down