如何解决AFRAME,在启动后不能使用下载的资产
因此,在一些初始API调用之后,我的一些a帧场景资产(图像,声音)会动态加载。
这些资产的URL无法在html文件中进行硬编码,因为我尚不知道它们将是什么。
(它们因您所访问的网页/ product / 123,/ product / 456等而异)
因此,我不能将<assets>
用于纯预加载。
在调用API之后,我创建了一些新的<img>
DOM元素,如下所示:
var new_asset = document.createElement("img");
new_asset.setAttribute('id',"late_photo");
new_asset.setAttribute('src',"https://cdn.glitch.com/2087dfa6-bd02-4451-a189-36095a66f386%2Fpoint3.jpg?v=1545394470620");
new_asset.setAttribute('crossOrigin',"anonymous");
document.getElementById("late_assets").appendChild( new_asset );
,然后尝试使用它们,其ID和setAttribute如下:
document.getElementById("skybox").setAttribute("src","#late_photo");
但是那是我遇到以下错误并且实体变黑的时候。
[Error] THREE.WebGLState: – SecurityError: The operation is insecure. — aframe-master.js:27470
SecurityError: The operation is insecure. — aframe-master.js:27470
texImage2D (bundle.js:39549)
uploadTexture (bundle.js:40462)
setTexture2D (bundle.js:40014)
safeSetTexture2D (bundle.js:40894)
setValueT1 (bundle.js:35554)
upload (bundle.js:36013)
setProgram (bundle.js:44218)
renderBufferDirect (bundle.js:42953)
renderObject (bundle.js:43700)
renderObjects (bundle.js:43670)
render (bundle.js:43447)
render (bundle.js:91687)
bound (bundle.js:95466)
onAnimationFrame (bundle.js:43306)
onAnimationFrame (bundle.js:33641)
我在大多数浏览器(safari 11 macOS,safari iOS 13,chrome iOS 13,firefox iOS 13)中都可以使用此功能……但是它确实可以在Mac上的Chrome上运行。
无论如何,我需要一种在所有浏览器上都可以使用的可靠机制,允许我随时加载/添加新资产并通过ID使用它们。
此处可运行的示例/代码:
- https://rattle-momentous-leaf.glitch.me
- https://glitch.com/edit/#!/rattle-momentous-leaf?path=index.html%3A40%3A76
谢谢。
PS:我不能仅使用url()
,因为当我与它们进行交互/单击时,我的实体可以更改其纹理,使用url意味着我的大纹理将每次都重新下载
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。