
    Mi!0                     <   S r SSKrSSKJrJr  SSKJr  SSKJ	r	J
r
  SSKJr  SSKJrJr   SSKr SS
KJr  S rSS\4S jjrSS jrSS jrSS\4S jjrSS jrg! \ a  rSS	KJr  \" \5      r SrCNESrCff = f! \ a  rSS	KJr  \" \5      r SrCN_SrCff = f)zL
repair.py
-------------

Fill holes and fix winding and normals of meshes.
    N   )graph	triangles)log)faces_to_edgestriangulate_quads)connected_components)
group_rowshashable_rows)ExceptionWrapper)faces_to_pathc           	      2   U R                   (       a  g[        R                  " U R                  5      nSnU R                  R                  [        R                  5      R                  5       n[        R                  " U5       H  nUR                  U5      n[        [        UR                  5       5      5      n[        R                  " XV5       H  n[        R                  " U5      nX7   n[!        U5      n	[#        [        R$                  " U	SS9SS9n
['        U
5      S:X  a  MV  XS      nUS   S   US   S   :X  d  Mq  US-  nX7S      SSS2   X7S   '   M     M     US:  a  X0l        [(        R*                  " SU['        U R                  5      S	-  5        g)
z
Traverse and change mesh faces in-place to make sure
winding is correct with edges on adjacent faces in
opposite directions.

Parameters
-------------
mesh : Trimesh
  Source geometry to alter in-place.
Nr   r   axis   require_countzflipped %d/%d edges   )is_winding_consistentnxfrom_edgelistface_adjacencyfacesviewnpndarraycopyr	   subgraphnextiternodes	bfs_edgesravelr   r
   sortlenr   debug)mesh	graph_allflippedr   
componentsgstart	face_pairpairedgesoverlap	edge_pairs               h/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/repair.pyfix_windingr4   !   sY    !!  !4!45IGJJOOBJJ',,.E --i8
z* T!'')_% a/I
 +I#D"4(E Q!7qIG7|q aj)I|A)A,q/11&+aL&9$B$&?l#% 0 9: {
II#Wc$**o.AB    	multibodyc                 v   U(       d2  U R                   (       a   U R                  S:  a  U R                  5         g[        U R                  5      n[
        R                  " [        U R                  5      [        S9nU R                  nU R                  nU R                  R                  S5      nU H}  n[        U5      S:  a  M  [        R                   " Xg   R                  S5      5      u  pU(       a  U	(       d  MM  [        R                  " XG   XW   SS9R                  n
U
S:  d  My  SX7'   M     UR!                  5       (       at  S	U R"                  ;   a'  U R$                  R'                  5       nX==   S
-  ss'   OSn[
        R(                  " U R                  U   5      U R                  U'   Ub  Xl        ggg)z
Check to see if a mesh has normals pointing "out."

Parameters
-------------
mesh : trimesh.Trimesh
  Mesh to fix in-place.
multibody : bool
  If True will try to fix normals on every body
g        Ndtype)r         )r   r   T)crossesskip_inertiaface_normalsg      )is_watertightvolumeinvertr	   r   r   zerosr&   r   boolr   triangles_crossr0   reshaper   mass_propertiesany_cacher>   r   fliplr)r(   r6   groupsfliptricross
face_edges
face_indexis_tightis_woundr@   normalss               r3   fix_inversionrS   Z   sq    $++"3KKM "$"5"56F 88C

O40D ..C  E##G,J 
 z?Q"001G1O1OPW1XY X **OU%6T

& 	
 C<#D' , xxzzT[[('',,.GMT!MG99TZZ%56

4 '  r5   c                 ,    [        U 5        [        XS9  g)a  
Fix the winding and direction of a mesh face and
face normals in-place.

Really only meaningful on watertight meshes but will orient all
faces and winding in a uniform way for non-watertight face
patches as well.

Parameters
-------------
mesh : trimesh.Trimesh
  Mesh to fix normals on
multibody : bool
  if True try to correct normals direction
  on every body rather than just one

Notes
--------------
mesh.faces : will flip columns on inverted faces
)r6   N)r4   rS   )r(   r6   s     r3   fix_normalsrU      s    , $,r5   c                    [         R                  " U R                  5      n[        UR	                  5       5      R                  5        VVs/ s H  u  p4US:w  d  M  UPM     nnn[        R                  " U5      nUbb  UR                  S:w  aR  [        R                  " U5      nUR                  S:X  d  UR                  S:X  d  / SQnXR                  R                  U'   U$ s  snnf )a8  
Return the index of faces in the mesh which break the
watertight status of the mesh.

Parameters
--------------
mesh : trimesh.Trimesh
  Mesh to check broken faces on
color: (4,) uint8 or None
  Will set broken faces to this color if not None

Returns
---------------
broken : (n, ) int
  Indexes of mesh.faces
r   r   )r;   )r   )   r   r   rW   )r   r   r   dictdegreeitemsr   arraysizeshapevisualface_colors)r(   color	adjacencykvbrokens         r3   broken_facesre      s    "   !4!45I !1!1!34::<G<DAQa<FGXXfFV[[A-t#u{{d':$E*/'M Hs   C!C!use_fanc                 Z   [        U R                  5      S:  a  gU R                  (       a  g[        U R                  SS9n[        U5      S:  a  gU R
                  U   n[        R                  " [        R                  " U5      5      n[        XAS9n[        U5      S:X  a  g[        U5      n[        U5      n[        U5      n[        R                  " Xx5      R                  S5      R                  SS	9n	[        R                   " XY   5      XY'   U R#                  U5        U R                  $ )
a  
Fill boundary holes in-place using fans, which may result
in bad answers if the holes are non convex!

Face colors and attributes will be padded with default values
so shapes match.

Parameters
----------
mesh : trimesh.Trimesh
    Mesh will be repaired in-place.
use_fan
  If passed, holes larger than quads will be triangulated
  using fans which are only valid for non-convex holes.
r   FTr   r   )rf   r   )r   r   r   )r&   r   r?   r
   edges_sortedr0   r   cycle_basisr   r   r   r   r   isinrE   rG   rI   extend_faces)
r(   rf   boundary_groupsboundaryholes	new_faces	new_edgeshashable_newhashable_oldneeds_reverses
             r3   
fill_holesrt      s     4:: !!2!2!DO
?a zz/*H NN2++H56E "%9I
9~ y)I !+L *L GGL7??HLLRSLTM  "yy)ABI 	i r5   c                 D   Uc)  [         R                  " [        U R                  5      5      n[	        X5      S    Vs/ s HL  n[        UR
                  5      S:  d  M  UR
                  S   UR
                  S   :X  d  M@  UR
                  PMN     nnU R                  nU R                  nU R                  nU R                  nU(       a  [         R                  " U V	s/ s H  oU	   R                  SS9PM     sn	5      n
[        U5      n[         R                  " XZ45      n[        U5       VV	s/ s HL  u  p[         R                  " [         R                  " [        U	5      S-
  [         S9X-   -  U	SS U	SS 45      PMN     nnn	OXU V	s/ s HK  n	[         R                  " [         R                  " [        U	5      S-
  [         S9U	S   -  U	SS	 U	S
S 45      PMM     nn	[#        [%        [        U5      5      U5       H  u  pUSS2SS24   R'                  5       nUR)                  SS9  UR+                  USS9n[        U5      S:X  a  MN  [         R,                  " U5      nXgU      n[.        R0                  " X^SS    5      u  nnUR3                  5       (       d  M  US   n[         R4                  " UU5      nUR                  5       S:  d  M  [         R6                  " U5      X'   M     [         R                  " U5      nU(       a  UW
4$ U$ s  snf s  sn	f s  sn	nf s  sn	f )a  
Create a fan stitch over the boundary of the specified
faces. If the boundary is non-convex a triangle fan
is going to be extremely wonky.

Parameters
-----------
mesh : trimesh.Trimesh
  Mesh to create fan stitch on.
faces : (n,) int
  Face indexes to stitch with triangle fans.
insert_vertices : bool
  Allow stitching to insert new vertices?

Returns
----------
fan : (m, 3) int
  New triangles referencing mesh.vertices.
vertices : (p, 3) float
  Inserted vertices (only returned `if insert_vertices`)
Nentitiesr   r   r   r   r   r8   r   
   g|=)r)r   aranger&   r   r   pointsverticesr>   
edges_faceedges_sorted_treer[   meanvstack	enumeratecolumn_stackonesintzipranger   r%   query_ball_pointconcatenater   rR   rG   dotrI   )r(   r   insert_verticeser{   r|   rR   r}   	tree_edgep	centroidscountifantquery
edge_indexoriginalcheckvalidsigns                        r3   stitchr     s   , }		#djj/* t+J77Aqxx=1 	!"!!< 	7   }}HG J&&IHHG1qk..A.6GH	H99h23
 "&)
) OORWWSVaZs;uyI1Sb6STUVUWSXYZ) 	 
 
 OORWWSVaZs;adBAaGQqQSWUV 	 
 E#c(OS) crc12gJOO	A
 **1*6u:?^^E*
 j12 !((BQ%9uyy{{a vvh&99;?YYq\CF; *> ))C.CI~JQ  H

s%   LL LL/AL
AL)F)N)NF)__doc__numpyr    r   r   	constantsr   geometryr   r   r	   groupingr
   r   networkxr   BaseExceptionE
exceptionsr   path.exchange.miscr   r4   rC   rS   rU   re   rt   r    r5   r3   <module>r      s       7 ' /(16CrB(4 B(J-6:=d =@dK   -	!	B  (,$Q'M(s.   A A= A:"A55A:=BBB