Stephen Keegan
Stephen Keegan

Reputation: 11

How do I add image assets at runtime?

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?

Upvotes: 1

Views: 1077

Answers (1)

ngokevin
ngokevin

Reputation: 13233

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

Upvotes: 2

Related Questions