Three.js intersectScene 获取空对象

发布于 2024-12-17 07:59:00 字数 1165 浏览 2 评论 0原文

我为 mouseMove 和 mouseDown 编写了两个非常相似的函数。虽然前者工作正常,但后者不断从 var intersects = ray.intersectScene( scene ) 获取空对象。

您可以在这里找到完整的代码 http://converteveryunit.com/pot/biluochun/temp/ 谢谢。

function onDocumentMouseMove(event) {

    mouseX = event.clientX - homeWidth/2;
    mouseY = event.clientY - homeHeight/2;

    var vector = new THREE.Vector3( ( event.clientX / homeWidth ) * 2 - 1, - ( event.clientY / homeHeight ) * 2 + 1, 0.5 );
    projector.unprojectVector( vector, camera );

    var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

    var intersects = ray.intersectScene( scene );
}


function onDocumentMouseDown( event ) {

    event.preventDefault();

    var vector = new THREE.Vector3( ( event.clientX / homeWidth ) * 2 - 1, - ( event.clientY / homeHeight ) * 2 + 1, 100 );
    projector.unprojectVector( vector, camera );

    var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

    var intersects = ray.intersectScene( scene );
    console.log( intersects);

    }

I wrote two very similar functions for mouseMove and mouseDown. While the former works fine the latter keep getting empty object from var intersects = ray.intersectScene( scene ).

You can find complete code here
http://converteveryunit.com/pot/biluochun/temp/
Thanks.

function onDocumentMouseMove(event) {

    mouseX = event.clientX - homeWidth/2;
    mouseY = event.clientY - homeHeight/2;

    var vector = new THREE.Vector3( ( event.clientX / homeWidth ) * 2 - 1, - ( event.clientY / homeHeight ) * 2 + 1, 0.5 );
    projector.unprojectVector( vector, camera );

    var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

    var intersects = ray.intersectScene( scene );
}


function onDocumentMouseDown( event ) {

    event.preventDefault();

    var vector = new THREE.Vector3( ( event.clientX / homeWidth ) * 2 - 1, - ( event.clientY / homeHeight ) * 2 + 1, 100 );
    projector.unprojectVector( vector, camera );

    var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

    var intersects = ray.intersectScene( scene );
    console.log( intersects);

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌生 2024-12-24 07:59:00

我对 Three.js 不是很熟悉,但我忍不住想知道为什么你的向量在第一个函数中的 Z 分量为 0.5,而在第二个函数中为 100。如果一个有效而另一个无效,那么这肯定是一个不错的起点。

I'm not terribly familiar with Three.js, but I can't help but wonder why your vector has a Z component of 0.5 in the first function and 100 in the second. If one works and the other doesn't, that certainly feels like a decent place to start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文