
    MiR                        S SK r S SKrS SKJr  S SKrSSKJrJr  SSK	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JrJrJrJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#  SSKJ$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK3J4r4   SSK5J6r6J7r7  S\\;   4S jr<S\\;   4S jr=    S/S \S!\\;   S"\\R|                     S#\\;   S$\?S\4S% jjr@    S0S \S!\\;   S"\\R|                     S$\?S&\\   S\4S' jjrAS\
4S( jrBS1S) jrCS*\;S\4S+ jrDS\4S, jrE  S2S!\\;   S"\\R|                     S$\?S\4S- jjrF\C\C\C\CS..rG0 rH\HR                  \$5        \HR                  \,5        \HR                  \*5        \HR                  \&5        \HR                  \(5        \HR                  \!5        \HR                  \#5        \HR                  \25        \HR                  \.5        \HR                  \05        \HR                  \45        \HR                  \5        0 rJ\JR                  \5        g! \8 a  r9\" \95      r6S\:4S jr7 Sr9C9GNSr9C9ff = f)3    N)deepcopy   )	resolversutil)Trimesh)ExceptionWrapper)Geometry
LoadSource
PointCloud)Sceneappend_scenes)DictLoadableOptionalSet)log   )misc)_binvox_loaders)_cascade_loaders)_collada_loaders)_gltf_loaders)_misc_loaders)_obj_loaders)_off_loaders)_ply_loaders)_stl_loaders)_threedxml_loaders)_three_loaders)_xaml_loaders)_xyz_loaders)	load_pathpath_formatsreturnc                      [        5       $ N)set     o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/exchange/load.pyr$   r$   %   s	    ur*   c                      [         R                  5        V Vs1 s H  u  p[        U[        5      (       a  M  U iM      snn $ s  snn f )z
Get a list of mesh formats available to load.

Returns
-----------
loaders
  Extensions of available mesh loaders
  i.e. `{'stl', 'ply'}`
)mesh_loadersitems
isinstancer   )kvs     r+   mesh_formatsr2   )   s3     ',,.V.$!jDT6UA.VVVs
   AAc                      [        5       n U R                  [        5       5        U R                  [        R	                  5       5        U $ )z
Get a list of all available loaders


Returns
-----------
loaders
  Extensions of all available loaders
  i.e. `{'stl', 'ply', 'dxf'}`
)r2   updater$   compressed_loaderskeys)loaderss    r+   available_formatsr8   7   s4     nGNN<>"NN%**,-Nr*   file_obj	file_typeresolverforceallow_remotec                    [        S	U UUUS.UD6nUS:X  a&  [        R                  " S5        UR                  5       $ US:X  a  [        R                  " S5        U$ UR                  R
                  n1 SknXx;  a  [        UR                  5      S:X  an  [        [        UR                  R                  5       5      5      n	U	R                  R                  UR                  5        [        U	[        5      (       d  US;   a  U	$ U$ )
a  
THIS FUNCTION IS DEPRECATED but there are no current plans for it to be removed.

For new code the typed load functions `trimesh.load_scene` or `trimesh.load_mesh`
are recommended over `trimesh.load` which is a backwards-compatibility wrapper
that mimics the behavior of the old function and can return any geometry type.

Parameters
-----------
file_obj : str, or file- like object
  The source of the data to be loadeded
file_type: str
  What kind of file type do we have (eg: 'stl')
resolver : trimesh.visual.Resolver
  Object to load referenced assets like materials and textures
force : None or str
  For 'mesh': try to coerce scenes into a single mesh
  For 'scene': try to coerce everything into a scene
allow_remote
  If True allow this load call to work on a remote URL.
kwargs : dict
  Passed to geometry __init__

Returns
---------
geometry : Trimesh, Path2D, Path3D, Scene
  Loaded geometry as trimesh classes
r9   r:   r;   r=   meshzO`trimesh.load(force='mesh')` is a compatibility wrapper for `trimesh.load_mesh`scenezQ`trimesh.load(force='scene')` is a compatibility wrapper for `trimesh.load_scene`>   glbzipgltf3dxmltar.gzr   >	   dxfmshobjoffplystlsvgxamlbinvoxr)   )
load_scener   debugto_meshsourcer:   lengeometrynextitervaluesmetadatar4   r/   r   )
r9   r:   r;   r<   r=   kwargsloadedkindalways_scenegeoms
             r+   loadr_   I   s    L  !	
 F 		]	
 ~~	'			_	
  ==""D<LC$8A$=D//123V__-dJ''4 
4
 
,
 KMr*   rY   c           
      h   [        U UUUS9n [        U [        5      (       a  [        U 5      nGOSUR                  [        5       ;   a%  [        SUR                  UR                  US.UD6nGOUR                  [        ;   ab  [        U5      nUR                  [        UR                     " SUR                  UR                  UR                  US.UD65        [        S0 UD6nOUR                  [        ;   a#  [        UR                  4SUR                  0UD6nOiUR                  [        ;   a<  [        UR                     " SUR                  UR                  UR                  S.UD6nO[        SUR                   S35      eUR                   (       a  UR                  R#                  5         [        U[$        5      (       d  Xgl        [%        U5      nXgl        UR(                  R+                  5        H	  n	Xil        M     U$ ! UR                   (       a  UR                  R#                  5         f f = f)	a  
Load geometry into the `trimesh.Scene` container. This may contain
any `parent.Geometry` object, including `Trimesh`, `Path2D`, `Path3D`,
or a `PointCloud`.

Parameters
-----------
file_obj : str, or file- like object
  The source of the data to be loadeded
file_type: str
  What kind of file type do we have (eg: 'stl')
resolver : trimesh.visual.Resolver
  Object to load referenced assets like materials and textures
force : None or str
  For 'mesh': try to coerce scenes into a single mesh
  For 'scene': try to coerce everything into a scene
allow_remote
  If True allow this load call to work on a remote URL.
kwargs : dict
  Passed to geometry __init__

Returns
---------
geometry : Trimesh, Path2D, Path3D, Scene
  Loaded geometry as trimesh classes
r?   )r9   r:   rY   )r9   r:   r;   rY   r:   r9   r:   r;   zfile_type 'z' not supportedr)   )_parse_file_argsr/   dict_load_kwargsr:   r$   r#   r9   r-   r   r4   r;   r5   _load_compressedvoxel_loadersNotImplementedError
was_openedcloser   _sourcerU   rX   )
r9   r:   r;   r=   rY   rZ   argr[   parsedgs
             r+   rP   rP      s   H !	C+!h%%!(+F]]ln, --! 	F ]]l*f%FMMS]]+  \\!mm \\%	
  "+F+F]]00%cllVcmmVvVF]]m+"3==1 -- 	F &CMM?/&RSS
 >>LL fe$$v N__##%	 & M >>LL  s   E5H .H1c                  4    [        U 0 UD6R                  5       $ )a  
Load a file into a Trimesh object.

Parameters
-----------
file_obj : str or file object
  File name or file with mesh data
file_type : str or None
  Which file type, e.g. 'stl'
kwargs : dict
  Passed to Trimesh constructor

Returns
----------
mesh
  Loaded geometry data.
)rP   rR   )argsrZ   s     r+   	load_meshrp     s    $ t&v&..00r*   c           
         [        XUS9n/ n[        R                  " UR                  UR                  S9n[
        R                  " U5      n0 nU(       a  [        5       n	OuUR                  5        V
s1 s H'  n
[        R                  " U
5      R                  5       iM)     nn
UR                  [        5       5      (       a  [        5       n	O
[        5       n	UR                  5        H{  u  p [        R                  " U5      R                  5       nUS;   a  SSKnM6  US:X  a  SSKnUR$                  " U 5      X'   MV  X;  a  M]  UR'                  [)        S
U UUS.UD65        M}     UR0                  (       a  UR                  R3                  5         [5        U5      n[7        U[8        5      (       a  UR:                  R=                  U5        U$ s  sn
f ! [*         a    [,        R.                  " SSS	9   GM  f = f)a  
Given a compressed archive load all the geometry that
we can from it.

Parameters
----------
file_obj : open file-like object
  Containing compressed data
file_type : str
  Type of the archive file
mixed : bool
  If False, for archives containing both 2D and 3D
  data will only load the 3D data into the Scene.

Returns
----------
scene : trimesh.Scene
  Geometry loaded in to a Scene object
ra   )r9   r:   )yamlymlr   Njsonzfailed to load file in zipT)exc_infor)   )rb   r   
decompressr9   r:   r   ZipResolverr8   r6   split_extensionlower
isdisjointr2   r$   r.   rr   	safe_loadrt   r_   appendrP   BaseExceptionr   rQ   rh   ri   r   r/   r   rY   r4   )r9   r:   r;   mixedrZ   rk   
geometriesarchivemeta_archive	availablencontains	file_namecompressed_typerr   rt   results                    r+   re   re     s   , HH
UC J oos||s}}MG$$W-H L %'	 >F]]_M_D((+113_M|~..$I$I&}}		C"229=CCEO /1 F**.))H*=' 1  %-% 	+  /F ~~ :&F &%  |,Mi NJ  	CII2TB	Cs*   2.G+.GG;GGG54G5urlc                     [        SU SS.UD6$ )a:  
Load a mesh at a remote URL into a local trimesh object.

This is a thin wrapper around:
  `trimesh.load_scene(file_obj=url, allow_remote=True, **kwargs)`

Parameters
------------
url
  URL containing mesh file
**kwargs
  Passed to `load_scene`

Returns
------------
loaded : Trimesh, Path, Scene
  Loaded result
T)r9   r=   r)   )rP   )r   rZ   s     r+   load_remoter   v  s    & @s@@@r*   c                    ^ S[         4U4S jjnS[        4U4S jjnU4S jnU4S jnU4S jn[        T5      S:X  a,  [        U 5      S:X  a  [        U S   [        5      (       a  U S   mUS	4US
4US4US4US44nTR                  5        VV	s0 s H  u  pU	c  M
  X_M     sn	nmU H(  u  p[        U4S jU 5       5      (       d  M!  U
" 5       s  $    [        STR                  5        35      es  sn	nf )z8
Load geometry from a properly formatted dict or kwargs
r%   c                  @  >^ T	R                  SS5      n T	S   R                  5        VVs0 s H  u  pU[        U5      _M     nnnU b  [        5       nUR                  R                  U5        U  H  n[        U[        5      (       a  UR                  R
                  " S0 UD6  M6  [        R                  " U5      (       d  MS  [        U5      S:X  d  Md  UR                  R
                  " US   US   40 US   D6  M     O[        U5      nT	R                  S5      nU(       a  XTl        T	R                  S	5      Ul        S
T	;   a  T	S
   UR                  l        T	R                  S5      m[        T[        5      (       a   UR                  R                  T	S   5        U$ [        T[         5      (       a:  U4S jU4S j/nU H%  n UR                  R                  U" 5       5          U$     U$ Tb  [$        R&                  " S5        U$ s  snnf ! ["         a     MZ  f = f)z
Load a scene from our kwargs.

class:      Scene
geometry:   dict, name: Trimesh kwargs
graph:      list of dict, kwargs for scene.graph.update
base_frame: str, base frame of graph
graphNrU      r   r   r   cameracamera_transform
base_framerY   c                  0   > [         R                  " T 5      $ r'   )rt   loadsrY   s   r+   <lambda>4_load_kwargs.<locals>.handle_scene.<locals>.<lambda>  s    

8,r*   c                  P   > [         R                  " T R                  SS5      5      $ )N'")rt   r   replacer   s   r+   r   r     s    

8#3#3C#=>r*   zunloadable metadatar)   )getr.   rd   r   rU   r4   r/   rc   r   r   is_sequencerT   r   r   r   rY   strr}   r   warning)
r   r0   r1   rU   rA   r   
candidatescrY   rZ   s
           @r+   handle_scene"_load_kwargs.<locals>.handle_scene  s    

7D)39*3E3K3K3MN3M41A|A&3MNGENN!!(+a&&KK&&++%%a((SVq[KK&&qtQqT:QqT:	  (OE H%!L%+ZZ0B%CE"6!%+L%9EKK"::j)h%%NN!!&"45$ # #&&
 ->J  NN))!#.     !KK-.S OH % s   H	 H
HHc                     > [        T S   [        5      (       d  [        T S   [        5      (       a  [        S0 [        R                  " T 5      D6$ [        S0 T D6$ )z3
Handle the keyword arguments for a Trimesh object
verticesfacesr)   )r/   rc   r   r   	load_dictrZ   s   r+   handle_mesh!_load_kwargs.<locals>.handle_mesh  sL    
 fZ($//:fWot3T3T4T^^F344   r*   c            	         > TS   TS   p[        U [        5      (       a  [        U 5      $ U[        ;   a  [	        S0 [        U   " XS9D6$ [        SU S35      e)z
Handle an exported mesh.
datar:   )r:   `z` is not supportedr)   )r/   rc   rd   r-   r   rg   )r   r:   rZ   s     r+   handle_export#_load_kwargs.<locals>.handle_export  sb     !.&*=idD!!%%,&P\)4TOPP!Ai[0B"CDDr*   c                     > SSK Jn Jn  [        R                  " TS   5      n[        U5      S:  a  U " 5       $ US   S:X  a  U " S0 TD6$ US   S:X  a  U" S0 TD6$ [        S5      e)Nr   )Path2DPath3Dr   r   r   zVertices must be 2D or 3D!r)   )pathr   r   npshaperT   
ValueError)r   r   r   rZ   s      r+   handle_path!_load_kwargs.<locals>.handle_path  si    )
+,u:>8O8q=#F##1X]#F##9::r*   c                     > [        S0 T D6$ )Nr)   r   r   s   r+   handle_pointcloud'_load_kwargs.<locals>.handle_pointcloud  s    #F##r*   r   r   )rU   )r   r   )entitiesr   )r   )r:   r   c              3   ,   >#    U  H	  oT;   v   M     g 7fr'   r)   ).0irZ   s     r+   	<genexpr>_load_kwargs.<locals>.<genexpr>  s     -HqF{Hs   zunable to determine type: )	r   r   rT   r/   rc   r.   allr   r6   )ro   rZ   r   r   r   r   r   handlersr0   r1   funcexpecteds    `          r+   rd   rd     s    
3% 3j! !
E;$
 6{aCINz$q'4/H/Ha
 
}%	+,	./	M*	-.H  &||~?~tqdad~?F"-H---6M #
 1&++-A
BB @s   	C0C0c                    SnSn[         R                  " U 5      (       a  [        U R                  5       5      n [         R                  " U 5      (       a  Uc  [        S5      e[        U [        5      (       Ga   [        R                  R                  [        R                  R                  U 5      5      n[        R                  R                  U5      nU(       aB  Uc  [        R                  " U5      nUc  [         R                  " USS/S9n[!        US5      n SnOS	U ;   a  S
n[         R"                  " U 5      n OSU ;   d  SU ;   a  U(       d  [        S5      eSSKn[         R                  " UR&                  R)                  U 5      R+                  SS5      S   R+                  S5      S   R-                  5       5      n[        R.                  " U S9n[         R"                  " UR1                  5       5      n OUc  [        SU  S35      e[        U[        5      (       a  SU;   a  [        R                  R                  [        R                  R                  U5      5      n	[         R                  " U5      n[        R                  R3                  U	5      (       a  U	nUc  [        R                  " U5      nUb  UR5                  5       nUcW  [7        U S5      (       aF  U R8                  b9  [;        U R8                  5      S:  a   [        R                  " U R8                  5      n[=        U UUUUS9$ ! [         a    SnSn GNnf = f)ak  
Given a file_obj and a file_type try to magically convert
arguments to a file-like object and a lowercase string of
file type.

Parameters
-----------
file_obj : str
  if string represents a file path, returns:
    file_obj:   an 'rb' opened file object of the path
    file_type:  the extension from the file path

 if string is NOT a path, but has JSON-like special characters:
    file_obj:   the same string passed as file_obj
    file_type:  set to 'json'

 if string is a valid-looking URL
    file_obj: an open 'rb' file object with retrieved data
    file_type: from the extension

 if string is none of those:
    raise ValueError as we can't do anything with input

 if file like object:
    ValueError will be raised if file_type is None
    file_obj:  same as input
    file_type: same as input

 if other object: like a shapely.geometry.Polygon, etc:
    file_obj:  same as input
    file_type: if None initially, set to the class name
                (in lower case), otherwise passed through

file_type : str
     type of file and handled according to above

Returns
-----------
args
  Populated `_FileArg` message
NFz)`file_type` must be set for file objects!rF   tar.bz2)specialrbT{rt   zhttps://zhttp://z,unable to load URL with `allow_remote=False`r   ?r   /)r   zstring is not a file: `r   .name)r9   r:   	file_pathrh   r;   )r   
is_pathlibr   absoluteis_filer   r/   osr   abspath
expanduserisfiler}   r   FilePathResolverrx   openwrap_as_streamurllibparseunquotesplitstripWebResolverget_baseexistsry   hasattrr   rT   r
   )
r9   r:   r;   r=   rZ   r   rh   r   r   r   s
             r+   rb   rb     s   b I Jx  x((*+||H)"3DEE(C  	(:(:8(DEIWW^^I.F $55i@   00XyDYZ	It,HJh"	..x8x'9+@#$%STT !00LL((288a@CII#NrRXXZ	 %00X>..x/@/@/BC" #:8*A!FGG)S!!cY&6 wwrww11)<=((3	77>>$I$55i@ OO%	 	Hf%%MM%"--hmm<   	FI	s   9AL1 1MM)rC   r   rF   bz2)NNNF)NNFN)NNF)NF)Krt   r   copyr   numpyr    r   r   baser   
exceptionsr   parentr	   r
   pointsr   scene.scener   r   typedr   r   r   r   r   r   rO   r   cascader   daer   rD   r   r   rI   r   rJ   r   rK   r   rL   r   	threedxmlr   threemfr    rN   r!   xyzr"   path.exchange.loadr#   r$   r}   Er(   r   r2   r8   ResolverLikeboolr_   rP   rp   re   r   rd   rb   r5   r-   r4   rf   r)   r*   r+   <module>r      s    	     ) )  . 1 1   # % !       ) #  <Wc#h W3s8 (  $15QQ}Q y--.Q C=	Q
 Q Ql  $15#bb}b y--.b 	b
 tnb bJ1' 1*\~AS Au A,wCX wCz 26	I}I y--.I 	I I\ 	     M "   L !   L !   L !   L !   $ %   M "   M "   & '   N #   L !   $ %    _ %W   #I#  s   $H: :I II