
    Mi&                        S SK rSSKJr  SSKJrJr   " S S\5      r\R                  " / SQ5      r
\R                  " S\R                  S	4S
/5      rS\S\4S jrS\S\4S jrS\S\4S jrS\4S jrS\4S jr\\S.rg)    N   )util)DictStreamc                       \ rS rSrSrg)HeaderError    N)__name__
__module____qualname____firstlineno____static_attributes__r
       n/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/exchange/stl.pyr   r      s    r   r   ))normals<f4   )verticesr   )r   r   )
attributesz<u2headerP   )
face_countz<u4file_objreturnc                     U R                  5       n [        U 5      $ ! [         a    U R                  U5        [	        U 5      s $ f = f)z
Load a binary or an ASCII STL file from a file object.

Parameters
----------
file_obj
  Containing STL data

Returns
----------
loaded
  Keyword arguments for a Trimesh constructor with
  data loaded into properly shaped numpy arrays.
)tellload_stl_binaryr   seekload_stl_ascii)r   kwargsfile_poss      r   load_stlr#      sI      }}H(
 x(( (h h''(s   
 &AAc                    [         R                  nU R                  U5      n[        U5      U:  a  [	        S5      e [
        R                  " U[         S9n S[        R                  " [        US   S   5      5      R                  5       0nU R                  5       nU R                  SS5        U R                  5       nU R                  U5        Xe-
  nUS   [        R                  -  nXx:w  a  [	        SU S	U 35      e[
        R                  " U R                  5       [        S9n	[        U	S
   5      (       d  S0 0$ [
        R                  " US   S   S-  5      R!                  S5      n
U	S
   R!                  S5      U	S   R!                  S5      U
SU	S   0US.nU$ ! [         a    [	        S5      ef = f! [         a    0 n GN:f = f)z
Load a binary STL file from a file object.

Parameters
----------
file_obj : open file- like object
  Containing STL data

Returns
----------
loaded
  Keyword arguments for a Trimesh constructor with data
  loaded into properly shaped numpy arrays.
z'Binary STL shorter than a fixed header!dtypezBinary header incorrect typer   r   r   r   z+Binary STL has incorrect length in header: z vs r   geometryr   r   r   stlr   )r   face_normalsfacesface_attributesmetadata)_stl_dtype_headeritemsizereadlenr   np
frombufferBaseExceptionr   decode_textbytesstripr   r   
_stl_dtypearangereshape)r   header_lengthheader_datar   r.   
data_startdata_endlen_datalen_expectedblobr,   results               r   r   r   7   s   " &..M--.K
;-'CDD:{2CD d..uVH5Ea5H/IJPPRS J MM!Q }}HMM*
 $H,'**=*==L 9(4~V
 	
 ==
;D tJ  B IIf\*1-12::7CE
 $,,W5Y//8!4#56F Mo  :899:  s   F 5F7 F47GGc           	      t   [         R                  " U R                  5       5      R                  5       nUR	                  5       n0 nSn[        [        U5      5       GH  nUR                  SU5      nUR                  SU5      nU[        S5      -   nUS:  d  US:  a    GOXg:  a  [        S5      eX&U nUR                  S5      n	[        R                  " SR                  S U	SS	  5       5      S[        R                  S
9n
[        U
5      S:  a  M  [        U
5      S-  S:w  a  [        S5      eU
R                  S5      n
[        R                  " [        U
5      5      R                  S5      nS	n UR                  S5      n[        R                  " SR                  S USS	  5       5      S[        R                  S
9n[        U5      [        U
5      :X  a  UR                  S5      n XXhR                  S5      -    SS	 R                  5       n[         R&                  " X5      nU
R                  S5      UUSU0S.X?'   GM     [        U5      S:X  a"  [)        [+        UR-                  5       5      5      $ SU0$ ! [          a!    [         R"                  R%                  SSS9   Nf = f! [          a    S	n Nf = f)z
Load an ASCII STL file from a file object.

Parameters
----------
file_obj : open file- like object
  Containing input data

Returns
----------
loaded
  Keyword arguments for a Trimesh constructor with
  data loaded into properly shaped numpy arrays.
r   solidendsolidz`endsolid` precedes `solid`!vertex c              3   H   #    U  H  oS UR                  S5       v   M     g 7fN
find.0lines     r   	<genexpr>!load_stl_ascii.<locals>.<genexpr>   s     I+DIIdO,    "   N)sepr&   r   zincorrect number of verticesr(   normalc              3   H   #    U  H  oS UR                  S5       v   M     g 7frJ   rL   rN   s     r   rQ   rR      s     M_T/		$0_rS   zfailed to extract face_normalsT)exc_inforK      name)r   r+   r,   r.   r'   )r   r6   r1   r8   lowerranger2   rM   
ValueErrorsplitr3   
fromstringjoinfloat64r;   r:   r5   logwarningunique_namenextitervalues)r   	raw_mixed	raw_lowerr!   position_solid_start	solid_endrE   vertex_textr   r,   r+   normal_textr   rZ   s                   r   r    r       s   "   1779I!I F H 3y>"nnWh7NN:x8	 s:. q=K!O ";<< i0 kk(+==HHIQRII**

 x=1x=1!;<< ##G,		#h-(009 
	N++h/KmmM[_MMjjG
 7|s8},&w7	 ;D9I+IJ12NTTVD - !((1(	
{ #H 6{aD)**1  	NHH=M	N  	D	s%   2A7I:*&J(:(J%$J%(J76J7c                    [         R                  " S[        S9n[        U S5      (       a  [	        U R
                  5      US'   UR                  5       n[        U S5      (       a\  [         R                  " [	        U R
                  5      [        S9nU R                  US'   U R                  US'   X#R                  5       -  nU$ )z
Convert a Trimesh object into a binary STL file.

Parameters
---------
mesh
  Trimesh object to export.

Returns
---------
export
  Represents mesh in binary STL form
rT   r%   r,   r   r   r   )
r3   zerosr/   hasattrr2   r,   tobytesr9   r+   	triangles)meshr   exportpackeds       r   
export_stlrx      s     XXa01FtW"4::|^^FtW#djj/< --y!^^z..""Mr   c                    [         R                  " [        U R                  5      SS45      nU R                  USS2SSS24'   U R
                  USS2SS2SS24'   SR                  / SQ5      [        U R                  5      -  nU R                  R                  SS	5      n[        U[        5      (       d  S	n[        U5      S
:  d  SU;   a  S	nSR                  SU 3UR                  " UR                  S5      6 S/5      $ )z
Convert a Trimesh object into an ASCII STL file.

Parameters
---------
mesh : trimesh.Trimesh

Returns
---------
export
  Mesh represented as an ASCII STL file
   r   Nr   rT   rK   )zfacet normal {} {} {}z
outer loopz/vertex {} {} {}
vertex {} {} {}
vertex {} {} {}endloopendfacet rZ   r}   r   zsolid r)   z	endsolid
)r3   rq   r2   r,   r+   rt   r`   r.   get
isinstancestrformatr;   )ru   rB   	formatterrZ   s       r   export_stl_asciir     s     88S_a+,D%%DAqM^^DABN 					
 	DJJI ==VR(DdC  
4y2~ 99tfoy'7'7b9I'JLYZZr   )r*   	stl_ascii)numpyr3   r}   r   typedr   r   	Exceptionr   r&   r9   voidr/   r#   r   r    r7   rx   r   r   _stl_loadersr
   r   r   <module>r      s       	) 	 XXQ
 HHx"57LMN (v (D (@Of O Odc V c  c L 8)[c )[X  h7r   