3 #include "shaders/model_character_view.h"
6 static struct skeleton_anim
*gumpa_idle
;
8 void npc_load_model( struct npc
*npc
, const char *path
)
10 vg_linear_clear( vg_mem
.scratch
);
12 mdl_context
*meta
= &npc
->meta
;
13 mdl_open( meta
, path
, vg_mem
.rtmemory
);
14 mdl_load_metadata_block( meta
, vg_mem
.rtmemory
);
15 mdl_load_animation_block( meta
, vg_mem
.rtmemory
);
17 struct skeleton
*sk
= &npc
->skeleton
;
18 skeleton_setup( sk
, vg_mem
.rtmemory
, meta
);
20 u32 mtx_size
= sizeof(m4x3f
)*sk
->bone_count
;
21 npc
->final_mtx
= vg_linear_alloc( vg_mem
.rtmemory
, mtx_size
);
23 if( !mdl_arrcount( &meta
->textures
) )
24 vg_fatal_error( "No texture in model" );
26 mdl_texture
*tex0
= mdl_arritm( &meta
->textures
, 0 );
27 void *data
= vg_linear_alloc( vg_mem
.scratch
, tex0
->file
.pack_size
);
28 mdl_fread_pack_file( meta
, &tex0
->file
, data
);
30 vg_tex2d_load_qoi_async( data
, tex0
->file
.pack_size
,
31 VG_TEX2D_NEAREST
|VG_TEX2D_CLAMP
,
34 mdl_async_load_glmesh( meta
, &npc
->mesh
, NULL
);
40 npc_load_model( &npc_gumpa
, "models/gumpa.mdl" );
41 gumpa_idle
= skeleton_get_anim( &npc_gumpa
.skeleton
, "gumpa_idle" );
44 static struct npc
*npc_resolve( u32 id
)
46 if( id
== 1 ) return &npc_gumpa
;
50 void npc_update( ent_npc
*ent
)
52 struct npc
*npc_def
= npc_resolve( ent
->id
);
56 struct skeleton
*sk
= &npc_def
->skeleton
;
57 pose
.type
= k_player_pose_type_ik
;
58 pose
.board
.lean
= 0.0f
;
60 skeleton_sample_anim( sk
, gumpa_idle
, vg
.time
, pose
.keyframes
);
62 v3_copy( ent
->transform
.co
, pose
.root_co
);
63 v4_copy( ent
->transform
.q
, pose
.root_q
);
64 apply_full_skeleton_pose( &npc_def
->skeleton
, &pose
, npc_def
->final_mtx
);
67 void npc_render( ent_npc
*ent
, world_instance
*world
, vg_camera
*cam
)
69 struct npc
*npc_def
= npc_resolve( ent
->id
);
72 shader_model_character_view_use();
74 glActiveTexture( GL_TEXTURE0
);
75 glBindTexture( GL_TEXTURE_2D
, npc_def
->texture
);
76 shader_model_character_view_uTexMain( 0 );
77 shader_model_character_view_uCamera( cam
->transform
[3] );
78 shader_model_character_view_uPv( cam
->mtx
.pv
);
79 shader_model_character_view_uDepthCompare( 0 );
81 WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world
, model_character_view
);
83 glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms
,
84 npc_def
->skeleton
.bone_count
,
86 (const GLfloat
*)npc_def
->final_mtx
);
88 mesh_bind( &npc_def
->mesh
);
89 mesh_draw( &npc_def
->mesh
);