Newer
Older
console.log(`Hubs version: ${process.env.BUILD_VERSION || "?"}`);
import "./assets/stylesheets/scene.scss";
import "aframe";
import "./utils/logging";
import { patchWebGLRenderingContext } from "./utils/webgl";
patchWebGLRenderingContext();
import "three/examples/js/loaders/GLTFLoader";
import "./components/debug";
import "./systems/nav";
import { getReticulumFetchUrl } from "./utils/phoenix-utils";
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import ReactDOM from "react-dom";
import React from "react";
import SceneUI from "./react-components/scene-ui";
import { disableiOSZoom } from "./utils/disable-ios-zoom";
import "./gltf-component-mappings";
import { App } from "./App";
window.APP = new App();
const qs = new URLSearchParams(location.search);
const isMobile = AFRAME.utils.device.isMobile();
window.APP.quality = qs.get("quality") || isMobile ? "low" : "high";
import "aframe-physics-system";
import "aframe-physics-extras";
import "./components/event-repeater";
import "./components/controls-shape-offset";
import registerTelemetry from "./telemetry";
registerTelemetry();
disableiOSZoom();
function mountUI(scene, props = {}) {
ReactDOM.render(
<SceneUI
{...{
scene,
...props
}}
/>,
document.getElementById("ui-root")
);
}
const onReady = async () => {
const scene = document.querySelector("a-scene");
window.APP.scene = scene;
const sceneId = qs.get("scene_id") || document.location.pathname.substring(1).split("/")[1];
console.log(`Scene ID: ${sceneId}`);
let uiProps = { sceneId: sceneId };
mountUI(scene);
const remountUI = props => {
uiProps = { ...uiProps, ...props };
mountUI(scene, uiProps);
};
const sceneRoot = document.querySelector("#scene-root");
const sceneModelEntity = document.createElement("a-entity");
const gltfEl = document.createElement("a-entity");
const camera = document.getElementById("camera");
sceneModelEntity.addEventListener("scene-loaded", () => {
remountUI({ sceneLoaded: true });
const previewCamera = gltfEl.object3D.getObjectByName("scene-preview-camera");
if (previewCamera) {
camera.object3D.position.copy(previewCamera.position);
camera.object3D.rotation.copy(previewCamera.rotation);
camera.object3D.updateMatrix();
const res = await fetch(getReticulumFetchUrl(`/api/v1/scenes/${sceneId}`)).then(r => r.json());
const sceneInfo = res.scenes[0];
const modelUrl = sceneInfo.model_url;
console.log(`Scene Model URL: ${modelUrl}`);
gltfEl.setAttribute("gltf-model-plus", { src: modelUrl, useCache: false, inflate: true });
gltfEl.addEventListener("model-loaded", () => sceneModelEntity.emit("scene-loaded"));
sceneModelEntity.appendChild(gltfEl);
remountUI({
sceneName: sceneInfo.name,
sceneDescription: sceneInfo.description,
};
document.addEventListener("DOMContentLoaded", onReady);