How to deallocate texture from memory in A-Frame?

点点圈 提交于 2019-12-11 01:13:52

问题


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>

回答1:


EDIT: 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.

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

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

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



来源:https://stackoverflow.com/questions/42427327/how-to-deallocate-texture-from-memory-in-a-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!