克隆一个由THREE.WebGLRenderTarget创建的纹理。

huangapple go评论85阅读模式
英文:

Cloning a texture created with THREE.WebGLRenderTarget

问题

我正在使用three.js,并且需要创建一些由THREE.WebGLRenderTarget()生成的纹理的克隆。

我可以使用原始纹理,例如:

scene.background = renderTarget.texture;

但如果我尝试使用它的克隆:

const tex = renderTarget.texture.clone();
scene.background = tex;

我会收到以下错误:

THREE.WebGLState: TypeError: Failed to execute 'texSubImage2D' on 'WebGL2RenderingContext': Overload resolution failed.

如果我添加以下代码:

tex.isRenderTargetTexture = true;

现在我不会收到任何错误,但纹理全是黑色的。

我还尝试过克隆渲染目标(而不是其纹理),但也没有成功。请您帮助我吗?

提前感谢您。

英文:

I'm using three.js and I need to create a few clones of a texture made with THREE.WebGLRenderTarget().

I can use the original texture, e.g.:

scene.background = renderTarget.texture;

But if I try to use a clone of it:

const tex = renderTarget.texture.clone();
scene.background = tex;

I get the following error:

THREE.WebGLState: TypeError: Failed to execute 'texSubImage2D' on 'WebGL2RenderingContext': Overload resolution failed.

If I add the line:

tex.isRenderTargetTexture = true;

Now I don't get any error, but the texture is all black.

I have also tried to clone the render target (instead of its texture) but it didn't work either. Can you please help me?

Thank you in advance.

答案1

得分: 0

问题已解决:我创建了一个帧缓冲纹理,并使用THREE.WebGLRenderer类的renderer.copyFramebufferToTexture()方法将纹理复制了出来。

英文:

Problem solved: I created a framebuffer texture, and I copied the texture by using method renderer.copyFramebufferToTexture() of class THREE.WebGLRenderer.

huangapple
  • 本文由 发表于 2023年6月1日 18:51:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定