XPresso in Cinema 4d
Node Programming
Xpresso is a system of programming using nodes connected by wires used to automate interactions between objects. A node can represent an object, a math function, a light, logic functions, iterators, object qualities, and more. It is truly a full featured programming language that can manage the many relations between objects in an animation.
The easiest way to use Xpresso is to relate two objects or more using the set driver/ set driven relationship. One attribute of an object, like position, can drive an attribute of another object, maybe scale. You simply right click the attribute and select expressions>set driver and on the second object click the desired attribute and select expressions>set driven. Then, any change in the first attribute, the driver, will cause a change to the second attribute in the second object. In the example an Xpresso editor is automatically created with the sphere and an output port of the position on the y axis and a cube with input port for rotation. Since both ports use vector data, there is no need to have a range mapper change from one data type to another.
The usual way to open the Xpresso editor is by right clicking the object where you want the Xpresso tag. Then you select programming tags>Xpresso. The objects from the object list are dragged and dropped into the editor. The next example is of two gears that can be made to rotate in a realistic manner. The range mapper node is necessary so that the gears rotate in the correct directions.
In a similar manner, Xpresso can be used to make the tires of a toy auto turn as the little car goes around a windy track. The car follows a curvy flower shaped path and gradually starts to move and then slows down to a California rolling stop. Then it is off again down the track.
With all the reports coming in from the war in Ukraine, I have had military tanks on my mind. Here are Russian tanks, one after another, heading for the front lines. The Xpresso was used to coordinate the rotation of the tank tread the and three wheels. Here is the setup and the Xpresso editor so you can see how this was accomplished.
On a lighter vein, here are two jack in the box, which jump up and down when the ball touches the box and triggers the movement. A comparison node sends a Boolean yes, or 1, when the distance from the ball to the center of the box is equal or less than a certain distance. A comparison node is used for each box to trigger the start of the up and down movement of the figures. The compare node sends a signal to the monoflop node, an interestingly named node, which activates a vibrate node for a specified number of frames.
Maybe you remember the Spirograph, which allows us to draw complex images composed of many interwoven lines. A Spirograph can be simulated in mathematics by using parametric equations with multiple variables. In Cinema 4d you can enter the variables in user data. Then, using Xpresso, most especially the Python node, these complex parametric curves can be easily plotted and animated. In the screen shot, you can see the Xpresso editor and the Python expression editor. There are very few objects needed in this case.
For something more like the images from a Spirograph here is another curve that I found the formula for in Wikipedia, parametric equations. It is a formula with 6 variables.
(cos(a*t)-pow(cos(b*t);j))*100
(sin(c*t)-pow(sin(d*t);k))*100
In the Python editor it looks like:
def main():
global xt, yt
xt = "(cos("+str(a)+"*t)-pow(cos("+str(b)+"*t);"+str(j)+"))*100"
yt = "(sin("+str(c)+"*t)-pow(sin("+str(d)+"*t);"+str(k)+"))*100"
The formulas found in the Python editor use that well known formatting scheme and give the means to use various variables in the equations. The animation is created by keyframing different values for the variables so that the program gradually substitutes intermediate values for each frame of the animation. It should be possible to recreate these animations in Cinema 4d by using these screenshots which show the objects, Xpresso nodes and their wires, plus the formulas seen in the Python expression editor.
Here is the Python code from the expression editor:
def main():
global xt, yt
xt = str(xs) +"*t*"+str(xm)
yt = str(ys)+"*cos(t*4)*Sin(t*"+str(ym)+")"
I think that Xpresso is one of the most useful features of Cinema 4d. Perhaps it is not as popular as it could be, due to many people’s resistance to the study of coding. I hope that I have shown that it is not as complex as other types of programming. If you do want to learn more about Xpresso there is one book about the subject.
Maxon Cinema 4d R20, A Detailed Guide to XPresso, by Predeep Mamgain.
I wholeheartedly recommend it. It is surprisingly, the only book that I have found that explains this unique way of programming.
Neal Crosier © 2022