From e47807684f40b410f7b4fa60ae6f65e627470fdc Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 17 Sep 2024 16:46:49 -0400 Subject: [PATCH 1/2] feat: added invert implementation - allow invert to be a number, vec 2|3|4, or color, subtracting the value from an optionally inputted amount field (which is defaulted to all parts 1 of the input type) --- examples/jsm/loaders/MaterialXLoader.js | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/examples/jsm/loaders/MaterialXLoader.js b/examples/jsm/loaders/MaterialXLoader.js index 051438732d6047..a50dad797b90d3 100644 --- a/examples/jsm/loaders/MaterialXLoader.js +++ b/examples/jsm/loaders/MaterialXLoader.js @@ -1,4 +1,4 @@ -import { FileLoader, Loader, TextureLoader, MeshBasicNodeMaterial, MeshPhysicalNodeMaterial, RepeatWrapping } from 'three'; +import { Color, FileLoader, Loader, TextureLoader, MeshBasicNodeMaterial, MeshPhysicalNodeMaterial, RepeatWrapping, Vector2, Vector3, Vector4 } from 'three'; import { float, bool, int, vec2, vec3, vec4, color, texture, @@ -44,6 +44,37 @@ const mx_power = ( in1, in2 = float( 1 ) ) => pow( in1, in2 ); const mx_atan2 = ( in1 = float( 0 ), in2 = float( 1 ) ) => atan2( in1, in2 ); const mx_timer = () => timerLocal(); const mx_frame = () => frameId; +const mx_invert = ( in1, amount = null ) => { + + if ( amount === null ) { + + if ( typeof in1.value === 'number' ) { + + amount = 1.0; + + } else if ( in1.value.isVector2 ) { + + amount = new Vector2( 1, 1 ); + + } else if ( in1.value.isVector3 ) { + + amount = new Vector3( 1, 1, 1 ); + + } else if ( in1.value.isVector4 ) { + + amount = new Vector4( 1, 1, 1, 1 ); + + } else if ( in1.value.isColor ) { + + amount = new Color( 1, 1, 1 ); + + } + + } + + return sub( amount, in1 ); + +}; const MXElements = [ @@ -131,6 +162,7 @@ const MXElements = [ //new MtlXElement( 'separate2', ... ), //new MtlXElement( 'separate3', ... ), //new MtlXElement( 'separate4', ... ) + new MXElement( 'invert', mx_invert, [ 'in', 'amount' ] ), new MXElement( 'time', mx_timer ), new MXElement( 'frame', mx_frame ) From b28bdef9aa189a15755d8a714e87a9fa42c184e3 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 19 Sep 2024 10:10:38 -0400 Subject: [PATCH 2/2] feat: update invert - simplified invert function - removed unneeded imports - moved invert to math nodes --- examples/jsm/loaders/MaterialXLoader.js | 36 +++---------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/examples/jsm/loaders/MaterialXLoader.js b/examples/jsm/loaders/MaterialXLoader.js index a50dad797b90d3..2670ef08705b1e 100644 --- a/examples/jsm/loaders/MaterialXLoader.js +++ b/examples/jsm/loaders/MaterialXLoader.js @@ -1,4 +1,4 @@ -import { Color, FileLoader, Loader, TextureLoader, MeshBasicNodeMaterial, MeshPhysicalNodeMaterial, RepeatWrapping, Vector2, Vector3, Vector4 } from 'three'; +import { FileLoader, Loader, TextureLoader, MeshBasicNodeMaterial, MeshPhysicalNodeMaterial, RepeatWrapping } from 'three'; import { float, bool, int, vec2, vec3, vec4, color, texture, @@ -44,37 +44,7 @@ const mx_power = ( in1, in2 = float( 1 ) ) => pow( in1, in2 ); const mx_atan2 = ( in1 = float( 0 ), in2 = float( 1 ) ) => atan2( in1, in2 ); const mx_timer = () => timerLocal(); const mx_frame = () => frameId; -const mx_invert = ( in1, amount = null ) => { - - if ( amount === null ) { - - if ( typeof in1.value === 'number' ) { - - amount = 1.0; - - } else if ( in1.value.isVector2 ) { - - amount = new Vector2( 1, 1 ); - - } else if ( in1.value.isVector3 ) { - - amount = new Vector3( 1, 1, 1 ); - - } else if ( in1.value.isVector4 ) { - - amount = new Vector4( 1, 1, 1, 1 ); - - } else if ( in1.value.isColor ) { - - amount = new Color( 1, 1, 1 ); - - } - - } - - return sub( amount, in1 ); - -}; +const mx_invert = ( in1, amount = float( 1 ) ) => sub( amount, in1 ); const MXElements = [ @@ -106,6 +76,7 @@ const MXElements = [ new MXElement( 'magnitude', length, [ 'in1', 'in2' ] ), new MXElement( 'dotproduct', dot, [ 'in1', 'in2' ] ), new MXElement( 'crossproduct', cross, [ 'in' ] ), + new MXElement( 'invert', mx_invert, [ 'in', 'amount' ] ), //new MtlXElement( 'transformpoint', ... ), //new MtlXElement( 'transformvector', ... ), //new MtlXElement( 'transformnormal', ... ), @@ -162,7 +133,6 @@ const MXElements = [ //new MtlXElement( 'separate2', ... ), //new MtlXElement( 'separate3', ... ), //new MtlXElement( 'separate4', ... ) - new MXElement( 'invert', mx_invert, [ 'in', 'amount' ] ), new MXElement( 'time', mx_timer ), new MXElement( 'frame', mx_frame )