- Parameter expressions: these are Python scripts inside the parameter input fields. You can right click on an input filed, and select Expressions > Edit Expressions. You need to make sure that your scripting language is set to Python. These scripts are saved as part of you Houdini model, in you .hip (or .hipnc) file.
- Python operators: these are custom nodes implemented from scratch in Python. These are saved in .otl files, and can be used the same way as the built in nodes.
In yesterdays workshop, we focused on parameter expressions, and we wrote some expressions to find the average of a set of input points. Here is the script:
# Get the data this_node = hou.node(".") inputs = this_node.inputs() first_input = inputs[0] input_geometry = first_input.geometry() points = input_geometry.points() # Loop through add add up all the points x = 0 for point in points: point_pos = point.position() x += point_pos[0] # Divide the values by the number of points num_points = len(points) x = x / num_points # Return the value return xThe Houdini functions and classes are all in the hou module. When scripting in Houdini, the hou module is imported automatically, so there is no need to have 'import hou' in your scripts. The key ones to loo at from todays sessions are the following:
- hou.node() function
- hou.Node class
- hou.Node.inputs() method returns a tuple of input
- hou.SopNode class (which is a sub class of hou.Node)
- hou.SopNode.geometry() method returns the geometry data in a node object
- hou.Geometry class
- hou.Geometry.points() method returns all the point data in a geometry object
- hou.Point class
- hou.Point.position() method returns the x,y,z position of the point object
No comments:
Post a Comment