如何监听或检测纹理是否已加载/应用于A

编程入门 行业动态 更新时间:2024-10-08 18:40:07
如何监听或检测纹理是否已加载/应用于A-Frame中的材质/实体?(How to listen or detect that a texture has been loaded/applied to a material/entity in A-Frame?)

如何确定纹理应用于实体的时间?

<a-entity material="src: url(mytexture.png)"></a-entity>
 

有material-texture-loaded事件( https://aframe.io/docs/0.2.0/components/material.html ),但似乎只有在纹理完全到达浏览器后才会触发(而不是实际上正在应用)。

How do I figure out when a texture is applied to an entity?

<a-entity material="src: url(mytexture.png)"></a-entity>
 

There is the material-texture-loaded event (https://aframe.io/docs/0.2.0/components/material.html), but that seems to only be fired once the texture has fully arrived to the browser (rather than actually being applied).

最满意答案

在我们使用three.js设置material.map和material.needsUpdate后立即应用materialtextureloaded事件。

我们发现发生的是纹理图像宽度/高度没有两种功率分辨率(例如,64x64,512x512,128x1024)。 这对于大型纹理尤其重要,例如在a-sky使用的equirectangular照片。

因此,在运行时期间,three.js需要一些时间来调整纹理大小。 一旦我们调整了纹理大小,事件就会越接近屏幕上显示的纹理。

myEntityEl.addEventListener('materialtextureloaded', function () { setTimeout(function () { // setTimeout for good measure. console.log('material now showing on screen'); }, 200); });

The materialtextureloaded event is applied immediately after we set material.map and material.needsUpdate using three.js.

What we found was happening was that the texture image width/height did not have power-of-two resolutions (e.g., 64x64, 512x512, 128x1024). This is especially important for large textures like equirectangular photos used in a-sky.

Because of that, it took some time for three.js to resize the texture during runtime. Once we resized the texture, the event was firing closer to the time the texture displayed on screen.

myEntityEl.addEventListener('materialtextureloaded', function () { setTimeout(function () { // setTimeout for good measure. console.log('material now showing on screen'); }, 200); });

更多推荐

本文发布于:2023-07-27 04:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284916.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:纹理   应用于   加载

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!