v5.2 preliminary tutorial on animation

Post Reply
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

v5.2 preliminary tutorial on animation

Post by Support »

Version 5.2 of Raylectron includes significant improvements and the introduction of component animations, which is currently only available in the CPU version. Let's take a closer look at how the animation feature works.

To animate objects, you will need to write a script using the Pascal programming language. Don't worry, it's easy to learn the basics of its syntax.

Let's start from scratch. Assuming you have a spaceship in SketchUp that you want to animate. First, convert the spaceship to a component and give it a name. Then, change the axis of the component to the bottom middle of the spaceship, that will be its rotating point. We define the axis as x, y, and z. In Sketchup, the x-axis is the green line, the y-axis is the red line, and the z-axis is the blue line. Knowing this will make it easy for you to know which axis to rotate or move the object along.

Now that your spaceship is set up properly in SketchUp, export your model to Raylectron using the CPU icon in the Raylectron toolbar.

Once Raylectron is open and your model is loaded, select Draft Mode and Simple Draft Mode from the toolbar. This will make updating the viewport much faster than if it is in render mode. Next, open the Animation tab on the right side of the screen. For this example, set the length of the animation to 30 seconds and the frame rate to 30 frames per second for smooth animations.

Now, right-click on your spaceship to load it, or select it from the list of available objects. You are now ready to enter a script in the editor. Let's rotate the spaceship along its up/down axis, which is called "yaw". Enter the following script in the editor:

Code: Select all

Yaw(360,1,10);
This will rotate the spaceship 360 degrees within 10 seconds, starting at 1 second into the animation and ending at 10 seconds. Now click the Play button to see the animation. You can change the Yaw command to Pitch or Roll for different types of rotation.

If you want the spaceship to accelerate in its forward direction, assuming the red line in Sketchup is aligned on the front to back of the spaceship, enter the following line of code in the script:

Code: Select all

py := Accelerate(1, meters, 0, 20);
Here, py is an internal variable that represents the distance to move along the y-axis. You could use px and pz to see what they do. The function "Accelerate" takes four parameters. The first and second parameters are the acceleration. In this case, we want the spaceship to accelerate at 1 meter per second, starting immediately as soon as the animation starts (0) and ending the acceleration but keeping a steady speed starting at 20 seconds into the animation. Click Play again to see the new animation.

That's it for this example. In the next section, we will explain all the variables and functions in more detail.

Here is the script for the following animation...

Code: Select all

// the video length is 30 sec at 30 fps
Roll(360,1,10);  // roll 360 deg starting at 1 sec until 10
Yaw(360,11,29);  // spin around 360 deg at 11 sec until 29 sec
Your support team.
https://SoftByteLabs.com
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

Re: v5.2 preliminary tutorial on animation

Post by Support »

For those unfamiliar with the Pascal programming language, here are the basics you need to know to get started with Raylectron.

All statements must end with a semicolon, and you can have more than one statement on a single line. For example:

Code: Select all

x := 1; y := 22; z := 321;
The above is equivalent to:

Code: Select all

x := 1;
y := 22;
z := 321;
Assignments must use ":=" instead of "=". The "=" operator is used for comparisons. For example:

x = 1 means "does x equal one?" If so, it returns True, otherwise it returns False. This is used in testing. For example:

Code: Select all

if x = 1 then x := 2 else x := 3;
This will test if x is equal to 1, and if it is, it will assign 2 to x. Otherwise, it will assign 3 to x.

The "if" statement ends with a semicolon, and it can also be on multiple lines. For example:

Code: Select all

if x = 1 then
  x := 2
else
  x := 3;
To perform multiple actions within an "if" statement, you can use the "begin" and "end" statements to form a block. For example:

Code: Select all

if x = 1 then
begin
  x := 2;
  y := 99;
end
else
begin
  x := 3;
  y := 0;
end;
It can also be written more compactly as follows:

Code: Select all

if x = 1 then begin
  x := 2;
  y := 99;
end else begin
  x := 3;
  y := 0;
end;
Now that you understand the basics, let's move on to variables and functions.
Your support team.
https://SoftByteLabs.com
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

Re: v5.2 preliminary tutorial on animation

Post by Support »

To help you get started with scripting in Raylectron, here are some internal variables that you can set:

px, py, and pz represent the distance to add to the object's current position. px is along the x (green) axis, py is along the y (red) axis, and pz is along the z (blue) axis. This must be specified in inches.

rx, ry, and rz are for rotation along the x, y, or z axis, respectively, and must be specified in degrees.

CamPosX, CamPosY, and CamPosZ are no different than px, py, and pz, except they are used to set the camera position instead of the object.

CamRotX, CamRotY, and CamRotZ are used to rotate the camera and are also specified in degrees.

Your script will be called for every frame of your animation. For example, if you have a 10-second video with a frame rate of 30 frames per second, your script will be called 300 times with the following variables set:

fps is the frame rate that you have set in the animation settings, such as 30 for 30 frames per second.

cf is the current frame, starting at 1. For example, at 2 seconds into the video, cf will be equal to 60.

sec is the current second, which is equal to cf divided by fps.

inx is the index of the instanced object in the list of objects. This is mainly used to randomize movements by some instances and not others. For example, if you load an asset like the Asteroid Rock and have 500 of them, they all share the same script, so you could use inx to perform some actions on some of them, such as those with an odd index number could rotate, and those with even index number will move.

Here are some of the functions that you'll use most often:

Pitch(Angle, StartAt, EndAt)
Roll(Angle, StartAt, EndAt)
Yaw(Angle, StartAt, EndAt)
Accelerate(AccPerSec, AccUnit, StartAt, EndAt)

You may already be familiar with these functions since we used them at the beginning of the tutorial.

This concludes our introduction to scripting in Raylectron. If you have any questions or need help with a specific task, feel free to ask in the comments below. We will cover more advanced topics in our upcoming tutorial.
Your support team.
https://SoftByteLabs.com
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

Re: v5.2 preliminary tutorial on animation

Post by Support »

Here is a script of an F-16 taking off, roll, turn around and flyby. The F-16 speed if 30x slower for this demonstration, it should, in real life, be about 30 m/s as opposed to 1 m/s

Code: Select all

py := Accelerate(1, meters, 0, 20); // accelerate at 1 m/sec for 20 sec
Pitch(20, 7, 10);   // nose up 20 deg at 7 sec till 10 sec
Roll(90, 12, 18);   // roll 90 deg at 12 sec till 18 sec
Pitch(180, 20, 24); // turn back 180 deg at 20 sec till 24 sec
Roll(-90, 24, 30);  // roll back straight by 90 deg at 24 sec till 30 sec
Pitch(20, 24, 30);  // nose back straight by 20 deg at 24 till 30 sec
Your support team.
https://SoftByteLabs.com
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

Re: v5.2 preliminary tutorial on animation

Post by Support »

Here is another one. This time, I loaded the Asteroid asset, have 200 of them and applied the following script to it...

Code: Select all

// my frame rate is 30 fps
// rotate 30 deg per sec in all axis...
rx := 1;
ry := 1;
rz := 1;

// move 30 inches per sec in the forward direction it's currently in...
px := 1;
py := 1;
pz := 1;
Your support team.
https://SoftByteLabs.com
User avatar
Support
Site Admin
Posts: 3004
Joined: Sun Oct 02, 2011 10:49 am

Re: v5.2 preliminary tutorial on animation

Post by Support »

Animation is not restricted to spaceships, cars etc. It can be used by cabinet makers for example. Like in the following animation, the top cabinet cover opens, the bottom one gets rotated at the beginning, so it opens from up down as opposed to down up.

The script for the small cover...

Code: Select all

// the cover will open by 80 degree within 5 seconds...
pitch(-80,0,5);
and for the wider cover...

Code: Select all

if cf = 1 then begin
  // rotate the cover first and move it at the right place...
  ry := 180;
  pz := -11;
end else
  // now lets open it starting at 1.5 second until 7 seconds...
  pitch(-80,1.5,7);
Your support team.
https://SoftByteLabs.com
Post Reply