Skip to main content

ThreeJS Face Tracking

This is sample application using three.js instead of AFRAME. The effect should be similar to Minimal

Try it out

Live Demo

<html>
<head>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/",
"mindar-face-three":"https://cdn.jsdelivr.net/npm/mind-ar@1.2.5/dist/mindar-face-three.prod.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { MindARThree } from 'mindar-face-three';
const mindarThree = new MindARThree({
container: document.querySelector("#container"),
});
const {renderer, scene, camera} = mindarThree;
const anchor = mindarThree.addAnchor(1);
const geometry = new THREE.SphereGeometry( 0.1, 32, 16 );
const material = new THREE.MeshBasicMaterial( {color: 0x00ffff, transparent: true, opacity: 0.5} );
const sphere = new THREE.Mesh( geometry, material );
anchor.group.add(sphere);
const start = async() => {
await mindarThree.start();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
}
const startButton = document.querySelector("#startButton");
startButton.addEventListener("click", () => {
start();
});
stopButton.addEventListener("click", () => {
mindarThree.stop();
mindarThree.renderer.setAnimationLoop(null);
});
</script>
<style>
body {
margin: 0;
}
#container {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}
#control {
position: fixed;
top: 0;
left: 0;
z-index: 2;
}
</style>
</head>
<body>
<div id="control">
<button id="startButton">Start</button>
<button id="stopButton">Stop</button>
</div>
<div id="container">
</div>
</body>
</html>