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

MaterialXLoader: added invert implementation #29433

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
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
34 changes: 33 additions & 1 deletion examples/jsm/loaders/MaterialXLoader.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 ) => {
sunag marked this conversation as resolved.
Show resolved Hide resolved

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 = [

Expand Down Expand Up @@ -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 )
Expand Down