Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,800 courses, including more 3D + Animation and personalized recommendations.Start Your Free Trial Now
- View Offline
- Linking objects to points in Xpresso
- Creating a data slider to control a spline wrap
- Controlling multiple objects with a single slider
- Understanding the traditional character animation workflow
- Using the Character object for building and applying rigs
Skill Level Beginner
Have you ever been interested in learning scripting, but have been afraid of all that code? Do you like the pick whips in After Effects for linking layers and parameters? Well, if you answered yes to those questions, then you're going to love XPresso. XPresso is about establishing relationships between objects or parameters. To illustrate that, let's create a very simple relationship here. I'm going to add a cube to a scene and move it on its negative X axis, and let's add a pyramid to the scene. What I want to be able to do is to have this pyramid drive the rotation of this cube.
The first step in our process for creating the relationship with XPresso is to add an XPresso tag. Let's right-click on the pyramid and go to CINEMA 4D tags, and then XPresso. When I let go, I get an XPresso Editor that pops up here, and then I also have this little XPresso tag on my object. It's good form to put the XPresso tag on the objects that you're going to be controlling. In theory though, XPresso tags can exist just about any place in your scene. Now I'm going to bring the XPresso Editor down just a bit, and let's actually make the window smaller so we can see the whole thing and bring it down right here.
Now what I want to be able to do is drive the rotation of the cube with the rotation of the pyramid. Now what I need to do is to get my nodes for each of these objects here in the X group window. So let's take the pyramid and drag it over here and I get this little rounded rectangle, and let's drag the cube and drag it in. Now I get a rounded rectangle for that. Now these are called nodes. And if I expand the node outward a little bit, and I'll do that for each of them, the size doesn't really matter. It's just a question of being able to read the contents of the node.
Now you may have noticed that there is colors here in the XPresso Editor window and those colors are very important. The node system in XPresso is designed around the idea of inflows and outflows. On the left-hand side is blue, and those are inflows. On the right-hand side is red, and those are outflows. If I click on each of these colors you see I get properties, and these properties will change based on which side you click on, but also want type of object it is or node that you're using. This node, when I select it, has its own set of parameters, and for a basic object operator node, the only real parameter I can change is the reference.
This tells me what object in the system it's referencing. So I want to establish a link between the rotation of the pyramid and the rotation of the cube. So let's go to the Pyramid and do Coordinates > Global Rotation > Global Rotation-H. That's around the Y axis. Let's enlarge the node just a little bit. Now what we can do to establish our link is take the outflow from this Global Rotation-H and link it to the inflow of the Global Rotation-H on the cubes. So when I click on this little circle here, and that represents the outflow for that parameter, and let's drag it across the blue.
When I let go I get a list, and I can go down to Coordinates, and then go to Global Rotation > Global Rotation-H. So I've just linked Global Rotation to Global Rotation. Now you can link a lot of different things together, but there's always problems with the format of the information coming out. Rotation and rotation are expressed in the same way with degrees. If I were trying to link rotation to position that would be more problematic and I'd need to interpret that data with a node in the middle here. For now though, let's see what's happened. It looks like, visually, nothing's happened in the window.
So if we go to the Pyramid and go to the Coordinate properties, if I scrub the Rotation-H you'll see that both objects now turn, so the rotation on the pyramid is driving the rotation on the cube. And you can have more than one element linked together inside the node. What I can do is go to the Pyramid, and let's add in Global Position-Y. If I click on that and go to Coordinates and do Global Position-Y, I want to link this Global Position-Y to the Global Position-Y of the Cube. What I want to have happen is I'd like for the Cube to always remain 10 units above the Pyramid.
No matter where it is in space I never want it to be able to come down below the Pyramid. I'll start off by going to the Cube and adding in, under Coordinates, Global Position-Y. Now if I were to just simply drag across Global Position-Y to Global Position-Y, it's going to look like nothing happened. That's because the cube and the pyramid are already on the same Y level. But you'll notice though, if I select the cube, I can no longer drag it up. It's locked. I can move it on X and Z, but I can't move it on Y, Cmd+Z or Ctrl+Z. That's because the position Y is being controlled by this linkage here.
So what we want to do is to have this always be above the pyramid. So let's disable that, and we're going to introduce a new node in the middle here. Let's right-click in the XPresso window and go to New Node, and then XPresso, and then Calculate. All of these other menus that you see here are all about other elements that you can create within XPresso. You can create XPresso Hair nodes, MoGraph nodes, and Dynamics and Thinking Particles nodes. These are the general XPresso nodes, and I'm going to go to the Calculate function and add in a little bit of math.
Now don't be scared, I stink at math, but this is going to be really easy to understand. And this math node has its own set of properties over here in the Attribute Manager. Now let's give ourselves a little bit more room to work. I'm going to use the 2 key on the keyboard and drag out just a bit. You notice as I zoom in and zoom out that the XPresso window zooms in with me. If I hold on the 1 key I can pan around the XPresso window. Now you look at the parameters for this Math Add Node, you'll see that we have a data type. These will be real numbers, and we can do a different type of math function.
Add, Subtract, Multiply, Divide, and then something called Modulo. We're going to use a simple Math Add function, and these are the two values that we're going to add together: input one and input two. Input one is going to come from the Pyramid. We're going to take the Global Position-Y and drag that into this input field right here. When I make that connection it looks like nothing has happened. That's because this Math Add Node doesn't do anything until you send the output from it to another object. So what we want to do is to send the output from this Math Add Node into the Global Position-Y of the cube.
When we do this, nothing happens. That's because in the Math Add Node, all we're adding is zero. So let's add some values here. The original position of the Pyramid is currently Y on zero-axis. So if we add 100 to the position of the cube in the Math Add Node, if we go in here and type in 100, you'll see that the cube has jumped 100 units up. That doesn't seem exciting until you go and start moving the Pyramid around. No matter where I move the pyramid, it's always going to say 100 units higher than the location of this axis.
So if I make that say 300, then the cube will jump up here. And you can see as I move that around, no matter where I move it, it stays that way, and you can still move on X and Y, and you also still have the linkage for the rotation. Let's back out here just a bit so you can see everything going on. The Y position on the cube is still locked and I can't move it up and down, but I can still move it left and right on X and Z. So this is just literally touching the tip of the XPresso iceberg.
Just keep in mind that XPresso is a scripting language. It can be as complicated as you want to make it. If you're a programmer and you love writing code, the XPresso Editor is going to be your best friend. But if you're not comfortable writing code, then you can still do a lot of really interesting things with XPresso. Now, I'm not a code writer. So in this chapter I'm going to be focusing on things that I know non-code writers are going to find useful.
Sign up for a Premium Membership to download courses for Internet-free viewing.
Watch offline with your iOS, Android, or desktop app.Start Your Free Trial
After signing up, download the course here or from the iOS/Android App.