bug fixes, raycasting to find good support spot
This commit is contained in:
parent
bef26fee2b
commit
8dc3956b64
5 changed files with 80 additions and 82 deletions
|
@ -10,22 +10,26 @@ TriangleSelectorWrapper::TriangleSelectorWrapper(const TriangleMesh &mesh) :
|
|||
|
||||
}
|
||||
|
||||
void TriangleSelectorWrapper::enforce_spot(const Vec3f &point, float radius) {
|
||||
size_t hit_face_index;
|
||||
Vec3f hit_point;
|
||||
auto dist = AABBTreeIndirect::squared_distance_to_indexed_triangle_set(mesh.its.vertices, mesh.its.indices,
|
||||
triangles_tree,
|
||||
point, hit_face_index, hit_point);
|
||||
if (dist < 0 || dist > radius * radius) {
|
||||
return;
|
||||
void TriangleSelectorWrapper::enforce_spot(const Vec3f &point, const Vec3f &origin, float radius) {
|
||||
std::vector<igl::Hit> hits;
|
||||
Vec3f dir = (point - origin).normalized();
|
||||
if (AABBTreeIndirect::intersect_ray_all_hits(mesh.its.vertices, mesh.its.indices, triangles_tree,
|
||||
Vec3d(origin.cast<double>()),
|
||||
Vec3d(dir.cast<double>()),
|
||||
hits)) {
|
||||
for (int hit_idx = hits.size() - 1; hit_idx >= 0; --hit_idx) {
|
||||
const igl::Hit &hit = hits[hit_idx];
|
||||
Vec3f pos = origin + dir * hit.t;
|
||||
Vec3f face_normal = its_face_normal(mesh.its, hit.id);
|
||||
if (point.z() + radius > pos.z() && face_normal.dot(dir) < 0) {
|
||||
std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>(
|
||||
pos, origin, radius, Transform3d::Identity(), TriangleSelector::ClippingPlane { });
|
||||
selector.select_patch(hit.id, std::move(cursor), EnforcerBlockerType::ENFORCER, Transform3d::Identity(),
|
||||
true, 0.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<TriangleSelector::Cursor> cursor = std::make_unique<TriangleSelector::Sphere>(hit_point, point,
|
||||
radius, Transform3d::Identity(), TriangleSelector::ClippingPlane { });
|
||||
|
||||
selector.select_patch(hit_face_index, std::move(cursor), EnforcerBlockerType::ENFORCER, Transform3d::Identity(),
|
||||
true,
|
||||
0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue