Creating hyperlinks for objects in three.js can be achieved by using the

Here is the code from my firstpage.js file:

 $(function(){

/* initializing variables */
var scene, camera, renderer;
var spotLight, hemi;
var SCREEN_WIDTH, SCREEN_HEIGHT;
var mouse
var loader, model, animation;
var objects = [];

function init(){


    /* creating scene and renderer */
    scene = new THREE.Scene();
    camera =  new THREE.PerspectiveCamera(100, window.innerWidth/window.innerHeight, .1, 1000);
    renderer = new THREE.WebGLRenderer({antialias:true});

    renderer.setClearColor(0xEBE0FF);
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMap.enabled= true;
    renderer.shadowMapSoft = false;


    camera.position.x = -2;
    camera.position.y = 2;
    camera.position.z = -9; 
    camera.lookAt(scene.position);

    //hemi light
    hemi = new THREE.HemisphereLight(0xbbbbbb, 0x660066);
    scene.add(hemi);        

    /* adding spot light with starting parameters*/
    spotLight = new THREE.SpotLight(0xffffff);
    spotLight.castShadow = true;
    spotLight.position.set (20, 35, 40);
    scene.add(spotLight);

    //load blender scene
    var loader = new THREE.ObjectLoader();
    loader.load("test.json",function ( obj ) {

        scene.add( obj );

        scene.traverse(function(children){
            objects.push(children);
        });                 
    });                
    $("#webGL-container").append(renderer.domElement);      
} 
 function render() { 
       scene.rotation.y += .005;       
}


function animate(){
    requestAnimationFrame(animate);
    render();
    renderer.render(scene, camera);
}

init();
animate();

$(window).resize(function(){
    SCREEN_WIDTH = window.innerWidth;
    SCREEN_HEIGHT = window.innerHeight;
    camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
    camera.updateProjectionMatrix();
    renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
});

}); 

And here is the content of my firstpage.html file:

<HTML>
<title> Demo Page</title>
<body>
<div id ="webGL-container" style="z-index:-9;"></div>
<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">     </script>
<script type="text/javascript" src="three.min.js"></script>
<script type ="text/javascript" src="firstpage.js"></script>        
</body>
</html>

I want to make each model a hyperlink that redirects to a new page. The test.json file contains four different characters.

Answer №1

To start, set up an eventListener to detect mouse clicks.

Within that event listener, create a raycaster to determine if any objects have been clicked.

If an object has been clicked, use window.open(link) to open the specified link.

If you want each object to have its own unique link, you must specify which object corresponds to which link. Since the raycaster returns an object, you can iterate through the list of children in the scene and create conditional statements for each one.
For example:

if(raycaster.intersects[0] === object1) {
        window.open(link1)
} else if (raycaster.intersects[0] === object2) {
        window.open(link2)
}

Continue this pattern for each object.

If you are unfamiliar with using a raycaster, check out this example on how to set it up and utilize it effectively.

Answer №2

3Dink.js is a convenient wrapper library for three.js in WebGL, allowing for easy creation of 3D hyperlinks. It proves to be quite useful in this scenario.

With just 3 lines of code, you can enable click functionality and change the cursor.

DDDINK.addURL(object, "https://www.npmjs.com/package/3dink");
DDDINK.readRendererObj( renderer, scene, camera );
DDDINK.domEvent.addFnc();

Check out its repository here: https://github.com/takashift/3Dink.js

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for refreshing a live ajax call to animate a circle

Currently, I am utilizing the gaugeMeter plugin to dynamically display the CPU usage of my elasticSearch Host. While the values are being displayed correctly, there seems to be an issue with the animation of the gauge/circle itself. Instead of the indicato ...

Pass information from one .jsp file to a JavaScript function in another .jsp file

Here is the content of OneEmployee.jsp: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <form> <td> <c:out value="${emp.getEmpid()}"/></td> <td> <input type="text" id="fname" value="<c:out v ...

RequireJs is failing to load a script based on its name

Recently, I delved into the world of RequireJs to enhance my understanding. However, I encountered a hurdle while trying to load a JavaScript dependency using its custom shortened name. Despite my efforts, I can't seem to figure out what I'm doin ...

Executing polymorphism in Javascript without the use of OOP classes

In JavaScript or other object-oriented programming languages, polymorphism is achieved by creating different types. For instance: class Field {...} class DropdownField extends Field { getValue() { //implementation .... } } Imagine a library f ...

Deactivate the button in the final <td> of a table generated using a loop

I have three different components [Button, AppTable, Contact]. The button component is called with a v-for loop to iterate through other items. I am trying to disable the button within the last item when there is only one generated. Below is the code for ...

Choosing from a variety of tr elements

I'm working with a table in HTML that has about 100 rows. I would like to apply different colors to specific groups of rows, such as making rows 1-10 red and rows 20-40 blue. Using nth-child seems like an option, but it can get quite verbose if I nee ...

Tips for invoking an external JavaScript function using AJAX

I find myself a bit confused. In my project, there is an external javascript file called Hierarchy.js located in the Scripts folder. This file contains several functions, one of which is KeySelected. I need to call this function in the OnClientItemSelected ...

How can one transfer information from a client to a server and complete a form using JavaScript?

Can the information be transferred from a client to the server using just JS, then fill out a form on the server, and finally redirect the client to view a pre-filled form? I am considering utilizing AJAX to send a JSON object, but unsure if it will be s ...

Utilizing Angular.js to extract data from a deeply nested array of objects in JSON

Hello, I am currently learning about Angular.js and working on developing a shopping cart. In this project, I need to display an image, name, and cost of each product for multiple tenants. Each tenant has an array called listOfBinaries which contains listO ...

Is there a way to transfer the submitted data to a different page without being redirected to it using #php and #ajaxjquery?

Hey there, I could use a little assistance. How can I send data to page update.page.php when submitting a form on index.php without being redirected? I want the functionality of sending a message from one page to another without having to refresh the ent ...

Customize specific styles for individual divs one at a time (without the use of jQuery)

Can you assist me with this issue? I am trying to display the <span class="badge badge-light"><i class="fa fa-check-circle"></i></span> tag (initially set to "visibility: hidden") when clicking on a div with the class "role-box". He ...

Could there be a mistake in the way array combinatorics are implemented in JavaScript?

Having encountered the necessity for generating unique combinations when dealing with multiple arrays, I developed this script. While it functions as intended during the combination process, storing the result in a final array yields unexpected outcomes. ...

My component is displaying a warning message that advises to provide a unique "key" prop for each child in a list during rendering

I need help resolving a warning in my react app: Warning: Each child in a list should have a unique "key" prop. Check the render method of `SettingRadioButtonGroup`. See https://reactjs.org/link/warning-keys for more information. at div ...

Strange rendering issues when using the react material-ui dialog

Exploring the Project Recently, I developed a front-end project focusing on a delivery service using React and Material UI. One interesting feature I added was a Dialog window that pops up when users click on an item, allowing them to customize it. Here i ...

Tips on how to remove the filter from a select element using Angular?

My code includes the following HTML: <select ng-options="mark.id as mark.name for mark in marks" ng-model="markSearch.mark.id"> <option value="">-- Choose mark --</option> </select> ... <tr ng-repeat-start="pipeType in pipeT ...

A guide on incorporating dynamic formControlName functionality into AngularJs2

Currently, I am building forms using the form builder in AngularJS2. My goal is to incorporate the formControlName property/attribute into the form element as shown below: <input type="text" formControlName={{'client_name' + i}} placeholder=" ...

Issues with jQuery custom accordion functionality in Internet Explorer, Safari, and Chrome browsers

When a corresponding <a> is clicked, my script should expand/collapse UL elements. It works perfectly in Firefox and you can check it out here. First, I load the jQuery library and then my own examples.js file which includes: function initExamples( ...

Creating sparse fieldset URL query parameters using JavaScript

Is there a way to send type-related parameters in a sparse fieldset format? I need help constructing the URL below: const page = { limit: 0, offset:10, type: { name: 's', age:'n' } } I attempted to convert the above ...

Dilemma of interdependencies between Socket.io and requirejs

I am facing a challenge with my legacy express project that has two servers. The project includes two separate client files: requirejs.config({ baseUrl: '/js' , paths: { "jquery": "lib/jquery/jquery-2.1.1.min", "socket.io" : "lib/socket/ ...

I am having trouble establishing a connection between my Node.js server and the Google Cloud Platform server

I've been working on a global ESP32 Cam project, aiming for worldwide connectivity. I came across a tutorial that has been my guide: https://www.youtube.com/watch?v=CpIkG9N5-JM. I followed all the steps in the tutorial diligently, but unfortunately, I ...