Getting EdgesHelper to align properly with Mesh in Three.js

Within a dynamic scene, multiple mesh objects (specifically cubes) have been included. A unique EdgeHelper has been generated for each cube to track its movements and rotations.

Whenever a particular cube mesh is selected, I am aiming to alter the color of its corresponding EdgeHelper object. The method used for selection is not crucial in this case.

Thus, my main query revolves around identifying the specific EdgeHelper object linked to a given cube mesh.

Answer №1

When adding an edgesHelper to a specific mesh, you simply need to create the helper object and assign it as a new property of the mesh:

var mesh = new THREE.Mesh( ... );

var edgesHelper = new THREE.EdgesHelper( mesh );

mesh.edgesHelper = edgesHelper;

To update the color of the helper, use the following code:

mesh.edgesHelper.material.color.set( 0xff0000 );

This functionality is available in three.js version r.76

Answer №2

Assigning the same .name attribute to meshes and EdgeHelpers is a common practice:

mesh0.name = 0;
edgeHelper0.name = 0;

mesh1.name = 1;
edgeHelper1.name = 1;

...and so forth

**if you put this in a loop, it's even more efficient

This allows for easy retrieval of the corresponding edgeHelper when a mesh is selected based on its .name attribute.

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

Strategies for transferring information to a different component in a React application

Building a movie site where users can search for films, click on a card, and access more details about the film is proving challenging. The problem lies in transferring the film details to the dedicated details page once the user clicks on the card. An onc ...

In Javascript, a function is executed only once within another function that is set on an interval

Using the Selenium Chrome driver in my JavaScript, I am constantly checking a value on a website every 2 seconds. However, I need to only save status changes to a text file, not every single check. The current code is functional but it saves the text fil ...

Executing a function within the constructor in Angular 2/IONIC 2

I am new to Angular 2 and I have a question regarding invoking a child method from the current constructor. Is it possible to call the getPosition method from the constructor? I attempted to do so, but encountered an exception stating "getPosition is not ...

The measurement of a HTML window's entire content height (not just the visible viewport height)

Currently, I am attempting to determine the total height of a webpage's content, not just what is visible. In my efforts, I have managed to achieve some success in FireFox using: document.getElementsByTagName('html')[0].offsetHeight. Howeve ...

AngularJS ng-model not refreshing

One of the features in my application is a Font Awesome icon picker that allows employees to easily access different icons without having to search for their codes online. However, I am facing an issue where clicking on an icon does not update the ng-mode ...

The dynamic duo of JavaScript and HTML forms are like peanut

My HTML form has some validation functions, but I'm running into an issue where some functions can access the form while others cannot! Here is the form code: <form id="contactForm" action="javascript:submitForm()" method="post"> <table ...

Issue with 1.bundle.js not loading during webpack production build with routing

I have been encountering an issue with my test repository for this specific problem (Link) It appears that the problem lies within the localization file, as I am using react-intl. The development version seems to be functioning properly. This is what&ap ...

How can I change the displayed value of a 'select' element programmatically in Internet Explorer?

My interactive graphic has a drop-down menu implemented with a <select> element. Everything functions correctly, except when using Internet Explorer. The issue arises when attempting to programmatically change the selected value of the <select> ...

Challenge with AngularJS data communication to Node Express server

Even though I should be using Angular 9, for this school assignment, I'm stuck with AngularJS. Within my html navbar, there is a search bar structured as follows: <ul id="nav-mobile" class="right hide-on-med-and-down"> <li><input ...

Transforming a React application from ES6 hooks to Class-based components

Hello, I am new to React and currently facing a challenge in converting the following code into a Class Based Component. Despite knowing that I am going in the opposite direction, I am unable to figure out how to proceed without encountering errors. Any ...

What is the best way to save data from a jQuery plugin to a database using ASP .NET MVC?

I have a jQuery plugin called "Slider" that displays the current price of an item. I would like to enhance it by allowing users to change prices using the jQuery slider and update them in the database. Here is the model: public class Item { public in ...

Adjusting the rotation axis within the heart of the Three-react-fiber model

My model is rotating on the X axis, but the center of rotation is not aligned with the axis. The code for rotation is quite straightforward: model.current.rotation.x += 0.016; (axis and speed) However, I am struggling to define the actual axis of rotation ...

Sometimes, a record goes missing from a PHP/JSON array

When calling a PHP script to retrieve results and converting the array into a JavaScript array for a multiple choice quiz, I encountered an issue where certain records were missing unexpectedly. It seems to occur randomly as there is no specific pattern to ...

The Chrome Extension was denied from loading due to a violation of the specified Content Security Policy

I am encountering an issue while loading a Chrome Extension using React. Whenever I try to load it, the error message below pops up: Refused to load the script 'https://code.jquery.com/jquery-3.2.1.slim.min.js' because it violates the following ...

Is there a way to retrieve real-time information using momentjs in a Vue.js application without needing to refresh the

I have a unique table where I showcase details about a particular website. Among the displayed information is the timestamp indicating when the data was last updated. At the top of the table, my aim is to include an icon that will only appear if the dura ...

Update of component triggered only upon double click

I'm encountering an issue with my parent component passing products and their filters down to a subcomponent as state. Whenever I add a filter, I have to double click it for the parent component to rerender with the filtered products. I know this is d ...

Passing a JSON object as a parameter in a dynamically created element's click event using JavaScript/AngularJS

How to pass a JSON object as a parameter in the click event of a dynamically created element using JavaScript and AngularJS? var _dataObj = "{"sor_SourcingAgentId":1,"sor_Name":"xx"}" var _dynHtml= '<input type="button" ng-click="fnSelectcustom ...

What is the process for interacting with pseudo HTML elements with Selenium WebDriver?

Is there a way to interact with pseudo HTML elements using Selenium WebDriver? For instance, elements like input::after and input::before that don't appear directly in the DOM but are visible on the page. ...

Create reactivity in output by utilizing global functions in Vue

I've recently dived into Vue, along with vue-cli and Single File Components. I'm facing a challenge where I need to have a global function that provides formatted text to components throughout my application. This text should be based on the curr ...

PUPPETER - Unpredictable pause in loop not functioning as expected

Having an issue with this specific part of the code: (async () => { const browser = await puppeteer.launch({ headless: false, // slowMo: 250 // slow down by 250ms }); const page = await browser.newPage(); //some code // CODE ABOVE WORKS, ...