Next Broadcast

Skeletal animation from scratch

hakkthazard GameDev DK30 Fall 2019 1 3

Description

As part of developing my own engine for game jams and side projects, I’d like to add skeletal animation that I can use for 3D games. I’d like to write at least the system to play some hardcoded animations with multiple bones, but there is potential to add additional features, like mesh skinning, reading in some open or custom format from blender, and blending between animations.

Recent Updates

hakkthazard 6 years ago

The finished project can be viewed in a browser here. You can use WASD and click and drag to fly around, and it should also work on phones.

hakkthazard 6 years ago

I’ve finished implementing the skeletal animation vertex shader, and additionally managed to implement mesh skinning, one of my stretch goals for week 4.

There are some artifacts in the animation visible when I use fewer keyframes. I think this is due to problems in the way I hardcoded all of the poses, but I hope to test more meshes to make sure there isn’t anything wrong with the animation system.

I set up a “snake” mesh as a test model. Previously I was drawing cubes for each bone, but I needed a single solid mesh to be able to test the vertex-deforming component of skeletal animation. I still don’t have a way to import models with animation data, because I want to make an exporter from scratch (and haven’t done it yet), so I generated a cylindrical tube in code and textured it with a snake pattern.

The first version of the shader assigned a single bone to each vertex, rather than a set of bones and weights. This results in a noticeable effect where you can see the bends between bones.

This is a good enough result to consider the project complete, but the version with mesh skinning was not too much additional work from what I already had. So for the final week, if I have time, I’d like to explore the python Blender API to see if I can write out a file with all the animation data I need (right now my models are either loaded from .obj’s or are hard-coded).

hakkthazard 6 years ago

There now can be multiple skeletons, animations, models in different animations states, and so on.

Previously there was just one set of bones and animations; the data was more or less hard-coded into the update loop, so there only ever could be one animating skeleton. This was all refactored so that a set of skeletons and animations can be loaded at the start, and the game update loop can ask for as many different animations as it wants.

This also sets up the code to be able to more easily load animation assets stored in files down the line.

hakkthazard 6 years ago

Set up a little walk cycle animation made up of hard-coded bones and poses. The animation timeline is still hacked together, so the next step will be fleshing that out and adding in a way to blend between the idle and walking animation

hakkthazard 6 years ago

Setting up a 3D test scene turned out to be quicker than I expected, since I was able to copy paste a bunch of code from a previous game project. So, I decided to jump right into making some data structures for skeletons and bones.

I already have a bunch of math functions for matrices, vectors and quaternions written out, so I was able to get a animated spine/tail/multiple-elbow-arm up and running fairly easily. The skeleton and the two poses are hard-coded, and the animation code is a bit hacked together, so the next step will be factoring that out into something that can be used for arbitrary skeletons and animations, and adding some kind of keyframe/animation timeline.

Estimated Timeframe

Sep 10th - Oct 10th

Week 1 Goal

Set up a 3d test scene from the existing engine to help visualize programming the animation system

Week 2 Goal

Animate some boxes with hardcoded animations. Just test the idea of blending between a “T-Pose” and the current animation frame. Try adding keyframes and turning animations on and off in the game loop.

Week 3 Goal

Add the idea of a “skeleton”, using a hardcoded mesh or some exported asset from Blender. Write the shader to determine the location of each vertex based on the transforms of the bones of the skeleton.

Week 4 Goal

Explore additional features, like a custom exporter for Blender, mesh skinning, etc.

Tags

  • gamedev
  • game
  • 3d
  • animation
  • skeleton
  • skeletal
  • bone
  • transform
  • engine
  • programming
  • shader
  • rendering
  • code
  • c
  • c++