Skip to content

Commit

Permalink
Fix renderer incorrectly filtering out negative scale factor (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jan 16, 2025
1 parent 8abf1dd commit 8d7a3b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- The application now has a MacOS-specific logo that more closely follows Apple's icon
guidelines.
- Negative scale factors are now supported by the 3D renderer, which can be handy for
mirroring meshes (thanks @carlosedubarreto, #974)

## [0.5.18] - 2025/01/16

Expand Down
5 changes: 4 additions & 1 deletion libOpenSimCreator/Graphics/SimTKDecorationGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <SimTKcommon/internal/PolygonalMesh.h>
#include <SimTKcommon/internal/State.h>

#include <cmath>
#include <cstddef>
#include <filesystem>

Expand All @@ -37,7 +38,9 @@ namespace
SimTK::Vec3 sf = geom.getScaleFactors();

for (int i = 0; i < 3; ++i) {
sf[i] = sf[i] <= 0.0 ? 1.0 : sf[i];
// filter out NaNs, but keep negative values, because some
// users use negative scales to mimic mirror imaging (#974)
sf[i] = not std::isnan(sf[i]) ? sf[i] : 0.0;
}

return to<Vec3>(sf);
Expand Down
23 changes: 23 additions & 0 deletions libOpenSimCreator/Graphics/SimTKDecorationGenerator.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,26 @@ TEST(SimTKDecorationGenerator, PropagatesHiddenRepresentation)
});
ASSERT_EQ(ncalls, 1) << "should only emit one is_wireframe sphere";
}

// ensure that the `SimTKDecorationGenerator` propagates negative scale factors,
// because some users use them to mirror-image geometry (#974)
TEST(SimTKDecorationGenerator, PropagatesNegativeScaleFactors)
{
SceneCache cache;

SimTK::MultibodySystem sys;
SimTK::SimbodyMatterSubsystem matter{sys};
SimTK::State state = sys.realizeTopology();
sys.realize(state);

SimTK::DecorativeSphere sphere;
sphere.setBodyId(0);
sphere.setRepresentation(SimTK::DecorativeGeometry::Hide);
sphere.setRadius(1.0);
sphere.setScaleFactors(SimTK::Vec3(1.0, -1.0, 1.0)); // note: negative

osc::GenerateDecorations(cache, matter, state, sphere, 1.0f, [&](const SceneDecoration& dec)
{
ASSERT_EQ(dec.transform.scale.y, -1.0f);
});
}

0 comments on commit 8d7a3b2

Please sign in to comment.