<div dir="auto">Indeed,  I forgot to mention my STL to X3D JSON which converts STL to X3D JSON (actually JavaScript) as an IndexedFaceSet.</div><div dir="auto"><br><div dir="auto"><a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertStlToJson.js">https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertStlToJson.js</a></div><div dir="auto"><br></div><div dir="auto">Once the STL is in X3D JSON, there are many resources in X3DJSONLD to load JSON and export other formats, see:</div><div dir="auto"><br><div dir="auto"><a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/json2all.js">https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/json2all.js</a></div></div><div dir="auto"><br></div><div dir="auto">These pretty much all leverage X3DJSONLD.js</div><div dir="auto"><br></div><div dir="auto">I am presently working on an X3D JSON to python load and export for instance:</div><div dir="auto"><br></div><div dir="auto"><div dir="auto"><a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py">https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py</a> (WIP)</div></div></div><div dir="auto"><br></div><div dir="auto">Note that stylesheets and tools in the browser converting  from XML to JSON are not a sure thing.   It’s probably best to use serverside tools for this conversion.</div><div dir="auto"><br></div><div dir="auto">X3DJSONLD.js is a part of both X3DOM and X_ITE.  See the JSONParser.js</div><div dir="auto"><br></div><div dir="auto">John</div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 9, 2022 at 6:34 PM <a href="mailto:vmarchetti@kshell.com">vmarchetti@kshell.com</a> <<a href="mailto:vmarchetti@kshell.com">vmarchetti@kshell.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div style="word-wrap:break-word;line-break:after-white-space">Moritz<div><br></div><div>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>IPython.core.display.</span><span>HTML function that at least I am used to seeing.</span></div><div><br></div><div>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><br></div><div>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" target="_blank">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><div><br></div><div>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" target="_blank">http://nbviewer.org/github/vincentmarchetti/web3d2021_jupyter_tutorial/blob/main/conic_figure.ipynb</a> .</div><div><br></div><div>I'm looking forward to continue sharing this work and ideas for further progress.</div><div><br></div><div>Vince Marchetti</div><div><br></div>

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

    
  
  <div><p>Hi,</p><p>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></p></div></div></blockquote>...</div></div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><br><blockquote type="cite"><div><div><p>- 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 href="http://nbviewer.org/github/hamogu/x3d-experiements/blob/main/Scence_for_notebook.ipynb" target="_blank">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>
    </p>
    <div style="font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)"><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">class</span><span style="font-family:Menlo,Monaco,"Courier New",monospace"> </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(38,127,153)">Scene</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">(</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(38,127,153)">x3d</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(38,127,153)">Scene</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">):</span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace">    </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">js_source</span><span style="font-family:Menlo,Monaco,"Courier New",monospace"> = </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">'<a href="https://www.x3dom.org/download/x3dom.js" target="_blank" style="font-family:Menlo,Monaco,"Courier New",monospace">https://www.x3dom.org/download/x3dom.js</a>'</span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace">    </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">css_source</span><span style="font-family:Menlo,Monaco,"Courier New",monospace"> = </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">'<a href="https://www.x3dom.org/download/x3dom.css" target="_blank" style="font-family:Menlo,Monaco,"Courier New",monospace">https://www.x3dom.org/download/x3dom.css</a>'</span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace">    </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">dimension_px</span><span style="font-family:Menlo,Monaco,"Courier New",monospace"> = (</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(9,134,88)">600</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">, </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(9,134,88)">400</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">)</span></div>
<div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace">    </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">def</span><span style="font-family:Menlo,Monaco,"Courier New",monospace"> </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(121,94,38)">_repr_html_</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">(</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">):</span></div>
<div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace">        </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(175,0,219)">return</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">(</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">f</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">"""</span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)"><html></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">  <head></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">    <meta http-equiv="X-UA-Compatible" content="IE=edge"/> </span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">     <script type='text/javascript' src='</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">{</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">js_source</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">}</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">'> </script> </span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">     <link rel='stylesheet' type='text/css' href='</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">{</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">css_source</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">}</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">'></link> </span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">  </head></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">  <body></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">    <x3d width='</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">{</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">dimension_px</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">[</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(9,134,88)">0</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">]</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">}</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">px' height='</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">{</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">dimension_px</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">[</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(9,134,88)">1</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">]</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">}</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">px'> </span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">      </span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">{</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,16,128)">self</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">.XML()</span><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,255)">}</span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">    </x3d></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">  </body></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)"></html></span></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><span style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(163,21,21)">"""</span><span style="font-family:Menlo,Monaco,"Courier New",monospace">)</span></div></div><p><br>
    </p><p>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>Yours,</p>
    Moritz
    <pre cols="72" style="font-family:monospace">-- 
Hans Moritz Günther
Massachusetts Institute of Technology
Kavli Institute for Astrophysics and Space Research
<a href="https://www.google.com/maps/search/77+Massachusetts+Avenue?entry=gmail&source=g" style="font-family:monospace">77 Massachusetts Avenue</a>
NE83-569
Cambridge, MA 02139
<a href="mailto:hgunther@mit.edu" target="_blank" style="font-family:monospace">hgunther@mit.edu</a>
<a href="https://space.mit.edu/home/guenther/" target="_blank" style="font-family:monospace">https://space.mit.edu/home/guenther/</a></pre>
  </div>

_______________________________________________<br>x3d-public mailing list<br><a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br><a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br>
</blockquote></div></div>