-
Notifications
You must be signed in to change notification settings - Fork 18
Animations
(This page assumes you're using Blender as your 3D modeling suite.)
As of v0.3, animations actually work just fine in Tetra3d, but require that you use the GLTF or GLB file formats - the DAE importer doesn't currently support animations. This is because the Blender DAE exporter only supports one animation per object currently, so it makes more sense to simply support GLTF / GLB files for animations.
When you import a GLTF or GLB file, the contents get converted to Tetra3D objects and stored in a Library. This is a storage place for scenes, meshes, materials, and animations, animations being indexed according to their name. Playback of animations starts on frame 0. To play back an animation, call AnimationPlayer.Play(animation)
with a reference to the animation, and call AnimationPlayer.Update(dt)
each frame with the delta time value (i.e. 1.0/60 FPS, if 60 FPS is your target, and you're not doing any delta timestep adjustment).
Object animations (objects simply moving, scaling, or rotating) work by simply calling Node.AnimationPlayer.Play(animation)
on a Node - the animation can be retrieved from a Library. AnimationPlayer has a few different functions for controlling playback and a callback that can be set for when the playback loops.
Skinned mesh / armature-based animations also work, and work similarly as well as Object Animations. However, there are some points to consider.
Skinned meshes work by animating vertices from a mesh using an armature - this is the skinning process. The armature object animates, and the mesh bends to mimic the armature, both in pose and in location. An "Armature" in Blender is converted to a hierarchy of Nodes in Tetra3D, starting with a root node indicating the object as created in Blender. Parenting an object (like a weapon or tool) to a bone (like a hand) is relatively trivial - you simply parent the object to the corresponding node and play the animation. The object will move to match the bone's movements accordingly.
When a skinned Model's Skinned
property is set to true, its vertices will take into account the Armature's transform and animation. Otherwise, it will default to its own transform and default vertex positions. Mesh skinning is done on the CPU, so disabling this reduces CPU load. Note that this flag is also an indicator indicating that the Model is skinned at all.
While a Model does not need to be a child of the armature that is deforming it (either in Tetra3d or in Blender), doing so is advised as it makes duplicating an animated Model simpler, as you then only need to call Clone()
on the armature's root. The skinned Model will also be duplicated and reassigned to point to the new bone tree.
To store multiple animations in a single file in Blender, you need to place the animations on separate tracks in the NLA (Nonlinear Animation) editor. You can do this by pressing the "Stash" buttons in the Action Editor. You can also press "Push Down" to move animations down to the top NLA track for the object (or create a new one if it doesn't exist or is occupied by a previous animation). You can use the up and down arrows to easily jump to these different animations to edit while keeping the animations starting on the same frame (0).
When you play an animation through an AnimationPlayer, by default it will overwrite any previously playing Animation. To blend from the previous animation into the next one, simply set AnimationPlayer.BlendTime
to the amount of time (in seconds) to blend between the two animations.
To use markers in your animations to time events, you'll need to install the Tetra3D Blender add-on. See the wiki page on the Blender Add-on.
The two marker types; local pose markers on the left, and normal markers on the right
Markers are small indicators indicating when something should happen in an animation. There are two kinds of markers in Blender - local pose markers (which look like diamonds / Blender bones, and are local to the currently selected animation), and "normal", non-local markers (which persist across multiple animations and look like triangles).
Local pose markers, specifically, are supported by Tetra3D. Local markers that are placed within Blender Animations get exported by the Blender add-on to the corresponding Tetra3d.Animation
. You can check the markers directly in Animation.Markers
, or pass a callback function to AnimationPlayer.OnMarkerTouch()
to be notified when a marker is touched in the process of playing back an animation.
Calling AnimationPlayer.Update()
updates the nodes under the animation player's root, allowing you to play back an animation. If you want to play back multiple animations at the same time on a single root node / armature, you'll need to create another AnimationPlayer with the same root node for the armature's base and ensure that the animations you have to play don't have any node channels in common (i.e. one animation can be comprised of an upper body animation while another can be of the lower body).
Calling AnimationPlayer.Update()
also updates the nodes all at once, meaning that you can modify the position, scale, and rotation of each node after calling Update()
. This is useful in case you need to, for example, have a bone track a position in space while playing back an animation.