javascript – Three.js THREE.Projector已移至

前端之家收集整理的这篇文章主要介绍了javascript – Three.js THREE.Projector已移至前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我明白在THREE 71版本中没有THREE.projector.

但我不会不知道,如何更换THREE.projector功能和什么?

这是我的点击功能

var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1,- ( event.clientY / window.innerHeight ) * 2 + 1,0.5 );
            projector.unprojectVector( vector,camera );
            var raycaster = new THREE.Raycaster( camera.position,vector.sub( camera.position ).normalize() );
            var intersects = raycaster.intersectObjects( objects );
          if ( intersects.length > 0 ) {
             clicked =  intersects[0];
             console.log("my clicked object:",clicked);


         }

什么是正确的方法

解决方法

现在有一种比较简单的图案可以用于正视和透视相机类型:
var raycaster = new THREE.Raycaster(); // create once
var mouse = new THREE.Vector2(); // create once

...

mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;

raycaster.setFromCamera( mouse,camera );

var intersects = raycaster.intersectObjects( objects,recursiveFlag );

three.js r.84

原文链接:https://www.f2er.com/js/151734.html

猜你在找的JavaScript相关文章