This section gives an overview of the component framework that is the basis for creating a dynamic 3D scene, i.e. one that is animated/simulated. The basic mechanism is quite simple to understand and you might already know it from other graphics packages as it is a common concept in computer graphics software. The basic idea is to have some black boxes that can generate values that vary with time and that can be connected to the attributes we want to be animated. For example, one such black box could output a three-dimensional vector which could then be connected to the position of a teapot. If this black box now produces a series of values that lie on a particular curve we have an animation of a teapot traveling along that curve.
In this package those black boxes and the teapot are called components. A component is a container for slots which represent the input or output values of their respective component. In the above example, the output value of the "curve point generator" and the position of the teapot are slots. You can also view them as "animatable attributes" of an object if they mainly serve as input values. Most slots can either serve as input value or output value. However, if the value of a slot is actually computed by some algorithm then this slot can only be used as output slot.
As a general rule, the actual slot corresponding to an attribute is
obtained by adding the suffix _slot to the attribute name.
Here is an example where two spheres s1 and s2 are created and
the position of s1 is connected to the position of s2 which means
s2 will always have the same position as s1:
>>> from cgkit import * >>> s1=Sphere(pos=(1,2,3)) >>> s2=Sphere(pos=(-1,0,5)) >>> s1.pos (1, 2, 3) >>> s2.pos (-1, 0, 5) # Connect the positions >>> s1.pos_slot.connect(s2.pos_slot) # Now s2 has the same position as s1 >>> s2.pos (1, 2, 3) # Changing the position of s1 will also change the position of s2 >>> s1.pos=vec3(-5,12,42) >>> s2.pos (-5, 12, 42)