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

TextureNode: Add .getTextureMatrix() #26461

Merged
merged 1 commit into from
Jul 19, 2023
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
2 changes: 2 additions & 0 deletions examples/jsm/nodes/accessors/CubeTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CubeTextureNode extends TextureNode {

}

setUpdateMatrix( /*updateMatrix*/ ) { } // Ignore .updateMatrix for CubeTextureNode

generate( builder, output ) {

const { uvNode, levelNode } = builder.getNodeProperties( this );
Expand Down
26 changes: 14 additions & 12 deletions examples/jsm/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class TextureNode extends UniformNode {
this.levelNode = levelNode;
this.compareNode = compareNode;

this.updateMatrix = uvNode === null;
this.updateMatrix = false;
this.updateType = NodeUpdateType.NONE;

this.setUpdateMatrix( this.updateMatrix );
this.setUpdateMatrix( uvNode === null );

}

Expand All @@ -46,13 +47,17 @@ class TextureNode extends UniformNode {

}

getDefaultUV( uvNode = null ) {
getDefaultUV() {

const texture = this.value;
return uv( this.value.channel );

}

if ( uvNode === null ) uvNode = uv( texture.channel );
getTextureMatrix( uvNode ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe getTransformedUV or getFinalUV? Because this method doesn't return the matrix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTransformedUV() sounds good to me 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!


const texture = this.value;

return uniform( texture.matrix ).mul( vec3( uvNode, 1 ) );
return uniform( texture.matrix ).mul( vec3( uvNode, 1 ) ).xy;

}

Expand All @@ -68,7 +73,6 @@ class TextureNode extends UniformNode {
construct( builder ) {

const properties = builder.getNodeProperties( this );
const texture = this.value;

//

Expand All @@ -80,13 +84,11 @@ class TextureNode extends UniformNode {

}

if ( this.updateMatrix ) {

uvNode = this.getDefaultUV( uvNode );
if ( ! uvNode ) uvNode = this.getDefaultUV();

} else if ( ! uvNode ) {
if ( this.updateMatrix ) {

uvNode = uv( texture.channel );
uvNode = this.getTextureMatrix( uvNode );

}

Expand Down