three.js 鼠标点击获取物体的信息

需要引用文件 renderers/Projector.js
在raycaster.intersectObjects()中写要监听的物体
调用 document.addEventListener('mousedown', getClickMap, false);

var projector=new  THREE.Projector();
var i=1;

function getClickMap(){

var    vector=new THREE.Vector3((event.clientX/window.innerWidth)*2-1,-(event.clientY/window.innerHeight)*2+1,0.5);

vector=vector.unproject(camera);

var raycaster=new THREE.Raycaster(camera.position,vector.sub(camera.position).normalize());

var  intersects=raycaster.intersectObjects([cube]);

if(intersects.length>0){

console.log(intersects[0]);

intersects[0].object.material.transparent=true;

intersects[0].object.material.opacity=1*i;

intersects[0].object.material.color=new THREE.Color(0xededed);

intersects[0].object.scale.x=2*i;



}

你可能感兴趣的:(three.js 鼠标点击获取物体的信息)