1 | # `@pixiv/three-vrm`
|
2 |
|
3 | Use [VRM](https://vrm.dev/) on [three.js](https://threejs.org/)
|
4 |
|
5 | ![three-vrm](https://github.com/pixiv/three-vrm/raw/dev/three-vrm.png)
|
6 |
|
7 | [GitHub Repository](https://github.com/pixiv/three-vrm/)
|
8 |
|
9 | [Examples](https://pixiv.github.io/three-vrm/examples)
|
10 |
|
11 | [Documentation](https://pixiv.github.io/three-vrm/docs)
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ### from HTML
|
16 |
|
17 | You will need:
|
18 |
|
19 | - [Three.js build](https://github.com/mrdoob/three.js/blob/master/build/three.js)
|
20 | - [GLTFLoader](https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js)
|
21 | - [A build of @pixiv/three-vrm](https://unpkg.com/browse/@pixiv/three-vrm/lib/)
|
22 | - `.module` ones are ESM, otherwise it's UMD and injects its modules into global `THREE`
|
23 | - `.min` ones are minified (for production), otherwise it's not minified and it comes with source maps
|
24 |
|
25 | Code like this:
|
26 |
|
27 | ```html
|
28 | <script src="three.js"></script>
|
29 | <script src="GLTFLoader.js"></script>
|
30 | <script src="three-vrm.js"></script>
|
31 |
|
32 | <script>
|
33 | const scene = new THREE.Scene();
|
34 |
|
35 | const loader = new THREE.GLTFLoader();
|
36 | loader.load(
|
37 |
|
38 | // URL of the VRM you want to load
|
39 | '/models/three-vrm-girl.vrm',
|
40 |
|
41 | // called when the resource is loaded
|
42 | ( gltf ) => {
|
43 |
|
44 | // generate a VRM instance from gltf
|
45 | THREE.VRM.from( gltf ).then( ( vrm ) => {
|
46 |
|
47 | // add the loaded vrm to the scene
|
48 | scene.add( vrm.scene );
|
49 |
|
50 | // deal with vrm features
|
51 | console.log( vrm );
|
52 |
|
53 | } );
|
54 |
|
55 | },
|
56 |
|
57 | // called while loading is progressing
|
58 | ( progress ) => console.log( 'Loading model...', 100.0 * ( progress.loaded / progress.total ), '%' ),
|
59 |
|
60 | // called when loading has errors
|
61 | ( error ) => console.error( error )
|
62 |
|
63 | );
|
64 | </script>
|
65 | ```
|
66 |
|
67 | ### via npm
|
68 |
|
69 | Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](https://www.npmjs.com/package/@pixiv/three-vrm) :
|
70 |
|
71 | ```sh
|
72 | npm install three @pixiv/three-vrm
|
73 | ```
|
74 |
|
75 | Code like this:
|
76 |
|
77 | ```javascript
|
78 | import * as THREE from 'three';
|
79 | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
80 | import { VRM } from '@pixiv/three-vrm';
|
81 |
|
82 | const scene = new THREE.Scene();
|
83 |
|
84 | const loader = new GLTFLoader();
|
85 | loader.load(
|
86 |
|
87 | // URL of the VRM you want to load
|
88 | '/models/three-vrm-girl.vrm',
|
89 |
|
90 | // called when the resource is loaded
|
91 | ( gltf ) => {
|
92 |
|
93 | // generate a VRM instance from gltf
|
94 | VRM.from( gltf ).then( ( vrm ) => {
|
95 |
|
96 | // add the loaded vrm to the scene
|
97 | scene.add( vrm.scene );
|
98 |
|
99 | // deal with vrm features
|
100 | console.log( vrm );
|
101 |
|
102 | } );
|
103 |
|
104 | },
|
105 |
|
106 | // called while loading is progressing
|
107 | ( progress ) => console.log( 'Loading model...', 100.0 * ( progress.loaded / progress.total ), '%' ),
|
108 |
|
109 | // called when loading has errors
|
110 | ( error ) => console.error( error )
|
111 |
|
112 | );
|
113 | ```
|
114 |
|
115 | ## Contributing
|
116 |
|
117 | See: [CONTRIBUTING.md](CONTRIBUTING.md)
|
118 |
|
119 | ## LICENSE
|
120 |
|
121 | [MIT](LICENSE)
|