Guide: Animating Weapons

From HBM's Nuclear Tech Wiki

Welcome to your first step in authoring weapon animations in Blender. Before we start off this guide you will need a few things:

In this guide, useful keyboard shortcuts for a given action will be indicated with square brackets, like so: [X]

Diagrams will be referenced with parentheses, like so: (1)

Setup & Importing

1. Assigning a material to an object

Setup JSON export tool

First, go to the toolbar and navigate through Edit > Preferences > Addons and Install... the export-json-animation-{version}.py script for your version and enable it in the list. This will add the Import/Export .json animation options to the File > Import/Export menus.

Import your model & texture

Start a new file in Blender and delete the default cube [X] and import your weapon .obj. This will introduce your model to the scene without any textures, which you can add via the material view (1). In this window you can set the texture via clicking the dot next to Base Color and selecting Image Texture. To make the texture look like it does in-game, change the interpolation from Linear to Closest.

Setup camera

Switch to the Animation tab and move the camera to about the same position as it is in game (move with [G], rotate with [R]), set the camera FoV to 70 to match the in-game FOV. On the bottom panel, switch from Dope Sheet to Action Editor, so we can store multiple different actions for each animation (reloading, firing, inspecting, etc).

Animating

Setting Framedata

Blender by default starts animations on frame 1, we will want to change that to frame 0 before we begin. This can be done at the bottom right of the Action Editor panel. Now, select your base weapon part, ensure it is at its base pose, and add a keyframe [I] for the location & rotation. This will add a new action. Make sure to click the shield next to the name of the action to add a fake user, this will keep it from being automatically deleted on save if it is unassigned (since you will have multiple animations for each part)!

This action needs to be named such that the mod understands which animation set this animation is for (the Name, eg. Reload, Fire), and to what part of the model to apply the animation to (the Part, eg. Gun, Barrel, Lever, Magazine). To achieve this, the action must be named like: Name.Part, so for an animation applied to the Body for Reload, it would be named Reload.Body.

Now you can begin animating your weapon!

Extras

The export tool saves all parent and offset data, so to make animation easier, you can set parents of certain objects such that they follow each other (like making a magazine be parented to the body of the gun such that it doesn't need to be animated while the gun moves around).

Adding to the mod

2. Defining the animations within the mod code

Once you have created your animations and exported your JSON file, adding to the mod is fairly simple, assuming the weapon has had a basic setup already (Bob has made animations for all weapons, so parenting and rendering should already be handled).

First, add the new animations to ResourceManager.java, following the example of the other JSON animations already present. You can then reference those animations in the XFactory for your desired weapon by simply returning the named animation (2).