diff --git a/src/nodes/math/MathNode.js b/src/nodes/math/MathNode.js index 1d36e805c97f66..522f0c21b4fff4 100644 --- a/src/nodes/math/MathNode.js +++ b/src/nodes/math/MathNode.js @@ -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 **/ @@ -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 +} ); diff --git a/src/nodes/math/OperatorNode.js b/src/nodes/math/OperatorNode.js index 9b744237729205..6fedb45fa9c632 100644 --- a/src/nodes/math/OperatorNode.js +++ b/src/nodes/math/OperatorNode.js @@ -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 **/ @@ -519,29 +519,6 @@ 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().' ); @@ -549,4 +526,27 @@ export const remainder = ( ...params ) => { // @deprecated, r168 }; -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 +} ); diff --git a/src/nodes/tsl/TSLCore.js b/src/nodes/tsl/TSLCore.js index 612362d8eaca00..a578c84b10cb74 100644 --- a/src/nodes/tsl/TSLCore.js +++ b/src/nodes/tsl/TSLCore.js @@ -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( '' ); @@ -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 +} );