CSG Object Calculator
This script creates and manages geometry in Houdini with Python:
-
Auto-placed Objects: Each new object appears in the scene with a name label.
-
Merged Layout: All objects are in a single container.
-
CSG Operations via Python Operators:
-
~Invert -
+Union -
-Difference -
&Intersection
1. Objects laid out with labels. Using the code stated in Canvas to test out the calculator:
box = CSG("box", "box")
sphere = CSG("sphere", "sphere")
thing = CSG("thing", "testgeometry_rubbertoy")
#Operations
union_result = box + thing
diff_result = thing - sphere
intersect_result = box & thing
invert_result = ~thing
2. Other operations:
#Operation Difference from first result:
union_result = sphere+ thing
diff_result = thing - box
intersect_result = sphere& thing
Troubleshooting:
When I was writing the script, it kept on giving me an invalid node name error, so I just looked up the error on Google and scoured several forums, which led me to the Python documentation for isalnum, allowing me to hardcode and remove any special characters Houdini does not like:
- only allow letters, numbers, and _
- for c in name: iterate over every character in the string
- c.isalnum(): true if character is a letter or number
- or c == "_": allow _
- else "_": any invalid name characters are replaced with _
- "".join(...): stitch back the string together
c meaning character
Perforce Submission:
//CLASSES/Cohort22/Students/Jocelyn.Fayola/Tech Art/Python/HW10.py




No comments:
Post a Comment