Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ogre2 assertions during ray queries #415

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion include/ignition/rendering/RayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,23 @@ namespace ignition
const math::Vector2d &_coord) = 0;

/// \brief Compute intersections
/// \param[in] _forceSceneUpdate Performance optimization hint
/// When true Ogre2 will update all derived transforms to their
/// latest to get correct results.
///
/// When false, that step is skipped. It is only safe to
/// set it to false when nothing has changed since the last
/// update (i.e. nothing moved, no new objects created).
///
/// Ogre will assert if built in Debug mode if this value
/// is set to false when it shouldn't be.
///
/// See https://ogrecave.github.io/ogre-next/api/2.2/
/// _ogre20_changes.html#AssersionCachedOutOfDate
/// for more info
/// \return A vector of intersection results
public: virtual RayQueryResult ClosestPoint() = 0;
public: virtual RayQueryResult ClosestPoint(
bool _forceSceneUpdate = true) = 0;
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions include/ignition/rendering/base/BaseRayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace ignition
const math::Vector2d &_coord) override;

// Documentation inherited
public: virtual RayQueryResult ClosestPoint() override;
public: virtual RayQueryResult ClosestPoint(
bool _forceSceneUpdate = true) override;

/// \brief Ray origin
protected: math::Vector3d origin;
Expand Down Expand Up @@ -142,7 +143,8 @@ namespace ignition

//////////////////////////////////////////////////
template <class T>
RayQueryResult BaseRayQuery<T>::ClosestPoint()
RayQueryResult BaseRayQuery<T>::ClosestPoint(
bool /*_forceSceneUpdate*/) // NOLINT
{
// TODO(anyone): implement a generic ray query here?
RayQueryResult result;
Expand Down
3 changes: 2 additions & 1 deletion ogre/include/ignition/rendering/ogre/OgreRayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace ignition
const math::Vector2d &_coord);

// Documentation inherited
public: virtual RayQueryResult ClosestPoint();
public: virtual RayQueryResult ClosestPoint(
bool _forceSceneUpdate = true);

/// \brief Get the mesh information for the given mesh.
/// \param[in] _mesh Mesh to get info about.
Expand Down
2 changes: 1 addition & 1 deletion ogre/src/OgreRayQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void OgreRayQuery::SetFromCamera(const CameraPtr &_camera,
}

//////////////////////////////////////////////////
RayQueryResult OgreRayQuery::ClosestPoint()
RayQueryResult OgreRayQuery::ClosestPoint(bool /*_forceSceneUpdate*/) // NOLINT
{
RayQueryResult result;
OgreScenePtr ogreScene = std::dynamic_pointer_cast<OgreScene>(this->Scene());
Expand Down
6 changes: 4 additions & 2 deletions ogre2/include/ignition/rendering/ogre2/Ogre2RayQuery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ namespace ignition
const math::Vector2d &_coord);

// Documentation inherited
public: virtual RayQueryResult ClosestPoint();
public: virtual RayQueryResult ClosestPoint(
bool _forceSceneUpdate = true);

/// \brief Get closest point by selection buffer.
/// This is executed on the GPU.
private: RayQueryResult ClosestPointBySelectionBuffer();

/// \brief Get closest point by ray triangle intersection test.
/// This is executed on the CPU.
private: RayQueryResult ClosestPointByIntersection();
private: RayQueryResult ClosestPointByIntersection(
bool _forceSceneUpdate);

/// \brief Private data pointer
private: std::unique_ptr<Ogre2RayQueryPrivate> dataPtr;
Expand Down
15 changes: 10 additions & 5 deletions ogre2/src/Ogre2RayQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ void Ogre2RayQuery::SetFromCamera(const CameraPtr &_camera,
}

//////////////////////////////////////////////////
RayQueryResult Ogre2RayQuery::ClosestPoint()
RayQueryResult Ogre2RayQuery::ClosestPoint(bool _forceSceneUpdate)
{
RayQueryResult result;

// ray query using selection buffer does not seem to work on some machines
// using cpu based ray-triangle intersection method
// \todo remove this line if selection buffer is working again
return this->ClosestPointByIntersection();
return this->ClosestPointByIntersection(_forceSceneUpdate);

#ifdef __APPLE__
return this->ClosestPointByIntersection();
return this->ClosestPointByIntersection(_forceSceneUpdate);
#else
if (!this->dataPtr->camera ||
!this->dataPtr->camera->Parent() ||
Expand All @@ -126,7 +126,7 @@ RayQueryResult Ogre2RayQuery::ClosestPoint()
// use legacy method for backward compatibility if no camera is set or
// camera is not attached in the scene tree or
// this function is called from non-rendering thread
return this->ClosestPointByIntersection();
return this->ClosestPointByIntersection(_forceSceneUpdate);
}
else
{
Expand Down Expand Up @@ -172,14 +172,19 @@ RayQueryResult Ogre2RayQuery::ClosestPointBySelectionBuffer()
}

//////////////////////////////////////////////////
RayQueryResult Ogre2RayQuery::ClosestPointByIntersection()
RayQueryResult Ogre2RayQuery::ClosestPointByIntersection(bool _forceSceneUpdate)
{
RayQueryResult result;
Ogre2ScenePtr ogreScene =
std::dynamic_pointer_cast<Ogre2Scene>(this->Scene());
if (!ogreScene)
return result;

if (_forceSceneUpdate)
{
ogreScene->OgreSceneManager()->updateSceneGraph();
}

Ogre::Ray mouseRay(Ogre2Conversions::Convert(this->origin),
Ogre2Conversions::Convert(this->direction));

Expand Down