
    -i,                     h    d Z ddlZddlZddlmZ ddlmZmZ ddede	fdZ
dd	Zdd
Zded   fdZy)zq
notebook.py
-------------

Render trimesh.Scene objects in HTML
and jupyter and marimo notebooks using three.js
    N)Literal   )	resourcesutilescape_quotesreturnc                 j   t        j                  t        j                  d      d      d   j	                         j                  d      }| j                  }| j                  d      }t        j                  |      j                  d      }|j                  d|      }|r|j                  dd	      S |S )
a  
    Return HTML that will render the scene using
    GLTF/GLB encoded to base64 loaded by three.js

    Parameters
    --------------
    scene : trimesh.Scene
      Source geometry
    escape_quotes
      If true, replaces quotes '"' with '&quot;' so that the
      HTML is valid inside a `srcdoc` property.

    Returns
    --------------
    html : str
      HTML containing embedded geometry
    ztemplates/viewer.zipzip)	file_typezviewer.html.templatezutf-8glbz$B64GLTF"z&quot;)r   
decompressr   	get_bytesreaddecodecameraexportbase64	b64encodereplace)scener   base_dataencodedhtmls          S/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/trimesh/viewer/notebook.pyscene_to_htmlr      s    * 		++,BCuU"	
 
	 	 	A<<%<(Dt$++G4G<<
G,D||C**K    c                     ddl m} t        | d      }|}|j                  dj	                  g d      j                  ||            }|S )aM  
    Convert a scene to HTML containing embedded geometry
    and a three.js viewer that will display nicely in
    an IPython/Jupyter notebook.

    Parameters
    -------------
    scene : trimesh.Scene
      Source geometry

    Returns
    -------------
    html : IPython.display.HTML
      Object containing rendered scene
    r   )displayTr   r    z<div><iframe srcdoc="{srcdoc}"z width="100%" height="{height}px"z$style="border:none;"></iframe></div>srcdocheight)IPythonr!   r   HTMLjoinformat)r   r'   kwargsr!   as_htmlr&   embeddeds          r   scene_to_notebookr/   ;   sT    "   %t<G F
 ||	
 &v&
.H Or   c                     ddl }t        | d      }|j                  dj                  g d      j	                  ||            }|S )a7  
    Convert a scene to HTML containing embedded geometry
    and a three.js viewer that will display nicely in
    an Marimo notebook.

    Parameters
    -------------
    scene : trimesh.Scene
      Source geometry

    Returns
    -------------
    html : mo.Html
      Object containing rendered scene
    r   NTr"   r#   r$   r%   )marimor   Htmlr*   r+   )r   r'   r,   mor&   r.   s         r   scene_to_mo_notebookr4   c   sM    "  d;F
 ww	
 &v&
.H Or   )jupyterr1   Fc                  .   	 t               } t        | j                        j                         }d|v }dt        j
                  v xr dt        j
                  d   v }|s|sy	 ddl}|j                         ry	 y# t        $ r Y #w xY w# t        $ r Y yw xY w)	z
    Check to see if we are in a Jypyter or Marimo notebook.

    Returns
    -----------
    in_notebook
      Returns the type of notebook we're in or False if it
      is running as terminal application.
    terminalr   spyderr5   r   Nr1   F)	get_ipythonstr	__class__lowerosenvironBaseExceptionr1   running_in_notebook)ipynamer7   r8   r3   s        r   in_notebookrC      s    m 3==!'')% 

"Bx2::c?'B 6!!# $     s$   AA9 "B 9	BB	BB)F)i  )__doc__r   r=   typingr    r   r   boolr:   r   r/   r4   rC    r   r   <module>rI      sL     	  ' ' 'T%P#L%W78 %r   