0

I'm using three.js to load an obj file, a ring with some pearls. 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).

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

...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

gman
  • 100,619
  • 31
  • 269
  • 393
gattass69
  • 101
  • 1
  • 12
  • There is no code to post, i have to understand if is possible to do one thing or not... and how, i can show how i'm loading the obj file but i don't think it is needed – gattass69 Nov 13 '17 at 12:40
  • Could you share a link for downloading of you obj file? – prisoner849 Nov 13 '17 at 12:42
  • this is it http://jaaxlab.com/test_youring/obj/prova1.obj @prisoner849 – gattass69 Nov 13 '17 at 12:44
  • I edited the question with some minor grammatical changes, added the link from the comments, and removed the intro/closing paragraphs, to keep the question succinct. Good luck! – Dan Eastwell Nov 13 '17 at 16:19
  • I see the following error: `(index):139 Uncaught ReferenceError: rObj is not defined at OBJLoader2Example.initGL ((index):139) at (index):274` in the console. Maybe that's a starting point for helping to debug :) – Dan Eastwell Nov 13 '17 at 16:20

1 Answers1

0

Your object has several children. The child with index 0 is the ring. Also, its name is 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.

Take a look at this 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.

prisoner849
  • 16,894
  • 4
  • 34
  • 68
  • Okay thanks, it seems to work, but i don't know how to add material in my code, every example i found online to work with obj file use different code and i don't know where to start, can you give me a hint? – gattass69 Nov 13 '17 at 13:45
  • @gattass69 I changed the answer. Don't forget that you have to have light sources in your scene, if you use a material different from `THREE.MeshBasicMaterialI()`. – prisoner849 Nov 13 '17 at 13:51
  • what do you mean with "light sources"? A light in the scene? Anyway thanks, i'll try right now – gattass69 Nov 13 '17 at 14:03
  • @gattass69 Well, yes, "lights" :) – prisoner849 Nov 13 '17 at 14:05