diffneusim 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
diffneusim/viz/render.py
ADDED
|
@@ -0,0 +1,1402 @@
|
|
|
1
|
+
"""ModernGL scene renderer for `.dnrec` clips.
|
|
2
|
+
|
|
3
|
+
A thin GPU layer (ModernGL) with our own shaders / scene graph / overlays — no
|
|
4
|
+
hand-written rasterizer, no fake physics (poses come straight from the engine
|
|
5
|
+
dump). Works headless (standalone context -> mp4) or inside a moderngl-window
|
|
6
|
+
(interactive viewer); both call `Scene.render(frame_idx, view, proj, eye)`.
|
|
7
|
+
|
|
8
|
+
Shading: directional light + Lambert diffuse + ambient + small Blinn specular,
|
|
9
|
+
depth-tested. Shadows use real SHADOW MAPPING: each frame the scene depth is
|
|
10
|
+
rendered from the light's point of view into a depth texture, then the lit pass
|
|
11
|
+
transforms every fragment (bodies AND the ground) into light space and compares
|
|
12
|
+
its depth against the shadow map (with PCF for soft edges and a slope-scaled
|
|
13
|
+
depth bias against acne) to decide shaded vs lit. The shadow therefore lands on
|
|
14
|
+
the ground exactly where the light is actually occluded — glued under a resting
|
|
15
|
+
body at its contact footprint and directly beneath an airborne one — for ANY
|
|
16
|
+
geometry (box included) and ANY camera, which the earlier planar-projection
|
|
17
|
+
decals could not do robustly. Overlays (contact force arrow / MTU activation
|
|
18
|
+
line / COM trail) are drawn from declared .dnrec channels and toggleable.
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import os
|
|
23
|
+
import pathlib
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
from diffneusim.viz.dnrec import DnRec
|
|
28
|
+
from diffneusim.viz import meshes as M
|
|
29
|
+
from diffneusim.viz.hud import TextHUD, LabelAtlas, AxisGizmo, SCENE_CAPTIONS, JOINT_DOF, live_lines, MapHUD, task_lines
|
|
30
|
+
|
|
31
|
+
# Muscle render modes (the G-key cycle). "mtu" = smooth fusiform swept tube (belly/tendon split);
|
|
32
|
+
# "capsule" = the older plain capsule-chain MTU split (chunkier). Both split the path by l_ce.
|
|
33
|
+
MUSCLE_RENDER_MODES = ("off", "mtu", "capsule")
|
|
34
|
+
|
|
35
|
+
# Series tendon radius as a fraction of the belly radius scaled at the full MTU path length: keeps the
|
|
36
|
+
# tendon thin and, referenced to the slowly varying l_mtu (not l_ce), non-bulging when the fiber contracts.
|
|
37
|
+
MTU_TENDON_R_FRAC = 0.4
|
|
38
|
+
# The belly volumetric coefficient rad_vol = V/pi (m^3) is O(1e-6..1e-3). A legacy .dnrec stored a
|
|
39
|
+
# sqrt(Fmax) RADIUS (a length, O(1e-3..1e-2 m)) in this slot instead; anything above this bound is that
|
|
40
|
+
# stale convention, not a volume -> fail fast so the file gets regenerated. (Checked on rad_vol itself,
|
|
41
|
+
# NOT the l_ce-amplified belly radius, so a legitimately over-contracted fiber never trips it.)
|
|
42
|
+
MTU_LEGACY_RADVOL_MAX = 2.0e-3
|
|
43
|
+
# Physical belly-radius clamp [m]. The lower bound keeps thin muscles visible; the upper bound saturates
|
|
44
|
+
# the isovolumetric bulge sqrt(V/(pi*l_ce)) as l_ce -> 0 (a real belly cannot fatten without bound).
|
|
45
|
+
MTU_BELLY_R_MIN, MTU_BELLY_R_MAX = 0.002, 0.11
|
|
46
|
+
# Studio backdrop gradient (top = deep cool, bottom = lighter horizon). The ground dissolves into BOT.
|
|
47
|
+
STUDIO_BG_TOP = (0.045, 0.050, 0.065)
|
|
48
|
+
STUDIO_BG_BOT = (0.140, 0.150, 0.180)
|
|
49
|
+
# DN_RENDER_LOOK=paper (opt-in, for figures on a white page): no studio gradient, the clear colour shows (RenderOptions.background), and
|
|
50
|
+
# the ground fades into PAPER_GROUND_FADE, which the tonemap takes to about the same near-white. Unset = the studio look, unchanged.
|
|
51
|
+
PAPER_LOOK = os.environ.get("DN_RENDER_LOOK") == "paper"
|
|
52
|
+
PAPER_GROUND_FADE = (3.0, 3.0, 3.0)
|
|
53
|
+
PAPER_AMBIENT = 0.32
|
|
54
|
+
PAPER_BODY_FILL = 0.20
|
|
55
|
+
PAPER_MUSCLE_FILL = 0.15
|
|
56
|
+
PAPER_KEY = (-0.50, 0.70, 0.60) # the key light in (camera right, world up, toward the camera)
|
|
57
|
+
PAPER_BONE = (0.78, 0.68, 0.52) # a tan, darker and warmer than the pale muscles, so bones separate from them (the model's own colour is (0.90, 0.87, 0.80))
|
|
58
|
+
PAPER_CREASE = 0.55 # depth darkening between overlapping parts, renderer._paper_crease
|
|
59
|
+
# Contact-arrow legibility floor: skip the arrow when the witness normal-z force is below this. A
|
|
60
|
+
# swing/airborne foot carries a ~0.5 N penalty residual (+ shear); stance is 100s-1000s N, so this
|
|
61
|
+
# cleanly separates stance from swing. Applied at DRAW time so the stored .dnrec keeps the RAW contact
|
|
62
|
+
# force (the record does not bake in a rendering threshold -- dnrec-format.md; matches rl_env_render).
|
|
63
|
+
CONTACT_NORMAL_MIN_N = 20.0
|
|
64
|
+
|
|
65
|
+
from diffneusim._paths import ROOT as _ROOT # tools/viz/render.py -> repo root # (3a) the repo root
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _resolve_mesh_path(f: str) -> str:
|
|
69
|
+
"""Resolve a visual-geom mesh 'file' to an absolute path (absolute as-is, else repo-relative)."""
|
|
70
|
+
p = pathlib.Path(f)
|
|
71
|
+
if not p.is_absolute():
|
|
72
|
+
p = _ROOT / f
|
|
73
|
+
assert p.exists(), f"mesh geom file not found: {p} (from {f!r})"
|
|
74
|
+
return str(p)
|
|
75
|
+
|
|
76
|
+
# ----------------------------------------------------------------------------
|
|
77
|
+
# Shaders
|
|
78
|
+
# ----------------------------------------------------------------------------
|
|
79
|
+
# Lit pass: shared by bodies and the ground. The ground is just a lit geom with a
|
|
80
|
+
# grid overlay, so it RECEIVES shadows through the exact same shadow-map sampling
|
|
81
|
+
# as the bodies (one code path, no separate decal).
|
|
82
|
+
LIT_VS = """
|
|
83
|
+
#version 330
|
|
84
|
+
uniform mat4 u_mvp;
|
|
85
|
+
uniform mat4 u_model;
|
|
86
|
+
uniform mat3 u_normal_mat;
|
|
87
|
+
uniform mat4 u_light_vp; // light view-projection (world -> light clip)
|
|
88
|
+
in vec3 in_pos;
|
|
89
|
+
in vec3 in_normal;
|
|
90
|
+
out vec3 v_world;
|
|
91
|
+
out vec3 v_normal;
|
|
92
|
+
out vec4 v_light_pos; // fragment position in light clip space
|
|
93
|
+
void main() {
|
|
94
|
+
vec4 wp = u_model * vec4(in_pos, 1.0);
|
|
95
|
+
v_world = wp.xyz;
|
|
96
|
+
v_normal = normalize(u_normal_mat * in_normal);
|
|
97
|
+
v_light_pos = u_light_vp * wp;
|
|
98
|
+
gl_Position = u_mvp * wp;
|
|
99
|
+
}
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
LIT_FS = """
|
|
103
|
+
#version 330
|
|
104
|
+
uniform vec3 u_light_dir; // direction TO the light (normalized)
|
|
105
|
+
uniform vec3 u_color;
|
|
106
|
+
uniform vec3 u_eye;
|
|
107
|
+
uniform float u_ambient;
|
|
108
|
+
uniform float u_alpha;
|
|
109
|
+
uniform float u_spec; // specular strength
|
|
110
|
+
uniform int u_grid; // 1 = draw a grid on this surface (ground)
|
|
111
|
+
uniform float u_grid_step;
|
|
112
|
+
uniform int u_recv_shadow; // 1 = sample the shadow map for this draw
|
|
113
|
+
uniform sampler2DShadow u_shadow; // light-space depth (hardware PCF compare)
|
|
114
|
+
uniform float u_shadow_texel; // 1 / shadow_map_size (PCF step)
|
|
115
|
+
uniform vec3 u_bg; // studio backdrop colour (the ground dissolves into it with distance)
|
|
116
|
+
out vec4 f_color;
|
|
117
|
+
in vec3 v_world;
|
|
118
|
+
in vec3 v_normal;
|
|
119
|
+
in vec4 v_light_pos;
|
|
120
|
+
|
|
121
|
+
vec3 tonemap(vec3 c) {
|
|
122
|
+
c = 1.0 - exp(-c * 1.35); // gentle exposure + smooth highlight rolloff
|
|
123
|
+
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
124
|
+
return clamp(mix(vec3(l), c, 1.10), 0.0, 1.0); // slight saturation lift
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
float shadow_factor(vec3 N, vec3 L) {
|
|
128
|
+
// perspective divide -> NDC -> [0,1] light-space uv + depth
|
|
129
|
+
vec3 p = v_light_pos.xyz / v_light_pos.w;
|
|
130
|
+
p = p * 0.5 + 0.5;
|
|
131
|
+
// outside the light frustum (incl. behind the far plane) -> fully lit.
|
|
132
|
+
if (p.z > 1.0 || p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0)
|
|
133
|
+
return 1.0;
|
|
134
|
+
// slope-scaled depth bias: surfaces grazing the light need a larger bias to
|
|
135
|
+
// avoid self-shadow acne; near-facing ones a small one.
|
|
136
|
+
float ndl = max(dot(N, L), 0.0);
|
|
137
|
+
float bias = mix(0.0018, 0.0004, ndl);
|
|
138
|
+
// 3x3 PCF for a soft edge. sampler2DShadow returns the comparison result
|
|
139
|
+
// (1 = lit, 0 = occluded), so the average is the lit fraction.
|
|
140
|
+
float lit = 0.0;
|
|
141
|
+
for (int dx = -1; dx <= 1; ++dx)
|
|
142
|
+
for (int dy = -1; dy <= 1; ++dy) {
|
|
143
|
+
vec2 off = vec2(dx, dy) * u_shadow_texel;
|
|
144
|
+
lit += texture(u_shadow, vec3(p.xy + off, p.z - bias));
|
|
145
|
+
}
|
|
146
|
+
return lit / 9.0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void main() {
|
|
150
|
+
vec3 N = normalize(v_normal);
|
|
151
|
+
vec3 L = normalize(u_light_dir);
|
|
152
|
+
vec3 V = normalize(u_eye - v_world);
|
|
153
|
+
float diff = max(dot(N, L), 0.0);
|
|
154
|
+
float vis = (u_recv_shadow == 1) ? shadow_factor(N, L) : 1.0;
|
|
155
|
+
// Hemispheric ambient: a cool "sky" tint from above, a warm dim "bounce" from below -- a unit-ish
|
|
156
|
+
// luminance TINT (not a dimming) so overall brightness matches the old flat ambient but gains form.
|
|
157
|
+
float hemi = 0.5 + 0.5 * N.z;
|
|
158
|
+
vec3 ambTint = mix(vec3(0.62, 0.55, 0.50), vec3(0.80, 0.86, 1.02), hemi);
|
|
159
|
+
vec3 H = normalize(L + V);
|
|
160
|
+
float spec = pow(max(dot(N, H), 0.0), 40.0) * u_spec * vis;
|
|
161
|
+
float fres = pow(1.0 - max(dot(N, V), 0.0), 4.0); // grazing-angle rim
|
|
162
|
+
vec3 col = u_color * (ambTint * u_ambient + (1.0 - u_ambient) * diff * vis)
|
|
163
|
+
+ vec3(spec)
|
|
164
|
+
+ u_color * fres * 0.22 * step(0.01, u_spec); // rim on bodies (u_spec>0), not the ground
|
|
165
|
+
if (u_grid == 1) {
|
|
166
|
+
float r = length(v_world.xy);
|
|
167
|
+
vec2 g = abs(fract(v_world.xy / u_grid_step - 0.5) - 0.5) / fwidth(v_world.xy / u_grid_step);
|
|
168
|
+
float line = min(g.x, g.y);
|
|
169
|
+
float grid = (1.0 - min(line, 1.0)) * (1.0 - smoothstep(1.5, 6.0, r)); // grid only near the subject
|
|
170
|
+
col = mix(col, vec3(0.34, 0.34, 0.40), 0.5 * grid);
|
|
171
|
+
col = mix(col, u_bg, smoothstep(2.0, 9.5, r)); // floor dissolves into the backdrop
|
|
172
|
+
}
|
|
173
|
+
f_color = vec4(tonemap(col), u_alpha);
|
|
174
|
+
}
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
# Depth-only pass: render the scene from the light to fill the shadow map. No
|
|
178
|
+
# fragment work needed — depth is written automatically.
|
|
179
|
+
DEPTH_VS = """
|
|
180
|
+
#version 330
|
|
181
|
+
uniform mat4 u_light_vp;
|
|
182
|
+
uniform mat4 u_model;
|
|
183
|
+
in vec3 in_pos;
|
|
184
|
+
void main() {
|
|
185
|
+
gl_Position = u_light_vp * u_model * vec4(in_pos, 1.0);
|
|
186
|
+
}
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
DEPTH_FS = """
|
|
190
|
+
#version 330
|
|
191
|
+
void main() { }
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
# Studio backdrop: a full-screen vertical gradient with a soft glow behind the subject and a corner
|
|
195
|
+
# vignette, so the scene sits in a lit studio rather than on a flat fill colour. Drawn first, depth
|
|
196
|
+
# test off (behind everything). One implementation shared by the mp4 and the interactive window.
|
|
197
|
+
BG_VS = """
|
|
198
|
+
#version 330
|
|
199
|
+
in vec2 in_pos; // fullscreen quad in NDC
|
|
200
|
+
out vec2 v_uv;
|
|
201
|
+
void main() { v_uv = in_pos * 0.5 + 0.5; gl_Position = vec4(in_pos, 0.0, 1.0); }
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
BG_FS = """
|
|
205
|
+
#version 330
|
|
206
|
+
uniform vec3 u_top;
|
|
207
|
+
uniform vec3 u_bot;
|
|
208
|
+
out vec4 f_color;
|
|
209
|
+
in vec2 v_uv;
|
|
210
|
+
void main() {
|
|
211
|
+
vec3 c = mix(u_bot, u_top, smoothstep(-0.15, 1.05, v_uv.y)); // vertical gradient
|
|
212
|
+
float glow = 1.0 - smoothstep(0.0, 0.78, distance(v_uv, vec2(0.5, 0.60)));
|
|
213
|
+
c += vec3(0.05, 0.055, 0.07) * glow; // soft light pool behind the subject
|
|
214
|
+
c *= 1.0 - 0.34 * smoothstep(0.45, 1.15, distance(v_uv, vec2(0.5, 0.5))); // corner vignette
|
|
215
|
+
f_color = vec4(c, 1.0);
|
|
216
|
+
}
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
# Muscle pass: a swept tube (meshes.swept_tube) carrying a fibre parametrisation. The fragment shader
|
|
220
|
+
# draws PROGRAMMATIC muscle fascicles -- longitudinal bundle striations (a periodic function of the
|
|
221
|
+
# around-coordinate uv.x, so the bands run along the fibre) with per-band amplitude + a slow length
|
|
222
|
+
# wave for organic variation -- and a Kajiya-Kay anisotropic highlight keyed on the fibre tangent, the
|
|
223
|
+
# wet fibrous sheen that reads as real muscle. No texture assets: everything is computed in-shader, so
|
|
224
|
+
# it is identical on Mac/Windows. (CPU/software raster falls back to the flat lit path; see the docs.)
|
|
225
|
+
MUSCLE_VS = """
|
|
226
|
+
#version 330
|
|
227
|
+
uniform mat4 u_mvp;
|
|
228
|
+
uniform mat3 u_normal_mat;
|
|
229
|
+
in vec3 in_pos;
|
|
230
|
+
in vec3 in_normal;
|
|
231
|
+
in vec2 in_uv;
|
|
232
|
+
in vec3 in_tangent;
|
|
233
|
+
in vec3 in_color;
|
|
234
|
+
out vec3 v_world;
|
|
235
|
+
out vec3 v_normal;
|
|
236
|
+
out vec2 v_uv;
|
|
237
|
+
out vec3 v_tangent;
|
|
238
|
+
out vec3 v_color;
|
|
239
|
+
void main() {
|
|
240
|
+
v_world = in_pos; // swept_tube emits world-space vertices
|
|
241
|
+
v_normal = normalize(u_normal_mat * in_normal);
|
|
242
|
+
v_tangent = normalize(u_normal_mat * in_tangent);
|
|
243
|
+
v_uv = in_uv;
|
|
244
|
+
v_color = in_color;
|
|
245
|
+
gl_Position = u_mvp * vec4(in_pos, 1.0);
|
|
246
|
+
}
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
MUSCLE_FS = """
|
|
250
|
+
#version 330
|
|
251
|
+
uniform vec3 u_light_dir;
|
|
252
|
+
uniform vec3 u_eye;
|
|
253
|
+
uniform float u_ambient;
|
|
254
|
+
uniform float u_fascicle_n; // number of longitudinal fascicle bundles around the circumference
|
|
255
|
+
uniform float u_fascicle_strength; // 0 = smooth, 1 = full fibre relief
|
|
256
|
+
out vec4 f_color;
|
|
257
|
+
in vec3 v_world;
|
|
258
|
+
in vec3 v_normal;
|
|
259
|
+
in vec2 v_uv;
|
|
260
|
+
in vec3 v_tangent;
|
|
261
|
+
in vec3 v_color;
|
|
262
|
+
|
|
263
|
+
float hash(float x) { return fract(sin(x * 127.1) * 43758.5453); }
|
|
264
|
+
|
|
265
|
+
vec3 tonemap(vec3 c) {
|
|
266
|
+
c = 1.0 - exp(-c * 1.35);
|
|
267
|
+
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
268
|
+
return clamp(mix(vec3(l), c, 1.12), 0.0, 1.0);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
void main() {
|
|
272
|
+
vec3 N = normalize(v_normal);
|
|
273
|
+
vec3 L = normalize(u_light_dir);
|
|
274
|
+
vec3 V = normalize(u_eye - v_world);
|
|
275
|
+
vec3 T = normalize(v_tangent);
|
|
276
|
+
// redness (0 at tendon, 1 at belly) gates fibre texture + subsurface glow + sheen strength
|
|
277
|
+
float belly = clamp((v_color.r - v_color.g) * 3.0, 0.0, 1.0);
|
|
278
|
+
float fasc = belly * u_fascicle_strength;
|
|
279
|
+
// programmatic fascicle striations (opt-in; two octaves; belly-gated so the tendon stays smooth)
|
|
280
|
+
float bands = v_uv.x * u_fascicle_n;
|
|
281
|
+
float bi = floor(bands);
|
|
282
|
+
float coarse = smoothstep(0.35, 1.0, abs(fract(bands) - 0.5) * 2.0);
|
|
283
|
+
float fine = smoothstep(0.20, 1.0, abs(fract(bands * 3.0) - 0.5) * 2.0);
|
|
284
|
+
float bandtint = 0.85 + 0.30 * hash(bi);
|
|
285
|
+
float lengthwave = 1.0 + 0.05 * sin(v_uv.y * 46.0 + 10.0 * hash(bi));
|
|
286
|
+
float shade = (1.0 - fasc * (0.34 * coarse + 0.12 * fine)) * mix(1.0, bandtint * lengthwave, fasc);
|
|
287
|
+
vec3 base = v_color * shade;
|
|
288
|
+
// WET MUSCLE shading: wrapped diffuse (soft terminator) + fake subsurface (light through the thin
|
|
289
|
+
// belly re-emerges reddened) + anisotropic fibre sheen + broad glossy + a pink fresnel wet rim.
|
|
290
|
+
float ndl = max(dot(N, L), 0.0);
|
|
291
|
+
float wrap = clamp((dot(N, L) + 0.4) / 1.4, 0.0, 1.0); // soft wrapped diffuse
|
|
292
|
+
float back = pow(clamp(dot(V, -L), 0.0, 1.0), 3.0);
|
|
293
|
+
vec3 sss = vec3(0.60, 0.07, 0.06) * back * belly; // reddened back-scatter through the belly
|
|
294
|
+
vec3 Hh = normalize(L + V);
|
|
295
|
+
float sinTH = sqrt(max(1.0 - dot(T, Hh) * dot(T, Hh), 0.0));
|
|
296
|
+
float sheen = (pow(sinTH, 64.0) * 0.45 + pow(max(dot(N, Hh), 0.0), 28.0) * 0.42) * ndl; // wet glossy
|
|
297
|
+
float fres = pow(1.0 - max(dot(N, V), 0.0), 3.5);
|
|
298
|
+
vec3 rim = vec3(0.95, 0.42, 0.40) * fres * (0.40 + 0.45 * belly); // pink wet edge
|
|
299
|
+
// warm reddish ambient fill (muscle glows red even in shadow, cooler from above) -- brighter than
|
|
300
|
+
// the shared u_ambient so bellies never sink to near-black maroon on the dark side.
|
|
301
|
+
vec3 amb = mix(vec3(0.44, 0.24, 0.22), vec3(0.60, 0.50, 0.50), 0.5 + 0.5 * N.z);
|
|
302
|
+
vec3 col = base * (amb + 0.90 * wrap) + sss + vec3(sheen) + rim;
|
|
303
|
+
f_color = vec4(tonemap(col), 1.0);
|
|
304
|
+
}
|
|
305
|
+
"""
|
|
306
|
+
|
|
307
|
+
if PAPER_LOOK:
|
|
308
|
+
# A white page shows every view a reader may get, so one key light follows the camera (Scene.render), above it and to its left, and casts the shadows:
|
|
309
|
+
# form reads from shading in every view. A low ambient and a small headlight fill keep the dark side from black. On muscles every term scales the base
|
|
310
|
+
# colour by one neutral factor and the view-dependent red back-scatter and pink rim are off, so hue depends on activation alone and shadow only darkens it.
|
|
311
|
+
# Bodies only (u_spec > 0): the ground keeps its own shading.
|
|
312
|
+
def _swap(src, old, new):
|
|
313
|
+
assert src.count(old) == 1, old
|
|
314
|
+
return src.replace(old, new)
|
|
315
|
+
|
|
316
|
+
LIT_FS = _swap(LIT_FS, " vec3 col = u_color * (ambTint * u_ambient + (1.0 - u_ambient) * diff * vis)\n",
|
|
317
|
+
" float body = step(0.01, u_spec);\n"
|
|
318
|
+
" vec3 amb = mix(vec3(0.82), mix(ambTint, vec3(1.0), 0.75), body);\n"
|
|
319
|
+
" float fill = body * PAPER_BODY_FILL * (0.25 + 0.75 * max(dot(N, V), 0.0));\n"
|
|
320
|
+
" vec3 col = u_color * (amb * u_ambient + (1.0 - u_ambient) * diff * vis + fill)\n".replace("PAPER_BODY_FILL", f"{PAPER_BODY_FILL:.3f}"))
|
|
321
|
+
LIT_FS = _swap(LIT_FS, "col = mix(col, vec3(0.34, 0.34, 0.40), 0.5 * grid);", "col = mix(col, vec3(0.36), 0.5 * grid);")
|
|
322
|
+
LIT_FS = _swap(LIT_FS, " + u_color * fres * 0.22 * step(0.01, u_spec); // rim on bodies (u_spec>0), not the ground\n",
|
|
323
|
+
" ;\n col *= 1.0 - body * 0.45 * pow(1.0 - max(dot(N, V), 0.0), 1.8); // edges darken, so each bone stands out from what lies behind it\n")
|
|
324
|
+
MUSCLE_FS = _swap(MUSCLE_FS, " vec3 amb = mix(vec3(0.44, 0.24, 0.22), vec3(0.60, 0.50, 0.50), 0.5 + 0.5 * N.z);\n",
|
|
325
|
+
" vec3 amb = vec3(mix(0.40, 0.48, 0.5 + 0.5 * N.z));\n")
|
|
326
|
+
MUSCLE_FS = _swap(MUSCLE_FS, " vec3 col = base * (amb + 0.90 * wrap) + sss + vec3(sheen) + rim;\n",
|
|
327
|
+
" vec3 col = base * (amb + 0.80 * clamp((dot(N, L) + 0.2) / 1.2, 0.0, 1.0) + PAPER_MUSCLE_FILL * max(dot(N, V), 0.0) + 0.30 * fres) + vec3(sheen);\n".replace("PAPER_MUSCLE_FILL", f"{PAPER_MUSCLE_FILL:.3f}"))
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class _Mesh:
|
|
331
|
+
"""An uploaded GPU mesh (vbo/ibo) reusable across many draws.
|
|
332
|
+
|
|
333
|
+
Lit meshes also get a second VAO bound to a depth-only program (sharing the
|
|
334
|
+
same vbo/ibo, reading just in_pos) so the shadow pass can render them without
|
|
335
|
+
re-uploading geometry or rebinding attributes."""
|
|
336
|
+
def __init__(self, ctx, prog, verts, normals, idx, lit=True, depth_prog=None):
|
|
337
|
+
self.ctx = ctx
|
|
338
|
+
self.n_idx = idx.size
|
|
339
|
+
self.lit = lit
|
|
340
|
+
self.depth_vao = None
|
|
341
|
+
if lit:
|
|
342
|
+
inter = np.hstack([verts, normals]).astype("f4")
|
|
343
|
+
self.vbo = ctx.buffer(inter.tobytes())
|
|
344
|
+
self.ibo = ctx.buffer(idx.astype("i4").tobytes())
|
|
345
|
+
self.vao = ctx.vertex_array(
|
|
346
|
+
prog, [(self.vbo, "3f 3f", "in_pos", "in_normal")], self.ibo)
|
|
347
|
+
if depth_prog is not None:
|
|
348
|
+
# same interleaved buffer; depth program reads only in_pos, so pad
|
|
349
|
+
# the normal slot with a 3-float skip.
|
|
350
|
+
self.depth_vao = ctx.vertex_array(
|
|
351
|
+
depth_prog, [(self.vbo, "3f 3x4", "in_pos")], self.ibo)
|
|
352
|
+
else:
|
|
353
|
+
self.vbo = ctx.buffer(verts.astype("f4").tobytes())
|
|
354
|
+
self.ibo = ctx.buffer(idx.astype("i4").tobytes())
|
|
355
|
+
self.vao = ctx.vertex_array(
|
|
356
|
+
prog, [(self.vbo, "3f", "in_pos")], self.ibo)
|
|
357
|
+
|
|
358
|
+
def render(self):
|
|
359
|
+
self.vao.render()
|
|
360
|
+
|
|
361
|
+
def render_depth(self):
|
|
362
|
+
self.depth_vao.render()
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _mat_gl(m: np.ndarray) -> tuple:
|
|
366
|
+
"""numpy row-major 4x4 -> column-major tuple for moderngl uniform write."""
|
|
367
|
+
return tuple(m.T.astype("f4").reshape(-1))
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
_ortho = M.ortho
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
class Scene:
|
|
374
|
+
"""Owns GPU resources for one `.dnrec` clip; render(frame, view, proj) draws it."""
|
|
375
|
+
|
|
376
|
+
def __init__(self, ctx, clip: DnRec, light_dir=(0.4, 0.5, 0.85),
|
|
377
|
+
shadow_size=2048):
|
|
378
|
+
self.ctx = ctx
|
|
379
|
+
self.clip = clip
|
|
380
|
+
self.light_dir = np.array(light_dir, dtype=np.float32)
|
|
381
|
+
self.light_dir /= np.linalg.norm(self.light_dir)
|
|
382
|
+
self.ambient = PAPER_AMBIENT if PAPER_LOOK else 0.35
|
|
383
|
+
|
|
384
|
+
self.lit_prog = ctx.program(vertex_shader=LIT_VS, fragment_shader=LIT_FS)
|
|
385
|
+
self.depth_prog = ctx.program(vertex_shader=DEPTH_VS, fragment_shader=DEPTH_FS)
|
|
386
|
+
self.muscle_prog = ctx.program(vertex_shader=MUSCLE_VS, fragment_shader=MUSCLE_FS)
|
|
387
|
+
# studio backdrop (fullscreen gradient quad, drawn first each frame)
|
|
388
|
+
self.bg_prog = ctx.program(vertex_shader=BG_VS, fragment_shader=BG_FS)
|
|
389
|
+
_bgq = np.array([-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1], dtype="f4")
|
|
390
|
+
self._bg_vbo = ctx.buffer(_bgq.tobytes())
|
|
391
|
+
self._bg_vao = ctx.vertex_array(self.bg_prog, [(self._bg_vbo, "2f", "in_pos")])
|
|
392
|
+
self.fascicle_n = 9.0 # longitudinal fibre bundles drawn around a muscle belly
|
|
393
|
+
self.fascicle_strength = 0.0 # 0 = smooth muscle (default; texture reads as mush at body scale),
|
|
394
|
+
# 1 = full fibre relief (opt-in for close-up single-muscle shots)
|
|
395
|
+
self.muscle_bundle = 1 # mtu mode: 1 = single fusiform tube; >1 = VIPER-style rod BUNDLE
|
|
396
|
+
# (K sub-rods filling the belly cross-section; geometric fascicles)
|
|
397
|
+
self.muscle_aspect = 1.0 # belly cross-section ellipse ratio. 1.0 = CIRCULAR (default; the
|
|
398
|
+
# oriented radial flatten kept mis-orienting, so it's off). >1 would
|
|
399
|
+
# flatten the belly (area/volume preserved) but the direction is fiddly.
|
|
400
|
+
# mtu muscle geometry is BATCHED into one buffer + CACHED: rebuilt only when the pose/params
|
|
401
|
+
# change (key below), so a camera-only move just re-draws (the geometry is world-space, camera
|
|
402
|
+
# independent). This is the fix for the per-frame 416-tube rebuild being CPU-bound.
|
|
403
|
+
self._mtu_vbo = self._mtu_ibo = self._mtu_vao = None
|
|
404
|
+
self._mtu_nidx = 0
|
|
405
|
+
self._mtu_cache_key = None
|
|
406
|
+
|
|
407
|
+
# --- Shadow map: depth-only FBO rendered from the light's POV. ----------
|
|
408
|
+
# A directional light is a parallel projection, so the light "camera" is an
|
|
409
|
+
# orthographic box aimed along -light_dir at the scene. Each lit fragment is
|
|
410
|
+
# transformed by u_light_vp and its depth compared against this texture (PCF
|
|
411
|
+
# + slope bias) to decide shaded vs lit. This replaces the old planar-
|
|
412
|
+
# projection decal entirely: the shadow is wherever the light is genuinely
|
|
413
|
+
# occluded, so it sits glued under a resting body and beneath an airborne
|
|
414
|
+
# one, for any geom (box too) and any camera. See _build_light_vp / render.
|
|
415
|
+
self.shadow_size = int(shadow_size)
|
|
416
|
+
self.shadow_tex = ctx.depth_texture((self.shadow_size, self.shadow_size))
|
|
417
|
+
# hardware depth-compare sampling (sampler2DShadow) + clamp so off-map
|
|
418
|
+
# lookups read the far plane (= lit), never wrap.
|
|
419
|
+
self.shadow_tex.compare_func = "<="
|
|
420
|
+
self.shadow_tex.repeat_x = False
|
|
421
|
+
self.shadow_tex.repeat_y = False
|
|
422
|
+
self.shadow_fbo = ctx.framebuffer(depth_attachment=self.shadow_tex)
|
|
423
|
+
self._shadow_unit = 1
|
|
424
|
+
|
|
425
|
+
# overlay toggles
|
|
426
|
+
self.show_shadow = True
|
|
427
|
+
self.show_contact = clip.has_channel("contact")
|
|
428
|
+
has_muscle_channel = any(
|
|
429
|
+
name in clip.channels and clip.channels[name].count > 0
|
|
430
|
+
for name in ("mtu_poly", "mtu_path")
|
|
431
|
+
)
|
|
432
|
+
self.muscle_mode = "mtu" if has_muscle_channel else "off"
|
|
433
|
+
assert self.muscle_mode in MUSCLE_RENDER_MODES
|
|
434
|
+
self.show_trail = clip.has_channel("com")
|
|
435
|
+
group_default = clip.header.get("geom_groups_default")
|
|
436
|
+
if group_default is None:
|
|
437
|
+
group_default = sorted({int(g.get("group", 0))
|
|
438
|
+
for b in clip.bodies for g in b.get("geoms", [])}) or [0]
|
|
439
|
+
self.enabled_geom_groups = set(int(g) for g in group_default)
|
|
440
|
+
if __import__("os").environ.get("DN_GEOM_DEBUG"):
|
|
441
|
+
from collections import Counter
|
|
442
|
+
c = Counter(int(g.get("group", 0)) for b in clip.bodies for g in b.get("geoms", []))
|
|
443
|
+
print(f"[GEOM] clip groups {dict(c)} enabled {sorted(self.enabled_geom_groups)}", flush=True)
|
|
444
|
+
assert all(g >= 0 for g in self.enabled_geom_groups), self.enabled_geom_groups
|
|
445
|
+
|
|
446
|
+
# --- build per-geom meshes (one entry per (body, geom)) ----------
|
|
447
|
+
# geom_instances: list of dict(body_idx, mesh, scale, local_pos, local_quat, rgba, group)
|
|
448
|
+
self.geoms = []
|
|
449
|
+
import os as _os; _DBG = _os.environ.get("DN_GEOM_DEBUG")
|
|
450
|
+
for bi, body in enumerate(clip.bodies):
|
|
451
|
+
for g in body.get("geoms", []):
|
|
452
|
+
group = int(g.get("group", 0))
|
|
453
|
+
assert group >= 0, f"geom group must be non-negative, got {group}"
|
|
454
|
+
if g["type"] == "mesh":
|
|
455
|
+
# STL bone mesh: raw verts loaded once (cached by path); the per-axis
|
|
456
|
+
# 'scale' (may be negative for mirrored left-side bones) is applied by
|
|
457
|
+
# the shared TRS path, exactly like a primitive's size scale.
|
|
458
|
+
mesh_cpu = M.load_stl(_resolve_mesh_path(g["file"]))
|
|
459
|
+
scale = np.array(g.get("scale", [1.0, 1.0, 1.0]), dtype=np.float32)
|
|
460
|
+
else:
|
|
461
|
+
mesh_cpu, scale = M.build_geom_mesh(g["type"], g["size"])
|
|
462
|
+
mesh = _Mesh(ctx, self.lit_prog, *mesh_cpu, lit=True,
|
|
463
|
+
depth_prog=self.depth_prog)
|
|
464
|
+
# rotation-invariant outer radius of the geom from its center, used
|
|
465
|
+
# to skip drawing geoms that have sunk far below the floor.
|
|
466
|
+
reach = float(np.max(np.linalg.norm(mesh_cpu[0] * scale, axis=1)))
|
|
467
|
+
self.geoms.append(dict(
|
|
468
|
+
body=bi, mesh=mesh, scale=scale, reach=reach,
|
|
469
|
+
group=group, collider=g.get("collider", ""),
|
|
470
|
+
local_pos=np.array(g.get("pos", [0, 0, 0]), dtype=np.float32),
|
|
471
|
+
local_quat=np.array(g.get("quat", [1, 0, 0, 0]), dtype=np.float32),
|
|
472
|
+
rgba=np.array(g.get("rgba", [0.8, 0.8, 0.85, 1]), dtype=np.float32),
|
|
473
|
+
))
|
|
474
|
+
if PAPER_LOOK and g["type"] == "mesh":
|
|
475
|
+
self.geoms[-1]["rgba"][:3] = PAPER_BONE
|
|
476
|
+
|
|
477
|
+
# ground (a LIT geom so it receives shadows through the same shader path)
|
|
478
|
+
self.ground = None
|
|
479
|
+
self.ground_z = 0.0 # fallback used by the light-frustum fit
|
|
480
|
+
self.ground_half = 1.0
|
|
481
|
+
g = clip.ground
|
|
482
|
+
if g is not None:
|
|
483
|
+
self.ground_z = float(g["z"])
|
|
484
|
+
self.ground_rgba = np.array(g.get("rgba", [0.5, 0.5, 0.55, 1]), dtype=np.float32)
|
|
485
|
+
self.ground_half = float(g["half_extent"])
|
|
486
|
+
self.ground = _Mesh(ctx, self.lit_prog, *M.ground_quad(self.ground_half), lit=True)
|
|
487
|
+
|
|
488
|
+
# overlay meshes (built once)
|
|
489
|
+
self.arrow = _Mesh(ctx, self.lit_prog, *M.arrow(), lit=True)
|
|
490
|
+
self.trail_sphere = _Mesh(ctx, self.lit_prog, *M.unit_sphere(), lit=True)
|
|
491
|
+
# MTU line uses a capless cylinder so its drawn extent equals exactly the
|
|
492
|
+
# origin->insertion distance (capsule caps would overshoot when stretched).
|
|
493
|
+
self.mtu_cyl = _Mesh(ctx, self.lit_prog, *M.unit_cylinder(), lit=True)
|
|
494
|
+
|
|
495
|
+
# precompute pose + channels
|
|
496
|
+
self.poses = clip.pose() # (B, 7)
|
|
497
|
+
self.contact = clip.channel("contact") # (1, 7) or None
|
|
498
|
+
self.activation = clip.channel("activation") # (M, 4)=[A,F_mtu,l_mtu,l_ce] or None
|
|
499
|
+
self.mtu_path = clip.channel("mtu_path") # (1, 6)=[org_xyz, ins_xyz] or None
|
|
500
|
+
self.mtu_poly = clip.channel("mtu_poly") # (M, 1+3*MAXPTS)=[npts, pts...] multi-site or None
|
|
501
|
+
self.com = clip.channel("com") # (1, 3) or None
|
|
502
|
+
# TASKWALK_FOOTSTEPS records: the footstep plan per frame in the task block (world p0x, p0y, p1x, p1y, heading, provisional,
|
|
503
|
+
# left stance; eval_ckpt._stamp_heading_task), drawn as translucent target spheres on the ground (as DeepLoco draws them)
|
|
504
|
+
_fs = (clip.header.get("task") or {}).get("footsteps")
|
|
505
|
+
self.footsteps = np.asarray(_fs, dtype=np.float32) if _fs else None
|
|
506
|
+
self.show_footsteps = self.footsteps is not None
|
|
507
|
+
|
|
508
|
+
# Fixed light view-projection for the whole clip, fit to the ground patch +
|
|
509
|
+
# the bodies that stay near/above it (so shadows never pop or clip frame to
|
|
510
|
+
# frame). Bodies that fall far through the floor are excluded from the fit.
|
|
511
|
+
# Built after poses are available (needs the swept body positions).
|
|
512
|
+
self.light_vp = self._build_light_vp()
|
|
513
|
+
|
|
514
|
+
# trail history buffer (filled progressively in interactive mode)
|
|
515
|
+
self._trail_pts = []
|
|
516
|
+
|
|
517
|
+
# text HUD (scene caption + live readouts). Toggleable.
|
|
518
|
+
self.show_hud = True
|
|
519
|
+
self.scene_name = clip.header.get("scene", "")
|
|
520
|
+
self._hud = TextHUD(ctx, font_size=20)
|
|
521
|
+
self._labels = LabelAtlas(ctx, font_size=16)
|
|
522
|
+
# Blender-style orientation gizmo (top-right); shown on every view, independent of the
|
|
523
|
+
# text-HUD toggle, so the world-axis orientation is always legible.
|
|
524
|
+
self.show_gizmo = True
|
|
525
|
+
self._gizmo = AxisGizmo(ctx, size_px=108)
|
|
526
|
+
# the steering task's live map (bottom-right, above a title band) when the clip carries header["task"]
|
|
527
|
+
self._map = MapHUD(ctx, size_px=300) if clip.header.get("task") else None
|
|
528
|
+
|
|
529
|
+
def set_enabled_geom_groups(self, groups):
|
|
530
|
+
groups = set(int(g) for g in groups)
|
|
531
|
+
assert groups, "at least one geom group must be enabled"
|
|
532
|
+
assert all(g >= 0 for g in groups), groups
|
|
533
|
+
self.enabled_geom_groups = groups
|
|
534
|
+
if hasattr(self, "light_vp"):
|
|
535
|
+
self.light_vp = self._build_light_vp()
|
|
536
|
+
|
|
537
|
+
def set_muscle_mode(self, mode):
|
|
538
|
+
assert mode in MUSCLE_RENDER_MODES, (mode, MUSCLE_RENDER_MODES)
|
|
539
|
+
if mode != "off":
|
|
540
|
+
assert self._has_muscle_data(), (
|
|
541
|
+
f"muscle mode {mode!r} requested, but this .dnrec has no mtu_poly/mtu_path channel")
|
|
542
|
+
self.muscle_mode = mode
|
|
543
|
+
|
|
544
|
+
def cycle_muscle_mode(self):
|
|
545
|
+
cur = MUSCLE_RENDER_MODES.index(self.muscle_mode)
|
|
546
|
+
for off in range(1, len(MUSCLE_RENDER_MODES) + 1):
|
|
547
|
+
mode = MUSCLE_RENDER_MODES[(cur + off) % len(MUSCLE_RENDER_MODES)]
|
|
548
|
+
if mode == "off" or self._has_muscle_data():
|
|
549
|
+
self.muscle_mode = mode
|
|
550
|
+
return mode
|
|
551
|
+
raise AssertionError("unreachable muscle mode cycle")
|
|
552
|
+
|
|
553
|
+
def toggle_fascicle(self):
|
|
554
|
+
"""Flip the programmatic fibre-bundle texture on the muscle bellies on/off (default off:
|
|
555
|
+
it reads as mush at body scale, useful for close-up single-muscle shots). Returns 'on'/'off'."""
|
|
556
|
+
self.fascicle_strength = 0.0 if self.fascicle_strength > 0.0 else 1.0
|
|
557
|
+
return "on" if self.fascicle_strength > 0.0 else "off"
|
|
558
|
+
|
|
559
|
+
def toggle_bundle(self):
|
|
560
|
+
"""Flip the VIPER-style muscle rod BUNDLE (mtu mode) between a single fusiform tube and a
|
|
561
|
+
6-rod fascicle bundle. Returns the sub-rod count."""
|
|
562
|
+
self.muscle_bundle = 1 if self.muscle_bundle > 1 else 6
|
|
563
|
+
self.mark_muscle_dirty()
|
|
564
|
+
return self.muscle_bundle
|
|
565
|
+
|
|
566
|
+
def mark_muscle_dirty(self):
|
|
567
|
+
"""Invalidate the cached mtu tube batch. MUST be called when the muscle channel data is mutated
|
|
568
|
+
IN PLACE at the current frame index (e.g. live-sim writes mtu_poly[0] every step) -- otherwise the
|
|
569
|
+
cache (keyed on the frame index) would keep drawing the stale initial-pose muscles while the bones
|
|
570
|
+
move. Playback (which advances the frame index) invalidates on its own."""
|
|
571
|
+
self._mtu_cache_key = None
|
|
572
|
+
|
|
573
|
+
def _has_muscle_data(self):
|
|
574
|
+
return ((self.mtu_poly is not None and self.mtu_poly.shape[1] > 0)
|
|
575
|
+
or (self.mtu_path is not None and self.mtu_path.shape[1] > 0))
|
|
576
|
+
|
|
577
|
+
def _geom_visible(self, gi: int) -> bool:
|
|
578
|
+
return self.geoms[gi]["group"] in self.enabled_geom_groups
|
|
579
|
+
|
|
580
|
+
# --- shadow-map light camera ----------------------------------------
|
|
581
|
+
def _caster_aabb(self) -> tuple[np.ndarray, np.ndarray]:
|
|
582
|
+
"""World AABB of the shadow-casting region for the whole clip: every geom's
|
|
583
|
+
swept position padded by its reach, but EXCLUDING geoms that fall far below
|
|
584
|
+
the floor (the no-collider box/ellipsoid that honestly pass through), so a
|
|
585
|
+
body plummeting to z=-16 doesn't blow the light frustum out. The lower face
|
|
586
|
+
is pulled down to the ground plane so the ground surface is inside the box
|
|
587
|
+
and receives the shadow."""
|
|
588
|
+
poses = self.poses # (B, 7)
|
|
589
|
+
lo = np.array([1e9, 1e9, 1e9], dtype=np.float64)
|
|
590
|
+
hi = -lo.copy()
|
|
591
|
+
floor = self.ground_z if self.ground is not None else 0.0
|
|
592
|
+
any_kept = False
|
|
593
|
+
for gi, g in enumerate(self.geoms):
|
|
594
|
+
if not self._geom_visible(gi):
|
|
595
|
+
continue
|
|
596
|
+
bi = g["body"]
|
|
597
|
+
reach = g["reach"]
|
|
598
|
+
c = poses[:, bi, 0:3].astype(np.float64) # (3) body origins
|
|
599
|
+
# keep only frames where this geom is near/above the floor (a body deep
|
|
600
|
+
# under the floor casts nothing useful and would distort the fit).
|
|
601
|
+
near = c[:, 2] > (floor - (reach + 1.0))
|
|
602
|
+
if not near.any():
|
|
603
|
+
continue
|
|
604
|
+
any_kept = True
|
|
605
|
+
cc = c[near]
|
|
606
|
+
lo = np.minimum(lo, cc.min(axis=0) - reach)
|
|
607
|
+
hi = np.maximum(hi, cc.max(axis=0) + reach)
|
|
608
|
+
if not any_kept: # degenerate: keep all
|
|
609
|
+
c = poses[:, :, 0:3].reshape(-1, 3).astype(np.float64)
|
|
610
|
+
lo, hi = c.min(axis=0) - 1.0, c.max(axis=0) + 1.0
|
|
611
|
+
# include the ground plane region directly under the bodies (bounded by the
|
|
612
|
+
# ground half-extent) so the receiving surface is covered without sizing the
|
|
613
|
+
# frustum to a possibly huge floor.
|
|
614
|
+
if self.ground is not None:
|
|
615
|
+
h = self.ground_half
|
|
616
|
+
lo[0] = max(lo[0], -h); hi[0] = min(hi[0], h)
|
|
617
|
+
lo[1] = max(lo[1], -h); hi[1] = min(hi[1], h)
|
|
618
|
+
lo[2] = min(lo[2], floor)
|
|
619
|
+
hi[2] = max(hi[2], floor)
|
|
620
|
+
# small margin so PCF taps near the frustum edge stay in-map.
|
|
621
|
+
margin = 0.05 * float(np.linalg.norm(hi - lo)) + 0.05
|
|
622
|
+
return lo - margin, hi + margin
|
|
623
|
+
|
|
624
|
+
def _build_light_vp(self) -> np.ndarray:
|
|
625
|
+
"""Orthographic light view-projection covering `_caster_aabb`, aimed along
|
|
626
|
+
-light_dir. Fit the ortho bounds to the AABB's 8 corners in light space so
|
|
627
|
+
the shadow map packs the scene tightly (sharp shadows) without clipping."""
|
|
628
|
+
lo, hi = self._caster_aabb()
|
|
629
|
+
center = (0.5 * (lo + hi)).astype(np.float32)
|
|
630
|
+
corners = np.array([[x, y, z] for x in (lo[0], hi[0])
|
|
631
|
+
for y in (lo[1], hi[1])
|
|
632
|
+
for z in (lo[2], hi[2])], dtype=np.float32)
|
|
633
|
+
radius = float(np.max(np.linalg.norm(corners - center, axis=1))) + 1e-3
|
|
634
|
+
L = self.light_dir
|
|
635
|
+
# an up vector not parallel to L (light is mostly +z here; use +z unless L
|
|
636
|
+
# is nearly vertical, then fall back to +y).
|
|
637
|
+
up = np.array([0, 0, 1.0], dtype=np.float32)
|
|
638
|
+
if abs(float(np.dot(L, up))) > 0.95:
|
|
639
|
+
up = np.array([0, 1.0, 0], dtype=np.float32)
|
|
640
|
+
eye = center + L * (radius * 2.0) # back the light off
|
|
641
|
+
view = M.look_at(eye, center, up)
|
|
642
|
+
# transform corners into light (view) space to get tight ortho extents.
|
|
643
|
+
cw = np.hstack([corners, np.ones((8, 1), dtype=np.float32)])
|
|
644
|
+
cv = (view @ cw.T).T[:, :3]
|
|
645
|
+
mn = cv.min(axis=0)
|
|
646
|
+
mx = cv.max(axis=0)
|
|
647
|
+
# view looks down -z, so depth spans [-mx_z, -mn_z] (positive near..far).
|
|
648
|
+
near = -mx[2] - 0.05
|
|
649
|
+
far = -mn[2] + 0.05
|
|
650
|
+
proj = _ortho(mn[0], mx[0], mn[1], mx[1], near, far)
|
|
651
|
+
return (proj @ view).astype(np.float32)
|
|
652
|
+
|
|
653
|
+
def draw_hud(self, screen_w: int, screen_h: int, frame: int,
|
|
654
|
+
view: np.ndarray | None = None, proj: np.ndarray | None = None):
|
|
655
|
+
"""Blit the scene caption + live numeric readout (call after render).
|
|
656
|
+
When view/proj are given, also draw the scene's labels/legend overlay."""
|
|
657
|
+
# Orientation gizmo first — always on when a view matrix is available, regardless of the
|
|
658
|
+
# text-HUD toggle (it is navigation chrome, not scene annotation).
|
|
659
|
+
if view is not None and self.show_gizmo:
|
|
660
|
+
self._gizmo.draw(screen_w, screen_h, view)
|
|
661
|
+
if not self.show_hud:
|
|
662
|
+
return
|
|
663
|
+
# header["caption"] (a producer-stamped list[str], see dnrec_io.write_dnrec) lets a clip
|
|
664
|
+
# declare its own caption; SCENE_CAPTIONS (keyed on scene name) is a generic fallback for a
|
|
665
|
+
# clip that omits it.
|
|
666
|
+
lines = list(self.clip.header.get("caption") or SCENE_CAPTIONS.get(self.scene_name, [self.scene_name]))
|
|
667
|
+
lines.append("") # spacer
|
|
668
|
+
if self._has_muscle_data():
|
|
669
|
+
lines.append(f"muscle render = {self.muscle_mode}")
|
|
670
|
+
lines += live_lines(self.clip, frame)
|
|
671
|
+
lines += task_lines(self.clip, frame)
|
|
672
|
+
self._hud.set_lines(lines)
|
|
673
|
+
self._hud.draw(screen_w, screen_h, corner="tl")
|
|
674
|
+
if self._map is not None and self._map.set_frame(self.clip, frame):
|
|
675
|
+
self._map.draw(screen_w, screen_h, corner="br", margin_px=16, margin_y_px=96)
|
|
676
|
+
if view is not None and proj is not None:
|
|
677
|
+
self.draw_labels(screen_w, screen_h, frame, view, proj)
|
|
678
|
+
|
|
679
|
+
# --- scene labels / legends -----------------------------------------
|
|
680
|
+
def _world_to_screen(self, p_world, vp, screen_w, screen_h):
|
|
681
|
+
"""World point -> (cx_frac, top_frac) screen fraction (y from bottom).
|
|
682
|
+
Returns None if behind the camera."""
|
|
683
|
+
clip = vp @ np.array([p_world[0], p_world[1], p_world[2], 1.0], dtype=np.float32)
|
|
684
|
+
if clip[3] <= 1e-6:
|
|
685
|
+
return None
|
|
686
|
+
ndc = clip[:3] / clip[3]
|
|
687
|
+
return (0.5 * (ndc[0] + 1.0), 0.5 * (ndc[1] + 1.0))
|
|
688
|
+
|
|
689
|
+
def draw_labels(self, screen_w, screen_h, frame, view, proj):
|
|
690
|
+
"""Per-body annotation overlay: floating joint/DOF labels + a right-side legend. Driven by
|
|
691
|
+
.dnrec header metadata -- each body's optional 'label' / 'role' string (see
|
|
692
|
+
dnrec_io.write_dnrec) -- when the clip declares it, so any model can opt in without a viewer
|
|
693
|
+
edit. For clips that carry neither (predate the fields), falls back to the built-in
|
|
694
|
+
joint-gallery / contact-legend scenes (keyed on scene name) so they keep rendering exactly as
|
|
695
|
+
before."""
|
|
696
|
+
vp = proj @ view
|
|
697
|
+
if any(b.get("label") for b in self.clip.bodies) or self.scene_name == "joints":
|
|
698
|
+
self._draw_joint_labels(screen_w, screen_h, frame, vp)
|
|
699
|
+
if any(b.get("role") for b in self.clip.bodies) or self.scene_name == "contact":
|
|
700
|
+
self._draw_contact_legend(screen_w, screen_h)
|
|
701
|
+
|
|
702
|
+
def _draw_joint_labels(self, screen_w, screen_h, frame, vp):
|
|
703
|
+
"""Label each moving child body. Prefers a body's own declared header 'label' (a string, or a
|
|
704
|
+
list of lines); falls back to a JOINT_DOF-derived "type (DOF)" label (joint type read from the
|
|
705
|
+
.dnrec body's 'joint' entry) for a clip that declares no labels at all -- the built-in joint
|
|
706
|
+
gallery. Each label is anchored at its body's parent MOUNT x (stationary, so labels stay in a
|
|
707
|
+
clean row and under the right body even as the child swings/tumbles) and pinned to a fixed
|
|
708
|
+
bottom row."""
|
|
709
|
+
for bi, body in enumerate(self.clip.bodies):
|
|
710
|
+
if body.get("parent", -1) < 0:
|
|
711
|
+
continue # only label the moving children (skip Fixed mounts / the world root)
|
|
712
|
+
declared = body.get("label")
|
|
713
|
+
if declared is not None:
|
|
714
|
+
lines = [declared] if isinstance(declared, str) else list(declared)
|
|
715
|
+
else:
|
|
716
|
+
jt = body.get("joint", "")
|
|
717
|
+
if jt not in JOINT_DOF:
|
|
718
|
+
continue
|
|
719
|
+
title, dof, desc = JOINT_DOF[jt]
|
|
720
|
+
lines = [f"{title} ({dof})", desc]
|
|
721
|
+
# horizontal anchor = the parent mount's (fixed) world position.
|
|
722
|
+
mount_p = self.poses[frame, body["parent"], 0:3]
|
|
723
|
+
scr = self._world_to_screen(mount_p, vp, screen_w, screen_h)
|
|
724
|
+
if scr is None:
|
|
725
|
+
continue
|
|
726
|
+
accent = tuple(self.geoms[self._first_geom_of(bi)]["rgba"][:3])
|
|
727
|
+
self._labels.draw_at(lines, accent,
|
|
728
|
+
screen_w, screen_h, scr[0], 0.20, anchor="center")
|
|
729
|
+
|
|
730
|
+
def _first_geom_of(self, body_idx):
|
|
731
|
+
for gi, g in enumerate(self.geoms):
|
|
732
|
+
if g["body"] == body_idx:
|
|
733
|
+
return gi
|
|
734
|
+
return 0
|
|
735
|
+
|
|
736
|
+
def _draw_contact_legend(self, screen_w, screen_h):
|
|
737
|
+
"""Right-side legend: each body's color -> geom type + role, its collider, and the joint
|
|
738
|
+
linking it to its parent. Role text prefers a body's own declared header 'role' string; for a
|
|
739
|
+
clip that declares no roles at all, falls back to a name-keyed hint for the built-in gallery's
|
|
740
|
+
kinematic chain (base -> thigh -> shank+foot). Every other field (joint, collider, geom type)
|
|
741
|
+
already comes straight from the generic .dnrec body/geom entries."""
|
|
742
|
+
bodies = self.clip.bodies
|
|
743
|
+
legacy_role = {"base": "torso / free base", "thigh": "upper leg link",
|
|
744
|
+
"shank": "lower leg + foot"}
|
|
745
|
+
rows = [] # (lines, accent)
|
|
746
|
+
for bi, body in enumerate(bodies):
|
|
747
|
+
jt = body.get("joint", "?")
|
|
748
|
+
parent = body.get("parent", -1)
|
|
749
|
+
pname = bodies[parent]["name"] if parent >= 0 else "world"
|
|
750
|
+
for g in body.get("geoms", []):
|
|
751
|
+
col = tuple(g.get("rgba", [0.8, 0.8, 0.85, 1])[:3])
|
|
752
|
+
coll = g.get("collider", "")
|
|
753
|
+
coll_txt = ("collider: sphere-plane" if coll == "sphere"
|
|
754
|
+
else "collider: capsule(2-sphere)" if coll == "sphere2"
|
|
755
|
+
else "no collider")
|
|
756
|
+
what = g["type"]
|
|
757
|
+
rr = body.get("role", legacy_role.get(body["name"], ""))
|
|
758
|
+
l1 = f"{body['name']}: {what}" + (f" ({rr})" if rr else "")
|
|
759
|
+
l2 = f"joint to {pname}: {jt} | {coll_txt}"
|
|
760
|
+
rows.append(([l1, l2], col))
|
|
761
|
+
# stack rows down the right edge
|
|
762
|
+
top = 0.96
|
|
763
|
+
for lines, accent in rows:
|
|
764
|
+
self._labels.draw_at(lines, accent, screen_w, screen_h,
|
|
765
|
+
0.985, top, anchor="right")
|
|
766
|
+
top -= 0.085
|
|
767
|
+
|
|
768
|
+
# --- helpers ---------------------------------------------------------
|
|
769
|
+
def _body_pose(self, frame, bi):
|
|
770
|
+
p = self.poses[frame, bi, 0:3]
|
|
771
|
+
q = self.poses[frame, bi, 3:7]
|
|
772
|
+
return p, q
|
|
773
|
+
|
|
774
|
+
def _geom_model(self, frame, gi):
|
|
775
|
+
g = self.geoms[gi]
|
|
776
|
+
bp, bq = self._body_pose(frame, g["body"])
|
|
777
|
+
# world = body_pose ∘ local_geom ; then scale the unit mesh
|
|
778
|
+
wq = M.quat_mul(bq, g["local_quat"])
|
|
779
|
+
wp = bp + M.quat_rotate(bq, g["local_pos"])
|
|
780
|
+
return M.trs(wp, wq, g["scale"]), wq, wp
|
|
781
|
+
|
|
782
|
+
# --- main draw -------------------------------------------------------
|
|
783
|
+
def _shadow_pass(self, frame: int):
|
|
784
|
+
"""Render the scene depth from the light into the shadow map. The caller's
|
|
785
|
+
framebuffer is restored afterwards."""
|
|
786
|
+
ctx = self.ctx
|
|
787
|
+
prev_fbo = ctx.fbo # caller's (MSAA) target to restore
|
|
788
|
+
self.shadow_fbo.use()
|
|
789
|
+
ctx.clear(depth=1.0)
|
|
790
|
+
ctx.enable(ctx.DEPTH_TEST)
|
|
791
|
+
# Front-face cull during the depth pass: shadow depth is taken from the
|
|
792
|
+
# geom's BACK faces (away from the light), which pushes self-shadow acne to
|
|
793
|
+
# the unlit side and largely removes it on the lit side (peter-panning is
|
|
794
|
+
# negligible here vs. the bias). Restored to default after.
|
|
795
|
+
ctx.enable(ctx.CULL_FACE)
|
|
796
|
+
ctx.cull_face = "back"
|
|
797
|
+
self.depth_prog["u_light_vp"].value = _mat_gl(self.light_vp)
|
|
798
|
+
for gi in range(len(self.geoms)):
|
|
799
|
+
if not self._geom_visible(gi):
|
|
800
|
+
continue
|
|
801
|
+
model, _, _ = self._geom_model(frame, gi)
|
|
802
|
+
self.depth_prog["u_model"].value = _mat_gl(model)
|
|
803
|
+
self.geoms[gi]["mesh"].render_depth()
|
|
804
|
+
ctx.disable(ctx.CULL_FACE)
|
|
805
|
+
prev_fbo.use()
|
|
806
|
+
|
|
807
|
+
def _draw_background(self):
|
|
808
|
+
"""Studio backdrop: a fullscreen gradient quad behind everything (depth test + write off)."""
|
|
809
|
+
if PAPER_LOOK:
|
|
810
|
+
return
|
|
811
|
+
ctx = self.ctx
|
|
812
|
+
ctx.disable(ctx.DEPTH_TEST)
|
|
813
|
+
ctx.depth_mask = False
|
|
814
|
+
self.bg_prog["u_top"].value = STUDIO_BG_TOP
|
|
815
|
+
self.bg_prog["u_bot"].value = STUDIO_BG_BOT
|
|
816
|
+
self._bg_vao.render()
|
|
817
|
+
ctx.depth_mask = True
|
|
818
|
+
ctx.enable(ctx.DEPTH_TEST)
|
|
819
|
+
|
|
820
|
+
def render(self, frame: int, view: np.ndarray, proj: np.ndarray, eye: np.ndarray):
|
|
821
|
+
ctx = self.ctx
|
|
822
|
+
vp = proj @ view
|
|
823
|
+
if PAPER_LOOK: # the key light follows the camera, so it holds in every view; it casts the shadows
|
|
824
|
+
key = PAPER_KEY[0] * view[0, :3] + PAPER_KEY[1] * np.array([0.0, 0.0, 1.0]) + PAPER_KEY[2] * view[2, :3]
|
|
825
|
+
self.light_dir = (key / np.linalg.norm(key)).astype(np.float32)
|
|
826
|
+
self.light_vp = self._build_light_vp()
|
|
827
|
+
|
|
828
|
+
# PASS 1 — fill the shadow map from the light's POV (skipped if disabled).
|
|
829
|
+
if self.show_shadow:
|
|
830
|
+
self._shadow_pass(frame)
|
|
831
|
+
|
|
832
|
+
# studio backdrop first (covers the flat clear colour), then the lit scene on top
|
|
833
|
+
self._draw_background()
|
|
834
|
+
|
|
835
|
+
# PASS 2 — lit scene. Bind the shadow map + shared light uniforms once.
|
|
836
|
+
# Bound unconditionally so the sampler always has a valid texture unit even
|
|
837
|
+
# when shadows are off (then u_recv_shadow=0 so it is simply never sampled).
|
|
838
|
+
ctx.enable(ctx.DEPTH_TEST)
|
|
839
|
+
self.shadow_tex.use(location=self._shadow_unit)
|
|
840
|
+
self.lit_prog["u_light_dir"].value = tuple(self.light_dir)
|
|
841
|
+
self.lit_prog["u_eye"].value = tuple(eye)
|
|
842
|
+
self.lit_prog["u_light_vp"].value = _mat_gl(self.light_vp)
|
|
843
|
+
self.lit_prog["u_shadow"].value = self._shadow_unit
|
|
844
|
+
self.lit_prog["u_shadow_texel"].value = 1.0 / float(self.shadow_size)
|
|
845
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
846
|
+
self.lit_prog["u_alpha"].value = 1.0
|
|
847
|
+
self.lit_prog["u_bg"].value = PAPER_GROUND_FADE if PAPER_LOOK else STUDIO_BG_BOT # ground fades into the backdrop horizon
|
|
848
|
+
|
|
849
|
+
# ground (a lit receiver: flat-shaded with grid, sampling the shadow map)
|
|
850
|
+
if self.ground is not None:
|
|
851
|
+
gm = np.eye(4, dtype=np.float32)
|
|
852
|
+
gm[2, 3] = self.ground_z
|
|
853
|
+
self.lit_prog["u_model"].value = _mat_gl(gm)
|
|
854
|
+
self.lit_prog["u_normal_mat"].value = (1, 0, 0, 0, 1, 0, 0, 0, 1)
|
|
855
|
+
self.lit_prog["u_color"].value = tuple(self.ground_rgba[:3])
|
|
856
|
+
self.lit_prog["u_ambient"].value = 0.62 # brighter ground so shadows read
|
|
857
|
+
self.lit_prog["u_spec"].value = 0.0
|
|
858
|
+
self.lit_prog["u_grid"].value = 1
|
|
859
|
+
self.lit_prog["u_grid_step"].value = 0.25
|
|
860
|
+
self.lit_prog["u_recv_shadow"].value = 1 if self.show_shadow else 0
|
|
861
|
+
self.ground.render()
|
|
862
|
+
self.lit_prog["u_grid"].value = 0
|
|
863
|
+
|
|
864
|
+
# lit geoms (cast AND receive: a body in another's shadow darkens correctly). Two passes:
|
|
865
|
+
# OPAQUE first, then TRANSLUCENT (rgba alpha<1) with alpha-blending + depth-write OFF.
|
|
866
|
+
self.lit_prog["u_ambient"].value = self.ambient
|
|
867
|
+
self.lit_prog["u_spec"].value = 0.25
|
|
868
|
+
self.lit_prog["u_recv_shadow"].value = 1 if self.show_shadow else 0
|
|
869
|
+
|
|
870
|
+
def _draw_geom(gi):
|
|
871
|
+
model, _, _ = self._geom_model(frame, gi)
|
|
872
|
+
nm = np.linalg.inv(model[:3, :3]).T
|
|
873
|
+
self.lit_prog["u_model"].value = _mat_gl(model)
|
|
874
|
+
self.lit_prog["u_normal_mat"].value = tuple(nm.T.astype("f4").reshape(-1))
|
|
875
|
+
self.lit_prog["u_color"].value = tuple(self.geoms[gi]["rgba"][:3])
|
|
876
|
+
self.geoms[gi]["mesh"].render()
|
|
877
|
+
|
|
878
|
+
alpha = [float(self.geoms[gi]["rgba"][3]) if len(self.geoms[gi]["rgba"]) > 3 else 1.0
|
|
879
|
+
for gi in range(len(self.geoms))]
|
|
880
|
+
for gi in range(len(self.geoms)):
|
|
881
|
+
if not self._geom_visible(gi):
|
|
882
|
+
continue
|
|
883
|
+
if alpha[gi] >= 0.999:
|
|
884
|
+
_draw_geom(gi)
|
|
885
|
+
if __import__("os").environ.get("DN_GEOM_DEBUG"):
|
|
886
|
+
from collections import Counter
|
|
887
|
+
drawn = Counter(self.geoms[gi]["group"] for gi in range(len(self.geoms))
|
|
888
|
+
if self._geom_visible(gi) and alpha[gi] >= 0.999)
|
|
889
|
+
print(f"[GEOM] opaque drawn by group {dict(drawn)}", flush=True)
|
|
890
|
+
trans = [gi for gi in range(len(self.geoms)) if self._geom_visible(gi) and alpha[gi] < 0.999]
|
|
891
|
+
if trans:
|
|
892
|
+
ctx.enable(ctx.BLEND)
|
|
893
|
+
ctx.blend_func = ctx.SRC_ALPHA, ctx.ONE_MINUS_SRC_ALPHA
|
|
894
|
+
ctx.depth_mask = False
|
|
895
|
+
# CULL BACK FACES. Every translucent geom here is a CLOSED shell (collider capsules and
|
|
896
|
+
# spheres; the bone meshes are opaque and went out in the pass above), so its far side is
|
|
897
|
+
# never wanted -- and without culling each shell blends TWICE. That doubling is what made
|
|
898
|
+
# `rgba alpha 0.35` behave like an opaque paint: the thigh region carries four overlapping
|
|
899
|
+
# self-collision capsules, so 8 layers at 0.35 leave 1 - 0.65^8 = 3% of what is behind them.
|
|
900
|
+
# Culled it is 4 layers, and with the alpha now at 0.12 the muscles read through at 60%.
|
|
901
|
+
ctx.enable(ctx.CULL_FACE)
|
|
902
|
+
ctx.cull_face = "back"
|
|
903
|
+
for gi in trans:
|
|
904
|
+
self.lit_prog["u_alpha"].value = alpha[gi]
|
|
905
|
+
_draw_geom(gi)
|
|
906
|
+
self.lit_prog["u_alpha"].value = 1.0
|
|
907
|
+
ctx.disable(ctx.CULL_FACE)
|
|
908
|
+
ctx.depth_mask = True
|
|
909
|
+
ctx.disable(ctx.BLEND)
|
|
910
|
+
|
|
911
|
+
if self.show_footsteps:
|
|
912
|
+
self._draw_footsteps(frame, vp)
|
|
913
|
+
|
|
914
|
+
# overlays do not sample the shadow map (thin markers; keep them crisp).
|
|
915
|
+
self.lit_prog["u_recv_shadow"].value = 0
|
|
916
|
+
if self.muscle_mode != "off":
|
|
917
|
+
if self.mtu_poly is not None and self.mtu_poly.shape[1] > 0:
|
|
918
|
+
self._draw_mtu_poly(frame, vp, eye, self.muscle_mode)
|
|
919
|
+
elif self.mtu_path is not None and self.mtu_path.shape[1] > 0:
|
|
920
|
+
self._draw_mtu_line(frame, vp, eye, self.muscle_mode)
|
|
921
|
+
if self.show_contact and self.contact is not None:
|
|
922
|
+
self._draw_contact_arrow(frame, vp, eye)
|
|
923
|
+
if self.show_trail and self.com is not None:
|
|
924
|
+
self._draw_trail(frame, vp, eye)
|
|
925
|
+
|
|
926
|
+
# --- overlay draws ---------------------------------------------------
|
|
927
|
+
def _draw_footsteps(self, frame, vp):
|
|
928
|
+
"""The footstep plan as translucent spheres resting on the ground: the swing foot's target (p0) the strongest, the next one
|
|
929
|
+
(p1) fainter, the last few swing targets fading out; left-foot targets cyan, right magenta (the map's colours). A
|
|
930
|
+
provisional plan (before the first strike after a reset) is not drawn."""
|
|
931
|
+
fs = self.footsteps
|
|
932
|
+
if frame >= len(fs) or fs[frame, 5] > 0.5:
|
|
933
|
+
return
|
|
934
|
+
ctx = self.ctx
|
|
935
|
+
r = 0.09
|
|
936
|
+
z = self.ground_z + r * 0.35 # the sphere sits slightly sunk into the floor
|
|
937
|
+
cyan, mag = (0.24, 0.86, 0.90), (0.92, 0.31, 0.86)
|
|
938
|
+
left_stance = fs[frame, 6] > 0.5
|
|
939
|
+
col_p0, col_p1 = (mag, cyan) if left_stance else (cyan, mag) # the swing foot is the other one
|
|
940
|
+
marks = [(fs[frame, 0:2], col_p0, 0.45), (fs[frame, 2:4], col_p1, 0.22)]
|
|
941
|
+
past, last = [], None
|
|
942
|
+
for k in range(frame, max(-1, frame - 600), -1): # the previous swing targets, newest first
|
|
943
|
+
if fs[k, 5] > 0.5:
|
|
944
|
+
break
|
|
945
|
+
if last is None or float(np.abs(fs[k, 0:2] - last).max()) > 1e-4:
|
|
946
|
+
if last is not None:
|
|
947
|
+
past.append((fs[k, 0:2], mag if fs[k, 6] > 0.5 else cyan))
|
|
948
|
+
last = fs[k, 0:2]
|
|
949
|
+
if len(past) >= 4:
|
|
950
|
+
break
|
|
951
|
+
marks += [(p, c, 0.10 * (1.0 - 0.2 * i)) for i, (p, c) in enumerate(past)]
|
|
952
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
953
|
+
self.lit_prog["u_recv_shadow"].value = 0
|
|
954
|
+
ctx.enable(ctx.BLEND)
|
|
955
|
+
ctx.blend_func = ctx.SRC_ALPHA, ctx.ONE_MINUS_SRC_ALPHA
|
|
956
|
+
ctx.depth_mask = False
|
|
957
|
+
ctx.enable(ctx.CULL_FACE)
|
|
958
|
+
ctx.cull_face = "back"
|
|
959
|
+
for xy, col, a in reversed(marks): # far (faint) first, the current target last
|
|
960
|
+
model = M.trs(np.array([xy[0], xy[1], z], np.float32), np.array([1, 0, 0, 0], np.float32),
|
|
961
|
+
np.array([r, r, r], np.float32))
|
|
962
|
+
nm = np.linalg.inv(model[:3, :3]).T
|
|
963
|
+
self.lit_prog["u_model"].value = _mat_gl(model)
|
|
964
|
+
self.lit_prog["u_normal_mat"].value = tuple(nm.T.astype("f4").reshape(-1))
|
|
965
|
+
self.lit_prog["u_color"].value = col
|
|
966
|
+
self.lit_prog["u_alpha"].value = a
|
|
967
|
+
self.trail_sphere.render()
|
|
968
|
+
self.lit_prog["u_alpha"].value = 1.0
|
|
969
|
+
ctx.disable(ctx.CULL_FACE)
|
|
970
|
+
ctx.depth_mask = True
|
|
971
|
+
ctx.disable(ctx.BLEND)
|
|
972
|
+
|
|
973
|
+
def _draw_contact_arrow(self, frame, vp, eye):
|
|
974
|
+
# one arrow per contact entry (count may be >1, e.g. multibody scene).
|
|
975
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
976
|
+
self.lit_prog["u_alpha"].value = 1.0
|
|
977
|
+
self.lit_prog["u_spec"].value = 0.25
|
|
978
|
+
n_contacts = self.contact.shape[1]
|
|
979
|
+
for ci in range(n_contacts):
|
|
980
|
+
c = self.contact[frame, ci]
|
|
981
|
+
witness = c[0:3]
|
|
982
|
+
force = c[3:6]
|
|
983
|
+
fmag = float(np.linalg.norm(force))
|
|
984
|
+
if fmag < 1e-3 or float(c[5]) < CONTACT_NORMAL_MIN_N: # skip degenerate + sub-floor (swing) arrows
|
|
985
|
+
continue
|
|
986
|
+
# length: log-compressed so an impact spike and the settled weight are
|
|
987
|
+
# both legible; thin constant-world-radius shaft.
|
|
988
|
+
length = 0.10 + 0.10 * np.log1p(fmag / 80.0)
|
|
989
|
+
length = float(min(length, 0.45))
|
|
990
|
+
model = self._align_z_to(force, witness, length, radius_scale=0.10)
|
|
991
|
+
nm = np.linalg.inv(model[:3, :3]).T
|
|
992
|
+
self.lit_prog["u_model"].value = _mat_gl(model)
|
|
993
|
+
self.lit_prog["u_normal_mat"].value = tuple(nm.T.astype("f4").reshape(-1))
|
|
994
|
+
self.lit_prog["u_color"].value = (1.0, 0.85, 0.1)
|
|
995
|
+
self.arrow.render()
|
|
996
|
+
|
|
997
|
+
def _muscle_split(self, frame, mi):
|
|
998
|
+
"""Per-muscle geometry inputs shared by both render modes: the world via-point polyline, its
|
|
999
|
+
segment lengths + total length, activation A, and the belly arc-length band [belly_lo, belly_hi]
|
|
1000
|
+
(= l_ce mapped onto the drawn path). Returns None for a degenerate muscle to skip."""
|
|
1001
|
+
row = self.mtu_poly[frame, mi]
|
|
1002
|
+
npts = int(round(float(row[0])))
|
|
1003
|
+
if npts < 2:
|
|
1004
|
+
return None
|
|
1005
|
+
pts = np.array([row[1 + s * 3: 4 + s * 3] for s in range(npts)], np.float64)
|
|
1006
|
+
seglen = np.linalg.norm(pts[1:] - pts[:-1], axis=1)
|
|
1007
|
+
L_poly = float(seglen.sum())
|
|
1008
|
+
if L_poly < 1e-6:
|
|
1009
|
+
return None
|
|
1010
|
+
assert self.activation is not None, (
|
|
1011
|
+
".dnrec has mtu_poly but no activation channel; regenerate it via rl_env_render.muscle_channels")
|
|
1012
|
+
A = float(self.activation[frame, mi, 0])
|
|
1013
|
+
rad_vol = float(self.activation[frame, mi, 1]) # V/pi (m^3)
|
|
1014
|
+
l_mtu_r = float(self.activation[frame, mi, 2])
|
|
1015
|
+
l_ce_r = float(self.activation[frame, mi, 3])
|
|
1016
|
+
assert l_mtu_r > 1e-6, f"invalid l_mtu={l_mtu_r:g} for muscle {mi}; cannot render MTU split"
|
|
1017
|
+
assert l_ce_r > 1e-6, f"invalid l_ce={l_ce_r:g} for muscle {mi}; cannot render MTU split"
|
|
1018
|
+
if rad_vol > 1e-12:
|
|
1019
|
+
assert rad_vol < MTU_LEGACY_RADVOL_MAX, (
|
|
1020
|
+
f"muscle {mi}: activation slot-1 = {rad_vol:.3e} is a length, not the volumetric "
|
|
1021
|
+
f"coefficient V/pi (m^3) from the current rl_env_render.muscle_channels; regenerate this .dnrec.")
|
|
1022
|
+
s_scale = L_poly / l_mtu_r
|
|
1023
|
+
l_se = max(l_mtu_r - l_ce_r, 0.0)
|
|
1024
|
+
belly_lo = 0.5 * l_se * s_scale
|
|
1025
|
+
belly_hi = belly_lo + min(l_ce_r, l_mtu_r) * s_scale
|
|
1026
|
+
return dict(pts=pts, seglen=seglen, A=A, rad_vol=rad_vol, l_mtu_r=l_mtu_r, l_ce_r=l_ce_r,
|
|
1027
|
+
belly_lo=belly_lo, belly_hi=belly_hi, belly_col=np.array(_mtu_activation_color(A)))
|
|
1028
|
+
|
|
1029
|
+
def _draw_mtu_poly(self, frame, vp, eye, mode):
|
|
1030
|
+
"""Draw the muscles. Mode "mtu" = smooth fusiform swept tubes (volume-conserving flattened belly)
|
|
1031
|
+
rendered by the muscle/fascicle shader; "capsule" = the older chunky capsule chain. The mtu tube
|
|
1032
|
+
geometry is BATCHED into one buffer and CACHED per (pose, bundle, aspect): a camera-only move
|
|
1033
|
+
just re-draws (world-space geometry is camera independent), so only a POSE change rebuilds."""
|
|
1034
|
+
self.muscle_prog["u_mvp"].value = _mat_gl(vp)
|
|
1035
|
+
self.muscle_prog["u_normal_mat"].value = (1, 0, 0, 0, 1, 0, 0, 0, 1)
|
|
1036
|
+
self.muscle_prog["u_light_dir"].value = tuple(self.light_dir)
|
|
1037
|
+
self.muscle_prog["u_eye"].value = tuple(eye)
|
|
1038
|
+
self.muscle_prog["u_fascicle_n"].value = float(self.fascicle_n)
|
|
1039
|
+
self.muscle_prog["u_fascicle_strength"].value = float(self.fascicle_strength)
|
|
1040
|
+
assert mode in ("mtu", "capsule"), mode
|
|
1041
|
+
if mode == "capsule":
|
|
1042
|
+
self._draw_mtu_capsule_mode(frame, vp)
|
|
1043
|
+
return
|
|
1044
|
+
key = (int(frame), int(self.muscle_bundle), round(float(self.muscle_aspect), 4))
|
|
1045
|
+
if key != self._mtu_cache_key:
|
|
1046
|
+
self._build_mtu_batch(frame)
|
|
1047
|
+
self._mtu_cache_key = key
|
|
1048
|
+
if self._mtu_nidx > 0 and self._mtu_vao is not None:
|
|
1049
|
+
self._mtu_vao.render()
|
|
1050
|
+
|
|
1051
|
+
def _draw_mtu_capsule_mode(self, frame, vp):
|
|
1052
|
+
"""Older plain-capsule look: per-muscle base radius ~sqrt(Fmax) (= sqrt(rad_vol/l_ce)), clipped to
|
|
1053
|
+
the original 2.5-12mm calibration, belly swelling with activation, series tendon a touch thinner."""
|
|
1054
|
+
tendon_col = np.array([0.94, 0.94, 0.92])
|
|
1055
|
+
for mi in range(self.mtu_poly.shape[1]):
|
|
1056
|
+
m = self._muscle_split(frame, mi)
|
|
1057
|
+
if m is None:
|
|
1058
|
+
continue
|
|
1059
|
+
base = float(np.sqrt(m["rad_vol"] / m["l_ce_r"])) if m["rad_vol"] > 1e-12 else 0.006
|
|
1060
|
+
base = float(np.clip(base, 0.0025, 0.012))
|
|
1061
|
+
self._draw_mtu_capsules(m["pts"], m["seglen"], vp, m["belly_lo"], m["belly_hi"],
|
|
1062
|
+
base * (1.0 + 0.6 * m["A"]), base * 0.55, m["belly_col"], tendon_col)
|
|
1063
|
+
|
|
1064
|
+
def _mtu_belly_radii(self, m):
|
|
1065
|
+
"""Volume-conserving belly + series-tendon radius for the fusiform tube (mtu mode)."""
|
|
1066
|
+
rad_vol, l_ce_r, l_mtu_r, A = m["rad_vol"], m["l_ce_r"], m["l_mtu_r"], m["A"]
|
|
1067
|
+
if rad_vol > 1e-12:
|
|
1068
|
+
belly_r = float(np.sqrt(rad_vol / l_ce_r)) * (1.0 + 0.12 * A) # isovolumetric + small active bulge
|
|
1069
|
+
tendon_r = MTU_TENDON_R_FRAC * float(np.sqrt(rad_vol / l_mtu_r))
|
|
1070
|
+
belly_r = float(np.clip(belly_r, MTU_BELLY_R_MIN, MTU_BELLY_R_MAX))
|
|
1071
|
+
# the free tendon end must read clearly THINNER than the belly -> cap at 0.4*belly_r (a
|
|
1072
|
+
# voluminous muscle whose raw tendon_r would otherwise saturate near the belly ends fat).
|
|
1073
|
+
tendon_r = float(np.clip(tendon_r, 0.0015, 0.4 * belly_r))
|
|
1074
|
+
else:
|
|
1075
|
+
belly_r, tendon_r = 0.017 + 0.014 * A, 0.007
|
|
1076
|
+
belly_r = min(belly_r, 0.25 * max(m["belly_hi"] - m["belly_lo"], 1e-6)) # spindle cap (no round beads)
|
|
1077
|
+
return belly_r, tendon_r
|
|
1078
|
+
|
|
1079
|
+
def _build_mtu_batch(self, frame):
|
|
1080
|
+
"""Build ALL muscle tubes for this pose into ONE interleaved vertex buffer + index buffer and
|
|
1081
|
+
upload once (instead of a VBO/VAO per muscle per frame -- the CPU-bound cost). Rebuilt only on a
|
|
1082
|
+
pose/param change (see the cache in _draw_mtu_poly)."""
|
|
1083
|
+
tendon_col = np.array([0.94, 0.94, 0.92])
|
|
1084
|
+
center = self.poses[frame, :, :2].mean(axis=0) # subject horizontal centre (for radial flatten)
|
|
1085
|
+
V, N, U, T, C, F = [], [], [], [], [], []
|
|
1086
|
+
voff = 0
|
|
1087
|
+
for mi in range(self.mtu_poly.shape[1]):
|
|
1088
|
+
m = self._muscle_split(frame, mi)
|
|
1089
|
+
if m is None:
|
|
1090
|
+
continue
|
|
1091
|
+
belly_r, tendon_r = self._mtu_belly_radii(m)
|
|
1092
|
+
skew = 0.36 + 0.28 * ((np.sin(mi * 12.9898) * 43758.5453) % 1.0) # per-muscle asymmetric belly
|
|
1093
|
+
centerline, arc = self._resample_centerline(m["pts"], m["seglen"])
|
|
1094
|
+
radii, colors = self._tube_profile(arc, m["belly_lo"], m["belly_hi"], belly_r, tendon_r,
|
|
1095
|
+
m["belly_col"], tendon_col, skew=skew)
|
|
1096
|
+
rods = (self._bundle_centerlines(centerline, radii, int(self.muscle_bundle))
|
|
1097
|
+
if self.muscle_bundle > 1 else [(centerline, radii, self.muscle_aspect)])
|
|
1098
|
+
for cl, rr, asp in rods:
|
|
1099
|
+
v, n, uv, t, col, f = self._tube_arrays(cl, rr, colors, asp, center=center)
|
|
1100
|
+
V.append(v); N.append(n); U.append(uv); T.append(t); C.append(col); F.append(f + voff)
|
|
1101
|
+
voff += len(v)
|
|
1102
|
+
if self._mtu_vao is not None:
|
|
1103
|
+
self._mtu_vao.release(); self._mtu_vbo.release(); self._mtu_ibo.release()
|
|
1104
|
+
self._mtu_vao = self._mtu_vbo = self._mtu_ibo = None
|
|
1105
|
+
if not V:
|
|
1106
|
+
self._mtu_nidx = 0
|
|
1107
|
+
return
|
|
1108
|
+
inter = np.hstack([np.concatenate(V), np.concatenate(N), np.concatenate(U),
|
|
1109
|
+
np.concatenate(T), np.concatenate(C)]).astype("f4")
|
|
1110
|
+
idx = np.concatenate(F).astype("i4")
|
|
1111
|
+
self._mtu_vbo = self.ctx.buffer(inter.tobytes())
|
|
1112
|
+
self._mtu_ibo = self.ctx.buffer(idx.tobytes())
|
|
1113
|
+
self._mtu_vao = self.ctx.vertex_array(
|
|
1114
|
+
self.muscle_prog,
|
|
1115
|
+
[(self._mtu_vbo, "3f 3f 2f 3f 3f", "in_pos", "in_normal", "in_uv", "in_tangent", "in_color")],
|
|
1116
|
+
self._mtu_ibo)
|
|
1117
|
+
self._mtu_nidx = len(idx)
|
|
1118
|
+
|
|
1119
|
+
def _draw_mtu_capsules(self, pts, seglen, vp, belly_lo, belly_hi, belly_r, tendon_r,
|
|
1120
|
+
belly_col, tendon_col):
|
|
1121
|
+
"""Older muscle style: draw the via-point polyline as a chain of CAPSULES (lit_prog), split by
|
|
1122
|
+
arc-length into belly (thick, activation-red) vs tendon (thin, pale) at [belly_lo, belly_hi].
|
|
1123
|
+
Kept as the `capsule` render mode alongside the smooth fusiform tube."""
|
|
1124
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
1125
|
+
self.lit_prog["u_alpha"].value = 1.0
|
|
1126
|
+
self.lit_prog["u_spec"].value = 0.25
|
|
1127
|
+
self.lit_prog["u_recv_shadow"].value = 0
|
|
1128
|
+
bcol, tcol = tuple(belly_col), tuple(tendon_col)
|
|
1129
|
+
acc = 0.0
|
|
1130
|
+
for s in range(len(pts) - 1):
|
|
1131
|
+
ln = float(seglen[s])
|
|
1132
|
+
if ln < 1e-6:
|
|
1133
|
+
continue
|
|
1134
|
+
a, b = pts[s], pts[s + 1]
|
|
1135
|
+
seg_lo, seg_hi = acc, acc + ln
|
|
1136
|
+
acc = seg_hi
|
|
1137
|
+
cuts = [c for c in (belly_lo, belly_hi) if seg_lo < c < seg_hi]
|
|
1138
|
+
bounds = [seg_lo] + sorted(cuts) + [seg_hi]
|
|
1139
|
+
for k in range(len(bounds) - 1):
|
|
1140
|
+
pa = a + (b - a) * ((bounds[k] - seg_lo) / ln)
|
|
1141
|
+
pb = a + (b - a) * ((bounds[k + 1] - seg_lo) / ln)
|
|
1142
|
+
mid = 0.5 * (bounds[k] + bounds[k + 1])
|
|
1143
|
+
if belly_lo <= mid <= belly_hi:
|
|
1144
|
+
self._draw_capsule_seg(pa, pb, belly_r, bcol)
|
|
1145
|
+
else:
|
|
1146
|
+
self._draw_capsule_seg(pa, pb, tendon_r, tcol)
|
|
1147
|
+
|
|
1148
|
+
def _resample_centerline(self, pts, seglen, target=0.010, smooth_iters=12):
|
|
1149
|
+
"""Densify the via-point polyline to ~`target` m spacing and Laplacian-smooth the interior so the
|
|
1150
|
+
swept tube rounds the via-point kinks into a natural muscle belly (no visible per-segment beads).
|
|
1151
|
+
Returns (points (K,3), arc (K,)) with arc = arc-length along the ORIGINAL polyline so the
|
|
1152
|
+
belly/tendon split maps onto the smoothed centerline unchanged."""
|
|
1153
|
+
P, S, acc = [], [], 0.0
|
|
1154
|
+
for s in range(len(pts) - 1):
|
|
1155
|
+
a, b, ln = pts[s], pts[s + 1], float(seglen[s])
|
|
1156
|
+
k = max(1, int(np.ceil(ln / target)))
|
|
1157
|
+
for t in range(k):
|
|
1158
|
+
f = t / k
|
|
1159
|
+
P.append(a + (b - a) * f)
|
|
1160
|
+
S.append(acc + ln * f)
|
|
1161
|
+
acc += ln
|
|
1162
|
+
P.append(pts[-1])
|
|
1163
|
+
S.append(acc)
|
|
1164
|
+
P = np.asarray(P, np.float64)
|
|
1165
|
+
for _ in range(smooth_iters): # rounds the sharp via-point corners
|
|
1166
|
+
Q = P.copy()
|
|
1167
|
+
Q[1:-1] = 0.5 * P[1:-1] + 0.25 * P[:-2] + 0.25 * P[2:]
|
|
1168
|
+
P = Q
|
|
1169
|
+
return P, np.asarray(S, np.float64)
|
|
1170
|
+
|
|
1171
|
+
def _tube_profile(self, S, belly_lo, belly_hi, belly_r, tendon_r, belly_col, tendon_col, skew=0.5):
|
|
1172
|
+
"""Per-centerline-point radius + colour along the arc-length S. The WHOLE muscle-tendon unit is ONE
|
|
1173
|
+
smooth fusiform SPINDLE: thin (tendon_r) at the free tendon ends, swelling to the peak belly_r at the
|
|
1174
|
+
belly centre, tapering gradually across the tendons (Scheepers 1997; Wilhelms & Van Gelder 1997). So
|
|
1175
|
+
the tendon is thick where it meets the belly and taper to a THIN free end -- no thin-string-with-a-lump
|
|
1176
|
+
(the tendon thickens toward the belly) and no blunt fat termination (the ends taper to tendon_r).
|
|
1177
|
+
`skew` in (0,1) biases the belly PEAK proximal/distal. Radius and colour are DECOUPLED: the RADIUS is
|
|
1178
|
+
the isovolumetric spindle (peak == belly_r keeps volume readable), while the fibre(red)/tendon(white)
|
|
1179
|
+
COLOUR is a separate l_ce-band split, so the red length still reads l_ce."""
|
|
1180
|
+
S = np.asarray(S, np.float64)
|
|
1181
|
+
L = float(S[-1]) if S.size else 0.0
|
|
1182
|
+
band = max(belly_hi - belly_lo, 1e-6)
|
|
1183
|
+
sk = min(max(skew, 0.15), 0.85)
|
|
1184
|
+
c = belly_lo + sk * band # belly peak location along the arc
|
|
1185
|
+
|
|
1186
|
+
def _smoother(x): # C2 smootherstep, flat slope at BOTH ends
|
|
1187
|
+
x = np.clip(x, 0.0, 1.0)
|
|
1188
|
+
return x * x * x * (x * (x * 6.0 - 15.0) + 10.0)
|
|
1189
|
+
|
|
1190
|
+
# single spindle: rise over [0,c], fall over [c,L]; the product peaks (==1) at c and -> 0 at the ends,
|
|
1191
|
+
# so R == belly_r at the belly centre (volume) and tapers smoothly to tendon_r at both free ends.
|
|
1192
|
+
prox = _smoother(S / c) if c > 1e-9 else np.ones_like(S)
|
|
1193
|
+
dist = _smoother((L - S) / (L - c)) if (L - c) > 1e-9 else np.ones_like(S)
|
|
1194
|
+
R = tendon_r + (belly_r - tendon_r) * (prox * dist)
|
|
1195
|
+
|
|
1196
|
+
# colour: fibre(belly_col) over the l_ce band, tendon(tendon_col) elsewhere, with a short smooth
|
|
1197
|
+
# transition centred on each junction (half-max == l_ce boundary). Independent of the radius spindle.
|
|
1198
|
+
def _ss(e0, e1, x):
|
|
1199
|
+
tt = np.clip((x - e0) / max(e1 - e0, 1e-9), 0.0, 1.0)
|
|
1200
|
+
return tt * tt * (3.0 - 2.0 * tt)
|
|
1201
|
+
tw = float(np.clip(0.04 * band, 0.003, 0.010)) # colour-transition half-width [m]
|
|
1202
|
+
w = _ss(belly_lo - tw, belly_lo + tw, S) * (1.0 - _ss(belly_hi - tw, belly_hi + tw, S))
|
|
1203
|
+
C = tendon_col[None, :] + (belly_col - tendon_col)[None, :] * w[:, None]
|
|
1204
|
+
return R, C
|
|
1205
|
+
|
|
1206
|
+
def _tube_arrays(self, centerline, radii, colors, aspect=1.0, seg=14, center=None):
|
|
1207
|
+
"""Build one swept tube's (verts, normals, uv, tangents, per-vertex colour, faces) for the
|
|
1208
|
+
BATCH. `aspect`>1 = flattened elliptical belly; when `center` (subject horizontal centre) is given,
|
|
1209
|
+
the flatten is ORIENTED so the thin axis points radially outward from the body's vertical axis
|
|
1210
|
+
(the muscle hugs the limb). Colour is per centerline point, repeated to every ring vertex."""
|
|
1211
|
+
radial = None
|
|
1212
|
+
if center is not None and abs(aspect - 1.0) > 1e-6:
|
|
1213
|
+
radial = centerline.copy()
|
|
1214
|
+
radial[:, 0] -= center[0]
|
|
1215
|
+
radial[:, 1] -= center[1]
|
|
1216
|
+
radial[:, 2] = 0.0 # outward in the horizontal (limb-wrapping) plane
|
|
1217
|
+
verts, norms, uv, tang, faces = M.swept_tube(centerline, radii, seg=seg, aspect=aspect, radial=radial)
|
|
1218
|
+
row = seg + 1
|
|
1219
|
+
col = np.repeat(colors.astype(np.float32), row, axis=0)
|
|
1220
|
+
n_caps = verts.shape[0] - len(centerline) * row # 0 or 2 cap-centre vertices
|
|
1221
|
+
if n_caps > 0:
|
|
1222
|
+
col = np.vstack([col, np.stack([colors[0], colors[-1]])[:n_caps].astype(np.float32)])
|
|
1223
|
+
return verts, norms, uv, tang, col, faces
|
|
1224
|
+
|
|
1225
|
+
def _bundle_centerlines(self, centerline, radii, K):
|
|
1226
|
+
"""VIPER-style muscle BUNDLE: fill the belly cross-section with K thinner sub-rods (a centre rod +
|
|
1227
|
+
a ring of K-1) offset in the parallel-transport frame. Sub-rod radius = R/sqrt(K) (K rods keep ~the
|
|
1228
|
+
same total cross-section area/volume); the ring offset = R - r_sub tapers with R so the bundle
|
|
1229
|
+
converges at the tendon ends. Returns a list of (sub_centerline, sub_radii, aspect=1.0)."""
|
|
1230
|
+
T, Nrm = M.parallel_frames(centerline)
|
|
1231
|
+
Bin = np.cross(T, Nrm)
|
|
1232
|
+
R = np.asarray(radii, np.float64)
|
|
1233
|
+
sub_r = np.clip(R / np.sqrt(float(K)), 0.0015, None)
|
|
1234
|
+
offsets = [(0.0, 0.0)] + [(np.cos(2 * np.pi * k / (K - 1)), np.sin(2 * np.pi * k / (K - 1)))
|
|
1235
|
+
for k in range(K - 1)]
|
|
1236
|
+
rods = []
|
|
1237
|
+
for ox, oy in offsets:
|
|
1238
|
+
mag = np.maximum(R - sub_r, 0.0) * float(np.hypot(ox, oy)) # 0 for centre rod, tapers on ring
|
|
1239
|
+
rods.append((centerline + (Nrm * ox + Bin * oy) * mag[:, None], sub_r, 1.0))
|
|
1240
|
+
return rods
|
|
1241
|
+
|
|
1242
|
+
def _draw_mtu_line(self, frame, vp, eye, mode):
|
|
1243
|
+
"""Draw the muscle-tendon unit as a belly/tendon split (diffneusim-main
|
|
1244
|
+
convention, src/diffneusim/mtu_render.py): a straight origin->insertion path
|
|
1245
|
+
split along its length into proximal tendon + muscle belly + distal tendon.
|
|
1246
|
+
Belly = fiber length l_ce (thick, activation-colored pale->red); the two
|
|
1247
|
+
tendons = series-elastic length l_se = l_mtu - l_ce, split 50/50 (thin,
|
|
1248
|
+
near-white). All lengths come from the engine (activation channel)."""
|
|
1249
|
+
if self.mtu_path is None:
|
|
1250
|
+
return
|
|
1251
|
+
assert mode in ("mtu", "capsule"), mode # both draw the belly/tendon split as capsules
|
|
1252
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
1253
|
+
for mi in range(self.mtu_path.shape[1]): # one MTU per channel item (1 or N muscles)
|
|
1254
|
+
org = self.mtu_path[frame, mi, 0:3]
|
|
1255
|
+
ins = self.mtu_path[frame, mi, 3:6]
|
|
1256
|
+
A = float(self.activation[frame, mi, 0]) if self.activation is not None else 0.5
|
|
1257
|
+
d = ins - org
|
|
1258
|
+
L = float(np.linalg.norm(d))
|
|
1259
|
+
if L < 1e-5:
|
|
1260
|
+
continue
|
|
1261
|
+
u = d / L
|
|
1262
|
+
tendon_r = 0.008
|
|
1263
|
+
belly_r = 0.018 + 0.018 * A # belly swells with activation
|
|
1264
|
+
belly_col = _mtu_activation_color(A)
|
|
1265
|
+
tendon_col = (0.94, 0.94, 0.92) # near-white series tendon
|
|
1266
|
+
assert self.activation is not None, (
|
|
1267
|
+
".dnrec has mtu_path but no activation channel; regenerate it via rl_env_render.muscle_channels")
|
|
1268
|
+
l_mtu = float(self.activation[frame, mi, 2])
|
|
1269
|
+
l_ce = float(self.activation[frame, mi, 3])
|
|
1270
|
+
assert l_mtu > 1e-5, (
|
|
1271
|
+
f"invalid l_mtu={l_mtu:g} for MTU {mi}; cannot render MTU split")
|
|
1272
|
+
assert l_ce > 1e-6, (
|
|
1273
|
+
f"invalid l_ce={l_ce:g} for MTU {mi}; refusing to render an accidental tendon-only MTU. "
|
|
1274
|
+
"Fix the .dnrec producer (rl_env_render.muscle_channels).")
|
|
1275
|
+
# belly occupies l_ce of the path, centered; tendons take the rest 50/50.
|
|
1276
|
+
l_se = max(l_mtu - l_ce, 0.0)
|
|
1277
|
+
belly_len = float(np.clip(l_ce, 0.0, l_mtu))
|
|
1278
|
+
prox = 0.5 * l_se
|
|
1279
|
+
# map along-path distances (in MTU-length units) onto the drawn segment of
|
|
1280
|
+
# world length L (path is straight here, so world == path scaling 1:1).
|
|
1281
|
+
s = L / l_mtu # world-per-mtu-length
|
|
1282
|
+
p0 = org
|
|
1283
|
+
p1 = org + u * (prox * s)
|
|
1284
|
+
p2 = org + u * ((prox + belly_len) * s)
|
|
1285
|
+
p3 = ins
|
|
1286
|
+
if prox * s > 1e-4:
|
|
1287
|
+
self._draw_capsule_seg(p0, p1, tendon_r, tendon_col)
|
|
1288
|
+
if belly_len * s > 1e-4:
|
|
1289
|
+
self._draw_capsule_seg(p1, p2, belly_r, belly_col)
|
|
1290
|
+
if prox * s > 1e-4:
|
|
1291
|
+
self._draw_capsule_seg(p2, p3, tendon_r, tendon_col)
|
|
1292
|
+
|
|
1293
|
+
def _draw_polyline(self, pts, radius, color):
|
|
1294
|
+
for i in range(len(pts) - 1):
|
|
1295
|
+
if float(np.linalg.norm(pts[i + 1] - pts[i])) < 1e-6:
|
|
1296
|
+
continue
|
|
1297
|
+
self._draw_capsule_seg(pts[i], pts[i + 1], radius, color)
|
|
1298
|
+
|
|
1299
|
+
def _draw_capsule_seg(self, a, b, radius, color):
|
|
1300
|
+
"""Draw a CAPSULE spanning world points a->b at the given radius: a
|
|
1301
|
+
capless cylinder for the shaft + a hemisphere-grade sphere cap at each
|
|
1302
|
+
end (rounded ends, matching the bone capsules)."""
|
|
1303
|
+
col = tuple(color)
|
|
1304
|
+
# shaft (capless cylinder scaled [r, r, |b-a|])
|
|
1305
|
+
model = self._capsule_between(a, b, radius)
|
|
1306
|
+
nm = np.linalg.inv(model[:3, :3]).T
|
|
1307
|
+
self.lit_prog["u_model"].value = _mat_gl(model)
|
|
1308
|
+
self.lit_prog["u_normal_mat"].value = tuple(nm.T.astype("f4").reshape(-1))
|
|
1309
|
+
self.lit_prog["u_color"].value = col
|
|
1310
|
+
self.mtu_cyl.render()
|
|
1311
|
+
# rounded end caps (unit spheres scaled by radius)
|
|
1312
|
+
sscale = np.array([radius, radius, radius], dtype=np.float32)
|
|
1313
|
+
ident = np.array([1, 0, 0, 0], dtype=np.float32)
|
|
1314
|
+
for end in (a, b):
|
|
1315
|
+
cm = M.trs(end.astype(np.float32), ident, sscale)
|
|
1316
|
+
cnm = np.linalg.inv(cm[:3, :3]).T
|
|
1317
|
+
self.lit_prog["u_model"].value = _mat_gl(cm)
|
|
1318
|
+
self.lit_prog["u_normal_mat"].value = tuple(cnm.T.astype("f4").reshape(-1))
|
|
1319
|
+
self.lit_prog["u_color"].value = col
|
|
1320
|
+
self.trail_sphere.render()
|
|
1321
|
+
|
|
1322
|
+
def _draw_trail(self, frame, vp, eye):
|
|
1323
|
+
# small spheres along the COM track, faded by recency. Two sources: a live-sim progressively
|
|
1324
|
+
# accumulates `_trail_pts` (frame is pinned at 0, so the com channel can't provide history);
|
|
1325
|
+
# playback reads the past track straight from the com channel up to the current frame.
|
|
1326
|
+
if self._trail_pts:
|
|
1327
|
+
pts = list(self._trail_pts)
|
|
1328
|
+
elif self.com is not None:
|
|
1329
|
+
n_back = 60
|
|
1330
|
+
step = max(1, frame // n_back) if frame > 0 else 1
|
|
1331
|
+
pts = [self.com[fi, 0] for fi in range(0, frame + 1, step)]
|
|
1332
|
+
else:
|
|
1333
|
+
return
|
|
1334
|
+
self.lit_prog["u_mvp"].value = _mat_gl(vp)
|
|
1335
|
+
s = 0.02
|
|
1336
|
+
for k, p in enumerate(pts):
|
|
1337
|
+
model = M.trs(np.asarray(p, np.float32), np.array([1, 0, 0, 0], dtype=np.float32),
|
|
1338
|
+
np.array([s, s, s], dtype=np.float32))
|
|
1339
|
+
nm = np.linalg.inv(model[:3, :3]).T
|
|
1340
|
+
recency = (k + 1) / max(1, len(pts))
|
|
1341
|
+
col = (0.2 + 0.6 * recency, 0.9 * recency, 0.3 + 0.5 * recency)
|
|
1342
|
+
self.lit_prog["u_model"].value = _mat_gl(model)
|
|
1343
|
+
self.lit_prog["u_normal_mat"].value = tuple(nm.T.astype("f4").reshape(-1))
|
|
1344
|
+
self.lit_prog["u_color"].value = col
|
|
1345
|
+
self.trail_sphere.render()
|
|
1346
|
+
|
|
1347
|
+
# --- geometry helpers for overlays -----------------------------------
|
|
1348
|
+
def _align_z_to(self, vec, origin, length, radius_scale=1.0):
|
|
1349
|
+
"""Model matrix orienting a +z unit-arrow to `vec`, placed at `origin`,
|
|
1350
|
+
scaled to `length` along the arrow and radius_scale across."""
|
|
1351
|
+
v = vec / (np.linalg.norm(vec) + 1e-9)
|
|
1352
|
+
q = _quat_from_to(np.array([0, 0, 1.0]), v)
|
|
1353
|
+
scale = np.array([radius_scale, radius_scale, length], dtype=np.float32)
|
|
1354
|
+
return M.trs(origin.astype(np.float32), q, scale)
|
|
1355
|
+
|
|
1356
|
+
def _capsule_between(self, a, b, radius):
|
|
1357
|
+
"""Model matrix for the unit capsule (radius 1, half_len 0.5, along z)
|
|
1358
|
+
stretched/oriented to span a->b with the given world radius."""
|
|
1359
|
+
d = b - a
|
|
1360
|
+
L = np.linalg.norm(d) + 1e-9
|
|
1361
|
+
q = _quat_from_to(np.array([0, 0, 1.0]), d / L)
|
|
1362
|
+
mid = 0.5 * (a + b)
|
|
1363
|
+
# unit capsule spans z in [-0.5-1, 0.5+1] (hemispheres add radius). We want
|
|
1364
|
+
# the cylindrical part length = L; scale z by L (caps then stick out by
|
|
1365
|
+
# radius*scale_z which is fine visually for a thin muscle line).
|
|
1366
|
+
scale = np.array([radius, radius, L], dtype=np.float32)
|
|
1367
|
+
return M.trs(mid.astype(np.float32), q, scale)
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
def _mtu_activation_color(value: float):
|
|
1371
|
+
"""Muscle-belly activation colormap: LIGHT PINK (a=0) -> DEEP RED (a=1).
|
|
1372
|
+
|
|
1373
|
+
The old map ran [0.85,0.24,0.22] -> [0.87,0.07,0.08] -- two nearly identical reds, so activation was
|
|
1374
|
+
invisible (every belly read as the same red regardless of a). This spans a wide, perceptually clear
|
|
1375
|
+
pink->crimson ramp so a is legible at a glance. The low endpoint is a clear PINK (green/blue well
|
|
1376
|
+
below red), NOT the pale cream near-white ([0.94,0.94,0.92]) that used to be confusable with the
|
|
1377
|
+
tendon colour -- so a belly always reads as muscle, and activation drives the pink->red saturation."""
|
|
1378
|
+
value = float(np.clip(value, 0.0, 1.0))
|
|
1379
|
+
low = np.array([1.00, 0.80, 0.82]) # light pink (a=0) -- clearly muscle, not tendon
|
|
1380
|
+
high = np.array([0.60, 0.00, 0.02]) # deep red (a=1)
|
|
1381
|
+
c = low + value * (high - low)
|
|
1382
|
+
return (float(c[0]), float(c[1]), float(c[2]))
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
def _quat_from_to(a: np.ndarray, b: np.ndarray) -> np.ndarray:
|
|
1386
|
+
"""Shortest-arc quaternion [w,x,y,z] rotating unit a -> unit b."""
|
|
1387
|
+
a = a / (np.linalg.norm(a) + 1e-12)
|
|
1388
|
+
b = b / (np.linalg.norm(b) + 1e-12)
|
|
1389
|
+
d = float(np.dot(a, b))
|
|
1390
|
+
if d > 0.999999:
|
|
1391
|
+
return np.array([1, 0, 0, 0], dtype=np.float32)
|
|
1392
|
+
if d < -0.999999:
|
|
1393
|
+
# 180 deg: pick any orthogonal axis
|
|
1394
|
+
axis = np.cross(a, np.array([1.0, 0, 0]))
|
|
1395
|
+
if np.linalg.norm(axis) < 1e-6:
|
|
1396
|
+
axis = np.cross(a, np.array([0, 1.0, 0]))
|
|
1397
|
+
axis /= np.linalg.norm(axis)
|
|
1398
|
+
return np.array([0.0, axis[0], axis[1], axis[2]], dtype=np.float32)
|
|
1399
|
+
axis = np.cross(a, b)
|
|
1400
|
+
w = 1.0 + d
|
|
1401
|
+
q = np.array([w, axis[0], axis[1], axis[2]], dtype=np.float32)
|
|
1402
|
+
return q / np.linalg.norm(q)
|