houdini .obj and .mtl files

   33904   22   2
User Avatar
Member
8 posts
Joined: 7月 2013
Offline
Hi,
I created a little obj and mtl importer for Houdini, Objilla. It creates materials, assigns colors, textures, transparency, supports multi-material obj import and multiple obj import. Hope you will find it useful.
https://www.sidefx.com/forum/topic/70201/ [www.sidefx.com]
User Avatar
Member
16 posts
Joined: 7月 2020
Online
This is an old thread but hopefully this info is useful to someone.

I didn't even realize the Labs OBJ Importer had `.mtl` support because it so consistently failed to work. I was even starting to script my own solution before I decided it might be worth searching the web, and then I ended up here.

In regards to why you would need such a thing - Obj files are incredibly common and they very often have a bunch of different textures applied to different prims. Personally I have mainly been playing with models ripped from old games, but I'm sure there issue could arise with newer models, too. For example, see the OBJ here https://www.models-resource.com/nintendo_64/elmosnumberjourney/model/22344/ [www.models-resource.com] which fails to apply the textures upon import.

It took a bit of digging around but I eventually realized the issue was a mismatch between the actual `shop_materialpath` attribute name and the one referred to by the auto-generated Labs Quick Material node. If you open the Labs Obj Importer's "Type Properties" and then "scripts" tab, you can see this assignment happening on line 17. Specifically, in this case all the actual `shop_materialpath` attributes were prefixed with `/mat/`, e.g. `/mat/material_71` but the Labs Quick Material referred only to `material_71`.

The fix is actually quite simple here, just need to modify the `re.replace` in the `clean_materialpaths` node to get rid of the `/mat/`. Attached is my modified Labs Obj Importer node which fixes this:

BEFORE:

nodename = re.sub(r"+", "_", nodename)

AFTER:

nodename = re.sub(r"+", "_", nodename)
nodename = re.sub(r"^/mat/", "", nodename)
Edited by maxpleaner - 2022年11月25日 01:52:48

Attachments:
sop_maxpl.dev.obj_importer_fix.2.0.hdalc (24.7 KB)

User Avatar
Member
1 posts
Joined: 6月 2015
Offline
maxpleaner
This is an old thread but hopefully this info is useful to someone.

I didn't even realize the Labs OBJ Importer had `.mtl` support because it so consistently failed to work. I was even starting to script my own solution before I decided it might be worth searching the web, and then I ended up here.

In regards to why you would need such a thing - Obj files are incredibly common and they very often have a bunch of different textures applied to different prims. Personally I have mainly been playing with models ripped from old games, but I'm sure there issue could arise with newer models, too. For example, see the OBJ here https://www.models-resource.com/nintendo_64/elmosnumberjourney/model/22344/ [www.models-resource.com] which fails to apply the textures upon import.

It took a bit of digging around but I eventually realized the issue was a mismatch between the actual `shop_materialpath` attribute name and the one referred to by the auto-generated Labs Quick Material node. If you open the Labs Obj Importer's "Type Properties" and then "scripts" tab, you can see this assignment happening on line 17. Specifically, in this case all the actual `shop_materialpath` attributes were prefixed with `/mat/`, e.g. `/mat/material_71` but the Labs Quick Material referred only to `material_71`.

The fix is actually quite simple here, just need to modify the `re.replace` in the `clean_materialpaths` node to get rid of the `/mat/`. Attached is my modified Labs Obj Importer node which fixes this:

BEFORE:

nodename = re.sub(r"+", "_", nodename)

AFTER:

nodename = re.sub(r"+", "_", nodename)
nodename = re.sub(r"^/mat/", "", nodename)


I downloaded your HDA, because I don't understand Python. I found that your Quick Material node was locked with your paths to textures, with your materials count, and had to change the paths myself. This could have confused beginners as it confused me.
So I created a blank OBJ Importer node and made changes following your guide. Now it's working out of the box.
I attached the new HDA down below.

Thank you for your guidance and instruction!

Attachments:
labs.obj_importer_FIX.2.1.hdalc (43.7 KB)

  • Quick Links