
    Ti(                        d dl Z d dlZd dlZddlmZmZ ddlmZ ddl	m
Z
 ddl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 ddlmZ ddlmZ ddlmZ ddZd ZddZddZ ddZ!eeeeeeedZ"e"#                    e           e"#                    e           e"#                    e
           e"#                    e           e"#                    e           dS )    N   )	resolversutil)log   )_collada_exporters)
export_glbexport_gltf)
export_obj)_off_exporters)_ply_exporters)
export_stlexport_stl_ascii)_3mf_exporters)export_urdf)_xyz_exportersc                    d}d}t          j        |          r!t          |                                          }t	          |t                    r|:t          |                              d          d                                         }|t          v rfd}|}t          j	        
                    t          j	                            |                    }t          |d          }|t          j        |          }t          |                                          }|t          vrt          d|          t	          | t           t"          t$          t&          j        f          rUd}| D ]}	|t+          |	j                  z  }t/          j        d	t+          |           ||                                           nJt5          | d
          r:t/          j        dt+          | j                  |                                           |dk    r||d<   t          |         | fi |}
t	          |
t6                    rp|9d|
v r5|
                    d          |
t          j	                            |          <   |1|
                                D ]\  }}|                    ||           |
S t5          |d          rt          j         ||
          }n|
}|r|!                                 |S )a  
    Export a Trimesh object to a file- like object, or to a filename

    Parameters
    -----------
    file_obj : str, file-like
      Where should mesh be exported to
    file_type : str or None
      Represents file type (eg: 'stl')
    resolver : None or trimesh.resolvers.Resolver
      Resolver to write referenced assets to

    Returns
    ----------
    exported : bytes or str
      Result of exporter
    FN.Twbz%s exporter not available!r   z2Exporting %d meshes with a total of %d faces as %sfaceszExporting %d faces as %sobjresolver
model.gltf)namedatawrite)"r   
is_pathlibstrabsolute
isinstancesplitlower_mesh_exportersospathabspath
expanduseropenr   FilePathResolver
ValueErrorlisttuplesetnpndarraylenr   r   debugupperhasattrdictpopbasenameitemsr   write_encodedclose)meshfile_obj	file_typer   kwargs
was_opened	file_name	file_pathr   mexportr   r   results                 Q/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/exchange/export.pyexport_meshrF      s   ( JIx   ,x((**++(C   AX,,S11"5<<>>I''J I(:(:8(D(DEEIIt,,H$5i@@ I$$&&I''5yAAA$uc2:677 R 	" 	"AS\\!EE	@IIOO		
 	
 	
 	
 
w		 R	,c$*ooy?P?PQQQ E%z Y'7777F &$ 
 \V%;%;28**\2J2JF27##I../ $llnn 5 5
dDt4444x!! #Hf55  M    c                 $    t          | d          S )zI
    Export a mesh as a dictionary, with data encoded
    to base64.
    base64)encoding)export_dict)r;   s    rE   export_dict64rL   p   s    
 th////rG   c                 l   d
fd	}g dfd| j                                         D             }| || j                   || j                   || j                  d}| j        j        dk    r || j        j                  |d<   n(| j        j        dk    r || j        j                  |d	<   |S )z
    Export a mesh to a dict

    Parameters
    ------------
    mesh : trimesh.Trimesh
      Mesh to be exported
    encoding : str or None
      Such as 'base64'

    Returns
    -------------
    export : dict
      Data stored in dict
    Nc                 p    |                                  S || j        }t          j        | |          S )N)dtyperJ   )tolistrO   r   array_to_encoded)itemrO   rJ   s     rE   encodezexport_dict.<locals>.encode   s;    ;;== }
(UXNNNNrG   )unitsr@   rA   c                 $    i | ]\  }}|v 	||S  rV   ).0kv	meta_keyss      rE   
<dictcomp>zexport_dict.<locals>.<dictcomp>   s$    IIIA!y..1...rG   )metadatar   face_normalsverticesfaceface_colorsvertexvertex_colorsN)	r\   r8   r   r]   r^   visualkindr`   rb   )r;   rJ   rS   r\   rC   rZ   s    `   @rE   rK   rK   x   s    "O O O O O O 433IIIII!4!4!6!6IIIH 
##t011F4=))	 F {6!! &t{'> ? ?}		X	%	%"(&)B"C"CMrG   FTc                 Z   | j                                         i | j                                        | j                                        | j                                        | j        dd}|rV	 t          j        t          j
        | j                            |d<   n&# t          $ r t          j        dd           Y nw xY w|rd}nd}| j                                        D ]E\  }}t#          |d	          r%|                    |
          |d}||d         |<   :||d         |<   F|S )z
    Export a Scene object as a dict.

    Parameters
    -------------
    scene : trimesh.Scene
      Scene object to be exported

    Returns
    -------------
    as_dict : dict
      Scene as a dict
    )boundsextentscentroidscale)graphgeometryscene_cacher\   zfailed to serialize metadataT)exc_infodict64r5   rC   )r=   )r   r=   rl   )rk   to_edgelistrg   rP   rh   ri   rj   jsonloadsr   jsonifyr\   BaseExceptionr   warningrl   r8   r4   rC   )scene
use_base64include_metadatarC   r=   geometry_namerl   exporteds           rE   scene_to_dictr{      sr   " ((**l))++}++----//[	
 
	 	F  G	G "&DL,H,H!I!IF: 	G 	G 	GK6FFFFFF	G  			 $)>#7#7#9#9 9 9x8X&& 
	9 !)<<& H 19F:}-- 19F:}--Ms   0.B  CCc                    t          | j                  dk    rt          d          t          j        |          r!t          |                                          }|Mt          |t
                    r)t          |                              d          d         }nt          d          |	                                
                                                    d          }|dk    rt          | fi |}n|dk    rt          | fi |}n|d	k    rt          | g|R  }n|d
k    r;|)t          |t
                    rt          j        |          }t#          | fd|i|}n|dk    rt          | d          }n|dk    rddlm}  |j        | fi |}n~|dk    r&t+          d         |                                 fi |}nR|dk    r t/          |                                 fi |}n,|dk    rt+          d         | fi |}nt          d|           t          |t0                    r|t          |t
                    rt          j        |          }t2          j                            |          d         }|                                D ]8\  }}	|dk    r|                    ||	           "|                    ||	           9|S t;          |d          rt          j        ||          S t          |t
                    ryt2          j                            t2          j                             |                    }
tC          |
d          5 }t          j        ||           ddd           n# 1 swxY w Y   |S )aK  
    Export a snapshot of the current scene.

    Parameters
    ----------
    file_obj : str, file-like, or None
      File object to export to
    file_type : str or None
      What encoding to use for meshes
      IE: dict, dict64, stl

    Returns
    ----------
    export : bytes
      Only returned if file_obj is None
    r   zCan't export empty scenes!Nr   r   zfile_type not specified!gltfglbr5   r   r   ro   T)rw   svg)svg_ioplystl3mfzunsupported export format: r   r   r   )"r1   rl   r+   r   r   r   r    r!   r"   stripr#   lstripr
   r	   r{   r   r*   r   trimesh.path.exchanger   
export_svgr$   to_meshr   r5   r%   r&   r8   r   r4   r9   r'   r(   r)   )rv   r<   r=   r   r>   r   r   	bare_pathr   blobrA   fs               rE   export_scener      s   " 5>a5666x   ,x((**++ h$$ 	9H++C004II7888 !!''))0055I F5++F++	e		%**6**	f		U,V,,,	e		 
8S 9 9 1(;;H%==(=f==	h		Ut444	e		000000 v 11&11	e		u%emmoo@@@@	e		%--//44V44	e		u%e66v66ByBBCCC $ 
 
8S 9 9 1(;;Hh//3I"jjll / /
d<''NN9d3333 NN4....x!! (!(D111	Hc	"	" (GOOBG$6$6x$@$@AA	)T"" 	(aq$'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( Ks   M11M58M5)r   r5   r~   r   r}   ro   	stl_ascii)NNrc   )FT)$rq   r%   numpyr/    r   r   	constantsr   daer   r}   r	   r
   r   r   offr   r   r   r   r   r   threemfr   urdfr   xyzr   rF   rL   rK   r{   r   r$   updaterV   rG   rE   <module>r      s    				                   # # # # # # ) ) ) ) ) ) ) )                   - - - - - - - - # # # # # #            Z Z Z Zz0 0 0+ + + +\7 7 7 7t\ \ \ \@ !    ~ & & &   ~ & & &   ) * * *   ~ & & &   ~ & & & & &rG   