Skip to content

Instantly share code, notes, and snippets.

@jmacey
Last active July 11, 2018 17:10
Show Gist options
  • Save jmacey/988c3a359d93fa91b269b7127b827645 to your computer and use it in GitHub Desktop.
Save jmacey/988c3a359d93fa91b269b7127b827645 to your computer and use it in GitHub Desktop.
Code for my Houdini Rotation Demo
# import math so we can use cos and sin
import math
# these are generated by houdini and give us access to the current node.
node = hou.pwd()
geo = node.geometry()
# create a 4x4 matrix, passing in 1 creates it as the identity matrix
rotX=hou.Matrix4(1)
# which is the same as calling
# rotX.setToIdentity()
# We can access inputs in different ways this is one
#deg=node.inputConnections()[1]
#d=deg.evalParm('rotX/default1v1')
# however I will use this one.
hou.parmTuple('/obj/geo1/rotX/value1v').evalAsFloats()[0]
deg=hou.node('/obj/geo1/rotX')
# we now need to convert this to radians
theta=math.radians(deg.evalParm('value1v1'))
# pre calculate cos and sin for speed
cosTheta=math.cos(theta)
sinTheta=math.sin(theta)
# now we set the matrix values note matrix starts at 0,0 and is row / col
rotX.setAt(1,1,cosTheta)
rotX.setAt(1,2,-sinTheta)
rotX.setAt(2,1,sinTheta)
rotX.setAt(2,2,cosTheta)
# now we grab each point in the geometry
for point in geo.points():
# get the position
pos = point.position()
# transform by our matrix
pos*=rotX
# and reset the position
point.setPosition(pos)
# Check if the user pressed Escape.
if hou.updateProgressAndCheckForInterrupt():
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment