我在three.js中创建了一个球体,其表面上有大约140个圆圈。
通过点击或触摸圆圈,用户可以更改其颜色。
虽然它在移动设备上有点滞后 - 有没有办法优化以下代码?
function onMouseDown( e ) {
mouseVector.x = 2 * (e.clientX / (window.innerWidth*0.8)) - 1;
mouseVector.y = 1 - 2 * ( e.clientY / window.innerHeight );
raycaster.setFromCamera( mouseVector, camera );
var intersects = raycaster.intersectObjects( circles );
if ( intersects.length > 0 ) {
var intersect = intersects[ 0 ];
pickedColor=parseInt(document.getElementById("color").value.replace('#', '0x'));
intersect.object.material.color = new THREE.Color( pickedColor );
render();
}
}