@pixiv/three-vrm
Use VRM on three.js
GitHub Repository
Examples
Documentations
API Reference
How to Use
from HTML
You will need:
You can import all of them via CDN. See the example below.
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/",
"@pixiv/three-vrm": "three-vrm.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { VRMLoaderPlugin } from '@pixiv/three-vrm';
const scene = new THREE.Scene();
const loader = new GLTFLoader();
loader.register((parser) => {
return new VRMLoaderPlugin(parser);
});
loader.load(
'/models/VRM1_Constraint_Twist_Sample.vrm',
(gltf) => {
const vrm = gltf.userData.vrm;
scene.add(vrm.scene);
console.log(vrm);
},
(progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
(error) => console.error(error),
);
</script>
via npm
Install three
and @pixiv/three-vrm
:
npm install three @pixiv/three-vrm
Code like this:
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { VRMLoaderPlugin } from '@pixiv/three-vrm';
const scene = new THREE.Scene();
const loader = new GLTFLoader();
loader.register((parser) => {
return new VRMLoaderPlugin(parser);
});
loader.load(
'/models/VRM1_Constraint_Twist_Sample.vrm',
(gltf) => {
const vrm = gltf.userData.vrm;
scene.add(vrm.scene);
console.log(vrm);
},
(progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
(error) => console.error(error),
);
Use with WebGPURenderer
Starting from v3, we provide WebGPURenderer compatibility.
To use three-vrm with WebGPURenderer, specify the WebGPU-compatible MToonNodeMaterialLoaderPlugin
for the mtoonMaterialPlugin
option of VRMLoaderPlugin
.
MToonNodeMaterial
only supports Three.js r161 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.
import { VRMLoaderPlugin, MToonNodeMaterialLoaderPlugin } from '@pixiv/three-vrm';
loader.register((parser) => {
const mtoonMaterialPlugin = new MToonNodeMaterialLoaderPlugin(parser);
return new VRMLoaderPlugin(parser, {
mtoonMaterialPlugin,
});
});
Contributing
See: CONTRIBUTING.md
LICENSE
MIT