0
我想在webgl中創建交互式地圖。地圖圖像中的每個國家都充滿了獨特的顏色。當用戶點擊圖像時,我使用readPixels()讀取單擊的點的像素數據,並根據像素的顏色來突出顯示該像素。但是,每次點擊同一個國家/地區都會返回稍微不同的顏色,導致點擊該國的信息不正確。變化的像素顏色值相同
如何消除找到圖像上點的確切顏色的錯誤,用戶點擊?陰影效果或照明位置是否會導致此問題? 還是有不同的方法來確定用戶點擊圖像的位置以及它對應的國家?
var texture = THREE.ImageUtils.loadTexture('map_indexed.png');
var material = new THREE.MeshLambertMaterial({map: texture});
var sphere = new THREE.Mesh(new THREE.SphereGeometry(globeRadius, globeRadius, globeRadius),material);
sphere.overdraw = true;
scene.add(sphere);
讀取像素數據
var x = e.pageX ;
var y = e.pageY ;
var canvas = document.getElementById('canvas');
var gl = renderer.getContext();
//read the pixel under the mouse from the texture
var pixelBuffer = new Uint8Array(4);
var xp=gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelBuffer);
代碼在哪裏? – mplungjan
@mplungjan添加了相關代碼的部分 –