Compare commits
	
		
			No commits in common. "8388fbfe3e43c41ae1bd8494e8d3604e9f476a06" and "8b7de58131da446b82cca4efc852eddec2fdd7ef" have entirely different histories.
		
	
	
		
			8388fbfe3e
			...
			8b7de58131
		
	
		
							
								
								
									
										89
									
								
								src/main.cc
									
									
									
									
									
								
							
							
						
						
									
										89
									
								
								src/main.cc
									
									
									
									
									
								
							| @ -42,15 +42,18 @@ typedef struct { | |||||||
| 
 | 
 | ||||||
| static void draw_imgui(ImDrawData*); | static void draw_imgui(ImDrawData*); | ||||||
| 
 | 
 | ||||||
|  | #define HANDMADE_MATH_IMPLEMENTATION | ||||||
| #define HANDMADE_MATH_NO_SSE | #define HANDMADE_MATH_NO_SSE | ||||||
| #include "HandmadeMath.h" | #include "HandmadeMath.h" | ||||||
| 
 | 
 | ||||||
| // ozz-animation headers
 | // ozz-animation headers
 | ||||||
| #include <cmath>  // fmodf
 | #include <cmath>  // fmodf
 | ||||||
| #include <fstream> | #include <fstream> | ||||||
|  | #include <memory>  // std::unique_ptr, std::make_unique
 | ||||||
| 
 | 
 | ||||||
| #include "SkinnedMeshRenderer.h" | #include "SkinnedMeshRenderer.h" | ||||||
| #include "ozz/animation/runtime/animation.h" | #include "ozz/animation/runtime/animation.h" | ||||||
|  | #include "ozz/animation/runtime/local_to_model_job.h" | ||||||
| #include "ozz/animation/runtime/sampling_job.h" | #include "ozz/animation/runtime/sampling_job.h" | ||||||
| #include "ozz/animation/runtime/skeleton.h" | #include "ozz/animation/runtime/skeleton.h" | ||||||
| #include "ozz/base/containers/vector.h" | #include "ozz/base/containers/vector.h" | ||||||
| @ -58,6 +61,7 @@ static void draw_imgui(ImDrawData*); | |||||||
| #include "ozz/base/io/stream.h" | #include "ozz/base/io/stream.h" | ||||||
| #include "ozz/base/log.h" | #include "ozz/base/log.h" | ||||||
| #include "ozz/base/maths/soa_transform.h" | #include "ozz/base/maths/soa_transform.h" | ||||||
|  | #include "ozz/base/maths/vec_float.h" | ||||||
| 
 | 
 | ||||||
| static struct { | static struct { | ||||||
|   struct { |   struct { | ||||||
| @ -65,7 +69,7 @@ static struct { | |||||||
|     ozz::animation::SamplingJob sampling_job; |     ozz::animation::SamplingJob sampling_job; | ||||||
|     ozz::vector<ozz::math::SoaTransform> local_matrices; |     ozz::vector<ozz::math::SoaTransform> local_matrices; | ||||||
|   } ozz; |   } ozz; | ||||||
|   sg_pass_action pass_action = {}; |   sg_pass_action pass_action; | ||||||
|   Camera camera; |   Camera camera; | ||||||
|   struct { |   struct { | ||||||
|     bool skeleton; |     bool skeleton; | ||||||
| @ -83,7 +87,7 @@ static struct { | |||||||
|     bool paused; |     bool paused; | ||||||
|     bool use_graph = false; |     bool use_graph = false; | ||||||
|   } time; |   } time; | ||||||
| } state = {}; | } state; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|   int32_t mousedX; |   int32_t mousedX; | ||||||
| @ -669,7 +673,6 @@ int main() { | |||||||
| 
 | 
 | ||||||
|   // Graph Editor
 |   // Graph Editor
 | ||||||
|   gApplicationConfig.graph_editor.config.SettingsFile = "graph_editor.json"; |   gApplicationConfig.graph_editor.config.SettingsFile = "graph_editor.json"; | ||||||
|   gApplicationConfig.graph_editor.config.NavigateButtonIndex = 2; |  | ||||||
|   gApplicationConfig.graph_editor.context = ax::NodeEditor::CreateEditor(&gApplicationConfig.graph_editor.config); |   gApplicationConfig.graph_editor.context = ax::NodeEditor::CreateEditor(&gApplicationConfig.graph_editor.config); | ||||||
| 
 | 
 | ||||||
|   // draw loop
 |   // draw loop
 | ||||||
| @ -712,7 +715,13 @@ int main() { | |||||||
|     // handle input
 |     // handle input
 | ||||||
|     handle_mouse(w, &gGuiInputState); |     handle_mouse(w, &gGuiInputState); | ||||||
| 
 | 
 | ||||||
|     if (!glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_RIGHT)) { |     if (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_RIGHT)) { | ||||||
|  |       if (gControlMode == ControlMode::ControlModeNone) { | ||||||
|  |         gControlMode = ControlMode::ControlModeFPS; | ||||||
|  |         Camera_CalcFromMatrix(&state.camera, &state.camera.mtxView[0]); | ||||||
|  |         glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_DISABLED); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|       gControlMode = ControlMode::ControlModeNone; |       gControlMode = ControlMode::ControlModeNone; | ||||||
|       glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); |       glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_NORMAL); | ||||||
|       Camera_Update( |       Camera_Update( | ||||||
| @ -756,11 +765,11 @@ int main() { | |||||||
| 
 | 
 | ||||||
|       Camera_Update( |       Camera_Update( | ||||||
|           &state.camera, |           &state.camera, | ||||||
|           offscreen_viewport.size[0], |           cur_width, | ||||||
|           offscreen_viewport.size[1], |           cur_height, | ||||||
|           static_cast<float>(state.time.frame), |           static_cast<float>(state.time.frame), | ||||||
|           static_cast<float>(gGuiInputState.mousedX), |           gGuiInputState.mousedX, | ||||||
|           static_cast<float>(gGuiInputState.mousedY), |           gGuiInputState.mousedY, | ||||||
|           camera_accel); |           camera_accel); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -813,7 +822,8 @@ int main() { | |||||||
|         // For simplicity use first animation data output
 |         // For simplicity use first animation data output
 | ||||||
|         const std::vector<Socket>& graph_output_sockets = |         const std::vector<Socket>& graph_output_sockets = | ||||||
|             anim_graph.getGraphOutputs(); |             anim_graph.getGraphOutputs(); | ||||||
|         for (const auto & output : graph_output_sockets) { |         for (int i = 0; i < graph_output_sockets.size(); i++) { | ||||||
|  |           const Socket& output = graph_output_sockets[i]; | ||||||
|           if (output.m_type == SocketType::SocketTypeAnimation) { |           if (output.m_type == SocketType::SocketTypeAnimation) { | ||||||
|             anim_graph.SetOutput(output.m_name.c_str(), &anim_graph_output); |             anim_graph.SetOutput(output.m_name.c_str(), &anim_graph_output); | ||||||
|           } |           } | ||||||
| @ -842,17 +852,9 @@ int main() { | |||||||
| 
 | 
 | ||||||
|         ImGui::Begin("Viewport", &gApplicationConfig.viewport_widget.visible); |         ImGui::Begin("Viewport", &gApplicationConfig.viewport_widget.visible); | ||||||
| 
 | 
 | ||||||
|         if (ImGui::IsWindowHovered() && ImGui::IsMouseDown(ImGuiMouseButton_Right)) { |  | ||||||
|           if (gControlMode == ControlMode::ControlModeNone) { |  | ||||||
|             gControlMode = ControlMode::ControlModeFPS; |  | ||||||
|             Camera_CalcFromMatrix(&state.camera, &state.camera.mtxView[0]); |  | ||||||
|             glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_DISABLED); |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         ImVec2 viewport_widget_size = ImGui::GetWindowSize(); |         ImVec2 viewport_widget_size = ImGui::GetWindowSize(); | ||||||
|         gApplicationConfig.viewport_widget.size[0] = static_cast<int>(viewport_widget_size.x); |         gApplicationConfig.viewport_widget.size[0] = viewport_widget_size.x; | ||||||
|         gApplicationConfig.viewport_widget.size[1] = static_cast<int>(viewport_widget_size.y); |         gApplicationConfig.viewport_widget.size[1] = viewport_widget_size.y; | ||||||
| 
 | 
 | ||||||
|         ImGui::Text( |         ImGui::Text( | ||||||
|             "Viewport size: %d, %d", |             "Viewport size: %d, %d", | ||||||
| @ -863,15 +865,15 @@ int main() { | |||||||
| 
 | 
 | ||||||
|         int* current_size = offscreen_viewport.size; |         int* current_size = offscreen_viewport.size; | ||||||
| 
 | 
 | ||||||
|         if (static_cast<float>(current_size[0]) != content_size[0] |         if (current_size[0] != content_size[0] | ||||||
|             || static_cast<float>(current_size[1]) != content_size[1] |             || current_size[1] != content_size[1] | ||||||
|             || offscreen_viewport.pass.id == 0) { |             || offscreen_viewport.pass.id == 0) { | ||||||
|           offscreen_viewport.Resize(static_cast<int>(content_size[0]), static_cast<int>(content_size[1])); |           offscreen_viewport.Resize(content_size[0], content_size[1]); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         ImGui::Image( |         ImGui::Image( | ||||||
|             (ImTextureID)(uintptr_t)offscreen_viewport.color_image.id, |             (ImTextureID)(uintptr_t)offscreen_viewport.color_image.id, | ||||||
|             ImVec2(static_cast<float>(offscreen_viewport.size[0]), static_cast<float>(offscreen_viewport.size[1])), |             ImVec2(offscreen_viewport.size[0], offscreen_viewport.size[1]), | ||||||
|             ImVec2(0.0f, 1.0f), |             ImVec2(0.0f, 1.0f), | ||||||
|             ImVec2(1.0f, 0.0f)); |             ImVec2(1.0f, 0.0f)); | ||||||
| 
 | 
 | ||||||
| @ -894,13 +896,13 @@ int main() { | |||||||
|       if (gApplicationConfig.skinned_mesh_widget.visible) { |       if (gApplicationConfig.skinned_mesh_widget.visible) { | ||||||
|         ImGui::SetNextWindowPos( |         ImGui::SetNextWindowPos( | ||||||
|             ImVec2( |             ImVec2( | ||||||
|                 static_cast<float>(gApplicationConfig.skinned_mesh_widget.position[0]), |                 gApplicationConfig.skinned_mesh_widget.position[0], | ||||||
|                 static_cast<float>(gApplicationConfig.skinned_mesh_widget.position[1])), |                 gApplicationConfig.skinned_mesh_widget.position[1]), | ||||||
|             ImGuiCond_FirstUseEver); |             ImGuiCond_FirstUseEver); | ||||||
|         ImGui::SetNextWindowSize( |         ImGui::SetNextWindowSize( | ||||||
|             ImVec2( |             ImVec2( | ||||||
|                 static_cast<float>(gApplicationConfig.skinned_mesh_widget.size[0]), |                 gApplicationConfig.skinned_mesh_widget.size[0], | ||||||
|                 static_cast<float>(gApplicationConfig.skinned_mesh_widget.size[1])), |                 gApplicationConfig.skinned_mesh_widget.size[1]), | ||||||
|             ImGuiCond_FirstUseEver); |             ImGuiCond_FirstUseEver); | ||||||
| 
 | 
 | ||||||
|         ImGui::Begin( |         ImGui::Begin( | ||||||
| @ -909,15 +911,15 @@ int main() { | |||||||
| 
 | 
 | ||||||
|         ImVec2 skinned_mesh_widget_position = ImGui::GetWindowPos(); |         ImVec2 skinned_mesh_widget_position = ImGui::GetWindowPos(); | ||||||
|         gApplicationConfig.skinned_mesh_widget.position[0] = |         gApplicationConfig.skinned_mesh_widget.position[0] = | ||||||
|             static_cast<int>(skinned_mesh_widget_position.x); |             skinned_mesh_widget_position.x; | ||||||
|         gApplicationConfig.skinned_mesh_widget.position[1] = |         gApplicationConfig.skinned_mesh_widget.position[1] = | ||||||
|             static_cast<int>(skinned_mesh_widget_position.y); |             skinned_mesh_widget_position.y; | ||||||
| 
 | 
 | ||||||
|         ImVec2 skinned_mesh_widget_size = ImGui::GetWindowSize(); |         ImVec2 skinned_mesh_widget_size = ImGui::GetWindowSize(); | ||||||
|         gApplicationConfig.skinned_mesh_widget.size[0] = |         gApplicationConfig.skinned_mesh_widget.size[0] = | ||||||
|             static_cast<int>(skinned_mesh_widget_size.x); |             skinned_mesh_widget_size.x; | ||||||
|         gApplicationConfig.skinned_mesh_widget.size[1] = |         gApplicationConfig.skinned_mesh_widget.size[1] = | ||||||
|             static_cast<int>(skinned_mesh_widget_size.y); |             skinned_mesh_widget_size.y; | ||||||
| 
 | 
 | ||||||
|         SkinnedMeshWidget(&skinned_mesh); |         SkinnedMeshWidget(&skinned_mesh); | ||||||
| 
 | 
 | ||||||
| @ -927,13 +929,13 @@ int main() { | |||||||
|       if (gApplicationConfig.animation_player_widget.visible) { |       if (gApplicationConfig.animation_player_widget.visible) { | ||||||
|         ImGui::SetNextWindowPos( |         ImGui::SetNextWindowPos( | ||||||
|             ImVec2( |             ImVec2( | ||||||
|                 static_cast<float>(gApplicationConfig.animation_player_widget.position[0]), |                 gApplicationConfig.animation_player_widget.position[0], | ||||||
|                 static_cast<float>(gApplicationConfig.animation_player_widget.position[1])), |                 gApplicationConfig.animation_player_widget.position[1]), | ||||||
|             ImGuiCond_FirstUseEver); |             ImGuiCond_FirstUseEver); | ||||||
|         ImGui::SetNextWindowSize( |         ImGui::SetNextWindowSize( | ||||||
|             ImVec2( |             ImVec2( | ||||||
|                 static_cast<float>(gApplicationConfig.animation_player_widget.size[0]), |                 gApplicationConfig.animation_player_widget.size[0], | ||||||
|                 static_cast<float>(gApplicationConfig.animation_player_widget.size[1])), |                 gApplicationConfig.animation_player_widget.size[1]), | ||||||
|             ImGuiCond_FirstUseEver); |             ImGuiCond_FirstUseEver); | ||||||
| 
 | 
 | ||||||
|         ImGui::Begin( |         ImGui::Begin( | ||||||
| @ -942,15 +944,15 @@ int main() { | |||||||
| 
 | 
 | ||||||
|         ImVec2 animation_player_widget_position = ImGui::GetWindowPos(); |         ImVec2 animation_player_widget_position = ImGui::GetWindowPos(); | ||||||
|         gApplicationConfig.animation_player_widget.position[0] = |         gApplicationConfig.animation_player_widget.position[0] = | ||||||
|             static_cast<int>(animation_player_widget_position.x); |             animation_player_widget_position.x; | ||||||
|         gApplicationConfig.animation_player_widget.position[1] = |         gApplicationConfig.animation_player_widget.position[1] = | ||||||
|             static_cast<int>(animation_player_widget_position.y); |             animation_player_widget_position.y; | ||||||
| 
 | 
 | ||||||
|         ImVec2 animation_player_widget_size = ImGui::GetWindowSize(); |         ImVec2 animation_player_widget_size = ImGui::GetWindowSize(); | ||||||
|         gApplicationConfig.animation_player_widget.size[0] = |         gApplicationConfig.animation_player_widget.size[0] = | ||||||
|             static_cast<int>(animation_player_widget_size.x); |             animation_player_widget_size.x; | ||||||
|         gApplicationConfig.animation_player_widget.size[1] = |         gApplicationConfig.animation_player_widget.size[1] = | ||||||
|             static_cast<int>(animation_player_widget_size.y); |             animation_player_widget_size.y; | ||||||
| 
 | 
 | ||||||
|         if (anim_graph.m_nodes.size() > 0) { |         if (anim_graph.m_nodes.size() > 0) { | ||||||
|           ImGui::Checkbox("Use Graph", &state.time.use_graph); |           ImGui::Checkbox("Use Graph", &state.time.use_graph); | ||||||
| @ -971,7 +973,7 @@ int main() { | |||||||
|                   "Animation", |                   "Animation", | ||||||
|                   &selected, |                   &selected, | ||||||
|                   items, |                   items, | ||||||
|                   static_cast<int>(skinned_mesh.m_animations.size()))) { |                   skinned_mesh.m_animations.size())) { | ||||||
|             state.ozz.animation = skinned_mesh.m_animations[selected]; |             state.ozz.animation = skinned_mesh.m_animations[selected]; | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
| @ -1013,7 +1015,7 @@ int main() { | |||||||
|       if (state.ozz.animation != nullptr) { |       if (state.ozz.animation != nullptr) { | ||||||
|         state.ozz.sampling_job.animation = state.ozz.animation; |         state.ozz.sampling_job.animation = state.ozz.animation; | ||||||
|         state.ozz.sampling_job.ratio = |         state.ozz.sampling_job.ratio = | ||||||
|             static_cast<float>(state.time.absolute) / state.ozz.animation->duration(); |             state.time.absolute / state.ozz.animation->duration(); | ||||||
|         state.ozz.sampling_job.context = &skinned_mesh.m_sampling_context; |         state.ozz.sampling_job.context = &skinned_mesh.m_sampling_context; | ||||||
|         state.ozz.sampling_job.output = |         state.ozz.sampling_job.output = | ||||||
|             ozz::make_span(skinned_mesh.m_local_matrices); |             ozz::make_span(skinned_mesh.m_local_matrices); | ||||||
| @ -1026,7 +1028,7 @@ int main() { | |||||||
|         skinned_mesh.CalcModelMatrices(); |         skinned_mesh.CalcModelMatrices(); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (state.time.use_graph && !anim_graph.m_nodes.empty() |       if (state.time.use_graph && anim_graph.m_nodes.size() > 0 | ||||||
|           && state.time.anim_update_time > 0.) { |           && state.time.anim_update_time > 0.) { | ||||||
|         anim_graph.markActiveNodes(); |         anim_graph.markActiveNodes(); | ||||||
|         anim_graph.updateTime(state.time.anim_update_time); |         anim_graph.updateTime(state.time.anim_update_time); | ||||||
| @ -1174,6 +1176,9 @@ int main() { | |||||||
|     draw_imgui(ImGui::GetDrawData()); |     draw_imgui(ImGui::GetDrawData()); | ||||||
|     sg_end_pass(); |     sg_end_pass(); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     sg_commit(); |     sg_commit(); | ||||||
|     glfwSwapBuffers(w); |     glfwSwapBuffers(w); | ||||||
|     glfwPollEvents(); |     glfwPollEvents(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user