Jump to content

How to import obj with python?


Bakiki

Recommended Posts

I'm trying to script a multiple obj importer, could someone tell me how to do a basic obj importer equivalent to the "File" SOP...

Here's what I have so far....

 

node = hou.pwd()
geo = node.geometry()

import os

import numpy as np

folder = r"PATH TO FOLDER WITH OBJ's "


models =  [f for f in os.listdir(folder) if f.endswith('.obj')]

 

rand = np.random.randint(0,len(models))

path =os.path.join(folder, models[rand])

 

print os.path.join(folder, models[rand])

obj = hou.node(path)

 

obj.createNode("geo")

 

 

 

 

 

 

 

Link to comment
Share on other sites

I made a python script similar to what you are trying to do.

Feel free to check out the code here. It might have some tips on how to make nodes and populate their parameters. It basically uses the existing File node, created by default when a geometry type object is created, to read natively supported mesh/object types.

 

If you are looking to create and manage a non-native 3D object type. Take a look at my moon scanner script. It reads NASA data and constructs a geometry mesh from that data.

Edited by Atom
Link to comment
Share on other sites

the simplest approach is to use a packed disk primitive.  create a pakedPrim for each file you wish to read, then stuff in the path using a primintrinsic.

 

http://www.sidefx.com/docs/houdini/hom/hou/PackedPrim.html

 

you can unpack later to turn into geo, or if you don't need to process anything, just leave them as-is for better performance for rendering and display.

if you need a format unsupported by houdini, then you've got a different problem on your hands.

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...