[x3d-public] Mojo Playground available through a JupyterHub

John Carlson yottzumm at gmail.com
Tue Jun 20 00:14:23 PDT 2023


I ran into a show stopper with Mojo.  I was progressing using a special
form of import, found here:

Modular Docs - Mojo🔥 programming manual
<https://docs.modular.com/mojo/programming-manual.html#python-integration>

But ran into:

error: Expression [10]:8:34: keyword arguments are not supported yet
    let newModel=x3d.X3D(profile='Immersive',version='3.3',
                                 ^

If anyone is interested, I can provide a notebook to work from.  I might
revamp PythonSerializers to do something else with keyword arguments, since
there seems to be a showstopper?

Error below:

error: Expression [10]:8:34: keyword arguments are not supported yet
    let newModel=x3d.X3D(profile='Immersive',version='3.3',
                                 ^

On Tue, Jun 20, 2023 at 1:16 AM John Carlson <yottzumm at gmail.com> wrote:

> I added a couple of more let's for variables at function scope.
>
> On Tue, Jun 20, 2023 at 12:13 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> I was able to avoid syntax errors (no global variables in Mojo).  Here's
>> my current code (note that this won't run in python due to "let"
>>
>> Thanks!
>>
>>
>> ####################################################################################################
>> #
>> # Now available: developmental python x3d.py package on PyPi for import.
>> #   This approach simplifies Python X3D deployment and use.
>> #   https://pypi.org/project/x3d
>> #
>> # Installation:
>> #       pip install x3d
>> # or
>> #       python -m pip install x3d
>> #
>> # Developer options for loading x3d package:
>> #
>> #    from x3d import *  # preferred approach, terser source that avoids
>> x3d.* class prefixes
>> #
>> # or
>> #    import x3d         # traditional way to subclass x3d package, all
>> classes require x3d.* prefix,
>> #                       # but python source is very verbose, for example
>> x3d.Material x3d.Shape etc.
>> #                       # X3dToPython.xslt stylesheet
>> insertPackagePrefix=true supports this option.
>> #
>>
>> ####################################################################################################
>> #print("'''")   # comment out output created by importing x3d (see below)
>> from x3d import *
>> from x3d import X3D
>> from IPython import HTML
>> #print("'''")   # comment out output created by importing x3d (see below)
>>
>> #  comment preceding root node
>> def createScene():
>>     let newModel=X3D(profile='Immersive',version='3.3',
>>       head=head(
>>         children=[
>>         meta(content='HelloWorld.x3d',name='title'),
>>         meta(content='Simple X3D scene example: Hello
>> World!',name='description'),
>>         meta(content='30 October 2000',name='created'),
>>         meta(content='31 October 2019',name='modified'),
>>         meta(content='Don Brutzman',name='creator'),
>>         meta(content='HelloWorld.tall.png',name='Image'),
>>         meta(content='http://en.wikipedia.org/wiki/Hello_world
>> ',name='reference'),
>>         meta(content='
>> https://en.wikipedia.org/wiki/Hello#.22Hello.2C_World.22_computer_program
>> ',name='reference'),
>>         meta(content='https://en.wikipedia.org/wiki/
>> "Hello,_World!"_program',name='reference'),
>>         meta(content='
>> http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world
>> ',name='reference'),
>>         meta(content='http://www.HelloWorldExample.net
>> ',name='reference'),
>>         meta(content='http://www.web3D.org',name='reference'),
>>         meta(content='
>> http://www.web3d.org/realtime-3d/news/internationalization-x3d
>> ',name='reference'),
>>         meta(content='
>> http://www.web3d.org/x3d/content/examples/HelloWorld.x3d
>> ',name='reference'),
>>         meta(content='
>> http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes
>> ',name='reference'),
>>         meta(content='
>> http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01TechnicalOverview/HelloWorld.x3d
>> ',name='identifier'),
>>         meta(content='
>> http://www.web3d.org/x3d/content/examples/license.html',name='license'),
>>         meta(content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit
>> ',name='generator'),
>>         #  Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D
>> Compressed Binary Encoding (CBE), X3DOM, JSON
>>         meta(content='HelloWorld.wrl',name='reference'),
>>         meta(content='HelloWorld.x3dv',name='reference'),
>>         meta(content='HelloWorld.x3db',name='reference'),
>>         meta(content='HelloWorld.xhtml',name='reference'),
>>         meta(content='HelloWorld.json',name='reference')]),
>>       Scene=Scene(
>>         #  Example scene to illustrate X3D nodes and fields (XML elements
>> and attributes)
>>         children=[
>>         WorldInfo(title='Hello World!'),
>>         WorldInfo(title="Hello ' apostrophe 1"),
>>         WorldInfo(title="Hello ' apostrophe 2"),
>>         WorldInfo(title='Hello " quotation mark 3'),
>>         WorldInfo(title='Hello " quotation mark 4'),
>>         MetadataSet(name="items'",
>>           value=[
>>           MetadataInteger(name='one',value=[1]),
>>           MetadataInteger(name='two',value=[2])]),
>>         Group(
>>           children=[
>>
>> Viewpoint(DEF='ViewUpClose',centerOfRotation=(0,-1,0),description='Hello
>> world!',position=(0,-1,7)),
>>           #  insert commas to test removal when converted to ttl
>>           Transform(DEF='TestWhitespaceCommas',rotation=(0,1,0,3),
>>             children=[
>>             Shape(
>>               geometry=Sphere(),
>>               appearance=Appearance(
>>
>> material=Material(DEF='MaterialLightBlue',diffuseColor=(0.1,0.5,1)),
>>
>> texture=ImageTexture(DEF='ImageCloudlessEarth',url=["earth-topo.png",
>> "earth-topo.jpg", "
>> https://www.web3d.org/x3d/content/examples/Basic/earth-topo.png","
>> http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg","
>> http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif
>> "])))]),
>>           Transform(translation=(0,-2,0),
>>             children=[
>>             Shape(
>>               geometry=Text(DEF='TextMessage',string=["Hello","world!"],
>>                 fontStyle=FontStyle(justify=["MIDDLE","MIDDLE"])),
>>               appearance=Appearance(
>>                 material=Material(USE='MaterialLightBlue')))])])])
>>     ) # X3D model complete
>>
>>
>> ####################################################################################################
>>     # Self-test diagnostics
>>
>> ####################################################################################################
>>     let htmlcode = """
>>     <script type='text/javascript' charset="UTF-8" src='
>> https://x3dom.org/release/x3dom-full.debug.js'> </script>
>>     <link rel='stylesheet' type='text/css' href='
>> https://x3dom.org/release/x3dom.css'></link>
>>     <style>
>>      x3d {
>>          width:720px;
>>          height:720px;
>>          border:2px solid black;
>>     }
>>     </style>
>>     """
>>
>>     let x3dnode = htmlcode+"""
>>     <x3d>%s</x3d>
>>     <script>
>>     window.x3dom.reload()
>>     </script>
>>     """ % newModel.Scene.HTML5()
>>
>>     HTML(x3dnode)
>>
>> createScene()
>>
>>
>> On Mon, Jun 19, 2023 at 10:45 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>>> Yes, I tried using Vince’s technique (nearly, couldn’t find %%html) with
>>> (Mojo) Jupyter and X3DOM.  I was hoping that Vince could show that his
>>> technique still works in Jupyter and (my?)binder.
>>>
>>> I’m not seeing anyway to render with Jupyter or Mojo Playground.
>>> Brython may still work.
>>>
>>> I will try again tonight.
>>>
>>> John
>>>
>>> On Mon, Jun 19, 2023 at 11:34 AM Brutzman, Donald (Don) (CIV) <
>>> brutzman at nps.edu> wrote:
>>>
>>>> I recommend you use the methods to export/launch to X3DOM.  If you have
>>>> a CORS server running locally, you can export/launch to X_ITE as well.
>>>>
>>>>
>>>>
>>>> all the best, Don
>>>>
>>>> --
>>>>
>>>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>>>> brutzman at nps.edu
>>>>
>>>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>>>> +1.831.656.2149
>>>>
>>>> X3D graphics, virtual worlds, navy robotics
>>>> https://faculty.nps.edu/brutzman
>>>>
>>>>
>>>>
>>>> *From:* John Carlson <yottzumm at gmail.com>
>>>> *Sent:* Monday, June 19, 2023 6:10 AM
>>>> *To:* Andreas Plesch <andreasplesch at gmail.com>; Brutzman, Donald (Don)
>>>> (CIV) <brutzman at nps.edu>; Joe D Williams <joedwil at earthlink.net>;
>>>> Peitso, Loren (CIV) <lepeitso at nps.edu>; Vincent Marchetti <
>>>> vmarchetti at kshell.com>; X3D Graphics public mailing list <
>>>> x3d-public at web3d.org>
>>>> *Subject:* Re: Mojo Playground available through a JupyterHub
>>>>
>>>>
>>>>
>>>> NPS WARNING: *external sender* verify before acting.
>>>>
>>>>
>>>>
>>>> Well, this appears harder than I thought.
>>>>
>>>>
>>>>
>>>> I haven’t gotten x3d python rendering working anywhere recently!
>>>> Python_OCC?  H3Dviewer?
>>>>
>>>>
>>>>
>>>> Is there another x3d rendering library (actually a python game engine
>>>> recommendation would probably be ok) for python (not JavaScript based)??
>>>>
>>>>
>>>>
>>>> On Mon, Jun 19, 2023 at 5:55 AM John Carlson <yottzumm at gmail.com>
>>>> wrote:
>>>>
>>>> This looks like a promising python library built on top of a native
>>>> rust GPU driver:  https://github.com/pygfx/wgpu-py/blob/main/LICENSE
>>>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpygfx%2Fwgpu-py%2Fblob%2Fmain%2FLICENSE&data=05%7C01%7Cbrutzman%40nps.edu%7C6c3a4b1466c14e2d934f08db70c6798c%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638227769999994001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MkjcY6prPMp7gWyJqwsP9c%2F6%2FScMMi3%2Bl2pf84xH0a8%3D&reserved=0>
>>>>
>>>>
>>>>
>>>> First hit in bing when you search for python webgpu!
>>>>
>>>>
>>>>
>>>> We're going to start converting JSON to wgpu-py!
>>>>
>>>>
>>>>
>>>> Have fun!
>>>>
>>>>
>>>>
>>>> John
>>>>
>>>>
>>>>
>>>> On Sun, Jun 18, 2023 at 11:14 PM John Carlson <yottzumm at gmail.com>
>>>> wrote:
>>>>
>>>> https://www.modular.com/mojo
>>>> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.modular.com%2Fmojo&data=05%7C01%7Cbrutzman%40nps.edu%7C6c3a4b1466c14e2d934f08db70c6798c%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638227769999994001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ew0csK%2F0epaSwqxTSXgrgxSD1%2F4Zvh5HiZ3Wgi93uUI%3D&reserved=0>
>>>>
>>>>
>>>>
>>>> Maybe we can get some people building native X3D graphics in Mojo?  By
>>>> same guys as LLVM.
>>>>
>>>>
>>>>
>>>> I’d love to disrupt the C/C++ community with a Python superset that
>>>> targets CPUs, GPUs, TPUs, etc. at native speeds.
>>>>
>>>>
>>>>
>>>> I know one person who does 3D python!
>>>>
>>>>
>>>>
>>>> This is not your mama’s C# or Java.
>>>>
>>>>
>>>>
>>>> John
>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230620/8586fca3/attachment-0001.html>


More information about the x3d-public mailing list