What is the process for making a name tag that pops up when a model is clicked in a 3-D viewer?

After loading individual STL structures into my 3-D viewer using three.js, I would like the ability to click on each structure and have a name tag appear when hovering over it.

I believe this functionality may be related to the coordinate point of the object or possibly the total surface area. Utilizing an onMouseClick eventHandler might be a solution, but I am uncertain.

Are there any sample codes or open source resources available that demonstrate this feature?

Thank you!!

Answer №1

If you're looking for examples of collision detection, be sure to check out the various demos in the examples folder. One particularly useful example is webgl_interactive_cubes.html, which can be found here:

By exploring these examples, you'll learn how to determine which element is located behind the mouse cursor.

For a deeper understanding of object picking in three.js, I have written a tutorial that delves into the internal workings of the process:

Once you have obtained the mouse position from the mousemove or mouseclick event, simply create a span or similar element and position it using CSS's left and top properties accordingly.

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

What is the best way to merge javascript files and have them load after the page has already loaded on an asp.net site?

I recently came across a helpful SE Post that discussed combining external javascript files for better optimization, which is something I'm interested in. Following recommendations, I have converted internal javascripts into an external .js file and s ...

When utilizing a node.js TCP socket to receive and send modified data, the functionality only operates successfully on the initial attempt

I am attempting to create a node.js TCP socket that will receive data, modify it, and then send it back. I found a helpful example on Stack Overflow here: . The example works perfectly as is, but when I add my own code to send data back, it only works for ...

Utilizing GCE API within my website

Currently, my goal is to retrieve GCE information in a read-only manner to showcase infrastructure data on my website. To achieve this, I aim to acquire an OAuth2 token using the JS API and then transmit it to a Python Backend for GCE API calls. It's ...

AngularJS is throwing a $injector:modulerr error and I've exhausted all possible solutions

I recently started learning Angular and I've been following the tutorial on the official AngularJS website. Here's what I've tried so far: Installed angular-route and included the script below angular.min.js Utilized ngRoute in my mod ...

Execute a refresh command on a JQuery function in order to update the selection picker

Below is the HTML code I have created to allow for multiple options to be selected with live search capabilities. My knowledge of jQuery is limited, but I have included a code snippet to refresh the selections if more than one option is chosen. < ...

Monitor website visitors' traffic sources using the Google Analytics Nuxt module

Recently I integrated Google Analytics into my Nuxt website. After installing the module, I configured it in the nuxt.config.js file like this: gtm: { id: 'GTM-WGW****' }, googleAnalytics: { id: 'UA-230******-*' ...

After clicking, an created modal is displayed, then disappears on its own

After creating 2 Modals, I encountered an issue where the second modal with the class "category-modal" reverts back to display none when I click the "+" sign on the form. The first modal, with the class "modal," displays correctly when the add button is cl ...

Is there a way to obtain the tasklist result of exec() from child_process and convert it to JSON format?

When I use the tasklist command with child_process, the stdout returns processes in Unicode string format that is not easily queryable. Here is the code snippet: var exec = require('child_process').exec; ... exec('tasklist', function( ...

Using webpack to bundle node_modules into your application

I am facing an issue while trying to load some modules like: moment echarts In my package.json file, I have the following versions specified: "echarts": "^3.1.10" "moment": "^2.14.1" However, I am encountering the errors below: VM2282:1 Uncaught Ref ...

What is the best way to declare strings within a Typescript interface?

I have an array of Projects with multiple strings in the stack property const projects: IProject[] = [ {name: '', description: '', stack: {'php', 'sql'}} ] What is the best approach for defining the interface? ...

Error message in Leaflet JS: Unable to access property 'addLayer' because it is undefined when trying to display drawnItems on the Map

My attempt to showcase a Leaflet Map with polygon-shaped surfaces encountered an issue. Sometimes, I face the error "cannot read property 'addLayer' of undefined," but when the page is refreshed, the map renders correctly. I am unsure where I wen ...

Creating a JavaScript object using a provided JSON string

Having a large JSON data that needs to be parsed in order to extract objects from the given JSON string. The top part of the data has been included here. Initial attempts to parse it using the code snippet below resulted in an error: let obj = JSON.parse(t ...

The navigation bar options are not collapsing as intended

When I resize my page to width:750px;, my navigation bar is not collapsing the items. Despite trying to edit my CSS, I am still clueless. Here is my live page. This is the CSS for my slidebar: @media (max-width: 480px) { /* Slidebar width on extra small ...

Ways to preserve decal placement using Three.js

I am searching for a solution to store and reload the decals generated in this example (source code). The goal is to allow users to save a new splatter they paint and then reload it at a later time. I have attempted various methods, but none have been succ ...

Is there a way to use the property of an object to perform a merge sort, rather than relying on an Array?

Query About Sorting JSON Object in JavaScript In search of the most efficient method to sort a large JSON object based on a specific property, I turned to JavaScript. My initial thought was to utilize a merge sort algorithm for this task due to its speed. ...

What is the best way to display a button only when a different element is in focus?

I am working on a feature where each row consists of two text inputs and a button. The goal is to show the button when a user focuses on one of the input fields, and hide it again when they lose focus. I have come up with this solution: const Input = ({inp ...

What is the technique for choosing the parent's ID with jQuery?

When a user clicks on any team, I need to retrieve the parent's parent ID. For example, if someone clicks on a Premier League Team, I want to store the ID 2 in a variable called league_id. Here are my attempts so far: Using Closest Method $('u ...

Unable to retrieve JSON data from a PHP file hosted on the server

I have a server-side database with a table called "customers" and a column named "names". My goal is to send a request to the server asking for the first two records in the "customers" table. However, when I execute the program, the browser does not displa ...

beforeprinting() and afterprinting() function counterparts for non-IE browsers

Is there a way to send information back to my database when a user prints a specific webpage, without relying on browser-specific functions like onbeforeprint() and onafterprint()? I'm open to using any combination of technologies (PHP, MySQL, JavaScr ...

Merging and Reorganizing files using Gulp based on Folder names

In my gulpfile.js, I am attempting to configure a setup that concatenates all .js files located in the src/js folder and names them based on their parent folder. Here is an example of the folder structure: project | +-assets | | | +-app.min.js | | | +-ve ...