how to export mtl alongside with obj

   2512   7   1
User Avatar
Member
171 posts
Joined: Oct. 2016
Offline
hey
seems can't find this option, need some advice... except installing blender for this
User Avatar
Member
2658 posts
Joined: June 2008
Offline
I'm not sure what you're expecting out of the venerable .obj format? It's forty years old.

However, here is a link to a post-frame script that will write a usemtl token for every g token into the OBJ format. This can allow some importers to pick up on the fact that certain face/primitives should have separate materials.

This means you'll need to convert any materials (i.e. unique s@shop_materialpath values) into groups before you export.

https://forums.odforce.net/topic/25214-post-processing-an-export/?do=findComment&comment=146948 [forums.odforce.net]
Edited by Enivob - Nov. 14, 2022 10:19:23
Using Houdini Indie 20.5
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
User Avatar
Member
171 posts
Joined: Oct. 2016
Offline
thanks a lot enivob need it for assigning materials to model in three.js with their mtlloader, will try it out today
User Avatar
Member
8177 posts
Joined: Sept. 2011
Offline
RyuKu
thanks a lot enivob need it for assigning materials to model in three.js with their mtlloader, will try it out today

doesn't three.js support gltf? I would think that would be preferable to obj
User Avatar
Member
171 posts
Joined: Oct. 2016
Offline
thanks jsmack for advice was reading about - and yes propbably gltf would be preferrable one, with some great help even managed to upload it to site (as well as obj though too)!
great that you don't need separate file and loader for mtl, just only one for gltf (glb actually) ^^
thanks a lot
by idea the final result cube will be near logo and logo is made with glassmorphism css effect
Edited by ryuku - Nov. 16, 2022 08:23:51

Attachments:
logo_cube_1.gif (1.3 MB)

User Avatar
Member
9 posts
Joined: Dec. 2023
Offline
Greetings. I am also trying to export .obj files from Houdini. I work with a software called Virtual Crash that works with 3d model imports, and it seems materials and textures apply to the models the best after import when using .obj.

Has anyone found a solution to this at this time? The python scripted suggested does not seem to export the .mtl file still. I tested every iteration of the script in the Post-Write Script section of the ROP Geometry Output SOP.
User Avatar
Member
2658 posts
Joined: June 2008
Offline
Try this file. The old code was written for Python 2.7. I've updated the script to work with Python 3. I'm attaching a working use case HIP file. Be warned, however, that the .MTL file doesn't offer much. You might be able to transfer color, but it certainly is not a full-fledged material transport system.
Edited by Enivob - July 20, 2025 09:36:45

Attachments:
ap_post_frame_python_OBJ_MTL_072025.hipnc (233.2 KB)

Using Houdini Indie 20.5
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
User Avatar
Member
9 posts
Joined: Dec. 2023
Offline
Thank you for the file @Enivob! It seems your script by default exports 2 objs as well as a mtl file. Is that supposed to happen? I just need 1.

Also, it seems to break when applying uvs and a material for each primitive group. It only outputs 1 obj. I put the file I was working on before. Is it possible to edit the python script to accommodate for this?

Houdini Console Message:
reading OBJ .
reformatting OBJ structure.
Detected 2 groups.
Post-Render
Edited by anon_user_29325004 - July 21, 2025 21:27:27

Attachments:
testFile_1.hipnc (443.2 KB)
Images.jpg (108.1 KB)
Ivory-Mortar-1.jpg (2.3 MB)

  • Quick Links