
    TiO                     D   d dl Z 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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mZ i d
dddddddddddddddddddddddddddd d!d"d#d$d!d%d%d&Zd
dddddddd d"d'd(Zd) Z	 	 	 	 dGd,ee         d-ed.ee         d/efd0Zd1 Zd2 Zd3 Z d4 Z!	 	 	 dHd6ee         d7efd8Z"d9 Z#dId:Z$d; Z%d< Z&d= Z'd> Z(d? Z)dJdAZ*dB Z+dCeiZ,dCe"iZ- ej.        dD          Z/ ej.        dE          Z0e0e+e,dF<   e/e*e-dF<   dS dS )K    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                 6    t           | j        dd                  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/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/exchange/ply.py_numpy_type_to_ply_typer4   6   s     ;?122.//    TFresolverfix_textureprefer_colorskip_materialsc                    t          |           \  }}}	|rt          ||            nt          ||            d}
|s	 ddl}|	A|                    |	          }|j                            t          j        |                    }
nE# t          $ r t          j        d           Y n%t          $ r t          j        dd           Y nw xY wt          |
|||          }|S )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%<%<"Hh
  (8X&&&&Hh''' E @	@ %||J//	t':4'@'@AA 	? 	? 	?I=>>>>> 	@ 	@ 	@K/$??????	@ !hKl  F Ms   AB C$CCc                    |                                 D ]l\  }}|j                            d          }|j        dk    r+|                     | ddf|||j        d         fg           U|                     ||f           m| S )a!  
    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      s     !&&(( . .
dj--c229q==LLd???E2T;
ST4VWXXXXLL$,----Lr5   c                 
   |                                 D ]m\  }}|j        dk    r/|                     dt          |j                   d| d           ?|                     dt          |j                   d| d           n| S )a'  
    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      !&&((  
d9>>MMT&=dj&I&ITTDTTTUUUUMMU'>tz'J'JUUTUUU    Mr5   c                     |                                 D ]H\  }}|j        dk    r3|j        d         t          j        |j        d                   z  | | d<   || |<   I| S )a  
    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      sl      !&&((    
d9q==*.*Q-"'$*Q-:P:P*PJ$'
4r5   c                     |                                  D ]5}|j        dvrt          d          |j        j        t          d          6dS )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      sj     !!## L L9F""NOOO :'JKKK (L Lr5   binaryvertex_normalinclude_attributesc                     |dk    rd}n|dvrt          d          |	d j        v }|rt           d          rt           d          rt           j        d	          rrt	          j         j        j                  t           j                  d
fk    r< j        j        dddf          j	        d<    j        j        dddf          j	        d<   t           j	                   t           d          rt           j                   ddg}dg}d}d}dg}t          j        d          }	|	d         g}
d|i}d}d}d}t           d          rt           j                  r% j        j        d         dk    rt          d          t           j                  dk    r fd j        D             }t	          j        d |D                       }t	          j        dgt	          j        |          dd         f          }|                                }t	          j        t	          j        d|dz
            t	          j        d|          f          t	          j        fdt-          |dz
  |          D                       }t	          j        |          }t          |          }t          |          }|dk    r|dk    r|
                    |	d                     t	          j        ||!          }t	          j        |t          j        !          |d <   |
                    |	d"                    t7          ||!          }|                    ||d#           nt           d$          r|
                    |	d                     t           j                  }||d%<   |r0|
                    |	d&                    |                    |           t           d          o> j        j        d k    o.t           j        j                  t           j                  k    }|r0|
                    |	d'                    |                    |           |rlt           d          rZt           j                  fd( j	                                        D             }tA          |
|           tC          ||           nd}t	          j        ||!          } j        |d <   |r
 j"        |d)<   |r j        j        |d*<   |r|tG          ||           t           d+          r7|
                    |	d,                     j        j        d,k    r6|d-k    r0|
                    |	d'                    |                    |           |r:t           d          r*tA          |
 j                   tC          | j                   t	          j        t           j$                  |!          }d|d.<    j$        |d/<    j        j        d,k    r|d-k    r j        j%        |d*<   t           j$                  |d0<   |r%t           d          rtG          | j                   |
                    |	d1                    tM          d2'                    |
                    (                    |          )                    d3          g}|dk    r||'|                    |*                                           |'|                    |*                                           |'|                    |*                                           n|d-k    r|=|                    tW          j,        |d4d56          )                    d3                     |?|-                    d7tW          j,        |d4d56          )                    d3          g           |?|-                    d7tW          j,        |d4d56          )                    d3          g           |                    d7           nt          d8          d9'                    |          S ):a/  
    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
    rr   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 plyc                 D    g | ]}|                     j                  S  )discretevertices).0emeshs     r3   
<listcomp>zexport_ply.<locals>.<listcomp>5  s'    IIIa

4=11IIIr5   c                 (    g | ]}|j         d          S )r   )r]   )r   ds     r3   r   zexport_ply.<locals>.<listcomp>8  s    $B$B$BAQWQZ$B$B$Br5   c                 0    g | ]\  }}d |         |z   S Nr   )r   lengthoffsetstacks      r3   r   zexport_ply.<locals>.<listcomp>B  s:       & '6'NV+  r5   r   rY   edge)
edge_countvertex_countr   r   rs   colorc                 b    i | ]+\  }}t          |d           rt          |          k    (||,S )__len__)hasattrlen)r   kvr   s      r3   
<dictcomp>zexport_ply.<locals>.<dictcomp>u  sN     % % %1q),,% 25Q<1G1G q1G1G1Gr5   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   _cacher   r
   ri   r]   rz   r   r   ry   rq   r}   r   get_jsonr   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\   )r   r   rs   rt   
dtype_facedtype_vertexdtype_vertex_normaldtype_color
dtype_edge	templatesrf   header_params
pack_edgespack_vertex
pack_facesr   discrete_lendiscrete_offlongestedgesr   num_vertices	num_edgesvertex_colorry   exportr   r   s   `                         @@r3   
export_plyr      s   . 8)	:	:	:;<<< (DK7  ;4,-- 		= h''CDK..C HT[^,,T]1C1CQ0GGG.2knQQQT.B&s+.2knQQQT.B&s+$T%;<<<4*++ 	;$T%9::: #$9:J*+L1&K'(J "#788I !F*M %)J%)K$(J tZ   YJt} 	H$-"5b"9Q">">FGGGt}!!IIII4=IIIH 8$B$B$B$B$BCCL>A3	,0G0G0L*MNNL #&&((GORYq'A+%>%>	!W@U@U$VWWE I   *-lQ.>*M*M   E y**Hx==LE

I1}}!1!1i1222 h|<HHH(*
82:(N(N(NH% i/0007ZPPP
 $$#,lKK   
z	"	" +Ji)***4=))(4n%  	5MM)O4555 3444 D(## E H,EDK-..#dm2D2DD 	
  	-MM)G,---,,, 	)t011 
)"4=11% % % % $ 6 < < > >% % %!
 *&2CDDD(7HIIII$(! h|<@@@ $H 	9%)%8K	" 	<"&+";K 	J"3"?)+7HIIItW Li'(((;v%%(g*=*=MM)G,---k*** 	G'$0A"B"B 	G%fd.BCCC$Z1EFFF Xc$*ooZ@@@

7"j
7;v%%(g*=*=!%!8Jv&)$*ool# 	L'$0A"B"B 	L)*d6JKKK
MM)G$%%%rwwv''22=AAHHQQRF)))"MM+--//000!MM*,,..///!MM*,,..///	W		"MM/3$  &//   !MM3"cT  fWoo	   !MM3"cT  fWoo	   	e <===88Fr5   c                    dt          |                                                                           vrt          d          |                                                     d                                                                          }d|v }ddgt          d|v                    }t          j                    }d}	 |                                 }|t          d
          |                    d                                          }|	                                }d|v rnMd|d         v r5|dd         \  }}	t          |	          t          j                    d||<   nd|d         v rt          |          dk    r:|dd         \  }
}|t          |
         z   ||         d         t          |          <   nd|d         v rN|dd         \  }}
}|t          |         z   dz   |z   t          |
         z   ||         d         t          |          <   n\d|                                v rF|                                                    d          dz   }||d                                         }|||fS )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   >bigNTz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44*+++   ""))'2288::@@BBH("H 3ZEX-../F&((H J'-!!;>???jj!!''))yy{{ 4 Q8LD&f++)577 HTNN
 47"" 4yyA~~#ABBxu;AGEN;R|,SZZ88 47"",0H)UEW[11L@6IGTYNZ |,SZZ8 ciikk)) IIKK%%m44r9EUVV**,,JO'-R Xz))r5   c                     dd ii}d v rS d         d         rEt          j         fddD                       }t          j        |d          st	          d          ni |d	<   |S 	 t          j         fd
dD                       }t          |          t          |          k    r||d<   n# t          $ r Y nw xY wd v r d         d         r d         d         }nd}d}ddg}	d}
t          j        |d          r|}nt          |t                    r |	D ]}||v r
||         } nd|v r|d         }
nt          |t           j	                  r d         d         }t          |j
        j                  dk    r|j
        j        d         }n4t          |j
        j                  dk    r|j
        j        D ]
}||	v r|} n||         d         }	 |d         d         }
n# t          t          f$ r Y nw xY w|t          j        |          }t          |          dk    rt          |          }|
g d}|D ]}	  d         d         |d                  } d         d         |d                  }t          j        ||                    d                   ||                    d                   fd                              |j        d         df          }
 n# t          t          f$ r Y w xY wt          j        |          }|
 t          |          dk    r|
j        |j        d         |j        d         dz  fk    r|rqddlm} |
                    d          }t'          j        |          \  }} |||                    |j                            \  }}}||         }||         |         }nNt          j        t          |          df          }|
                    d          ||                    d          <   t,          j                            ||          |d<   ne|
cddlm} t          j        t          |          df          }|
                    d          ||                    d          <    ||           |d<   ||d!<   ||d"<   d v rt3           d                   |d#<   d v rt3           d                   |d$<                        d%i                               dd          }|d}t          |t                    r_	 t          j        |d&         |d'         f          }n# t          $ r. t7          j        d(|                                 d)*           Y nYw xY wt          |t           j	                  r;t          |j                  dk    r|j        d         dk    r|}nt=          |          }|+dd+lm } |!                     |||d"                              |S ),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   c                 8    g | ]}d          d         |         S r   rR   r   )r   ir>   s     r3   r   z'_elements_to_kwargs.<locals>.<listcomp>5  s(    #Q#Q#QaHX$6v$>q$A#Q#Q#Qr5   xyz)r   r   zVertices were not (n,3)!geometryc                 8    g | ]}d          d         |         S r   r   )r   jr>   s     r3   r   z'_elements_to_kwargs.<locals>.<listcomp>?  s(    GGGqXh'*GGGr5   )nxnynzrx   r   rR   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   r   rx   	face_datar   index_namesr   r   	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 <?#Q#Q#Q#Q5#Q#Q#QRR}Xw// 	97888	9  zGGGG4FGGG
 
 ~#h--//'5F#$    hv.x8V$V,		 	 "#34KH}Y-- !	It	$	$  	 	AI~~!!  "" ,H	Irz	*	* V$V,	 y$%%**?(+DD&''!++_*  ##DE $ $%	 ,T2HHH% 	 	 	 D	
 u::??%e,,E RQQN'  
"8,V4U1X>C"8,V4U1X>C!xU]]2../U]]25F5F1GHr     gu{1~r233  E"H-   D   E

a5;q>5;q>A3E"FFF  B:::::: "))'22 #+"6v">">
 *77??5;77* *&vw $F+F^G, Xs8}}a011(0(8(8(A(A5==$$%  &~<<%<PPF8!7777773x==!,--B$,$4$4W$=$=Bu}}R  !-~444F8w!F:  /0@ A A}8"1(82D"E"E VR((,,VT::Ii&& 	>9)=y?S(TUU    	Pinn>N>NPP!     
 	2:.. 	>9?##q((Y_Q-?1-D-D! 39==::::::MM--vj/ABBCCCMsJ   'AB- -
B:9B:G G32G3:BKK.-K."T6 65U.-U.c                 z     g d} fd|D             }t          |          dk    rt          j        |          S dS )aT  
    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alphac                 @    g | ]}|d          v d         |         S )r   rR   r   )r   r   r   s     r3   r   z#_element_colors.<locals>.<listcomp>  s1    WWWqAAV<V<V*<V<V<Vr5   r   N)r   ri   r   )r   r  candidate_colorss   `  r3   r  r    sT    " -,,DWWWWDWWW
!!/0004r5   c                   	 d |                                  D             	|D ]}d}|                                 D ]}\  }}d}d|v r5|                    d          d         }t          ||                   }|dz  }||z   }	|                             |||                             |                     |}~d 	                                D             }|                    	fd|                                D                        |S )	aW  
    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.
    c                     i | ]}|g S r   r   )r   r   s     r3   r   z+_load_element_different.<locals>.<dictcomp>  s    ...qQ...r5   r   r/   $LIST($LIST,)r   c                 B    i | ]\  }}|t          j        |d           S )objectr   )ri   r   )r   r   r   s      r3   r   z+_load_element_different.<locals>.<dictcomp>  s-    HHH$!Qq"(1H---HHHr5   c                     i | ]V\  }}t          |j                  d k    ||                                                    |         d         j                  WS )r   r   )r   r]   squeezeastyperY   )r   r   r   edatas      r3   r   z+_load_element_different.<locals>.<dictcomp>"  s]     	
 	
 	
117||q   qyy{{!!%(1+"344   r5   )r  rX   r   r   r^   r0  r   )
r   rR   rowstartr`   dtr   endr/  r1  s
            @r3   _load_element_differentr6    s?    /.JOO--...E  "((** 	 	HD"F"}}XXj))"- SZ
&.C$Ks59~44R88999EE	  IH%++--HHHGNN	
 	
 	
 	
	
 	
 	
   Nr5   c                    |d         }i }d}|                                  D ]\  }}|t          |          k    r nd|v rf|                    d          d         }t          ||                   }|dd|dz   |dz   |z   f                             |          ||<   ||dz   z  }|dd||dz   f                             |          ||<   |dz  }|S )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   r0  )	r   rR   firstcolumnscurrentr`   r4  rY   r   s	            r3   _load_element_singler;  ,  s   " GEGG$$&&  b c%jj  Eb==HHZ((,E w((F GaK'A+2F$F!FGNNuUUGDMvz!GG Ggk$9!9:AA"EEGDMqLGGNr5   c                    t          |                                                    d                    }t                               |          }d |D             }d}|                                 D ]\  }}d|vs|d         dk    r||||d         z            }||d         z  }	 t          j        |          }d}	n# t          $ r d}	Y nw xY wt          d |d         	                                D                       }
|	r|
d	k    rt          |d         |          }nt          |d         |          }|| |         d
<   dS )aX  
    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   c                 :    g | ]}t          j        |d           S )rd   )sep)ri   
fromstring)r   r   s     r3   r   z_ply_ascii.<locals>.<listcomp>h  s'    6661R]1#&&&666r5   r   r   TFc              3   "   K   | ]
}d |v dV  dS )r*  r/   Nr   )r   r4  s     r3   	<genexpr>z_ply_ascii.<locals>.<genexpr>|  s'      TTrgQSmmmmmmTTr5   r   r/   rR   N)r1   readr   
splitlinesrX   ri   r   ro   sumrn   r;  r6  )r>   rL   textlinesr   row_poskeyrn   rR   col_count_equal
list_countelement_datas               r3   r@   r@   U  sz    x}}%%g..//DNN4  E66666EG  ~~'' - -V6!!VH%5%:%:Ww)999:6(##	$9T??D"OO 	$ 	$ 	$#OOO	$ TTVL%9%@%@%B%BTTTTT
 		OzQ 0|0DdKKLL
 36,3GNNL ,f7- -s   &B==CCc                     d }d }d } |||            t          j        |          } ||           }||k    rt          d           |||            dS )ac  
    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                    |                                  }|                                  }g }|                                D ]\  }}|d         }d}|                                D ]\  }	}
g }d|
v r t          j        |
                    d          d                   }t          |          dk    rd}nt          j        |          j        }|                     ||z              |                     |j                  }t          |          dk    r|	                    |	            nXt          j
        ||          d         }||	                             dt          |                    ||	<   |||	         dz   z  }t          |          dk    rD|D ]}|                    |           t          |          dk    r|	                    |           t          j        d                    |                                                    j        }||d         |z  z  }|                     |           |D ]}|                    |           d	S )
a1  
        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seekrB  r^   
frombufferreplacer1   popr   rn   )rL   r>   p_start	p_currentelem_popelement_keyr   props
prior_datar   rY   prop_popra   r   blobsizerT  rP  s                     r3   populate_listsizez&_ply_binary.<locals>.populate_listsize  s;    --//MMOO	$,NN$4$4 #	6 #	6 KL)EJ!KKMM - -5e## #%(5;;s+;+;A+>"?"?K:!++!"!#*!5!5!>MM)f"4555#==)=>>D4yyA~~ ***=[AAA!DD$Qx//TCCE!HeAhn,

8}}q  # # #CIIcNNNN u::??OOK000x		%,,.. 9 9::CH*X55IIg 	 	CLL	 	r5   c                    |                                 D ]}t          ||         d                                                   }t          j        |          }|                     ||         d         |j        z            }	 t          j        ||          ||         d<   # t          $ r% t          j
        d|            d||         d<   Y w xY w|S )z
        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   rB  rP  rR  rI   r   rJ   )rL   r>   rH  rX   rY   rR   s         r3   populate_dataz"_ply_binary.<locals>.populate_data  s    
 ==?? 	- 	-C#|4::<<==EHUOOE==#x!85>!IJJD-(*d%(H(H(Hf%%  - - -<s<<===(,f%%%- s   B"",CCc                     d}|                                  D ]T}t          j        d                    |d                                                              }||d         |j        z  z  }U|S )z
        Given an elements data structure populated from the header,
        calculate how long the file should be if it is intact.
        r   rN  r   r   )rn   ri   rY   r   rP  )r>   r]  r   rY   s       r3   _elements_sizez#_ply_binary.<locals>._elements_size  sk    
 (( 	7 	7GHSXXgl&;&B&B&D&DEEFFEGH%66DDr5   zPLY is unexpected length!N)r	   distance_to_endro   )r>   rL   r^  r`  rb  	size_filesize_elementss          r3   rA   rA     s    3 3 3j   	 	 	 h))) $X..I #N8,,M M!!4555 M(H%%%%%r5      c                     t          j        d          5 }|                    t          |                      |                                 t          j        d          5 }t          j        t          dt          t          |                    d|j
        d|j
        g           |                    d           |                                }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |S )	a  
    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`   rQ  rB  )r   bitstemp_plyencodedrR   s        r3   export_dracorx    s^   ( 
	$F	3	3	3 "xz$''((((777 	"7#!D		NNML
 
 
 LLOOO<<>>D	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"" " " " " " " " " " " " " " "" Ks7   AC3"A.CC3C 	 C3#C 	$C33C7:C7c           	         t          j        d          5 }|                    |                                            |                                 t          j        d          5 }t          j        t          d|j        d|j        g           |	                    d           t          |          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |S )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
    rk  ri  rh  rl  rm  r   N)rn  ro  rp  rB  rq  rr  rs  draco_decoderr`   rQ  rS   )rL   rN   temp_drcrv  s       r3   
load_dracor|  &  sI    
	$F	3	3	3 	(xx}}'''(777 	(8#hmT8=I   MM!h''F	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(		( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( Ms7   AC'AC 4C C	CC	CCCr   rt  rz  drc)NTNF)rr   NTr   )rf  )1r   rr  rn  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  r6  r;  r@   rA   rx  r|  _ply_loaders_ply_exporterswhichrt  rz  r   r5   r3   <module>r     s                      Y Y Y Y Y Y Y Y 0 0 0 0 0 0 0 0 0 0 0 0       ( ( ( ( ( (             % % % % % % % %
DT T d	
 
4 D T T T D T d d d T  t!" t#$ '  0 









 0 0 0" $("& A Ax A A 3-	A
 A A A AH  2  4  .L L L2 $(#	_ _ D>_ 	_ _ _ _DK* K* K*\J J J JZ  0* * *Z& & &R3- 3- 3-lp& p& p&f% % % %P  8 x $
?++
?++$L(N5 r5   