Solaris Sink
· Houdini MOC · #note/sink ·
Assigning materials with VEX
Using partitions
This is the case when you have materials already assigned in SOPs. It solves 2 problems at once. First, getting rid of the unindexed shop_materialpath
attribute, it saves memory and is more robust. And secondly, it automatically reconstructs the new LOP material primitive path from the subset primitive names (which have the material paths in them).
- Import/create SOP geometry, and set
shop_materialpath
as partition attribute.
DisablePrefix Subsets with Attribute Name
for shorter names.
This will create GeomSubset primitives under each of your Mesh primitives, and their names will contain the path to each material (with slashes replaced with underscores). We'll use these names to get our materials re-assigned in LOPs. - If it is a few objects, you might want to create a separate
Material Library
with unique path to each geo's material set. - Use
Assign Material
node with Vexpression.
To iterate through the GeomSubset
primitives set Primitives field to:
%type:GeomSubset
Use vexpression:
string separator = chs("separator"); // the name of material network in SOPs
string submat = chs("submat"); // the name of LOPs material subprimitive
string mat = split(@primpath, '/')[-1]; // extract the subset name from the full primitive path
mat = re_replace(".*" + separator + "_", "/materials/" + submat + "/", mat); // replace the path with the LOPs material path
return mat;
- Add 2 string field to the node interface for
separator
andsubmat
values. Or hard-code them instead.