
    MiO                     F   S SK r 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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Jr  0 S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S!_S%S%S&.ErS
SSSSSSSS S"S'S(.rS) r    SCS*\\   S+\S,\\   S-\4S. jjrS/ rS0 rS1 r S2 r!   SDS3\\   S4\4S5 jjr"S6 r#SES7 jr$S8 r%S9 r&S: r'S; r(S< r)SFS= jr*S> r+S?\0r,S?\"0r-\R\                  " S@5      r/\R\                  " SA5      r0\0b  \+\,SB'   \/b  \*\-SB'   gg)G    N)Template)structured_to_unstructuredunstructured_to_structured   )grouping	resourcesutilvisual)log)triangulate_quads)Resolver)NDArrayOptionalchari1ucharu1shorti2ushortu2inti4int8int16int32int64i8uintu4uint8uint16uint32uint64u8floatf4float16f2float32f8)float64doubler-   )r   r   r   r   r   r   r    r%   r'   r)   r+   c                 .    [         U R                  SS    $ )z
Returns the closest ply equivalent of a numpy type

Parameters
---------
_numpy_type : a numpy datatype

Returns
---------
ply_type : string
   N)_inverse_dtypesstr)_numpy_types    n/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/exchange/ply.py_numpy_type_to_ply_typer4   6   s     ;??12.//    resolverfix_textureprefer_colorskip_materialsc                    [        U 5      u  pxn	U(       a  [        Xp5        O[        Xp5        Sn
U(       dH   SSKnU	b@  UR	                  U	5      nUR
                  R                  [        R                  " U5      5      n
[        XX#S9nU$ ! [         a    [        R                  " S5         N.[         a    [        R                  " SSS9   NNf = f)a>  
Load a PLY file from an open file object.

Parameters
---------
file_obj : an open file- like object
  Source data, ASCII or binary PLY
resolver
  Object which can resolve assets
fix_texture
  If True, will re- index vertices and faces
  so vertices with different UV coordinates
  are disconnected.
skip_materials
  If True, will not load texture (if present).
prefer_color
  None, 'vertex', or 'face'
  Which kind of color to prefer if both defined

Returns
---------
mesh_kwargs : dict
  Data which can be passed to
  Trimesh constructor, eg: a = Trimesh(**mesh_kwargs)
Nr   z%textures require `pip install pillow`zunable to load image!Texc_info)imageelementsr7   r8   )_parse_header
_ply_ascii_ply_binary	PIL.ImagegetImageopenr	   wrap_as_streamImportErrorr   debugBaseExceptionwarning_elements_to_kwargs)file_objr6   r7   r8   r9   argskwargsr>   is_ascii
image_namer=   PILdatas                r3   load_plyrS   E   s    H &38%<"H
 8&H' E	@ %||J/		t':':4'@A !KF M  	?II=> 	@KK/$?	@s   AB
 
 C,CCc                    UR                  5        Hk  u  p#UR                  R                  S5      nUR                  S:  a)  U R	                  U S3S4X$UR
                  S   4/5        MY  U R                  X$45        Mm     U $ )z
Parses attribute datatype to populate a numpy dtype list

Parameters
----------
dtype : list of numpy datatypes
  operated on in place
attributes : dict
  contains all the attributes to parse

Returns
----------
dtype : list of numpy datatypes
<r/   _count<u1)itemsdtypenewbyteorderndimextendshapeappend)rY   
attributesnamerR   field_dtypes        r3   _add_attributes_to_dtyperb      sx     !&&(
jj--c299q=LLdV6?E2T

ST4VWXLL$,- ) Lr5   c                    UR                  5        Hm  u  p#UR                  S:X  a-  U R                  S[        UR                  5       SU S35        MB  U R                  S[        UR                  5       SU S35        Mo     U $ )z
Parses attributes in to ply header entries

Parameters
----------
header : list of ply header entries
  operated on in place
attributes : dict
  contains all the attributes to parse

Returns
----------
header : list
  Contains ply header entries
r/   z	property  
zproperty list uchar )rX   r[   r^   r4   rY   )headerr_   r`   rR   s       r3   _add_attributes_to_headerrg      s|      !&&(
99>MMI&=djj&I%J!D6QSTUMM&'>tzz'J&K1TFRTU	 ) Mr5   c                     UR                  5        HQ  u  p#UR                  S:  a8  UR                  S   [        R                  " UR                  S   5      -  X S3'   X0U'   MS     U $ )ac  
Parses attribute data in to a custom array, assumes datatype has been defined
appropriately

Parameters
----------
data_array : numpy array with custom datatype
  datatype reflects all the data to be stored for a given ply element
attributes : dict
  contains all the attributes to parse

Returns
----------
data_array : numpy array with custom datatype
r/   r   rV   )rX   r[   r]   npones)
data_arrayr_   r`   rR   s       r3   _add_attributes_to_data_arrayrl      s`      !&&(
99q=*.**Q-"''$**Q-:P*PJv'4 ) r5   c                     U R                  5        H@  nUR                  S;  a  [        S5      eUR                  R                  c  M7  [        S5      e   g)z
Asserts that a set of attributes is valid for PLY export.

Parameters
----------
attributes : dict
  Contains the attributes to validate

Raises
--------
ValueError
  If passed attributes aren't valid.
)r/   r   z/PLY attributes are limited to 1 or 2 dimensionsNz+PLY attributes must be of a single datatype)valuesr[   
ValueErrorrY   names)r_   rR   s     r3   _assert_attributes_validrq      sM     !!#99F"NOO ::'JKK $r5   vertex_normalinclude_attributesc           	         US:X  a  SnOUS;  a  [        S5      eUc  SU R                  ;   nU(       Ga  [        U S5      (       a  [        U S5      (       a  [        U R                  S	5      (       a  [        R
                  " U R                  R                  5      [        U R                  5      S
4:X  aT  U R                  R                  SS2S4   U R                  S'   U R                  R                  SS2S4   U R                  S'   [        U R                  5        [        U S5      (       a  [        U R                  5        SS/nS/nSnSnS/n[        R                  " S5      n	U	S   /n
SU0nSnSnSn[        U S5      (       GaC  [        U R                  5      (       a(  U R                  R
                  S   S:w  a  [        S5      e[        U R                  5      S:  Ga  U R                   Vs/ s H  oR                  U R                  5      PM     nn[        R                   " U Vs/ s H  nUR
                  S   PM     sn5      n[        R"                  " S/[        R$                  " U5      SS 45      nUR'                  5       n[        R(                  " [        R*                  " SUS-
  5      [        R*                  " SU5      45      n[        R,                  " [/        US-
  U5       VVs/ s H  u  nnUSU U-   PM     snn5      n[        R,                  " U5      n[        U5      n[        U5      nUS:  a  US:  a  U
R1                  U	S   5        [        R2                  " UUS9n[        R4                  " U[        R6                  S9US'   U
R1                  U	S   5        [9        UUS9nUR;                  UUS .5        GO[        U S!5      (       Ga  U
R1                  U	S   5        [        U R                  5      nUUS"'   U(       a%  U
R1                  U	S#   5        UR1                  U5        [        U S5      =(       aU    U R                  R<                  S:H  =(       a5    [        U R                  R>                  5      [        U R                  5      :H  nU(       a%  U
R1                  U	S$   5        UR1                  U5        U(       a  [        U S5      (       a  [        U R                  5      nU R                  RA                  5        VVs0 s H-  u  nn[        US%5      (       d  M  [        U5      U:X  d  M*  UU_M/     n nn[C        U
U 5        [E        UU 5        OSn [        R2                  " UUS9nU R                  US'   U(       a  U RF                  US&'   U(       a  U R                  R>                  US''   U(       a  W b  [I        UU 5        [        U S(5      (       GaU  U
R1                  U	S)   5        U R                  R<                  S):X  a+  US*:w  a%  U
R1                  U	S$   5        UR1                  U5        U(       a;  [        U S5      (       a*  [C        XR                  5        [E        X@R                  5        [        R2                  " [        U RJ                  5      US9nSUS+'   U RJ                  US,'   U R                  R<                  S):X  a  US*:w  a  U R                  RL                  US''   [        U RJ                  5      US-'   U(       a&  [        U S5      (       a  [I        XR                  5        U
R1                  U	S.   5        [O        S/RQ                  U
5      5      RS                  U5      RU                  S05      /n!US:X  ag  Ub  U!R1                  URW                  5       5        Ub  U!R1                  URW                  5       5        Ub  U!R1                  URW                  5       5        OUS*:X  a  Ub4  U!R1                  [X        RZ                  " US1S2S39RU                  S05      5        Ub6  U!R]                  S4[X        RZ                  " US1S2S39RU                  S05      /5        Ub6  U!R]                  S4[X        RZ                  " US1S2S39RU                  S05      /5        U!R1                  S45        O[        S55      eS6RQ                  U!5      $ s  snf s  snf s  snnf s  snnf )7z
Export a mesh in the PLY format.

Parameters
----------
mesh : trimesh.Trimesh
  Mesh to export.
encoding : str
  PLY encoding: 'ascii' or 'binary_little_endian'
vertex_normal : None or include vertex normals

Returns
----------
export : bytes of result
binarybinary_little_endian)rv   asciiz encoding must be binary or asciiNvertex_normalsvertex_attributesr
   uvr   r   sr/   tface_attributes)countrW   )index<i4   )vertex<f4r   )normalsr   r   )rgbarW      )r   r   r   ztemplates/ply.jsonintroencodingentitiesr   z'only Path3D export is supported for plyr   rY   edge)
edge_countvertex_countverticesr   rr   color__len__r   r   facesfacerw   r~   r   
face_countoutro utf-8rd   re   )	col_delim	row_delim   
z!encoding must be ascii or binary!r5   )/ro   _cachehasattrr
   ri   r]   rz   lenr   ry   rq   r}   r   get_jsonr   discretearrayconcatenatecumsummaxcolumn_stackarangevstackzipr^   zerosasarrayr*   r   updatekindvertex_colorsrX   rg   rb   rx   rl   r   face_colorsr   join
substituteencodetobytesr	   structured_array_to_stringr\   )"meshr   rr   rs   
dtype_facedtype_vertexdtype_vertex_normaldtype_color
dtype_edge	templatesrf   header_params
pack_edgespack_vertex
pack_faceser   ddiscrete_lendiscrete_offlongeststacklengthoffsetedgesr   num_vertices	num_edgesvertex_colorr   kvry   exports"                                     r3   
export_plyr      s   . 8)	:	:;<< (DKK7 4,-- h''DKK..HHT[[^^,T]]1CQ0GG.2kknnQT.B&&s+.2kknnQT.B&&s+$T%;%;<4*++$T%9%9: #$9:J*+L1&K'(J ""#78I !F*M %)J%)K$(J tZ  t}}$--"5"5b"9Q">FGGt}}!;?==I=a

4==1=HI 88$BAQWWQZ$BCL>>A3		,0G0L*MNL #&&(GOORYYq'A+%>		!W@U$VWE II +.lQ.>*M*M '6NV+*ME yy*Hx=LE
I1}!1i12 hh|<H(*

82::(NH% i/07ZP
 $$#,lK 
z	"	"i)*4==)(4n% MM)O45 34 D(# E  H,EDKK--.#dmm2DD 	
 MM)G,-,t011"4==1 !% 6 6 < < >% >1q), 14Q<1G AqD > " %
 *&2CD(7HI$(! hh|<@ $H%)%8%8K	""&++";";K"3"?)+7HItWi'(;;v%(g*=MM)G,-k*'$0A"B"B%f.B.BC$Z1E1EF XXc$**oZ@

7"jj
7;;v%(g*=!%!8!8Jv&)$**ol#'$0A"B"B)*6J6JK
MM)G$%rwwv'22=AHHQRF))"MM+--/0!MM*,,./!MM*,,./	W	"MM//3$&/ !MM33"cTfWo	 !MM33"cTfWo	 	e <==88Fi J %Cf%s$   4$c.c5c!
c'3c'c'c                    S[        U R                  5       5      R                  5       ;  a  [        S5      eU R                  5       R	                  S5      R                  5       R                  5       nSU;   nSS/[        SU;   5         n[        R                  " 5       nSn U R                  5       nUc  [        S	5      eUR	                  S5      R                  5       nUR                  5       nS
U;   a  OSUS   ;   a+  USS u  p[        U	5      [        R                  " 5       S.XH'   OSUS   ;   au  [        U5      S:X  a&  USS u  pU[        U
   -   UW   S   [        U5      '   OSUS   ;   a6  USS u  pnU[        U   -   S-   U-   [        U
   -   UW   S   [        U5      '   OHSUR                  5       ;   a4  UR                  5       R                  S5      S-   nXmS R                  5       nGMQ  XBU4$ )a  
Read the ASCII header of a PLY file, and leave the file object
at the position of the start of data but past the header.

Parameters
-----------
file_obj : open file object
  Positioned at the start of the file

Returns
-----------
elements : collections.OrderedDict
  Fields and data types populated
is_ascii : bool
  Whether the data is ASCII or binary
image_name : None or str
  File name of TextureFile
plyzNot a ply file!r   rw   rU   >bigNzHeader not terminated properly!
end_headerelementr   r/   )r   
propertiespropertyr   r   listr   z
, ($LIST,)texturefile   )r1   readlinelowerro   decodestripr   collectionsOrderedDictsplitr   _dtypesr   )rL   r   rO   endianr>   rP   rawliner`   r   rY   fielddtype_countr   s                 r3   r?   r?     s   ( C))+,2244*++   "))'288:@@BH("H 3ZEX-./F&&(H J
!;>??jj!'')yy{ 4 Q8LDf+)557HN
 47" 4yA~#ABx;AGEN;R|,SZ8 47",0H)EW[11L@6IGTYNZ |,SZ8 ciik) IIK%%m4r9EV**,JO R z))r5   c                    SSU 00nSU ;   ad  U S   S   (       aW  [         R                  " S Vs/ s H  oPS   S   U   PM     sn5      n[        R                  " US5      (       d  [	        S5      eO0 US	'   U$  [         R                  " S
 Vs/ s H  opS   S   U   PM     sn5      n[        U5      [        U5      :X  a  XS'   SU ;   a  U S   S   (       a	  U S   S   n	OSn	Sn
SS/nSn[        R                  " U	S5      (       a  U	n
O[        U	[        5      (       a   U H  nXY;   d  M
  X   n
  O   SU	;   a  U	S   nO[        U	[         R                  5      (       a  U S   S   n[        UR                  R                  5      S:X  a  UR                  R                  S   nOI[        UR                  R                  5      S:  a&  UR                  R                   H  nX[;   d  M
  Un  O   UW   S   n
 US   S   nW
Gb:  [         R                  " U
5      n[        U5      S:w  a  [        U
5      n
Uc  / SQnU Hy  n U S   S   US      nU S   S   US      n[         R                  " UU
R!                  S5         UU
R!                  S5         4SS9R!                  U
R                  S   S45      n  O   [         R                  " U
5      nUGb  [        U5      S:X  Ga   UR                  U
R                  S   U
R                  S   S-  4:X  a  U(       ad  SSKJn  UR!                  S5      n[&        R(                  " U5      u  nnU" U
UR!                  U
R                  5      5      u  n
nnUU   nUU   U   nOD[         R*                  " [        U5      S45      nUR!                  S5      UU
R!                  S5      '   [,        R.                  R1                  UUS9US'   OVUbS  SSKJn  [         R*                  " [        U5      S45      nUR!                  S5      UU
R!                  S5      '   U" US9US'   XS'   XdS '   SU ;   a  [3        U S   5      US!'   SU ;   a  [3        U S   5      US"'   U R5                  S#0 5      R5                  SS5      nUb  Sn[        U[        5      (       a    [         R                  " US$   US%   45      nOY[        U[         R                  5      (       a:  [        UR                  5      S:X  a  UR                  S   S:X  a  UnO[=        U5      nUb!  SS)KJ n  URC                  U" UUS    5      5        U$ s  snf s  snf ! [         a     GNf = f! [        [        4 a     GNyf = f! [        [        4 a     GMT  f = f! [         a)    [6        R8                  " S&UR;                  5        3S'S(9   Nf = f)*a  
Given an elements data structure, extract the keyword
arguments that a Trimesh object constructor will expect.

Parameters
------------
elements : OrderedDict object
  With fields and data loaded
fix_texture : bool
  If True, will re- index vertices and faces
  so vertices with different UV coordinates
  are disconnected.
image : PIL.Image
  Image to be viewed
prefer_color : None, 'vertex', or 'face'
  Which kind of color to prefer if both defined

Returns
-----------
kwargs : dict
  Keyword arguments for Trimesh constructor
metadata_ply_rawr   r   xyzrR   )r   r   zVertices were not (n,3)!geometry)nxnynzrx   r   Nvertex_indexvertex_indices)r   )r   r   texcoordr/   r   f1r   ))	texture_u	texture_v)ur   )r{   r|   r   )axis)unmerge_faces)r   r   )rz   r=   r
   )TextureVisuals)rz   r   r   r   r   r   vertex1vertex2z'failed to convert PLY edges from keys: Tr;   )edges_to_path)"ri   r   r	   is_shapero   r   rI   
isinstancedictndarrayrY   rp   KeyErrorr]   r   r   reshapevisual.texturer   r   unique_rowsr   r
   texturer   _element_colorsrC   r   rH   keysr   path.exchange.miscr   r   )r>   r7   r=   r8   rN   ir   jrx   	face_datar   index_namesr   	face_blobr`   r]   texcoord_namesrp   t_ut_vr   uv_alluniqueinversemask_vmask_vtrz   r   	edge_datar   r   s                                  r3   rK   rK     s   0 :x01F8 28 <??5#Q5aX$6v$>q$A5#QR}}Xw//788 0  z4FG4Fqh'*4FG
 ~#h-/'5#$ hv.x8V$V,	 	 "#34KH}}Y--	It	$	$A~! 
 " ,H	Irzz	*	*V$V,	 y$$%*??((+D&&'!+__**#D +
 $%	 ,T2H u:?%e,E RN'
"8,V4U1X>C"8,V4U1X>C!xxU]]2./U]]25F1GHr gu{{1~r23   (   E
a5;;q>5;;q>A3E"FF : "))'2 #+"6"6v">
 *77??5;;7*&vw $F+F^G, XXs8}a01(0(8(8(A5==$%  &~~<<%<PF8!73x=!,-B$,$4$4W$=Bu}}R !-4F8w!:  /0@ A}8"1(82D"E VR(,,VT:Ii&&9)=y?S(TU 	2::..9??#q(Y__Q-?1-D! 39=:MM-vj/ABCM_ $R H  X H% 	 	2 #H- T ! 		=inn>N=OP!s`   U9U U!#U 4U" =A5U9)V U 
UU"U65U69VV0WWc                     / SQnU Vs/ s H  o"U S   ;   d  M  U S   U   PM     nn[        U5      S:  a  [        R                  " U5      $ gs  snf )a   
Given an element, try to extract RGBA color from
properties and return them as an (n,3|4) array.

Parameters
-------------
element : dict
  Containing color keys

Returns
------------
colors : (n, 3) or (n, 4) float
  Colors extracted from the element
signal : float
  Estimate of range
)redgreenbluealphar   rR   r   N)r   ri   r   )r   r  r  candidate_colorss       r3   r  r    s[    " -D48WDqAV<V**DW
!/00 Xs
   AAc                    U R                  5        Vs0 s H  o"/ _M     nnU Hv  nSnU R                  5        H]  u  pgSnSU;   a&  UR                  S5      S   n[        XE   5      nUS-  nXX-   n	X6   R	                  XEU	 R                  U5      5        U	nM_     Mx     UR                  5        VV
s0 s H  u  p*U[        R                  " U
SS9_M     nnn
UR                  UR                  5        VV
s0 s HN  u  p*[        U
R                  5      S:X  d  M   X*R                  5       R                  X2   S   R                  5      _MP     sn
n5        U$ s  snf s  sn
nf s  sn
nf )	a/  
Load elements which include lists of different lengths
based on the element's property-definitions.

Parameters
------------
properties : dict
  Property definitions encoded in a dict where the property name is the key
  and the property data type the value.
data : array
  Data rows for this element.
r   r/   $LIST($LIST,)r   objectr   r   )r  rX   r   r   r^   astyperi   r   r   r   r]   squeezerY   )r   rR   r   edatarowstartr`   dtr   endr   r   s               r3   _load_element_differentr&    sP    'OO-.-qU-E."((*HDF"}XXj)"- SZ
.CKs~44R89E + $ ;@++-H-$!q"((1H---GHNN  	
'177|q  5Ayy{!!%(1+"3"344'	
 N; /& I	
s   E0"E3E
2E
c                 ^   US   n0 nSnU R                  5        H  u  pVU[        U5      :  a    U$ SU;   aO  UR                  S5      S   n[        X$   5      nUSS2US-   US-   U-   24   R	                  U5      X5'   XHS-   -  nMl  USS2XDS-   24   R	                  U5      X5'   US-  nM     U$ )a  
Load element data with lists of a single length
based on the element's property-definitions.

Parameters
------------
properties : dict
  Property definitions encoded in a dict where
  the property name is the key and the property
  data type the value.
data : array
  Data rows for this element, if the data contains
  list-properties all lists belonging to one property
  must have the same length.
r   r  r  r   Nr/   )rX   r   r   r   r  )	r   rR   firstcolumnscurrentr`   r$  rY   r   s	            r3   _load_element_singler+  ,  s    " GEGG$$& c%j  N b=HHZ(,E (F GaK'A+2F$F!FGNNuUGMz!G Gk$9!9:AA"EGMqLG! '$ Nr5   c                 L   [        UR                  5       R                  S5      5      n[         R                  U5      nU Vs/ s H  n[        R
                  " USS9PM     nnSnU R                  5        H  u  pxSU;  d	  US   S:X  a  M  XVXhS   -    n	XhS   -  n [        R                  " U	5      n	Sn
[        S US	   R                  5        5       5      nU
(       a  US
::  a  [        US	   U	5      nO[        US	   U	5      nXU   S'   M     gs  snf ! [         a    Sn
 Nnf = f)a0  
Load data from an ASCII PLY file into an existing elements data structure.

Parameters
------------
elements : OrderedDict
  Populated from the file header, data will
  be added in-place to this object
file_obj : file-like-object
  Current position at the start
  of the data section (past the header).
r   rd   )sepr   r   TFc              3   6   #    U  H  nS U;   d  M  Sv   M     g7f)r  r/   N ).0r$  s     r3   	<genexpr>_ply_ascii.<locals>.<genexpr>|  s     T%BrgQSm%Bs   
	r   r/   rR   N)r1   readr   
splitlinesri   
fromstringrX   r   ro   sumrn   r+  r&  )r>   rL   textlinesr  r   row_poskeyrn   rR   col_count_equal
list_countelement_datas                r3   r@   r@   U  s)    x}}%%g./DNN4 E0561R]]1#&E6G  ~~'6!VH%5%:w)99:(##	$99T?D"O
 TVL%9%@%@%BTT
zQ 0|0DdKL
 36,3GNL ,f7 ( 7   	$#O	$s   DDD#"D#c                     S nS nS nU" X5        [         R                  " U5      nU" U 5      nXV:w  a  [        S5      eU" X5        g)a;  
Load the data from a binary PLY file into the elements data structure.

Parameters
------------
elements : OrderedDict
  Populated from the file header.
  Object will be modified to add data by this function.
file_obj : open file object
  With current position at the start
  of the data section (past the header)
c                    U R                  5       nU R                  5       n/ nUR                  5        GH  u  pVUS   nSnUR                  5        H  u  p/ nSU
;   a  [        R                  " U
R	                  S5      S   5      n[        U5      S:X  a  SnO [        R                  " U5      R                  nU R                  X=-   5        U R                  UR                  5      n[        U5      S:X  a  UR                  U	5          OD[        R                  " XS9S   nXy   R                  S[        U5      5      Xy'   XU	   S-   -  nM     [        W5      S:  a=  U H  nUR                  U5        M     [        U5      S:X  a  UR                  U5        GMd  [        R                  " SR                  UR                  5       5      5      R                  nX6S   U-  -  nGM     U R                  U5        U H  nUR                  U5        M     g	)
a	  
Given a set of elements populated from the header if there are any
list properties seek in the file the length of the list.

Note that if you have a list where each instance is different length
(if for example you mixed triangles and quads) this won't work at all
r   r   r  ,r   r   z, r   N)tellrX   ri   rY   r   r   itemsizeseekr3  r^   
frombufferreplacer1   popr   rn   )rL   r>   p_start	p_currentelem_popelement_keyr   props
prior_datar   rY   prop_popra   r   blobsizerF  rB  s                     r3   populate_listsize&_ply_binary.<locals>.populate_listsize  s    --/MMO	$,NN$4 KL)EJ!KKMe# #%((5;;s+;A+>"?K:!+!"!#*!5!>!>MM)"45#==)=)=>D4yA~ *==A!DD$x//TCEHAhn,
' *( 8}q #CIIcN $ u:?OOK0xx		%,,. 9:CCH*X55IG %5J 	gCLL r5   c                 x   UR                  5        Ht  n[        X   S   R                  5       5      n[        R                  " U5      nU R                  X   S   UR                  -  5      n [        R                  " XTS9X   S'   Mv     U$ ! [         a$    [        R                  " SU 35        SX   S'    M  f = f)zw
Given the data type and field information from the header,
read the data and add it to a 'data' field in the element.
r   r   r   rR   zPLY failed to populate: N)r  r   rX   ri   rY   r3  rB  rD  rI   r   rJ   )rL   r>   r:  rX   rY   rR   s         r3   populate_data"_ply_binary.<locals>.populate_data  s    
 ==?C|4::<=EHHUOE==x!85>>!IJD-(*d(Hf% #  ! -6se<=(,f%-s   ,B*B98B9c                     SnU R                  5        HM  n[        R                  " SR                  US   R                  5       5      5      nXS   UR                  -  -  nMO     U$ )zt
Given an elements data structure populated from the header,
calculate how long the file should be if it is intact.
r   r@  r   r   )rn   ri   rY   r   rB  )r>   rO  r   rY   s       r3   _elements_size#_ply_binary.<locals>._elements_size  s\    
 (GHHSXXgl&;&B&B&DEFEH%66D ) r5   zPLY is unexpected length!N)r	   distance_to_endro   )r>   rL   rP  rS  rV  	size_filesize_elementss          r3   rA   rA     sX    3j 	 h) $$X.I #8,M !455 (%r5   c                    [         R                  " SS9 nUR                  [        U 5      5        UR	                  5         [         R                  " SS9 n[
        R                  " [        S[        [        U5      5      SUR                  SUR                  /5        UR                  S5        UR                  5       nSSS5        SSS5        W$ ! , (       d  f       N= f! , (       d  f       W$ = f)	aO  
Export a mesh using Google's Draco compressed format.

Only works if draco_encoder is in your PATH:
https://github.com/google/draco

Parameters
----------
mesh : Trimesh object
  Mesh to export
bits : int
  Bits of quantization for position
  tol.merge=1e-8 is roughly 25 bits

Returns
----------
data : str or bytes
  DRC file bytes
.plysuffix.drcz-qp-i-or   N)tempfileNamedTemporaryFilewriter   flush
subprocesscheck_outputdraco_encoderr1   r   r`   rC  r3  )r   bitstemp_plyencodedrR   s        r3   export_dracorl    s    ( 
	$	$F	3xz$'(((77##!D	NMMLL
 LLO<<>D 8 
4" K 87 
4	3" Ks$   ?C A)C=C 
C	C  
C/c           	         [         R                  " SS9 nUR                  U R                  5       5        UR	                  5         [         R                  " SS9 n[
        R                  " [        SUR                  SUR                  /5        UR                  S5        [        U5      nSSS5        SSS5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)z
Load a mesh from Google's Draco format.

Parameters
----------
file_obj : file- like object
  Contains data

Returns
----------
kwargs : dict
  Keyword arguments to construct a Trimesh object
r_  r]  r\  r`  ra  r   N)rb  rc  rd  r3  re  rf  rg  draco_decoderr`   rC  rS   )rL   rN   temp_drcrj  s       r3   
load_dracorp  &  s     
	$	$F	3xx}}'((78##hmmT8==I MM!h'F 8	 
4 M 87	 
4	3 Ms%   ACAB;)C;
C		C
Cr   rh  rn  drc)NTNF)ru   NT)N)   )1r   rf  rb  stringr   numpyri   numpy.lib.recfunctionsr   r   r   r   r   r	   r
   	constantsr   r   r   	resolversr   typedr   r   r   r0   r4   boolr1   rS   rb   rg   rl   rq   r   r?   rK   r  r&  r+  r@   rA   rl  rp  _ply_loaders_ply_exporterswhichrh  rn  r/  r5   r3   <module>r}     sK        Y 0 0  (   %
DT T d	
 
4 D T T T D T d d d T  t!" t#$ '0 









0" $("& Ax A A 3-	A
 AH24.L2 $(#	_ D>_ 	_DK*\JZ0*Z&R3-lp&f%P8 x $

?+

?+$L(N5 r5   