<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Moritz<div class=""><br class=""></div><div class="">Thank you for posting this example of your work with X3D in Python, by means of X3DOM. I admit I was completely mystified by how it worked, until I checked and discovered that the instance method _repr_html_ is in fact a 'magic method name' in IPython and Jupyter, when that method is implemented by the return value of  Python expression then Jupyter treats the string value as returned by this method call as HTML markup to be inserted into the web page; it's a shortcut for the <span class="nn">IPython.core.display.</span><span class="n">HTML function that at least I am used to seeing.</span></div><div class=""><br class=""></div><div class="">The x3d.py developers can judge whether it's useful to include this in that package, I just want to point out that using the _repr_html_ method could be extended, John Carlson has mentioned elsewhere STL files and object; and I can imagine a utility class that wrapped the data defining an STL file or other mesh, and the _repr_html_ method took care of converting that mesh into X3D code, with standard viewpoints and lighting, and presented as a 3D rendering.</div><div class=""><br class=""></div><div class="">You mentioned that part of your work involvea x-ray optics and instrumentation, you may be interested in the work Andreas Plesch has done with rendering CAD files, particularly in STEP format, in Jupyter; utilizing work in STEP to X3D conversion done by a whole bunch of people. An example nbviewer static view of such a conversion can be seen at <a href="https://nbviewer.org/github/vincentmarchetti/step_jupyter/blob/nist_example/notebooks/step_to_x3dom.ipynb" style="font-family: Calibri; font-size: 11pt;" class="">https://nbviewer.org/github/vincentmarchetti/step_jupyter/blob/nist_example/notebooks/step_to_x3dom.ipynb</a> .(you will have to scroll all the way down to see the CAD rendering) This notebook uses the HTML() function to inject the HTML markup into the webpage, not as slick as the _repr_html_ but the use of the X3DOM library and rendering an inline scene is essentially the same</div>

<div class=""><div class=""><br class=""></div><div class="">Similarly, we've demonstrated putting an animated X3D scene into a Jupyter notebook at <a href="http://nbviewer.org/github/vincentmarchetti/web3d2021_jupyter_tutorial/blob/main/conic_figure.ipynb" style="font-family: Calibri; font-size: 11pt;" class="">http://nbviewer.org/github/vincentmarchetti/web3d2021_jupyter_tutorial/blob/main/conic_figure.ipynb</a> .</div><div class=""><br class=""></div><div class="">I'm looking forward to continue sharing this work and ideas for further progress.</div><div class=""><br class=""></div><div class="">Vince Marchetti</div><div class=""><br class=""></div>

<div><br class=""><blockquote type="cite" class=""><div class="">On Feb 9, 2022, at 11:23 AM, Hans Moritz Guenther <<a href="mailto:hgunther@mit.edu" class="">hgunther@mit.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
  
  <div class=""><p class="">Hi,</p><p class="">I'm starting to use the x3d.py library to generate x3d output.
      I'm very much a Python programmer using what people call the
      "scientific stack" in Python (the libraries numpy, scipy, pandas,
      etc.) with very little experience in 3D visualization or
      web-programming.</p><p class=""></p></div></div></blockquote>...<br class=""><blockquote type="cite" class=""><div class=""><div class=""><p class="">- Jupyter notebook: The Jupyter notebook seems like an ideal tool
      for work with X3D in Python, since it is rendered on the web and
      can display any web output. Here is a simple addition of a
      `_repr_html_`method to the Scene class in the x3d.py that will
      render any valid scene with no additional effort to the screen.
      Sure, the header is a little simplistic, but it's just a quick way
      to look at what your are specifying. Since I did not want to edit
      x3d.py itself, I simply made a new class that inherits from the
      x3d.Scene, but it would obviously be even easier if this was part
      of x3d itself. See
<a class="moz-txt-link-freetext" href="http://nbviewer.org/github/hamogu/x3d-experiements/blob/main/Scence_for_notebook.ipynb">http://nbviewer.org/github/hamogu/x3d-experiements/blob/main/Scence_for_notebook.ipynb</a>
      for an example and note how the X3D output at the bottom is not
      just a screenshot, but a live output that your can zoom and rotate
      with your mouse, even though the notebook is not running live, but
      instead you just see the rendered output of what I run some time
      in the past on my laptop. (I admit that this is a naive
      implementation and it might be useful to add a few <meta> or
      <WorldInfo> nodes. Also, maybe Scene is not the best node,
      or not the only node, where to define this functionality, but it
      seems to work well.)<br class="">
    </p>
    <div style="background-color: rgb(255, 255, 255); font-family: Menlo, Monaco, "Courier New", monospace; font-weight: normal; font-size: 12px; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #0000ff;" class="">class</span><span style="" class=""> </span><span style="color: #267f99;" class="">Scene</span><span style="" class="">(</span><span style="color: #267f99;" class="">x3d</span><span style="" class="">.</span><span style="color: #267f99;" class="">Scene</span><span style="" class="">):</span></div><div class=""><span style="" class="">    </span><span style="color: #001080;" class="">js_source</span><span style="" class=""> = </span><span style="color: #a31515;" class="">'<a class="moz-txt-link-freetext" href="https://www.x3dom.org/download/x3dom.js">https://www.x3dom.org/download/x3dom.js</a>'</span></div><div class=""><span style="" class="">    </span><span style="color: #001080;" class="">css_source</span><span style="" class=""> = </span><span style="color: #a31515;" class="">'<a class="moz-txt-link-freetext" href="https://www.x3dom.org/download/x3dom.css">https://www.x3dom.org/download/x3dom.css</a>'</span></div><div class=""><span style="" class="">    </span><span style="color: #001080;" class="">dimension_px</span><span style="" class=""> = (</span><span style="color: #098658;" class="">600</span><span style="" class="">, </span><span style="color: #098658;" class="">400</span><span style="" class="">)</span></div>
<div class=""><span style="" class="">    </span><span style="color: #0000ff;" class="">def</span><span style="" class=""> </span><span style="color: #795e26;" class="">_repr_html_</span><span style="" class="">(</span><span style="color: #001080;" class="">self</span><span style="" class="">):</span></div>
<div class=""><span style="" class="">        </span><span style="color: #af00db;" class="">return</span><span style="" class="">(</span><span style="color: #0000ff;" class="">f</span><span style="color: #a31515;" class="">"""</span></div><div class=""><span style="color: #a31515;" class=""><html></span></div><div class=""><span style="color: #a31515;" class="">  <head></span></div><div class=""><span style="color: #a31515;" class="">    <meta http-equiv="X-UA-Compatible" content="IE=edge"/> </span></div><div class=""><span style="color: #a31515;" class="">     <script type='text/javascript' src='</span><span style="color: #0000ff;" class="">{</span><span style="color: #001080;" class="">self</span><span style="" class="">.</span><span style="color: #001080;" class="">js_source</span><span style="color: #0000ff;" class="">}</span><span style="color: #a31515;" class="">'> </script> </span></div><div class=""><span style="color: #a31515;" class="">     <link rel='stylesheet' type='text/css' href='</span><span style="color: #0000ff;" class="">{</span><span style="color: #001080;" class="">self</span><span style="" class="">.</span><span style="color: #001080;" class="">css_source</span><span style="color: #0000ff;" class="">}</span><span style="color: #a31515;" class="">'></link> </span></div><div class=""><span style="color: #a31515;" class="">  </head></span></div><div class=""><span style="color: #a31515;" class="">  <body></span></div><div class=""><span style="color: #a31515;" class="">    <x3d width='</span><span style="color: #0000ff;" class="">{</span><span style="color: #001080;" class="">self</span><span style="" class="">.</span><span style="color: #001080;" class="">dimension_px</span><span style="" class="">[</span><span style="color: #098658;" class="">0</span><span style="" class="">]</span><span style="color: #0000ff;" class="">}</span><span style="color: #a31515;" class="">px' height='</span><span style="color: #0000ff;" class="">{</span><span style="color: #001080;" class="">self</span><span style="" class="">.</span><span style="color: #001080;" class="">dimension_px</span><span style="" class="">[</span><span style="color: #098658;" class="">1</span><span style="" class="">]</span><span style="color: #0000ff;" class="">}</span><span style="color: #a31515;" class="">px'> </span></div><div class=""><span style="color: #a31515;" class="">      </span><span style="color: #0000ff;" class="">{</span><span style="color: #001080;" class="">self</span><span style="" class="">.XML()</span><span style="color: #0000ff;" class="">}</span></div><div class=""><span style="color: #a31515;" class="">    </x3d></span></div><div class=""><span style="color: #a31515;" class="">  </body></span></div><div class=""><span style="color: #a31515;" class=""></html></span></div><div class=""><span style="color: #a31515;" class="">"""</span><span style="" class="">)</span></div></div><p class=""><br class="">
    </p><p class="">Please let me know if there is anything I can do to help with
      this awesome package, that really makes generating X3D from Python
      so much simpler already.</p><p class="">Yours,</p>
    Moritz
    <pre class="moz-signature" cols="72">-- 
Hans Moritz Günther
Massachusetts Institute of Technology
Kavli Institute for Astrophysics and Space Research
77 Massachusetts Avenue
NE83-569
Cambridge, MA 02139
<a class="moz-txt-link-abbreviated" href="mailto:hgunther@mit.edu">hgunther@mit.edu</a>
<a class="moz-txt-link-freetext" href="https://space.mit.edu/home/guenther/">https://space.mit.edu/home/guenther/</a></pre>
  </div>

_______________________________________________<br class="">x3d-public mailing list<br class=""><a href="mailto:x3d-public@web3d.org" class="">x3d-public@web3d.org</a><br class="">http://web3d.org/mailman/listinfo/x3d-public_web3d.org<br class=""></div></blockquote></div><br class=""></div></body></html>