Jump to content

Export materials in obj fiiles

Recommended Posts


I would like to know if there is a solution for the export  of obj with materials identical to other dccs.

I want to use Houdini as part of a workflow in Archviz and it's required that I'll export directly from Houdni to Obj.

Atom already posted a solution, but it implies that materials would be applied to disconnected face groups .


I've alread  sent a request to SF, but is there any other solution?




Share this post

Link to post
Share on other sites

From the link above i've introduced a feature, which introduces constant material names via group names.

It's a simple hack to the wavefront exporter, but it works once you prepare groups to be able to transfer material names. I'll leave it here, if someone find it useful or wants to improve it.




## Add a default material for each group and specific material names for specific groups
# Run after .OBJ export.

import os

PRE_FIX = "hobj"                                        # Pick your own prefix token here.
node = hou.pwd()                                        # Get the node this code is running under.
file_name_in = node.evalParm('sopoutput')               # Fetch the name from the ROP Output panel.
the_path = os.path.dirname(file_name_in)                # Get the path.
the_name = os.path.basename(file_name_in)               # Get the name.
name_only = os.path.splitext(the_name)[0]               # Remove the file extension.
s = "%s_%s.obj" % (PRE_FIX,name_only)                   # Construct a new name that uses the PREFIX.
file_name_out = os.path.join(the_path, s)

with open(file_name_in, 'r') as f:
    lines = f.read().splitlines()   # Remove slash n character at the end of each line.

new_lines = []
for line in lines:
    ary = line.split(' ')   
    if ary[0] == 'g':
        if mat_count > 0:               # Detected a group.
            gr_nm=ary[1]                # check group name
            if gr_nm[0:4] == 'hmt_':    # Pick another material prefix token here.
                mat_name = gr_nm
                new_lines.append("usemtl %s" % mat_name)
                mat_name = "mat_%d" % mat_count
                new_lines.append("usemtl %s" % mat_name)
        mat_count +=1
f = open(file_name_out, 'w')
for line in new_lines:
  f.write("%s\n" % line)


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now