Skip to content

Commit

Permalink
Merge pull request #1465 from pixiv/r168-compat
Browse files Browse the repository at this point in the history
Bump Three.js to r168
  • Loading branch information
0b5vr authored Sep 5, 2024
2 parents 7a35f7e + 5decd5f commit 34def0a
Show file tree
Hide file tree
Showing 52 changed files with 166 additions and 120 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ You can import all the dependencies via CDN like [jsDelivr](https://www.jsdelivr
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.min.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-animation/examples/dnd.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.js",
"@pixiv/three-vrm-animation": "../lib/three-vrm-animation.module.js"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-animation/examples/loader-plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.js",
"@pixiv/three-vrm-animation": "../lib/three-vrm-animation.module.js"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"@pixiv/types-vrmc-vrm-animation-1.0": "3.1.0"
},
"devDependencies": {
"@types/three": "^0.167.0",
"@types/three": "^0.168.0",
"lint-staged": "15.2.9",
"three": "^0.167.0"
"three": "^0.168.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/expressions.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/firstPerson.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/humanoid.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/humanoidAnimation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
{
"imports": {
"fflate": "https://cdn.jsdelivr.net/npm/[email protected]/esm/browser.js",
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/lookAt.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/examples/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-core": "../lib/three-vrm-core.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"@pixiv/types-vrmc-vrm-1.0": "3.1.0"
},
"devDependencies": {
"@types/three": "^0.167.0",
"three": "^0.167.0"
"@types/three": "^0.168.0",
"three": "^0.168.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-hdr-emissive-multiplier": "../lib/three-vrm-materials-hdr-emissive-multiplier.module.js"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"@pixiv/types-vrmc-materials-hdr-emissive-multiplier-1.0": "3.1.0"
},
"devDependencies": {
"@types/three": "^0.167.0",
"three": "^0.167.0"
"@types/three": "^0.168.0",
"three": "^0.168.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-materials-mtoon/examples/feature-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.webgpu.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.webgpu.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js",
"@pixiv/three-vrm-materials-mtoon/nodes": "../lib/nodes/index.module.js"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.webgpu.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.webgpu.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js",
"@pixiv/three-vrm-materials-mtoon/nodes": "../lib/nodes/index.module.js"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-materials-mtoon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"@pixiv/types-vrmc-materials-mtoon-1.0": "3.1.0"
},
"devDependencies": {
"@types/three": "^0.167.0",
"three": "^0.167.0"
"@types/three": "^0.168.0",
"three": "^0.168.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<THREE.Node> }) => {
const getShading = FnCompat(({ dotNL }: { dotNL: THREE.ShaderNodeObject<THREE.Node> }) => {
const shadow = 1.0; // TODO

const feather = THREE.float(1.0).sub(shadingToony);
Expand All @@ -48,7 +49,7 @@ const getShading = THREE.tslFn(({ dotNL }: { dotNL: THREE.ShaderNodeObject<THREE
/**
* Mix diffuseColor and shadeColor using shading factor and light color
*/
const getDiffuse = THREE.tslFn(
const getDiffuse = FnCompat(
({
shading,
lightColor,
Expand Down
30 changes: 24 additions & 6 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> {
// 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 @@ -262,7 +262,7 @@ export class MToonNodeMaterial extends THREE.NodeMaterial {

if (this.normalMap && this.normalMap.isTexture === true) {
const map = refNormalMap.context({ getUV: () => this._animatedUVNode });
this.normalNode = map.normalMap(refNormalScale);
this.normalNode = THREE.normalMap(map, refNormalScale);
}

if (this.isOutline) {
Expand All @@ -271,11 +271,29 @@ 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>;

// 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;

// type workaround: pretend to return a valid value
// r167 doesn't use the return value anyway
return undefined as any;
}
}

public setupLighting(builder: THREE.NodeBuilder): THREE.Node {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as THREE from 'three/webgpu';
import { FnCompat } from './utils/FnCompat';

export const mtoonParametricRim = THREE.tslFn(
export const mtoonParametricRim = FnCompat(
({
parametricRimLift,
parametricRimFresnelPower,
Expand Down
20 changes: 20 additions & 0 deletions packages/three-vrm-materials-mtoon/src/nodes/utils/FnCompat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as THREE from 'three/webgpu';

/**
* A compat function for `Fn()` / `tslFn()`.
* `tslFn()` has been renamed to `Fn()` in r168.
* We are going to use this compat for a while.
*
* See: https://github.com/mrdoob/three.js/pull/29064
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const FnCompat: typeof THREE.Fn = (jsFunc: any) => {
// 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.Fn(jsFunc);
} else {
return (THREE as any).tslFn(jsFunc);
}
};
4 changes: 2 additions & 2 deletions packages/three-vrm-materials-v0compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"@pixiv/types-vrmc-materials-mtoon-1.0": "3.1.0"
},
"devDependencies": {
"@types/three": "^0.167.0",
"three": "^0.167.0"
"@types/three": "^0.168.0",
"three": "^0.168.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-node-constraint/examples/aim.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"tweakpane": "https://cdn.jsdelivr.net/npm/[email protected]",
"tweakpane-plugin-rotation": "https://cdn.jsdelivr.net/npm/@0b5vr/[email protected]",
"@pixiv/three-vrm-node-constraint": "../lib/three-vrm-node-constraint.module.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-node-constraint/examples/importer.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"tweakpane": "https://cdn.jsdelivr.net/npm/[email protected]",
"tweakpane-plugin-rotation": "https://cdn.jsdelivr.net/npm/@0b5vr/[email protected]",
"@pixiv/three-vrm-node-constraint": "../lib/three-vrm-node-constraint.module.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-node-constraint/examples/roll.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"tweakpane": "https://cdn.jsdelivr.net/npm/[email protected]",
"tweakpane-plugin-rotation": "https://cdn.jsdelivr.net/npm/@0b5vr/[email protected]",
"@pixiv/three-vrm-node-constraint": "../lib/three-vrm-node-constraint.module.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-node-constraint/examples/rotation.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"tweakpane": "https://cdn.jsdelivr.net/npm/[email protected]",
"tweakpane-plugin-rotation": "https://cdn.jsdelivr.net/npm/@0b5vr/[email protected]",
"@pixiv/three-vrm-node-constraint": "../lib/three-vrm-node-constraint.module.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-node-constraint/examples/upper-arm.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
"three": "https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/",
"tweakpane": "https://cdn.jsdelivr.net/npm/[email protected]",
"tweakpane-plugin-rotation": "https://cdn.jsdelivr.net/npm/@0b5vr/[email protected]",
"@pixiv/three-vrm-node-constraint": "../lib/three-vrm-node-constraint.module.js"
Expand Down
Loading

0 comments on commit 34def0a

Please sign in to comment.