我的raycaster没有看到需要查看的对象,我尝试将鼠标xyz放置在对象所在的坐标上,但仍然无法正常工作,这是Three.js的新手,并且进行了raycasting,所以我陷入了这个问题最近2天
this.raycaster = new THREE.Raycaster();
this.mouse = new THREE.Vector3();
s.raycaster.setFromCamera(s.mouse, s.getCamera() );
s.canvas_model[0].addEventListener( 'mousedown', function(event)
{s.onMouseDown(event);} , false);
onMouseDown(event) {
let s = this;
s.bounds = s.canvas_model[0].getBoundingClientRect()
s.mouse.x = ( (event.clientX - s.bounds.left) / s.canvas_model[0].clientWidth ) * 2 - 1;
s.mouse.y = - ( (event.clientY - s.bounds.top) / s.canvas_model[0].clientHeight ) * 2 + 1;
s.intersects = s.raycaster.intersectObjects(s.blocks, true);
for ( var i = 0; i < s.intersects.length; i++){
s.intersects[ i ].object.material.color.set( 0xff0000 );
console.log(s.intersects)
console.log(s.mouse.x);
console.log(s.mouse.y);
}
if (s.intersects == 0){
// console.log(s.intersects)
// console.log(s.mouse.x)
// console.log(s.mouse.y)
}
我尝试过s.scene.children,它将看到地板和网格,但看不到块screenshot of application
希望这里的人遇到这样的问题,可以在这里帮助我