Skip to content

Commit d23facc

Browse files
committed
Shifter: Auto Fit Guide: update accel #620
1 parent 857f08f commit d23facc

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

python_src/include/rgp_accel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ RecordMirrorResult record_mirror(
536536
const std::vector<int>& face_vert_counts,
537537
const std::vector<int>& face_vert_indices,
538538
int num_verts,
539+
const std::vector<double>& mirror_positions,
539540
ProgressCB progress_cb = nullptr);
540541

541542
/**

python_src/src/bindings.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ PYBIND11_MODULE(_rgp_accel_cpp, m) {
108108
const std::vector<int>& face_vert_counts,
109109
const std::vector<int>& face_vert_indices,
110110
int num_verts,
111+
const std::vector<double>& mirror_positions,
111112
py::object progress_cb) -> py::dict
112113
{
113114
auto cb = wrap_progress(progress_cb);
@@ -121,7 +122,7 @@ PYBIND11_MODULE(_rgp_accel_cpp, m) {
121122
sample_count,
122123
points, face_normals,
123124
face_vert_counts, face_vert_indices,
124-
num_verts, cb);
125+
num_verts, mirror_positions, cb);
125126
}
126127

127128
py::dict d;
@@ -137,10 +138,14 @@ PYBIND11_MODULE(_rgp_accel_cpp, m) {
137138
py::arg("face_vert_counts"),
138139
py::arg("face_vert_indices"),
139140
py::arg("num_verts"),
141+
py::arg("mirror_positions"),
140142
py::arg("progress_cb") = py::none(),
141143
"Record mirror side for all guides (batch).\n\n"
142144
"Performs BFS flood-fill + reference matrix construction for\n"
143-
"each mirror position. Returns dict with:\n"
145+
"each mirror position. Uses mirror_positions (reflected guide\n"
146+
"world positions) as the distance reference for vertex sorting,\n"
147+
"matching the Python path behavior.\n\n"
148+
"Returns dict with:\n"
144149
" vert_ids: flat list of guide_count * sample_count ints\n"
145150
" ref_matrices: flat list of guide_count * 16 doubles"
146151
);

python_src/src/rgp_accel.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ RecordMirrorResult record_mirror(
391391
const std::vector<int>& face_vert_counts,
392392
const std::vector<int>& face_vert_indices,
393393
int num_verts,
394+
const std::vector<double>& mirror_positions,
394395
ProgressCB progress_cb)
395396
{
396397
int guide_count = static_cast<int>(seed_offsets.size()) - 1;
@@ -419,20 +420,12 @@ RecordMirrorResult record_mirror(
419420
seed_vert_ids.begin() + seed_start,
420421
seed_vert_ids.begin() + seed_end);
421422

422-
// We need a reference position for distance sorting.
423-
// Use the centroid of the seed vertices as the reference.
424-
Vec3 ref_pos;
425-
for (int s : seeds) {
426-
ref_pos.x += points[s * 3];
427-
ref_pos.y += points[s * 3 + 1];
428-
ref_pos.z += points[s * 3 + 2];
429-
}
430-
if (!seeds.empty()) {
431-
double inv = 1.0 / static_cast<double>(seeds.size());
432-
ref_pos.x *= inv;
433-
ref_pos.y *= inv;
434-
ref_pos.z *= inv;
435-
}
423+
// Use the reflected guide position for distance sorting.
424+
// This matches the Python path which passes the exact mirror
425+
// world-space position to getClosestNVerticesFromTransform().
426+
Vec3 ref_pos(mirror_positions[g * 3],
427+
mirror_positions[g * 3 + 1],
428+
mirror_positions[g * 3 + 2]);
436429

437430
// BFS flood-fill
438431
std::vector<int> closest = find_n_closest_vertices(

release/scripts/mgear/shifter/relative_guide_placement.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ def _yield_guide_relative_accel(shape_name, mesh_name, guideOrder,
600600
shape_name, p_mirror_positions)
601601

602602
# 6. C++ record_mirror: BFS + ref matrices for mirror side
603+
# Pass mirror_positions so C++ uses the reflected guide position
604+
# (not seed polygon centroid) as the distance reference for BFS.
603605
mirror_result = record_mirror(
604606
mr_seed_vert_ids,
605607
mr_seed_offsets,
@@ -609,6 +611,7 @@ def _yield_guide_relative_accel(shape_name, mesh_name, guideOrder,
609611
face_vert_counts,
610612
face_vert_indices,
611613
num_verts,
614+
p_mirror_positions,
612615
)
613616

614617
mr_vert_ids = mirror_result["vert_ids"]

0 commit comments

Comments
 (0)