Three.js intersectScene 获取空对象
我为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 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.