Custom ANIM3DTRANS animation - working.

Discuss the future of Warzone 2100 with us.
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:With frame animation do you mean texture animation
yes
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 »

MaNGusT wrote: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. :(
Send me your test case and I'll look into it.
User avatar
astorian
Trained
Trained
Posts: 154
Joined: 29 Jun 2009, 12:26

Re: Custom ANIM3DTRANS animation - working.

Post by astorian »

Hi, time is a luxury also for me. But i was able to invest some time into the development.
Jorzi, i have tested your python script, but it crashes. See attached image.
error001.PNG
error001.PNG (37.22 KiB) Viewed 8804 times
Now to continue on export script development discussion. Here are my main points:

Location precision & rotation in degrees The obj.location limits the result to 4 decimal places. It is not enough, we need to export 5 decimal places to have the same precision like in ani files. You have stated:
astorian wrote: gues you can just change the factor 1000 to 10000
Unfortunately, that would add one zero at the end, but we need to export the real value 0~9. I have posted on blenderartists.org to ask for help getting more precise readings. (See the post: http://blenderartists.org/forum/showthr ... lp-request)
So thanks to kastoria and CoDEmanX now we are able to get high precision location values, outputs degrees right away and it gets rid of the vector and euler text in output. Here is the example script:

Code: Select all

import bpy
scn = bpy.context.scene
obj = bpy.context.active_object
for f in range(scn.frame_start, scn.frame_end+1):
     scn.frame_set(f)
    print(scn.frame_current, obj.location.x, obj.location.y, obj.location.z, degrees(obj.rotation_euler.x), degrees(obj.rotation_euler.y), degrees(obj.rotation_euler.z))
Jorzi do you think the to_tuple() method could be incorporated in the script (see CoDEmanX post in the blenderartist link above) to round and cut of the rest?
Also is it ok to get the degrees right away or do you think your recalculation works better?

Values and formatting
The rotation in blender has negative value and in the ani file positive value. Is it possible to change negative and positive values to opposite when exporting?
Now to the formatting. As i state above,
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.
Is it possible to use a 8 character column and align the text in it to the right side?

Please let me know if you know some or all answers to the questions.
If not, i have to dig for them elsewhere. But i am sure not to give up until the script works :)
BR Astorian

EDIT:
@ Jorzi - I stand corrected on one thing from the above. Changing to pos = obj.location * 100000 actually gives a correct rounded position value.
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

Hi

The degrees() function does the same as my formula, but yeah, do use it, it's neater and more explanatory. Also, if you want to change the sign, just multiply by -1.

When it comes to scaling, this is tricky. What you want is to make sure your exported mesh and your exported animation use the exact same scaling. This gets even more tricky since you are also able to animate the scale. Also the default scale (one wz square = 256) is way too big to work with unless you reconfigure blender's depth buffer

When it comes to the formatting:
I'm pretty sure the parser doesn't require fixed widths on the numbers, just integers with whitespace inbetween should suffice, unless you have received more specific information from someone working with the code. (This guess is based on my experience of writing text parsers). Also, the two-tab indentation at the start of the row should be just for readability.

When it comes to number precision, remember: all the numbers have a huge load of decimals, it's just a matter of how you want to print them on screen. What I do in my code is to use the %d formatting tag which formats them as ordinary integers, simply dropping all the decimals when printing. The reason why they are scaled by 1000 and converted into integers is that the game was originally made for the playstation 1 which could only handle integers. The scaling by 1000 is simply a way to get 3 decimals of precision.

I couldn't find out why my .py file didn't work, what blender version do you use? Also, don't be afraid of the lots of extra code it has. All the stuff you're working on is inside the first function, the rest is just formalities you don't have to worry about. The only difference is I use f.write instead of print, so stuff gets written into a file instead of the console. I cut out the essential code for you if you don't get it to work otherwise

Code: Select all

    print("exporting file...")
    f = open("testfile.ani", 'w', encoding='utf-8') # filename goes here
    # start with file header
    f.write("/* header format: anim3d [filename] [frames][framerate] [num objects]            */\n")
    f.write("/* anim line: [frame] [x] [y] [z] [xrot] [yrot] [zrot][xscale] [yscale] [zscale] */\n")
    scn = bpy.context.scene
    if selectedOnly:
        objectList = bpy.context.selected_objects
    else:
        objectList = bpy.context.visible_objects
    
    numberOfFrames = scn.frame_end+1-scn.frame_start
    f.write('ANIM3DTRANS "placeholder.pie" %d %d %d\n' % (numberOfFrames, scn.render.fps, len(objectList)))
    f.write("{\n")
    
    # create the data blocks for each animated object
    objIndex = 0
    for obj in objectList:
        if obj.type == "MESH":
            f.write('ANIMOBJECT %d "%s"\n' % (objIndex, obj.name))
            objIndex += 1
            f.write("\t{\n")
            for frame in range(scn.frame_start, scn.frame_end+1):
                # use frame_set() so that keyed values are updated
                scn.frame_set(frame)
                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
                f.write("\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n" % (scn.frame_current, pos.x, pos.y, pos.z, rotx, roty, rotz, scale.x, scale.y, scale.z))
            
            f.write("\t}\n")
    
    f.write("}\n")

    f.close()
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:
MaNGusT wrote: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. :(
Send me your test case and I'll look into it.
anim_test.zip
(281.39 KiB) Downloaded 258 times
Image
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

After some serious debugging, I was able to make my script work much better.
I replaced obj.rotation, obj.location and obj.scale with obj.matrix_world.decompose().
This takes parent transformations & stuff into account so you can use all of blender's rigging tools.

One known bug is that if you select non-mesh objects when exporting it will count them into the number of pie levels and the animation will malfunction (it will not, however, create any entries for the non-mesh objects)

I made a small demo mod that turns the derrick into a steam engine just to show off the capabilities of the script.
Attachments
wz_anim_export.py
(3.75 KiB) Downloaded 216 times
steamengine.wz
(6.75 KiB) Downloaded 247 times
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 »

MaNGusT wrote:
anim_test.zip
The texture file names need a .png suffix.

What is supposed to happen?

Testing it on propulsions is perhaps the worst test case, since these are special cased in the code, and this special casing might override whatever you are doing.

Finally, there is no .ani file? And anim.cfg is not modified? Not sure how this was supposed to work.
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:
MaNGusT wrote:
The attachment anim_test.zip is no longer available
The texture file names need a .png suffix.

What is supposed to happen?

Testing it on propulsions is perhaps the worst test case, since these are special cased in the code, and this special casing might override whatever you are doing.

Finally, there is no .ani file? And anim.cfg is not modified? Not sure how this was supposed to work.
I just gave you model with 3 levels. Animation stuff I used was from oil derrick. Yeah, I created this package inaccuratelely but if you'd fix png typos, add wheels' model to cfg and fix ani file, you'd see that engine shows only 1st mesh from model file. So, no animation either.
Also, could we get a list of models that are special cased?
anim_test.zip
a fixed one
(282.63 KiB) Downloaded 244 times
Image
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 blender 2.72 on windows 8.1 and blender 2.69 on Ubuntu.
On both environments has gives the script an error:

Code: Select all

bpy.context.area.type = 'GRAPH_EDITOR'
Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\modules\bpy_extras\io_utils.py", line 76, in invoke
    self.filepath = blend_filepath + self.filename_ext
  File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\modules\bpy_types.py", line 593, in __getattribute__
    return super().__getattribute__(attr)
AttributeError: 'ExportANI' object has no attribute 'filename_ext'

location: <unknown location>:-1

bpy.ops.object.select_all(action='TOGGLE')
Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\modules\bpy_extras\io_utils.py", line 76, in invoke
    self.filepath = blend_filepath + self.filename_ext
  File "C:\Program Files\Blender Foundation\Blender\2.72\scripts\modules\bpy_types.py", line 593, in __getattribute__
    return super().__getattribute__(attr)
AttributeError: 'ExportANI' object has no attribute 'filename_ext'

location: <unknown location>:-1

Please set your User Preferences' 'Translation Branches Directory' path to a valid directory

will it help to find the cause?

I did not have time to test your custom animated model in wz2100, but i do it in the next days.
Astorian
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

My first advice is to install 2.73a, although the error report doesn't really indicate that.
I'm currently installing 2.72 to see if the syntax is somehow different...
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 »

Downloaded 2.72 and it works fine for me...
How are you running the script?
Your error log says 'ExportANI' object has no attribute 'filename_ext' but it's very clearly defined in the script
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 »

I have tested your steam engine model - its seampunky awesome :)

Now to the script. I am running it two ways. First is to paste from clipboard into the Blenders python console. The second is to install the addon in user preferences (install from file)
Astorian
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

There's a third way, you can open the text file in blender's text editor and press alt+p to run it.
Anyway, installing it as an addon should have worked...
Gotta try the script on some other computer, at least on the two computers I usually use it works just fine, although both of them use windows 7 of course...
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 »

Running the script from Blenders text editor worked like a charm :) I made only one adjustment:
pos = pos * 100000 -to get the correct values
I like the script really much. The number of object was +1 but i solved that by deleting the camera.
Thank you for the script Jorzi.
Astorian
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Custom ANIM3DTRANS animation - working.

Post by Jorzi »

The reason for the scale being off is that I like working in 1/10 scale in blender, then upscaling by 10 in WMIT before exporting :P
When it comes to scaling I think the perfect workflow is not yet achieved, but good to know you got it to work.
The bug with the number of objects could be fixed by doing another for loop over all the objects and counting only meshes, or alternatively removing all non-mesh objects from the list before writing to the file.
ImageImage
-insert deep philosophical statement here-
Post Reply