update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / player_model.h
index 20e5c0a46c4d8e0d80d35279b70f7d09ade974d6..8d5dd80efc7ac3c2ff8c59d244267dcccca2e54a 100644 (file)
@@ -2,123 +2,9 @@
  * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
  */
 
-#ifndef CHARACTER_H 
-#define CHARACTER_H
-
-#include "player.h"
+#pragma once
+#include "model.h"
+#include "skeleton.h"
 #include "player_ragdoll.h"
-#include "shaders/viewchar.h"
-
-vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" };
-
-static void player_model_init(void)
-{
-   shader_viewchar_register();
-   vg_acquire_thread_sync();
-   {
-      vg_tex2d_init( (vg_tex2d *[]){ &tex_characters }, 1 );
-   }
-   vg_release_thread_sync();
-}
-
-static void player_model_free(void *_)
-{
-   mesh_free( &player.mdl.mesh );
-   vg_tex2d_free( (vg_tex2d *[]){ &tex_characters }, 1 );
-}
-
-/*
- * Load model from file (.mdl)
- */
-static void player_load_model( const char *name )
-{
-   char buf[64];
-
-   snprintf( buf, sizeof(buf)-1, "models/%s.mdl", name );
-   mdl_header *src = mdl_load( buf );
-
-   if( !src )
-   {
-      vg_error( "Could not load model\n" );
-      return;
-   }
-
-   struct player_model temp;
-
-   mdl_unpack_glmesh( src, &temp.mesh );
-   skeleton_setup( &temp.sk, src );
-
-   /* 
-    * Link animations
-    */
-   struct _load_anim
-   {
-      const char *name;
-      struct skeleton_anim **anim;
-   }
-   anims[] = {
-      { "pose_stand",   &temp.anim_stand },
-      { "pose_highg",   &temp.anim_highg },
-      { "pose_slide",   &temp.anim_slide },
-      { "pose_air",     &temp.anim_air   },
-      { "push",         &temp.anim_push  },
-      { "push_reverse", &temp.anim_push_reverse },
-      { "ollie",        &temp.anim_ollie },
-      { "ollie_reverse",&temp.anim_ollie_reverse },
-      { "grabs",        &temp.anim_grabs },
-      { "walk",         &temp.anim_walk  },
-      { "run",          &temp.anim_run   },
-      { "idle_cycle",   &temp.anim_idle  }
-   };
-   
-   for( int i=0; i<vg_list_size(anims); i++ )
-   {
-      *anims[i].anim = skeleton_get_anim( &temp.sk, anims[i].name );
-      
-      if( !(*anims[i].anim) )
-      {
-         vg_error( "Animation '%s' is missing from character '%s'\n",
-                     anims[i].name, name );
-         vg_free( src );
-         return;
-      }
-   }
-
-   /* 
-    * Link bones
-    */
-   struct _load_bone
-   {
-      const char *name;
-      u32 *bone_id;
-   }
-   bones[] = {
-      { "hips",      &temp.id_hip },
-      { "hand.IK.L", &temp.id_ik_hand_l },
-      { "hand.IK.R", &temp.id_ik_hand_r },
-      { "elbow.L",   &temp.id_ik_elbow_l },
-      { "elbow.R",   &temp.id_ik_elbow_r },
-      { "head",      &temp.id_head }
-   };
-
-   for( int i=0; i<vg_list_size(bones); i++ )
-   {
-      *bones[i].bone_id = skeleton_bone_id( &temp.sk, bones[i].name );
-
-      if( !(*bones[i].bone_id) )
-      {
-         vg_error( "Required bone '%s' is missing from character '%s'\n",
-                     bones[i].name, name );
-         vg_free( src );
-         return;
-      }
-   }
-
-   /* swap temp into actual model */
-   mesh_free( &player.mdl.mesh );
-   player.mdl = temp;
-   player_init_ragdoll( src );
-   vg_free( src );
-}
 
-#endif
+#include "shaders/model_character_view.h"