Clicking objects returning and same name and uuid

So I have a scene with planets everytime I click on a different planet it is returning the same uuid and name “VenusLow_venus_0” and “53FFC54B-FF01-4BF7-A741-BE2F9A9B6315”
so If I click the Sun for example or Jupiter it is returning the VenusLow name and the 53FF uuid it is the same if I click the black space where there is no object…
I an curious to what I am doing wrong?

Snippet:

var raycaster, mouse;
init();

    function init() {
    raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
    renderergl.domElement.addEventListener( 'click', onClick, false );
    }

function onClick() {

	event.preventDefault();

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

	raycaster.setFromCamera( mouse, camera );

	var intersects = raycaster.intersectObjects( scene.children, true );

if (intersects.length > 0){
    var clickedID = intersects[0].object.uuid;
    var clickedName = intersects[0].object.name;
    console.log('You clicked: ' + clickedName); 
    console.log('UUID: ' + clickedID); 
}

}

https://jsfiddle.net/qdcga0hj/1/

hi, first it’s necessary full example code to check what’s happen.
I recommend you jsfiddle vs codesandbox.

It’s possible you need to set intersects[0].object

Hi here is a jsfiddle
https://jsfiddle.net/qdcga0hj/1/ (it might take a second of 2 for the models to load)

if you click on the sun for example or anything else even in the black space it keeps returning Venus in the console

it seems it works correct, this is a nearest object to camera

So when I click the sun how would I return its name or uuid ? because at the moment I keep getting Venus

I think you should check, what is VenusLow_venus_0, why it is so close to camera, but we cannot see it

1 Like

I think the problem is the structure of scene.gltf because gltf.scene[0] is a Group.
You can open console here https://jsfiddle.net/8abf7yLj/13/ and you look scene.children and result of click.

1 Like