For AI agents: the complete documentation index is available at /vue-vrm/llms.txt, the full documentation bundle is available at /vue-vrm/llms-full.txt, and this page is available as Markdown at /vue-vrm/api/utilities.md.

Utilities

These functions work without the VrmCanvas component. Use them to check files before uploading, or to build your own three.js scene.

Validation

FunctionDescription
validateVrm(buffer)Throws if the buffer is not a GLB file with a VRM 1.0 extension. VRM 0.x is rejected.
validateVrma(buffer)Throws if the buffer is not a GLB file with a VRMA extension.

Both functions only read the file header and the JSON chunk, so they are fast enough to run before uploading:

import { validateVrm } from 'vue-vrm';

async function check(file: File): Promise<string | undefined> {
  try {
    validateVrm(await file.arrayBuffer());
    return undefined;
  } catch (error) {
    return (error as Error).message;
  }
}

Loading

FunctionReturnsDescription
loadVrm(buffer)Promise<VRM>Validates and loads a VRM 1.0 model.
autoPositionY(vrm)voidMoves the model so its lowest point is at y = 0.
disposeVrm(vrm)voidFrees the model's GPU resources.
loadVRMAnimation(buffer)Promise<VRMAnimation>Validates and loads a VRMA animation.
createMixerWithClips(vrm, animations, weights?, options?)AnimationMixerCreates a mixer that plays the animations with the given weights. options.loop defaults to true.
disposeMixer(mixer)voidStops the mixer and releases its cached clips.
import { createMixerWithClips, loadVRMAnimation, loadVrm } from 'vue-vrm';
import { Scene, Timer } from 'three';

const scene = new Scene();
const vrm = await loadVrm(modelBuffer);
scene.add(vrm.scene);

const animation = await loadVRMAnimation(animationBuffer);
const mixer = createMixerWithClips(vrm, [animation]);

const timer = new Timer();
renderer.setAnimationLoop(timestamp => {
  timer.update(timestamp);
  const delta = timer.getDelta();
  mixer.update(delta);
  vrm.update(delta);
  renderer.render(scene, camera);
});

Building your own component

useVrmCanvas is the composable behind VrmCanvas. Together with vrmCanvasProps and vrmCanvasEmits, it lets you render the canvas with your own markup:

import { defineComponent, h } from 'vue';
import { useVrmCanvas, vrmCanvasEmits, vrmCanvasProps } from 'vue-vrm';

export default defineComponent({
  props: vrmCanvasProps,
  emits: vrmCanvasEmits,
  setup(props, { emit, expose }) {
    const api = useVrmCanvas(props, emit);
    expose(api.exposed);
    return () =>
      h('div', { ref: api.container, style: api.containerStyle.value, class: 'my-avatar' }, [
        h('canvas', { ref: api.canvas, onKeydown: api.handleCanvasKeydown })
      ]);
  }
});

Meta

Meta contains the package version and build date:

import { Meta } from 'vue-vrm';

console.log(Meta.version, Meta.date);

Deprecated

FunctionReplacement
resetVrmCanvasCamera(instance)instance.resetCamera()