Skip to content

Commit cbca91d

Browse files
committed
refactor: use tbx engine
1 parent 433e475 commit cbca91d

11 files changed

Lines changed: 45 additions & 51 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,6 @@
154154
[submodule "src/graphics/ui_render_suite_implementation"]
155155
path = src/graphics/ui_render_suite_implementation
156156
url = git@github.com:cpp-toolbox/ui_render_suite_implementation.git
157+
[submodule "src/utility/collection_utils"]
158+
path = src/utility/collection_utils
159+
url = git@github.com:cpp-toolbox/collection_utils.git

.required_shader_batchers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures
1+
texture_packer_rigged_and_animated_cwl_v_transformation_ubos_1024_with_textures(1000000)
415 KB
Loading
4.29 MB
Binary file not shown.

assets/config/user_cfg.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[general]
2+
model_path = assets/animations/skeleton/skeleton.fbx
3+
requested_animation_name = cast
4+
5+
; model_path = assets/animations/shotgun_with_hands.fbx
6+
; requested_animation_name = fire
7+
8+
; model_path = assets/animations/sniper_rifle_with_hands.fbx
9+
; requested_animation_name = fire
10+
;
11+
; model_path = assets/animations/knife_with_hands.fbx
12+
; requested_animation_name = swing

src/graphics/draw_info

src/graphics/texture_packer

src/main.cpp

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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

@@ -35,7 +36,7 @@
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;

src/utility/collection_utils

Submodule collection_utils added at 78d2821

0 commit comments

Comments
 (0)