Rotar Paul
Rotar Paul

Reputation: 129

Three js Raycast inside a Skydome

So I'm working at a game world where everything is contained in a skydome(giant sphere with environment texture applied).

I'm trying to find out the intersect point of the ray inside the skydome in order to find out the vector player will need to move towards.

the only Issue I found out so far is that the ray wont be casted inside the skydome but when zooming outside of it.

This is how the raycaster looks like on my side.

        mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
        mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

        // update the picking ray with the camera and mouse position
        raycaster.setFromCamera( mouse, camera );
        // raycaster.set(playerModel, c);

        // calculate objects intersecting the picking ray
        var intersects = raycaster.intersectObjects( scene.children, true );

        console.log(intersects);
        for ( var i = 0; i < intersects.length; i++ ) {

            intersects[ i ].object.material.color.set( 0xff0000 );

        }

Also, I would be gratefull if anyone can explain me how do I get the vector where the raycast goes to, not by using raycaster.setFromCamera( mouse, camera ); but raycaster.set(playerModel, targetVector); Does the target vector needs to be the position vector of the skydome?

Upvotes: 0

Views: 506

Answers (1)

Martin
Martin

Reputation: 2683

Working example i used manytimes:

var spaceplane = [];           
var spaceMaterial  = new THREE.MeshBasicMaterial();
    spaceMaterial.side = THREE.BackSide;
var meshSpace = new THREE.Mesh( new THREE.IcosahedronGeometry( 1000000, 1 ) , spaceMaterial );       
    meshSpace.rotation.order = 'XZY';
    spaceplane.push( meshSpace );
    //// add to the scene of course

//////////////// selection on mouse click etc...
var raycaster = new THREE.Raycaster();
    raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( spaceplane, true );


if ( intersects.length > 0 ) {                         
                            /// here you have intersection    
}

Upvotes: 1

Related Questions