This repository contains Three.js implementations of OMI glTF extensions.
Try it out here: https://omigroup.github.io/three-omi/
Assuming you have Node.js 18+ installed, including the npm and npx commands, run these commands to clone the repository and start a local server:
git clone https://github.com/omigroup/three-omi
cd three-omi
npm install
npx viteInstall with this command:
npm install -S three three-omiThen use it like this:
import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { GLTFLoaderAudioEmitterExtension } from "three-omi/src/khr_audio_emitter.js";
// Set up your scene, camera, and renderer here.
// The extension needs a reference to your AudioListener.
// Make sure you have one added as a child of your camera.
const listener = new THREE.AudioListener();
camera.add(listener);
// Create a glTF loader and register the extension.
const gltfLoader = new GLTFLoader();
gltfLoader.register((parser) => new GLTFLoaderAudioEmitterExtension(parser, listener));
gltfLoader.load(
"path/to/your/model.glb",
function (generated) {
scene.add(generated.scene);
},
undefined,
function (error) {
console.error(error);
}
);