Updated ozz-animation to version 0.14.3 (commit 92c392b667844)

This commit is contained in:
Martin Felis
2024-03-17 12:47:11 +01:00
parent 1ef53d6486
commit c7d2d195a3
28 changed files with 284 additions and 282 deletions
+21 -25
View File
@@ -528,31 +528,32 @@ bool Application::Gui() {
}
bool Application::FrameworkGui() {
char label[64];
// Downcast to public imgui.
ImGui* im_gui = im_gui_.get();
{ // Render statistics
static bool open = true;
ImGui::OpenClose stat_oc(im_gui, "Statistics", &open);
if (open) {
char szLabel[64];
{ // FPS
Record::Statistics statistics = fps_->GetStatistics();
std::sprintf(szLabel, "FPS: %.0f",
statistics.mean == 0.f ? 0.f : 1000.f / statistics.mean);
std::snprintf(label, sizeof(label), "FPS: %.0f",
statistics.mean == 0.f ? 0.f : 1000.f / statistics.mean);
static bool fps_open = false;
ImGui::OpenClose stats(im_gui, szLabel, &fps_open);
ImGui::OpenClose stats(im_gui, label, &fps_open);
if (fps_open) {
std::sprintf(szLabel, "Frame: %.2f ms", statistics.mean);
im_gui->DoGraph(szLabel, 0.f, statistics.max, statistics.latest,
std::snprintf(label, sizeof(label), "Frame: %.2f ms",
statistics.mean);
im_gui->DoGraph(label, 0.f, statistics.max, statistics.latest,
fps_->cursor(), fps_->record_begin(),
fps_->record_end());
}
}
{ // Update time
Record::Statistics statistics = update_time_->GetStatistics();
std::sprintf(szLabel, "Update: %.2f ms", statistics.mean);
std::snprintf(label, sizeof(label), "Update: %.2f ms", statistics.mean);
static bool update_open = true; // This is the most relevant for ozz.
ImGui::OpenClose stats(im_gui, szLabel, &update_open);
ImGui::OpenClose stats(im_gui, label, &update_open);
if (update_open) {
im_gui->DoGraph(nullptr, 0.f, statistics.max, statistics.latest,
update_time_->cursor(), update_time_->record_begin(),
@@ -561,9 +562,9 @@ bool Application::FrameworkGui() {
}
{ // Render time
Record::Statistics statistics = render_time_->GetStatistics();
std::sprintf(szLabel, "Render: %.2f ms", statistics.mean);
std::snprintf(label, sizeof(label), "Render: %.2f ms", statistics.mean);
static bool render_open = false;
ImGui::OpenClose stats(im_gui, szLabel, &render_open);
ImGui::OpenClose stats(im_gui, label, &render_open);
if (render_open) {
im_gui->DoGraph(nullptr, 0.f, statistics.max, statistics.latest,
render_time_->cursor(), render_time_->record_begin(),
@@ -580,18 +581,15 @@ bool Application::FrameworkGui() {
im_gui->DoButton("Freeze", true, &freeze_);
im_gui->DoCheckBox("Fix update rate", &fix_update_rate, true);
if (!fix_update_rate) {
char sz_factor[64];
std::sprintf(sz_factor, "Time factor: %.2f", time_factor_);
im_gui->DoSlider(sz_factor, -5.f, 5.f, &time_factor_);
std::snprintf(label, sizeof(label), "Time factor: %.2f", time_factor_);
im_gui->DoSlider(label, -5.f, 5.f, &time_factor_);
if (im_gui->DoButton("Reset time factor", time_factor_ != 1.f)) {
time_factor_ = 1.f;
}
} else {
char sz_fixed_update_rate[64];
std::sprintf(sz_fixed_update_rate, "Update rate: %.0f fps",
fixed_update_rate);
im_gui->DoSlider(sz_fixed_update_rate, 1.f, 200.f, &fixed_update_rate,
.5f, true);
std::snprintf(label, sizeof(label), "Update rate: %.0f fps",
fixed_update_rate);
im_gui->DoSlider(label, 1.f, 200.f, &fixed_update_rate, .5f, true);
if (im_gui->DoButton("Reset update rate", fixed_update_rate != 60.f)) {
fixed_update_rate = 60.f;
}
@@ -615,10 +613,9 @@ bool Application::FrameworkGui() {
}
// Vertical sync & swap interval
bool changed = im_gui->DoCheckBox("Vertical sync", &vertical_sync_);
char szLabel[64];
std::sprintf(szLabel, "Swap interval: %d", swap_interval_);
std::snprintf(label, sizeof(label), "Swap interval: %d", swap_interval_);
changed |=
im_gui->DoSlider(szLabel, 1, 4, &swap_interval_, 1.f, vertical_sync_);
im_gui->DoSlider(label, 1, 4, &swap_interval_, 1.f, vertical_sync_);
if (changed) {
glfwSwapInterval(vertical_sync_ ? swap_interval_ : 0);
}
@@ -640,10 +637,9 @@ bool Application::FrameworkGui() {
}
}
char szResolution[64];
std::sprintf(szResolution, "Resolution: %dx%d", resolution_.width,
resolution_.height);
if (im_gui->DoSlider(szResolution, 0, kNumPresets - 1, &preset_lookup)) {
std::snprintf(label, sizeof(label), "Resolution: %dx%d", resolution_.width,
resolution_.height);
if (im_gui->DoSlider(label, 0, kNumPresets - 1, &preset_lookup)) {
// Resolution changed.
resolution_ = resolution_presets[preset_lookup];
glfwSetWindowSize(resolution_.width, resolution_.height);
+1 -1
View File
@@ -149,7 +149,7 @@ class Application {
enum LoopStatus {
kContinue, // Can continue with next loop.
kBreak, // Should stop looping (ex: exit).
kBreakFailure, // // Should stop looping beacause something went wrong.
kBreakFailure, // Should stop looping because something went wrong.
};
LoopStatus OneLoop(int _loops);
@@ -100,7 +100,7 @@ bool FormatFloat(float _value, char* _string, const char* _string_end) {
if (!_string || _string_end - _string < 8 + precision + 1) {
return false;
}
std::sprintf(_string, "%.2g\n", _value);
std::snprintf(_string, _string_end - _string, "%.2g\n", _value);
// Removes unnecessary '0' digits in the exponent.
char* exponent = strchr(_string, 'e');
@@ -160,12 +160,12 @@ bool Shooter::Process() {
GL(BindBuffer(GL_PIXEL_PACK_BUFFER, shot.pbo));
const void* pixels = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
if (pixels) {
char name[16];
sprintf(name, "%06d.tga", shot_number_++);
char filename[16];
std::snprintf(filename, sizeof(filename), "%06d.tga", shot_number_++);
ozz::sample::image::WriteTGA(name, shot.width, shot.height, image_format_,
reinterpret_cast<const uint8_t*>(pixels),
false);
ozz::sample::image::WriteTGA(
filename, shot.width, shot.height, image_format_,
reinterpret_cast<const uint8_t*>(pixels), false);
GL(UnmapBuffer(GL_PIXEL_PACK_BUFFER));
}
GL(BindBuffer(GL_PIXEL_PACK_BUFFER, 0));
+22 -21
View File
@@ -110,21 +110,22 @@ bool PlaybackController::OnGui(const animation::Animation& _animation,
_im_gui->DoCheckBox("Loop", &loop_, _enabled);
char szLabel[64];
char label[64];
// Uses a local copy of time_ so that set_time is used to actually apply
// changes. Otherwise previous time would be incorrect.
float ratio = time_ratio();
std::sprintf(szLabel, "Animation time: %.2f", ratio * _animation.duration());
if (_im_gui->DoSlider(szLabel, 0.f, 1.f, &ratio, 1.f,
std::snprintf(label, sizeof(label), "Animation time: %.2f",
ratio * _animation.duration());
if (_im_gui->DoSlider(label, 0.f, 1.f, &ratio, 1.f,
_enabled && _allow_set_time)) {
set_time_ratio(ratio);
// Pause the time if slider as moved.
play_ = false;
time_changed = true;
}
std::sprintf(szLabel, "Playback speed: %.2f", playback_speed_);
_im_gui->DoSlider(szLabel, -5.f, 5.f, &playback_speed_, 1.f, _enabled);
std::snprintf(label, sizeof(label), "Playback speed: %.2f", playback_speed_);
_im_gui->DoSlider(label, -5.f, 5.f, &playback_speed_, 1.f, _enabled);
// Allow to reset speed if it is not the default value.
if (_im_gui->DoButton("Reset playback speed",
@@ -139,7 +140,7 @@ bool OnRawSkeletonJointGui(
ozz::sample::ImGui* _im_gui,
ozz::animation::offline::RawSkeleton::Joint::Children* _children,
ozz::vector<bool>::iterator* _oc_state) {
char txt[255];
char label[255];
bool modified = false;
for (size_t i = 0; i < _children->size(); ++i) {
@@ -152,23 +153,23 @@ bool OnRawSkeletonJointGui(
// Translation
ozz::math::Float3& translation = joint.transform.translation;
_im_gui->DoLabel("Translation");
sprintf(txt, "x %.2g", translation.x);
modified |= _im_gui->DoSlider(txt, -1.f, 1.f, &translation.x);
sprintf(txt, "y %.2g", translation.y);
modified |= _im_gui->DoSlider(txt, -1.f, 1.f, &translation.y);
sprintf(txt, "z %.2g", translation.z);
modified |= _im_gui->DoSlider(txt, -1.f, 1.f, &translation.z);
snprintf(label, sizeof(label), "x %.2g", translation.x);
modified |= _im_gui->DoSlider(label, -1.f, 1.f, &translation.x);
snprintf(label, sizeof(label), "y %.2g", translation.y);
modified |= _im_gui->DoSlider(label, -1.f, 1.f, &translation.y);
snprintf(label, sizeof(label), "z %.2g", translation.z);
modified |= _im_gui->DoSlider(label, -1.f, 1.f, &translation.z);
// Rotation (in euler form)
ozz::math::Quaternion& rotation = joint.transform.rotation;
_im_gui->DoLabel("Rotation");
ozz::math::Float3 euler = ToEuler(rotation) * ozz::math::kRadianToDegree;
sprintf(txt, "x %.3g", euler.x);
bool euler_modified = _im_gui->DoSlider(txt, -180.f, 180.f, &euler.x);
sprintf(txt, "y %.3g", euler.y);
euler_modified |= _im_gui->DoSlider(txt, -180.f, 180.f, &euler.y);
sprintf(txt, "z %.3g", euler.z);
euler_modified |= _im_gui->DoSlider(txt, -180.f, 180.f, &euler.z);
snprintf(label, sizeof(label), "x %.3g", euler.x);
bool euler_modified = _im_gui->DoSlider(label, -180.f, 180.f, &euler.x);
snprintf(label, sizeof(label), "y %.3g", euler.y);
euler_modified |= _im_gui->DoSlider(label, -180.f, 180.f, &euler.y);
snprintf(label, sizeof(label), "z %.3g", euler.z);
euler_modified |= _im_gui->DoSlider(label, -180.f, 180.f, &euler.z);
if (euler_modified) {
modified = true;
ozz::math::Float3 euler_rad = euler * ozz::math::kDegreeToRadian;
@@ -179,8 +180,8 @@ bool OnRawSkeletonJointGui(
// Scale (must be uniform and not 0)
_im_gui->DoLabel("Scale");
ozz::math::Float3& scale = joint.transform.scale;
sprintf(txt, "%.2g", scale.x);
if (_im_gui->DoSlider(txt, -1.f, 1.f, &scale.x)) {
snprintf(label, sizeof(label), "%.2g", scale.x);
if (_im_gui->DoSlider(label, -1.f, 1.f, &scale.x)) {
modified = true;
scale.y = scale.z = scale.x = scale.x != 0.f ? scale.x : .01f;
}
@@ -328,7 +329,7 @@ bool LoadAnimation(const char* _filename,
}
bool LoadRawAnimation(const char* _filename,
ozz::animation::offline::RawAnimation* _animation) {
ozz::animation::offline::RawAnimation* _animation) {
assert(_filename && _animation);
ozz::log::Out() << "Loading raw animation archive: " << _filename << "."
<< std::endl;