Skip to content

Instantly share code, notes, and snippets.

@nicolocarpignoli
Created November 5, 2019 13:22
Show Gist options
  • Save nicolocarpignoli/b9c76d6cef260d0c15aca6e2734102ca to your computer and use it in GitHub Desktop.
Save nicolocarpignoli/b9c76d6cef260d0c15aca6e2734102ca to your computer and use it in GitHub Desktop.
window.onload = () => {
// setTimeout is a temporary fix
const button = document.querySelector('button[data-action="change"]');
button.innerText = '﹖';
setTimeout(() => {
let places = staticLoadPlaces();
renderPlaces(places);
}, 3000);
};
function staticLoadPlaces() {
return [
{
name: 'Pokèmon',
location: {
// lat: <your-latitude>,
// lng: <your-longitude>,
},
},
];
}
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: '0 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);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment