threelet = {
const threelet = new Threelet({
canvas: document.getElementById('canvas'),
optCameraPosition: [0, 0.7, 2],
optAxes: false,
optVR: true,
optVRAppendButtonTo: div,
})
invalidation.then(() => threelet.dispose());
threelet.setup('mod-controls', THREE.OrbitControls);
threelet.setup('mod-sky', THREE.Sky);
threelet.scene.add(createTestHemisphereLight());
threelet.scene.add(createTestDirectionalLight());
threelet.scene.add(new THREE.GridHelper(10, 20));
threelet.enableInteractiveGroup('drag');
const group = threelet.getInteractiveGroup();
const testObjs = createTestObjects();
testObjs.forEach(obj => group.add(obj));
threelet.scene.add(group);
group.add(data.base);
const addAvatarIfNotYet = () => {
if (data.avatar && ! data.avatar.parent) {
console.log('@@ adding avatar to scene');
threelet.scene.add(data.avatar);
}
};
threelet.on('mouse-click', (x, y) => {
const isec = threelet.raycastFromMouse(x, y, [data.base, ...testObjs], false);
if (isec && isec.object.name === 'base') {
addAvatarIfNotYet();
updateBase();
}
});
threelet.on('vr-trigger-press-start', (i) => {
const isects = threelet.raycastFromController(
i, [data.base, ...testObjs], false);
if (isects.length > 0 && isects[0].object.name === 'base') {
addAvatarIfNotYet();
updateBase();
}
});
threelet.update = (t, dt) => {
const py = 0.4 * Math.sin(t) + 0.5;
data.base.position.y = py;
if (data.mixer !== null) {
data.mixer.update(dt);
data.avatar.position.y = py;
}
};
const fps = 30;
threelet.updateLoop(fps);
threelet.render();
return threelet;
}