Announcement

Collapse
No announcement yet.

get shader from proxy node

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • get shader from proxy node

    Hi there,
    I am playing around with the new V-Ray 5 proxy node and I was wondering if it is possible to get a list of the shaders in the proxy and set the override shader via script.
    I was able to do that with the old proxy node but since things have changed (for the better ), my old dode does not work anymore.
    Florian von Behr
    CG Supervisor
    The Scope GmbH
    Behance

  • #2
    You can get a list of the proxy's contents like this:
    Code:
    cmds.vrayUpdateProxy(nodeName, getObjectNames=True)
    The result is an array of strings, the prefix indicates what type of object it is (mesh/hair/particles/shader):
    Code:
    ['m:/pSphere1/pSphereShape1', 'm:/pSphere2/pSphereShape2', 's:/pSphere1/pSphereShape1/VRayMtl1SG', 's:/pSphere1/pSphereShape1/VRayMtl2SG']
    There are two types of overrides:
    • The normal ones created by the TreeView hierarchical control, these are sorted during rendering so that /pSphere1/pSphereShape1 has a higher priority than /pSphere1/* for example ("leaf" rules override inherited rules).
    • Advanced (custom) overrides, these have a lower priority than the normal ones and are applied in the order they are defined. Those have "Custom" added to the attribute names.
    These are compound array attributes and can be set like this (increment the array index if you're adding multiple rules):
    Code:
    cmds.setAttr(nodeName+'.shaders[0].shadersNames', '*', type='string')
    cmds.connectAttr('lambert1.outColor', nodeName+'.shaders[0].shadersConnections')
    As you can see, shadersNames accepts wildcards, '*' applies to everything, '/pSphere1/*' will override a part of the hierarchy.
    You can use listAttr to find all the relevant attributes. Additionally, the Python code in C:\Program Files\Autodesk\Maya2020\vray\scripts\vray\aetempla tes\ may provide some hints.
    Deyan Spirov
    V-Ray for Maya developer

    Comment


    • #3
      That works! Nice.

      I can see the connections in the node editor and when rendering but the overrides don't show up in the AE. What command do I need to call to get the attribute editor to show those changes?
      Code:
      refreshAE;
      doesn't do it.
      Attached Files
      Florian von Behr
      CG Supervisor
      The Scope GmbH
      Behance

      Comment


      • #4
        Hey Deyan,
        I did some more digging. It seems your code does add material overrides to the mesh nodes and they also show up in the AE.So please ignore my last post.

        How can I override just the shaders in the proxy?
        Florian von Behr
        CG Supervisor
        The Scope GmbH
        Behance

        Comment


        • #5
          Hi,
          I'm not sure I understand your question, these attributes can only override the shaders in the proxy. You can override just a specific shader shader by putting its name in the rule attribute, or all of them using "*".
          One more thing to note is that you can only attach shader overrides to things that have the shader icon on the right in the Object Hierarchy, since they are matched to the shaderSet name, not to the geometry name.
          Deyan Spirov
          V-Ray for Maya developer

          Comment


          • #6
            I'll check it out.
            Last edited by TheScope; 25-04-2021, 11:10 PM.
            Florian von Behr
            CG Supervisor
            The Scope GmbH
            Behance

            Comment


            • #7
              Works! The trick is to use the shader name without the s:
              Here is the code snippet for further reference:

              Code:
              proxy_node = "my_vray_proxy"
              proxy_content = cmds.vrayUpdateProxy(proxy_node, getObjectNames=True)
              
              for i, node in enumerate(proxy_content):
                  if node.startswith("s:"):
                  shader_name = node[2:]
                  cmds.setAttr(proxy_node + '.shaders[{}].shadersNames'.format(i), shader_name, type="string")
                  cmds.connectAttr(shader_name + ".outColor", proxy_node + '.shaders[{}].shadersConnections'.format(i))
              Florian von Behr
              CG Supervisor
              The Scope GmbH
              Behance

              Comment

              Working...
              X