Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Three.js: how to add a custom URL on a loaded GLTF model

I have a galaxy made of 3 planets and a spaceship and I want all of them to be clickable to load another page. I managed to do so with the 3 planets adding planet.userData = {URL: "my.html"}; but not with the spaceship, which is a GLTF loaded model.

This is how I loaded the spaceship:

const loader = new GLTFLoader();
            loader.load('models/spaceship.glb', function(gltf) {

                const spaceship = gltf.scene;
            
                spaceship.scale.set(0.08, 0.08, 0.08);
                spaceship.userData = {URL: "my.html"}; //Adding the URL here
                objects.push(spaceship); //This is for raycasting
                scene.add(spaceship);
                
                
            }, undefined, function(error){
                console.error(error);
            });

And this is the function for the Mouse Down event:

function onDocumentMouseDown(){

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

                const raycaster = new THREE.Raycaster();
                raycaster.setFromCamera(mouse, camera);
                const intersects = raycaster.intersectObjects(objects, true);

                if ( intersects.length > 0 ) {
                    window.open(intersects[0].object.userData.URL); // <-- Doesn't work
                }

            }

When clicking on the spaceship the URL value is "undefined". I'm sure there is another way to do so but I can't find any solution. Thank you so much in advance to anyone helping!

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!