0
votes

I have a .obj, .mtl files with multiple materials for a specified material, I want to print the vertices and their corresponding uv coords. Is there a way to e.g. parse a .obj, and .mtl file and export them to json? When using

  • wavefront-obj-parser
  • PyWavefront
  • meshlab All these tools generate a json file I think that the data is partial - I don't see the materials in there.

EDIT:

I tested with an example 3d model

step1: converted the .obj and .mtl with multiple materials into a .json file

  • Added the addon to Blender (version 2.76b) as instructed in here
  • In Blender, imported the .obj, .mtl (the model shows up but not the material textures)
  • In Blender exported to Three.json (see here)

step2: loaded the generated .json file (foo1.json) within a threejs example

  • Used the example webgl_loader_json_objconverter.html from here
  • Replaced Female02_slim.js with foo1.json
  • The model Male02_dds.js is loaded but the foo1.json is not and I'm getting an error message: TypeError: vertices is undefined

Some links indicate that Blender Exporter and Json File Loader are not so reliable (see here, here, here, and here in general) Is there any other converter from .obj, .mtl to .json that anybody can recommend? (not necessarily in relation to three.js)

Assuming that I can convert to glTF format, is there a tool, (e.g. a command line utility in python) that will let me specify a material index and get the vertices and corresponding uv coords for this material?


Solved: I ended up using meshlab plugin export to json. It works (almost) fine for me

1

1 Answers

0
votes

Sure, you can use Blender and THREE JS plugin (exporter):

https://www.blender.org/

https://github.com/mrdoob/three.js/tree/dev/utils/exporters/blender

Exported file have materials as array if you use JSON Loader function

https://threejs.org/docs/#api/loaders/JSONLoader