Retrieve the object model's name that is loaded using OBJLoader when hovering - Three.js

How can we retrieve the name of an object model that was defined during loading from the array returned by the intersectObjects function? The code snippet below is currently returning undefined.

var objLoader = new THREE.OBJLoader();
  objLoader.setPath('obj/');
  objLoader.load('deadpool.obj', function(object){
    objModel = object;
    objModel.name = 'ObjectModel3D';
    modelHasLoaded = true;
    scene.add(objModel);
});

window.addEventListener('mousemove', function(eventTarget){
  var intersects = checkIntersection(eventTarget);
  if(intersects.length){
    console.log(intersects[0].name);
  }
}, false);

Answer №1

Successfully discovered the resolution. The key is to define the name with objModel.userData.name attribute. For accessing it upon hover, utilize intersects[0].object.parent.name. Trust this will be beneficial for any upcoming questions.

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

Identifying the JS Tree nodes that have been repositioned via drag-and-drop

I'm working with a JS Tree structure that includes drag and drop functionality. Here's the basic code I have so far: $('#using_html_1').jstree({ "core": { "check_callback":true }, "plugins" : ["dn ...

how to attach a function to a dynamically generated element

Currently, I am in the process of developing a placeholder-enabling feature. var t=document.createElement("input"); "placeholder" in t||$("input").each(function(){ if("submit"!==$(this).attr("type")){ var n=$(this),l=n.attr("placeholder"); ...

Rails Navigation Issue: JQuery Confirmation Not Functioning Properly

Having a Rails app, I wanted to replicate the onunload effect to prompt before leaving changes. During my search, I came across Are You Sure?. After implementing it on a form, I noticed that it only works on page refreshes and not on links that take you a ...

What is the method for displaying a view created from a dynamic URL in Django?

I'm facing a challenge with a page that displays a table of all clients from a database. My goal is to enable users to click on a specific client in the table and have only that client's data passed to the next page. My initial approach involved ...

Creating an Angular table row that can expand and collapse using ng-bootstrap components is a convenient and

I need assistance with an application I am developing, where I want to expand a table row to display details when it is clicked. The issue I am facing is that currently, all rows expand and show the data of the clicked row as seen in the image result below ...

Tips for arranging alternating elements in a column layout using an array data model

In the $scope there is a dynamic array and in the HTML template, there are three columns. The goal is to render elements from the array in the HTML like this: <div class="first-column"> <div><!--element of (index + 3) % 3 === 0 will be pl ...

Retrieving data from the Vuex store in a Nuxt component

https://i.stack.imgur.com/htnuL.png Seeking guidance on passing a list of button names into a menu component from the Vuex store as per the instructions at https://nuxtjs.org/guide/vuex-store In my /store/store.js: export const state = () => ({ & ...

Querying a list of objects with nested pointers using the Parse.com Javascript API

How can I efficiently query my Parse.com backend for a list of objects that contain specific pointers within them? For example, if ObjectA contains a list of pointers to ObjectB, how can I query for all ObjectA's that have ObjectB in their list? I a ...

What is the method for altering the text color in a password reset form?

After updating my password reset form in Django, I customized the background color to black and the text color to white. However, the help text still remains black, as shown in this image: https://i.sstatic.net/jhXqV.png I've attempted various method ...

ReactJS issue: Violation of the Invariant

I have recently started working on an exciting project using React JS and I have been enjoying the process so far. However, I recently encountered an error that has been causing me some trouble. Here is the error message I received: Uncaught Error: Invari ...

Issues with basic routing in Angular version 1 are causing problems

I'm encountering an issue while setting up my first Angular app with routing. It seems to be a simple problem but it's not working properly. Whenever I click on the links, the URL changes. index.html - file:///C:/Users/me/repos/angularRouteTes ...

Change the moment js format to the standard format

Seeking assistance to convert a date I obtained as Dec, 9th 2019, 05:23 AM using the format 'MMM Do YYYY, hh:mm A' back to the default format. However, all I'm receiving is 'Date '. Utilizing moment js for this task and uncertain i ...

Token not provided (Vue Stripe)

I am facing an issue while trying to process a payment using Stripe. Every time I click onPurchase, I receive an error message saying "no token provided". Can anyone assist me with this? Below is my Vue template where I call the function: <span class ...

Can an NPM package, originally developed with Angular 8 and converted to NPM, be utilized in JavaScript or React Native environments?

Looking to convert my Angular module (v8) into an NPM package in order to utilize it as a library within regular JavaScript, or even in a React or React Native application. Is this conversion feasible? ...

Issue with applying Jquery toggleClass to an element

I'm encountering an issue with applying a toggleClass that is not working to add the new class. Can someone help me understand what's happening? <a href="#" id="cf_onclick">Click</a> <div id="main" class="invisible"> Hi there ...

Persistent extra pixels found in CSS radiobutton group buttons that persist despite attempts to remove them

UPDATE: I have corrected the title of this post, as it was mistakenly taken from another post. For the past few months, I've been working on a sports app using React. However, I am facing a minor cosmetic problem with my radio buttons. Despite my eff ...

Using JavaScript to assign the id attribute to the header element based on its content

Is there a straightforward way in JavaScript to assign an ID to a header based on its content, replacing spaces with hyphens and converting it to lowercase? Take, for instance, this header: <h1>Header one content</h1> How can we transform it ...

Issues with Jquery's Slice, Substr, and Substring functionalities

I need to divide the content into two separate sections. Unfortunately, the first variable (summarySentence1and2) is not capturing the desired result, while the second variable (summarySentanceOthers) is storing all of the content from the source field. I ...

JavaScript, Page Method, and GridView are essential components to creating dynamic and interactive

After learning how to use the page method in JavaScript and ASP.Net (VB.Net), I encountered an issue when trying to insert multiple items into a database using a gridview. Despite my efforts, there were no error messages appearing. Here is what I have so f ...

What is the most efficient method for displaying a voxel animation in WebGL?

I am interested in creating an animated voxel scene using WebGL and Three.js for a personal project. The goal is to visually represent real-time point cloud data from a server-side stream. The scene will consist of approximately 2 million points, organize ...