Skip to content

Commit a60e55e

Browse files
authored
Merge pull request #1412 from pixiv/dev-v3
`dev-v3`
2 parents 042fdde + 320335f commit a60e55e

File tree

194 files changed

+3949
-4080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+3949
-4080
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/packages/*/docs/
22
/packages/*/lib/
33
/packages/*/node_modules/
4-
/packages/*/ts*/
54
/packages/*/types/
5+
!/packages/types-*/types/
66

77
jest.config.js

.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"plugin:@typescript-eslint/recommended",
1010
"plugin:@typescript-eslint/eslint-recommended"
1111
],
12+
"globals": {
13+
"process": true
14+
},
1215
"env": {
1316
"browser": true
1417
},
@@ -53,6 +56,10 @@
5356
{
5457
"selector": "enumMember",
5558
"format": ["PascalCase"]
59+
},
60+
{
61+
"selector": "import",
62+
"format": ["camelCase", "PascalCase", "UPPER_CASE"]
5663
}
5764
],
5865
"@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }], // we sometimes have to define unused arguments

.github/workflows/inspect.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
path: |
5757
packages/*/lib/
5858
packages/*/types/
59-
packages/*/ts*/
6059
6160
lint:
6261
runs-on: ubuntu-latest

.github/workflows/publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,3 @@ jobs:
6565
path: |
6666
packages/*/lib/
6767
packages/*/types/
68-
packages/*/ts*/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/packages/*/node_modules
44
/packages/*/docs
55
/packages/*/lib
6-
/packages/*/ts*/
76
/packages/*/types
7+
/tmp

README.md

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,27 @@ Use [VRM](https://vrm.dev/) on [three.js](https://threejs.org/)
1414

1515
[API Reference](https://pixiv.github.io/three-vrm/packages/three-vrm/docs)
1616

17-
## v1
18-
19-
**three-vrm v1 has been released!**
20-
21-
three-vrm v1 supports [VRM1.0](https://vrm.dev/vrm1/), which is a new version of VRM format (the previous version of VRM is also supported, don't worry!).
22-
It also adopts the GLTFLoader plugin system which is a relatively new feature of GLTFLoader.
23-
24-
There are a lot of breaking changes!
25-
See [the migration guide](https://github.com/pixiv/three-vrm/blob/dev/docs/migration-guide-1.0.md) for more info.
26-
2717
## How to Use
2818

2919
### from HTML
3020

3121
You will need:
3222

33-
- [Three.js build](https://github.com/mrdoob/three.js/blob/master/build/three.js)
34-
- [GLTFLoader](https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js)
35-
- [A build of @pixiv/three-vrm](https://www.jsdelivr.com/package/npm/@pixiv/three-vrm?tab=files&path=lib)
23+
- Three.js build
24+
- GLTFLoader
25+
- A build of @pixiv/three-vrm
3626
- `.module` ones are ESM, otherwise it's UMD and injects its modules into global `THREE`
3727
- `.min` ones are minified (for production), otherwise it's not minified and it comes with source maps
3828

39-
You can import all of them via CDN. See the example below.
40-
41-
Code like this:
29+
You can import all the dependencies via CDN like [jsDelivr](https://www.jsdelivr.com/).
4230

4331
```html
4432
<script type="importmap">
4533
{
4634
"imports": {
47-
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
48-
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/",
49-
"@pixiv/three-vrm": "three-vrm.module.js"
35+
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
36+
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
37+
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.min.js"
5038
}
5139
}
5240
</script>
@@ -56,11 +44,12 @@ Code like this:
5644
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
5745
import { VRMLoaderPlugin } from '@pixiv/three-vrm';
5846
59-
const scene = new THREE.Scene();
47+
// ... Setup renderer, camera, scene ...
6048
49+
// Create a GLTFLoader - The loader for loading VRM models
6150
const loader = new GLTFLoader();
6251
63-
// Install GLTFLoader plugin
52+
// Install a GLTFLoader plugin that enables VRM support
6453
loader.register((parser) => {
6554
return new VRMLoaderPlugin(parser);
6655
});
@@ -87,9 +76,15 @@ Code like this:
8776
// called when loading has errors
8877
(error) => console.error(error),
8978
);
79+
80+
// ... Perform the render loop ...
9081
</script>
9182
```
9283

84+
See the Three.js document if you are not familiar with Three.js yet: https://threejs.org/docs/#manual/en/introduction/Creating-a-scene
85+
86+
See the example for the complete code: https://github.com/pixiv/three-vrm/blob/release/packages/three-vrm/examples/basic.html
87+
9388
### via npm
9489

9590
Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](https://www.npmjs.com/package/@pixiv/three-vrm) :
@@ -98,46 +93,48 @@ Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](
9893
npm install three @pixiv/three-vrm
9994
```
10095

101-
Code like this:
96+
### Use with WebGPURenderer
97+
98+
Starting from v3, we provide [WebGPURenderer](https://github.com/mrdoob/three.js/blob/master/examples/jsm/renderers/webgpu/WebGPURenderer.js) compatibility.
99+
To use three-vrm with WebGPURenderer, specify the WebGPU-compatible `MToonNodeMaterial` for the `materialType` option of `MToonMaterialLoaderPlugin`.
102100

103-
```javascript
104-
import * as THREE from 'three';
105-
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
101+
`MToonNodeMaterial` only supports Three.js r167 or later.
102+
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.
103+
104+
```js
106105
import { VRMLoaderPlugin } from '@pixiv/three-vrm';
106+
import { MToonNodeMaterial } from '@pixiv/three-vrm/nodes';
107107

108-
const scene = new THREE.Scene();
108+
// ... Setup renderer, camera, scene ...
109109

110+
// Create a GLTFLoader
110111
const loader = new GLTFLoader();
111112

112-
// Install GLTFLoader plugin
113+
// Register a VRMLoaderPlugin
113114
loader.register((parser) => {
114-
return new VRMLoaderPlugin(parser);
115-
});
116115

117-
loader.load(
118-
// URL of the VRM you want to load
119-
'/models/VRM1_Constraint_Twist_Sample.vrm',
116+
// create a WebGPU compatible MToonMaterialLoaderPlugin
117+
const mtoonMaterialPlugin = new MToonMaterialLoaderPlugin(parser, {
118+
119+
// set the material type to MToonNodeMaterial
120+
materialType: MToonNodeMaterial,
121+
122+
});
120123

121-
// called when the resource is loaded
122-
(gltf) => {
123-
// retrieve a VRM instance from gltf
124-
const vrm = gltf.userData.vrm;
124+
return new VRMLoaderPlugin(parser, {
125125

126-
// add the loaded vrm to the scene
127-
scene.add(vrm.scene);
126+
// Specify the MToonMaterialLoaderPlugin to use in the VRMLoaderPlugin instance
127+
mtoonMaterialPlugin,
128128

129-
// deal with vrm features
130-
console.log(vrm);
131-
},
129+
});
132130

133-
// called while loading is progressing
134-
(progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
131+
});
135132

136-
// called when loading has errors
137-
(error) => console.error(error),
138-
);
133+
// ... Load the VRM and perform the render loop ...
139134
```
140135

136+
See the example for the complete code: https://github.com/pixiv/three-vrm/blob/release/packages/three-vrm/examples/webgpu-dnd.html
137+
141138
## Contributing
142139

143140
See: [CONTRIBUTING.md](CONTRIBUTING.md)

bin/build.mjs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// @ts-check
2+
import esbuild from 'esbuild';
3+
import path from 'node:path';
4+
import fs from 'node:fs/promises';
5+
6+
// == envs =========================================================================================
7+
const NODE_ENV = process.env.NODE_ENV;
8+
const DEV = NODE_ENV === 'development';
9+
const SERVE = process.env.SERVE === '1';
10+
const PORT = parseInt(process.env.PORT || '10001', 10);
11+
12+
// == build =========================================================================================
13+
14+
const workDir = process.argv[2] ? path.join(process.cwd(), process.argv[2]) : process.cwd();
15+
await buildPackage(workDir);
16+
17+
// == implement =====================================================================================
18+
19+
/**
20+
*
21+
* @param {string} absWorkingDir
22+
*/
23+
async function buildPackage(absWorkingDir) {
24+
/**
25+
* @type {{ name: string, version: string, description: string, module: string }}
26+
*/
27+
const packageJson = JSON.parse(await fs.readFile(path.join(absWorkingDir, './package.json'), 'utf-8'));
28+
29+
// == constants ====================================================================================
30+
/** copyright text */
31+
const copyright = '(c) 2019-2024 pixiv Inc.';
32+
33+
/** name of the license */
34+
const licenseName = 'MIT License';
35+
36+
/** url of the license */
37+
const licenseUri = 'https://github.com/pixiv/three-vrm/blob/release/LICENSE';
38+
39+
/** filename of output */
40+
const filename = packageJson.name.split('/').at(-1) || 'index';
41+
42+
// == banner =======================================================================================
43+
const bannerTextDev = `/*!
44+
* ${packageJson.name} v${packageJson.version}
45+
* ${packageJson.description}
46+
*
47+
* Copyright ${copyright}
48+
* ${packageJson.name} is distributed under ${licenseName}
49+
* ${licenseUri}
50+
*/`;
51+
52+
const bannerTextProd = `/*! ${copyright} - ${licenseUri} */`;
53+
54+
/**
55+
* @param {'esm' | 'cjs'} format
56+
*/
57+
const entryPoints = (format) => {
58+
/**
59+
* Add suffix according to the format to the given basename of the output file.
60+
* @param {string} base Basename of the output file
61+
* @returns {string} `<base>[.module][.min]`
62+
*/
63+
const addSuffix = (base) => {
64+
let outFilename = base + (format === 'esm' ? '.module' : '');
65+
return outFilename + (DEV ? '' : '.min');
66+
};
67+
68+
const needsNodesBuild = ['@pixiv/three-vrm', '@pixiv/three-vrm-materials-mtoon'].includes(packageJson.name);
69+
const extraEntryPoints = needsNodesBuild
70+
? { [addSuffix('nodes/index')]: 'src/nodes/index.ts' }
71+
: {};
72+
73+
return {
74+
entryPoints: {
75+
[addSuffix(filename)]: 'src/index.ts',
76+
...extraEntryPoints,
77+
},
78+
format,
79+
};
80+
};
81+
82+
/**
83+
* @type {import('esbuild').BuildOptions}
84+
*/
85+
const buildOptions = {
86+
banner: {
87+
js: DEV ? bannerTextDev : bannerTextProd,
88+
},
89+
bundle: true,
90+
target: 'es6',
91+
// eslint-disable-next-line @typescript-eslint/naming-convention
92+
loader: { '.frag': 'text', '.vert': 'text' },
93+
sourcemap: DEV ? 'inline' : false,
94+
absWorkingDir,
95+
logLevel: 'info',
96+
color: true,
97+
minify: !DEV,
98+
external: ['three'],
99+
};
100+
101+
// == serve ========================================================================================
102+
async function serve() {
103+
const esmContext = await esbuild.context({
104+
...buildOptions,
105+
...entryPoints('esm'),
106+
outdir: 'lib',
107+
absWorkingDir,
108+
});
109+
110+
await esmContext.watch();
111+
await esmContext.serve({ servedir: '.', port: PORT });
112+
}
113+
114+
async function build() {
115+
await esbuild.build({
116+
...buildOptions,
117+
...entryPoints('esm'),
118+
outdir: 'lib',
119+
});
120+
121+
await esbuild.build({
122+
...buildOptions,
123+
...entryPoints('cjs'),
124+
outdir: 'lib',
125+
outExtension: {
126+
// eslint-disable-next-line @typescript-eslint/naming-convention
127+
'.js': '.cjs',
128+
},
129+
});
130+
}
131+
132+
// == main =========================================================================================
133+
await (SERVE ? serve : build)();
134+
}

jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// it's required to make vscode-jest work properly...
2+
export default {
3+
transform: {
4+
'^.+\\.ts$': 'ts-jest',
5+
},
6+
};

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"npmClient": "yarn",
33
"useWorkspaces": true,
44
"packages": ["packages/*"],
5-
"version": "2.1.3"
5+
"version": "3.0.0-beta.2"
66
}

0 commit comments

Comments
 (0)