Gadget: output the difference of parameters between nodes in Houdini

Keywords: houdini

demand

The parameters of a node affect the behavior of the node. Therefore, for node users, comparing the differences of parameters between nodes can understand the differences of their behavior.

However, there are too many parameters in some nodes, so it will be troublesome to compare the differences between their parameters. Without tools, you can only jump back and forth between nodes to compare the differences of parameters.

I think it can actually be used Python module of Houdini It's not troublesome to write code to automatically compare and output differences. Finally, if you can output a more readable format (such as csv table or Markdown table syntax), it will make the comparison more efficient.

In addition, I also assume that the types of the nodes being compared are the same, so this makes the code simpler -- just access the parameters in order, because the order of the parameters must be the same.

Compare the difference of two node parameters

The code that compares only two nodes is very simple.
For example, I put two box nodes and adjusted the scaling parameters differently.

#Two contrasting nodes:
node1 = hou.node("../box1");
node2 = hou.node("../box2");

#Number of parameters of node
parmCount = len(node1.parms());

#Traverse all parameters to find different values
for i in range(parmCount) :
    if(node1.parms()[i].eval() != node2.parms()[i].eval()):
        message = "";
        message += node1.parms()[i].description()
        message += " " + str(node1.parms()[i].eval()) + " " + str(node2.parms()[i].eval())
        print(message)

Output:

Uniform Scale 1.0 3.11

Multi node comparison

When considering multiple nodes, take the 0 as the reference, and compare other nodes with it. As long as one node is different, the values of all nodes of this parameter will be output.
For example, I put three box nodes. The second and third have one parameter respectively, which is different from the first.

#Nodes to compare: (take the 0 as the reference)
nodes = [];
nodes.append(hou.node("../box1"));
nodes.append(hou.node("../box2"));
nodes.append(hou.node("../box3"));

#Number of parameters of node
parmCount = len(nodes[0].parms());

#Traverse all parameters to find different values
for i in range(parmCount) :
    allsame = True; #Are the parameters the same
    message = "";   #Information is displayed only when there are different parameters
    message += nodes[0].parms()[i].description()        #Parameter name
    message += " " + str(nodes[0].parms()[i].eval())    #Parameter value of reference node
    for j in range(len(nodes)-1):
        #If the parameters are different, write the value
        if(nodes[j+1].parms()[i].eval() != nodes[0].parms()[i].eval()): 
            allsame = False;
            message += " " + str(nodes[j+1].parms()[i].eval())
        #Same parameter: omit value
        else:
            message += " -"
    if not allsame :    #Output information only when there are different parameters
        print(message)

Output:

Size 1.0 - 1.9
Uniform Scale 1.0 3.11 -

Output MarkDown table syntax

MarkDown table syntax It can also be used in CSDN blog.

such as

| Syntax | Description |
| - | - |
| Header | Title |
| Paragraph | Text |

In the blog, it will become:

SyntaxDescription
HeaderTitle
ParagraphText

Therefore, the code is modified to:

#Nodes to compare: (take the 0 as the reference)
nodes = [];
nodes.append(hou.node("../box1"));
nodes.append(hou.node("../box2"));
nodes.append(hou.node("../box3"));

#The first two rows of the MarkDown table:
line1 = "| - | "
line2 = "| - | "
for n in range(len(nodes)):
    line1 += nodes[n].name() +" |"
    line2 += "- |"
print(line1)
print(line2)

#Number of parameters of node
parmCount = len(nodes[0].parms());

#Traverse all parameters to find different values
for i in range(parmCount) :
    allsame = True; #Are the parameters the same
    message = "| ";   #Information is displayed only when there are different parameters
    message += nodes[0].parms()[i].description()                #Parameter name
    message += " | " + str(nodes[0].parms()[i].eval()) + " |"   #Parameter value of reference node
    for j in range(len(nodes)-1):
        #If the parameters are different, write the value
        if(nodes[j+1].parms()[i].eval() != nodes[0].parms()[i].eval()): 
            allsame = False;
            message += " " + str(nodes[j+1].parms()[i].eval())+ " |"
        #Same parameter: omit value
        else:
            message += " - |"
    if not allsame :    #Output information only when there are different parameters
        print(message)

Output:

| - | box1 |box2 |box3 |
| - | - |- |- |
| Size | 1.0 | - | 1.9 |
| Uniform Scale | 1.0 | 3.11 | - |

If you copy this paragraph directly to your blog, it will become:

-box1box2box3
Size1.0-1.9
Uniform Scale1.03.11-

Try in a complex example

Downloadable fabrics It's some display effects of Houdini's official Vellum cloth simulation

Engineering documents can be found in here Download.

I created a default Vellum cloth configuration and then tried to compare it with the current eight cloth configurations

#Nodes to compare: (take the 0 as the reference)
nodes = [];
nodes.append(hou.node("../default"));
nodes.append(hou.node("../vellumcloth10"));
nodes.append(hou.node("../vellumcloth11"));
nodes.append(hou.node("../vellumcloth15"));
nodes.append(hou.node("../vellumcloth3"));
nodes.append(hou.node("../vellumcloth6"));
nodes.append(hou.node("../vellumcloth8"));
nodes.append(hou.node("../vellumcloth9"));
nodes.append(hou.node("../vellumcloth_wool"));

...

The results are as follows:

-defaultvellumcloth10vellumcloth11vellumcloth15vellumcloth3vellumcloth6vellumcloth8vellumcloth9vellumcloth_wool
Density0.10.40.040.40.250.040.040.020.04
Thickness2-3-33333
Edge Length Scale0.25-----0.2--
Normal Drag10.0-80.0--40.080.040.080.0
Tangent Drag0.12.00.45.01.00.40.840.00.4
Stiffness1.0100000000.0-100000000.0-----
Damping Ratio0.0010.0001-0.0001-----
Stiffness1.02000.0---0.15-2.0-
×-41010610-6-7-7-
bendstiffnessscalemode0-1------
Damping Ratio0.01---0.0075-0.1--
Rest Angle Scale1.0-2.0-2.0----
dobendstiffnessfalloff0---1----
Stiffness Dropoff0.055.085.055.048.085.070.085.085.0
bendstiffnessfalloffdir0-1-11111
dobendstiffnessdropoffmin0--11----
Min Stiffness0.0--0.00015e-06----
Enable Plasticity01-111-11
Threshold10.03.0-35.015.00.1-1.00.005
Rate1.06.0-5.00.30.25-2.0-
Hardening1.00.5-5.0-0.3-2.0-
Promotion Method25-5-----
Tagdefaultvellumcloth10vellumcloth11vellumcloth15vellumcloth3vellumcloth6vellumcloth8vellumcloth9vellumcloth_wool

Through this list, you can know which parameters have changed, that is, which parameters I need to pay attention to.

Problem record:

Errors will be reported when running python scripts:

I'm on this question Python troubleshooting Unicode encodeerror 'ascii' codec can't encode character error resolution - guest granting - blog Garden The solution is found, that is, run this code first:

import sys

reload(sys)

sys.setdefaultencoding('utf8')

After that, there was no error

Posted by obsidian on Sun, 10 Oct 2021 20:54:29 -0700