You are on page 1of 5

Xpresso Basics

Range of use
From the previous chapter you now know for which purposes Expressions can be used. They influence the properties and behavior of objects. Some of CINEMA 4Ds pre-defined Expressions you already know as tags that are assigned to objects. For example, the Vibrate tag will modify the position of the object to which it is assigned. All of these pre-defined tags serve their own useful purpose. Nevertheless, not all imaginable functions can be performed by these pre-defined tags and this is where XPresso comes in. XPresso lets you create a custom tag step-by-step that performs exactly the task you want. CINEMA 4D offers an integrated programming language, C.O.F.F.E.E., but not everyone has a knack for programming. XPresso offers an easier-touse alternative by letting you create tags via its own graphic interface. Even after working through this tutorial you will surely have to invest more time in practicing using XPresso to better understand its ways.

The Node system


An XPresso Expression is made up of Nodes, which are the basis of any Expression. XPresso is a node-based system in which various Nodes are connected to perform one or more functions. A node-based system bears the advantage that Expressions can be created faster and that those new to the system can relate better to a graphic interface than line after line of programming code. If you have never worked with XPresso it may at first seem a little confusing. After working through this tutorial and a little practice you will be able to easily create an Expression like the one pictured above.

XPresso tag
The Xpresso tag can be viewed as a container in which our Expressions are housed. We will first create a Null. Right-click on the newly created object in the Object Manager and select XPresso from the CINEMA 4D Tagsmenu. The XPresso Editor window will automatically open. This is where we will create our Expressions. This window can be scaled, if necessary, and re-opened anytime by simply double-clicking on the XPresso tag in the Object Manager. In most cases it doesnt matter which object has the XPresso tag assigne to it.

XPresso Editor
A set of connected Nodes is called an XPresso Expression. All Nodes are created and linked in the XPresso Editor. At the left of the XPresso Editor window are two tabs, the X-Manager and X-Pool tabs. The X-Pool tab contains all Nodes that are available for use. We can also right-click on the XPresso Editors XGroup field to display this list of available Nodes; the X -Manager tab displays a list of all Nodes contained in our Expression.

Nodes
A Node represents an object or a function. A Nodes parameters are displayed in the Attribute Manager. Lets take a closer look at the following Expression:

The scene contains a Cube and a Sphere object, respectively. The XPresso tag has been assigned to the Sphere object. It makes no difference which object has been assigned the XPresso tag. The corresponding Expression is open and shows two Nodes that are connected by a black line. Each Node represents an object in the scene and are referred to as Object Nodes. Nodes have Ports through which data is input or output. Depending on the type of Node, it can have one or more Ports. If a Port is located on the left side of a Node it will accept input from other Ports; if a Port is located on the right side of a Node it puts data out (output) to other Ports. An Object Node can input or output any of an objects properties. These properties are the same that

are displayed in the Attribute Manager as well as several additional attributes belonging to that particular object. Ports are connected in the XPresso Editor. An input Port can be connected with multiple output Ports, even if the output Ports are located on different Nodes. However, an input Port can only have a single connection from an output Port. Now lets apply this to the example above. The spheres Object Node has an output Port named Global Position, which outputs the position of the sphere to the input Port of the other Node. This means that the Cube object is assigned the position of the Sphere object. If you now move the sphere the cube will follow accordingly.

File types
So far we have talked about how a Node can assume data (input Port) or assign data (output Port). As ween with the Object Node we know that an objects properties are included. If we take a look at the Attribute Manager we can see the objects various parameters, among them its name and position coordinates. If we were to output the data from these two parameters via an Object Node we would have to ask ouselves in which format will this data be output. After all, a coordinate is a vector consisting of three floating point numbers and the name is a string of characters. Two vectors can be multiplied and two strings of characters can be connected but an operation between a vector and a string of characters does not really make any sense. This prevents the data that have nothing in common from being included in an operation. Only Ports of related data types can be connected with one another. If the data types have common characteristics an automatic conversion will take place. In the followig we will explain several XPresso data types that are available in CINEMA 4D:

Boolean
There are two types of boolean states: true or false. These states are expressed as numbers: 1=true; 0=false. This operation is explained in more detail in the Boolean Algebra section.

Integers
An integer (or "whole number") has no decimal place and is, for example, used to display the number of subdivisions an object has. In integer can have either a positive or a negative value.

Real
A real number (also called a "floating point number") is a number that continues after the decimal place. A real number can have either a positive or a negative value and has an accuracy of up to six decimal places behind the comma. Note however that the CINEMA 4D GUI only displays the first three numbers behind the decimal. When a real number is converted to a vector the value will be transferred to the comonents of the vector. If a number is converted from real to integer all places behind the comma will be removed and no rounding will take place.

Vektor
CINEMA 4D uses vectors everywhere where a value cannot be displayed by a single number. This includes position (X,Y,Z), color (red, green, blue) and rotation (heading (H), pitch (P), bank (B)). A vector consists of three components, which themselves are real numbes. Normally these components are lebeled X, Y or Z. If a vector is converted to a real number the result is the length of the vector.

Matrix
A matrix is a group of four vectors that are used by CINEMA 4D to describe a coordinate system. These components are lebeled v1, v2, and v3 for each axis, respectively. This data type will be explained in more detail in the course of this tutorial.

String
A string can consist of an infinite number of characters (letters, numbers, special characters). A string can be used to save individual words or blocks of text.

Link
A link is a connection to an object within the scene. This can be a tag, object or even a material. Many Nodes types have the ability to modify the properties of a linked object or extract values for further processing. Use a link to reference an element in the scene.

Telescopic Arm
We will introduce XPresso to you by creating a telescopic arm that can be extended and contracted. Create three Cylinder and name them Cylinder_small, Cylinder_middle and Cylinder_big, respectively. In the Attribute Manager..., set the middle cylinders Radius to 45 and the small cylinders radius to 40, which will result in three cylinders of differing diameters.

What we want to do is move the small cylinder upwards and have the middle cylinder automatically move up accordingly while remaining in the center of the other cylinders, thus creating a telescope effect. Create a new XPresso Expression by right-clicking on the Cylinder in the Object Manager... and selecting CINEMA 4D Tags | XPresso from the menu that appears. In this example, it doesnt matte r which object is assigned the tag. The XPresso Editor window will open. Drag all three cylinders from the Object Manager onto the XPresso Editor window. The objects will be represented by small rectangles, called Nodes.

Nodes have Input and Output ports that can be used to exchange data between Nodes. All of a Nodes Input ports can be displayed by clicking on the small blue square at the top left of the Node. The Output ports can be displayed by clicking on the red square at the top right of the Node. Take a look at the Cylinder Nodes Output ports. Some of these properties will probably already be familiar to you from the Attribute Manager. Since we want to move the small cylinder upwards we have to modify its Y position value. This should in turn affect the middle cylinders Y position value. Its Y position value should always remain at the center of the small cylinder and big cylinder s Y position values. Click on the Cylinder Nodes red square and select Coordinates / Position / Position.Y. Do th e same for the small Cylinder Node.

Both cylinders can now pass on their individual Y position values. We want to calculate the average of these values. We will use a special Node to do so. Drag a Mix Node from the X-Pool tab (System Operators / XPresso / Calculate / Mix). In the Attribute Manager, set the Nodes Mixing Factor to 50%.

Connect the small cylinder Nodes Position.Y Output port to the Mix Nodes Input 1 port; connect the big cylinders Position. Y Node with the Input 2 port.

Both Y positions will now be passed on to the Mix Node, which will calcuate the average of the two values. The 50% setting ensures that the values will be mixed equally. The result will be the Y position of the middle cylinder. Click on the middle cylinders blue square and create an Input port for the Y position (Coordinates / Position / Position.Y). Connect the Mix Nodes Output port to the middle cylinders Input port.

Take a look at the result in the Viewport. Move the small cylinder along its green Y axis. The middle cylinder will follow automatically. We still have one small problem to solve, though: the cylinder can be pulled so far apart that the telescopt comes apart. We need to restrict the amount of movement allowed.

To do so, add a Clamp Node (System Operators | XPresso | Calculate) and set the Maxvalue to 300 in the Attribute Manager.

The Clamp Node will now restrict all values entered into its Value Input port to a value between 0 and 300. Now we will connect this Node to the rest of our Expression. Click on the small cylinders blue square and create a Position.Y Input port (Coordi nates / Position / Position.Y). Drag the small cylinder from the Object Manager into the XPresso Editor window again and create a Position.Y Output port. Connect this Output port with the Clamp Nodes Value port and connect the Clamp Nodes Output port with the Position.Y Input port on the initial small cylinders Node.

The cylinders movement is now restricted in the Y direction, as a real telescope would be.

Automatic Rotation
Rotating objects are a part of many animations - Wheels, propellers, radar antennae. These objects can be rotated by setting keyframes but we will show you how its done using XPresso. The scene contains a simple model of a fan, including materials, lighting and background. All individual parts of the fan are grouped in a Null Object.

You might also like