Implemented 3D Skeletal Mesh when previous most complicated object in engine was a sphere
Created Transform hierarchy using Matrix transformations
Animated 3D character programmatically
48 hour game jam
Personal engine
Spring 2020
Skeletal Mesh Bone
Below is the heart of the skeletal mesh code. Each Skeletal Mesh has a parent bone and child bones. Updating the bones transforms are done in game code since I wasn’t sure of the best way to do it. Each bone asks its parent for its Model Matrix to render itself before calling all of its children’s render methods.
SkeletalMeshBone::SkeletalMeshBone( GPUMesh* mesh, SkeletalMeshBone* parentBone, Transform localTransform ) : m_mesh( mesh ), m_parentBone( parentBone ), m_transform( localTransform ) {} Mat44 SkeletalMeshBone::GetRelativeModelMatrix() const { Mat44 parentMatrix; Mat44 myLocalMatrix = m_transform.ToMatrix(); if( nullptr != m_parentBone ) { parentMatrix = m_parentBone->GetRelativeModelMatrix(); } parentMatrix.TransformBy( myLocalMatrix ); return parentMatrix; } void SkeletalMeshBone::Render() { if( nullptr != m_mesh ) { RenderContext* context = m_mesh->m_renderContext; if( nullptr != context ) { Mat44 modelMatrix = GetRelativeModelMatrix(); context->SetModelMatrix( modelMatrix ); context->BindTexture( m_diffuseTex ); context->BindNormal( m_normalTex ); context->BindShader( m_shader ); context->DrawMesh( m_mesh ); } } for( size_t boneIndex = 0; boneIndex < m_childBones.size(); boneIndex++ ) { if( nullptr != m_childBones[boneIndex] ) { m_childBones[boneIndex]->Render(); } } }
Post Mortem
What was learned
Should have made the skeletal mesh handle simple physics as well as rendering
Character head requires extra work to avoid fighting between look direction and mesh forward direction
Would have been useful to allow bones to be rotated in both local and world space
What went well
Wrote successful plan to build project in just 48 hours
Created simple Skeletal Mesh with Transform Hierarchy quickly
Built simple programmatic animations to prove use of skeletal mesh