2025年11月7日星期五

Tech Art - Week12 - Class Hierarchy



Analysis

As usual, let’s start with a quick review of the assignment.


This week’s task is fairly straightforward with no major logical hurdles. The main thing to watch out for is the class hierarchy. I sketched the minimal layout as follows: the CSG class goes in CSGModule.py, while the Box and Tube classes go in ShapeModule.py.


One important detail: we use variables t, r, s, and c to store Position, Rotation, Scale, and Color respectively. When you actually modify them, make sure you are updating the node’s internal parameters. This is where __setattr__ helps a lot and greatly simplifies the code. Since __setattr__ is invoked whenever an attribute is set, we just detect changes to t, r, s, and c and then forward those changes to the node’s parameters.


Because this week’s assignment asks you to split classes across different files and call them from a main file, you can simply place those modules into Houdini’s Python library so they can be imported directly.

Example (Houdini 20.5.613)

  1. Find Houdini’s Start Menu folder:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Side Effects Software\Houdini 20.5.613
  1. Go to the Python libs directory:

C:\Program Files\Side Effects Software\Houdini 20.5.613\houdini\python3.11libs
  1. Put the files there:

CSGModule.py ShapeModule.py
  1. In your Houdini Python script, import the classes:

from ShapeModule import *

Note: I didn’t import CSGModule.py explicitly here because it is already imported inside ShapeModule.py, so there’s no need to import it again.

没有评论:

发表评论