My JavaScript skills are lacking... T_T
Is it possible to retrieve the position (x, y, z) where I clicked on a sprite or object?
Here is the code I have so far. Can someone help me out?
// Creating a sprite
var spriteMap = new THREE.TextureLoader().load( 'tag.png' );
var spriteMaterial = new THREE.SpriteMaterial( { map: spriteMap, color: 0xffffff } );
var sprite = new THREE.Sprite( spriteMaterial );
sprite.scale.set(3, 3, 1)
sprite.position.set(25, 20, 20)
scene.add( sprite );
objects.push(sprite);
// Adding a text sprite
var spritey = makeTextSprite( " spritey ",
{ fontsize: 24, borderColor: {r:255, g:0, b:0, a:1.0}, backgroundColor: {r:255, g:100, b:100, a:1.0} } );
spritey.position.set(-85,105,55);
scene.add( spritey );
console.log(makeTextSprite);
objects.push(spritey);
///////////////////Skipping some codes//////////////////////////////////
function onDocumentMouseUp(event) {
event.preventDefault();
var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2-1, -(event.clientY / window.innerHeight) * 2 + 1, 0.5);
projector.unprojectVector(vector, camera);
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObjects(objects);
if (intersects.length > 0) {
window.open(intersects[0].object.userData.URL);
console.log(intersects.length)
}
}