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

查看:15
本文介绍了动态更改 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天全站免登陆