Skip to content

Commit a7500fd

Browse files
authored
TSL: add addMethodsChaining (mrdoob#30201)
* TSL: add `addMethodsChaining` * usage ES6 * Revert "usage ES6" This reverts commit a91ea44. * cleanup ---------
1 parent 62b2a82 commit a7500fd

File tree

3 files changed

+119
-107
lines changed

3 files changed

+119
-107
lines changed

src/nodes/math/MathNode.js

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import TempNode from '../core/TempNode.js';
22
import { sub, mul, div } from './OperatorNode.js';
3-
import { addMethodChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
3+
import { addMethodsChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
44
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../../constants.js';
55

66
/** @module MathNode **/
@@ -950,61 +950,62 @@ export const inversesqrt = inverseSqrt;
950950

951951
// Method chaining
952952

953-
addMethodChaining( 'all', all );
954-
addMethodChaining( 'any', any );
955-
addMethodChaining( 'equals', equals );
956-
957-
addMethodChaining( 'radians', radians );
958-
addMethodChaining( 'degrees', degrees );
959-
addMethodChaining( 'exp', exp );
960-
addMethodChaining( 'exp2', exp2 );
961-
addMethodChaining( 'log', log );
962-
addMethodChaining( 'log2', log2 );
963-
addMethodChaining( 'sqrt', sqrt );
964-
addMethodChaining( 'inverseSqrt', inverseSqrt );
965-
addMethodChaining( 'floor', floor );
966-
addMethodChaining( 'ceil', ceil );
967-
addMethodChaining( 'normalize', normalize );
968-
addMethodChaining( 'fract', fract );
969-
addMethodChaining( 'sin', sin );
970-
addMethodChaining( 'cos', cos );
971-
addMethodChaining( 'tan', tan );
972-
addMethodChaining( 'asin', asin );
973-
addMethodChaining( 'acos', acos );
974-
addMethodChaining( 'atan', atan );
975-
addMethodChaining( 'abs', abs );
976-
addMethodChaining( 'sign', sign );
977-
addMethodChaining( 'length', length );
978-
addMethodChaining( 'lengthSq', lengthSq );
979-
addMethodChaining( 'negate', negate );
980-
addMethodChaining( 'oneMinus', oneMinus );
981-
addMethodChaining( 'dFdx', dFdx );
982-
addMethodChaining( 'dFdy', dFdy );
983-
addMethodChaining( 'round', round );
984-
addMethodChaining( 'reciprocal', reciprocal );
985-
addMethodChaining( 'trunc', trunc );
986-
addMethodChaining( 'fwidth', fwidth );
987-
addMethodChaining( 'atan2', atan2 );
988-
addMethodChaining( 'min', min );
989-
addMethodChaining( 'max', max );
990-
addMethodChaining( 'mod', mod );
991-
addMethodChaining( 'step', step );
992-
addMethodChaining( 'reflect', reflect );
993-
addMethodChaining( 'distance', distance );
994-
addMethodChaining( 'dot', dot );
995-
addMethodChaining( 'cross', cross );
996-
addMethodChaining( 'pow', pow );
997-
addMethodChaining( 'pow2', pow2 );
998-
addMethodChaining( 'pow3', pow3 );
999-
addMethodChaining( 'pow4', pow4 );
1000-
addMethodChaining( 'transformDirection', transformDirection );
1001-
addMethodChaining( 'mix', mixElement );
1002-
addMethodChaining( 'clamp', clamp );
1003-
addMethodChaining( 'refract', refract );
1004-
addMethodChaining( 'smoothstep', smoothstepElement );
1005-
addMethodChaining( 'faceForward', faceForward );
1006-
addMethodChaining( 'difference', difference );
1007-
addMethodChaining( 'saturate', saturate );
1008-
addMethodChaining( 'cbrt', cbrt );
1009-
addMethodChaining( 'transpose', transpose );
1010-
addMethodChaining( 'rand', rand );
953+
addMethodsChaining( {
954+
all: all,
955+
any: any,
956+
equals: equals,
957+
radians: radians,
958+
degrees: degrees,
959+
exp: exp,
960+
exp2: exp2,
961+
log: log,
962+
log2: log2,
963+
sqrt: sqrt,
964+
inverseSqrt: inverseSqrt,
965+
floor: floor,
966+
ceil: ceil,
967+
normalize: normalize,
968+
fract: fract,
969+
sin: sin,
970+
cos: cos,
971+
tan: tan,
972+
asin: asin,
973+
acos: acos,
974+
atan: atan,
975+
abs: abs,
976+
sign: sign,
977+
length: length,
978+
lengthSq: lengthSq,
979+
negate: negate,
980+
oneMinus: oneMinus,
981+
dFdx: dFdx,
982+
dFdy: dFdy,
983+
round: round,
984+
reciprocal: reciprocal,
985+
trunc: trunc,
986+
fwidth: fwidth,
987+
atan2: atan2,
988+
min: min,
989+
max: max,
990+
mod: mod,
991+
step: step,
992+
reflect: reflect,
993+
distance: distance,
994+
dot: dot,
995+
cross: cross,
996+
pow: pow,
997+
pow2: pow2,
998+
pow3: pow3,
999+
pow4: pow4,
1000+
transformDirection: transformDirection,
1001+
mix: mixElement,
1002+
clamp: clamp,
1003+
refract: refract,
1004+
smoothstep: smoothstepElement,
1005+
faceForward: faceForward,
1006+
difference: difference,
1007+
saturate: saturate,
1008+
cbrt: cbrt,
1009+
transpose: transpose,
1010+
rand: rand
1011+
} );

src/nodes/math/OperatorNode.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import TempNode from '../core/TempNode.js';
2-
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
2+
import { addMethodsChaining, nodeProxy } from '../tsl/TSLCore.js';
33

44
/** @module OperatorNode **/
55

@@ -519,34 +519,34 @@ export const shiftLeft = /*@__PURE__*/ nodeProxy( OperatorNode, '<<' );
519519
*/
520520
export const shiftRight = /*@__PURE__*/ nodeProxy( OperatorNode, '>>' );
521521

522-
addMethodChaining( 'add', add );
523-
addMethodChaining( 'sub', sub );
524-
addMethodChaining( 'mul', mul );
525-
addMethodChaining( 'div', div );
526-
addMethodChaining( 'modInt', modInt );
527-
addMethodChaining( 'equal', equal );
528-
addMethodChaining( 'notEqual', notEqual );
529-
addMethodChaining( 'lessThan', lessThan );
530-
addMethodChaining( 'greaterThan', greaterThan );
531-
addMethodChaining( 'lessThanEqual', lessThanEqual );
532-
addMethodChaining( 'greaterThanEqual', greaterThanEqual );
533-
addMethodChaining( 'and', and );
534-
addMethodChaining( 'or', or );
535-
addMethodChaining( 'not', not );
536-
addMethodChaining( 'xor', xor );
537-
addMethodChaining( 'bitAnd', bitAnd );
538-
addMethodChaining( 'bitNot', bitNot );
539-
addMethodChaining( 'bitOr', bitOr );
540-
addMethodChaining( 'bitXor', bitXor );
541-
addMethodChaining( 'shiftLeft', shiftLeft );
542-
addMethodChaining( 'shiftRight', shiftRight );
543-
544-
545522
export const remainder = ( ...params ) => { // @deprecated, r168
546523

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

550527
};
551528

552-
addMethodChaining( 'remainder', remainder );
529+
addMethodsChaining( {
530+
add: add,
531+
sub: sub,
532+
mul: mul,
533+
div: div,
534+
modInt: modInt,
535+
equal: equal,
536+
notEqual: notEqual,
537+
lessThan: lessThan,
538+
greaterThan: greaterThan,
539+
lessThanEqual: lessThanEqual,
540+
greaterThanEqual: greaterThanEqual,
541+
and: and,
542+
or: or,
543+
not: not,
544+
xor: xor,
545+
bitAnd: bitAnd,
546+
bitNot: bitNot,
547+
bitOr: bitOr,
548+
bitXor: bitXor,
549+
shiftLeft: shiftLeft,
550+
shiftRight: shiftRight,
551+
remainder: remainder
552+
} );

src/nodes/tsl/TSLCore.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export function addMethodChaining( name, nodeElement ) {
2929

3030
}
3131

32+
export function addMethodsChaining( object ) {
33+
34+
for ( const key in object ) {
35+
36+
addMethodChaining( key, object[ key ] );
37+
38+
}
39+
40+
}
41+
3242
const parseSwizzle = ( props ) => props.replace( /r|s/g, 'x' ).replace( /g|t/g, 'y' ).replace( /b|p/g, 'z' ).replace( /a|q/g, 'w' );
3343
const parseSwizzleAndSort = ( props ) => parseSwizzle( props ).split( '' ).sort().join( '' );
3444

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

632-
addMethodChaining( 'toColor', color );
633-
addMethodChaining( 'toFloat', float );
634-
addMethodChaining( 'toInt', int );
635-
addMethodChaining( 'toUint', uint );
636-
addMethodChaining( 'toBool', bool );
637-
addMethodChaining( 'toVec2', vec2 );
638-
addMethodChaining( 'toIVec2', ivec2 );
639-
addMethodChaining( 'toUVec2', uvec2 );
640-
addMethodChaining( 'toBVec2', bvec2 );
641-
addMethodChaining( 'toVec3', vec3 );
642-
addMethodChaining( 'toIVec3', ivec3 );
643-
addMethodChaining( 'toUVec3', uvec3 );
644-
addMethodChaining( 'toBVec3', bvec3 );
645-
addMethodChaining( 'toVec4', vec4 );
646-
addMethodChaining( 'toIVec4', ivec4 );
647-
addMethodChaining( 'toUVec4', uvec4 );
648-
addMethodChaining( 'toBVec4', bvec4 );
649-
addMethodChaining( 'toMat2', mat2 );
650-
addMethodChaining( 'toMat3', mat3 );
651-
addMethodChaining( 'toMat4', mat4 );
652-
653642
// basic nodes
654643

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

659-
addMethodChaining( 'element', element );
660-
addMethodChaining( 'convert', convert );
648+
addMethodsChaining( {
649+
toColor: color,
650+
toFloat: float,
651+
toInt: int,
652+
toUint: uint,
653+
toBool: bool,
654+
toVec2: vec2,
655+
toIVec2: ivec2,
656+
toUVec2: uvec2,
657+
toBVec2: bvec2,
658+
toVec3: vec3,
659+
toIVec3: ivec3,
660+
toUVec3: uvec3,
661+
toBVec3: bvec3,
662+
toVec4: vec4,
663+
toIVec4: ivec4,
664+
toUVec4: uvec4,
665+
toBVec4: bvec4,
666+
toMat2: mat2,
667+
toMat3: mat3,
668+
toMat4: mat4,
669+
element: element,
670+
convert: convert
671+
} );

0 commit comments

Comments
 (0)