如何在运行时添加图像资产? [英] How do I add image assets at runtime?

查看:70
本文介绍了如何在运行时添加图像资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的实体:

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

我正在尝试分配一个新的Base64图像字符串,如下所示:

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

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

这似乎有用,因为出现了 myTexture 包含新图像。但是, entity1 不会使用该新材料进行更新。

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?

推荐答案

修改实体,而不是修改< a-assets> 中的内容。资产管理系统用于预加载和缓存。如果您是动态设置资产,则可以将其内联设置。

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

这篇关于如何在运行时添加图像资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆