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

BREAKING feature: preparing for Three.js r167 #1446

Merged
merged 8 commits into from
Jul 26, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Code like this:
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@pixiv/three-vrm": "three-vrm.module.js"
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ loader.load(
Starting from v3, we provide [WebGPURenderer](https://github.com/mrdoob/three.js/blob/master/examples/jsm/renderers/webgpu/WebGPURenderer.js) compatibility.
To use three-vrm with WebGPURenderer, specify the WebGPU-compatible `MToonNodeMaterial` for the `materialType` option of `MToonMaterialLoaderPlugin`.

`MToonNodeMaterial` only supports Three.js r161 or later.
`MToonNodeMaterial` only supports Three.js r167 or later.
The NodeMaterial system of Three.js is still under development, so we may break compatibility with older versions of Three.js more frequently than other parts of three-vrm.

```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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@2.1.0/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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@2.1.0/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.0.0-beta.1"
},
"devDependencies": {
"@types/three": "^0.164.0",
"@types/three": "^0.167.0",
"lint-staged": "15.2.2",
"three": "^0.164.1"
"three": "^0.167.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
6 changes: 5 additions & 1 deletion packages/three-vrm-animation/src/VRMAnimationLoaderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ export class VRMAnimationLoaderPlugin implements GLTFLoaderPlugin {
parentWorldMatrix.decompose(_v3A, _quatB, _v3A);

const trackValues = arrayChunk(origTrack.values, 4).flatMap((q) =>
_quatC.fromArray(q).premultiply(_quatB).multiply(_quatA).toArray(),
_quatC
.fromArray(q as THREE.QuaternionTuple)
.premultiply(_quatB)
.multiply(_quatA)
.toArray(),
);

const track = origTrack.clone();
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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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/fflate@0.7.4/esm/browser.js",
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.0.0-beta.1"
},
"devDependencies": {
"@types/three": "^0.164.0",
"three": "^0.164.1"
"@types/three": "^0.167.0",
"three": "^0.167.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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.0.0-beta.1"
},
"devDependencies": {
"@types/three": "^0.164.0",
"three": "^0.164.1"
"@types/three": "^0.167.0",
"three": "^0.167.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
2 changes: 1 addition & 1 deletion packages/three-vrm-materials-mtoon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MToon (toon material) module for @pixiv/three-vrm
Starting from v3, we provide [WebGPURenderer](https://github.com/mrdoob/three.js/blob/master/examples/jsm/renderers/webgpu/WebGPURenderer.js) compatibility.
To use MToon with WebGPURenderer, specify the WebGPU-compatible `MToonNodeMaterial` for the `materialType` option of `MToonMaterialLoaderPlugin`.

`MToonNodeMaterial` only supports Three.js r161 or later.
`MToonNodeMaterial` only supports Three.js r167 or later.
The NodeMaterial system of Three.js is still under development, so we may break compatibility with older versions of Three.js more frequently than other parts of three-vrm.

```js
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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@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,22 +23,22 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
"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/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js",
"@pixiv/three-vrm-materials-mtoon/nodes": "../lib/nodes/index.module.js"
}
}
</script>

<script type="module">
import * as THREE from 'three';
import * as THREE from 'three/webgpu';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
import { MToonNodeMaterial } from '@pixiv/three-vrm-materials-mtoon/nodes';

// renderer
const renderer = new WebGPURenderer();
const renderer = new THREE.WebGPURenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.164.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.0/examples/jsm/",
"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/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js",
"@pixiv/three-vrm-materials-mtoon/nodes": "../lib/nodes/index.module.js"
}
}
</script>

<script type="module">
import * as THREE from 'three';
import * as THREE from 'three/webgpu';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
import { MToonMaterialLoaderPlugin } from '@pixiv/three-vrm-materials-mtoon';
import { MToonNodeMaterial } from '@pixiv/three-vrm-materials-mtoon/nodes';

// renderer
const renderer = new WebGPURenderer();
const renderer = new THREE.WebGPURenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
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.0.0-beta.1"
},
"devDependencies": {
"@types/three": "^0.164.0",
"three": "^0.164.1"
"@types/three": "^0.167.0",
"three": "^0.167.0"
},
"peerDependencies": {
"three": ">=0.137"
Expand Down
28 changes: 14 additions & 14 deletions packages/three-vrm-materials-mtoon/src/nodes/MToonAnimatedUVNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Nodes from 'three/addons/nodes/Nodes.js';
import * as THREE from 'three/webgpu';
import {
refUVAnimationMaskTexture,
refUVAnimationRotationPhase,
refUVAnimationScrollXOffset,
refUVAnimationScrollYOffset,
} from './materialReferences';

export class MToonAnimatedUVNode extends Nodes.TempNode {
export class MToonAnimatedUVNode extends THREE.TempNode {
public readonly hasMaskTexture: boolean;

public constructor(hasMaskTexture: boolean) {
Expand All @@ -15,30 +15,30 @@ export class MToonAnimatedUVNode extends Nodes.TempNode {
this.hasMaskTexture = hasMaskTexture;
}

public setup(): Nodes.ShaderNodeObject<Nodes.VarNode> {
let uvAnimationMask: Nodes.NodeRepresentation = 1.0;
public setup(): THREE.ShaderNodeObject<THREE.VarNode> {
let uvAnimationMask: THREE.NodeRepresentation = 1.0;

if (this.hasMaskTexture) {
uvAnimationMask = Nodes.vec4(refUVAnimationMaskTexture).context({ getUV: () => Nodes.uv() }).r;
uvAnimationMask = THREE.vec4(refUVAnimationMaskTexture).context({ getUV: () => THREE.uv() }).r;
}

let uv: Nodes.ShaderNodeObject<Nodes.Swizzable> = Nodes.uv();
let uv: THREE.ShaderNodeObject<THREE.Swizzable> = THREE.uv();

// rotate
const phase = refUVAnimationRotationPhase.mul(uvAnimationMask);

// WORKAROUND: Nodes.rotateUV causes an issue with the mask texture
// WORKAROUND: THREE.rotateUV causes an issue with the mask texture
// We are going to spin using a 100% organic handmade rotation matrix
// uv = Nodes.rotateUV(uv, phase, Nodes.vec2(0.5, 0.5));
// uv = THREE.rotateUV(uv, phase, THREE.vec2(0.5, 0.5));

const c = Nodes.cos(phase);
const s = Nodes.sin(phase);
uv = uv.sub(Nodes.vec2(0.5, 0.5));
uv = uv.mul(Nodes.mat2(c, s, s.negate(), c));
uv = uv.add(Nodes.vec2(0.5, 0.5));
const c = THREE.cos(phase);
const s = THREE.sin(phase);
uv = uv.sub(THREE.vec2(0.5, 0.5));
uv = uv.mul(THREE.mat2(c, s, s.negate(), c));
uv = uv.add(THREE.vec2(0.5, 0.5));

// scroll
const scroll = Nodes.vec2(refUVAnimationScrollXOffset, refUVAnimationScrollYOffset).mul(uvAnimationMask);
const scroll = THREE.vec2(refUVAnimationScrollXOffset, refUVAnimationScrollYOffset).mul(uvAnimationMask);
uv = uv.add(scroll);

return uv.temp('AnimatedUV');
Expand Down
Loading
Loading