Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GPU在三个JS中拾取_Javascript_Three.js - Fatal编程技术网

Javascript GPU在三个JS中拾取

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

我正在使用三个js中的GPU拾取示例。有人能解释一下我们是如何从拾取纹理中检索对象的吗。我不明白代码是怎么工作的

//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对应,您可以确定单击的对象。