1
votes

In a scene I have added several mesh objects (cubes). An EdgeHelper has been made for each cube. The cubes move and rotate and the Edgehelpers move and rotate with them.

I would like to change the color of an EdgeHelper when it's associated cube mesh is selected. (The selection method is not important).

So, given a particular cube mesh, how do I find the associated EdgeHelper object?

2

2 Answers

3
votes

When you create an edgesHelper for a given mesh, all you have to do is add a new property to the mesh:

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

var edgesHelper = new THREE.EdgesHelper( mesh );

mesh.edgesHelper = edgesHelper;

Now you can change the helper color like so:

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

three.js r.76

1
votes

When you create meshes and EdgeHelpers you can assign them the same .name attribute:

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

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

...and so on

**if you wrap this in a loop even better

so when a mesh is selected you can read its .nameattribute and pick the corresponding edgeHelper.