@@ -480,24 +480,6 @@ static void mapPose(const mjtNum xpos1[3], const mjtNum xquat1[4],
480
480
mju_quat2Mat (mat12 , quat12 );
481
481
}
482
482
483
- // subtract mesh position from sdf transformation
484
- static void undoTransformation (const mjModel * m , const mjData * d , int g ,
485
- mjtNum sdf_xpos [3 ], mjtNum sdf_quat [4 ]) {
486
- mjtNum * xpos = d -> geom_xpos + 3 * g ;
487
- mjtNum * xmat = d -> geom_xmat + 9 * g ;
488
- if (m -> geom_type [g ] == mjGEOM_MESH || m -> geom_type [g ] == mjGEOM_SDF ) {
489
- mjtNum negpos [3 ], negquat [4 ], xquat [4 ];
490
- mjtNum * pos = m -> mesh_pos + 3 * m -> geom_dataid [g ];
491
- mjtNum * quat = m -> mesh_quat + 4 * m -> geom_dataid [g ];
492
- mju_mat2Quat (xquat , xmat );
493
- mju_negPose (negpos , negquat , pos , quat );
494
- mju_mulPose (sdf_xpos , sdf_quat , xpos , xquat , negpos , negquat );
495
- } else {
496
- mju_copy3 (sdf_xpos , xpos );
497
- mju_mat2Quat (sdf_quat , xmat );
498
- }
499
- }
500
-
501
483
//---------------------------- narrow phase -----------------------------------------------
502
484
503
485
// comparison function for contact sorting
@@ -767,8 +749,7 @@ int mjc_HFieldSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int
767
749
768
750
// collision between a mesh and a signed distance field
769
751
int mjc_MeshSDF (const mjModel * m , const mjData * d , mjContact * con , int g1 , int g2 , mjtNum margin ) {
770
- mjtNum * pos1 = d -> geom_xpos + 3 * g1 ;
771
- mjtNum * mat1 = d -> geom_xmat + 9 * g1 ;
752
+ mjGETINFO ;
772
753
773
754
mjtNum offset [3 ], rotation [9 ], corners [9 ], x [3 ], depth ;
774
755
mjtNum points [3 * MAXSDFFACE ], dist [MAXMESHPNT ], candidate [3 * MAXMESHPNT ];
@@ -790,10 +771,10 @@ int mjc_MeshSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g
790
771
sdf .geomtype = & geomtype ;
791
772
792
773
// compute transformation from g1 to g2
793
- mjtNum pos2true [ 3 ], sdf_quat [4 ], quat1 [4 ];
774
+ mjtNum sdf_quat [4 ], quat1 [4 ];
794
775
mju_mat2Quat (quat1 , mat1 );
795
- undoTransformation ( m , d , g2 , pos2true , sdf_quat );
796
- mapPose (pos1 , quat1 , pos2true , sdf_quat , offset , rotation );
776
+ mju_mat2Quat ( sdf_quat , mat2 );
777
+ mapPose (pos1 , quat1 , pos2 , sdf_quat , offset , rotation );
797
778
798
779
// binary tree search
799
780
collideBVH (m , (mjData * )d , g1 , offset , rotation , faces , & npoints , & n0 , & sdf );
@@ -845,7 +826,7 @@ int mjc_MeshSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g
845
826
846
827
// add only the first mjMAXCONPAIR pairs
847
828
for (int i = 0 ; i < mju_min (ncandidate , mjMAXCONPAIR ); i ++ ) {
848
- cnt = addContact (points , con , candidate + 3 * index [i ], pos2true , sdf_quat ,
829
+ cnt = addContact (points , con , candidate + 3 * index [i ], pos2 , sdf_quat ,
849
830
dist [index [i ]], cnt , m , & sdf , (mjData * )d );
850
831
}
851
832
@@ -871,17 +852,13 @@ int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, m
871
852
872
853
// compute transformations from/to g1 to/from g2
873
854
mjtNum quat1 [4 ], quat2 [4 ];
874
- mjtNum pos1true [3 ], offset21 [3 ], rotation21 [9 ], rotation12 [9 ];
875
- mjtNum pos2true [3 ], offset1 [3 ], rotation1 [9 ], offset12 [3 ];
876
- mjtNum offset2 [3 ], rotation2 [9 ], squat1 [4 ], squat2 [4 ];
877
- undoTransformation (m , d , g1 , pos1true , squat1 );
878
- undoTransformation (m , d , g2 , pos2true , squat2 );
855
+ mjtNum offset21 [3 ], rotation21 [9 ], rotation12 [9 ];
856
+ mjtNum offset12 [3 ], offset2 [3 ], rotation2 [9 ];
879
857
mju_mat2Quat (quat1 , mat1 );
880
858
mju_mat2Quat (quat2 , mat2 );
881
- mapPose (pos2 , quat2 , pos1 , quat1 , offset1 , rotation1 );
882
- mapPose (pos1 , quat1 , pos1true , squat1 , offset2 , rotation2 );
883
- mapPose (pos2true , squat2 , pos1true , squat1 , offset21 , rotation21 );
884
- mapPose (pos1true , squat1 , pos2true , squat2 , offset12 , rotation12 );
859
+ mapPose (pos1 , quat1 , pos1 , quat1 , offset2 , rotation2 );
860
+ mapPose (pos2 , quat2 , pos1 , quat1 , offset21 , rotation21 );
861
+ mapPose (pos1 , quat1 , pos2 , quat2 , offset12 , rotation12 );
885
862
886
863
// axis-aligned bounding boxes in g1 frame
887
864
for (int i = 0 ; i < 8 ; i ++ ) {
@@ -893,8 +870,8 @@ int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, m
893
870
vec2 [1 ] = (i & 2 ? size2 [1 ]+ size2 [4 ] : size2 [1 ]- size2 [4 ]);
894
871
vec2 [2 ] = (i & 4 ? size2 [2 ]+ size2 [5 ] : size2 [2 ]- size2 [5 ]);
895
872
896
- mju_mulMatVec3 (vec2 , rotation1 , vec2 );
897
- mju_addTo3 (vec2 , offset1 );
873
+ mju_mulMatVec3 (vec2 , rotation21 , vec2 );
874
+ mju_addTo3 (vec2 , offset21 );
898
875
899
876
for (int k = 0 ; k < 3 ; k ++ ) {
900
877
aabb1 [0 + k ] = mju_min (aabb1 [0 + k ], vec1 [k ]);
@@ -983,7 +960,7 @@ int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, m
983
960
984
961
// contact point and normal - we use the midsurface where SDF1=SDF2 as zero level set
985
962
sdf .type = mjSDFTYPE_MIDSURFACE ;
986
- cnt = addContact (contacts , con , x , pos2true , squat2 , dist , cnt , m , & sdf , (mjData * )d );
963
+ cnt = addContact (contacts , con , x , pos2 , quat2 , dist , cnt , m , & sdf , (mjData * )d );
987
964
988
965
// SHOULD NOT OCCUR
989
966
if (cnt > mjMAXCONPAIR ) {
0 commit comments