How do I add image assets at runtime?

2019-09-11 11:08发布

问题:

I've got an entity like this:

<a-entity id="entity1" 
    position="0 0 -1"
    geometry="primitive: plane; width: 1"
    material="src: #myTexture;  opacity:0.9; transparent:true;">

I'm attempting to assign a new Base64 image string like this:

myTexture.setAttribute('src','data:image/png;base64,xxx');

This seems to work in that myTexture appears to contain the new image. However, entity1 is not updated with that new material.

Does anybody know how to fix it?

回答1:

Modify the entity rather than the stuff in <a-assets>. The asset management system is for preloading and caching. If you are setting assets dynamically, you can set them inline.

el.setAttribute('material', 'src', 'url(data:image/png;base64,xxx)').



标签: aframe