1. tuned arrow mesh drawing

2. centralixzed arrow config in layout.py
3. seperate mesh render and display resolution to speed up (~40 fps)
This commit is contained in:
ykcheungab
2026-06-19 14:28:28 +08:00
parent 3fd9b839a9
commit 2e5c047d1e
19 changed files with 980 additions and 147 deletions
+42
View File
@@ -0,0 +1,42 @@
import sys
from pathlib import Path
_EXAMPLES = Path(__file__).resolve().parents[1] / "examples"
if str(_EXAMPLES) not in sys.path:
sys.path.insert(0, str(_EXAMPLES))
from viz.contact_arrow import (
ContactArrowStyle,
DEFAULT_CONTACT_ARROW_STYLE,
force_visual_strength,
length_from_force,
thickness_scale_from_force,
)
REFERENCE_NORMAL_FORCE = DEFAULT_CONTACT_ARROW_STYLE.reference_normal_force
def test_force_visual_strength_monotonic():
forces = [0.0, 50.0, 175.0, 1000.0, 5000.0, REFERENCE_NORMAL_FORCE, 20000.0]
strengths = [force_visual_strength(f) for f in forces]
assert strengths[0] == 0.0
assert all(strengths[i] <= strengths[i + 1] for i in range(len(strengths) - 1))
assert strengths[-1] == 1.0
def test_log_mode_more_sensitive_than_linear_at_low_force():
low = 175.0
log_style = ContactArrowStyle(force_strength_mode="log")
lin_style = ContactArrowStyle(force_strength_mode="linear")
assert force_visual_strength(low, style=log_style) > force_visual_strength(low, style=lin_style)
def test_length_and_thickness_track_same_strength():
force = 2500.0
mesh_span = 10.0
strength = force_visual_strength(force)
length = length_from_force(force, mesh_span)
thick = thickness_scale_from_force(force)
assert length > mesh_span * 0.02
assert thick > 0.20
assert strength == force_visual_strength(force)