11#include " utility/glm_utils/glm_utils.hpp"
2+ #include " utility/logger/logger.hpp"
23#include < glad/glad.h>
34#include < GLFW/glfw3.h>
45
3536#include < iostream>
3637#include < vector>
3738
38- int main (int argc, char *argv[] ) {
39+ int main () {
3940
4041 std::vector<ShaderType> requested_shaders = {
4142 ShaderType::TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_1024_WITH_TEXTURES,
@@ -59,21 +60,26 @@ int main(int argc, char *argv[]) {
5960
6061 glm::mat4 identity = glm::mat4 (1 );
6162
62- std::string path = (argc > 1 ) ? argv[1 ] : " assets/animations/shotgun_with_hands.fbx" ;
63- // std::string path = (argc > 1) ? argv[1] : "assets/animations/test.fbx";
63+ std::string model_path = tbx_engine.configuration .get_value (" general" , " model_path" )
64+ .value_or (" assets/animations/shotgun_with_hands.fbx" );
65+
66+ std::string requested_animation =
67+ tbx_engine.configuration .get_value (" general" , " requested_animation_name" ).value_or (" equip" );
6468
6569 rigged_model_loading::RecIvpntRiggedCollector rirc (
6670 tbx_engine.batcher
6771 .texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures_shader_batcher
6872 .object_id_generator );
69- auto ivpntrs = rirc.parse_model_into_ivpntrs (rp.gfp (path ).string ());
73+ auto ivpntrs = rirc.parse_model_into_ivpntrs (rp.gfp (model_path ).string ());
7074 auto ivpntprs = texture_packer_model_loading::convert_ivpntr_to_ivpntpr (ivpntrs, texture_packer);
75+ auto tig = draw_info::TransformedIVPNTPRGroup{
76+ ivpntprs, tbx_engine.batcher
77+ .texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures_shader_batcher
78+ .object_id_generator .get_id ()};
7179
7280 double current_animation_time = 0 ;
7381 bool animation_is_playing = false ;
7482
75- std::string requested_animation = " equip" ;
76-
7783 std::function<void (double )> tick = [&](double dt) {
7884 if (tbx_engine.input_state .is_just_pressed (EKey::p)) {
7985 animation_is_playing = not animation_is_playing;
@@ -105,61 +111,32 @@ int main(int argc, char *argv[]) {
105111 restart_requested = true ;
106112 }
107113
114+ // knife has swing instead
108115 if (tbx_engine.input_state .is_just_pressed (EKey::LEFT_MOUSE_BUTTON)) {
109- requested_animation = " fire" ;
116+ // requested_animation = "fire";
110117 restart_requested = true ;
111118 }
112119
113120 // first we upload the animation matrix
114- std::vector<glm::mat4> bone_transformations ;
115- rirc.set_bone_transforms (dt, bone_transformations , requested_animation, false , restart_requested, true );
121+ std::vector<glm::mat4> bone_id_to_lastutb ;
122+ rirc.set_animated_bone_transforms (dt, bone_id_to_lastutb , requested_animation, false , restart_requested, true );
116123
117124 const unsigned int MAX_BONES_TO_BE_USED = 100 ;
118125 ShaderProgramInfo shader_info = tbx_engine.shader_cache .get_shader_program (
119126 ShaderType::TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_1024_WITH_TEXTURES);
120127
121- GLint location = glGetUniformLocation (
128+ GLint bone_animation_transforms_opengl_handle = glGetUniformLocation (
122129 shader_info.id ,
123130 tbx_engine.shader_cache .get_uniform_name (ShaderUniformVariable::BONE_ANIMATION_TRANSFORMS).c_str ());
124131
125132 tbx_engine.shader_cache .use_shader_program (
126133 ShaderType::TEXTURE_PACKER_RIGGED_AND_ANIMATED_CWL_V_TRANSFORMATION_UBOS_1024_WITH_TEXTURES);
127- glUniformMatrix4fv (location, bone_transformations.size (), GL_FALSE, glm::value_ptr (bone_transformations[0 ]));
128-
129- // now the model geometry:
130- for (auto &ivpntpr : ivpntprs) {
131- // Populate bone_indices and bone_weights
132- std::vector<glm::ivec4> bone_indices;
133- std::vector<glm::vec4> bone_weights;
134-
135- for (const auto &vertex_bone_data : ivpntpr.bone_data ) {
136- glm::ivec4 indices (static_cast <int >(vertex_bone_data.indices_of_bones_that_affect_this_vertex [0 ]),
137- static_cast <int >(vertex_bone_data.indices_of_bones_that_affect_this_vertex [1 ]),
138- static_cast <int >(vertex_bone_data.indices_of_bones_that_affect_this_vertex [2 ]),
139- static_cast <int >(vertex_bone_data.indices_of_bones_that_affect_this_vertex [3 ]));
140-
141- glm::vec4 weights (vertex_bone_data.weight_value_of_this_vertex_wrt_bone [0 ],
142- vertex_bone_data.weight_value_of_this_vertex_wrt_bone [1 ],
143- vertex_bone_data.weight_value_of_this_vertex_wrt_bone [2 ],
144- vertex_bone_data.weight_value_of_this_vertex_wrt_bone [3 ]);
145-
146- bone_indices.push_back (indices);
147- bone_weights.push_back (weights);
148- }
149-
150- std::vector<int > packed_texture_indices (ivpntpr.xyz_positions .size (), ivpntpr.packed_texture_index );
151- int ptbbi = texture_packer.get_packed_texture_bounding_box_index_of_texture (ivpntpr.texture );
152- std::vector<int > packed_texture_bounding_box_indices (ivpntpr.xyz_positions .size (), ptbbi);
153-
154- // bad!
155- std::vector<unsigned int > ltw_indices (ivpntpr.xyz_positions .size (), ivpntpr.id );
156-
157- tbx_engine.batcher
158- .texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures_shader_batcher
159- .queue_draw (ivpntpr.id , ivpntpr.indices , ltw_indices, bone_indices, bone_weights,
160- packed_texture_indices, ivpntpr.packed_texture_coordinates ,
161- packed_texture_bounding_box_indices, ivpntpr.xyz_positions );
162- }
134+ glUniformMatrix4fv (bone_animation_transforms_opengl_handle, bone_id_to_lastutb.size (), GL_FALSE,
135+ glm::value_ptr (bone_id_to_lastutb[0 ]));
136+
137+ tbx_engine.batcher
138+ .texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures_shader_batcher .queue_draw (
139+ tig);
163140
164141 tbx_engine.batcher
165142 .texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures_shader_batcher
@@ -178,6 +155,7 @@ int main(int argc, char *argv[]) {
178155
179156 std::function<bool ()> termination = [&]() { return tbx_engine.window_should_close (); };
180157
158+ tbx_engine.main_loop .log_mode = LogSection::LogMode::disable;
181159 tbx_engine.start (tick, termination);
182160
183161 return 0 ;
0 commit comments