reuse search result texture for selected challenge section

This commit is contained in:
Kevin Ngo
2018-09-20 01:09:16 -07:00
parent a338824ba1
commit bb927748b4
2 changed files with 30 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
/**
* Reuse images from the search results to not create another texture.
*/
AFRAME.registerComponent('menu-selected-challenge-image', {
schema: {
selectedChallengeId: {type: 'string'}
},
init: function () {
this.searchResultEls = document.getElementById('searchResultList');
},
update: function () {
const data = this.data;
const el = this.el;
if (!data.selectedChallengeId) { return; }
const imageEl = this.searchResultEls
.querySelector(`[data-id="${data.selectedChallengeId}"] .searchResultImage`);
el.getObject3D('mesh').material.map = imageEl.getObject3D('mesh').material.map;
el.getObject3D('mesh').material.needsUpdate = true;
}
});