X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skeleton.h;h=34e1b8e8fba779b0e9c2bb11ca1c068106d6eaee;hb=3ee65e6e24bfc39db7c7dd8c1f4cec3d5c42d0f8;hp=e143fa2ec2038f34fb0d4fb5f890f10d568c8151;hpb=6a4dafa6fe9a3dd4bb88698bbe964154364390ec;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skeleton.h b/skeleton.h index e143fa2..34e1b8e 100644 --- a/skeleton.h +++ b/skeleton.h @@ -1,3 +1,7 @@ +/* + * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved + */ + #ifndef SKELETON_H #define SKELETON_H @@ -14,6 +18,8 @@ struct skeleton int defer; mdl_keyframe kf; + + char name[16]; } *bones; m4x3f *final_mtx; @@ -42,6 +48,16 @@ struct skeleton useless cpu IK bones. */ }; +static u32 skeleton_bone_id( struct skeleton *skele, const char *name ) +{ + for( u32 i=0; ibone_count; i++ ) + { + if( !strcmp( skele->bones[i].name, name )) + return i; + } + return 0; +} + /* * Lerp between two sets of keyframes and store in dest. Rotations use Nlerp. */ @@ -174,6 +190,9 @@ static void skeleton_inverse_for_ik( struct skeleton *skele, m3x3_transpose( inverse, inverse ); } +/* + * Creates inverse rotation matrices which the IK system uses. + */ static void skeleton_create_inverses( struct skeleton *skele ) { /* IK: inverse 'plane-bone space' axis '(^axis,^bone,...)[base] */ @@ -193,9 +212,11 @@ static void skeleton_create_inverses( struct skeleton *skele ) } } +/* + * Apply a model matrix to all bones, should be done last + */ static void skeleton_apply_transform( struct skeleton *skele, m4x3f transform ) { - /* bone space inverse matrix */ for( int i=0; ibone_count; i++ ) { struct skeleton_bone *sb = &skele->bones[i]; @@ -203,6 +224,10 @@ static void skeleton_apply_transform( struct skeleton *skele, m4x3f transform ) } } +/* + * Apply an inverse matrix to all bones which maps vertices from bind space into + * bone relative positions + */ static void skeleton_apply_inverses( struct skeleton *skele ) { for( int i=0; ibone_count; i++ ) @@ -295,6 +320,23 @@ static void skeleton_apply_ik_pass( struct skeleton *skele ) } } +/* + * Applies the typical operations that you want for an IK rig: + * Pose, IK, Pose(deferred), Inverses, Transform + */ +static void skeleton_apply_standard( struct skeleton *skele, mdl_keyframe *pose, + m4x3f transform ) +{ + skeleton_apply_pose( skele, pose, k_anim_apply_defer_ik ); + skeleton_apply_ik_pass( skele ); + skeleton_apply_pose( skele, pose, k_anim_apply_deffered_only ); + skeleton_apply_inverses( skele ); + skeleton_apply_transform( skele, transform ); +} + +/* + * Get an animation by name + */ static struct skeleton_anim *skeleton_get_anim( struct skeleton *skele, const char *name ) { @@ -360,6 +402,7 @@ static int skeleton_setup( struct skeleton *skele, mdl_header *mdl ) v3_copy( pnode->co, sb->co ); v3_copy( pnode->s, sb->end ); sb->parent = pnode->parent-skeleton_root; + strncpy( sb->name, mdl_pstr(mdl,pnode->pstr_name), 15 ); if( is_ik ) {