Skip to content

Commit

Permalink
Fix: add a r168 compat to MToonNodeMaterial
Browse files Browse the repository at this point in the history
Starting from r168, `setupNormal` returns the normal node instead of assigning inside the `NodeMaterial.setupNormal`

See: mrdoob/three.js#29137
  • Loading branch information
0b5vr committed Aug 19, 2024
1 parent ec7ddf8 commit 5bd5b17
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class MToonNodeMaterial extends THREE.NodeMaterial {
parametricRim.assign(this._setupParametricRimNode());
}

public setupNormal(builder: THREE.NodeBuilder): void {
public setupNormal(builder: THREE.NodeBuilder): THREE.ShaderNodeObject<THREE.Node> | null | undefined {
// we must apply uv scroll to the normalMap
// this.normalNode will be used in super.setupNormal() so we temporarily replace it
const tempNormalNode = this.normalNode;
Expand All @@ -271,11 +271,25 @@ export class MToonNodeMaterial extends THREE.NodeMaterial {
}
}

// the ordinary normal setup
super.setupNormal(builder);
// COMPAT r168: `setupNormal` now returns the normal node
// instead of assigning inside the `super.setupNormal`
// See: https://github.com/mrdoob/three.js/pull/29137
const threeRevision = parseInt(THREE.REVISION, 10);
if (threeRevision >= 168) {
const ret = this.normalNode as THREE.ShaderNodeObject<THREE.Node> | null;

// revert the normalNode
this.normalNode = tempNormalNode;
// revert the normalNode
this.normalNode = tempNormalNode;

return ret;
} else {
// pre-r168
// the ordinary normal setup
super.setupNormal(builder);

// revert the normalNode
this.normalNode = tempNormalNode;
}
}

public setupLighting(builder: THREE.NodeBuilder): THREE.Node {
Expand Down

0 comments on commit 5bd5b17

Please sign in to comment.