forked from leggedrobotics/robot_self_filter
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: apply scale and padding to mesh collision bodies #3
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
Open
satoimotaro
wants to merge
4
commits into
sbgisen:main
Choose a base branch
from
satoimotaro:fix/mesh-scale-padding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9ff6d29
Apply scale and padding to mesh collision bodies
satoimotaro c023f7c
Note which of scale and padding reach the containment test
satoimotaro a7b3796
Make scale reach the mesh containment test as well
satoimotaro 0dbb75d
Fall back to unscaled rather than dividing the padding by zero
satoimotaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -408,7 +408,11 @@ bool ConvexMesh::containsPoint(const tf2::Vector3 &p, bool) const | |
| { | ||
| if (!m_boundingBox.containsPoint(p)) return false; | ||
| tf2::Vector3 ip = m_iPose * p; | ||
| ip = m_meshCenter + (ip - m_meshCenter); // uniform scale/padding can be applied if desired | ||
| // The planes describe the unscaled hull, so bring the query point back into that | ||
| // frame rather than growing the hull. Dividing is what makes a scale above 1 a | ||
| // larger body; the code this replaced multiplied, which shrank it instead. | ||
| if (m_scale != 1.0) | ||
| ip = m_meshCenter + (ip - m_meshCenter) / m_scale; | ||
| return isPointInsidePlanes(ip); | ||
| } | ||
| bool ConvexMesh::intersectsRay(const tf2::Vector3 &origin, | ||
|
|
@@ -593,25 +597,35 @@ void ConvexMesh::updateInternalData() | |
| tf2::Transform pose = m_pose; | ||
| pose.setOrigin(m_pose * m_boxOffset); | ||
| m_boundingBox.setPose(pose); | ||
| // Could apply uniform scale/padding if desired, left as-is for example | ||
| // The bounding box is the first rejection test in containsPoint, so it has to | ||
| // grow with the padding or a padded point never reaches the plane test. | ||
| m_boundingBox.setScale(m_scale, m_scale, m_scale); | ||
| m_boundingBox.setPadding(m_padding, m_padding, m_padding); | ||
| m_iPose = m_pose.inverse(); | ||
| m_center = m_pose * m_meshCenter; | ||
| m_radiusB = m_meshRadiusB; | ||
| m_radiusB = m_meshRadiusB * m_scale + m_padding; | ||
| m_radiusBSqr = m_radiusB * m_radiusB; | ||
|
|
||
| m_scaledVertices.resize(m_vertices.size()); | ||
| for (size_t i=0; i<m_vertices.size(); i++) | ||
| { | ||
| // Uniform scaling placeholder | ||
| m_scaledVertices[i] = m_vertices[i]; | ||
| tf2::Vector3 v = m_vertices[i] - m_meshCenter; | ||
| double norm = v.length(); | ||
| if (norm > 1e-9) | ||
| m_scaledVertices[i] = m_meshCenter + v * (m_scale + m_padding / norm); | ||
| else | ||
| m_scaledVertices[i] = m_vertices[i]; | ||
| } | ||
|
Comment on lines
609
to
618
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-blocking ここで作るm_scaledVerticesは、少し上のintersectsRay()の内外判定に使われます。intersectsRay()が使う面(m_planes)は常に未スケールなので、面と三角形がずれます。 そのぶんレイの当たり判定がわずかに外側まで伸びます。単位立方体ではpad 0.02で約11.5mm外側まで伸びました。 この構造自体は本PR以前からあり、paddingが常に0だったため今まで表面化していませんでした。 |
||
| } | ||
| bool ConvexMesh::isPointInsidePlanes(const tf2::Vector3 &point) const | ||
| { | ||
| for (auto &plane : m_planes) | ||
| { | ||
| double dist = plane(0)*point.x() + plane(1)*point.y() + plane(2)*point.z() + plane(3); | ||
| if (dist > 0.0) return false; | ||
| // Plane normals are unit length, so dist is a signed distance, and the padding | ||
| // shifts every face of the hull outward by that much. containsPoint measures in | ||
| // the unscaled frame, so a padding given in metres divides by the scale here. | ||
| if (dist > m_padding / m_scale) return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking
setScale()は非正値やNaNを1.0にフォールバックしますが、setPadding()にはそのガードがありません。
m_paddingにNaNを渡すと、内外判定がすべての点をinside扱いにしてしまい、点群が丸ごと消えます。
提案:
m_padding = std::isfinite(p) ? p : 0.0;の1行で塞げます。