简体   繁体   English

使用three.js在单个obj文件上使用多种材质

[英]Multiple material on single obj file with three.js

I'm using three.js to load an obj file, a ring with some pearls. 我正在使用three.js加载obj文件,其中包含一些珍珠。 I haven't got an mtl file, as the software we use to export the obj (rhinoceros(?)) won't generate it with an obj file (this is what I was told by the graphic designer). 我还没有mtl文件,因为我们用于导出obj的软件(rhinoceros(?))不会与obj文件一起生成(这是图形设计师告诉我的)。

I need to set a metallic material ONLY for the ring, and glass material ONLY for the stone/pearls. 我只需要为戒指设置金属材料,而只为石头/珍珠设置玻璃材料。

This is a link to the test page where I actually load the file: jaaxlab.com/test_youring 这是指向我实际加载文件的测试页面的链接: jaaxlab.com/test_youring

...for the rest I don't know how to set a single material and also multiple. ...对于其余的我不知道如何设置一种材料以及多种材料。

Link to obj file jaaxlab.com/test_youring/obj/prova1.obj 链接到obj文件jaaxlab.com/test_youring/obj/prova1.obj

Your object has several children. 您的对象有几个孩子。 The child with index 0 is the ring. 索引为0的孩子是环。 Also, its name is sezione_B_misura13_Riviera_mix_full anello_sezione_B_misura13 . 另外,其名称为sezione_B_misura13_Riviera_mix_full anello_sezione_B_misura13

So, you can access it like: 因此,您可以像这样访问它:

obj.children[0].material = new THREE.MeshStandardMaterial(...);

or 要么

obj.getObjectByName('sezione_B_misura13_Riviera_mix_full anello_sezione_B_misura13').material = new THREE.MeshStandardMaterial(...);

Given that obj is the object, loaded with you loader. 假设obj是对象,则使用加载程序加载。

Take a look at this jsfiddle . 看看这个jsfiddle Load your file, then check the console log. 加载文件,然后检查控制台日志。 You can also click any part of the object and see its id and name in the console. 您还可以单击对象的任何部分,然后在控制台中查看其ID和名称。

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

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