Blender Scripts for Civilization V and Civilization VI

Blender Scripts for Civilization V and Civilization VI 16.4

Deliverator

Graphical Hackificator
Joined
Feb 12, 2008
Messages
4,806
Location
London, UK
These are scripts for importing/exporting 3D graphics between Civ 5 .gr2 and Civ 6 .fgx formats and Blender (both 2.49 and 2.7+ versions).

Update History

16.4 Update

* Fixes NA2 animation import for 2.8+ (including 3.x) versions of Blender.

16.3 Update
* Re-instate correct BR2 export add on script for Blender 2.7*. Somehow the wrong one got included back in the 15.2 Update in September 2019. Sorry to anyone whose tried to use it since then and has experience difficulties!

16.2 Update
* .na2 format Animation import script for Blender 2.8, updated from 2.7 version by Sukritact.
* .na2 format is now referred to as "Civilization Animation" in all scripts given that the format may be used to extract animations from both Civ V and Civ VI.

16.1 Update
* Optimized load time for .na2 Animation import script in Blender 2.7*.

16.0 Update
* Animation import to 2.7* versions of Blender now working via the .na2 format. Actually the fix was a simple change to NB2 and CN6 import scripts. Many thanks to Magarto for finding this!

This means animations from Civ V, Civ VI and Beyond Earth can loaded directly into Blender 2.7* versions for the first time.

Will need to re-install and re-enable NB2/CN6 Import Addons for this to work.

15.2 Update
* BR2 Export: Use original normals, binormals and tangents for meshes imported from .cn6 format.

15.1 Update
* Ignore mesh modifiers that point to missing parent armatures in BR2 and CN6 export (Blender 2.7 and 2.8).

15.0 Update
* First version of .cn6 import/export scripts for Blender version 2.8, thanks to @sukritact.

14.6 Update
* Don't create VERTEX_KEYS with original Normals, Tangents and Binormals if they are all identical e.g. Nexus Buddy 2 exported .cn6.

14.5 Update
* CN6 Export: Don't use original normals if VERTEX_KEYS Vertex Group is deleted. This will now properly recalculate Binormals and Tangents when you export having deleted the VERTEX_KEYS Vertex Group.

14.4 Update
* Fixed serious bug where .cn6 import was not dividing weights by 255 but was instead using the raw values. This meant that all vertex weights greater than zero would be equal to 1 when imported rather than properly scaled within the 0-1 range. This fix should mean that you can remove/add to animated meshes such as units and vertex weights will be properly preserved during the .fgx -> .cn6 -> Blender -> .cn6 -> .fgx round trip.

TL;DR - Vertex Weights were being mangled - now they are OK. :)

14.3 Update
* Blender 2.7 CN6 Import: Bone names containing spaces can now be imported.
* Blender 2.7 CN6 Export: Incorporate Sukritact's fix for vertex bone weights not totalling 255.

14.2 Update
* CN6 Export: Now exports one vertex for each vertex/UV coordinate combination in a similar way to the BR2 export script.

14.1 Update
Changes to CN6 Export Script
* Default data for 2nd and 3rd UV Map so you don't have to create them manually.
* Added better exception handling.

14.0 Version
* Add .cn6 import/export scripts for working with CivNexus6. Read more here.

13.1 Version

* NB2 Import: Update all MAX_* values to allow complex models with 1000+ bones and many many vertices and triangles (e.g. Civ 6 Leaders) to be correctly imported to Blender.

* BR2 Export: Only export single World Bone if there is only one bone and it has the same name as the Armature. This will be case if the original .nb2 only had one bone. This is useful for correctly exporting anything that has just a single bone (e.g. Civ 6 unit weapons and helmets).

13.0 Version

1. With both Blender 2.7+ and Blender 2.49 scripts it is possible to extract from .gr2 into Blender (via .nb2 format) and back into .gr2 from Blender (via .br2 format) without needing to use the FBX format at all. You can use the "Open BR2" function in Nexus Buddy 2.3.3 and all mesh and skeleton information should be preserved. You should only need to export to FBX if you are editing animations - even editing skeletons now works via .br2.

2. Mesh object names are now suffixed with "#M" to ensure that they have a different name to Armature objects. This was causing vertex groups to be deleted when importing objects using only a single bone which is most of the Resources, Improvements, Wonders, etc. Editing or replacing static 3D assets ought to be a lot more straightforward with this fix. I can simply import the mesh to Blender via .nb2 and then use BR2 overwrite to put my updated/replacement mesh back into the Wonder/Improvement/whatever .gr2 file.


Deliverator Blender Scripts for Blender 2.49 - Version 12

* NB2 Import: Bones other than the root bone that had no parent bones (e.g. weapons bones) ere not being imported with 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.


Deliverator Blender Scripts for Blender 2.49 - Version 11

* NA2 Import: All new animation import script

* NB2 Import: Removed incorrect 90 degree bone roll to make FBX exported animations work with vanilla units. Removed menu options as they are no longer needed.

* FBX Export: Default Rotate Y-90 to off as it is made redundant with recent changes to Nexus Buddy 2 (version 2.3.2).


Blender 2.7x - Version 3/Blender 2.49 - Version 10

* BR2 Export: Allow rigging to the root bone by assigning vertices to a vertex group that has the same name as the armature object. Useful for ships etc where the many part of the vessel is rigging to the root bone.

* NB2 Import: Ignore bogus triangles that refer to vertex index numbers that do not exist in the mesh.


Deliverator Blender Scripts V9

+ BR2 Export: Fix for issue where vertex bone weights were not adding up to 255 causing stray vectors to appear in game - see here and here.


Deliverator Blender Scripts - Version 8

+ Added an option to FBX export to rotate the animation of the root bone 'backwards' by 90 degrees so that it appears upright in Granny's Y-axis up coordinate system.

+ ".fbx" now gets automatically append to the filename by the FBX export script if not already present.





NB2 Import Script

This is an import script for the NB2 format files that have been exported from Nexus Buddy 2. Using this script it is possible to getting the vast majority of 3D game assets including Units, Leaders, Wonders into Blender with both mesh and skeleton data so that they can be altered or used as a template for new graphics.

BR2 Export Script

This exports from Blender into a new simple format that is designed to make import into GR2 as straight-forward as possible. Nexus Buddy 2 take just the meshes from the BR2 to overwrite those in an existing GR2 file.

Overwrite from BR2 in Nexus Buddy 2 is the reliable way to get meshes from Blender into a GR2. For custom animations or those ported from Civ IV, it is better to use FBX import for skeleton and animations and then use Overwrite from BR2 for the meshes.

Copy/Paste Object Script

This allows meshes and armatures (skeletons) to be copied between instances of Blender 2.49. You must save you file as a .blend before performing a copy/paste. Credit: Mariano Hidalgo.

Credits: Campbell Barton, Markus Ilmola, Mariano Hidalgo, Sukritact.
 
Last edited:
Does this work with Blender 2.6+? If no, any chance for an update?

Blender completely re-wrote the python API after 2.49 for later versions. Updating the scripts to work with the newer API would be a lot of work and I don't think I'll ever take the job on myself.

You can always use Blender 2.49 to import, save a .blend file and then open in Blender 2.6+ and do your work in the later versions. If you then re-save your .blend which you can re-open in the older version and export. I haven't tested this much but it seems to be work OK.
 
You can always use Blender 2.49 to import, save a .blend file and then open in Blender 2.6+ and do your work in the later versions. If you then re-save your .blend which you can re-open in the older version and export. I haven't tested this much but it seems to be work OK.

I think back when we were messing with smd I did it a few times and seemed to have no issues/ The biggest thing later blender gives us is the armature naming as far as I can tell. The interface with 2.6+ is a learning curve if you are used to 2.49
 
I think back when we were messing with smd I did it a few times and seemed to have no issues/ The biggest thing later blender gives us is the armature naming as far as I can tell. The interface with 2.6+ is a learning curve if you are used to 2.49

I found that I could configure 2.6+ to work in the same way as 2.49. It was mostly just tweaking some of the global options for the 3D view such as Trackball/Turntable rotation.

http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Navigating/3D_View

After that 2.6+ was quite a bit nicer to work with.
 
Should I suppose there will be an update of your scripts working in Blender 2.6.X ??? :eek:

Just ... extraordinary GREAT !
 
something isnt rigged. If you have blender issues, I recommend posting the blend files so we can try and duplicate the error
I know which mesh is the problem, but I don't see anything that is "not rigged". All parts of the mesh seem to have been defined proper bone weight, and when I move the bones all the proper parts move too. Unless that's not what you mean?
 
sometimes you can miss just one vertices. Did you go through each bone/vertex group and press 'select' and see it light up until all vertex groups have been selected? thats how I find if something is missing.

the other issue is if it is parented right. Are you using the outliner window to see if its coming under the armature?
 
*Facepalm* I don't know why I said it was rigged fine, because it obviously wasn't as I looked a little deeper.

That was precisely the issue, thank you.
 
Don't know where this question should go to, but:

Do you guys know what causes the problem of a bone from the unit/leader to be twisted when importing to blender? This commonly happens, I import an unit and the part connecting the head and shoulders is twisted. Also I recently imported a leader and his head was all twisted too.
 
What are you clicking for import options? deleting the top bone and rotating 90? I'd mess with those settings and see.

But rotating the bone shouldn't matter. you export your br2 then use that br2 to overwrite a copy of the base gr2. I had to do that with parkes because it was unrigging some parts of the animation for some reason.
 
Don't know where this question should go to, but:

Do you guys know what causes the problem of a bone from the unit/leader to be twisted when importing to blender? This commonly happens, I import an unit and the part connecting the head and shoulders is twisted. Also I recently imported a leader and his head was all twisted too.

Yeah, this happens with some units and leaders, such as the Spearman unit.

As far as I can tell it is to do with the mathematics involved in representing bones rotation and direction. In the Granny format these are represented using quaternions, but to import these into Blender these quaternion rotations need to be convert into matrix rotations. Unfortunately, matrix is not as robust way of representing rotations in 3D dimensions due to the phenomenon of gimbal lock. What I assume is happening is that this lack of robustness in the conversion from quaternions is resulting in the wrong bone angle matrix being calculated in some cases. The best solution would be import the bone rotations as quaternions, but the 2.49 version of Blender doesn't support this. Potentially the newer version of Blender might support this, but that would require updating the import and export scripts to the newer Blender API, and as I've said elsewhere this is not likely to be a job I take on myself.

That might be more information that you wanted, but that's what I believe is causing the issue.

Often I've found it is not too difficult to rotate part of the skeleton to match the mesh in Blender seeing as it is usually only a single bone that has incorrect rotation. To make the Spearman template in the Ancient units template I just rotated the part of the skeleton that was incorrectly rotated into correct position by hand. Not ideal I know, but it's one of those things. A little over a year ago we had no way to extract mesh and skeletons for Civ 5 models so things have already come a long way!
 
Last edited:
Often I've found it is not too difficult to rotate part of the skeleton to match the mesh in Blender seeing as it is usually only a single bone that has incorrect rotation. To make the Spearman template in the Ancient units template I just rotated the part of the skeleton that was incorrectly rotated into correct position by hand. Not ideal I know, but it's one of those things. A little over a year ago we had no way to extract mesh and skeletons for Civ 5 models so things have already come a long way!
I did the same thing when I worked with my own spearman model change. The problem is when it comes to leaders - they have an INSANE amount of bones, some which I don't even know why are there (probably helpers that made more sense in the original .max files, but here are just on the way). So it's harder to find and correctly move the bone that causes the problem. Not to mention you have to select all the different meshes associated to it and disable skin distortion which by itself is already annoying.

Thanks for the explanation by the way.
 
I did the same thing when I worked with my own spearman model change. The problem is when it comes to leaders - they have an INSANE amount of bones, some which I don't even know why are there (probably helpers that made more sense in the original .max files, but here are just on the way). So it's harder to find and correctly move the bone that causes the problem. Not to mention you have to select all the different meshes associated to it and disable skin distortion which by itself is already annoying.

Thanks for the explanation by the way.

Is that on attila? I haven't seen too many rotated ones.
 
I'm currently trying to use the script to import some NB2 files, but I'm having difficulties.

I've installed the latest 64 bit version of Blender on my system (Windows 7).

Though, it didn't seem to create a folder within:
*\Users\[username]\AppData\Roaming\

I tried placing the scripts in Blender's script folder here:
*\Program Files\Blender Foundation\Blender\2.71\scripts

And still no luck, it seems.

Perhaps I'm not looking in the correct place within the interface to find the scripts? After searching throughout the interface, I went to Google, and supposedly there should be a "Scripts" option when you select "Objects" near the bottom-left of the screen. Though, I don't see it.

EDIT: Also, I went to the Help menu and generated a system-info.txt file within Blender. I then used the Scripting screen layout to open the text file and it shows the correct directory for user scripts. Though, like I said earlier, I don't see it when I go there.
 
Top Bottom