IWTE - Units in Blender/Milkshape
Contents
Tips and instructions for working with RTW and M2TW battle map units and strat map characters via IWTE and Blender using the .dae format - December 2020 version onwards.
The .dae files used for the Collada import/export can also be used with 3ds Max, however, max users absolutely have to use the OpenCollada plugin and file format when importing/exporting files, max comes with the AutodeskCollada file format by default which neither imports nor exports files from the game correctly.
- For queries about these functions please ask here.
- For information on working on M2TW Settlements in Blender see IWTE - Settlements in Blender
- For general tips on working with Blender see Blender hints and tips
Export and Import M2TW .mesh Units
The most useful method of export involves matching the unit .mesh with its skeleton basepose and one or more animations.
The drop-down menu in IWTE allows a unit .mesh to be merged with its basepose skeleton and one animation. A task file is needed to allow combining of animations and is the only way to also incorporate weapon animations.
The drop-down menu button location is shown below:
Select the double mesh option for unit meshes that have both a main and attachment texture. Select the single mesh option for most other cases (e.g. standard mounts). You will be prompted to select the model .mesh first, then the basepose.cas for the skeleton, and then optionally any number of animation.cas files that are compatible with that skeleton. Press cancel when you have loaded all the animations you want to view in the one file.
Export/Import by Task Process
To generate a .dae file from .mesh and .anims via the task process you will need a text file ending in _task.txt which starts with the mesh to dae command. See example below:
<task_id> mesh_to_dae <mesh_file_full_path_in> C:\M2TW\mods\devkit\data\animations\EB_Slinger\numidian_slinger_lod0.mesh <mesh_double_texture> yes <cas_file_types_in_list> body weapon <cas_file_full_path_in_default_list> C:\M2TW\mods\devkit\data\animations\EB_Slinger\EB_Slinger_basepose.cas C:\M2TW\mods\devkit\data\animations\EB_Slinger\Weapon\w_EB_Slinger_default.cas <cas_file_full_path_in_action_list> C:\M2TW\mods\devkit\data\animations\EB_Slinger\EB_Slinger_stand_A_idle.cas C:\M2TW\mods\devkit\data\animations\EB_Slinger\Weapon\w_EB_Slinger_default.cas C:\M2TW\mods\devkit\data\animations\EB_Slinger\EB_Slinger_attack_missile_ready.cas C:\M2TW\mods\devkit\data\animations\EB_Slinger\Weapon\w_EB_Slinger_attack_missile_ready.cas <directory_out> C:\M2TW\mods\devkit\data\animations\EB_Slinger <dae_file_name_out> EBslingerAnims.dae <create_text_file> yes
Please see the IWTE example control processes.txt file that ships with IWTE for further details/instructions. (the code is hard to display well on wiki!)
Running the task will generate you a .dae file with the animations joined together with an additional 'basepose' frame added at frame 0, to aid editing. The task will also auto-generate for a reverse dae_to_mesh_****_task.txt file for you, this will list the start and end frame positions of all included animations and the names of all the files that will be re-created from the .dae. The names and frame positions can be edited to suit any changes you may require before running the return task.
When creating the task files it is common to make minor errors in the file names/paths that mean IWTE cannot find all the elements! If you get an error message whilst running the task you'll get a chance to read the error message (which is easier in the command window) - you can then click "Ignore" to keep IWTE open, fix the name/path/file issue in the .txt file and try running the task again. The error message should indicate which file it couldn't find. If you forget to add the file extension and try and get it to open a folder you'll get an 'access violation' type message.
For unit models that do not have any elements weighted to the 'weapon bones' you only need to run the process with
<cas_file_types_in_list> body
and supply the main skeleton basepose and animation.
If the mesh has a weapon weighted to weapon bones use the body weapon example shown above.
If the mesh has both a weapon weighted to weapon bones and a shield weighted to bone_shield etc use
<cas_file_types_in_list> body weapon shield
and supply the main skeleton, weapon animation and shield animation baseposes and animations in sets of three in order.
Note: a lot of models that are apparently using fs_test_shield according to their battle_models.modeldb entry don't actually have anything weighted to bone_shield, making the shield 'anim' irrelevant.
UV Mapping for Double Texture Units
The mesh format for both double and singled textured units in M2TW is actually exactly the same with just one set of uv's that should range from 0 to 1.0 in both horizontal and vertical axis.
If you assign two textures to a unit in the battle_models.modeldb then the game expands out the horizontal axis of the uv maps so that the area from 0 to 0.5 is used to cover 0 to 1 on the first texture, and the uv's from 0.5 to 1.0 on the horizontal axis are used to cover 0 to 1 on the second texture.
Milkshape/.mesh converters use the texture (Main or Attachment) assigned to a mesh group to determine which section of the uv map the group's uv coordinates will be moved to, with Main texture co-ordinates compressed into the 0>0.5 area and Attachment texture co-ordinates compressed into the 0.75>1.0 section.
The IWTE mesh to .dae for Blender process works differently. The texture assignment process is used purely so you can view the mesh groups with the correct relevant texture. The 0>1.0 horizontal uvs are expanded to 0>2.0 if you use the process for 'double textures' and then compressed back to 0>1.0 on the return to .mesh.
In Blender the uv mapping to the two textures will look like the image below.
To see the 2nd texture under its uv's open the sidebar (n) in the uv screen and select the 'repeat texture' button. In Blender it is possible to partially assign some triangles from a group to the 1st texture and some triangles to the 2nd texture, if you do that please remember to also move the uv's to the appropriate zone.
Export and Import .cas Units/Characters
The process for this is similar to the .mesh Export/Import process described above, the button locations are shown in the below image:
The first file requested will be the .cas 'mesh', e.g. the one with the body model in it. The second file requested will be an animation file, if you do not have a suitable animation file just click 'Cancel' to close the selection screen. Use the 'Animated cas/dae' button for all unit/character .cas files even if you aren't going to load an animation.
This will have generated a .dae file in a /to_dae sub-folder of the folder your .cas model was in. You will also have two task files generated in the /iwte_tasks folder of the folder where your IWTE.exe is located. The dae_to_cas one provides a default task file for reversing the process and generating a new .cas file. The cas_to_dae one allows you to repeat the process you just did by simply running the IWTE Task.
Creating a simple Multi-weighted Section
NOTE: This will not allow you to import a typical M2TW unit with complex weighting directly into RTW!
NOTE2: This only works properly in-game if the MODEL is scaled 1.0, strat models that are normally scaled down x0.7 need to be reduced in size so they can be used at 1.0 scale.
Contrary to popular belief .cas files allow a limited amount of vertexes to be assigned with weighting to two bones per vertex, for more details about the limitation see the Cas Models page.
The limit of 100 vertexes in a multi-weighted .cas section appears to be a hard coded limit, IWTE will currently try and split any such group into separate sections. It is highly recommended that you only attempt to have a few multi-weighted vertexes, such as having a ring of 50/50 weighted vertexes at the Upperarm/Torso junction to smooth out shoulder movement. Cas files with multi-weighting must use the model_flexi_m setting to work in-game. They should work in-game for RTW unit models and for M2TW strat models, however, the .cas models created with this are unlikely to convert/load successfully with any tool other than IWTE currently. Other existing tools do not export the multi-weighted sections from vanilla models.
As an example of how you could easily add some transitional weighting to an RTW unit model, you could add or re-weight verts between the area assigned to the pelvis and the area assigned to the abs bones. If there is already a wide gap in this area you could add more verts, as you want as few verts that need the multi-weighting as possible, first convert the mesh in that area from tri's to quads:
If you then 'Bisect' this area or otherwise split the edges and then re-triangulate and view in 'Weight Paint' mode, you will see that Blender has assigned the new verts proportionately between the abs and pelvis:
The triangles between the two arrows, the ring of verts attached wholly to the Abs bone, and the ring of verts attached wholly to the Pelvis bone will have to be included in a separate 'type 3' section within the .cas file. IWTE will do this for you. DO NOT attempt to split the area into a separate group yourself, this will only result in unnecessary seams and additional 'named' groups which cause other problems with the game limits. Also please see the section on limitation for this, the shared verts must only be between direct parent/child bones so, Pelvis/Abs works, Pelvis/Torso will not work.
Supported .cas animation types
Currently, the tool only supports the uncompressed (never packed) versions of .cas files, not the ones that have been generated from Pack files by IDX or similar decompression and splitting tools.
RTW .cas unit models can (for viewing purposes) use the M2TW strat model animations which were released in non-packed format by Caliban, see here. IWTE generates animations in the same format as the above non-packed files, these are suitable for re-packing via M2TW's automated process, they are not suitable for re-packing via RTW tools.
In Blender you can make any alteration you like to the 'Pose Mode' this will only affect the animation frames. Do NOT, unless you know what you are doing... move or edit the bones in the 'Armature' edit mode, this will affect the bone positions in the model.cas produced.
Siege Engine Skeleton Alteration Example Process
- In top menu bar go to Model Files > Siege Engine mesh to dae > select mesh, then default cas then anim cas.
- Check that the default .cas is actually the one listed as anim-default in descr_engine_skeleton.txt
- also check that you're using an anim that is in use in game - some of the anims in the folder don't work.
- IWTE will have written a .dae file in "to_dae" sub-folder below your .mesh model location.
- Load in Blender by using 'file' 'import' 'collada'
- Add bones as required to the Armature - note there should only be one top level bone, e.g bone_body add all other bones as child of this, or of existing bones.
- Use 'weight paint' to assign vertices to bones as required.
- Note - the .mesh file will only accept vertexes weighted to a max of 2 bones
- use 'limit total' in 'weights' menu and set to 2 to avoid any verts weighted to 3 or more bones - (this is applied to selected verts only)
- use 'normalise all' to make sure verts are fully weighted, use 'auto normalise' option whilst working also
- change animation by switching to 'animation' layout in top bar
- trigger Pose mode by clicking pose running man symbol within the Armature
- if you can't see bones, or the summary when you click them, in main sidebar click the pose (running man) button, select "viewport display" and select the "in front" option
- when you move a bone in the pose mode use shortcut "i" in main window to open keyframe dialogue and select "LocRot"
- you can delete copy or move keyframes around for selected bones in the Dope Sheet section
- Export collada - in settings check Anim is on Matrix option and 'keep keyframes' and 'all keyed curves' are selected
Temporary Note for IWTE version B:
!!!!!!!DO NOT USE IWTE Model Files > Siege Engine dae to mesh to go back.... the dae doesn't include enough info to get the mesh textures back properly!!!!!!!!
USE the "dae_to_mesh_*****_task.txt" that IWTE has written into the "IWTE_Tasks" sub-folder where your IWTE.exe is
- change the .dae name you're reading in to the one you've just saved - change any other output names IF you need to
- check the number of frames listed ties up with the end frame you set in collada - for version B of IWTE you need to add the line.
- <mesh_compressed> no
- below the mesh section. The need to do this will be fixed in version C.
- Run the task file from the IWTE Task button in top menu bar, the separate files will be saved where specified in the task file.
- If you have changed the number of bones used or their positions you will need to align all the other .cas anims used by the mesh, to do this use the skeleton replacement process explained below.
Skeleton Replacement
To replace the skeleton in a batch of .cas animations in IWTE top menu bar go to:
- Model Files > Cas Models > Skeleton Replacement
On the first prompt select the .cas file containing the bones in the basepose positions you want (probably the default or basepose .cas)
On the second prompt select the FOLDER that contains all the .cas files you want to change.
The revised files will be saved in a sub folder of that folder called "updateskeletons" they will have the same names as the original .cas files and can be used to directly replace them. Please back-up your original files before doing this, and remember that other .cas/.mesh models may be using the same files, so you may need to create a separate folder and separate entry in descr_skeleton.txt etc.
Adding bones should be straightforward, if you delete bones that had child bones then the result may be unpredictable and the resulting animations may need editing.
Bone Renaming Task
To rename the bones throughout a folder of full .cas animations use a task file. If you want to swap the names of bones you need to add an additional stage to re-name one bone to a temporary name, the example below shows how to swap bone_H_Saddle and bone_Spine names with each other:
<task_id> cas_bone_name_change # changes a bone name (the NEW name must not already exist in a skeleton this is being applied to) <directory_in> I:\M2TW\mods\WD_PKH\data\animations\pkh_horse_marka # optional path to directory where .cas files are (if different to _task.txt file location) <directory_out> I:\M2TW\mods\WD_PKH\data\animations\pkh_horse_marka\changedbones # directory where extracted files will be put <bone_name_change_list> # list of cas bone names to be swapped bone_H_Saddle bone_H_Saddlex bone_Spine bone_H_Saddle bone_H_Saddlex bone_Spine
IWTE Task File Options
Text File Output
using <create_text_file> you can optionally generate .txt files that show, for information purposes only, the content of the incoming .mesh/.cas files, the default option is
<create_text_file> no #stops any text file being created <create_text_file> yes #creates a summary text file with header/trailer info, numbers of verts, texture and mesh names etc. <create_text_file> full #creates a full text file showing the interpretation of all the ints/floats etc in the file, with comments