Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixiv/three-vrm

Package Overview
Dependencies
Maintainers
7
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixiv/three-vrm

VRM file loader for three.js.

  • 3.0.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
decreased by-6.38%
Maintainers
7
Weekly downloads
 
Created
Source

@pixiv/three-vrm

@pixiv/three-vrm on npm

Use VRM on three.js

three-vrm

GitHub Repository

Examples

Documentations

API Reference

How to Use

from HTML

You will need:

  • Three.js build
  • GLTFLoader
  • A build of @pixiv/three-vrm
    • .module ones are ESM, otherwise it's UMD and injects its modules into global THREE
    • .min ones are minified (for production), otherwise it's not minified and it comes with source maps

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();

  // Install GLTFLoader plugin
  loader.register((parser) => {
    return new VRMLoaderPlugin(parser);
  });

  loader.load(
    // URL of the VRM you want to load
    '/models/VRM1_Constraint_Twist_Sample.vrm',

    // called when the resource is loaded
    (gltf) => {
      // retrieve a VRM instance from gltf
      const vrm = gltf.userData.vrm;

      // add the loaded vrm to the scene
      scene.add(vrm.scene);

      // deal with vrm features
      console.log(vrm);
    },

    // called while loading is progressing
    (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),

    // called when loading has errors
    (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();

// Install GLTFLoader plugin
loader.register((parser) => {
  return new VRMLoaderPlugin(parser);
});

loader.load(
  // URL of the VRM you want to load
  '/models/VRM1_Constraint_Twist_Sample.vrm',

  // called when the resource is loaded
  (gltf) => {
    // retrieve a VRM instance from gltf
    const vrm = gltf.userData.vrm;

    // add the loaded vrm to the scene
    scene.add(vrm.scene);

    // deal with vrm features
    console.log(vrm);
  },

  // called while loading is progressing
  (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),

  // called when loading has errors
  (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';

// ...

// Register a VRMLoaderPlugin
loader.register((parser) => {

  // create a WebGPU compatible MToon loader plugin
  const mtoonMaterialPlugin = new MToonNodeMaterialLoaderPlugin(parser);

  return new VRMLoaderPlugin(parser, {

    // Specify the MToon loader plugin to use in the VRMLoaderPlugin instance
    mtoonMaterialPlugin,

  });

});

Contributing

See: CONTRIBUTING.md

LICENSE

MIT

FAQs

Package last updated on 17 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc