Skip to content

Commit

Permalink
fix follow path not working with path as target and shape with 0 opacity
Browse files Browse the repository at this point in the history
fixes #7155
We have to also check all paths belonging to a shape before deferring the path update

Diffs=
1c7e61b8a fix follow path not working with path as target and shape with 0 opacity (#7156)

Co-authored-by: hernan <hernan@rive.app>
  • Loading branch information
bodymovin and bodymovin committed Apr 29, 2024
1 parent f0fa7aa commit d32253e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
328d307dfdfcc3c4a9d7c726f783b5325bfbef43
1c7e61b8a075b2eaacbcce4f5438d6072b30e420
1 change: 1 addition & 0 deletions include/rive/shapes/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Path : public PathBase
void update(ComponentDirt value) override;

void addDefaultPathSpace(PathSpace space);
bool canDeferPathUpdate();
void addVertex(PathVertex* vertex);

virtual void markPathDirty();
Expand Down
6 changes: 6 additions & 0 deletions src/shapes/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void Path::addVertex(PathVertex* vertex) { m_Vertices.push_back(vertex); }

void Path::addDefaultPathSpace(PathSpace space) { m_DefaultPathSpace |= space; }

bool Path::canDeferPathUpdate()
{
return ((m_DefaultPathSpace & PathSpace::Clipping) != PathSpace::Clipping) &&
((m_DefaultPathSpace & PathSpace::FollowPath) != PathSpace::FollowPath);
}

const Mat2D& Path::pathTransform() const { return worldTransform(); }

void Path::buildPath(CommandPath& commandPath) const
Expand Down
16 changes: 14 additions & 2 deletions src/shapes/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ void Shape::addPath(Path* path)

bool Shape::canDeferPathUpdate()
{
return renderOpacity() == 0 && (pathSpace() & PathSpace::Clipping) != PathSpace::Clipping &&
(pathSpace() & PathSpace::FollowPath) != PathSpace::FollowPath;
auto canDefer = renderOpacity() == 0 &&
(pathSpace() & PathSpace::Clipping) != PathSpace::Clipping &&
(pathSpace() & PathSpace::FollowPath) != PathSpace::FollowPath;
if (canDefer)
{
for (auto path : m_Paths)
{
if (!path->canDeferPathUpdate())
{
return false;
}
}
}
return canDefer;
}

void Shape::update(ComponentDirt value)
Expand Down
Binary file added test/assets/follow_path_path_0_opacity.riv
Binary file not shown.
20 changes: 20 additions & 0 deletions test/follow_path_constraint_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ TEST_CASE("follow path with 0 opacity constraint updates world transform", "[fil
REQUIRE(targetComponents.x() == rectComponents.x());
REQUIRE(targetComponents.y() == rectComponents.y());
}

TEST_CASE("follow path constraint with path at 0 opacity updates world transform", "[file]")
{
auto file = ReadRiveFile("../../test/assets/follow_path_path_0_opacity.riv");

auto artboard = file->artboard();

REQUIRE(artboard->find<rive::TransformComponent>("target") != nullptr);
auto target = artboard->find<rive::TransformComponent>("target");

REQUIRE(artboard->find<rive::TransformComponent>("rect") != nullptr);
auto rectangle = artboard->find<rive::TransformComponent>("rect");

artboard->advance(0.0f);

auto targetComponents = target->worldTransform().decompose();
auto rectComponents = rectangle->worldTransform().decompose();
REQUIRE(targetComponents.x() == rectComponents.x());
REQUIRE(targetComponents.y() == rectComponents.y());
}

0 comments on commit d32253e

Please sign in to comment.