Fix wires with 3+ sections: initTopology accumulation + chained-section rest frame#228
Conversation
…ons (sofa-framework#223) x_used is the global curvilinear abscissa; adding x_start again placed the rest node at 2*x_start + local_offset instead of x_used. For wires with two or more RodStraightSections this produced enormous elastic restoring forces at every timestep, causing simulation explosion. Fix: use x_used directly, consistent with RodSpireSection and RodMeshSection.
…logy Fixes sofa-framework#225. Both accumulators were reset via assignment instead of accumulation, corrupting point coordinates and edge indices for any wire with three or more sections.
BaseRodSectionMaterial::getRestTransformOnX previously received only (x_used, x_start) and reconstructed world rest positions by adding Vec3(x_start, 0, 0). That assumes every preceding section ran straight along world +X -- true for one Straight base + one curved tip, but wrong as soon as a non-straight section is chained after another non-straight section: the rest shape was placed along world +X at keyPts[i] instead of continuing tangent-continuous from the curved predecessor tip, producing persistent unbalanced elastic forces and a "floppy" terminal section. - BaseRodSectionMaterial::getRestTransformOnX gains a const Transform& predecessor_H_sectionStart parameter. - RodStraightSection / RodSpireSection / RodMeshSection compute their local rest geometry in the section's own frame (origin at section start, +X = predecessor tip tangent) and compose with the predecessor transform instead of adding Vec3(x_start, 0, 0). - WireRestShape::getRestTransformOnX walks preceding sections, querying each tip at keyPts[i] with its accumulated predecessor, then dispatches to the owning section with the composed frame. Backward-compatible for one-section wires (predecessor = identity, x_start = 0) and for Straight + curved-tip pairs (straight tip produces (keyPts[1], 0, 0) with identity, matching the old hardcoded form). Fixes chained non-straight sections.
|
Hi @lkarstensen |
epernod
left a comment
There was a problem hiding this comment.
interesting, I'm not fully sure about the global fix, but the bug description makes sense.
An example not working that is fixed by this PR would be very useful as I never used multiple section not straights
| prev_length += length; | ||
| prev_edges += nbrVisuEdges; |
There was a problem hiding this comment.
yes this is correct if we have more than 2 sections!
| Transform predecessor = Transform::identity(); | ||
| for (sofa::Size i = 1; i < keyPts.size(); ++i) | ||
| { | ||
| if (x_used <= keyPts[i]) | ||
| { | ||
| return l_sectionMaterials.get(i - 1)->getRestTransformOnX(global_H_local, x_used, keyPts[i - 1]); | ||
| return l_sectionMaterials.get(i - 1)->getRestTransformOnX( | ||
| global_H_local, x_used, keyPts[i - 1], predecessor); | ||
| } | ||
|
|
||
| Transform tip; | ||
| l_sectionMaterials.get(i - 1)->getRestTransformOnX( | ||
| tip, keyPts[i], keyPts[i - 1], predecessor); | ||
| predecessor = tip; |
There was a problem hiding this comment.
| Transform predecessor = Transform::identity(); | |
| for (sofa::Size i = 1; i < keyPts.size(); ++i) | |
| { | |
| if (x_used <= keyPts[i]) | |
| { | |
| return l_sectionMaterials.get(i - 1)->getRestTransformOnX(global_H_local, x_used, keyPts[i - 1]); | |
| return l_sectionMaterials.get(i - 1)->getRestTransformOnX( | |
| global_H_local, x_used, keyPts[i - 1], predecessor); | |
| } | |
| Transform tip; | |
| l_sectionMaterials.get(i - 1)->getRestTransformOnX( | |
| tip, keyPts[i], keyPts[i - 1], predecessor); | |
| predecessor = tip; | |
| Transform predecessor = Transform::identity(); | |
| for (sofa::Size i = 1; i < keyPts.size(); ++i) | |
| { | |
| l_sectionMaterials.get(i - 1)->getRestTransformOnX(global_H_local, x_used, keyPts[i - 1], predecessor); | |
| if (x_used <= keyPts[i]) | |
| { | |
| return; | |
| } | |
| predecessor = global_H_local; |
|
Hi @hugtalbot Best Regards, |
|
Great thanks a lot @lkarstensen 🙏 |
|
Hey @lkarstensen |
Fixes #227 (combined issue covering both bugs).
Two related bugs make any wire with three or more sections (or two chained non-straight sections) unusable. Both are fixed here.
Bug 1 —
WireRestShape::initTopologyaccumulationprev_length = lengthandprev_edges = nbrVisuEdgesdiscard the cumulative offset/edge count after section 0. Only N=2 wires happen to produce identical output. From iteration 2 onward, points are placed at non-monotonic abscissas, edges become degenerate, andWireBeamInterpolation/MultiAdaptiveBeamMappingbreak.Fix:
(Originally tackled in #226, closed when further testing exposed Bug 2.)
Bug 2 — Rod section rest shape ignores predecessor section frame
BaseRodSectionMaterial::getRestTransformOnX(global_H_local, x_used, x_start)carries no predecessor-tip transform.RodSpireSection/RodMeshSectionreconstruct world position with+ Vec3(x_start, 0, 0), which is correct only when the wire so far ran straight along world +X. As soon as a non-straight section follows another non-straight section, the rest pose sits in empty space,AdaptiveBeamForceFieldAndMassinjects unbalanced elastic forces, and the terminal section becomes "floppy".Fix:
const Transform& predecessor_H_sectionStart.RodStraightSection/RodSpireSection/RodMeshSectioncompute their local rest geometry in the section's own frame (origin at section start, +X = predecessor tip tangent) and compose with the predecessor transform instead of addingVec3(x_start, 0, 0).WireRestShape::getRestTransformOnXwalks preceding sections, queries each tip atkeyPts[i]with its accumulated predecessor, then dispatches to the owning section with the composed frame.Backward-compatible:
x_start = 0→ unchanged.(keyPts[1], 0, 0)with identity → matches old hardcoded form.Files changed
src/BeamAdapter/component/engine/WireRestShape.inlsrc/BeamAdapter/component/model/BaseRodSectionMaterial.hsrc/BeamAdapter/component/model/RodStraightSection.{h,inl}src/BeamAdapter/component/model/RodSpireSection.{h,inl}src/BeamAdapter/component/model/RodMeshSection.{h,inl}Test plan
Verified manually:
WireRestShape_test(Straight + Spire) still passes — backward-compat case: predecessor stays identity for the straight, then(95, 0, 0)identity for the spire dispatch, matching the oldVec3(x_start, 0, 0)form.EdgeSetTopologyContainerhas monotonic point coordinates and the expected total edge count, no overlap.Straight + Spire(+90°) + Spire(+90°): rest pose of the second spire continues tangent to the first spire's tip instead of being placed along world +X atkeyPts[2]; tip no longer drifts under no input.cmake --build . --target BeamAdapter.