From 5bd5b17093533b75bd0300897676183bbefcc56a Mon Sep 17 00:00:00 2001 From: 0b5vr <0b5vr@0b5vr.com> Date: Mon, 19 Aug 2024 18:37:14 +0900 Subject: [PATCH 1/7] Fix: add a r168 compat to MToonNodeMaterial Starting from r168, `setupNormal` returns the normal node instead of assigning inside the `NodeMaterial.setupNormal` See: https://github.com/mrdoob/three.js/pull/29137 --- .../src/nodes/MToonNodeMaterial.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts b/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts index b707c2bd1..a6e6a35d3 100644 --- a/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts +++ b/packages/three-vrm-materials-mtoon/src/nodes/MToonNodeMaterial.ts @@ -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 | 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; @@ -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 | 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 { From 2dd95f149b926f6e162d2307335a74dae218f1d0 Mon Sep 17 00:00:00 2001 From: 0b5vr <0b5vr@0b5vr.com> Date: Mon, 19 Aug 2024 18:46:05 +0900 Subject: [PATCH 2/7] Fix: add a r168 compat to tslFn calling In r168, `tslFn` has been renamed to `Fn` See: https://github.com/mrdoob/three.js/pull/29064 --- .../src/nodes/MToonLightingModel.ts | 7 ++++--- .../src/nodes/mtoonParametricRim.ts | 3 ++- .../src/nodes/utils/FnCompat.ts | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 packages/three-vrm-materials-mtoon/src/nodes/utils/FnCompat.ts diff --git a/packages/three-vrm-materials-mtoon/src/nodes/MToonLightingModel.ts b/packages/three-vrm-materials-mtoon/src/nodes/MToonLightingModel.ts index 9c7b35ef5..26a3aa27c 100644 --- a/packages/three-vrm-materials-mtoon/src/nodes/MToonLightingModel.ts +++ b/packages/three-vrm-materials-mtoon/src/nodes/MToonLightingModel.ts @@ -8,10 +8,11 @@ import { shadingShift, shadingToony, } from './immutableNodes'; +import { FnCompat } from './utils/FnCompat'; // TODO: 0% confidence about function types. -const linearstep = THREE.tslFn( +const linearstep = FnCompat( ({ a, b, @@ -30,7 +31,7 @@ const linearstep = THREE.tslFn( /** * Convert NdotL into toon shading factor using shadingShift and shadingToony */ -const getShading = THREE.tslFn(({ dotNL }: { dotNL: THREE.ShaderNodeObject }) => { +const getShading = FnCompat(({ dotNL }: { dotNL: THREE.ShaderNodeObject }) => { const shadow = 1.0; // TODO const feather = THREE.float(1.0).sub(shadingToony); @@ -48,7 +49,7 @@ const getShading = THREE.tslFn(({ dotNL }: { dotNL: THREE.ShaderNodeObject { + // COMPAT r168: `tslFn()` has been renamed to `Fn()` + // See: https://github.com/mrdoob/three.js/pull/29064 + const threeRevision = parseInt(THREE.REVISION, 10); + if (threeRevision >= 168) { + return (THREE as any).Fn(jsFunc); + } else { + return (THREE as any).tslFn(jsFunc); + } +}; From 2f91aeb50f9552196fffe490790f4967ee41d3ef Mon Sep 17 00:00:00 2001 From: 0b5vr <0b5vr@0b5vr.com> Date: Fri, 30 Aug 2024 17:49:52 +0900 Subject: [PATCH 3/7] deps: Bump three to r168 @types/three is not released yet --- README.md | 4 ++-- packages/three-vrm-animation/examples/dnd.html | 4 ++-- packages/three-vrm-animation/examples/loader-plugin.html | 4 ++-- packages/three-vrm-animation/package.json | 2 +- packages/three-vrm-core/examples/expressions.html | 4 ++-- packages/three-vrm-core/examples/firstPerson.html | 4 ++-- packages/three-vrm-core/examples/humanoid.html | 4 ++-- .../three-vrm-core/examples/humanoidAnimation/index.html | 4 ++-- packages/three-vrm-core/examples/lookAt.html | 4 ++-- packages/three-vrm-core/examples/meta.html | 4 ++-- packages/three-vrm-core/package.json | 2 +- .../examples/loader-plugin.html | 4 ++-- .../package.json | 2 +- .../examples/emissive-strength.html | 4 ++-- .../three-vrm-materials-mtoon/examples/feature-test.html | 4 ++-- .../three-vrm-materials-mtoon/examples/loader-plugin.html | 4 ++-- .../examples/webgpu-feature-test.html | 6 +++--- .../examples/webgpu-loader-plugin.html | 6 +++--- packages/three-vrm-materials-mtoon/package.json | 2 +- packages/three-vrm-materials-v0compat/package.json | 2 +- packages/three-vrm-node-constraint/examples/aim.html | 4 ++-- packages/three-vrm-node-constraint/examples/importer.html | 4 ++-- packages/three-vrm-node-constraint/examples/roll.html | 4 ++-- packages/three-vrm-node-constraint/examples/rotation.html | 4 ++-- .../three-vrm-node-constraint/examples/upper-arm.html | 4 ++-- packages/three-vrm-node-constraint/package.json | 2 +- packages/three-vrm-springbone/examples/collider.html | 4 ++-- packages/three-vrm-springbone/examples/loader-plugin.html | 4 ++-- packages/three-vrm-springbone/examples/multiple.html | 4 ++-- packages/three-vrm-springbone/examples/single.html | 4 ++-- packages/three-vrm-springbone/package.json | 2 +- packages/three-vrm/README.md | 4 ++-- packages/three-vrm/examples/animations.html | 4 ++-- packages/three-vrm/examples/basic.html | 4 ++-- packages/three-vrm/examples/bones.html | 4 ++-- packages/three-vrm/examples/debug.html | 4 ++-- packages/three-vrm/examples/dnd.html | 4 ++-- packages/three-vrm/examples/expressions.html | 4 ++-- packages/three-vrm/examples/firstperson.html | 4 ++-- packages/three-vrm/examples/humanoidAnimation/index.html | 4 ++-- packages/three-vrm/examples/lookat-advanced.html | 4 ++-- packages/three-vrm/examples/lookat.html | 4 ++-- packages/three-vrm/examples/materials-debug.html | 4 ++-- packages/three-vrm/examples/meta.html | 4 ++-- packages/three-vrm/examples/mouse.html | 4 ++-- packages/three-vrm/examples/webgpu-dnd.html | 6 +++--- packages/three-vrm/package.json | 2 +- yarn.lock | 8 ++++---- 48 files changed, 93 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index b309fd36b..1351d2211 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ You can import all the dependencies via CDN like [jsDelivr](https://www.jsdelivr