
    Mi;                     R   S r SSKrSSKrSSKr\" \R                  R                  S5      S   5      S:  a  \" S5      eSSK	J
r
Jr  SSKJr  SSKJrJrJrJrJrJr  SS	KJr  S
SKJr  S\R2                  S'   SSKJr  Sr " S S\R:                  R<                  5      rS r  SS jr!g)z
windowed.py
---------------

Provides a pyglet- based windowed viewer to preview
Trimesh, Scene, PointCloud, and Path objects.

Works on all major platforms: Windows, Linux, and OSX.
    N.   z;`trimesh.viewer.windowed` requires `pip install "pyglet<2"`)	renderingutil)translation_matrix)	ArrayLikeCallableDictIterableNumberOptional)to_rgba   )	TrackballFshadow_windowaX  
# SceneViewer Controls

| Input                      | Action                                        |
|----------------------------|-----------------------------------------------|
| `mouse click + drag`       | Rotates the view                              |
| `ctl + mouse click + drag` | Pans the view                                 |
| `mouse wheel`              | Zooms the view                                |
| `z`                        | Resets to the initial view                    |
| `w`                        | Toggles wireframe mode                        |
| `c`                        | Toggles backface culling                      |
| `g`                        | Toggles an XY grid with Z set to lowest point |
| `a`                        | Toggles an XYZ-RGB axis marker between: off,  |
|                            | at world frame, or at every frame and world,  |
|                            | and at every frame                            |
| `f`                        | Toggles between fullscreen and windowed mode  |
| `h`                        | Prints this help message                      |
| `m`                        | Maximizes the window                          |
| `q`                        | Closes the window                             |
|----------------------------|-----------------------------------------------|
c                     ^  \ rS rSr                 S2S\S\\   S\S\\   S\S\S\S	\\   S
\\	   S\\
   S\\   S\S\\   S\S\4U 4S jjjrS rS rS rS rS rS rS rS3S jrS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S4S  j5       r\S! 5       rS" rS# rS$ r S% r!S& r"S' r#S( r$S) r%S* r&S+ r'S, r(S- r)S. r*U 4S/ jr+S0 r,S1r-U =r.$ )5SceneViewer9   smoothflagsvisible
resolution
fullscreen	resizable
start_loopcallbackcallback_periodcaptionfixedoffset_linesline_settingsprofilerecordc                 p  > U=U l         U l        Xl        Xl        U R                  U R                   l        [        U5      U l        Xl        UR                  R                  5       U l
        [        SSU R                  (       a  UR                  S-  OS/5      U l        U R                  5         [        R                   R#                  5       U l        X l        [        U5      U l        U R(                  (       a  SSKJn  UU l        [        U5      U l        U R.                  (       a  / U R                   R0                  S'   UU l        SU l        SU l        0 U l        0 U l        0 U l        Xl        [A        5       U l!        0 U l"        Uc  URF                  RH                  nOXQRF                  l$        Uc  Sn[K        U5      nUS-  US-  S	.U l&        Ub  U RL                  RO                  U5        Uc2   [P        RR                  " S
SSSS9n[T        TU ]  UUUUUS   US
   US9  O[T        TU ]  UUUUUS   US
   US9  U R]                  5         U R_                  5         U R`                  " U6   Ub  U R                  US9  U Rc                  5         U R                  b&  U
c  Sn
[        Rd                  Rg                  S U
5        U(       a  [        Rh                  Rk                  5         gg! [        RX                  RZ                   a0    [P        RR                  " SS9n[T        TU ]  UUUUUS   US
   US9   Nf = f)a  
Create a window that will display a trimesh.Scene object
in an OpenGL context via pyglet.

Parameters
---------------
scene : trimesh.scene.Scene
  Scene with geometry and transforms
smooth
  If True try to smooth shade things
flags
  If passed apply keys to self.view:
  ['cull', 'wireframe', etc]
visible
  Display window or not
resolution
  Initial resolution of window
fullscreen
  Determines whether the window is rendered in fullscreen mode.
resizable
  Determines whether the rendered window can be resized by the user.
start_loop
  Call pyglet.app.run() at the end of init
callback
  A function which can be called periodically to
  update things in the scene
callback_period
  How often to call the callback, in seconds
caption
  Caption for the window title
fixed
  List of keys in scene.geometry to skip view
  transform on to keep fixed relative to camera
offset_lines
  If True, will offset lines slightly so if drawn
  coplanar with mesh geometry they will be visible
line_settings
  Override default line width and point size with keys
  'line_width' and 'point_size' in pixels
background
  Color for background
window_conf
  Passed to window init
profile
  If set will run a `pyinstrument` profile for
  every call to `on_draw` and print the output.
record
  If True, will save a list of `png` bytes to
  a list located in `scene.metadata['recording']`
kwargs
  Additional arguments to pass, including
  'background' for to set background color
r   i  )Profiler	recordingNz"Trimesh SceneViewer (`h` for help)   i  )
point_size
line_widthr         T)sample_bufferssamples
depth_sizedouble_buffer)configr   r   r   widthheightr   )r/   )r0   r   r   r   r1   r2   r   )r   g?c                     U $ N )xs    q/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/viewer/windowed.py<lambda>&SceneViewer.__init__.<locals>.<lambda>  s    Q    )6scene_scener   r   _redrawboolr    
backgroundcamera_transformcopy_initial_camera_transformr   scale_line_offset
reset_viewpygletgraphicsBatchbatch_smooth_profilepyinstrumentr%   _recordmetadatakwargs_axis_gridvertex_listvertex_list_hashvertex_list_moder   set_nodes_hiddentexturescamerar   maxr!   updateglConfigsuper__init__windowNoSuchConfigException_update_vertex_listinit_glset_sizeupdate_flagsclockschedule_intervalapprun)selfr;   r   r   r   r   r   r   r   r   r   r   r   r    r!   r?   window_confr"   r#   rO   r%   rC   conf	__class__s                          r7   r^   SceneViewer.__init__:   s    V $)(
T[ .!\\

 .$).)?)?)D)D)F& /):):5;;%B
 	__**,
W==-$DMF|<</1DJJ,  

 " "
 U 00J&0LL#?:G J,1CKus{S$%%m4  yy#$aBd  #)'$Q-%a=# ! , G"%# m!!}   	  " 	z"OO%O( ==$&", LL**;HJJNN W ==66 
yyt4 )'#$Q-%a=# ! 
s   20K' 'AL54L5c                 $    U R                  5         g r4   )on_drawri   s    r7   r=   SceneViewer._redraw  s    r:   c                    U R                   R                  R                  5        He  u  pUR                  (       a  M  [	        U5      U R
                  R                  U5      :X  a  MB  U R                  X[        U R                  5      S9  Mg     g )N)namegeometryr   )
r;   rt   itemsis_empty_geometry_hashrS   getadd_geometryr>   rJ   )ri   rs   geoms      r7   ra   SceneViewer._update_vertex_list
  sh    **--335JD}}d#t'<'<'@'@'FF4tDLL?QR 6r:   c                     U R                   bR  U R                  U R                  5        U R                  5         U R                  U R                  U R
                  5        g g r4   )r   r;   ra   _update_perspectiver1   r2   rp   s    r7   _update_meshesSceneViewer._update_meshes  sE    ==$MM$**%$$&$$TZZ= %r:   c                 \    [         R                  " U40 UD6nU R                  R                  " U6 U R                  U'   [        U5      U R                  U'   US   U R                  U'   [        USS5      n[        US5      (       aF  [        US	5      (       a4   [         R                  " UR                  5      nUb  X`R                   U'   gggg! [         a%    [        R                  R                  SU S3SS9   gf = f! [         a!    [        R                  R                  S
SS9   gf = f)z
Add a geometry to the viewer.

Parameters
--------------
name : hashable
  Name that references geometry
geometry : Trimesh, Path2D, Path3D, PointCloud
  Geometry to display in the viewer window
kwargs **
  Passed to rendering.convert_to_vertexlist
zfailed to add geometry ``Texc_infoNr   visualuvmaterialzfailed to load texture)r   convert_to_vertexlistBaseExceptionr   logwarningrI   add_indexedrR   rw   rS   rT   getattrhasattrmaterial_to_texturer   rW   )ri   rs   rt   rO   argsr   texs          r7   ry   SceneViewer.add_geometry  s'   	228FvFD "&!7!7!>&4X&>d#&*1gd# 8T264  WVZ%@%@J33FOOD?*-MM$' # &A   	HH7vQ?$O	$ ! J  !9D IJs#   C 1D  ,C=<C= (D+*D+c                    U R                   R                  nUR                   Vs1 s H
  o!U   S   iM     nnU R                   Vs/ s H  oDU;  d  M
  UPM     nnU Hs  nU R                  R	                  US5        U R
                  R	                  US5        U R                  R	                  US5        U R                  R	                  US5        Mu     gs  snf s  snf )zC
Remove any stored vertex lists that no longer
exist in the scene.
r   N)r;   graphnodes_geometryrR   poprS   rT   rW   )ri   r   node	geom_keeprz   geom_deletes         r7   cleanup_geometriesSceneViewer.cleanup_geometries?  s     

  050D0DE0D4[^0D	E(,(8(8R(8	<Qt(8RD  t,!!%%dD1!!%%dD1MMdD)   FRs   C	CCc                 :    U R                   R                  U5        g)z
If a node is hidden remove the flag and show the
geometry on the next draw.

Parameters
-------------
node : str
  Node to display
N)rV   discardri   r   s     r7   unhide_geometrySceneViewer.unhide_geometryQ  s     	""4(r:   c                 :    U R                   R                  U5        g)z}
Don't display the geometry contained at a node on
the next draw.

Parameters
-------------
node : str
  Node to not display
N)rV   addr   s     r7   hide_geometrySceneViewer.hide_geometry]  s     	t$r:   c                    SSSSS[        U R                  U R                  R                  R                  U R                  R
                  U R                  R                  S9S.U l         [        U[        5      (       aI  UR                  5        H$  u  p#X R                  ;   d  M  X0R                  U'   M&     U R                  5         gg! [         a     gf = f)z
Set view to the default view.

Parameters
--------------
flags : None or dict
  If any view key passed override the default
  e.g. {'cull': False}
TF)posesizerC   target)cullaxisgridr   	wireframeballN)r   rB   r;   rX   r   rC   centroidview
isinstancedictru   rd   r   )ri   r   kvs       r7   rE   SceneViewer.reset_viewi  s     33ZZ&&11jj&&zz**	
		%&&!KKMDAII~'(		! * !!#	 '
  		s   *7C	 %"C	 	
CCc                    U R                   c  [        R                  " S5      nO7[        U R                   5      nUR	                  [        R
                  5      S-  nU R                  U5        U R                  U R                  R                  5        U R                  5         U R                  5         U R                  " S0 U R                  D6  U R                  U R                  5        g)zH
Perform the magic incantations to create an
OpenGL scene using pyglet.
Nr*   g     o@r5   )r?   nponesr   astypefloat64_gl_set_background_gl_enable_depthr;   rX   _gl_enable_color_material_gl_enable_blending_gl_enable_smooth_linesr!   _gl_enable_lighting)ri   r?   s     r7   rb   SceneViewer.init_gl  s     ??"J !1J#**2::6>J
+djj//0&&(  "$$:t'9'9:  ,r:   c                 *    [         R                  " U 6   g r4   r[   glClearColor)r?   s    r7   r   SceneViewer._gl_set_background  s    
$r:   c                  .    [         R                  " / SQ6   g )N)r   r   r   r   r   r5   r:   r7   _gl_unset_background SceneViewer._gl_unset_background  s    
&r:   c                 P   [         R                  " S5        [         R                  " [         R                  5        [         R                  " [         R
                  5        [         R                  " [         R                  5        [         R                  " [         R                  5        g)zB
Enable depth test in OpenGL using distances
from `scene.camera`.
g      ?N)r[   glClearDepthglEnableGL_DEPTH_TESTglDepthFunc	GL_LEQUALGL_CULL_FACE)rX   s    r7   r   SceneViewer._gl_enable_depth  sT     	
B$$%
r||$
B$$%
BOO$r:   c            	         [         R                  " [         R                  [         R                  5        [         R                  " [         R
                  5        [         R                  " [         R                  5        [         R                  " [         R                  [         R                  [        R                  " SSS5      5        [         R                  " [         R                  [         R                  [        R                  " SSS5      5        [         R                  " [         R                  [         R                  [        R                  " SSS5      5        [         R                  " [         R                  [         R                   S5        g )NgS㥛?g-=?gC?gI@)r[   glColorMaterialGL_FRONT_AND_BACKGL_AMBIENT_AND_DIFFUSEr   GL_COLOR_MATERIALglShadeModel	GL_SMOOTHglMaterialfvGL_FRONT
GL_AMBIENTr   vector_to_gl
GL_DIFFUSEGL_SPECULARglMaterialfGL_SHININESSr5   r:   r7   r   %SceneViewer._gl_enable_color_material  s     	2//1J1JK
B(()
%
KKMM""8Xx@	

 	KKMM""8Xx@	

 	KKNN""9iC	
 	r{{BOO[Ar:   c                      [         R                  " [         R                  5        [         R                  " [         R                  [         R
                  5        g r4   )r[   r   GL_BLENDglBlendFuncGL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHAr5   r:   r7   r   SceneViewer._gl_enable_blending  s,     	BKK 
r(A(ABr:   c                 
   [         R                  " [         R                  5        [         R                  " [         R                  [         R
                  5        [         R                  " U 5        [         R                  " U5        g r4   )r[   r   GL_LINE_SMOOTHglHintGL_LINE_SMOOTH_HINT	GL_NICESTglLineWidthglPointSize)r)   r(   s     r7   r   #SceneViewer._gl_enable_smooth_lines  sF     	B%%&
		"((",,7
z"
z"r:   c                    [         R                  " [         R                  5        [        U R                  SS 5       H  u  p[        SU 35      nU R                  R                  UR                  5      S   n[        R                  " X$US9n[         R                  " U5        U H  n[         R                  " U6   M     M     g)zJ
Take the lights defined in scene.lights and
apply them as openGL lights.
N   zgl.GL_LIGHTr   )light	transformlightN)r[   r   GL_LIGHTING	enumeratelightsevalr   rx   rs   r   light_to_gl	glLightfv)r;   ir   r   matrix	multiargsr   s          r7   r   SceneViewer._gl_enable_lighting  s     	BNN#!%,,r"23HAKs+,F [[__UZZ03F "--fI
 KK!d# " 4r:   c                 f    U R                   S   (       + U R                   S'   U R                  5         g)z
Toggle back face culling.

It is on by default but if you are dealing with
non- watertight meshes you probably want to be able
to see the back sides.
r   Nr   rd   rp   s    r7   toggle_cullingSceneViewer.toggle_culling  s*     !%		& 11		&r:   c                 f    U R                   S   (       + U R                   S'   U R                  5         g)zI
Toggle wireframe mode

Good for  looking inside meshes, off by default.
r   Nr   rp   s    r7   toggle_wireframeSceneViewer.toggle_wireframe  s*     &*YY{%;!;		+r:   c                 f    U R                   S   (       + U R                   S'   U R                  5         g)z.
Toggle between fullscreen and windowed mode.
r   Nr   rp   s    r7   toggle_fullscreenSceneViewer.toggle_fullscreen  s*     '+ii&="=		,r:   c                     / SQnUR                  U R                  S   5      S-   [        U5      -  nX   U R                  S'   U R                  5         g)zF
Toggle a rendered XYZ/RGB axis marker:
off, world frame, every frame
)Fworldallwithout_worldr   r   N)indexr   lenrd   )ri   statesr
  s      r7   toggle_axisSceneViewer.toggle_axis  sJ     :dii/014FC"M		&r:   c                 f    U R                   S   (       + U R                   S'   U R                  5         g)z
Toggle a rendered grid.
r   Nr   rp   s    r7   toggle_gridSceneViewer.toggle_grid#  s*    
 !%		& 11		&r:   c                 "   U R                   S   (       a4  [        R                  " [        R                  [        R                  5        O3[        R                  " [        R                  [        R
                  5        U R                  U R                   S   S9  U R                   S   (       a%  [        R                  " [        R                  5        O$[        R                  " [        R                  5        U R                   S   (       an  U R                  ca  SSKJn  UR                  U R                  R                  S	-  S
9n[         R"                  " U5      nU R$                  R&                  " U6 U l
        OBU R                   S   (       d.  U R                  b!  U R                  R)                  5         SU l
        U R                   S   (       a  U R*                  c   SSKJn  U R                  R0                  nUR3                  SS9nUS   S   [4        R6                  " USS2S4   5      S	-  -
  US'   [4        R6                  " USS9SS R9                  5       nU" US[;        U5      S9n[         R<                  " U5      nU R$                  R&                  " U6 U l        gU R                   S   (       d0  U R*                  b"  U R*                  R)                  5         SU l        ggg! [>         a!    [@        RB                  RE                  SSS9   gf = f)z7
Check the view flags, and call required GL functions.
r   r   )r   r   r   Nr   )creationd   )origin_sizer   )r   r   )r   r*   )sidecountr   zfailed to create grid!Tr   )#r   r[   glPolygonModer   GL_LINEGL_FILLset_fullscreenr   r   	glDisablerP    r  r   r;   rC   r   mesh_to_vertexlistrI   r   deleterQ   path.creationr   boundsmeanr   ptprY   r   r   r   r   r   r   )	ri   r  r   r   r   r!  centerr  	grid_meshs	            r7   rd   SceneViewer.update_flags,  sD   
 99[!R112::>R112::> 	tyy'>? 99VKK(LL) 99V!3# ==TZZ-=-=-C=DD//5D//6DJ 6"tzz'=JJDJ99V!3J0**!, #1IaLBFF6!Q$<,@3,FGq	vvf1-bq1557 d!?QRX?YZ	 66yA!ZZ33T:
 6"tzz'=JJDJ (>" ! J  !9D IJs   CK# #(LLc                     U R                  5       u  p[        R                  " SSX5        [        R                  " [        R
                  5        [        R                  " 5         U R                  R                  n[        R                  " UR                  S   U[        U5      -  UR                  UR                  5        [        R                  " [        R                  5        X4$ ! [         a     Nf = f)Nr   r   )get_viewport_sizer   r[   
glViewportglMatrixModeGL_PROJECTIONglLoadIdentityr;   rX   gluPerspectivefovfloatz_nearz_farGL_MODELVIEW)ri   r1   r2   rX   s       r7   r}   SceneViewer._update_perspectivej  s    	 !224ME 	aE*
(()
 "" 	JJqM55=0&--	
 	(}%  		s   C( (
C54C5c                 *   U R                  X5      u  pX4U R                  R                  l        U R                  S   R                  U R                  R                  R                  5        U R                  S   R                  U R                  l        g)z
Handle resized windows.
r   N)r}   r;   rX   r   r   resizer   r@   )ri   r1   r2   s      r7   	on_resizeSceneViewer.on_resize  sl     00?(-

$		&  !2!2!=!=>&*ii&7&<&<

#r:   c                    U R                   S   R                  [        R                  5        U[        R
                  R                  R                  :X  a  U[        R
                  R                  R                  -  nU[        R
                  R                  R                  -  nU(       a5  U(       a.  U R                   S   R                  [        R                  5        GOU(       a-  U R                   S   R                  [        R                  5        OU(       a,  U R                   S   R                  [        R                  5        OU[        R
                  R                  R                  :X  a-  U R                   S   R                  [        R                  5        OTU[        R
                  R                  R                  :X  a,  U R                   S   R                  [        R                  5        U R                   S   R!                  ["        R$                  " X/5      5        U R                   S   R&                  U R(                  l        g)z"
Set the start point of the drag.
r   N)r   	set_stater   STATE_ROTATErF   r_   mouseLEFTkeyMOD_CTRL	MOD_SHIFT
STATE_ZOOM
STATE_ROLL	STATE_PANMIDDLERIGHTdownr   arrayr   r;   r@   )ri   r6   ybuttons	modifiersctrlshifts          r7   on_mouse_pressSceneViewer.on_mouse_press  sw    			&##I$:$:;fmm))...v}}00999D 1 1 ; ;;E		&!++I,@,@A		&!++I,@,@A		&!++I,?,?@++222IIf''	(;(;<++111IIf''	(<(<=		&rxx/0&*ii&7&<&<

#r:   c                     U R                   S   R                  [        R                  " X/5      5        U R                   S   R                  U R
                  l        g)z
Pan or rotate the view.
r   N)r   dragr   rF  r   r;   r@   )ri   r6   rG  dxdyrH  rI  s          r7   on_mouse_dragSceneViewer.on_mouse_drag  sA     			&rxx/0&*ii&7&<&<

#r:   c                     U R                   S   R                  U5        U R                   S   R                  U R                  l        g)z
Zoom the view.
r   N)r   scrollr   r;   r@   )ri   r6   rG  rP  rQ  s        r7   on_mouse_scrollSceneViewer.on_mouse_scroll  s6     			&  $&*ii&7&<&<

#r:   c                    SnU[         R                  R                  R                  :X  a  U R	                  5         GOU[         R                  R                  R
                  :X  a  U R                  5         GOU[         R                  R                  R                  :X  a  U R                  5         GOUU[         R                  R                  R                  :X  a  U R                  5         GOU[         R                  R                  R                  :X  a  U R                  5         OU[         R                  R                  R                  :X  a  U R                  5         OU[         R                  R                  R                  :X  a  U R!                  5         OpU[         R                  R                  R"                  :X  a  U R%                  5         O7U[         R                  R                  R&                  :X  a  [)        [*        5        U[         R                  R                  R,                  [         R                  R                  R.                  [         R                  R                  R0                  [         R                  R                  R2                  4;   Gan  U R4                  S   R7                  SS/5        U[         R                  R                  R,                  :X  a"  U R4                  S   R9                  U* S/5        OU[         R                  R                  R.                  :X  a!  U R4                  S   R9                  US/5        OU[         R                  R                  R0                  :X  a"  U R4                  S   R9                  SU* /5        OHU[         R                  R                  R2                  :X  a   U R4                  S   R9                  SU/5        U R4                  S   R:                  U R<                  l        gg)z/
Call appropriate functions given key presses.

   r   r   N) rF   r_   r=  Wr  ZrE   Cr   Ar  Gr  Qon_closeMmaximizeFr  Hprint_HELP_MESSAGEr<  rD  DOWNUPr   rE  rO  r   r;   r@   )ri   symbolrI  	magnitudes       r7   on_key_pressSceneViewer.on_key_press  s    	V]]&&(((!!#v}}((***OOv}}((***!v}}((***v}}((***v}}((***MMOv}}((***MMOv}}((***""$v}}((***- MM""MM##MM""MM  	
 
 IIf""Aq6***///		&!&&
A76==,,222		&!&&	1~66==,,111		&!&&I:76==,,///		&!&&9~6*.))F*;*@*@DJJ'
r:   c                 4   U R                   (       a   U R                  5       nUR                  5         U R                  5         [        R
                  " [        R                  [        R                  -  5        [        R                  " 5         [        R                  R                  U R                  R                  5      n[        R                  " [        R                   " U5      5        ["        R$                  " U R                  R&                  R(                  5      n[+        U5      nSnU R,                  (       a:  U R.                  S   S:X  d'  U R,                  R1                  [        R2                  S9  U R4                  (       a'  U R4                  R1                  [        R6                  S9  U R                  R8                  nU R                  R&                  n[+        U5      S:  Gaa  US-  nUR;                  5       nXR<                  ;   a  M6  UR?                  U5      u  pU
b  XR@                  ;  a  M]  U RB                  bc  XRB                  ;   aT  [        R                  R                  [        RD                  " U RF                  U5      5      n[        RD                  " X5      n	Xj   nURH                  (       a  M  U R@                  U
   nU[        R6                  :X  aA  [J        RL                  " U	[        R                  R                  U5      U RN                  U/5      n	[        RP                  " 5         [        R                  " [        R                   " U	5      5        U R.                  S   S:X  a(  U R,                  R1                  [        R2                  S9  OiU R.                  S   S:X  aV  [J        RR                  " U	[        RT                  " S	5      S
S9(       d'  U R,                  R1                  [        R2                  S9  [W        US5      (       ad  [W        URX                  S5      (       aI  URX                  RZ                  (       a.  XT:  a)  UR]                  U5        [        R^                  " 5         GM  SnXR`                  ;   aZ  U R`                  U
   n[        Rb                  " URd                  5        [        Rf                  " URd                  URh                  5        U Rj                  U
   R1                  US9  [        R^                  " 5         Ub   [        Rl                  " URd                  5        [+        U5      S:  a  GMa  U R                   (       a>  WRo                  5         [J        Rp                  Rs                  URu                  SSS95        gg)z
Run the actual draw calls.
r   r	  )moder   r   Nr  r*   gh㈵>)atolr   transparencyT)unicodecolor);rK   r%   startr~   r[   glClearGL_COLOR_BUFFER_BITGL_DEPTH_BUFFER_BITr,  r   linalginvr;   r@   glMultMatrixfr   matrix_to_glcollectionsdequer   r   r  rP   r   drawGL_TRIANGLESrQ   GL_LINESrt   popleftrV   rx   rT   r   dotrB   rv   r   	multi_dotrD   glPushMatrixallcloseeyer   r   rq  appendglPopMatrixrW   r   r   glBindTextureidrR   r  stopr   debugoutput_text)ri   profilertransform_camera
node_namescount_originalr  rt   r   current_noder   geometry_nametransform_fixmeshro  textures                  r7   ro   SceneViewer.on_draw  s   
 ==}}HNN


2))B,B,BBC
 99==)D)DE 	//0@AB !&&tzz'7'7'F'FG
Z ::dii/?BJJOOO1::JJOOO- ::&&

  *o!QJE%--/L111 (-yy'>$I$=R=R(R zz%-::*E "		FF499;KL! FF9<	 *D}}((7D r{{" NN!		&67))(		 OOY33I>? yy E)

R__56"o5}}Yq	EJJOOO9 h''DKK88KK,, )%%l3NN$ G---6GNN+  < ]+00d0;NN "W^^,g *o!j ==MMOHHNN8//D/IJ r:   c                   > [         TU ]  5         U R                  (       al  U R                  [        R
                  " 5       5      nUR                  S5        U R                  R                  S   R                  UR                  5       5        g g )Nr   r&   )r]   fliprM   
save_imager   BytesIOseekr;   rN   r  read)ri   imgrl   s     r7   r  SceneViewer.flipW  sZ    <<//$,,.1CHHQKJJ,33CHHJ? r:   c                     [         R                  R                  5       nUR                  5       n[	        US5      (       a  UR                  US9  U$ UR                  US9  U$ )z
Save the current color buffer to a file object
in PNG format.

Parameters
-------------
file_obj: file name, or file- like object
write)file)filename)rF   imageget_buffer_managerget_color_bufferr   save)ri   file_objmanagercolorbuffers       r7   r  SceneViewer.save_imagea  sa     ,,113..08W%%(+  h/r:   )r%   rP   rQ   rB   rD   rV   rK   rM   r<   rJ   r?   rI   r   r   r   rO   r!   r    r;   rW   rR   rS   rT   r   )TNTNFTTNNNNTNNNFFr4   )r*   r*   )/__name__
__module____qualname____firstlineno__r>   r   r
   r   r	   r   strr   r^   r=   ra   r~   ry   r   r   r   rE   rb   staticmethodr   r   r   r   r   r   r   r   r  r  r  r  rd   r}   r6  rL  rR  rV  rk  ro   r  r  __static_attributes____classcell__)rl   s   @r7   r   r   9   s"     $*. '+,0!%$(!(,'K K ~	K
 K Y'K K K K 8$K "&)K #K !K K  ~K$ %K& 'K KZS>#JJ*$
)
%B-0 % % ' ' 
% 
% B B0 C C
 # # $ $2	<|2==,=='AR|K|@ r:   r   c                     [        [        U 5      5      n[        U S5      (       a!  U[        [        U R                  5      5      -  nU$ )zn
Get a hash for a geometry object

Parameters
------------
geometry : object

Returns
------------
hash : str
r   )r  hashr   r   )rt   hs     r7   rw   rw   t  s<     	DNAx""	Shoo&''Hr:   c           	         [        U 4SUUUUS.UD6nSSKJn  S H  n[        R                  R                  5         UR                  5         UR                  5         UR                  S5        UR                  5         U(       d  Mk  U" 5       n	UR                  U	5        U	R                  S5        U	R                  5       n
M     UR                  5         W
$ )a0  
Render a preview of a scene to a PNG. Note that
whether this works or not highly variable based on
platform and graphics driver.

Parameters
------------
scene : trimesh.Scene
  Geometry to be rendered
resolution : (2,) int or None
  Resolution in pixels or set from scene.camera
visible : bool
  Show a window during rendering. Note that MANY
  platforms refuse to render with hidden windows
  and will likely return a blank image; this is a
  platform issue and cannot be fixed in Python.
fullscreen : bool
  Determines whether the window is rendered in fullscreen mode.
  Defaults to False (windowed).
resizable : bool
  Determines whether the rendered window can be resized by the user.
  Defaults to True (resizable).
kwargs : **
  Passed to SceneViewer

Returns
---------
render : bytes
  Image in PNG format
F)r   r   r   r   r   r   )r  )FFTro   r   )r   r   r  rF   re   tick	switch_todispatch_eventsdispatch_eventr  r  r  r  close)r;   r   r   r   r   rO   r_   r  r  r  renders              r7   render_scener    s    B  F  % i(4yHh'MM!]]_F % LLNMr:   )NTFT)"__doc__r|  numpyr   rF   intversionsplitImportErrorr  r   r   transformationsr   typedr   r	   r
   r   r   r   r   r   	trackballr   options	pyglet.glr[   rf  r_   Windowr   rw   r  r5   r:   r7   <module>r     s       v~~C #$)
S
TT  0 I I   "'  .x&--&& xv* GK<r:   