Enhance your .obj files by incorporating buttons using three.js

I am currently using three.js to load multiple obj files into a scene. These files combine to create a single unit. My objective is to enable users to customize the color of each part of this rendered unit. I am attempting to place buttons on each section of the unit so that users can click on them to access different customization options for that specific part. However, I am facing challenges in adding child objects to the various components of the unit. Any assistance or guidance on how to approach this would be highly valued.

Answer №1

When the mouse hovers over an object, I am able to display a tag on that object using a raycaster.

//Defining a vector to project the mouse onto objects
var vector = new THREE.Vector3(mouseX, mouseY, 1);
projector.unprojectVector(vector, camera);

raycaster.set(camera.position, vector.sub(camera.position).normalize());
// Finding the intersected object
var intersects = raycaster.intersectObjects(scene.children);

if (intersects.length > 0) {
   var intersected = intersects[0].object;
   // The drawtag method is defined on the object to draw additional elements like shapes and text
   intersected.drawTag();
}

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

Managing timeout in nodejs requestsDoes this work for you?

Currently, I am facing an issue while making a request to a server with a set timeout. I need to handle both the timeout event and the 'abort' event separately, but my current implementation involves using a quick fix which doesn't seem idea ...

Creating a text field that allows both letters and numbers to be entered

Here is the input field setup: <input id="address1" class="work" />Address1 <input id="address2" class="work" />Address2 <input style="float: right; margin-bottom:20px" ...

Utilizing Weather APIs to fetch JSON data

Trying to integrate with the Open Weather API: Check out this snippet of javascript code: $(document).ready(function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { $(".ok").html("latitude: " + ...

Programmatically control the opening and closing of a React Material UI Snackbar component

Currently, I am facing some challenges while working on programming a Single Page Application (SPA) using React and Material-UI. In my project, I have created a modal login box that gets triggered by a button on the navigation bar. Upon clicking submit, I ...

Access basePath within the Next.js AppRouter

Is there a way to access the basePath in Next.js 13 when using AppRouter? To retrieve it, we can simply get router.basePath through the useRouter hook of PageRouter by importing `import { useRouter } from 'next/router' I am currently unable to ...

Unable to access the get method of an undefined node.js object

I'm currently working on implementing a new structure and scalability approach for an express application. Challenge: I am looking for a way to automatically load routes without having to define each one in the app.js file. Proposed Solution: I ai ...

Is it possible to use an if statement within the .map()

I am seeking guidance on how to incorporate an if statement inside .map() Please refer to the code snippet below for context. Currently, the delete button is disabled when the image is not uploaded by the current user, but my objective is to complet ...

Having trouble with CORS errors persisting despite configuring CORS options for Google Authentication on React/Node/Passport

Currently, I'm in the process of developing a basic application using React for the frontend and Node/Express/MongoDB for the backend. User authentication is being handled through Passport, with local authentication and Google authentication both func ...

Ways to block WebSocket access on a personal computer

Is it possible to protect my server resources from being accessed by other websites, such as example.com, via WebSocket? I want to prevent them from accessing the server using a URL like "ws://47.80.151.189:1234", and utilizing its resources (bandwidth, me ...

Use jQuery to smoothly scroll a div

I created a container using a <div> element which is divided into 3 inner divs. The first two inner divs are meant to serve as previous and next buttons, with ids of prev and next respectively. At the bottom, there are 3 more inner divs, each with un ...

Tips for effectively passing query string parameters in Angular

I am looking to make an HTTP request with parameters through a query For instance: URL: https://api/endpoint?d=1&value=2 ...

I'm experiencing a lack of feedback while implementing jQuery/AJAX with JSONP

Attempting to perform a cross-domain request using jQuery/AJAX, I have the code below; $.ajax({ url: "http://www.cjihrig.com/development/jsonp/jsonp.php?callback=jsonpCallback&message=Hello", crossDomain:true }) .done(function( msg ) { alert( ...

Including additional data in JSON objects

For example: I have an object named tempobj with sample data at indexes tempobj[0] and tempobj[1]. Now, I would like to include additional information like name and status in this object. tempobj["info"]["name"] = "title"; tempobj["info"]["id"] = "23243 ...

Attempting to store a specific h1 text.event as a variable, allowing it to be saved upon input of the initial letter

After typing the second key, you can continue to input more characters as desired. It is possible to customize the text displayed in the h1 using your own name or any other text of your preference without needing a textbox. $(document).keypress(functio ...

I can't seem to establish a connection with my MongoDB Atlas cluster. I encountered the MongooseError, which is as follows:

Error [MongooseError]: The uri parameter for the openUri() method needs to be a string but is currently set as "undefined". Please ensure that the first parameter for mongoose.connect() or mongoose.createConnection() is a valid string. const express = r ...

How can you apply color to {{expression}} text using AngularJS while also keeping all the text on a single line?

After writing the following code, I noticed that when I enter text into the input box, an output appears. However, I am now trying to find a way to color the output text while keeping it on the same line. <script src="https://ajax.googleapis.com/ajax ...

Troubleshooting issue with the JQuery .change function not working in HTML <select>

I can't figure out why this code isn't working. It seems like it should be simple enough. Take a look at my drop-down menu code: <div> <form> <select id='yearDropdown'> <c:forEach var="year ...

Setting up Webpack for react-pdf in a Next.js application

In my Next.js application, I am utilizing the react-pdf library to generate and handle PDF files on the client side without involving the server. However, I am facing challenges in setting up Webpack for Next.js as I lack sufficient expertise in this area. ...

What is the best way to adjust an image's dimensions to fit a specific screen size without distorting it on a webpage?

Currently working on a website, and the top section has a small column on the right with an image taking up the majority of the space to the left. The problem arises when the image spills over the screen size, messing up the overall layout of the page. I d ...

Importing a CSV file into Highcharts for data visualization

I am in the process of plotting Csv column data using highcharts. Instead of utilizing the following code snippet: $.get('5.csv', function(data) I am interested in inputting a local desktop Csv file with the help of: function handleFileSelect( ...