Thought I’d post my first little (of many) experiments.
A piece of code that helped me create the header image in Houdini 11.
Sort of a hello_site example.
I plan on posting something every week or so. As in a tutorial or small experiment that helped me achieve a certain task or goal. At work or for fun.
To get this snippet of code working, create a Python geometry operator in Houdini: “file” > “new operator type”. Select: “Python Type” and “Geometry Operator”. Give the new operator a name and location on disk (default is your Houdini home / “otl”
You should be presented with a screen asking you to create new parameters and place your code.
For this piece of code to work, 4 parameters are required:
- name: width, type: int, default: 20
- name: slope, type: int, default: 1
- name: size, type: float, default: 1
- name: attr_name, type: string, default: pscale
On their own these parameters do absolutely nothing. We need to bind them in our code. See the example below on how to achieve this. All code is commented and can be placed directly in the python operator.
After pasting or writing the code, click on “Accept”. You should now be able to tab and find the operator. The “width” defines the amount of base points, the “slope” defines the triangle angle slope, the “size” specifies the element size (or space between points). The attributre “pscale” is created and set for each point. When copying a cube on to every point, the cube should have the correct size because of the pscale attribute.
geo = hou.pwd().geometry()
# Evaluate our parameters
width = hou.pwd().evalParm("width")
slope = hou.pwd().evalParm("slope")
size = hou.pwd().evalParm("size")
attrib_name = hou.pwd().evalParm("attr_name")
# Initialize base numbers
height = 0
offset = 0
# Add point attribute
attrib = geo.addAttrib(hou.attribType.Point, attrib_name, 1.0)
# Compensate for slope
width_offset = 2*slope
slope_offset = 1*slope
# Compensate for center
center_offset = float(width) / 2.0
# Calculate Point Grid
while width > 0:
for i in range(width):
# Create the point
point = geo.createPoint()
# Get the x position
x_position = float(offset+i) - center_offset
# Set the point in space
# Add point attribute
# Compensate the position every iteration
width -= width_offset
height += 1
offset += slope_offset