-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (75 loc) · 1.98 KB
/
script.js
File metadata and controls
90 lines (75 loc) · 1.98 KB
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
87
88
89
90
window.onload = () => {
const button = document.querySelector('button[data-action="change"]');
button.innerText = "﹖";
let places = staticLoadPlaces();
renderPlaces(places);
};
function staticLoadPlaces() {
return [
{
name: "Pokèmon",
location: {
lat: 28.1238,
lng: -15.4409,
},
},
];
}
var models = [
{
url: "./assets/magnemite/scene.gltf",
scale: "0.5 0.5 0.5",
info: "Magnemite, Lv. 5, HP 10/10",
rotation: "0 180 0",
},
{
url: "./assets/articuno/scene.gltf",
scale: "0.2 0.2 0.2",
rotation: "180 180 0",
info: "Articuno, Lv. 80, HP 100/100",
},
{
url: "./assets/dragonite/scene.gltf",
scale: "0.08 0.08 0.08",
rotation: "0 180 0",
info: "Dragonite, Lv. 99, HP 150/150",
},
];
var modelIndex = 0;
var setModel = function (model, entity) {
if (model.scale) {
entity.setAttribute("scale", model.scale);
}
if (model.rotation) {
entity.setAttribute("rotation", model.rotation);
}
if (model.position) {
entity.setAttribute("position", model.position);
}
entity.setAttribute("gltf-model", model.url);
const div = document.querySelector(".instructions");
div.innerText = model.info;
};
function renderPlaces(places) {
let scene = document.querySelector("a-scene");
places.forEach((place) => {
let latitude = place.location.lat;
let longitude = place.location.lng;
let model = document.createElement("a-entity");
model.setAttribute(
"gps-entity-place",
`latitude: ${latitude}; longitude: ${longitude};`
);
setModel(models[modelIndex], model);
model.setAttribute("animation-mixer", "");
document
.querySelector('button[data-action="change"]')
.addEventListener("click", function () {
var entity = document.querySelector("[gps-entity-place]");
modelIndex++;
var newIndex = modelIndex % models.length;
setModel(models[newIndex], entity);
});
scene.appendChild(model);
});
}