
    jR                        d dl Z d dlZd dlmZ d dlZddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddlm$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 	 ddl5m6Z6m7Z7 dee;   fdZ<dee;   fdZ=	 	 	 	 d/d ed!ee;   d"eej|                     d#ee;   d$e?defd%Z@	 	 	 	 d0d ed!ee;   d"eej|                     d$e?d&ee   defd'ZAde
fd(ZBd1d)ZCd*e;defd+ZDdefd,ZE	 	 d2d!ee;   d"eej|                     d$e?defd-ZFeCeCeCeCd.ZGi ZHeHj                  e$       eHj                  e,       eHj                  e*       eHj                  e&       eHj                  e(       eHj                  e!       eHj                  e#       eHj                  e2       eHj                  e.       eHj                  e0       eHj                  e4       eHj                  e       i ZJeJj                  e       y# e8$ rZ9 ee9      Z6de:fdZ7Y dZ9[9dZ9[9ww xY w)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                      t               S N)set     B/DATA/.local/lib/python3.12/site-packages/trimesh/exchange/load.pyr$   r$   %   s	    ur*   c                  ~    t         j                         D  ch c]  \  } }t        |t              r|  c}} S c c}} w )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   )   s5     ',,.V.$!QjDT6UA.VVVs   99c                      t               } | j                  t                      | j                  t        j	                                | S )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                    t        d	| |||d|}|dk(  r%t        j                  d       |j                         S |dk(  rt        j                  d       |S |j                  j
                  }h d}||vrt        |j                        dk(  rgt        t        |j                  j                                     }	|	j                  j                  |j                         t        |	t              s|dv r|	S |S )
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           
      6   t        | |||      }	 t        | t              rt        |       }nI|j                  t               v r%t        d|j                  |j                  |d|}n|j                  t        v rat        |      }|j                  t        |j                     d|j                  |j                  |j                  |d|       t        di |}n|j                  t        v r#t        |j                  fd|j                  i|}nf|j                  t        v r;t        |j                     d|j                  |j                  |j                  d|}nt        d|j                   d      |j                   r|j                  j#                          	 t        |t$              s||_        t%        |      }||_        |j(                  j+                         D ]	  }	||	_         |S # |j                   r|j                  j#                          w w xY w)	aR  
    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 FN__##%	 & M >>LL  s   E&G/ /)Hc                  4    t        | i |j                         S )aJ  
    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           
         t        | ||      }g }t        j                  |j                  |j                        }t        j                  |      }i }|rt               }	nl|j                         D 
ch c]%  }
t        j                  |
      j                         ' }}
|j                  t                     rt               }	n
t               }	|j                         D ]t  \  }} 	 t        j                  |      j                         }|dv rddl}3|dk(  rddl} |j$                  |       ||<   R||	vrW|j'                  t)        d
| ||d|       v |j0                  r|j                  j3                          t5        |      }t7        |t8              r|j:                  j=                  |       |S c c}
w # t*        $ r t-        j.                  dd	       Y w xY w)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   , H	H
UC J oos||s}}MG$$W-H L %'	 >F]]_M_D((+113_M|~.$I$I&}}	8	C"229=CCEO /1 F**3$))H*=Y' 	1  %-% 	+  /F ~~ :&F &% |,Mi NJ  	CII2TB	Cs*   2*F1#+F6F6.F63F66 GGurlc                     t        d| dd|S )ar  
    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                     dt         ffd}dt        ffd}fd}fd}fd}t              dk(  r&t        |       dk(  rt        | d   t              r| d   |d	f|d
f|df|df|dff}j                         D 	ci c]  \  }}	|		||	 c}	}|D ]"  \  }
}t        fd|D              s |
       c S  t        dj                                c c}	}w )z@
    Load geometry from a properly formatted dict or kwargs
    r%   c                     	j                  dd      } 	d   j                         D ci c]  \  }}|t        |       }}}| t               }|j                  j                  |       | D ]{  }t        |t              r |j                  j
                  di | 0t        j                  |      sFt        |      dk(  sU |j                  j
                  |d   |d   fi |d    } nt        |      }	j                  d      }|r||_        	j                  d	      |_        d
	v r	d
   |j                  _        	j                  d      t        t              r |j                  j                  	d          |S t        t               r6fdfdg}|D ]%  }	 |j                  j                   |               |S  |S t%        j&                  d       |S c c}}w # t"        $ r Y Tw xY w)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                  .    t        j                         S r'   )rt   loadsrY   s   r+   <lambda>z4_load_kwargs.<locals>.handle_scene.<locals>.<lambda>  s    

8,r*   c                  N    t        j                   j                  dd            S )N'")rt   r   replacer   s   r+   r   z4_load_kwargs.<locals>.handle_scene.<locals>.<lambda>  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_scenez"_load_kwargs.<locals>.handle_scene  s    

7D)39*3E3K3K3MN3M41aA|A&3MNGENN!!(+a&&EKK&&++%%a(SVq[&EKK&&qtQqT:QqT:	  (OE H%!EL%+ZZ0B%CE"6!%+L%9EKK"::j)h%NN!!&"45$ # #&
 ->J  NN))!#.     !KK-.S OH % s   G  G%%	G10G1c                      t         d   t              st         d   t              rt        di t        j                         S t        di  S )zC
        Handle the keyword arguments for a Trimesh object
        verticesfacesr)   )r/   rc   r   r   	load_dictrZ   s   r+   handle_meshz!_load_kwargs.<locals>.handle_mesh  sF    
 fZ($/:fWot3T4T^^F344   r*   c                      d   d   }} t        | t              rt        |       S |t        v rt	        di t        |   | |      S t        d| d      )z*
        Handle an exported mesh.
        datar:   )r:   `z` is not supportedr)   )r/   rc   rd   r-   r   rg   )r   r:   rZ   s     r+   handle_exportz#_load_kwargs.<locals>.handle_export  sc     !.&*=idD!%%,&P\)4TYOPP!Ai[0B"CDDr*   c                      ddl m} m} t        j                  d         }t        |      dk  r |        S |d   dk(  r | di S |d   dk(  r |di S t        d      )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_pathz!_load_kwargs.<locals>.handle_path  si    )
+,u:>8O8q=#F##1X]#F##9::r*   c                      t        di  S )Nr)   r   r   s   r+   handle_pointcloudz'_load_kwargs.<locals>.handle_pointcloud  s    #F##r*   r   r   )rU   )r   r   )entitiesr   )r   )r:   r   c              3   &   K   | ]  }|v  
 y wr'   r)   ).0irZ   s     r+   	<genexpr>z_load_kwargs.<locals>.<genexpr>  s     -HqqF{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a
 
}%	+,	./	M*	-.H  &||~?~tq!ad~?F"h-H--6M #
 1&++-A
BB @s   
CCc                    d}d}t        j                  |       rt        | j                               } t        j                  |       r|t        d      t        | t              r	 t        j                  j                  t        j                  j                  |             }t        j                  j                  |      }|rA|t        j                  |      }|t        j                  |ddg      }t!        |d      } d}nd	| v rd
}t        j"                  |       } nd| v sd| v r|st        d      ddl}t        j                  |j&                  j)                  |       j+                  dd      d   j+                  d      d   j-                               }t        j.                  |       }t        j"                  |j1                               } n|t        d|  d      t        |t              rd|v rt        j                  j                  t        j                  j                  |            }	t        j                  |      }t        j                  j3                  |	      r|	}|t        j                  |      }||j5                         }|Ot7        | d      rC| j8                  7t;        | j8                        dkD  rt        j                  | j8                        }t=        | ||||      S # t        $ r d}d}Y Dw xY w)a  
    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   'AK6 6LL)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3II