Skip to content

Commit 2dd95f1

Browse files
committed
Fix: add a r168 compat to tslFn calling
In r168, `tslFn` has been renamed to `Fn` See: mrdoob/three.js#29064
1 parent 5bd5b17 commit 2dd95f1

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

packages/three-vrm-materials-mtoon/src/nodes/MToonLightingModel.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
shadingShift,
99
shadingToony,
1010
} from './immutableNodes';
11+
import { FnCompat } from './utils/FnCompat';
1112

1213
// TODO: 0% confidence about function types.
1314

14-
const linearstep = THREE.tslFn(
15+
const linearstep = FnCompat(
1516
({
1617
a,
1718
b,
@@ -30,7 +31,7 @@ const linearstep = THREE.tslFn(
3031
/**
3132
* Convert NdotL into toon shading factor using shadingShift and shadingToony
3233
*/
33-
const getShading = THREE.tslFn(({ dotNL }: { dotNL: THREE.ShaderNodeObject<THREE.Node> }) => {
34+
const getShading = FnCompat(({ dotNL }: { dotNL: THREE.ShaderNodeObject<THREE.Node> }) => {
3435
const shadow = 1.0; // TODO
3536

3637
const feather = THREE.float(1.0).sub(shadingToony);
@@ -48,7 +49,7 @@ const getShading = THREE.tslFn(({ dotNL }: { dotNL: THREE.ShaderNodeObject<THREE
4849
/**
4950
* Mix diffuseColor and shadeColor using shading factor and light color
5051
*/
51-
const getDiffuse = THREE.tslFn(
52+
const getDiffuse = FnCompat(
5253
({
5354
shading,
5455
lightColor,

packages/three-vrm-materials-mtoon/src/nodes/mtoonParametricRim.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as THREE from 'three/webgpu';
2+
import { FnCompat } from './utils/FnCompat';
23

3-
export const mtoonParametricRim = THREE.tslFn(
4+
export const mtoonParametricRim = FnCompat(
45
({
56
parametricRimLift,
67
parametricRimFresnelPower,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as THREE from 'three/webgpu';
2+
3+
/**
4+
* A compat function for `Fn()` / `tslFn()`.
5+
* `tslFn()` has been renamed to `Fn()` in r168.
6+
* We are going to use this compat for a while.
7+
*
8+
* See: https://github.com/mrdoob/three.js/pull/29064
9+
*/
10+
// eslint-disable-next-line @typescript-eslint/naming-convention
11+
export const FnCompat: typeof THREE.tslFn = (jsFunc: any) => {
12+
// COMPAT r168: `tslFn()` has been renamed to `Fn()`
13+
// See: https://github.com/mrdoob/three.js/pull/29064
14+
const threeRevision = parseInt(THREE.REVISION, 10);
15+
if (threeRevision >= 168) {
16+
return (THREE as any).Fn(jsFunc);
17+
} else {
18+
return (THREE as any).tslFn(jsFunc);
19+
}
20+
};

0 commit comments

Comments
 (0)