THREE.js: get data from THREE.WebGLRenderTarget

青春壹個敷衍的年華 提交于 2019-12-01 04:50:44

问题


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).


回答1:


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.




回答2:


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

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