Jump to content

Object merge question


Recommended Posts

I am experiencing a behaviour when using object merge that is driving me mad… ok, here it goes… hopefully will be clear

 

I have a car, 1 body and 4 wheels. All 5 elements are separate objects and I apply the materials at OBJ level too by drag&drop.

 

But then I want to "collect" those objects so I can manipulate them as one when I object merge the OBJ the material is lost… it only works if I put a material node at SOP level which is not what I want. I am viewport century and the whole point of drag&drop at OBJ level seems to be lost.

 

My question is… am I missing something or is this by design not possible? I already have a few workarounds but I just would like to know if this is possible.

 

thanks in advance.

Link to comment
Share on other sites

to be more precise, no materials assigned at OBJ level travel through the Object Merge, and actually it makes sense. (I´m pretty sure you already know the following, but just in case) When you apply a material at OBJ level, you´re not actually applying any attributes to the geometry until it reaches the shader, which is where it´s reading that OBJ material info. Hence, there´s´no shop_material_path attribute applied yet and it reads whatever new material you apply at OBJ level. As you mentioned, if you apply the SOP Material and then merge that somewhere else, it does read it, because the shop_material_path is there already. I think it is designed this way, because that allows you to object merge some geometry, but choose a new material from OBJ level. But yes, from a drag&drop workflow POV, it´s not ideal. Just to put it from a different perspective. What if you wanted to keep on using drag&drop, but wanted a copy of your objects with different materials? Then, any other method would force you to use the SOP material again.

Edited by Netvudu
Link to comment
Share on other sites

Thanks Javier, I was not aware of the details (thanks for developing) but this is from the user experience point of view a bug… anyway, I guess a possible solution would be to always add a sop material reading the object material? I will try this on monday and see how it behaves as for me the drag and drop functionality is critical to scale teams up.

 

 

:-)

 

 

to be more precise, no materials assigned at OBJ level travel through the Object Merge, and actually it makes sense. (I´m pretty sure you already know the following, but just in case) When you apply a material at OBJ level, you´re not actually applying any attributes to the geometry until it reaches the shader, which is where it´s reading that OBJ material info. Hence, there´s´no shop_material_path attribute applied yet and it reads whatever new material you apply at OBJ level. As you mentioned, if you apply the SOP Material and then merge that somewhere else, it does read it, because the shop_material_path is there already. I think it is designed this way, because that allows you to object merge some geometry, but choose a new material from OBJ level. But yes, from a drag&drop workflow POV, it´s not ideal. Just to put it from a different perspective. What if you wanted to keep on using drag&drop, but wanted a copy of your objects with different materials? Then, any other method would force you to use the SOP material again.

Link to comment
Share on other sites

Sure. Python to the rescue!

 

You could reference the object material from a Material SOP added to the Object Merge

 

 

EDIT: I found a spare hour this weekend (of course it must be the weekend, otherwise there´s virtually no spare time) and created what you need.

The attached shelf tool allows you to select from the viewer whichever object/s you need, and automagically brings them to a new node currently called "nuevo" (*ahem*you should change that :huh: ). It names each Object merge with the proper object´s name, and adds a material SOP (also with proper name) that references to the OBJ level material parameter, so if you change the original the new one follows.

I had to choose the Object_merge transform mode for you, but it should be trivial changing that to what you need for a specific occasion.

 

Finally, I didn´t crash-test it a lot. I just made sure that it works for objects at different levels and also it complains if you don´t select anything. Some more error-testing checks should be made prior to considering it production-ready. For instance, you could add checks to see if you decided to go the Material SOP route instead of using the OBJ-level material parameter for the original objects.

 

The silly code is commented just in case you want to change anything.

 

Hope it helps "realising" (huh-huh :P ) your pipeline.

 

ObjectMergePlus.zip

Edited by Netvudu
Link to comment
Share on other sites

  • 1 year later...

Hey Netvudu,

Thank you so much for the script, works great.  After running it and pushing it through a sim,  I used an unpack to bring the textures back in the viewport but having same issue when rendered the geo is white. 

 

edit ( just had to dump the textures in the correct directory with the FBX.)

Thanks again, that script rocks!

Edited by cowboy71
Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

in h17 you must comment the destroy function because the file node doesn't exist anymore

import toolutils

scene_viewer = toolutils.sceneViewer()

# Ask for the objects to combine
selected_objects = list(scene_viewer.selectObjects(
    prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory()),
    allow_multisel = True,
    allowed_types = ("geo",)))
# The following will raise an exception if nothing was selected.
if len(selected_objects) == 0:
    raise hou.Error("Nothing was selected.")



#print selected_objects

# Create a new geo node, delete the file SOP and create a Merge SOP
t= hou.node('/obj').createNode("geo","md_merge_1")
# arch1= hou.node(t.path()+'/file1')
# arch1.destroy()
m1= t.createNode("merge")

#Loop through every selected object and create an object merge and a
# material SOP, both with the proper name and the original material.
# Also set the object merge transform parameters and connect the material
# SOP to the Merge.
for s in selected_objects:

    om1=t.createNode("object_merge")
    nombre1= s.name()
    omname= "object_merge_"+nombre1
    om1.setName(omname)
    om1.parm("objpath1").set(s.path())
    om1.parm("xformtype").set(1)
    mat1=t.createNode("material")
    mat1.setName("material_"+nombre1)
    mat1.setFirstInput(om1)
    pmat1=mat1.parm("shop_materialpath1")
    mat_s= hou.parm(s.path()+"/shop_materialpath")
    pmat1.set(mat_s)
    m1.setNextInput(mat1)

#Set all flags to the final Merge and properly place the nodes.
#Also, go back to /obj level

m1.setDisplayFlag(True)
m1.setRenderFlag(True)
for a in t.children():
    a.moveToGoodPosition()
t.moveToGoodPosition()

t.setCurrent(True,True)
toolutils.homeToSelectionNetworkEditorsFor(t)

 

Edited by NNois
  • Like 1
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...