diff --git a/samples/additive/sample_additive.cc b/samples/additive/sample_additive.cc index d033bbc1c..54a915a72 100644 --- a/samples/additive/sample_additive.cc +++ b/samples/additive/sample_additive.cc @@ -294,7 +294,8 @@ class AdditiveBlendSampleApplication : public ozz::sample::Application { _bound->min = hand_position - extent; _bound->max = hand_position + extent; } else { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds( + make_span(models_), ozz::math::Float4x4::identity(), _bound); } } diff --git a/samples/attach/sample_attach.cc b/samples/attach/sample_attach.cc index d425f6273..e8bd6ffd7 100644 --- a/samples/attach/sample_attach.cc +++ b/samples/attach/sample_attach.cc @@ -179,7 +179,8 @@ class AttachSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/baked/sample_baked.cc b/samples/baked/sample_baked.cc index c70f220fa..c534d147f 100644 --- a/samples/baked/sample_baked.cc +++ b/samples/baked/sample_baked.cc @@ -149,7 +149,8 @@ class BakedSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/blend/sample_blend.cc b/samples/blend/sample_blend.cc index 0f6860aa0..be44457a5 100644 --- a/samples/blend/sample_blend.cc +++ b/samples/blend/sample_blend.cc @@ -247,7 +247,8 @@ class BlendSampleApplication : public ozz::sample::Application { for (int i = 0; i < kNumLayers; ++i) { Sampler& sampler = samplers_[i]; - std::snprintf(label, sizeof(label), "Weight %d: %.2f", i, sampler.weight); + std::snprintf(label, sizeof(label), "Weight %d: %.2f", i, + sampler.weight); _im_gui->DoSlider(label, 0.f, 1.f, &sampler.weight, 1.f, manual_); } @@ -279,7 +280,8 @@ class BlendSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/framework/utils.cc b/samples/framework/utils.cc index da8eefaad..0061a5908 100644 --- a/samples/framework/utils.cc +++ b/samples/framework/utils.cc @@ -205,6 +205,7 @@ bool RawSkeletonEditor::OnGui(animation::offline::RawSkeleton* _skeleton, // Uses LocalToModelJob to compute skeleton model space posture, then forwards // to ComputePostureBounds void ComputeSkeletonBounds(const animation::Skeleton& _skeleton, + const ozz::math::Float4x4& _transform, math::Box* _bound) { using ozz::math::Float4x4; @@ -228,38 +229,36 @@ void ComputeSkeletonBounds(const animation::Skeleton& _skeleton, job.skeleton = &_skeleton; if (job.Run()) { // Forwards to posture function. - ComputePostureBounds(job.output, _bound); + ComputePostureBounds(job.output, _transform, _bound); } } // Loop through matrices and collect min and max bounds. -void ComputePostureBounds(ozz::span _matrices, +void ComputePostureBounds(ozz::span _models, + const ozz::math::Float4x4& _transform, math::Box* _bound) { assert(_bound); // Set a default box. *_bound = ozz::math::Box(); - if (_matrices.empty()) { + if (_models.empty()) { return; } // Loops through matrices and stores min/max. - // Matrices array cannot be empty, it was checked at the beginning of the - // function. - const ozz::math::Float4x4* current = _matrices.begin(); - math::SimdFloat4 min = current->cols[3]; - math::SimdFloat4 max = current->cols[3]; - ++current; - while (current < _matrices.end()) { - min = math::Min(min, current->cols[3]); - max = math::Max(max, current->cols[3]); - ++current; + math::SimdFloat4 min = + math::simd_float4::Load1(std::numeric_limits::max()); + math::SimdFloat4 max = -min; + + for (const auto& current : _models) { + min = math::Min(min, current.cols[3]); + max = math::Max(max, current.cols[3]); } // Stores in math::Box structure. - math::Store3PtrU(min, &_bound->min.x); - math::Store3PtrU(max, &_bound->max.x); + math::Store3PtrU(TransformPoint(_transform, min), &_bound->min.x); + math::Store3PtrU(TransformPoint(_transform, max), &_bound->max.x); return; } diff --git a/samples/framework/utils.h b/samples/framework/utils.h index 85a6c9a1a..a1354e43e 100644 --- a/samples/framework/utils.h +++ b/samples/framework/utils.h @@ -127,11 +127,13 @@ class PlaybackController { // skeleton's joints in model space. // _bound must be a valid math::Box instance. void ComputeSkeletonBounds(const animation::Skeleton& _skeleton, + const ozz::math::Float4x4& _transform, math::Box* _bound); // Computes the bounding box of posture defines be _matrices range. // _bound must be a valid math::Box instance. -void ComputePostureBounds(ozz::span _matrices, +void ComputePostureBounds(ozz::span _models, + const ozz::math::Float4x4& _transform, math::Box* _bound); // Allows to edit translation/rotation/scale of a skeleton pose. diff --git a/samples/millipede/sample_millipede.cc b/samples/millipede/sample_millipede.cc index 7a23d542d..a1273e1e5 100644 --- a/samples/millipede/sample_millipede.cc +++ b/samples/millipede/sample_millipede.cc @@ -403,7 +403,8 @@ class MillipedeSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/optimize/sample_optimize.cc b/samples/optimize/sample_optimize.cc index ae6ce111e..ff4107597 100644 --- a/samples/optimize/sample_optimize.cc +++ b/samples/optimize/sample_optimize.cc @@ -349,7 +349,8 @@ class OptimizeSampleApplication : public ozz::sample::Application { if (open) { rebuild |= _im_gui->DoCheckBox("Enable iframes", &enable_iframes_); - std::snprintf(label, sizeof(label), "Iframe interval: %0.2f s", iframe_interval_); + std::snprintf(label, sizeof(label), "Iframe interval: %0.2f s", + iframe_interval_); rebuild |= _im_gui->DoSlider(label, .1f, 20.f, &iframe_interval_, .5f, enable_iframes_); } @@ -483,7 +484,8 @@ class OptimizeSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(models(), _bound); + ozz::sample::ComputePostureBounds(models(), ozz::math::Float4x4::identity(), + _bound); } private: diff --git a/samples/partial_blend/sample_partial_blend.cc b/samples/partial_blend/sample_partial_blend.cc index abda62d78..60060e3d3 100644 --- a/samples/partial_blend/sample_partial_blend.cc +++ b/samples/partial_blend/sample_partial_blend.cc @@ -268,21 +268,21 @@ class PartialBlendSampleApplication : public ozz::sample::Application { _im_gui->DoLabel("Manual settings:"); _im_gui->DoLabel("Lower body layer:"); std::snprintf(label, sizeof(label), "Layer weight: %.2f", - lower_body_sampler.weight_setting); + lower_body_sampler.weight_setting); _im_gui->DoSlider(label, 0.f, 1.f, &lower_body_sampler.weight_setting, 1.f, !automatic); std::snprintf(label, sizeof(label), "Joints weight: %.2f", - lower_body_sampler.joint_weight_setting); + lower_body_sampler.joint_weight_setting); _im_gui->DoSlider(label, 0.f, 1.f, &lower_body_sampler.joint_weight_setting, 1.f, !automatic); _im_gui->DoLabel("Upper body layer:"); std::snprintf(label, sizeof(label), "Layer weight: %.2f", - upper_body_sampler.weight_setting); + upper_body_sampler.weight_setting); _im_gui->DoSlider(label, 0.f, 1.f, &upper_body_sampler.weight_setting, 1.f, !automatic); std::snprintf(label, sizeof(label), "Joints weight: %.2f", - upper_body_sampler.joint_weight_setting); + upper_body_sampler.joint_weight_setting); _im_gui->DoSlider(label, 0.f, 1.f, &upper_body_sampler.joint_weight_setting, 1.f, !automatic); @@ -302,8 +302,8 @@ class PartialBlendSampleApplication : public ozz::sample::Application { ozz::sample::ImGui::kLeft, false); char label[64]; std::snprintf(label, sizeof(label), "%s (%d)", - skeleton_.joint_names()[upper_body_root_], - upper_body_root_); + skeleton_.joint_names()[upper_body_root_], + upper_body_root_); if (_im_gui->DoSlider(label, 0, skeleton_.num_joints() - 1, &upper_body_root_)) { SetupPerJointWeights(); @@ -331,7 +331,8 @@ class PartialBlendSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/playback/sample_playback.cc b/samples/playback/sample_playback.cc index f5242f5b0..5d87dde27 100644 --- a/samples/playback/sample_playback.cc +++ b/samples/playback/sample_playback.cc @@ -130,7 +130,8 @@ class PlaybackSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/skinning/sample_skinning.cc b/samples/skinning/sample_skinning.cc index 831d85b59..8f5bf0961 100644 --- a/samples/skinning/sample_skinning.cc +++ b/samples/skinning/sample_skinning.cc @@ -186,7 +186,8 @@ class SkinningSampleApplication : public ozz::sample::Application { ozz::sample::ImGui::OpenClose oc(_im_gui, "Model statisitics", &open); if (open) { char label[255]; - std::snprintf(label, sizeof(label), "%d animated joints", skeleton_.num_joints()); + std::snprintf(label, sizeof(label), "%d animated joints", + skeleton_.num_joints()); _im_gui->DoLabel(label); int influences = 0; @@ -200,14 +201,16 @@ class SkinningSampleApplication : public ozz::sample::Application { for (const auto& mesh : meshes_) { vertices += mesh.vertex_count(); } - std::snprintf(label, sizeof(label), "%.1fK vertices", vertices / 1000.f); + std::snprintf(label, sizeof(label), "%.1fK vertices", + vertices / 1000.f); _im_gui->DoLabel(label); int indices = 0; for (const auto& mesh : meshes_) { indices += mesh.triangle_index_count(); } - std::snprintf(label, sizeof(label), "%.1fK triangles", indices / 3000.f); + std::snprintf(label, sizeof(label), "%.1fK triangles", + indices / 3000.f); _im_gui->DoLabel(label); } } @@ -232,7 +235,7 @@ class SkinningSampleApplication : public ozz::sample::Application { static bool ocr_open = false; ozz::sample::ImGui::OpenClose ocr(_im_gui, "Rendering options", - &ocr_open); + &ocr_open); if (ocr_open) { _im_gui->DoCheckBox("Show triangles", &render_options_.triangles); _im_gui->DoCheckBox("Show texture", &render_options_.texture); @@ -250,7 +253,8 @@ class SkinningSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputeSkeletonBounds(skeleton_, _bound); + ozz::sample::ComputeSkeletonBounds(skeleton_, + ozz::math::Float4x4::identity(), _bound); } private: diff --git a/samples/user_channel/sample_user_channel.cc b/samples/user_channel/sample_user_channel.cc index 59bfaf0fc..936473b4a 100644 --- a/samples/user_channel/sample_user_channel.cc +++ b/samples/user_channel/sample_user_channel.cc @@ -325,7 +325,8 @@ class UserChannelSampleApplication : public ozz::sample::Application { } virtual void GetSceneBounds(ozz::math::Box* _bound) const { - ozz::sample::ComputePostureBounds(make_span(models_), _bound); + ozz::sample::ComputePostureBounds(make_span(models_), + ozz::math::Float4x4::identity(), _bound); } private: