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

TSL: add addMethodsChaining #30201

Merged
merged 4 commits into from
Dec 26, 2024
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
119 changes: 60 additions & 59 deletions src/nodes/math/MathNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TempNode from '../core/TempNode.js';
import { sub, mul, div } from './OperatorNode.js';
import { addMethodChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
import { addMethodsChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../../constants.js';

/** @module MathNode **/
Expand Down Expand Up @@ -950,61 +950,62 @@ export const inversesqrt = inverseSqrt;

// Method chaining

addMethodChaining( 'all', all );
addMethodChaining( 'any', any );
addMethodChaining( 'equals', equals );

addMethodChaining( 'radians', radians );
addMethodChaining( 'degrees', degrees );
addMethodChaining( 'exp', exp );
addMethodChaining( 'exp2', exp2 );
addMethodChaining( 'log', log );
addMethodChaining( 'log2', log2 );
addMethodChaining( 'sqrt', sqrt );
addMethodChaining( 'inverseSqrt', inverseSqrt );
addMethodChaining( 'floor', floor );
addMethodChaining( 'ceil', ceil );
addMethodChaining( 'normalize', normalize );
addMethodChaining( 'fract', fract );
addMethodChaining( 'sin', sin );
addMethodChaining( 'cos', cos );
addMethodChaining( 'tan', tan );
addMethodChaining( 'asin', asin );
addMethodChaining( 'acos', acos );
addMethodChaining( 'atan', atan );
addMethodChaining( 'abs', abs );
addMethodChaining( 'sign', sign );
addMethodChaining( 'length', length );
addMethodChaining( 'lengthSq', lengthSq );
addMethodChaining( 'negate', negate );
addMethodChaining( 'oneMinus', oneMinus );
addMethodChaining( 'dFdx', dFdx );
addMethodChaining( 'dFdy', dFdy );
addMethodChaining( 'round', round );
addMethodChaining( 'reciprocal', reciprocal );
addMethodChaining( 'trunc', trunc );
addMethodChaining( 'fwidth', fwidth );
addMethodChaining( 'atan2', atan2 );
addMethodChaining( 'min', min );
addMethodChaining( 'max', max );
addMethodChaining( 'mod', mod );
addMethodChaining( 'step', step );
addMethodChaining( 'reflect', reflect );
addMethodChaining( 'distance', distance );
addMethodChaining( 'dot', dot );
addMethodChaining( 'cross', cross );
addMethodChaining( 'pow', pow );
addMethodChaining( 'pow2', pow2 );
addMethodChaining( 'pow3', pow3 );
addMethodChaining( 'pow4', pow4 );
addMethodChaining( 'transformDirection', transformDirection );
addMethodChaining( 'mix', mixElement );
addMethodChaining( 'clamp', clamp );
addMethodChaining( 'refract', refract );
addMethodChaining( 'smoothstep', smoothstepElement );
addMethodChaining( 'faceForward', faceForward );
addMethodChaining( 'difference', difference );
addMethodChaining( 'saturate', saturate );
addMethodChaining( 'cbrt', cbrt );
addMethodChaining( 'transpose', transpose );
addMethodChaining( 'rand', rand );
addMethodsChaining( {
all: all,
any: any,
equals: equals,
radians: radians,
degrees: degrees,
exp: exp,
exp2: exp2,
log: log,
log2: log2,
sqrt: sqrt,
inverseSqrt: inverseSqrt,
floor: floor,
ceil: ceil,
normalize: normalize,
fract: fract,
sin: sin,
cos: cos,
tan: tan,
asin: asin,
acos: acos,
atan: atan,
abs: abs,
sign: sign,
length: length,
lengthSq: lengthSq,
negate: negate,
oneMinus: oneMinus,
dFdx: dFdx,
dFdy: dFdy,
round: round,
reciprocal: reciprocal,
trunc: trunc,
fwidth: fwidth,
atan2: atan2,
min: min,
max: max,
mod: mod,
step: step,
reflect: reflect,
distance: distance,
dot: dot,
cross: cross,
pow: pow,
pow2: pow2,
pow3: pow3,
pow4: pow4,
transformDirection: transformDirection,
mix: mixElement,
clamp: clamp,
refract: refract,
smoothstep: smoothstepElement,
faceForward: faceForward,
difference: difference,
saturate: saturate,
cbrt: cbrt,
transpose: transpose,
rand: rand
} );
50 changes: 25 additions & 25 deletions src/nodes/math/OperatorNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TempNode from '../core/TempNode.js';
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
import { addMethodsChaining, nodeProxy } from '../tsl/TSLCore.js';

/** @module OperatorNode **/

Expand Down Expand Up @@ -519,34 +519,34 @@ export const shiftLeft = /*@__PURE__*/ nodeProxy( OperatorNode, '<<' );
*/
export const shiftRight = /*@__PURE__*/ nodeProxy( OperatorNode, '>>' );

addMethodChaining( 'add', add );
addMethodChaining( 'sub', sub );
addMethodChaining( 'mul', mul );
addMethodChaining( 'div', div );
addMethodChaining( 'modInt', modInt );
addMethodChaining( 'equal', equal );
addMethodChaining( 'notEqual', notEqual );
addMethodChaining( 'lessThan', lessThan );
addMethodChaining( 'greaterThan', greaterThan );
addMethodChaining( 'lessThanEqual', lessThanEqual );
addMethodChaining( 'greaterThanEqual', greaterThanEqual );
addMethodChaining( 'and', and );
addMethodChaining( 'or', or );
addMethodChaining( 'not', not );
addMethodChaining( 'xor', xor );
addMethodChaining( 'bitAnd', bitAnd );
addMethodChaining( 'bitNot', bitNot );
addMethodChaining( 'bitOr', bitOr );
addMethodChaining( 'bitXor', bitXor );
addMethodChaining( 'shiftLeft', shiftLeft );
addMethodChaining( 'shiftRight', shiftRight );


export const remainder = ( ...params ) => { // @deprecated, r168

console.warn( 'TSL.OperatorNode: .remainder() has been renamed to .modInt().' );
return modInt( ...params );

};

addMethodChaining( 'remainder', remainder );
addMethodsChaining( {
add: add,
sub: sub,
mul: mul,
div: div,
modInt: modInt,
equal: equal,
notEqual: notEqual,
lessThan: lessThan,
greaterThan: greaterThan,
lessThanEqual: lessThanEqual,
greaterThanEqual: greaterThanEqual,
and: and,
or: or,
not: not,
xor: xor,
bitAnd: bitAnd,
bitNot: bitNot,
bitOr: bitOr,
bitXor: bitXor,
shiftLeft: shiftLeft,
shiftRight: shiftRight,
remainder: remainder
} );
57 changes: 34 additions & 23 deletions src/nodes/tsl/TSLCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export function addMethodChaining( name, nodeElement ) {

}

export function addMethodsChaining( object ) {

for ( const key in object ) {

addMethodChaining( key, object[ key ] );

}

}

const parseSwizzle = ( props ) => props.replace( /r|s/g, 'x' ).replace( /g|t/g, 'y' ).replace( /b|p/g, 'z' ).replace( /a|q/g, 'w' );
const parseSwizzleAndSort = ( props ) => parseSwizzle( props ).split( '' ).sort().join( '' );

Expand Down Expand Up @@ -629,32 +639,33 @@ export const mat4 = new ConvertType( 'mat4' );
export const string = ( value = '' ) => nodeObject( new ConstNode( value, 'string' ) );
export const arrayBuffer = ( value ) => nodeObject( new ConstNode( value, 'ArrayBuffer' ) );

addMethodChaining( 'toColor', color );
addMethodChaining( 'toFloat', float );
addMethodChaining( 'toInt', int );
addMethodChaining( 'toUint', uint );
addMethodChaining( 'toBool', bool );
addMethodChaining( 'toVec2', vec2 );
addMethodChaining( 'toIVec2', ivec2 );
addMethodChaining( 'toUVec2', uvec2 );
addMethodChaining( 'toBVec2', bvec2 );
addMethodChaining( 'toVec3', vec3 );
addMethodChaining( 'toIVec3', ivec3 );
addMethodChaining( 'toUVec3', uvec3 );
addMethodChaining( 'toBVec3', bvec3 );
addMethodChaining( 'toVec4', vec4 );
addMethodChaining( 'toIVec4', ivec4 );
addMethodChaining( 'toUVec4', uvec4 );
addMethodChaining( 'toBVec4', bvec4 );
addMethodChaining( 'toMat2', mat2 );
addMethodChaining( 'toMat3', mat3 );
addMethodChaining( 'toMat4', mat4 );

// basic nodes

export const element = /*@__PURE__*/ nodeProxy( ArrayElementNode );
export const convert = ( node, types ) => nodeObject( new ConvertNode( nodeObject( node ), types ) );
export const split = ( node, channels ) => nodeObject( new SplitNode( nodeObject( node ), channels ) );

addMethodChaining( 'element', element );
addMethodChaining( 'convert', convert );
addMethodsChaining( {
toColor: color,
toFloat: float,
toInt: int,
toUint: uint,
toBool: bool,
toVec2: vec2,
toIVec2: ivec2,
toUVec2: uvec2,
toBVec2: bvec2,
toVec3: vec3,
toIVec3: ivec3,
toUVec3: uvec3,
toBVec3: bvec3,
toVec4: vec4,
toIVec4: ivec4,
toUVec4: uvec4,
toBVec4: bvec4,
toMat2: mat2,
toMat3: mat3,
toMat4: mat4,
element: element,
convert: convert
} );
Loading