本文介绍了在 THREE.js 中克隆纹理而不会导致重复的卡内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用精灵表通过 THREE.js 创建动画纹理.每个精灵实例利用纹理偏移来控制呈现该帧的图像.多个动画精灵可能同时出现在屏幕上.

I am using sprite sheets to create animated textures with THREE.js. Each sprite instance utilizes texture offsets to control which of the images to present that frame. Multiple animated sprites may be on the screen at once.

目前我正在使用 Texture.clone() 来复制精灵表纹理.但是,除非我将 Texture.needsUpdate 设置为 true,否则纹理不会显示在精灵上.将 needsUpdate 设置为 true 允许我同时显示多个独立的动画精灵,但不幸的是这会导致纹理内存在卡(/集成芯片)上重复.使用 Chrome WebGL Inspector,我可以清楚地看到精灵纹理的复制次数与渲染的动画精​​灵相同.

Currently I am using Texture.clone() to duplicate the sprite sheet texture. However, unless I set Texture.needsUpdate to true, the texture will not display on the sprites. Setting needsUpdate to true allows me to display multiple independent animated sprites at once, but unfortunately this causes the texture memory to be duplicate on the card (/ integrated chip). Using Chrome WebGL Inspector I can clearly see that the sprite texture has been duplicate the same number of times as animated sprites that have been rendered.

有没有办法在不复制内存的情况下为每个实例克隆/重用具有不同偏移量的纹理?这是错误还是我做错了什么.

Is there any way to clone / reuse the texture with different offsets for each instance without duplicating the memory? Is this a bug or am I doing something wrong.

三.js r67

更新:

我们解决这个问题的一种方法(我承认这不是一个好方法)是复制分配给原始纹理的 GL 纹理 ID,并将克隆的纹理设置为已初始化.

One way that we have gotten around this (not a great way I admit) is to duplicate the GL texture ID assigned to the original texture and set the cloned texture as being initialized.

clonedTexture.__webglTexture = origTexture.__webglTexture;
clonedTexture.__webglInit = true;

这要求纹理已经发送到卡片,我们使用 render.setTexture(origTexture...) 强制发送.

This requires that the texture has already been sent to the card, which we force with render.setTexture(origTexture...).

推荐答案

这是正在进行中的事情.随时关注 THREE.Image 登陆.

This is something that's in the works. Keep an eye for whenever THREE.Image lands.

这篇关于在 THREE.js 中克隆纹理而不会导致重复的卡内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:51