简体   繁体   English

如何在three.js / WebGL中更改STL对象的不透明度?

[英]How do I change the opacity of an STL object in three.js/WebGL?

I'm self teaching myself WebGL for a project I want to work on but I'm pretty new to all the nifty features of Three.js. 我正在为要从事的项目自学WebGL,但对于Three.js的所有精妙功能我还是很陌生。

I have an STL object that I'm using an STL loader for to import into the 3-D Viewer. 我有一个STL对象,正在使用STL加载器导入到3-D Viewer中。 Now, I want to be able to change the opacity of that object and also, perhaps remove certain features of that object to see the interior of the STL image. 现在,我希望能够更改该对象的不透明度,并且还可以删除该对象的某些功能以查看STL图像的内部。 How do change the opacity of the object, perhaps create a button to change the opacity. 如何更改对象的不透明度,也许创建一个按钮来更改不透明度。 How do I do so? 我该怎么做?

Also, if possible (since the model loaded is composed of several parts) remove certain structures? 另外,如果可能的话(由于加载的模型由几个部分组成),是否要删除某些结构? Perhaps with a toolbar on the side, that says part 1, part 2, part 3 and for each part, you just see that part. 也许旁边有一个工具栏,上面有第1部分,第2部分,第3部分,对于每个部分,您只看到该部分。

Thank you so much!! 非常感谢!! :D :d

At some point in your code you must have loaded the STL file using the STLLoader. 在代码中的某些时候,您必须已经使用STLLoader加载了STL文件。 And since STL files do not have materials you would have added a material definition like so: 并且由于STL文件没有材料,因此您应该添加材料定义,如下所示:

var material = new THREE.MeshPhongMaterial ({ color: 0xFF0000 });
var mesh = new THREE.Mesh (object, material);

where object is assigned from the event.target in the addEventListener function, since that is the way to load STL files. 从addEventListener函数中的event.target分配对象的位置,因为这是加载STL文件的方式。 You can change the material definition to: 您可以将材料定义更改为:

var material = new THREE.MeshPhongMaterial ({ color: 0xFF0000, opacity: 0.5, transparent: true });
var mesh = new THREE.Mesh (object, material);

to get a red transparent material. 获得红色透明材料。 You dont have to use Phong, you can also use LambertMaterial. 您不必使用Phong,也可以使用LambertMaterial。

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

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