-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery-scene.js
71 lines (61 loc) · 2.07 KB
/
gallery-scene.js
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
import AFRAME from 'aframe';
import './components/caustics';
import './components/bubble';
import './components/gradient';
import './components/ocean-shader';
import 'aframe-orbit-controls';
import 'aframe-extras';
import {html, render} from 'lit-html';
import jsYaml from 'js-yaml';
let coralModels = [];
let currentIndex = 0;
async function loadCoralModels(yamlUrl) {
try {
const response = await fetch(yamlUrl);
const yamlText = await response.text();
coralModels = jsYaml.load(yamlText);
console.log('Loaded coral models:', coralModels);
updateCoralModel();
} catch (error) {
console.log('Error loading coral models:', error);
}
}
function updateCoralModel() {
const coral = coralModels[currentIndex];
const template = html`
<a-entity
gltf-model="#coral-${coral.assetId}"
animation-mixer="loop: repeat; delay: 0.2; timeScale:0.4"
position="${coral.lowPolyPosition.join(' ')}"
scale="${coral.lowPolyScale.join(' ')}"
></a-entity>
<a-entity
id="info-panel"
position="0 2.5 5"
geometry="primitive: plane; width: 4; height: 0.5"
material="color: #000000; opacity: 0.7"
>
<a-text
value="${coral.frenchName}\n${coral.latinName}"
position="-1.9 0 0.01"
scale="0.5 0.5 0.5"
color="#FFFFFF"
width="8"
></a-text>
</a-entity>
`;
render(template, document.querySelector('#coralContainer'));
console.log('Updated coral model:', coral);
}
function nextCoral() {
currentIndex = (currentIndex + 1) % coralModels.length;
updateCoralModel();
}
function prevCoral() {
currentIndex = (currentIndex - 1 + coralModels.length) % coralModels.length;
updateCoralModel();
}
document.getElementById('nextButton').addEventListener('click', nextCoral);
document.getElementById('prevButton').addEventListener('click', prevCoral);
// Load coral models from YAML file
loadCoralModels('./gallery.yaml');