简体   繁体   English

Three.js:如何将EdgesHelper匹配到网格

[英]Three.js: How to match EdgesHelper to Mesh

In a scene I have added several mesh objects (cubes). 在一个场景中,我添加了几个网格物体(立方体)。 An EdgeHelper has been made for each cube. 已为每个多维数据集制作了一个EdgeHelper。 The cubes move and rotate and the Edgehelpers move and rotate with them. 多维数据集移动和旋转,Edgehelpers随之移动和旋转。

I would like to change the color of an EdgeHelper when it's associated cube mesh is selected. 选择关联的立方体网格时,我想更改EdgeHelper的颜色。 (The selection method is not important). (选择方法并不重要)。

So, given a particular cube mesh, how do I find the associated EdgeHelper object? 因此,给定特定的立方体网格,如何找到关联的EdgeHelper对象?

When you create an edgesHelper for a given mesh , all you have to do is add a new property to the mesh: 当为给定的mesh edgesHelper创建一个edgesHelper ,您要做的就是向mesh edgesHelper添加一个新属性:

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 three.js r.76

When you create meshes and EdgeHelpers you can assign them the same .name attribute: 创建网格和EdgeHelpers时,可以为其分配相同的.name属性:

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 .name attribute and pick the corresponding edgeHelper. 因此,选择网格时,您可以读取其.name属性并选择相应的edgeHelper。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM