I would like to equip a virtual tour with many different objects
with eventlistener, which show text in a html-element when onlick or mousover. (Individually per object)
Now I’m dealing with raycaster, as I understand it at the moment or in every example I’ve seen, the raycaster reads the mouse position and then executes the event.
Now my questions :
Would it be possible to give the raycaster a position so that the event only fires when I move my mouse over my objects ?
Like this ?
const raycasterMadonna = new THREE.Raycaster();
const mouse2 = new THREE.Vector3(x,y,z);
function onMouseMove( event ) {
}
function render() {
raycasterMadonna.setFromCamera( mouse2, camera );
const intersects = raycasterMadonna.intersectObjects( scene.children );
for ( let i = 0; i < intersects.length; i ++ ) {
intersects[ i ].object.material.colour.set( 0xff0000 );
}
renderer.render( scene, camera );
}
window.addEventListener( 'mousemover', false );
(I took the code from several examples here in the forum, and modified it a bit.)
raycasting can be used like an object. It’s not mandatory to use it with camera or mouse. Here is a basic example with a raycast starting at the center of the scene, firing up to 100 unit lenght on axe Y.
//direction
let direction = new THREE.Vector3( 0, 100, 0 );
direction.normalize();
//origin
let origin = new THREE.Vector3( 0, 0, 0 );
//raycaster
let raycaster = new THREE.Raycaster(origin, direction);