1 | # `@pixiv/three-vrm`
|
2 |
|
3 | [![@pixiv/three-vrm on npm](https://img.shields.io/npm/v/@pixiv/three-vrm)](https://www.npmjs.com/package/@pixiv/three-vrm)
|
4 |
|
5 | Use [VRM](https://vrm.dev/) on [three.js](https://threejs.org/)
|
6 |
|
7 | ![three-vrm](https://github.com/pixiv/three-vrm/raw/dev/three-vrm.png)
|
8 |
|
9 | [GitHub Repository](https://github.com/pixiv/three-vrm/)
|
10 |
|
11 | [Examples](https://pixiv.github.io/three-vrm/packages/three-vrm/examples)
|
12 |
|
13 | [Documentations](https://github.com/pixiv/three-vrm/tree/dev/docs/README.md)
|
14 |
|
15 | [API Reference](https://pixiv.github.io/three-vrm/packages/three-vrm/docs)
|
16 |
|
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 |
|
27 | ## How to Use
|
28 |
|
29 | ### from HTML
|
30 |
|
31 | You will need:
|
32 |
|
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://unpkg.com/browse/@pixiv/three-vrm/lib/)
|
36 | - `.module` ones are ESM, otherwise it's UMD and injects its modules into global `THREE`
|
37 | - `.min` ones are minified (for production), otherwise it's not minified and it comes with source maps
|
38 |
|
39 | Code like this:
|
40 |
|
41 | ```html
|
42 | <!-- About import maps, see the Three.js official docs: -->
|
43 | <!-- https://threejs.org/docs/#manual/en/introduction/Installation -->
|
44 | <script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
|
45 |
|
46 | <script type="importmap">
|
47 | {
|
48 | "imports": {
|
49 | "three": "https://unpkg.com/three@0.160.0/build/three.module.js",
|
50 | "three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/",
|
51 | "@pixiv/three-vrm": "three-vrm.module.js"
|
52 | }
|
53 | }
|
54 | </script>
|
55 |
|
56 | <script type="module">
|
57 | import * as THREE from 'three';
|
58 | import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
59 | import { VRMLoaderPlugin } from '@pixiv/three-vrm';
|
60 |
|
61 | const scene = new THREE.Scene();
|
62 |
|
63 | const loader = new GLTFLoader();
|
64 |
|
65 | // Install GLTFLoader plugin
|
66 | loader.register((parser) => {
|
67 | return new VRMLoaderPlugin(parser);
|
68 | });
|
69 |
|
70 | loader.load(
|
71 | // URL of the VRM you want to load
|
72 | '/models/VRM1_Constraint_Twist_Sample.vrm',
|
73 |
|
74 | // called when the resource is loaded
|
75 | (gltf) => {
|
76 | // retrieve a VRM instance from gltf
|
77 | const vrm = gltf.userData.vrm;
|
78 |
|
79 | // add the loaded vrm to the scene
|
80 | scene.add(vrm.scene);
|
81 |
|
82 | // deal with vrm features
|
83 | console.log(vrm);
|
84 | },
|
85 |
|
86 | // called while loading is progressing
|
87 | (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
|
88 |
|
89 | // called when loading has errors
|
90 | (error) => console.error(error),
|
91 | );
|
92 | </script>
|
93 | ```
|
94 |
|
95 | ### via npm
|
96 |
|
97 | Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](https://www.npmjs.com/package/@pixiv/three-vrm) :
|
98 |
|
99 | ```sh
|
100 | npm install three @pixiv/three-vrm
|
101 | ```
|
102 |
|
103 | Code like this:
|
104 |
|
105 | ```javascript
|
106 | import * as THREE from 'three';
|
107 | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
108 | import { VRMLoaderPlugin } from '@pixiv/three-vrm';
|
109 |
|
110 | const scene = new THREE.Scene();
|
111 |
|
112 | const loader = new GLTFLoader();
|
113 |
|
114 | // Install GLTFLoader plugin
|
115 | loader.register((parser) => {
|
116 | return new VRMLoaderPlugin(parser);
|
117 | });
|
118 |
|
119 | loader.load(
|
120 | // URL of the VRM you want to load
|
121 | '/models/VRM1_Constraint_Twist_Sample.vrm',
|
122 |
|
123 | // called when the resource is loaded
|
124 | (gltf) => {
|
125 | // retrieve a VRM instance from gltf
|
126 | const vrm = gltf.userData.vrm;
|
127 |
|
128 | // add the loaded vrm to the scene
|
129 | scene.add(vrm.scene);
|
130 |
|
131 | // deal with vrm features
|
132 | console.log(vrm);
|
133 | },
|
134 |
|
135 | // called while loading is progressing
|
136 | (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
|
137 |
|
138 | // called when loading has errors
|
139 | (error) => console.error(error),
|
140 | );
|
141 | ```
|
142 |
|
143 | ## Contributing
|
144 |
|
145 | See: [CONTRIBUTING.md](CONTRIBUTING.md)
|
146 |
|
147 | ## LICENSE
|
148 |
|
149 | [MIT](LICENSE)
|