2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
9 #include "player_ragdoll.h"
10 #include "shaders/viewchar.h"
12 vg_tex2d tex_characters
= { .path
= "textures/ch_gradient.qoi" };
14 static void player_model_init(void)
16 shader_viewchar_register();
17 vg_acquire_thread_sync();
19 vg_tex2d_init( (vg_tex2d
*[]){ &tex_characters
}, 1 );
21 vg_release_thread_sync();
24 static void player_model_free(void *_
)
26 mesh_free( &player
.mdl
.mesh
);
27 vg_tex2d_free( (vg_tex2d
*[]){ &tex_characters
}, 1 );
31 * Load model from file (.mdl)
33 static void player_load_model( const char *name
)
37 snprintf( buf
, sizeof(buf
)-1, "models/%s.mdl", name
);
38 mdl_header
*src
= mdl_load( buf
);
42 vg_error( "Could not load model\n" );
46 struct player_model temp
;
48 mdl_unpack_glmesh( src
, &temp
.mesh
);
49 skeleton_setup( &temp
.sk
, src
);
57 struct skeleton_anim
**anim
;
60 { "pose_stand", &temp
.anim_stand
},
61 { "pose_highg", &temp
.anim_highg
},
62 { "pose_slide", &temp
.anim_slide
},
63 { "pose_air", &temp
.anim_air
},
64 { "push", &temp
.anim_push
},
65 { "push_reverse", &temp
.anim_push_reverse
},
66 { "ollie", &temp
.anim_ollie
},
67 { "ollie_reverse",&temp
.anim_ollie_reverse
},
68 { "grabs", &temp
.anim_grabs
},
69 { "walk", &temp
.anim_walk
},
70 { "run", &temp
.anim_run
},
71 { "idle_cycle", &temp
.anim_idle
}
74 for( int i
=0; i
<vg_list_size(anims
); i
++ )
76 *anims
[i
].anim
= skeleton_get_anim( &temp
.sk
, anims
[i
].name
);
78 if( !(*anims
[i
].anim
) )
80 vg_error( "Animation '%s' is missing from character '%s'\n",
81 anims
[i
].name
, name
);
96 { "hips", &temp
.id_hip
},
97 { "hand.IK.L", &temp
.id_ik_hand_l
},
98 { "hand.IK.R", &temp
.id_ik_hand_r
},
99 { "elbow.L", &temp
.id_ik_elbow_l
},
100 { "elbow.R", &temp
.id_ik_elbow_r
},
101 { "head", &temp
.id_head
}
104 for( int i
=0; i
<vg_list_size(bones
); i
++ )
106 *bones
[i
].bone_id
= skeleton_bone_id( &temp
.sk
, bones
[i
].name
);
108 if( !(*bones
[i
].bone_id
) )
110 vg_error( "Required bone '%s' is missing from character '%s'\n",
111 bones
[i
].name
, name
);
117 /* swap temp into actual model */
118 mesh_free( &player
.mdl
.mesh
);
120 player_init_ragdoll( src
);