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

  1. Import/create SOP geometry, and set shop_materialpath as partition attribute.
    Disable Prefix 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.
  2. If it is a few objects, you might want to create a separate Material Library with unique path to each geo's material set.
  3. Use Assign Material node with Vexpression.
    To iterate through the GeomSubset primitives set Primitives field to:
    %type:GeomSubset
    
    Use code:
    string mat = split(@primpath, '/')[-1]; // extract the subset name from the full primitive path
    mat = replace(mat, "_obj_michael_matnet1_", "/materials/michael/"); // replace the path with the LOPs material path
    return mat;