Custom ANIM3DTRANS animation - working.

Discuss the future of Warzone 2100 with us.
User avatar
astorian
Trained
Trained
Posts: 154
Joined: 29 Jun 2009, 12:26

Custom ANIM3DTRANS animation - working.

Post by astorian »

Hi, as the title is stating, it is possible to use custom ANIM3DTRANS animation type.
You may ask: Why to use ANIM3DTRANS instead of ANIM3DFRAMES?
Well, ANIM3DFRAMES animation type is displaying the objects stored in the pie - one object for one frame. This means you have to model objects for every frame. (Or you use one object and animate the textures frame by frame)
ANIM3DTRANS however, lets you animate the object by changing the location, rotation and scale values of the objects. So you model them once and then animate them with much better control. Since you can define the number of frames, frame rate, and multiple objects, the animation can be smooth and good looking, with low resources usage.
So, i was using reverse engineering to understand how the animation is working, and to get the right measurement for dimensions and rotations. To get some results, I made custom objects - see rotation image attachment. -I have used the rotation data from oil derrick animation - the arrow was showing me how much degrees it rotates.

How does it work:
First, let’s go thought the animation file blderik.ani to understand the formats and limitations:
The file header is actually quite self-explanatory:
/* header format: anim3d [filename] [frames][framerate] [num objects] */
/* anim line: [frame] [x] [y] [z] [xrot] [yrot] [zrot][xscale] [yscale] [zscale] */
ANIM3DTRANS "BLDerik.pie" 25 15 3
This means that the animation format is ANIM3DTRANS, it is animating the "BLDerik.pie" it has 25 frames total, frame rate is 15 frames per second and number of animated objects is 3

Then the objects are defined: ANIMOBJECT 0 – that is targeting the LEVEL 1 in the pie. (: ANIMOBJECT 1 will target LEVEL 2 and so on…) The "DerrickBase" is just a description to reference the animated object.
The animation values have a strict order and character space they occupy:
[frame] [x] [y] [z] [xrot] [yrot] [zrot][xscale] [yscale] [zscale]
0 0 0 0 0 0 0 1000 1000 1000
1 0 0 0 0 0 0 1000 1000 1000
First there are two tabulators, than 3 characters for frame number, which theoretically should allow 999 frames maximum.
Than one tabulator and now the values - 8 characters for each x, y, z, xrot, yrot, zrot, xscale, yscale, zscale value. Since the values can be also negative defined by “-” minus sign it leaves 7 characters for each value, which theoretically should allow maximum 9999999 values. It is important to use the correct spacing - all values are aligned to the right in the 8 character space, so all remaining characters to the left have to be empty space “ ”. I recommend tools like notepad++ to check the structure.

Now the scale ratio.
Let me start with the rotation, since it is easy to explain. One degree of rotation equals 1000 value. (1° = 1000) I didn't test if you can go beyond 360° (360000), but I presume it is possible (for spiral ascending paths for example).
The scale can be translated to percent 100% equals to 1000. So 50% is 500 and so on …
The location (or size dimension) are little harder to explain.
If you are working with the blender PIE plugin, like I do, the default cube in new scene is 2 blender tiles big. One blender tile = 100000 value (or 0,1 blender tile = 10000 value).
If you don’t use blender, let me describe the oil derrick size. The Derick base size is 89062 by 60938 wz units.
(The “piston” moves on z axis to 29827 wz units on frame 12.)

I have imported the oil derrick pie to blender and manually entered the location, rotation and scale values for each frame.You can open the attached blender file and press Alt + A to see the animation.

I have tested custom animation, -it works, but manually editing the ani file takes lot of time. The best would be to have a export script that exports the values for each frame. I have googled and found a script for exporting the location for each key frame. I just added the rotation and scale properties:

import bpy
scn = bpy.context.scene
obj = bpy.context.active_object
for f in range(scn.frame_start, scn.frame_end+1):
# use frame_set() so that keyed values are updated
scn.frame_set(f)
print(scn.frame_current, obj.location, obj.rotation_euler, obj.scale)

This is the output:
0 <Vector (0.0000, 0.0000, 0.0000)> <Euler (x=0.0000, y=0.0000, z=0.0000), order='XYZ'> <Vector (1.0000, 1.0000, 1.0000)>
1 <Vector (0.0067, 0.0000, 0.0017)> <Euler (x=0.0000, y=-0.0117, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
2 <Vector (0.0268, 0.0000, 0.0071)> <Euler (x=0.0000, y=-0.0335, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
3 <Vector (0.0600, 0.0000, 0.0172)> <Euler (x=0.0000, y=-0.0755, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
4 <Vector (0.1058, 0.0000, 0.0337)> <Euler (x=0.0000, y=-0.1345, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
5 <Vector (0.1632, 0.0000, 0.0589)> <Euler (x=0.0000, y=-0.2103, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
6 <Vector (0.2305, 0.0000, 0.0956)> <Euler (x=0.0000, y=-0.3031, z=-0.0000), order='XYZ'> <Vector (1.0000, 1.0000, 1.0000)>
7 <Vector (0.2989, 0.0000, 0.1418)> <Euler (x=0.0000, y=-0.4030, z=-0.0000), order='XYZ'> <Vector (0.9990, 1.0000, 0.9990)>
….
First is location, than rotation and on the end scale. However the location requires one more decimal point, the rotation is in radians and not in degrees. I found the degree calculation http://blenderartists.org/forum/showthr ... alculation, but I don’t know how to incorporate it into the script.

So if there is someone that understand python language (not the real snake) - your help is wanted and welcomed to export the values. At least text containing location, rotation and scale for each frame in correct wz values would be awesome.

my best regards,
Astorian
Attachments

[The extension blend has been deactivated and can no longer be displayed.]

rotation.png
rotation.png (88.69 KiB) Viewed 11197 times
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

As you said, ANIM3DTRANS is definitely the cooler one (even though ANIM3DFRAMES has its uses)
I've been thinking of doing this myself but I have no free time currently. Maybe I could assist a bit with some technical details...
Anyway, 2*pi radians is 360 degrees, so angle(degrees) = angle(radians) * 360 / (2*pi).
And inversely, angle(radians) = angle(degrees) * (2*pi) / 360
As for the angle unit in blender, I'm not even sure whether we use degrees or have a custom scale like 1023 = 360 degrees, but that can be tested later.
ImageImage
-insert deep philosophical statement here-
User avatar
astorian
Trained
Trained
Posts: 154
Joined: 29 Jun 2009, 12:26

Re: Custom ANIM3DTRANS animation - working.

Post by astorian »

Hi Jorzi, i have tested the rotation, and as i state above: "One degree of rotation equals 1000 value. (1° = 1000) I didn't test if you can go beyond 360° (360000), but I presume it is possible (for spiral ascending paths for example)."
Blender uses degrees, but also radians,so i have posted on blender python forum to get help with the calculation in the script.
Maybe i can use excel or similar tool for working with the values. However a python programmer/scripter is welcome.
If we could get the correct text formatting and spacing, that would be awesome.
Astorian
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

Sounds good, I pretty much conclude the same from looking at http://developer.wz2100.net/wiki/AniFormat
I did some formatting stuff to get you started:

Code: Select all

import bpy
import math
scn = bpy.context.scene
obj = bpy.context.active_object
for f in range(scn.frame_start, scn.frame_end+1):
    # use frame_set() so that keyed values are updated
    scn.frame_set(f)
    pos = obj.location * 1000
    rotx = obj.rotation_euler.x * 1000 * 360 / (2*math.pi)
    roty = obj.rotation_euler.y * 1000 * 360 / (2*math.pi)
    rotz = obj.rotation_euler.z * 1000 * 360 / (2*math.pi)
    scale = obj.scale * 1000
    print("\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d" % (scn.frame_current, pos.x, pos.y, pos.z, rotx, roty, rotz, scale.x, scale.y, scale.z))
ImageImage
-insert deep philosophical statement here-
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

I guess the next step would be doing this for all selected objects and adding the proper headers and indentation.
Btw:
I use special syntax inside the string:
"%d" means "here comes a number formatted as an integer", it will take the values from the listed variables after the string.
"\t" means "here comes a tab"
ImageImage
-insert deep philosophical statement here-
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

After looking a bit at the blender Python API, I realized they have a heap of really useful readymade templates.

One of them was an exporter template where I can simply copypaste in the stuff we've written so far and suddenly we have a full featured exporter with a save dialog etc..
Did I mention blender is awesome? :)
ImageImage
-insert deep philosophical statement here-
User avatar
astorian
Trained
Trained
Posts: 154
Joined: 29 Jun 2009, 12:26

Re: Custom ANIM3DTRANS animation - working.

Post by astorian »

Hi Jorzi.
First let me thank you for your help with the scripting. I only know Powershell which is also object oriented.
Blender is the best 3d tool i have used. I have modeled 99% of my models in it. Blender rocks!
Still, the location value is one decimal point short. Is it possible to get one more from the obj.location somehow? The manual input was alowed as you cas see from the blender file.
my best regards,
Astorian
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

I gues you can just change the factor 1000 to 10000
Remember though that one wz2100 square is 256 blender units wide.

Here is the script, I added some metadata & stuff so now it can be installed and run from the export menu just like any other blender addon. Also, it should export data correctly for all selected mesh objects (non-mesh objects are ignored)
Attachments
wz_anim_export.py
(3.71 KiB) Downloaded 283 times
ImageImage
-insert deep philosophical statement here-
User avatar
MaNGusT
Art contributor
Posts: 1152
Joined: 22 Sep 2006, 10:31
Location: Russia

Re: Custom ANIM3DTRANS animation - working.

Post by MaNGusT »

May I admit that ANIM3DTRANS works only for the oil derrick model? I mean it's hardcoded and was never fixed. So, it's awesome to have a working animation exporter but use it only for one model... sounds a bit sad...
Image
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

Works on cyborg legs too :P But yeah, would be nice to assign .ani files to firing animations etc.
Anyway, writing this script actually turned out to take less time than modeling the actual oil derrick thanks to blender's nice templates :P
ImageImage
-insert deep philosophical statement here-
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Custom ANIM3DTRANS animation - working.

Post by Per »

ANIM3DTRANS doesn't seem hard-coded to those particular game objects in the code...?

(The movement animation stuff used to be hard-coded but is not anymore in git master version.)
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

Ok, let's figure out what's possible and what's not, here are some possible stuff we might want to do:
-Firing animations for weapons
-Rotating the fans of factories (&moving pistons maybe?) instead of animating the texture
-Open factory door when production is ready
-Custom gate opening animation
-Rotating wheels, moving tracks
-Landing bridge for super transport (and spinning fans, of course)
-Custom animation loops for any structure (power gen / command center with moving parts wouldn't look too bad)
-Moving parts on truck while building
-Spinning barrels on multibarrel weapons (assault gun, pepperpot, hellstorm, assault cannon etc..)

So the questions are:
-How much of this can be done already?
-What are the steps needed to make most of this stuff possible?
-For stuff that's not in the animation loop all the time: What determines the "rest pose" of the sytem? First frame? Everything at zero?
ImageImage
-insert deep philosophical statement here-
User avatar
Berg
Regular
Regular
Posts: 2204
Joined: 02 Sep 2007, 23:25
Location: Australia

Re: Custom ANIM3DTRANS animation - working.

Post by Berg »

Jorzi wrote:-For stuff that's not in the animation loop all the time: What determines the "rest pose" of the sytem? First frame? Everything at zero?
I think thats just a matter of stats editing not real sure... stop position run position etc

Most of this stuff if you wona use ani is hard coded I suspect.
If you wona use frame animation its just a matter of enabling it per item ..like structure animation is already enabled but unit and defense animation maybe not for frames.
you need to hire a good coder Jorzi. (Good Coder Required ..see jorzi for jobs list!!!)
I also think the rate you can move Levels in a pie file will have limits high speed stuff is sorta out. (levels in pie files needed to use ani animation)
With effects you only need to add them to the stats and or modify whats already in use a lot of effects are there but are either not used or are faulty see the fortress effects I did years back.

All this is possible there is no real limit to any animation in my opinion. The only real life limit is real life...how much time you can spend on this project.
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

The only real life limit is real life...how much time you can spend on this project.
Unfortunately this is my biggest current limitation.
I also think the rate you can move Levels in a pie file will have limits high speed stuff is sorta out.
But you can increase the framerate, right?

With frame animation do you mean texture animation? It's cool and all but with some stuff you really want to move the geometry. Texture animation is also one of those things that really would need a tool. I've done it on some stuff but the manual editing of polygon flags as well as offsets & stuff is tedious to say the least.

Anyway, anyone who can use blender and has knowledge of warzone's animation system (I guess that's like 3 people in the world), please test my script.
ImageImage
-insert deep philosophical statement here-
User avatar
MaNGusT
Art contributor
Posts: 1152
Joined: 22 Sep 2006, 10:31
Location: Russia

Re: Custom ANIM3DTRANS animation - working.

Post by MaNGusT »

Per wrote:ANIM3DTRANS doesn't seem hard-coded to those particular game objects in the code...?
Last time I tested it on propulsion model and it didn't work. I just splitted the new model of wheels propulsion onto 3 levels (as oil derrick have) and renamed derrick's anim to correct propulsion name. :(
Image
Post Reply