Javascript GPU在三个JS中拾取
我正在使用三个js中的GPU拾取示例。有人能解释一下我们是如何从拾取纹理中检索对象的吗。我不明白代码是怎么工作的Javascript GPU在三个JS中拾取,javascript,three.js,Javascript,Three.js,我正在使用三个js中的GPU拾取示例。有人能解释一下我们是如何从拾取纹理中检索对象的吗。我不明白代码是怎么工作的 //create buffer for reading single pixel var pixelBuffer = new Uint8Array( 4 ); //read the pixel under the mouse from the texture renderer.readRenderTargetP
//create buffer for reading single pixel
var pixelBuffer = new Uint8Array( 4 );
//read the pixel under the mouse from the texture
renderer.readRenderTargetPixels(pickingTexture, mouse.x, pickingTexture.height - mouse.y, 1, 1, pixelBuffer);
//interpret the pixel as an ID
var id = ( pixelBuffer[0] << 16 ) | ( pixelBuffer[1] << 8 ) | ( pixelBuffer[2] );
var data = pickingData[ id ];
我知道我们是从纹理中获取像素值,但不清楚我们如何使用ID引用对象,所以实际上你要做的是读取光标下的颜色值。如果要渲染pickingTexture,您会看到所有框的RGB值略有不同。这些值与ID对应,您可以确定单击的对象。