part
<part>
defines a parameterized component that can be
reused in multiple places in the design of a 3D model, and each instance
can have a different parameter setting.
Using
<part>
in the code is highly encouraged because it greatly improves
the reusability, readability, and maintainability of your code.
Suppose we've designed a simple frame by cutting a cube out of a larger cube like below.
We can wrap these tags with a
<part>
tag and give it a meaningful
name by adding name="frame"
as an attribute. This allows us to create
multiple instances of the frame later by writing <frame/>
. In the example
below, we create two frames and insert a cube between them.
Suppose we want to update the design of the frame part. Instead of a square
hole, we want the hole to be a circle. We can simply modify the code inside
the <part name="frame">
tag, changing the second <cube>
to <cylinder>
.
Then, both instances of the frame part are updated with the new design.
Furthermore, suppose we want to control the size of the hole of each frame.
We can introduce a parameter by adding a
<param>
tag and
giving it diameter
as the name. Then, we can assign each instance of
the <frame>
with a different diameter value to achieve what we want.