Extract GR2 Animations into Blender and Re-Import to Civ V/Civ BE

Deliverator

Graphical Hackificator
Joined
Feb 12, 2008
Messages
4,806
Location
London, UK
With Nexus Buddy 2 it is now possible to extract animations into Blender for the first time. This tutorial briefly describes the process for getting animations into Blender so that they can be edited before converting them back to the Civ V .gr2 format.

What You Will Need
Nexus Buddy 2
Blender 2.49b or Blender 2.79b
Civ V Blender Scripts


Tutorial One - Extract Animation to Blender

First we'll walk through the simple case when everything works fine.

1. Open you model in Nexus Buddy 2.3.2 or above. This can a unit or a leader or anything else that has separate .gr2 animation files. For example, open u_greek_hoplite.gr2.

2. Press Export Animation to NA2 and select the animation you want to export. For example, u_greek_hoplite_attacka.gr2.

3. All being well a file should be created in the same directory as the animation called u_greek_hoplite_attacka__0.000-1.000.na2.

4. Also export the model to NB2 format by pressing Export to NB2 (There is only one model for a unit so it doesn't matter which of the two buttons you use All Models/Current Model).

5. In Blender first import the NB2 model, for example u_greek_hoplite.nb2.

6. Now import the NA2 model using the script, for example u_greek_hoplite_attacka__0.000-1.000.na2.

7. Now switch to an animation view that has the Timeline window open, and right click the skeleton of the model. You should see all the animation keyframes have been imported and you can play the animation.

8. You are now able to edit the animation before exporting it to FBX for use in the game.

Here's a video that demonstrates step 5 onwards:


Other example showing the victory animation:



Tips

Tip One: Scrambled Skeleton Workaround

When using the Blender 2.49 NB2 import script some skeletons get scrambled due to incorrect bone rotations. The Blender 2.7 NB2 script doesn't have this issue. So the workaround for units that end up with a scrambled skeleton (e.g. Spearman, Landsknecht) is to:
1) Import the .nb2 file into Blender 2.7 using the Import NB2 Addon script.
2) Save the .blend file with Legacy Mesh Format checked.
3) Open the .blend file in Blender 2.49, dismissing the warning message.
4) Resave the .blend file.
5) Now you can import the NA2 animation and everything should work fine. :)

I've tried and failed to convert the NA2 scripts to Blender 2.7. If you want to attempt to fix my effort my best effort Addon script is here. It imports the animation data successfully but the bone rotations are not correct somehow.

So if you want to work on custom skeletons and animations you'll have to use "Old Faithful" Blender 2.49 (unless someone fixes the code above).

Resources

This classic Tutorial from the Coyote is a good introduction to bespoke animation with Blender; the Nifskope stuff isn't relevant to Civ 5 but much of the rest is:
http://forums.civfanatics.com/downloads.php?do=file&id=10989

Some cool applications of this capability in this thread: Animation Tweaks of Existing CiV Units.

The Parameters

NA2 Start Time/NA2 End Time - This default to the start and end of the GR2 animations but you can specify the time window if you wish.

If NA2 End Time is set to a value greater than the length of the animation then the whole animation will be extracted but nothing more. In code terms if NA2 End Time > Animation Length then NA2 End Time = Animation Length.

FPS: Frames per Second. This controls the frequency with which frames are sampled. The default of 60 might be overkill for some applications, Civ 4 only used 30 FPS. The lower the FPS the small the amount of keyframes and data there will be in the resulting NA2 file for the same timeframe.

Some Technical Background

The animation extract feature in Nexus Buddy uses a function called Sample Bone that is exposed in the Firaxis Granny library. This function does not seem to handle memory well on repeat usage from what I can tell. It seems that after calling this function a certain number of times it will start trying to accessing memory blocks that it is not allowed to. I have handled this by catching the memory access violation and retrying. The program will try a maximum of five times to get an exception free extraction. In almost all cases this solution appears to work.


Anyway that's it for now. I will try and add more on editing animations and re-importing to .gr2 later.
 
Last edited:
Great job Deliverator, a much welcome addition.:)

I have given it a try however and cannot get past step 3 no matter what I put as the NA2 end time or what unit I choose. I even tried the u_greek_hoplite_attacka.gr2 like in the tut and no good. I always get NexusBuddy2.3 has stopped working.

I have just recently downgraded to windows 10 and feel this may have something to do with it.
 
I always get NexusBuddy2.3 has stopped working.

I have just recently downgraded to windows 10 and feel this may have something to do with it.

Mmmmm. I'm running Windows 10 so I don't think it's that. Are you running NB2 from it's own directory? In other word are you just unzipping the zip file and running the program from there?

Does it fail even you set the start and end times both to 0?
 
Mmmmm. I'm running Windows 10 so I don't think it's that. Are you running NB2 from it's own directory? In other word are you just unzipping the zip file and running the program from there?

Does it fail even you set the start and end times both to 0?

Yeah I have just unzipped it and it is running from its own folder. The normal stuff still works. I tried setting both start and end times to 0 and still stopped working.
 
Ok Wolfdog try this updated version.

I've added some code that catches the access violation exceptions and retries if it fails. See if it works for you.
 
Thanks Deliverator, works fine now. Retry count was 2 so that seems to have done the trick.:)

Great! I'll release this 2.3.1 version soon and update the tutorial above.

It actually simplifies matters quite a bit as you not longer need to export two separate files and combine them as a workaround, and there is no restarting of NB2 required. Also I have made the start and end time default to 0 and the animation length respectively so you shouldn't need to set them manually.

I have found one animation in the Hoplite set that won't export successfully even with the retries in place, u_greek_hoplite_fortify_fidget.gr2, but everything else seems to work.
 
Deliverator, 2.3.1 seems to work well for me, but I am having problems creating animations from Blender. Following the tutorial, I am creating a base .nb2 from the CiV .gr2 (in this case, Scout.gr2) and exporting the animation to .na2. In Blender, I import the Scout.nb2, then the animation .na2 file and everything appears beautifully. Without changing anything, I export it to .fbx and create an animation .gr2 from it with NexusBuddy. When I open the original Scout.gr2 in Granny and insert my exported .gr2 animation, however, I get this:



The animation is deformed, even though I have made no changes between the import and the export. When importing the .nb2 I have "Delete Top Bone" enabled and "Rotate Meshes 90 degrees" disabled. When exporting, the "Rotate Y -90" animation fix is disabled. For the record, I have tried every combination using the rotation and top bone selections just to be sure, but nothing appears to work. The only thing that does work is if I create a new Scout.gr2 by importing the .nb2 then exporting as an .fbx with .br2 overwrite. Then, the animations I export will work with the newly-created base model. Unfortunately, it means that the original CiV Scout animations won't. Any ideas?

BTW, if that can be figured out I have a nice little preview of creating a spellcasting animation from the base Scout animations:



I would just hate to have to create 45 new animations just to tweak this one! :lol:
 

Attachments

  • Scoutanim.jpg
    Scoutanim.jpg
    121.3 KB · Views: 4,882
  • Spellanim.jpg
    Spellanim.jpg
    15.4 KB · Views: 4,906
The animation is deformed, even though I have made no changes between the import and the export.

The good news is that as "deformed" goes it is not far off. If you switch between the vanilla animation .gr2 and the one that has been extracted and re-imported via Blender you can seen that the bone points are positioned correctly but the rotation of each of them is out by 90 degrees - hence head/feet/etc twisted 90 degrees. It should be possible to update the FBX export script to optionally correct for this - I'll look into it when I have chance.
 
The good news is that as "deformed" goes it is not far off. If you switch between the vanilla animation .gr2 and the one that has been extracted and re-imported via Blender you can seen that the bone points are positioned correctly but the rotation of each of them is out by 90 degrees - hence head/feet/etc twisted 90 degrees. It should be possible to update the FBX export script to optionally correct for this - I'll look into it when I have chance.

Great, thanks! I still have plenty of other work to keep me busy in the interim.... :cool:
 
Great, thanks! I still have plenty of other work to keep me busy in the interim.... :cool:

The good news is that I've cracked it! The issue was that my NB2 import script was adding an unnecessary 90 degree bone roll to every bone. I've removed that and altered the NA2 import to string to match the same rotation. Now the whole round trip works; I can edit vanilla animations in Blender, export via FBX and they work with unedited vanilla units. :)

The minor bad news is that I think you'll need to recreate your spellcasting animation from NB2/NA2 files re-imported via the new scripts as fixing them up is probably too hard.

I've also figured out the proper way to correct for the different coordinate systems between Blender and CiV GR2 (Blender uses Z-axis-up, GR2 uses Y-axis-up). There is a setting in the vanilla GR2s under the Art Tool info that I haven't played with before that is a matrix for the coordinate system that was used to create the model. Effectively this specifies how the coordinate system of the source Art Tool differs from the native GR2 Y-axis-up. I noticed this was being set differently when importing an entire new model from FBX (or BR2) so I changed it in the Nexus Buddy 2 code to be the same as for the vanilla units. The upshot of this is that models that appear upright in Blender (with Z-axis up) now appear upright in .GR2 (with Y-axis up) which renders the previous attempted workarounds for this redundant.

It also seems that full BR2 > GR2 conversion now works including skeleton data, if anyone wants to use that instead of FBX followed by BR2 overwrite. So whole models imported from BR2 now work correctly with vanilla animations.

I'll upload new a Nexus Buddy version 2.3.2 and the new scripts in the next 24 hours. Thanks for your testing efforts Nomad!
 
The good news is that I've cracked it! The issue was that my NB2 import script was adding an unnecessary 90 degree bone roll to every bone. I've removed that and altered the NA2 import to string to match the same rotation. Now the whole round trip works; I can edit vanilla animations in Blender, export via FBX and they work with unedited vanilla units. :)

The minor bad news is that I think you'll need to recreate your spellcasting animation from NB2/NA2 files re-imported via the new scripts as fixing them up is probably too hard.

I've also figured out the proper way to correct for the different coordinate systems between Blender and CiV GR2 (Blender uses Z-axis-up, GR2 uses Y-axis-up). There is a setting in the vanilla GR2s under the Art Tool info that I haven't played with before that is a matrix for the coordinate system that was used to create the model. Effectively this specifies how the coordinate system of the source Art Tool differs from the native GR2 Y-axis-up. I noticed this was being set differently when importing an entire new model from FBX (or BR2) so I changed it in the Nexus Buddy 2 code to be the same as for the vanilla units. The upshot of this is that models that appear upright in Blender (with Z-axis up) now appear upright in .GR2 (with Y-axis up) which renders the previous attempted workarounds for this redundant.

It also seems that full BR2 > GR2 conversion now works including skeleton data, if anyone wants to use that instead of FBX followed by BR2 overwrite. So whole models imported from BR2 now work correctly with vanilla animations.

I'll upload new a Nexus Buddy version 2.3.2 and the new scripts in the next 24 hours. Thanks for your testing efforts Nomad!

WOW...just...WOW!!! :wow: Thanks a million for this colossal breakthrough of the entire conversion process! :goodjob: :thumbsup: :clap: :bowdown: :worship: :hatsoff: :wow: :rockon: :band: :dance: :beer: :thanx: :trophy: :w00t: :woohoo:
 
I think you missed a smiley... ;)
 
Shamelessly plugging a new thread to demonstrate the full capabilities of this amazing breakthrough with animations. Here is an example of the "spellcasting" Scout animation in action:


I would love to hear the ideas of others! Please kindly visit the thread here if you are so inclined.

And once again, thank you Deliverator! :) (I used up all of the other emoticons in my previous post....)
 
Cooool! :goodjob:

Out of interest are you make use of the new scaling bone feature in Nexus Buddy 2 yet?

I've added this tip for working around the scrambled skeleton issue to the OP:

When using the Blender 2.49 NB2 import script some skeletons get scrambled due to incorrect bone rotations. The Blender 2.7 NB2 script doesn't have this issue. So the workaround for units that end up with a scrambled skeleton (e.g. Spearman, Landsknecht) is to:
1) Import the .nb2 file into Blender 2.7 using the Import NB2 Addon script.
2) Save the .blend file with Legacy Mesh Format checked.
3) Open the .blend file in Blender 2.49, dismissing the warning message.
4) Resave the .blend file.
5) Now you can import the NA2 animation and everything should work fine. :)

I'm not planning to convert the NA2 script to Blender 2.7 as the FBX export script doesn't play nicely with the Nexus Buddy 2 FBX import code. So if you want to work on custom skeletons and animations you'll have to use "Old Faithful" Blender 2.49.
 
Cooool! :goodjob:

Out of interest are you make use of the new scaling bone feature in Nexus Buddy 2 yet?

I've added this tip for working around the scrambled skeleton issue to the OP:

When using the Blender 2.49 NB2 import script some skeletons get scrambled due to incorrect bone rotations. The Blender 2.7 NB2 script doesn't have this issue. So the workaround for units that end up with a scrambled skeleton (e.g. Spearman, Landsknecht) is to:
1) Import the .nb2 file into Blender 2.7 using the Import NB2 Addon script.
2) Save the .blend file with Legacy Mesh Format checked.
3) Open the .blend file in Blender 2.49, dismissing the warning message.
4) Resave the .blend file.
5) Now you can import the NA2 animation and everything should work fine. :)

I'm not planning to convert the NA2 script to Blender 2.7 as the FBX export script doesn't play nicely with the Nexus Buddy 2 FBX import code. So if you want to work on custom skeletons and animations you'll have to use "Old Faithful" Blender 2.49.

Thanks for that info; "Old Faithful" works for me and I still use it about 99% of the time. I normally only use 2.7 for importing from various formats, pretty much like what you describe above.

I haven't had the opportunity to use the scaling bone, but I do intend to do so very soon with the existing Naga unit as well as any others that I previously created with this issue. That sure beats having to re-size every animation over again! I have used the .ftsxml sorter, though, and it is awesome!
 
I have released new versions of the NB2/NA2 scripts to fix and improve working with vanilla animations:

https://forums.civfanatics.com/threads/deliverators-blender-scripts.497821/

* NB2 Import: Bones other than the root bone that had no parent bones (e.g. weapons bones) were not being imported with the correct rotation. This meant that weapons (for example) were not always in the correct rotation for models and animations based on NB2/NA2 imports to Blender. This issue is now fixed - the NB2 script now imports unparented bones in the correct rotation.

* NA2 Import: The animation keyframes will now be imported starting from the currently selected keyframe. If keyframe 1 is selected then there is no change in behaviour. This is useful if you want to use poses from multiple animations - for example, if you want to create smooth transitions from one animation to another.
 
Last edited:
Hi Delivator,
I have
-NexusBuddy 2.3.3
-Blender 2.49 with latest nexus scripts
-Net Framework 4.0

When I try to export animation to NA2 i have next mesage on nexus:

Models: 1 Current Model: Tube04(Index:0)
Meches (Current Model): 2 Meches(Total):2
Materials: 2
Shader Types Used: (1) UiShader
ANIMATION EXPORT FAILED! Retry Count: 5

Help me please
 
Top Bottom