How do I add image assets at runtime?

我与影子孤独终老i 提交于 2019-12-12 03:06:02

问题


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)').



来源:https://stackoverflow.com/questions/40143721/how-do-i-add-image-assets-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!