Skip to content

Commit

Permalink
Adds a transform to bound computation helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed Mar 17, 2024
1 parent 9f92f24 commit 20fdb54
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 38 deletions.
3 changes: 2 additions & 1 deletion samples/additive/sample_additive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion samples/attach/sample_attach.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion samples/baked/sample_baked.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions samples/blend/sample_blend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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:
Expand Down
29 changes: 14 additions & 15 deletions samples/framework/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<const ozz::math::Float4x4> _matrices,
void ComputePostureBounds(ozz::span<const ozz::math::Float4x4> _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<float>::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;
}
Expand Down
4 changes: 3 additions & 1 deletion samples/framework/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const ozz::math::Float4x4> _matrices,
void ComputePostureBounds(ozz::span<const ozz::math::Float4x4> _models,
const ozz::math::Float4x4& _transform,
math::Box* _bound);

// Allows to edit translation/rotation/scale of a skeleton pose.
Expand Down
3 changes: 2 additions & 1 deletion samples/millipede/sample_millipede.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions samples/optimize/sample_optimize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions samples/partial_blend/sample_partial_blend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion samples/playback/sample_playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions samples/skinning/sample_skinning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion samples/user_channel/sample_user_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 20fdb54

Please sign in to comment.