get transformed vertices positions after vertex shader in THREE.js

回眸只為那壹抹淺笑 提交于 2019-12-06 08:59:51

问题


I am changing the positions of some vertices inside a vertex shader but i can't find a way to get those new updated vertices positions back inside js (i'm currently using THREE.js : the vertex position of my mesh's vertices always remains the same). I found this link Retrieve Vertices Data in THREE.js, but glGetTexImage doesn't exist in webgl (and i'm quite skeptical about this floating-point texture method as well). Thanks for your help !


回答1:


If reading the data from the buffer is the only problem, you can do that like this:

//render the pass into the buffer
renderer.render( rttScene, rttCamera, rttTexture, true );

// ...


//allocate an array to take the data from the buffer
var width = rttTexture.width;
var height = rttTexture.height;
var pixels = new Uint8Array(4 * width * height); 


//get gl context bind buffers, read pixels
var gl = renderer.context; 
var framebuffer = rttTexture.__webglFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);        
gl.viewport(0, 0, width, height);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);

WebGL - reading pixel data from render buffer

But setting all this up is complicated, and reading the texture might be slow, why not do this on the cpu?



来源:https://stackoverflow.com/questions/32974942/get-transformed-vertices-positions-after-vertex-shader-in-three-js

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