动态更改Raycaster位置 [英] Changing Raycaster position dynamically

查看:121
本文介绍了动态更改Raycaster位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块画布,里面有几个立方体.我使用Raycaster来选择它们并更改它们的颜色.但是画布位于draggable对象的内部,当我四处走动时无法更改颜色,因此颜色更改可以在原始位置进行.我认为我还必须更改Raycaster的尺寸.我该怎么办?

I have a canvas, inside that I have several cubes. I use Raycaster to select them and change their colors. But the canvas is inside of a draggable object and when I move around I cannot change the colors, the color changing works in the original position. I think I also have to change the dimensions of the Raycaster. How can I do that?

这是示例.

推荐答案

尝试如下更改代码:

function onDocumentMouseDown( event ) {

    event.preventDefault();

    var x = event.offsetX == undefined ? event.layerX : event.offsetX;
    var y = event.offsetY == undefined ? event.layerY : event.offsetY;

    var vector = new THREE.Vector3();
    vector.set( ( x / renderer.domElement.width ) * 2 - 1, - ( y / renderer.domElement.height ) * 2 + 1, 0.5 );
    vector.unproject( camera );

    raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
...

这篇关于动态更改Raycaster位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆