A THREE.Texture
can be used as a map in a material and has a property called "image".
A THREE.WebGLRenderTarget
can be used as a map in a material but does not have a property called "image".
How would I retrieve the texture-data from a WebGLRenderTarget
? I would like to save it to a file (or, if that is not possible, as a byte array).
New function for this now:
WebGLRenderer.readRenderTargetPixels ( renderTarget, x, y, width, height, buffer )
Reads the pixel data from the renderTarget into the buffer you pass in. Buffer should be a Javascript Uint8Array instantiated with new Uint8Array( renderTargetWidth * renderTargetWidth * 4 ) to account for size and color information. This is a wrapper around gl.readPixels.
I haven't tried it myself, but it should be possible to get a byte array using WebGL's readPixels function passing the render target's (private) __webglTexture
property.
来源:https://stackoverflow.com/questions/13475209/three-js-get-data-from-three-webglrendertarget