-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (82 loc) · 3.12 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<script src="https://aframe.io/releases/1.0.3/aframe.min.js"></script>
<script src="THREE.MeshLine.js"></script>
<script src="components/al-bounding-box.js"></script>
<script src="components/al-gltf-model.js"></script>
<script src="components/al-orbit-control.js"></script>
<script src="components/al-control-lights.js"></script>
<script src="utils.js"></script>
<script src="OrbitControls.js"></script>
<script src="constants.js"></script>
<style>
body {
background: #000;
}
</style>
</head>
<body>
<a-scene
renderer="colorManagement: true; sortObjects: true; antialias: true"
vr-mode-ui="enabled: false"
light="defaultLightsEnabled: false">
<a-entity id="model-container">
<a-entity id="src" al-gltf-model="src: https://aleph-gltf-models.netlify.app/Frog.glb"></a-entity>
<!-- <a-entity id="src" al-gltf-model="src: https://aleph-gltf-models.netlify.app/FlightHelmet.glb"></a-entity> -->
<!-- <a-entity id="src" al-gltf-model="src: https://aleph-gltf-models.netlify.app/BoxTextured.glb"></a-entity> -->
<a-entity id="bounding-box"></a-entity>
</a-entity>
<a-camera
id="main-camera"
fov="45"
near="0.05"
look-controls="enabled: false"
far="10000"
/>
</a-scene>
<script>
const scene = document.querySelector("a-scene");
const boundingBox = document.getElementById("bounding-box");
const camera = document.getElementById("main-camera");
function center(model) {
const box = getBoundingBox(model);
const center = box.getCenter(new THREE.Vector3());
model.position.x += (model.position.x - center.x);
model.position.y += (model.position.y - center.y);
model.position.z += (model.position.z - center.z);
}
function setupBoundingBox(model) {
const box = getBoundingBox(model);
const size = new THREE.Vector3();
box.getSize(size);
boundingBox.setAttribute("al-bounding-box", "scale:" + stringifyVec3(size));
}
function setupCamera(model) {
const cameraState = getCameraStateFromModel(model, Constants.zoomFactor, Constants.fov);
camera.setAttribute("al-orbit-control",
"controlPosition:" + stringifyVec3(cameraState.position) + ";" +
"controlTarget:" + stringifyVec3(cameraState.target) + ";" +
"minPolarAngle: 0.25;" +
"maxPolarAngle: 175;" +
"minDistance: 0;" +
"screenSpacePanning: true;" +
"rotateSpeed: 0.5;" +
"zoomSpeed: 1;" +
"enableDamping: true;" +
"dampingFactor: 0.25;" +
"panSpeed: 0.25");
camera.setAttribute("al-control-lights", "");
}
window.addEventListener("DOMContentLoaded", (event) => {
scene.addEventListener("al-model-loaded", (e) => {
const model = e.detail.model;
//const mesh = getMesh(model);
//center(mesh)
center(model);
setupBoundingBox(model);
setupCamera(model);
}, false);
});
</script>
</body>
</html>