gpt4 book ai didi

javascript - Three.js THREE.Projector 已移至

转载 作者:可可西里 更新时间:2023-11-01 01:45:53 27 4
gpt4 key购买 nike

我知道版本 71 中没有 THREE.projector(请参阅 deprecated list),但我不明白如何替换它,尤其是在检测哪个对象已被替换的代码中点击:

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

关于javascript - Three.js THREE.Projector 已移至,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29366109/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com