
    MiL                        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  SSK	Jr  S rSS jrS	\R                  S
4S jrS r S SKrS SKJr  S\0rS\0rg! \ a$  rSSKJr  S\" \5      0rS\" \5      0r SrCgSrCff = f)    N)defaultdict   )graphutil)log)unique_namec                    U R                  S5      nU R                  S5      nSR                  UR                  S5       Vs/ s H4  nUR                  S    SUR                  S    SUR                  S    3PM6     sn5      n[        R
                  " U[        R                  SS9R                  S	5      nSR                  UR                  S
5       Vs/ s H4  nUR                  S    SUR                  S    SUR                  S    3PM6     sn5      n[        R
                  " U[        R                  SS9R                  S	5      nXW4$ s  snf s  snf )a  
Read a `<mesh ` XML element into Numpy vertices and faces.

This is generally the most expensive operation in the load as it
has to operate in Python-space on every single vertex and face.

Parameters
----------
mesh : lxml.etree.Element
  Input mesh element with `vertex` and `triangle` children.

Returns
----------
vertex_array : (n, 3) float64
  Vertices
face_array : (n, 3) int64
  Indexes of vertices forming triangles.
z{*}verticesz{*}triangles z	{*}vertexxyz)dtypesep)   z{*}trianglev1v2v3)	findjoiniterattribnp
fromstringfloat64reshapeint64)meshverticesfacesivsv_arrayfsf_arrays           r/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/exchange/threemf.py
_read_meshr'      s:   ( yy'HIIn%E 
 ]];/	
/ xx}oQqxx}oQqxx}o>/	

B mmBbjjc:BB7KG 
 ZZ.	
. xx~a/q$0@A.	

B mmBbhhC8@@IG#	
	
s   ;E;Ec           
      V   [         R                  " U SS9n[        [        S UR	                  5        5       5      5      n[        [
        R                  " USSS95      u  pVSUR                  ;   a  SUR                  S   0nOSS	0n0 n[        [        5      n	[        [        5      n
[        [        5      n/ n0 n[        5       nUR                  S
5        [
        R                  " USSS9 GHv  u  nnSUR                  ;   Ga  UR                  S   n[        UR                  R                  S[        U5      5      X5      nUR!                  U5        UUU'   UR                  S5       H9  n[#        U5      u  nnU	U   R%                  U5        U
U   R%                  U5        M;     UR                  S5       GH)  nUR                  S   n['        UR                  5      nUU   R%                  UU45        [        S UR                  R	                  5        5       S5      nUc  Mn  UU;   d  Mv  UU   R                  S
5        [        UR                  R                  S[        U5      5      UU5      nUR!                  U5        UUU'   [
        R                  " UU   SSS9 H<  u  nn[#        U5      u  nnU	U   R%                  U5        U
U   R%                  U5        M>     GM,     SUR                  ;   d  GM  UR                  S5       HU  n['        UR                  5      nUR                  R                  SS5      nUR%                  UR                  S   UU45        MW     GMy     0 nU	R)                  5        H}  n[         R*                  " U	U   U
U   5      u  nnUU   nUUUR-                  5       S.UU'   UU   R/                  UR	                  5        VVs0 s H  u  nnUc  M  UU_M     snn5        M     [0        R2                  " 5       n U H  u  nn!nU R5                  SUUU!S9  M     UR	                  5        H#  u  n"n#U# H  u  nn!U R5                  U"UU!S9  M     M%     / n$[        [        5      n%[        5       n&[6        R8                  " U SS9 GH  n[6        R:                  " U USS9n'[=        U'5      S:X  a  U'S
   nO[         R>                  " U'5      nUS    S
   n(U(U;  a  [@        RB                  " S!U( S"35        Mo  [=        US    5      S:  a$  [E        US    S   [        5      (       a	  US    S   nOUU(   n[        UU&5      nU&R!                  U5        UU(   n)[=        U5      S#:  a  US$   S
   n*U%U*   R!                  U(5        U$R%                  SUUU)S%.5        GM     U(       a  [G        S& UR)                  5        5       5      (       a  UR)                  5        Vs0 s H  nUU_M     n+nU%R	                  5        HF  u  n*n,[=        U,5      S:w  a  M  UU*   RI                  S'5      S
   U+U[        [        U,5      5         '   MH     UR	                  5        VVs0 s H  u  nnU+U   U_M     nnnU$ H  n-S(U-;   d  M  U+U-S(      U-S('   M     SU$UUS).nU$ s  snnf s  snf s  snnf )*z
Load a 3MF formatted file into a Trimesh scene.

Parameters
------------
file_obj : file-like
  Contains 3MF formatted data

Returns
------------
kwargs : dict
  Constructor arguments for `trimesh.Scene`
zip)	file_typec              3   V   #    U  H  u  pS UR                  5       ;   d  M  Uv   M!     g7f)z3d/3dmodel.modelNlower.0kvs      r&   	<genexpr>load_3MF.<locals>.<genexpr>O   s"     WODA7IQWWY7VaaOs   )	)z{*}model)start)tageventsunitunitsmillimetersr   )z	{*}objectz{*}build)endobjectidnamez{*}meshz{*}componentobjectidc              3   x   #    U  H0  u  pUR                  S 5      (       d  M  UR                  S5      v   M2     g7f)path/N)endswithstripr.   s      r&   r2   r3      s+     U.>da!**VBT\QWWS\\.>s   ::Nbuildz{*}item
partnumber)r   r    metadataworld)keymatrix)rI   )GsourcerI   )rJ   	traversalr      r   zid z included but not defined!r   )
frame_fromframe_torI   geometryc              3   H   #    U  H  nS UR                  5       ;   v   M     g7f)bodyNr,   r/   r!   s     r&   r2   r3      s     F16QWWY.s    "(rQ   )
base_framer   rQ   rF   )%r   
decompressnextr   itemsetree	iterparser   r   listsetseekr5   r   getstraddr'   append_attrib_to_transformkeysappend_facescopyupdatenxMultiDiGraphadd_edger   multigraph_pathsmultigraph_collectlen	multi_dotr   warning
isinstanceallsplit).file_objpostprocesskwargsarchivemodel_eventrootrF   id_namev_seqf_seq
componentsbuild_itemsconsumed_countsconsumed_names_objindexr=   r   r1   fc
mesh_index	transformr@   mitemrE   meshesgidr0   gtfr4   group
graph_argsparents
used_names
transformslastgeomparentrename	mesh_nameargs.                                                 r&   load_3MFr   =   sC     ooh%8GWGMMOWWXE J
STLFT[[01 ]+ GEE T"J K OUN 
JJqM//%-FxX3swwJJt$E
 

vs5z2ND t$!GEN +!$'1e##A&e##A& , XXn-XXj1
0:	5!((*i)@A Uahhnn.>U #DM&&q)&

vs:?&'D
 #&&t,*.GJ' %Ix!1  *!}1j)003j)003!+ .: cgg+0=	![[__\4@
""DKK
$;Y
#ST ,m Y~ Fzz|  sU3Z81s| 
t 	tfllnNndaTQTnNO  	A  +R	

7CZ
;  + #((*uGCJJuc"J-  + J#GJ&&7;--T(S
z?a"1Iz2I Bx{wKK#dV#=>?tBx=1DHQK!=!=8A;D 4=D 4,t t} t9q="Xa[FFO%% # 		
G <\ sFFFF &.1!Q$.!(FI 9~"5<V_5J5J35OPQ5RF74Y012 "1 ,2<<>:>41a&)Q,>:CS "(Z"9J  	F M} OL / ;s   
Z%Z#Z Z%i      c                 ,  ^  SSK Jn  [        X5      (       d  U" U 5      n U R                  nU R                  R                  5       nU R                  R                  nSSSSSSS	.nS
S0n	/ m U 4S jn
[        R                  " 5       nSU0nX<S'   [        R                  " U4SS0UD6 nUR                  SSS9 n[        R                  " USS9 nUR                  5         UR                  SSS0US9   UR                  S5         [!        UR#                  5       5       GH  u  nu  nnU
" U5      US[%        [&        R(                  " 5       5      S.nUR                  " SA0 UD6   UR                  S5         UR                  S5         UR+                  5         [-        S[/        UR0                  5      U5       H^  nUR0                  UUU-    nS[/        U5      -  nUR3                  UR4                  " UR7                  5       6 R9                  S5      5        M`     S
S
S
5        UR                  S5         UR+                  5         [-        S[/        UR:                  5      U5       H^  nUR:                  UUU-    nS [/        U5      -  nUR3                  UR4                  " UR7                  5       6 R9                  S5      5        M`     S
S
S
5        S
S
S
5        S
S
S
5        GM     UR<                   GHA  nUU:X  d  UR?                  S!5      (       a  M"  [/        UU   5      S:X  a  M6  U
" U5      US[%        [&        R(                  " 5       5      S.nUR                  " SA0 UD6   UR                  S"5         UU   R#                  5        H  u  nnS#RA                  S$ [B        RD                  " US%   5      S
S&2S
S'24   RF                  R7                  5        5       5      nUR3                  [        RH                  " S(S)U;   a  U
" US)   5      OU
" U5      US*.5      5        M     S
S
S
5        S
S
S
5        GMD     S
S
S
5        UR                  S+S,[%        [&        R(                  " 5       5      05         Xg   R#                  5        H  u  nnUR?                  S!5      (       a  M  S#RA                  S- [B        RD                  " US%   5      S
S&2S
S'24   RF                  R7                  5        5       5      nS.R5                  US/   5      nUR3                  [        RH                  " S0S1U
" URK                  S)U5      5      S2UU[%        [&        R(                  " 5       5      S3U0US95        M     S
S
S
5        S
S
S
5        S
S
S
5        S
S
S
5        UR                  S4S5       n[        R                  " USS9 nUR                  5         UR                  S5U	S9   S6nUR3                  [        RH                  " S7US8S9S:95        S
S
S
5        S
S
S
5        S
S
S
5        UR                  S;S5       n[        R                  " USS9 nUR                  5         S
S<0n/ S=QnUR                  S>US9   U H+  u  nnUR3                  [        RH                  " S?UUS@95        M-     S
S
S
5        S
S
S
5        S
S
S
5        S
S
S
5        URM                  5       $ ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GM  = f! , (       d  f       GN= f! , (       d  f       GM>  = f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN5= f! , (       d  f       GN?= f! , (       d  f       GNI= f! , (       d  f       URM                  5       $ = f)Ba  
Converts a Trimesh object into a 3MF file.

Parameters
---------
mesh trimesh.trimesh
  Mesh or Scene to export.
batch_size : int
  Number of nodes to write per batch.
compression : zipfile.ZIP_*
  Type of zip compression to use in this export.
compresslevel : int
  For Python > 3.7 specify the 0-9 compression level.

Returns
---------
export : bytes
  Represents geometry as a 3MF file.
r   )Scenez9http://schemas.microsoft.com/3dmanufacturing/core/2015/02z=http://schemas.microsoft.com/3dmanufacturing/material/2015/02z?http://schemas.microsoft.com/3dmanufacturing/production/2015/06z@http://schemas.microsoft.com/3dmanufacturing/beamlattice/2017/02z:http://schemas.microsoft.com/3dmanufacturing/slice/2015/07zBhttp://schemas.microsoft.com/3dmanufacturing/securecontent/2019/04)Nr   pbsscNz<http://schemas.openxmlformats.org/package/2006/relationshipsc                 l   > U T;  a  TR                  U 5        [        TR                  U 5      S-   5      $ )NrM   )rb   r`   r   )r   modelss    r&   model_idexport_3MF.<locals>.model_idE  s.    F?MM!6<<?Q&''    compressioncompresslevelmodewz3D/3dmodel.model)r   zutf-8)encodingrw   r7   
millimeter)nsmap	resources)r<   r=   typep:UUIDr   r   r   z<vertex x="{}" y="{}" z="{}" />	trianglesz$<triangle v1="{}" v2="{}" v3="{}" />camerar}   r
   c              3   8   #    U  H  n[        U5      v   M     g 7fNr`   rT   s     r&   r2   export_3MF.<locals>.<genexpr>  s!      9&26A ),A26   rI   r      	componentrQ   )r>   r   rD   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   rT   s     r&   r2   r     s      -,XqCFF,Xr   z
{{{}}}UUIDr   r   r>   r   rE   z_rels/.relsRelationshipsz<http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodelRelationshipz/3D/3dmodel.modelrel0)TypeTargetIdz[Content_Types].xmlz<http://schemas.openxmlformats.org/package/2006/content-types))jpeg
image/jpeg)jpgr   )rw   z6application/vnd.ms-package.3dmanufacturing-3dmodel+xml)pngz	image/png)relsz8application/vnd.openxmlformats-package.relationships+xml)texturez9application/vnd.ms-package.3dmanufacturing-3dmodeltextureTypesDefault)	ExtensionContentType)r;   )'scene.scener   rp   rQ   r   to_networkxrV   ioBytesIOzipfileZipFileopenrZ   xmlfilewrite_declarationelement	enumeraterY   r`   uuiduuid4flushrangerm   r   writeformatflattenencoder    nodes
startswithr   r   arrayTElementr_   getvalue)!r   
batch_sizer   r   r   rQ   r   rV   model_nsmap
rels_nsmapr   rs   
zip_kwargsr   r   xfr!   r=   r   attribsbatchfragmentnoderX   datar   uuid_tagrtr   typesextctyper   s!                                   @r&   
export_3MFr     s   * $d""T{}}HJJ""$E&&J JLNOIRK VWJ F( zz|H  -J"/		:	:z	:aVV&SV1Q9
  " Gfl%;;OZZ,(1(..2B(C9D! #+4.$($+&)$**,&7	#  ZZ<G<!#F!3%'ZZ
%; %'HHJ-21c!**oz-R01

1q:~0N,MPSTYPZ,Z )1 )*,4OOU]]_,M,T,T07-.)* .S	 &< &(ZZ%<$&HHJ-21c!''lJ-O01A
N0K,R.1%j-9 )1 )*,4OOU]]_,M,T,T07-.)* .P &= "4 =< )DN !&:-1J1J$uT{+q0$ #+4.$($+&)$**,&7	#  ZZ<G<!#L!927+2C2C2EJD$03 9&13$x.1I,.QBF2**+!GGI269& 1&I %'HH(-,7 4>3E =ET*EU<V5=d^=F	-.)*
%& 3F ": =< !,S -V ZZ(C

4E)FG&+&7&=&=&?
d??844$$'HH -,.HHT(^,DRaR!V,L,N,N,V,V,X- %	 $0#6#6{37G#H!MM &$.*d9S0T$/$,c$**,.?$0$	!" '2	 '@ H[ P9
1R VVM3'1emmA.PTV  "O:>SMM&2!	 ? /Q' VV)3/1emm7
  "YZE
E G51"'JCHHU]]9QVWX #( 2'7
/u 
;b w &<%; &=%< "4!3 =<X ":!9 =<k -,V HG[ PO9
 9
11X ?> /Q.P''D 21'7
 7
//u 
;	:b s  '_68]8$]&2]	A\0#[85[&B[[&3B[[&[8B
\0 \2B.\ \(\058]	-C8]%]	-]&5]8=_6^.-!^)^
	7^?^._6!_$7)_ 2_ 	__$"_6
[[&
[#[&&
[50[88
\	\0
\\
\-'	\00
\?:]	
]]	
]#]&&
]50]88
^	_6

^^
^+&^..
^=	8_6 
_
_
_!_$$
_3	._66
`c                    [         R                  " S[         R                  S9nSU ;   aW  [         R                  " U S   R	                  5       [         R                  S9R                  S5      R                  nX!SS2SS24'   U$ )z
Extract a homogeneous transform from a dictionary.

Parameters
------------
attrib: dict, optionally containing 'transform'

Returns
------------
transform: (4, 4) float, homogeonous transformation
r   )r   r   )r   r   Nr   )r   eyer   r   rr   r   r   )r   r   valuess      r&   rc   rc     sn     q

+If&-335RZZHPPQWXZZ""1"bqb&r   )rZ   3mf)ExceptionWrapper)T)r   r   r   collectionsr   numpyr    r   r   	constantsr   r   r'   r   ZIP_DEFLATEDr   rc   networkxrh   lxmlrZ   _three_loaders_3mf_exportersBaseExceptionE
exceptionsr    r   r&   <module>r     s    	   #    -`Xv !%'2F2FVW K\,
2X&NZ(N 2--a01N-a01N	2s   	A B"BB