commit c9131d1c8bcd79ac8adba74d6dedd59d7986fe34
parent 46ad1520f80035840cdf42d20177f1c1008361f8
Author: Michael Savage <mikejsavage@gmail.com>
Date: Thu, 30 May 2019 02:30:13 +0300
Ctrl to draw skeleton
Diffstat:
M | gltf.cc | | | 73 | +++++++++++++++++++++++++++++++++++++------------------------------------ |
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/gltf.cc b/gltf.cc
@@ -446,26 +446,46 @@ GAME_FRAME( game_frame ) {
UniformBinding view_uniforms = renderer_uniforms( V, P, game->pos );
UniformBinding joints_uniforms = renderer_upload_uniforms( skinning_matrices, model.animation.num_joints * sizeof( Mat4 ), 16 );
- // draw skinned model
- {
- RenderState render_state;
- render_state.shader = get_shader( SHADER_SKINNED_FLAT_VERTEX_COLOURS );
- render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms;
- render_state.uniforms[ UNIFORMS_JOINT_POSES ] = joints_uniforms;
- render_state.textures[ 0 ] = renderer_blue_noise();
-
- for( u32 i = 0; i < model.num_meshes; i++ ) {
- renderer_draw_mesh( model.meshes[ i ], render_state );
+ if( !input->keys[ KEY_LEFTCTRL ] ) {
+ // draw skinned model
+ {
+ RenderState render_state;
+ render_state.shader = get_shader( SHADER_SKINNED_FLAT_VERTEX_COLOURS );
+ render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms;
+ render_state.uniforms[ UNIFORMS_JOINT_POSES ] = joints_uniforms;
+ render_state.textures[ 0 ] = renderer_blue_noise();
+
+ for( u32 i = 0; i < model.num_meshes; i++ ) {
+ renderer_draw_mesh( model.meshes[ i ], render_state );
+ }
}
- }
- // draw an arrow on the guy's head
- {
- u8 head_joint = 4;
- v3 pos = ( joint_matrices[ head_joint ] * v4( 0, 0, 0, 1 ) ).xyz();
- v3 up = ( joint_matrices[ head_joint ] * v4( 0, 1, 0, 0 ) ).xyz();
+ // draw an arrow on the guy's head
+ {
+ u8 head_joint = 4;
+ v3 pos = ( joint_matrices[ head_joint ] * v4( 0, 0, 0, 1 ) ).xyz();
+ v3 up = ( joint_matrices[ head_joint ] * v4( 0, 1, 0, 0 ) ).xyz();
- immediate_arrow( pos, up, 1, v4( 0, 1, 0, 1 ) );
+ immediate_arrow( pos, up, 1, v4( 0, 1, 0, 1 ) );
+
+ RenderState render_state;
+ render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS );
+ render_state.uniforms[ UNIFORMS_VIEW ] = renderer_uniforms( V, P );
+ immediate_render( render_state );
+ }
+ }
+ else {
+ // draw skeleton
+ for( u32 i = 0; i < model.animation.num_joints; i++ ) {
+ v3 pos = ( joint_matrices[ i ] * v4( 0, 0, 0, 1 ) ).xyz();
+ v3 parent_pos = ( joint_matrices[ model.animation.joints[ i ].parent ] * v4( 0, 0, 0, 1 ) ).xyz();
+ v3 forward = ( joint_matrices[ i ] * v4( 0, 1, 0, 0 ) ).xyz();
+
+ immediate_sphere( pos, 0.025, v4( 1 ) );
+ immediate_arrow( pos, forward, 0.2, v4( 0.5, 0.5, 0.5, 1 ) );
+ if( i != 0 )
+ immediate_arrow( pos, ( parent_pos - pos ), 0.1, v4( 1, 0, 0, 1 ) );
+ }
RenderState render_state;
render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS );
@@ -473,25 +493,6 @@ GAME_FRAME( game_frame ) {
immediate_render( render_state );
}
- // draw skeleton
- // {
- // for( u32 i = 0; i < model.animation.num_joints; i++ ) {
- // v3 pos = ( sample_matrices[ i ] * v4( 0, 0, 0, 1 ) ).xyz();
- // v3 parent_pos = ( sample_matrices[ model.animation.joints[ i ].parent ] * v4( 0, 0, 0, 1 ) ).xyz();
- // v3 forward = ( sample_matrices[ i ] * v4( 0, 1, 0, 0 ) ).xyz();
- //
- // immediate_sphere( pos, 0.025, v4( 1 ) );
- // immediate_arrow( pos, forward, 0.2, v4( 0.5, 0.5, 0.5, 1 ) );
- // if( i != 0 )
- // immediate_arrow( pos, ( parent_pos - pos ), 0.1, v4( 1, 0, 0, 1 ) );
- // }
- //
- // RenderState render_state;
- // render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS );
- // render_state.uniforms[ UNIFORMS_VIEW ] = renderer_uniforms( V, P );
- // immediate_render( render_state );
- // }
-
renderer_end_pass();
renderer_end_frame();
}