THREE.js:从 THREE.WebGLRenderTarget 获取数据 [英] THREE.js: get data from THREE.WebGLRenderTarget

查看:109
本文介绍了THREE.js:从 THREE.WebGLRenderTarget 获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A THREE.Texture 可用作材质中的贴图,并具有称为图像"的属性.THREE.WebGLRenderTarget 可以用作材质中的贴图,但没有称为图像"的属性.

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

如何从 WebGLRenderTarget 检索纹理数据?我想将其保存到文件中(或者,如果不可能,则保存为字节数组).

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

推荐答案

新功能:

WebGLRenderer.readRenderTargetPixels ( renderTarget, x, y, width, height, buffer )

从 renderTarget 读取像素数据到您传入的缓冲区中.缓冲区应该是一个使用 new Uint8Array( renderTargetWidth * renderTargetWidth * 4 ) 实例化的 Javascript Uint8Array 以说明大小和颜色信息.这是 gl.readPixels 的包装器.

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.

这篇关于THREE.js:从 THREE.WebGLRenderTarget 获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆