
    jO                     6   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	 	 	 	 dCd*ee   d+ed,ee   d-efd.Zd/ Zd0 Zd1 Z d2 Z!	 	 	 dDd3ee   d4efd5Z"d6 Z#dEd7Z$d8 Z%d9 Z&d: Z'd; Z(d< Z)dFd=Z*d> Z+d?eiZ,d?e"iZ- ej\                  d@      Z/ ej\                  dA      Z0e0e+e,dB<   e/e*e-dB<   yy)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                 .    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    A/DATA/.local/lib/python3.12/site-packages/trimesh/exchange/ply.py_numpy_type_to_ply_typer4   6   s     ;??12.//    resolverfix_textureprefer_colorskip_materialsc                    t        |       \  }}}	|rt        ||        nt        ||        d}
|sF	 ddl}|	?|j	                  |	      }|j
                  j                  t        j                  |            }
t        |
|||      }|S # t        $ r t        j                  d       Y 1t        $ r t        j                  dd       Y Rw xY w)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 !hKlF M  	?II=> 	@KK/$?	@s   AB C&CCc                    |j                         D ]k  \  }}|j                  j                  d      }|j                  dkD  r)| j	                  | ddf|||j
                  d   fg       Y| j                  ||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jj--c299q=LLdV6?E2T;

ST4VWXLL$,- ) Lr5   c                    |j                         D ]k  \  }}|j                  dk(  r,| j                  dt        |j                         d| d       A| j                  dt        |j                         d| d       m | 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99>MMI&=djj&I%J!D6QSTUMM&'>tzz'J&K1TFRTU	 ) Mr5   c                     |j                         D ]Q  \  }}|j                  dkD  r8|j                  d   t        j                  |j                  d         z  | | d<   || |<   S | 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      sf      !&&(
d99q=*.**Q-"''$**Q-:P*PJ$v'
4 ) r5   c                     | j                         D ]<  }|j                  dvrt        d      |j                  j                  3t        d       y)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           	         |dk(  rd}n|dvrt        d      |d| j                  v }|rt        | d      rt        | d      rt        | j                  d	      rt	        j
                  | j                  j                        t        | j                        d
fk(  rT| 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      r3t        | j                        r'| j                  j
                  d   dk7  rt        d      t        | j                        dkD  r| j                  D cg c]  }|j                  | j                         }}t	        j                   |D cg c]  }|j
                  d    c}      }t	        j"                  dgt	        j$                  |      dd f      }|j'                         }t	        j(                  t	        j*                  d|dz
        t	        j*                  d|      f      }t	        j,                  t/        |dz
  |      D cg c]  \  }}|d| |z    c}}      }t	        j,                  |      }t        |      }t        |      }|dkD  r^|dkD  rX|
j1                  |	d          t	        j2                  ||      }t	        j4                  |t        j6                        |d<   |
j1                  |	d          t9        ||      }|j;                  ||d        nt        | d!      r|
j1                  |	d          t        | j                        }||d"<   |r%|
j1                  |	d#          |j1                  |       t        | d      xrP | j                  j<                  dk(  xr5 t        | j                  j>                        t        | j                        k(  }|r%|
j1                  |	d$          |j1                  |       |rt        | d      rut        | j                        }| j                  jA                         D ci c]"  \  }}t        |d%      rt        |      |k(  r||$ } }}tC        |
|        tE        ||        nd} t	        j2                  ||      }| j                  |d<   |r| jF                  |d&<   |r| j                  j>                  |d'<   |r tI        ||        t        | d(      rB|
j1                  |	d)          | j                  j<                  d)k(  r*|d*k7  r%|
j1                  |	d$          |j1                  |       |r8t        | d      r,tC        |
| j                         tE        || j                         t	        j2                  t        | jJ                        |      }d|d+<   | jJ                  |d,<   | j                  j<                  d)k(  r|d*k7  r| j                  jL                  |d'<   t        | jJ                        |d-<   |r"t        | d      rtI        || j                         |
j1                  |	d.          tO        d/jQ                  |
            jS                  |      jU                  d0      g}!|dk(  rd||!j1                  |jW                                ||!j1                  |jW                                ||!j1                  |jW                                n|d*k(  r|6|!j1                  tY        jZ                  |d1d23      jU                  d0             |8|!j]                  d4tY        jZ                  |d1d23      jU                  d0      g       |8|!j]                  d4tY        jZ                  |d1d23      jU                  d0      g       |!j1                  d4       nt        d5      d6jQ                  |!      S c c}w c c}w c c}}w c c}}w )7a/  
    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"4==1 !% 6 6 < < >% >1q),Q<1G qD > " %
 *&2CD(7HI$(! hh|<@ $H%)%8%8K	""&++";";K"3"?)+7HItWi'(;;v%(g*=MM)G,-k*'$0A"B%fd.B.BC$Z1E1EF XXc$**oZ@

7"jj
7;;v%(g*=!%!8!8Jv&)$**ol#'$0A"B)*d6J6J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   "a=a;a
='ac                    dt        | j                               j                         vrt        d      | j                         j	                  d      j                         j                         }d|v }ddgt        d|v          }t        j                         }d}	 | j                         }|t        d	      |j	                  d      j                         }|j                         }d
|v rnd|d   v r,|dd \  }}	t        |	      t        j                         d||<   nd|d   v rtt        |      dk(  r'|dd \  }
}|t        |
   z   |   d   t        |      <   nd|d   v r|dd \  }}
}|t        |   z   dz   |z   t        |
   z   |   d   t        |      <   nGd|j                         v r5|j                         j                  d      dz   }||d j                         }H|||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   >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HTN
 47" 4yA~#ABxu;AGEN;R|,SZ8 47",0H)UEW[11L@6IGTYNZ |,SZ8 ciik) IIK%%m4r9EUV**,JO R Xz))r5   c                 
   dd| ii}d| v rU| d   d   rMt        j                  dD cg c]  }| d   d   |    c}      }t        j                  |d      st	        d      i |d	<   |S 	 t        j                  d
D cg c]  }| d   d   |    c}      }t        |      t        |      k(  r||d<   d| v r| d   d   r	| d   d   }	nd}	d}
ddg}d}t        j                  |	d      r|	}
nt        |	t              r|D ]  }||	v s|	|   }
 n d|	v r|	d   }nt        |	t         j                        r| d   d   }t        |j                  j                        dk(  r|j                  j                  d   }nEt        |j                  j                        dkD  r#|j                  j                  D ]
  }||v s|} n |   d   }
	 |d   d   }
1t        j                  |
      }t        |      dk7  rt        |
      }
|g d}|D ]{  }	 | d   d   |d      }| d   d   |d      }t        j                  ||
j!                  d         ||
j!                  d         fd      j!                  |
j                  d   df      } n t        j                  |
      }|	t        |      dk(  r|j                  |
j                  d   |
j                  d   dz  fk(  r|rcddlm} |j!                  d      }t'        j(                  |      \  }} ||
|j!                  |
j                              \  }
}}||   }||   |   }nCt        j*                  t        |      df      }|j!                  d      ||
j!                  d      <   t,        j.                  j1                  ||      |d<   nW|Uddlm} t        j*                  t        |      df      }|j!                  d      ||
j!                  d      <    ||      |d<   |
|d<   ||d <   d| v rt3        | d         |d!<   d| v rt3        | d         |d"<   | j5                  d#i       j5                  dd      }|d}t        |t              r	 t        j                  |d$   |d%   f      }nRt        |t         j                        r8t        |j                        dk(  r|j                  d   dk(  r|}nt=        |      }|!dd)lm } |jC                   |||d                 |S c c}w c c}w # t        $ r Y ]w xY w# t        t        f$ r Y [w xY w# t        t        f$ r Y 8w xY w# t        $ r+ t7        j8                  d&|j;                          d'(       Y w xY w)*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#Q5aHX$6v$>q$A5#QR}}Xw/788  z4FG4FqXh'*4FG
 ~#h-/'5F#$ hv.x8V$V,	 	 "#34KH}}Y-	It	$AI~!! 
 " ,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!F:  /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`   S7(T ;S<#T  T A7T'"T= <T 	TTT$#T$'T:9T:=1U10U1c                     g d}|D cg c]  }|| d   v s| d   |    }}t        |      dk\  rt        j                  |      S yc c}w )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alphar   rR   r   N)r   ri   r   )r   r  r  candidate_colorss       r3   r  r    sZ    " -D48WDqAAV<V*DW
!/00 Xs
   A
Ac                    | j                         D ci c]  }|g  }}|D ]v  }d}| j                         D ]_  \  }}d}d|v r'|j                  d      d   }t        ||         }|dz  }||z   }	||   j	                  |||	 j                  |             |	}a x |j                         D 
ci c]  \  }}
|t        j                  |
d       }}}
|j                  |j                         D 
ci c]M  \  }}
t        |
j                        dk(  r0||
j                         j                  ||   d   j                        O c}
}       |S c c}w c c}
}w c c}
}w )	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.
    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&    sb    'OO-.-qQU-E."((*HD"F"}XXj)"- SZ
&.C$Ks5~44R89E + $ ;@++-H-$!Qq"((1H---GHNN  	
'1177|q  qyy{!!%(1+"3"344'	
 N; /& I	
s   
E-"E0AE
c                 ^   |d   }i }d}| j                         D ]  \  }}|t        |      k\  r |S d|v rQ|j                  d      d   }t        ||         }|dd|dz   |dz   |z   f   j	                  |      ||<   ||dz   z  }l|dd||dz   f   j	                  |      ||<   |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   r  )	r   rR   firstcolumnscurrentr`   r$  rY   r   s	            r3   _load_element_singler+  ,  s    " GEGG$$&b c%j  N b=HHZ(,E w(F GaK'A+2F$F!FGNNuUGDMvz!G Ggk$9!9:AA"EGDMqLG! '$ Nr5   c                 8   t        |j                         j                  d            }t         j                  |      }|D cg c]  }t	        j
                  |d       }}d}| j                         D ]  \  }}d|vs|d   dk(  r||||d   z    }	||d   z  }	 t	        j                  |	      }	d}
t        d |d	   j                         D              }|
r|d
k  rt        |d	   |	      }nt        |d	   |	      }|| |   d<    yc c}w # t        $ r d}
Y fw xY w)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   rd   )sepr   r   TFc              3   *   K   | ]  }d |v sd  yw)r  r/   N ).0r$  s     r3   	<genexpr>z_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  s3    x}}%%g./DNN4 E0561R]]1#&E6G  ~~'V6!VH%5%:Ww)99:6(##	$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                     d }d }d } |||        t        j                  |      } ||       }||k7  rt        d       |||        y)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                    | j                         }| j                         }g }|j                         D ]  \  }}|d   }d}|j                         D ]  \  }	}
g }d|
v rt        j                  |
j	                  d      d         }t        |      dk(  rd}nt        j                  |      j                  }| j                  ||z          | j                  |j                        }t        |      dk(  r|j                  |	        nHt        j                  ||      d   }||	   j                  dt        |            ||	<   |||	   dz   z  } t              dkD  r9|D ]  }|j                  |        t        |      dk(  r|j                  |       `t        j                  dj                  |j                                     j                  }||d   |z  z  } | j                  |       |D ]  }|j                  |        y	)
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seekr2  r^   
frombufferreplacer1   popr   rn   )rL   r>   p_start	p_currentelem_popelement_keyr   props
prior_datar   rY   prop_popra   r   blobsizerE  rA  s                     r3   populate_listsizez&_ply_binary.<locals>.populate_listsize  s    --/MMO	$,NN$4 KL)EJ!KKM5e# #%((5;;s+;A+>"?K:!+!"!#*!5!>!>MM)f"45#==)=)=>D4yA~ *==[A!DD$Qx//TCE!HeAhn,
' *( 8}q #CIIcN $ u:?OOK0xx		%,,. 9:CCH*X55IG %5J 	gCLL r5   c                 z   |j                         D ]x  }t        ||   d   j                               }t        j                  |      }| j                  ||   d   |j                  z        }	 t        j                  ||      ||   d<   z |S # t        $ r# t        j                  d|        d||   d<   Y w xY w)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   r2  rA  rC  rI   r   rJ   )rL   r>   r9  rX   rY   rR   s         r3   populate_dataz"_ply_binary.<locals>.populate_data  s    
 ==?C#|4::<=EHHUOE==#x!85>>!IJD-(*d%(Hf% #  ! -6se<=(,f%-s   -B)B:9B:c                     d}| j                         D ]L  }t        j                  dj                  |d   j                                     }||d   |j                  z  z  }N |S )z
        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   rA  )r>   rN  r   rY   s       r3   _elements_sizez#_ply_binary.<locals>._elements_size  s^    
 (GHHSXXgl&;&B&B&DEFEGH%66D ) r5   zPLY is unexpected length!N)r	   distance_to_endro   )r>   rL   rO  rQ  rS  	size_filesize_elementss          r3   rA   rA     s^    3j 	 h) $$X.I #8,M M!455 (H%r5   c                    t        j                  d      5 }|j                  t        |              |j	                          t        j                  d      5 }t        j                  t        dt        t        |            d|j                  d|j                  g       |j                  d       |j                         }ddd       ddd       S # 1 sw Y   xY w# 1 sw Y   S xY w)	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`   rB  r2  )r   bitstemp_plyencodedrR   s        r3   export_dracorh    s    ( 
	$	$F	3xz$'(((77##!D	NMMLL
 LLO<<>D 8 
4" K 87 
4" Ks%   ACA(C CC	CC(c           	         t        j                  d      5 }|j                  | j                                |j	                          t        j                  d      5 }t        j                  t        d|j                  d|j                  g       |j                  d       t        |      }ddd       ddd       |S # 1 sw Y   xY w# 1 sw Y   |S xY w)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[  rY  rX  r\  r]  r   N)r^  r_  r`  r2  ra  rb  rc  draco_decoderr`   rB  rS   )rL   rN   temp_drcrf  s       r3   
load_dracorl  &  s     
	$	$F	3xx}}'((78##hmmT8==I MM!h'F 8	 
4 M 87	 
4 Ms%   AC
AB>,C
>C	C

Cr   rd  rj  drc)NTNF)ru   NT)N)   )1r   rb  r^  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   rh  rl  _ply_loaders_ply_exporterswhichrd  rj  r/  r5   r3   <module>ry     sO        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   