如何在A帧中从内存中释放纹理? [英] How to deallocate texture from memory in A-Frame?

查看:117
本文介绍了如何在A帧中从内存中释放纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从特定场景中不再需要的资产中分配内存。当前,在场景中卸载资产后,我们的资产纹理仍保留在内存中。

I’d like to know how to deallocate memory from assets that I no longer need in a particular scene. Currently, our assets textures are staying in memory after we unload the asset in a scene.

<a-scene>
  <a-box src="texture.jpg"></a-box>
</a-scene>


推荐答案

编辑:处理纹理的最简单方法是:获取实体的材质,然后调用 material.map.dispose()。例如, this.el.getObject3D('mesh')。material.map.dispose(),直到A-Frame可以自动处理它。

The easiest way to dispose a texture is to grab an entity's material and call material.map.dispose(). For example, this.el.getObject3D('mesh').material.map.dispose(), until A-Frame can automatically handle it.

您可以从 document.querySelector('a-scene')。systems.material.textureCache 获取纹理对象并运行 .dispose()在纹理上。

You can get the texture objects from document.querySelector('a-scene').systems.material.textureCache and run .dispose() on a texture.

或者,我相信您可以通过<$ c $从实体中获取纹理c> document.querySelector('a-entity')。components.material.material.map.dispose()。

Alternatively, I believe you can grab the texture from an entity via document.querySelector('a-entity').components.material.material.map.dispose().

有一个问题已提交以自动执行此操作: https://github.com/aframevr/aframe/issues/2166

There is an issue filed to do this automatically: https://github.com/aframevr/aframe/issues/2166

这篇关于如何在A帧中从内存中释放纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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