The clear and simple steps to export a GLTF model with various animations included
As we progress with new projects in Decentraland, we learn new techniques and utilize new software.
One of the tools we've been using extensively is Blender, as it facilitates seamless export of GLTF and GLB formats. We have previously discussed animation in Blender in other posts.
Here is a concise guide to exporting a GLTF model with multiple attached animations. This enables you to switch between animations within a GLTF viewer of your preference.
To create distinct animations in Blender, it's essential to understand the concept of actions: what they are, how to create them, how they function, and how to delete them.
An action in Blender is a tool used to record and encapsulate data. Similar to other elements in Blender, actions are data blocks. When you animate an object by altering its position with keyframes, the resulting animation is stored within an action. Consequently, you can generate numerous animations by creating multiple actions.
Each animation can be treated as a distinct action for a character or object. For instance, animations like running, idling, and shooting can be defined as separate actions.
To initiate the creation of a new action in Blender, you will need to modify one of the existing windows or create an entirely new one. To achieve this, follow these steps:
Hover your cursor over one of the corners of a window until the cursor icon changes into a cross.
Click and drag your cursor to establish the boundaries of a new window.
Next, to access the action menu, modify the content of the window to display the “Dope Sheet”. From there, you can navigate to the “Action Editor” by following these steps:
Change the content of the window to display the “Dope Sheet”.
Within the “Dope Sheet”, navigate to the “Action Editor”.
Once you have the editor in view, you can begin creating actions. However, before doing so, there are a couple of key considerations:
Actions can only be linked to ONE object. If your model is divided into two separate pieces, you cannot assign the same action to both of them.
To work around the above point, actions should be linked to the Armature. In Blender, an armature functions as a sort of empty group that serves as the parent for the model and its bones.
As the term suggests, an armature is closely related to bones. When you create an Armature, it automatically generates a bone, and they are intrinsically linked. Consequently, when you animate the Armature, the bones are affected as well.
Importantly, this means that models must be animated using bones.
Once you have created an armature (located in the top corner under Add → Armature), you are prepared to generate actions. With the Armature selected, click the "New" button, rename the animation, and remember to click the "shield" icon (If you neglect to click the shield, Blender won't save the new name, potentially resulting in the loss of changes made to the action).
With the armature selected create a new action.
When you have completed working on an action, close it by clicking the X button on the right side. This will take you back to the initial menu in the editor, allowing you to create a new action from the beginning. Here's an important note: if you wish to delete an action because you find it unnecessary, don't need it, or if you accidentally duplicated it, DO NOT solely click the X button (as mentioned earlier, this closes the action but doesn't delete it). Also, DO NOT press the delete key or the backspace key; these won't delete the action either.
The ONLY way to delete an action is to press Shift + the X button on the right.
After doing so, close and reopen the file to refresh the system. If you don't close the program, you might still see the actions that you've deleted.
Check the shield to save the name and the action.
Check the shield to save the name and the action.
Once you've completed all the desired actions, you need to store them within the model so they can be selected in the GLTF model. To achieve this, follow these steps:
In the “Action Editor”, locate the "Stash" button on the left side.
Press the "Stash" button to store the actions. Ensure that you don't intend to make further edits before stashing.
Save both the name of the action and the action itself.
From Maya to Blender
Let's consider a scenario where you want to work in another software like Maya. The transition is relatively straightforward, but it involves a series of steps to ensure a smooth process. Follow these guidelines:
Create the animations using bones. When you import them into Blender, an Armature will be generated.
Ensure that all animations are on the same timeline, even if you separate the frames to distinguish animations. Keep them within the same timeline.
Export the animations in FBX format with bones. In the export options, select "Bake Animation."
Once you import the FBX file back into Blender, it will create an Armature in the scene containing the animations. At this point, you need to:
Rename the action to reflect the animation's content.
Duplicate the action for each animation you created.
Remove unnecessary frames and adjust the timeline to start at the appropriate point for each animation.
After these adjustments, stash the animations and export the model.
This process will ensure that your animations are successfully integrated into Blender for further use.
Exporting and viewing
When exporting the model, ensure that you check certain options in the presets:
"Limit to Selected Objects": If your scene contains multiple objects, make sure you select everything inside the armature that you intend to export.
"Apply Modifiers": This option applies the deformation of the bones to the models.
In the "Animation" section, under "Skinning," select "Include All Bone Influences" to ensure that all the bones are exported with their influences.
After exporting, you can inspect the model's correctness using a GLTF/GLB viewer. There are several online viewers available. When you import the model into a viewer, ensure that there's a tab where you can select and preview different animations associated with the model.
This step will help you confirm that the exported model and its animations are working as intended.
Creative Art Director
Passionate about videogames, movies and creatures. Artist by day and superhero at night.