Jump to content

Export materials in obj fiiles


mnlrbr

Recommended Posts

Hi,

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?

Thx

 

 

Link to comment
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.

Best

Manuel

 

## 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.
f.close()

mat_count=0
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.
                new_lines.append(line)
                mat_name = gr_nm
                new_lines.append("usemtl %s" % mat_name)
            else:        
                new_lines.append(line)
                mat_name = "mat_%d" % mat_count
                new_lines.append("usemtl %s" % mat_name)
        mat_count +=1
    else:
        new_lines.append(line)
        
f = open(file_name_out, 'w')
for line in new_lines:
  f.write("%s\n" % line)
f.close()

os.remove(file_name_in)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...