change material binding with vex

   3550   13   5
User Avatar
Member
23 posts
Joined: Sept. 2021
Offline
Is it possible to set the material binding via wrangle node? I found the usd_boundmaterialpath command, but there seems no way of setting it. I also checked usd_relationshipnames and usd_attribnames but I don't see any material in either.

Cheers
M
User Avatar
Member
1737 posts
Joined: May 2006
Offline
You can, but only with a vexpression within the assign material lop.

Notes:

https://www.tokeru.com/cgwiki/index.php?title=HoudiniLops#Assign_material_lop_vex_basics [www.tokeru.com]
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Staff
4164 posts
Joined: Sept. 2007
Offline
The usd_setrelationshiptargets() [www.sidefx.com] function can be used to override the material binding, which is just a relationship:

usd_setrelationshiptargets(0, @primpath, "material:binding", {"/materials/plastic"} );

This method does not add the MaterialBindingAPI schema, when used to create a new material binding. It renders with Karma at least, and should be safe for overriding an existing binding. But using the vexpression mode on Material Assign as @mestela suggested, is probably safer.

Hope that helps!
Edited by goldleaf - Dec. 14, 2021 18:02:06

Attachments:
screenshot_20211214_155142.png (471.8 KB)
set_relationshiptargets_materials.hip (421.1 KB)

I'm o.d.d.
User Avatar
Member
1737 posts
Joined: May 2006
Offline
Oooh good to know! Adding that to the wiki...
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
23 posts
Joined: Sept. 2021
Offline
Ah, thanks guys. When I tried it this morning also usd_relationshipnames() showed the material:binding - so I guess I did something wrong yesterday. Works now!
User Avatar
Member
94 posts
Joined: Nov. 2017
Offline
Guess the difference is that Matt's way doesn't work if the material library is still coming in the node tree, while setrelationshiptargets works also the library hasn't been introduced to the prims yet.
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
goldleaf
This method does not add the MaterialBindingAPI schema
goldleaf
But using the vexpression mode on Material Assign as @mestela suggested, is probably safer.

What are the risks/consequences of assigning the material and missing the MaterialBindingAPI schema like it happens when using usd_setrelationshiptargets() in a wrangle?

I am guessing there is no VEX way of adding schemas; only python or inline.

Thanks!
Edited by Cicuta - Jan. 9, 2024 06:57:58
User Avatar
Staff
4164 posts
Joined: Sept. 2007
Offline
H20 now has usd_applyapi()
https://www.sidefx.com/docs/houdini/vex/functions/usd_applyapi.html [www.sidefx.com]
Edited by goldleaf - Jan. 9, 2024 11:59:41
I'm o.d.d.
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
Hello again!

I have been going through the documentation and I am not being able to find a clear explanation for what the MaterialBindingAPI is doing, and why would a material:binding relationship alone work by itself, or the potential issues derived from not having the schema.

Is there a specific place in the documentation that goes through this that I might be missing?

Thanks!
User Avatar
Staff
4164 posts
Joined: Sept. 2007
Offline
MaterialBindingAPI is an ApiSchema. ApiSchemas can provide just an API (i.e. set of functions) to author certain data on a prim. Or they additionally might "decorate" a prim, and recorded as having been applied.

In previous versions of USD and Solaris, USD was less strict about having the ApiSchema recorded on the prim. But in the last year (or two?) that has changed, and USD/Hydra require the ApiSchema to be applied. LOPs is generally good about doing this, so that change in strictness didn't generally affect Houdini users. It's also true that, although strict in authoring, Houdini and Karma can still pretty forgiving. When someone used a Wrangle or Python LOP to author a relationship or attribute directly, rather than the API of the ApiSchema, that's where they'd get bit by this change.

https://openusd.org/release/glossary.html#api-schema [openusd.org] has more info about ApiSchema's generally. And you can get more info about MaterialBindingAPI here: https://openusd.org/dev/api/class_usd_shade_material_binding_a_p_i.html#details [openusd.org]

Hope that helps!
Edited by goldleaf - Jan. 10, 2024 08:53:15
I'm o.d.d.
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
Thanks so much for the answer!

Then I imagine a good practice that you would recommend is using the new usd_applyapi() whenever we create something by vex code in a wrangle to add the corresponding schema. For example, whenever we create a material:binding rel (MaterialBindingAPI), but also in other cases such as creating a collection:include rel (CollectionAPI) right?

It'd be great to have some info/warning popping whenever a schema is missing, or some documentation with the types of relationships that need a schema to be added by de user... it feels like it can lead to some errors pretty hard to debug, and makes working with wrangles lops a bit scary when they are often a very handy way of doing some more complex USD operations.
Edited by Cicuta - Jan. 10, 2024 10:52:37
User Avatar
Member
8554 posts
Joined: July 2007
Offline
Cicuta
Then I imagine a good practice that you would recommend is using the new usd_applyapi() whenever we create something by vex code in a wrangle to add the corresponding schema. For example, whenever we create a material:binding rel (MaterialBindingAPI), but also in other cases such as creating a collection:include rel (CollectionAPI) right?


to me it sounds like it should be the opposite and we should add the schema first and rather than doing some custom code to try to handle the binding or whatever we should use the API for that

which would meant that VEX should gain the ability to call functions from attached API as well, since I imagine that's the whole purpose of API that then we should call its Bind() function rather than set up relationship the naive way, or am I misunderstanding?
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
55 posts
Joined: Nov. 2019
Offline
tamte
to me it sounds like it should be the opposite and we should add the schema first and rather than doing some custom code to try to handle the binding or whatever we should use the API for that

which would meant that VEX should gain the ability to call functions from attached API as well, since I imagine that's the whole purpose of API that then we should call its Bind() function rather than set up relationship the naive way

Exactly. If that is the case I don't see the logic behind using functions such as usd_setrelationshiptargets() if its a "dangerous" non-standard way of doing things USD. Following this it seems like I have been using functions in VEX that do things the naive way (even though, they seemed to work just fine).
Edited by Cicuta - Jan. 10, 2024 13:51:07
User Avatar
Staff
4164 posts
Joined: Sept. 2007
Offline
It's not necessarily dangerous, it's just the generic function for relationship attributes is all we have; I think we just need a VEX function to create material bindings. While warnings/detection could be good (could be done with the Scene Doctor LOP), I think the "correct" way is just make functions that do the action and apply the schema. VEX already does this in some cases (i.e. collections); we just need one to make material assignments in a general VEX script.
I'm o.d.d.
  • Quick Links