0
votes

I'm trying to get a distance to intersection of a mesh. The mesh is a imported json loaded with ObjectLoader.

    trnek.set(pozTravcex,0,pozTravcez);
    sidro.set(pozTravcex,100,pozTravcez);
    sidro.normalize();
    plovc.set(trnek,sidro);
    scene.updateMatrixWorld();
    visinaTravce = plovc.intersectObjects(scene.children,true);
    var point=0;
    for (var j=0; j < visinaTravce.length; j++){
        if (visinaTravce[j].object.name == "tla"){
                pozTravcey = visinaTravce[j].distance; //plovc.ray.origin.distanceTo(visinaTravce[0].point);
            point = visinaTravce[j].point;
            console.log("razdalja je: ",visinaTravce[j].point.y);
  • I got it working, if I shrink the mesh before I export it. ( so I operate with coordinates <2.0.
  • Scaling the mesh gives issues to raycaster ( I updated the scenes matrixWorld. )

So bottom line is. I get the right y distance if the object is super small. If I resize and export it, then the measured distance gets messed up the farther away from center it goes.

http://s000.tinyupload.com/?file_id=51927245638674467144

on the left side the picture grass is near 0,0,0, the distance measured ( y ) is right. Farther away the distance gets wrong. If I shrink the object, everything is in place.

is this a bug perhaps?

1
To anyone else having issues with this... if you're using setInterval or setTimeout for your animation/physics and requestAnimationFrame for rendering, you may be depending on your render timing to call scene.updateMatrixWorld() while your Object3D positions are updated via setInterval. That's nondeterminism because the raycaster may sometimes be using an old transform. An easy fix is to call scene.updateMatrixWorld at the end of each timestep. - Samuel Danielson

1 Answers

0
votes

Oh, I was making a mistake when using the Raycaster. The second parameter is just the direction. I set it to 0,1,0 and it worked.