Updated ozz-animation to version 0.14.1.

This commit is contained in:
Martin Felis
2023-04-15 00:07:29 +02:00
parent eb70c06c57
commit 72bcf8a21b
29 changed files with 1389 additions and 1071 deletions
+67 -36
View File
@@ -9,6 +9,7 @@
#define SOKOL_IMPL
#define SOKOL_GLCORE33
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "sokol_time.h"
#define SOKOL_GL_IMPL
#include "util/sokol_gl.h"
@@ -28,6 +29,7 @@ const int MaxVertices = (1 << 16);
const int MaxIndices = MaxVertices * 3;
uint64_t last_time = 0;
const int cMSAASampleCount = 8;
sg_pass_action pass_action;
sg_pipeline pip;
@@ -42,7 +44,6 @@ static void draw_imgui(ImDrawData*);
#define HANDMADE_MATH_IMPLEMENTATION
#define HANDMADE_MATH_NO_SSE
#include "HandmadeMath.h"
#include "camera.h"
// ozz-animation headers
#include <cmath> // fmodf
@@ -77,7 +78,7 @@ static struct {
struct {
double frame;
double anim_update_time;
float absolute;
double absolute;
uint64_t laptime;
float factor;
float anim_ratio;
@@ -107,6 +108,7 @@ struct Viewport {
sg_pass_action pass_action = {};
sg_pass pass = {};
sg_pipeline pip = {};
sgl_pipeline glpip = {};
sg_bindings bind = {};
sg_image color_image = {};
sg_image depth_image = {};
@@ -138,7 +140,7 @@ struct Viewport {
.width = this->size[0],
.height = this->size[1],
.pixel_format = SG_PIXELFORMAT_RGBA8,
.sample_count = 4,
.sample_count = cMSAASampleCount,
.min_filter = SG_FILTER_LINEAR,
.mag_filter = SG_FILTER_LINEAR,
.wrap_u = SG_WRAP_REPEAT,
@@ -155,6 +157,14 @@ struct Viewport {
offscreen_pass_desc.label = "offscreen-pass";
this->pass = sg_make_pass(&offscreen_pass_desc);
sg_pipeline_desc gl_pipeline_desc = {
.depth = {
.compare = SG_COMPAREFUNC_LESS_EQUAL,
.write_enabled = true
},
.cull_mode = SG_CULLMODE_BACK
};
}
};
@@ -350,11 +360,8 @@ ApplicationConfig gApplicationConfig;
static uint8_t skel_data_buffer[4 * 1024];
static uint8_t anim_data_buffer[32 * 1024];
static void draw_grid(void);
static void draw_ui(void);
// static void skeleton_data_loaded(const sfetch_response_t* response);
// static void animation_data_loaded(const sfetch_response_t* response);
static void frame(void);
static void draw_grid();
static void frame();
void handle_mouse(GLFWwindow* w, GuiInputState* io_input_state) {
if (!glfwGetWindowAttrib(w, GLFW_FOCUSED)) {
@@ -414,6 +421,19 @@ void save_application_config(const char* filename) {
output_file.close();
}
void sokol_logger(
const char* tag,
uint32_t log_level,
uint32_t log_item_id,
const char*
message_or_null, // a message string, may be nullptr in release mode
uint32_t line_nr, // line number in sokol_gl.h
const char*
filename_or_null, // source filename, may be nullptr in release mode
void* user_data) {
fprintf(stderr, "%s\n", message_or_null);
}
int main() {
// window and GL context via GLFW and flextGL
glfwInit();
@@ -423,7 +443,8 @@ int main() {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE);
glfwWindowHint(GLFW_SAMPLES, 16);
GLFWwindow* w = glfwCreateWindow(Width, Height, "ATP Editor", 0, 0);
GLFWwindow* w =
glfwCreateWindow(Width, Height, "ATP Editor", nullptr, nullptr);
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
@@ -476,16 +497,19 @@ int main() {
// setup sokol_gfx and sokol_time
stm_setup();
sg_desc desc = {};
sg_desc desc = {.logger = {.func = slog_func}};
sg_setup(&desc);
assert(sg_isvalid());
// setup sokol-gl
sgl_desc_t sgldesc = {
.sample_count = 4
};
.sample_count = cMSAASampleCount,
.logger = sokol_logger};
sgl_setup(&sgldesc);
// sgl_context_desc_t sgl_context_desc = {};
// sgl_context ctx = sgl_make_context(&sgl_context_desc);
SkinnedMeshResource skinned_mesh_resource;
skinned_mesh_resource.loadFromFile("../media/SampleSkinnedMesh.json");
@@ -602,6 +626,7 @@ int main() {
pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA;
pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
pip_desc.colors[0].write_mask = SG_COLORMASK_RGB;
pip_desc.label = "imgui-rendering";
pip = sg_make_pipeline(&pip_desc);
// initial clear color
@@ -625,7 +650,7 @@ int main() {
if (state.ozz.animation != nullptr) {
state.time.absolute =
fmodf(state.time.absolute, state.ozz.animation->duration());
fmod(state.time.absolute, state.ozz.animation->duration());
}
// Update window state
@@ -643,7 +668,6 @@ int main() {
glfwGetFramebufferSize(w, &cur_width, &cur_height);
// this is standard ImGui demo code
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2(float(cur_width), float(cur_height));
io.DeltaTime = (float)stm_sec(stm_laptime(&last_time));
ImGui::NewFrame();
@@ -664,7 +688,7 @@ int main() {
&state.camera,
offscreen_viewport.size[0],
offscreen_viewport.size[1],
state.time.frame,
static_cast<float>(state.time.frame),
0,
0,
nullptr);
@@ -703,7 +727,7 @@ int main() {
&state.camera,
cur_width,
cur_height,
state.time.frame,
static_cast<float>(state.time.frame),
gGuiInputState.mousedX,
gGuiInputState.mousedY,
camera_accel);
@@ -769,22 +793,22 @@ int main() {
if (gApplicationConfig.viewport_widget.visible) {
ImGui::SetNextWindowPos(
ImVec2(
gApplicationConfig.viewport_widget.position[0],
gApplicationConfig.viewport_widget.position[1]),
static_cast<float>(
gApplicationConfig.viewport_widget.position[0]),
static_cast<float>(
gApplicationConfig.viewport_widget.position[1])),
ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(
ImVec2(
gApplicationConfig.viewport_widget.size[0],
gApplicationConfig.viewport_widget.size[1]),
static_cast<float>(gApplicationConfig.viewport_widget.size[0]),
static_cast<float>(gApplicationConfig.viewport_widget.size[1])),
ImGuiCond_FirstUseEver);
ImGui::Begin("Viewport", &gApplicationConfig.viewport_widget.visible);
ImVec2 viewport_widget_size = ImGui::GetWindowSize();
gApplicationConfig.viewport_widget.size[0] =
viewport_widget_size.x;
gApplicationConfig.viewport_widget.size[1] =
viewport_widget_size.y;
gApplicationConfig.viewport_widget.size[0] = viewport_widget_size.x;
gApplicationConfig.viewport_widget.size[1] = viewport_widget_size.y;
ImGui::Text(
"Viewport size: %d, %d",
@@ -795,15 +819,15 @@ int main() {
int* current_size = offscreen_viewport.size;
if (current_size[0] != content_size[0] || current_size[1] != content_size[1]) {
if (current_size[0] != content_size[0]
|| current_size[1] != content_size[1]
|| offscreen_viewport.pass.id == 0) {
offscreen_viewport.Resize(content_size[0], content_size[1]);
}
ImGui::Image(
(ImTextureID)(uintptr_t)offscreen_viewport.color_image.id,
ImVec2(
offscreen_viewport.size[0],
offscreen_viewport.size[1]),
ImVec2(offscreen_viewport.size[0], offscreen_viewport.size[1]),
ImVec2(0.0f, 1.0f),
ImVec2(1.0f, 0.0f));
@@ -927,13 +951,16 @@ int main() {
if (state.ozz.animation != nullptr) {
ImGui::SameLine();
ImGui::SliderFloat(
"Time",
&state.time.absolute,
0,
state.ozz.animation->duration(),
"%.3f",
0);
float time_absolute_float = static_cast<float>(state.time.absolute);
if (ImGui::SliderFloat(
"Time",
&time_absolute_float,
0,
state.ozz.animation->duration(),
"%.3f",
0)) {
state.time.absolute = time_absolute_float;
}
}
ImGui::End();
@@ -1012,8 +1039,9 @@ int main() {
ImGui::ShowDemoWindow();
}
// Rendering of the offscreen scene
sgl_defaults();
sg_begin_pass(offscreen_viewport.pass, &offscreen_viewport.pass_action);
sgl_load_pipeline(offscreen_viewport.glpip);
sgl_draw();
sg_end_pass();
@@ -1023,6 +1051,9 @@ int main() {
draw_imgui(ImGui::GetDrawData());
sg_end_pass();
sg_commit();
glfwSwapBuffers(w);
glfwPollEvents();