
    Mi\                         S SK r S SKr S SKr " S S5      r " S S5      r " S S5      rS rS	 r	S
 r
g! \ a    Sr N2f = f)    Nc                   T    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	S r
Srg	)
ContactData   zC
Data structure for holding information about a collision contact.
c                     [        U5      U l        US   UR                  US   UR                  0U l        UR
                  U l        UR                  U l        UR                  U l
        g)z
Initialize a ContactData.

Parameters
----------
names : list of str
  The names of the two objects in order.
contact : fcl.Contact
  The contact in question.
r      N)setnamesb1b2_indsnormal_normalpos_pointpenetration_depth_depth)selfr	   contacts      k/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/collision.py__init__ContactData.__init__   sR     Z
Ah

E!HgjjA
~~kk//    c                     U R                   $ )zn
The 3D intersection normal for this contact.

Returns
-------
normal : (3,) float
  The intersection normal.
)r   r   s    r   r   ContactData.normal"   s     ||r   c                     U R                   $ )zn
The 3D point of intersection for this contact.

Returns
-------
point : (3,) float
  The intersection point.
)r   r   s    r   pointContactData.point.        {{r   c                     U R                   $ )z
The penetration depth of the 3D point of intersection for this contact.

Returns
-------
depth : float
  The penetration depth.
)r   r   s    r   depthContactData.depth:   r   r   c                      U R                   U   $ )z
Returns the index of the face in contact for the mesh with
the given name.

Parameters
----------
name : str
  The name of the target object.

Returns
-------
index : int
  The index of the face in collision
r   r   names     r   indexContactData.indexF        zz$r   )r   r   r   r   r	   N)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r!   r'   __static_attributes__ r   r   r   r      sM    0" 	 	 	 	 	 	 r   r   c                   :    \ rS rSrSrS r\S 5       rS rS r	Sr
g)	DistanceDataX   z@
Data structure for holding information about a distance query.
c                     [        U5      U l        US   UR                  US   UR                  0U l        US   UR
                  S   US   UR
                  S   0U l        UR                  U l        g)z
Initialize a DistanceData.

Parameters
----------
names : list of str
  The names of the two objects in order.
contact : fcl.DistanceResult
  The distance query result.
r   r   N)	r   r	   r
   r   r   nearest_points_pointsmin_distance	_distance)r   r	   results      r   r   DistanceData.__init__]   so     Z
Ah		58VYY?
!Hf++A.!Hf++A.
  ,,r   c                     U R                   $ )z
Returns the distance between the two objects.

Returns
-------
distance : float
  The euclidean distance between the objects.
)r9   r   s    r   distanceDistanceData.distancep   s     ~~r   c                      U R                   U   $ )z
Returns the index of the closest face for the mesh with
the given name.

Parameters
----------
name : str
  The name of the target object.

Returns
-------
index : int
  The index of the face in collisoin.
r$   r%   s     r   r'   DistanceData.index|   r)   r   c                      U R                   U   $ )z
The 3D point of closest distance on the mesh with the given name.

Parameters
----------
name : str
  The name of the target object.

Returns
-------
point : (3,) float
  The closest point.
)r7   r%   s     r   r   DistanceData.point   s     ||D!!r   )r9   r   r7   r	   N)r*   r+   r,   r-   r.   r   r/   r=   r'   r   r0   r1   r   r   r3   r3   X   s*    -& 	 	 ""r   r3   c                       \ rS rSrSrS rSS jrS rS r SS jr	SS	 jr
SS
 jr SS jrSS jrSS jrS rS rSrg)CollisionManager   z 
A mesh-mesh collision manager.
c                     [         c  [        S5      e0 U l        [        R                  " S 5      U l        [         R                  " 5       U l        U R                  R                  5         g)z+
Initialize a mesh-mesh collision manager.
Nz7No FCL Available! Please install the python-fcl libraryc                      g Nr1   r1   r   r   <lambda>+CollisionManager.__init__.<locals>.<lambda>   s    dr   )	fcl
ValueError_objscollectionsdefaultdict_namesDynamicAABBTreeCollisionManager_managersetupr   s    r   r   CollisionManager.__init__   sP     ;VWW
 "--l;;;=r   Nc                 x   Uc  [         R                  " S5      n[         R                  " U[         R                  S9nUR                  S:w  a  [        S5      eU R                  U5      n[        R                  " USS2SS24   USS2S4   5      n[        R                  " XE5      nXR                  ;   a(  U R                  R                  U R                  U   5        XdS.U R                  U'   XR                  [        U5      '   U R                  R                  U5        U R                  R!                  5         U$ )a6  
Add an object to the collision manager.

If an object with the given name is already in the manager,
replace it.

Parameters
----------
name : str
  An identifier for the object
mesh : Trimesh object
  The geometry of the collision object
transform : (4,4) float
  Homogeneous transform matrix for the object
N   dtype)rV   rV   ztransform must be (4,4)!   )objgeom)npeye
asanyarrayfloat32shaperL   _get_fcl_objrK   	TransformCollisionObjectrM   rR   unregisterObjectrP   idregisterObjectupdate)r   r&   mesh	transformr[   tos          r   
add_objectCollisionManager.add_object   s   $ q	IMM)2::>	??f$788   & MM)BQBF+Yrr1u-=>( ::MM**4::d+;<#$3

4 $BtH$$Q'r   c                 n   XR                   ;   a  U R                  R                  U R                   U   S   5        U R                  R                  U R                   U   S   5        [	        U R                   R                  U5      S   5      nU R                  R                  U5        g[        U S35      e)zp
Delete an object from the collision manager.

Parameters
----------
name : str
  The identifier for the object
rZ   r[    not in collision manager!N)rM   rR   rd   rg   re   poprP   rL   )r   r&   geom_ids      r   remove_objectCollisionManager.remove_object   s     ::MM**4::d+;E+BCMM  D!1%!89-f56GKKOOG$v%?@AAr   c                     XR                   ;   a`  U R                   U   S   nUR                  USS2SS24   5        UR                  USS2S4   5        U R                  R	                  U5        g[        U S35      e)z
Set the transform for one of the manager's objects.
This replaces the prior transform.

Parameters
----------
name : str
  An identifier for the object already in the manager
transform : (4,4) float
  A new homogeneous transform matrix for the object
rZ   NrY   ro   )rM   setRotationsetTranslationrR   rg   rL   )r   r&   ri   rk   s       r   set_transformCollisionManager.set_transform   s~     ::

4 'AMM)BQBF+,Yrr1u-.MM  #v%?@AAr   c                    Uc  [         R                  " S5      nU R                  U5      n[        R                  " USS2SS24   USS2S4   5      n[        R
                  " XV5      n[        R                  " 5       nU(       d  U(       a'  [        R                  " [        R                  " SSS9S9nU R                  R                  Xx[        R                  5        UR                  R                  n	[        5       n
/ nU(       d  U(       a  UR                  R                   H  nUR                  nX:X  a  UR                   nU R#                  U5      nUS4nXR                   :X  a  [%        ['        U5      5      nU(       a  U
R)                  U5        U(       d  My  UR+                  [-        X5      5        M     U(       a  U(       a  XU4$ U(       a  X4$ U(       a  X4$ U	$ )	a  
Check a single object for collisions against all objects in the
manager.

Parameters
----------
mesh : Trimesh object
  The geometry of the collision object
transform : (4,4) float
  Homogeneous transform matrix
return_names : bool
  If true, a set is returned containing the names
  of all objects in collision with the object
return_data :  bool
  If true, a list of ContactData is returned as well

Returns
------------
is_collision : bool
  True if a collision occurs and False otherwise
names : set of str
  [OPTIONAL] The set of names of objects that collided with the
  provided one
contacts : list of ContactData
  [OPTIONAL] All contacts detected
NrV   rY   順 Tnum_max_contactsenable_contactrequest
__external)r\   r]   ra   rK   rb   rc   CollisionDataCollisionRequestrR   collidedefaultCollisionCallbackr:   is_collisionr   contactso1o2_extract_nametuplereversedaddappendr   )r   rh   ri   return_namesreturn_datar[   rj   rk   cdatar:   objs_in_collisioncontact_datar   cgr&   r	   s                   r   in_collision_single$CollisionManager.in_collision_single  s   : q	I   & MM)BQBF+Yrr1u-=>( !!#;%%,,fUYZE 	a(D(DE**  E; <<00ZZ: B))"-|,#!(5/2E%))$/; ''E(CD 1 Kl::,,''Mr   c                    [         R                  " 5       nU(       d  U(       a'  [         R                  " [         R                  " SSS9S9nU R                  R	                  U[         R
                  5        UR                  R                  n[        5       n/ nU(       d  U(       a  UR                  R                   H  nU R                  UR                  5      U R                  UR                  5      4nU(       a#  UR                  [        [        U5      5      5        U(       d  Ml  UR!                  [#        X5      5        M     U(       a  U(       a  XEU4$ U(       a  XE4$ U(       a  XF4$ U$ )aq  
Check if any pair of objects in the manager collide with one another.

Parameters
----------
return_names : bool
  If true, a set is returned containing the names
  of all pairs of objects in collision.
return_data :  bool
  If true, a list of ContactData is returned as well

Returns
-------
is_collision : bool
  True if a collision occurred between any pair of objects
  and False otherwise
names : set of 2-tup
  The set of pairwise collisions. Each tuple
  contains two names in alphabetical order indicating
  that the two corresponding objects are in collision.
contacts : list of ContactData
  All contacts detected
rz   Tr{   r~   )rK   r   r   rR   r   r   r:   r   r   r   r   r   r   r   r   sortedr   r   )	r   r   r   r   r:   r   r   r   r	   s	            r   in_collision_internal&CollisionManager.in_collision_internalP  s   0 !!#;%%,,fUYZE 	eS%A%AB**E; <<00++GJJ79K9KGJJ9WX%))%u*>?; ''E(CD 1 Kl::,,''Mr   c                    [         R                  " 5       nU(       d  U(       a'  [         R                  " [         R                  " SSS9S9nU R                  R	                  UR                  U[         R
                  5        UR                  R                  n[        5       n/ nU(       d  U(       a  UR                  R                   H  nSn	U R                  UR                  5      UR                  UR                  5      4n
U
S   c8  U R                  UR                  5      UR                  UR                  5      4n
Sn	U(       a  UR                  U
5        U(       d  M  U	(       a  [        [        U
5      5      n
UR!                  [#        X5      5        M     U(       a  U(       a  XVU4$ U(       a  XV4$ U(       a  XW4$ U$ )a  
Check if any object from this manager collides with any object
from another manager.

Parameters
-------------------
other_manager : CollisionManager
  Another collision manager object
return_names : bool
  If true, a set is returned containing the names
  of all pairs of objects in collision.
return_data : bool
  If true, a list of ContactData is returned as well

Returns
-------------
is_collision : bool
  True if a collision occurred between any pair of objects
  and False otherwise
names : set of 2-tup
  The set of pairwise collisions. Each tuple
  contains two names (first from this manager,
  second from the other_manager) indicating
  that the two corresponding objects are in collision.
contacts : list of ContactData
  All contacts detected
rz   Tr{   r~   Fr   )rK   r   r   rR   r   r   r:   r   r   r   r   r   r   r   r   r   r   r   )r   other_managerr   r   r   r:   r   r   r   reverser	   s              r   in_collision_other#CollisionManager.in_collision_other  sh   8 !!#;%%,,fUYZE 	m44eS=Y=YZ**E; <<00&&wzz2!//

; 8#**7::6%33GJJ?E #G%))%0; %huo 6 ''E(CD% 1( Kl::,,''Mr   c                    Uc  [         R                  " S5      nU R                  U5      n[        R                  " USS2SS24   USS2S4   5      n[        R
                  " XV5      n[        R                  " [        R                  " SS95      nU(       a=  [        R                  " [        R                  " SSS9[        R                  " 5       5      nU R                  R                  Xx[        R                  5        UR                  R                  n	Su  pU(       d  U(       a  UR                  R                  nX:X  a  UR                  R                  nU R!                  U5      n
U
S4nXR                  R                  :X  a  [#        [%        U5      5      n[        XR                  5      nU(       a  U(       a  XU4$ U(       a  X4$ U(       a  X4$ U	$ )	aY  
Get the minimum distance between a single object and any
object in the manager.

Parameters
---------------
mesh : Trimesh object
  The geometry of the collision object
transform : (4,4) float
  Homogeneous transform matrix for the object
return_names : bool
  If true, return name of the closest object
return_data : bool
  If true, a DistanceData object is returned as well

Returns
-------------
distance : float
  Min distance between mesh and any object in the manager
name : str
  The name of the object in the manager that was closest
data : DistanceData
  Extra data about the distance query
NrV   rY   Tenable_signed_distanceenable_nearest_pointsr   NNr   )r\   r]   ra   rK   rb   rc   r3   DistanceRequestDistanceResultrR   r=   defaultDistanceCallbackr:   r8   r   r   r   r   r   )r   rh   ri   return_namer   r[   rj   rk   ddatar=   r&   datar   r	   s                 r   min_distance_single$CollisionManager.min_distance_single  s   6 q	I   & MM)BQBF+Yrr1u-=>(   !4!4D!QR$$##*.t ""$	E 	q)D)DE<<,,  
+Bz\\__%%b)D<(E\\__$huo.||4D;4''>!>!Or   c                 D   [         R                  " [         R                  " SS95      nU(       a=  [         R                  " [         R                  " SSS9[         R                  " 5       5      nUb  XR                  ;  a  [        U S35      eU R                  U   S   nU R                  R                  U5        U R                  R                  U5        U R                  R                  XT[         R                  5        U R                  R                  U5        U R                  R                  5         O*U R                  R                  U[         R                  5        UR                  R                  nSu  pxU(       d  U(       as  U R                  UR                  R                  5      U R                  UR                  R                   5      4n[        XtR                  5      n[#        [%        U5      5      nU(       a  U(       a  XgU4$ U(       a  Xg4$ U(       a  Xh4$ U$ )a4  
Get the minimum distance between objects in the manager.

If name is provided, computes the minimum distance between the
specified object and any other object in the manager.
If name is None, computes the minimum distance between any pair
of objects in the manager.

Parameters
-------------
name : str or None
  If provided, the identifier for the object already in the manager
  to compute distances from. If None, computes distances between
  all pairs of objects.
return_names : bool
  If true, a 2-tuple is returned containing the names
  of the closest objects.
return_data : bool
  If true, a DistanceData object is returned as well

Returns
-----------
distance : float
  Min distance between objects
names : (2,) str
  The names of the closest objects
data : DistanceData
  Extra data about the distance query
Tr   r   ro   rZ   r   )rK   r3   r   r   rM   rL   rR   rd   rg   r=   r   rf   r:   r8   r   r   r   r   r   )	r   r&   r   r   r   rZ   r=   r	   r   s	            r   min_distance_internal&CollisionManager.min_distance_internal  s   <   !4!4D!QR$$##*.+/ ""$E ::% D6)C!DEE**T"5)CMM**3/MM  % MM""3s/J/JK MM((-MM  " MM""5#*E*EF<<,, ;""5<<??3""5<<??3E  ||4D&-(EKD((?">!Or   c                    [         R                  " [         R                  " SS95      nU(       a=  [         R                  " [         R                  " SSS9[         R                  " 5       5      nU R                  R                  UR                  U[         R                  5        UR                  R                  nSu  pgU(       d  U(       a  SnU R                  UR                  R                  5      UR                  UR                  R                  5      4nUS   cL  SnU R                  UR                  R                  5      UR                  UR                  R                  5      4n[        U5      n	U(       a  [        [        U	5      5      n	[        XR                  5      nU(       a  U(       a  XVU4$ U(       a  XV4$ U(       a  XW4$ U$ )a  
Get the minimum distance between any pair of objects,
one in each manager.

Parameters
----------
other_manager : CollisionManager
  Another collision manager object
return_names : bool
  If true, a 2-tuple is returned containing
  the names of the closest objects.
return_data : bool
  If true, a DistanceData object is returned as well

Returns
-----------
distance : float
  The min distance between a pair of objects,
  one from each manager.
names : 2-tup of str
  A 2-tuple containing two names (first from this manager,
  second from the other_manager) indicating
  the two closest objects.
data : DistanceData
  Extra data about the distance query
Tr   r   r   Fr   )rK   r3   r   r   rR   r=   r   r:   r8   r   r   r   r   r   )
r   r   r   r   r   r=   r	   r   r   dnamess
             r   min_distance_other#CollisionManager.min_distance_otherd  se   6   !4!4D!QR$$##*.+/ ""$E 	}55uc>Y>YZ<<,, ;G""5<<??3++ELLOO<E Qx&&u||7!//@
 5\Fx/05DKD((?">!Or   c                 X    UR                   (       a  [        U5      nU$ [        U5      nU$ )z
Get a BVH or Convex for a mesh.

Parameters
-------------
mesh : Trimesh
  Mesh to create BVH/Convex for

Returns
--------------
obj : fcl.BVHModel or fcl.Convex
  BVH/Convex object of source mesh
)	is_convexmesh_to_convexmesh_to_BVH)r   rh   rZ   s      r   ra   CollisionManager._get_fcl_obj  s-     >> &C 
 d#C
r   c                 2    U R                   [        U5         $ )z
Retrieve the name of an object from the manager by its
CollisionObject, or return None if not found.

Parameters
-----------
geom : CollisionObject or BVHModel
  Input model

Returns
------------
names : hashable
  Name of input geometry
)rP   re   )r   r[   s     r   r   CollisionManager._extract_name  s     {{2d8$$r   )rR   rP   rM   rH   )NFF)FF)r*   r+   r,   r-   r.   r   rl   rr   rw   r   r   r   r   r   r   ra   r   r0   r1   r   r   rD   rD      s_    (TB&B* EJKZ4lBJ DIHTN`CJ*%r   rD   c                    [         R                  " 5       nUR                  [        U R                  5      [        U R
                  5      S9  UR                  U R
                  U R                  S9  UR                  5         U$ )z
Create a BVHModel object from a Trimesh object

Parameters
-----------
mesh : Trimesh
  Input geometry

Returns
------------
bvh : fcl.BVHModel
  BVH of input geometry
)	num_tris_num_vertices_)verts	triangles)rK   BVHModel
beginModellenfacesverticesaddSubModelendModel)rh   bvhs     r   r   r     sV     ,,.CNNS_C<NNOOO$--4::O>LLNJr   c                 (   [         R                  " S[         R                  " [        U R                  5      S4[         R
                  S9-  U R                  4SS9n[        R                  " U R                  [        U5      UR                  5       5      $ )z
Create a Convex object from a Trimesh object

Parameters
-----------
mesh : Trimesh
  Input geometry

Returns
------------
convex : fcl.Convex
  Convex of input geometry
rY   r   rW   )axis)
r\   concatenateonesr   r   int64rK   Convexr   flatten)rh   fss     r   r   r     sd     
	
RWWc$**oq):	:DJJGa
B ::dmmSWbjjl;;r   c                     [        5       n0 nU R                  R                   H3  nU R                  U   u  pEUR                  X0R                  U   US9X#'   M5     X4$ )a4  
Create collision objects from a trimesh.Scene object.

Parameters
------------
scene : trimesh.Scene
  Scene to create collision objects for

Returns
------------
manager : CollisionManager
  CollisionManager for objects in scene
objects: {node name: CollisionObject}
  Collision objects for nodes in scene
)r&   rh   ri   )rD   graphnodes_geometryrl   geometry)scenemanagerobjectsnodeTr   s         r   scene_to_collisionr     se       GG**kk$'**NN84 + 
 +
 r   )rN   numpyr\   rK   BaseExceptionr   r3   rD   r   r   r   r1   r   r   <module>r      s`     
I  I XC" C"Lo% o%d*<(c  
Cs   6 A A