
    j                     p    d dl Z d dlZd dl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  G d d	      Zy)
    N)Template)CalledProcessErrorcheck_output)NamedTemporaryFile   )exchange)logc                   &    e Zd ZddZd Zd Zd Zy)
MeshScriptc                 J    || _         || _        || _        || _        || _        y )N)debugkwargsmeshesscriptr   )selfr   r   r   r   r   s         G/DATA/.local/lib/python3.12/site-packages/trimesh/interfaces/generic.py__init__zMeshScript.__init__   s%    
     c           	      `   t        t        t        | j                                    }t        t        | j                              D cg c]9  }t	        d| j
                   t        |      j                  |       ddd      ; c}| _        t	        d| j
                   dd      | _        t	        dd      | _	        t        | j                  | j                        D ]!  \  }}|j                  |j                  	       # t        | j                        D ci c]  \  }}d
t        |      z   |j                    c}}| _        t        | j                  D cg c]  }|j                   c}      | j                  d<   | j                  j                  | j                  d<   | j                  j                  | j                  d<   t        | j                         j#                  | j                        }t%        j&                         dk(  r|j)                  dd      }| j                  j+                  |j-                  d             | j                  j/                          | j                  j/                          | j                  D ]  }|j/                           | S c c}w c c}}w c c}w )N._wbF)suffixprefixmodedeleterb)r   r   r   )r   r   )file_objMESH_MESH_PRE	MESH_POSTSCRIPTWindows\z\\zutf-8)lenstrr   ranger   r   zfillmesh_pre	mesh_post
script_outzipexportname	enumeratereplacementr   r   
substituteplatformsystemreplacewriteencodeclose)r   digit_countimeshr   mscript_texts          r   	__enter__zMeshScript.__enter__   s(   
 #c$++./0 3t{{+,
 - 4==/*a&,,{34A6	 -
 ,t}}o&T%
 -$uE "$++t}}=ND(KKK/ > BK4==AYZAYAGc!f,aff4AYZ'*DMM+JMqAFFM+J'K$(,(;(;%%)__%9%9"t{{+66t7G7GH??	)%--dF;Kk009: 	HNN &C
$ [+Js   >J #J%J+c                    t        |      j                  | j                        j                         }d }t	        j
                         dk(  r7t        j                         }|xj                  t        j                  z  c_        | j                  r3t        j                  dj                  dj                  |                   	 t        |t        j                   |      }| j                  r#t        j                  |j)                                t+        j,                  j.                  | j0                  j2                  fi | j4                  }|S # t"        $ r(}t%        |j&                  j)                               d }~ww xY w)Nr#   zexecuting: {} )stderrstartupinfo)r   r1   r0   splitr2   r3   
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWr   r	   infoformatjoinr   STDOUTr   RuntimeErroroutputdecoder   load	load_meshr*   r.   r   )r   commandcommand_runrA   rL   Emesh_resultss          r   runzMeshScript.run=   s   w'2243C3CDJJL??	)$002K:#B#BB::HH_++CHH[,ABC	2!J$5$5;F ::HHV]]_%  }}..t~~/B/BRdkkR " 	2qxx011	2s   E 	E?#E::E?c                 z   | j                   r-t        j                  d| j                  j                          y t        j                  | j                  j                         | j                  D ]!  }t        j                  |j                         # t        j                  | j                  j                         y )NzMeshScript.debug: not deleting )	r   r	   rG   r+   r.   osremover)   r*   )r   argsr   r   s       r   __exit__zMeshScript.__exit__X   sw    ::HH6t7K7K6LMN 			$//&&'HIIhmm$ &
		$..%%&r   N)stlF)__name__
__module____qualname__r   r=   rT   rY    r   r   r   r      s    !'R6	'r   r   )rV   r2   rC   stringr   r   r   tempfiler    r   utilr	   r   r^   r   r   <module>rc      s)    	    7 '  U' U'r   