Exporting VPython objects to STL (or other 3D file formats)

378 views
Skip to first unread message

Larry Byars

unread,
Jan 23, 2019, 3:12:47 PM1/23/19
to VPython-users
Hello VPython-users,

I've been working with VPython for a few months and have successfully used it to help in the design of a partial-sphere PET scanner (positron emission tomography, not Fido). The code I wrote distributes a number of boxes placed on the surface of a sphere, all of which are pointing toward the center of the sphere. However I want to do a bit more than just "look" at the boxes. In particular, I would like to be able to export the boxes as an STL file. I have a reasonable understanding of STL format (both ascii and binary) but to generate the mesh for each box I need to know the coordinates of the corners of the boxes. So the simple question I would ask is:

How can I determine the x,y,z coordinates of the corners of a box that has undergone translation and multiple rotations?

I've also constructed the boxes using compounds made of 6 quads but I cannot discover how to access the component quads after they have been translated and rotated.


Any ideas?

Thank you for your inputs.

Larry Byars (BoomerTN)

Bruce Sherwood

unread,
Jan 23, 2019, 3:56:35 PM1/23/19
to VPython-users
This should probably be a function built into VPython, but here goes (retrieved from an earlier posting in this forum).  The function isn't perfect, as there will be a problem if up is parallel to axis.

def bounding_box(obj):
    centered = [box, sphere, ellipsoid, ring]
    x = norm(obj.axis)
    y = norm(obj.up)
    z = norm(cross(x,y))
    y = norm(cross(z,x))
    L = obj.size.x
    H = obj.size.y
    W = obj.size.z
    p = vector(obj.pos) # make a copy of obj.pos, so changes to p won't affect the object
    if type(obj) not in centered:
        p = p + 0.5*L*x # move to center
    pts = []
    for dx in [-L/2, L/2]:
        for dy in [-H/2, H/2]:
            for dz in [-W/2, W/2]:
                pts.append(p + dx*x + dy*y + dz*z)
    return pts

b = box(pos=vector(4,2,0), axis=vector(3,1,0), size=vector(8,6,4))
#b = pyramid(pos=vector(4,2,0), axis=vector(3,1,0), size=vector(8,6,4))
c = bounding_box(b)
for v in c:
    sphere(pos=v, radius=0.3, color=color.red)

Bruce Sherwood

unread,
Jan 23, 2019, 4:01:00 PM1/23/19
to VPython-users
Also, from a previous posting that asked about STL:

I was able to partially update an old (VPython 6) STL converter which is now available as a zip file (with sample STL files included) at


The section for binary files needs to be rewritten; I didn't have a binary STL file to try. If you do have a binary file, perhaps you can update that section of the converter program, based on what I did for text files.

I also ignore color, as the documentation I found about binary files indicated that it's not possible for my program to distinguish between two different color codings.

I also did not attempt to assign texpos coordinates to the vertexes, so one can't assign a texture in a meaningful way. Again, this might be something you could contribute.

Bruce Sherwood

unread,
Jan 23, 2019, 4:10:48 PM1/23/19
to VPython-users
I should comment that if working with quads you would access the list of vertex objects that is used by the quad:

v0 = vertex(pos=vec(-1.5,-1,0), normal=vec(0,0,1), color=color.cyan)
v1 = vertex(pos=vec(1.5,-1,0), normal=vec(0,0,1), color=color.cyan)
v2 = vertex(pos=vec(1,1,0), normal=vec(0,0,1), color=color.cyan)
v3 = vertex(pos=vec(-1,1,0), normal=vec(0,0,1), color=color.cyan)
q = quad(vs=[v0,v1,v2,v3])
for p in q.vs:
    print(p.pos)

Larry Byars

unread,
Jan 24, 2019, 11:07:26 AM1/24/19
to VPython-users
Hello Bruce,

Thank you for the quick and precise response concerning determining the coordinates of the corners of a box. Very helpful. I believe I can use that information to be able to export a list of boxes as an STL file. For my application that is sufficient. However it would be nice to be able to access the "internal" triangles of any object so that any object could be exported as an STL file.

Larry

John Carlson

unread,
Feb 26, 2019, 6:56:46 AM2/26/19
to VPython-users
Larry, we're interested in X3D format output from VPython. We're currently porting  X3D to python, using VPython or VPython-like APIs.  Then you could take your exported X3D XML (from the API) and convert to X3D JSON, which has STL output (not well tested for medical purposes, please test extensively) from the X3DJSONLD tool. We have a couple of converters to JSON from XML, namely X3d-Edit and X3DJSONLD.  There are also stylesheet and JS converters.

However, I do not have all of X3D implemented at this time in the STL tool.  Box and IndexedFaceSet, yes.  Others are on request

We are looking for Python programmers for the task of converting an XML unified object model to a python API similar to vpython. http://www.web3d.org/specifications/X3DUOM.html, the unified object model, will guide us.  The effort will include exporting scenegraphs to X3D XML and comparing to original XML generated from PythonSerializers (TBD, based on the API). The API and Python Serializers are currently based on PyJNIus.  We want to make it more pythonic, and encourage your participation.

If possible, we could use vpython creating renderings (we have a set of standard images to test if you do not).   Then I would add a Web rendering of vpython to my site https://coderextreme.net/X3DJSONLD/  I currently have X3DOM, X_ITE renderings of JSON and XML.    I want my site to be the swiss-army knife of X3DJSON.  Thus we would convert JSON to vpython and render it on the site.

The pythonic API would serve as the basis for an ISO standard (one implementation) we need 2 implementations for a standard, so ultimately we would have X3DOM, X_ITE, and vpython, all vying for the same developers. vpython would immediately benefit from the WebGL and JavaScript developed in X3DOM and X_ITE using XML or DOM export/import.   We might be able to do embedded scripting with python in X_ITE and X3DOM. We need developers interested in creating a 3D pythonic royalty free standards presence on the web and in 3D based browsers. No, we're not collecting fees on a per browser basis or at all, sorry.

Thus, this would be a good target for python on the web, and extend python ideas into X3D, VRML, etc.

Thanks,

John

John Carlson

unread,
Feb 26, 2019, 10:06:11 AM2/26/19
to vpytho...@googlegroups.com, X3D Graphics public mailing list

Here’s an example API that I getting close to shooting for for X3D-VPython.  Can we align something like this with vpython with possibly a few uppercase/lower case changes? I am getting feedback from another list, and then I will be posting more examples.

 

John

 

from X3Dpackage import *

X3D0 = X3D(profile="Immersive", version="3.3", Head = (head(

Meta = [(meta(name="title", content="abox.x3d")),

(meta(name="creator", content="John Carlson")),

(meta(name="generator", content="manual")),

(meta(name="identifier", content="https://coderextreme.net/X3DJSONLD/abox.x3d")),

(meta(name="description", content="a box"))])),

Scene = (Scene(Children = [

(ProtoDeclare(name="anyShape",

ProtoInterface = (ProtoInterface(Field = (field(type = field.TYPE_MFNODE, name="myShape",

accessType=field.ACCESSTYPE_INPUTOUTPUT, Child = (Shape(geometry = (Sphere()))))))),

ProtoBody = (ProtoBody(Child = (Transform(IS = (IS(Connect = (connect(nodeField="children", protoField="myShape")))))))))),

(ProtoDeclare(name="one",

ProtoInterface = (ProtoInterface(Field = (field(type = field.TYPE_MFNODE, name="myShape",

accessType=field.ACCESSTYPE_INPUTOUTPUT, Child = (Shape(geometry = (Cylinder()))))))),

ProtoBody = (ProtoBody(Child = (Transform(Child =

(ProtoInstance(name="anyShape", IS = (IS(Connect = (connect(nodeField="myShape", protoField="myShape")))))))))))),

(ProtoInstance(name="one", FieldValue = (fieldValue(name="myShape", Child = (Shape(geometry = (Box(size=[140,140,140]))))))])))))

X3D0.toFileX3D("/x3d-code/www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/data/abox.newf.x3d")

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Bruce Sherwood

unread,
Feb 26, 2019, 10:28:23 AM2/26/19
to VPython-users
I don't know what the code example is supposed to do, but seeing the words Sphere, Cylinder, and Box I'm guessing that this is equivalent to these GlowScript VPython statements:

    sphere()
    cylinder()
    box(size=vec(140,140,140)

If so, the example is extremely verbose, so you need to explain what this has to do with the kinds of tasks for which GlowScript VPython is used.

Bruce

Bruce Sherwood

unread,
Feb 26, 2019, 10:29:41 AM2/26/19
to VPython-users
Sorry for the typo; should be box(size=vec(140,140,140)). Missed a right parenthesis.

John Carlson

unread,
Feb 26, 2019, 10:49:19 AM2/26/19
to vpytho...@googlegroups.com, X3D Graphics public mailing list

Here’s another example (HelloWorld.kwargs.py). (pardon excessive meta objects, they were in the original).  This one nearly compiles.  Can some small changes allow this to compile under vpython/glowscript?   Thanks!   If there are small changes, I will proceed to adapt to the vpython/glowscript 3D API in hopes that we can standardize it (write a specification for the API).  If there are larger changes, then I will attempt to write an X3D API on top of vpython/glowscript 3D API

 

from X3Dpackage import *

X3D0 = X3D(profile="Immersive", version="3.3", Head = head(

    Meta = [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="14 April 2017", 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)

        Child = [

            WorldInfo(title="Hello world!"),

            Group(

                Child = [

                    Viewpoint(DEF="ViewUpClose", centerOfRotation=[0,-1,0], description="Hello world!", position=[0,-1,7]),

                    Transform(

                        Child = [ Shape(

                            Geometry = Sphere(),

                            Appearance = Appearance(

                                Material = Material(

                                    Texture = (ImageTexture(DEF="ImageCloudlessEarth", url=["earth-topo.png","earth-topo.jpg","earth-topo-small.gif","http://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"])),

       DEF="MaterialLightBlue",

       diffuseColor=[0.1,0.5,1]))),

                        rotation=[0,1,0,3],

                        ),

                    Transform(

                        Child = [ Shape(

                            Geometry = Text(DEF="TextMessage", string=["Hello","world!"], FontStyle = (FontStyle(justify=["MIDDLE","MIDDLE"]))),

                            Appearance = Appearance(

                                Material = Material(USE="MaterialLightBlue")))],

                        translation=[0,-2,0])])]))

X3D0.toFileX3D("/x3d-code/www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/data/HelloWorld.newf.x3d")

Bruce Sherwood

unread,
Feb 26, 2019, 11:50:56 AM2/26/19
to VPython-users
Again, this highly verbose code would seem to be approximately equivalent to the following very brief VPython code:

label(text="Hello world!", pos=vec(0,1,0)) # I put the text above the 3D earth
s = sphere(pos=vec(0,-2,0), texture=textures.earth)
s.rotate(angle=pi/4, axis=vec(0,1,0)) # not sure of the meaning of rotation=[0,1,0,3], so I give an example

Please explain what connection your project has to VPython and its goal of serving users who need not be highly expert in 3D graphics. The only connection I'm able to glimpse is that it could perhaps be used somehow for creating tools for import of sophisticated 3D models to VPython programs, and/or for export of 3D models generated by VPython programs. Neither import nor export facilities currently exist for VPython (except for the rudimentary STL example).

Bruce

Bruce Sherwood

unread,
Feb 26, 2019, 12:03:29 PM2/26/19
to VPython-users
You asked whether your "Hello world" example can be run under vpython/glowscript. There are two major flavors of VPython:

1) At glowscript.org, Python programs are compiled to JavaScript in the browser, using the RapydScript-ng transpiler. There is no access to Python packages such as X3Dpackage (but glowscript.org is great for novice programmers, among other things because no installation is required). 

2) At vpython.org are instructions for using the vpython module ("VPython 7") with installed Python, which has the advantage of enabling access to all Python modules, including X3Dpackage. These two flavors of VPython both use the GlowScript run-time library, which interfaces to WebGL in a browser. I'm guessing that importing both vpython and X3Dpackage into a single Python program would not work, if they're both trying to invoke WebGL. 

Here is an overview of the architecture of the various flavors of VPython:

    
All flavors share the same API.

Bruce

John Carlson

unread,
Feb 26, 2019, 12:21:43 PM2/26/19
to vpytho...@googlegroups.com, Don Brutzman, Vincent Marchetti

Sorry this email is complex and wide ranging.  Ask questions!. All, I found a much more manageable Python library to start on than pythonocc, blender, and the like. Bruce, Hi.  I’m attempting to create a standardized python scripting environment for the X3D/VRML family of standards.  Note that I’ve created “proto”types (as in prototypical inheritance), so actually, only the box shows up visually when the X3D is visualized. I am hoping with some small changes (such as uppercase to lowercase) and thinking about the scenegraph (X3D has groups and transforms in the scenegraph, which makes it easier to create large assemblies and animate them as a single unit or several units. Vpython appears to be more useful for massively duplicating an animation or grouping a bunch of objects into a single animation, but no easy middle ground data structure to handle all transformations. Specifically, X3D is designed to animate directed acyclic graphs of shapes and groupings (I think it may stack overflow on a cyclic graph, so if you require a cyclic graph, we will stick to the lower level nodes such as geometry). Our current focus is getting an Human-Animoid (H-Anim or HAnim) standard which you may want to adopt. H-Anim is currently a draft international standard (DIS) at V2.0.  H-Anim 1.0 is the current international standard. HAnim 2.0 contains many more detailed features about the human (or other) body.  Including skin morphing I believe. http://www.web3d.org/standards/h-anim (see HTML for HTML version).   There are several “profiles” which we may want to support in the X3D standard, or declare that the Python standard is required to implement certain “components.”  Ideally, we could create a python API fairly quickly with some examples I’ve got. I can provide the H-Anim object model or specification (data structure reference document).

 

Question.  Is vpython/glowscript the basis for Blender’s graphics?  What is Blender’s main 3D graphics API if you know it?

 

If there was a large amount of overlap between VPython API, would you like to create a core API which includes elements of both vpython and an X3D standard (geometry and appearance), then we can diverge in a separate but related python package where our goals don’t align as much (transforms and grouping, scenegraph structure, events and routes, verbosity).

 

Here is recent documentation for our Java API, X3DJSAIL, recently developed for managing conversions between graphics formats http://www.web3d.org/specifications/java/javadoc/index.html

 

I suggest looking in  these areas for compatibility similarities:

org.web3d.x3d.jsail.Geometry3D

org.web3d.x3d.jsail.Geometry2D

org.web3d.x3d.jsail.CADGeometry

org.web3d.x3d.jsail.NURBS

org.web3d.x3d.jsail.Geospatial

org.web3d.x3d.jsail.ParticleSystems

org.web3d.x3d.jsail.RigidBodyPhysics

It has been said that people pick and choose what graphics APIs they want to implement. I believe that X3D makes this possible with both wide ranging (X3DJSAIL) and narrow (H-Anim) APIs. (the H-Anim API is in the packages as well)

 

I do hope I can use your code for a rendering API, if not a transforms API. I need a rendering API to adopt, and bringing vpython into the X3D fold would likely be a big win for me in reputation—we might actually get people who program python to use X3D.

 

·         If you would like to collaborate on the scenegraph, I would suggest looking at the org.web3d.x3d.jsail.Grouping package of X3DJSAIL along with the org.web3d.x3d.jsail.X3DConcreteElement for setDEF/USE and getDEF/USE for managing the scenegraph.  Are there similar concepts in vpython?

We can provide an object model that we can develop converters for to convert the object model to an API. We have already done this with Java (and JavaScript (untested) by way of JSweet, nashorn, node, and Python via PyJNIus).   We are adding C/C#/C++.   We have 4000 test cases we run on every build.  We have many externalized formats for you to select from.

 

Why *not* collaborate?  Loss of control?   That’s a good reason. Maybe I could learn from your software development lifecycle if you would like to share that with me.

 

I suggest we start small, like with my first example showing the cube or the HelloWorld program showing an earth as an image textured sphere and a text string.  Or can we start with XML or JSON as an interface, and maintain more granular dependency between our codes.    We have a large stack of test cases, documented here:

 

http://www.web3d.org/x3d/content/examples/X3dResources.html#Examples

 

I can start converting to your API as soon as we have a good definition for the API, which will require some sessions on the phone, I believe (when are you available?). If you can put your API/data structure in to this unified object model http://www.web3d.org/specifications/X3DUOM.html (somehow we need to pick a package for your code). Don, can you create aliases in Semantic Model you are creating for the vpython object model as documented here: https://www.glowscript.org/docs/VPythonDocs/index.html LICENSE is here: https://www.glowscript.org/docs/VPythonDocs/license.txt we may have to contact the University of Manchester for use.

 

Alternatively, Don, are you preparing to use Blender as a rendering package for our test cases?  Such that a python API would be extremely useful?  If so point me at the Blender source or documentation where the graphics api is documented, thanks,

 

I think we should get X3DUOM, Blender and Vpython/GlowScript (if Bruce is in agreement) into the Semantic Model so we can manage complexity.

 

John

 

Sent from Mail for Windows 10

 

From: Bruce Sherwood
Sent: Tuesday, February 26, 2019 9:28 AM
To: VPython-users
Subject: Re: Exporting VPython objects to STL (or other 3D file formats)

 

I don't know what the code example is supposed to do, but seeing the words Sphere, Cylinder, and Box I'm guessing that this is equivalent to these GlowScript VPython statements:

--

John Carlson

unread,
Feb 26, 2019, 1:53:46 PM2/26/19
to vpytho...@googlegroups.com, Don Brutzman, Leonard Daly, Vincent Marchetti

I’d like to export our examples to your vpython API (or a layer on top of your API) and hopefully pass much of the X3D test suite. Thus, your API or the layer on top would become part of ISO International Standard (we can discuss this. I think it’s a matter of treating functions as constructors in vpython and returning graphics objects from the constructors.   At a minimum, I will be creating examples to go into the international standard (I need a rendering library to support the python API, to show the standard is feasible in python, vpython seems about the right size for me to port examples to without stepping on too many toes).  Don is a member of a working group developing a semantic model for 3D graphics, and it would be very good to get a near immediate mode graphics API into the semantic model, don’t you think?

 

Are either of you interesting in Processing (the graphics language).

 

Your API is fine, Bruce, if you don’t have to look up meanings for pos, vec in a dictionary. X3D is an international standard with LOADS of documentation.  Yes, you can use vpython for very small projects, but what if next you want to create an authoring or blender-like program with your API?   You have a very small API that could grow if given a little watering.   If you haven’t seen D3.js I encourage you to look at it’s structure for creating graphics from data.  The loops stay out of data and buried in code where they belong. Does python have generators? Take a gander at those.

 

What you have is an immediate mode graphics API similar to OpenGL, WebGL or a thin structured layer on top of an immediate mode API.  We are trying to create a structured mode graphics API similar to OpenInventor, VRML, PHIGS.  Structured mode graphics APIs are built on top of immediate mode graphics APIs. Do you want us to build a structured model graphics API on top of vpython? I believe that vpython can stay pretty much as is, except for textures.   We need to discuss this, but probably there are people who have architected X3D can better say why the texture belongs way down under appearance and material.

 

“Cleaning” up my code, I get this code which might appear as compatible with both vpython and X3D, we will just need to add X3D, meta, Scene, Group, Transform, Sphere, Appearance, Material (probably all these can be stubbed out in vpython, somehow). We would have to figure out where the best place to put the texture in the code is, in a separate object (which would support multiple URLs for various deployment scenarios), or as an attribute.  What’s the best way of potential sharing a texture between spheres and other shapes?

 

And we won’t be writing much python anyway if the API is designed right.   We’ll be generating it from XML, JSON, or application code or similar.

 

X3D0 = X3D(profile="Vpython", version="3.3", Head = head(

    Meta = [meta(content="HelloWorld.vpy", name="title")]

    ),

    Scene = Scene(

        Child = [

            Group(

                Child = [

                    Transform(

                        Child = [ Shape(

                            Geometry = Sphere(),

                            Appearance = Appearance(

                                Material = Material(

                                    Texture = ImageTexture(["textures_earth.gif"]))))],

                        rotation=[0,1,0,3],

                        ),

                    Transform(

                        Child = [ Shape(

                            Geometry = Text(string=["Hello","world!"]))),

                        translation=[0,-2,0])])]))

X3D0.toFileX3D("/x3d-code/www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/data/HelloWorld.newf.x3d")

 

If I write a serializer for vpython, I will need to convert a lot of classes over (lots of mappings).  It might be reasonable to create a small API just for this proof-of-concept and not to go into any production code or standard.

 

Don, Leonard, How about we design something like a Scene object or Group Object which takes a list of Shapes with transforms applied in HTML5 (yay, HTML5 attributes).   It’s reasonable to support HTML5 in V4.   Or can I do it with a proto (which I would have to implement in python.  Ugh!). We will be limiting the python API to V4 environments, but will that be a bad thing?  Can XSeen support Bruce’s verbosity requirements?

 

Thus my minimally supported somewhat verbose code for HelloWorld.vpy becomes:

 

X3D0 = X3D(profile="Vpython", version="4.0",

        children = [

Sphere(Texture = ImageTexture(["textures_earth.gif"]), rotation=[0,1,0,3]),

               Text(string=["Hello","world!"], translation=[0,-2,0], color=color.BLUE),

        ]

)

X3D0.postXML("https://www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/data/HelloWorld.newf.x3d")

# .postJSON, .postEXI, etc.


Would this be acceptable in a Python API for X3D V 4 (or beyond)?

 

 

Are we reaching consensus yet? I definitely think that nested Transforms should be supported in vpython. How does vpython support nested Transforms?  Can you support a keyword arg “children” that is an array/list  that we can put transforms and shapes in? Would you like me to propose a syntax for our example? Or would you prefer to provide an example or two with our “newly supported” “children” kw? Note that children can be shared between parents, so that satisifies DEF/USE in X3D.

 

Is this good API design?

 

Quaternions would likely be specified with a quaternion attribute.  Rotations would be from the Transform node in X3D. Quaternions are preferred I believe http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/group.html#Transform

 

VPython is of note because they’ve got a version of python that is converted to JavaScript on the web. That’s why it’s an important. If it’s used from applications like Jupyter etc. it needs to be succinct enough for mere humans to understand.  So we will be creating a “less powerful” X3D for the web with the python version.

 

Thanks,

 

John

Sent from Mail for Windows 10

 

From: Bruce Sherwood
Sent: Tuesday, February 26, 2019 10:50 AM
To: VPython-users
Subject: Re: Exporting VPython objects to STL (or other 3D file formats)

 

Again, this highly verbose code would seem to be approximately equivalent to the following very brief VPython code:

--

John Carlson

unread,
Feb 26, 2019, 1:58:31 PM2/26/19
to vpytho...@googlegroups.com

May I forward the PDF to Don Brutzman and Vince Marchetti?  Thanks,

 

John

 

Sent from Mail for Windows 10

 

From: Bruce Sherwood
Sent: Tuesday, February 26, 2019 11:03 AM
To: VPython-users
Subject: Re: Exporting VPython objects to STL (or other 3D file formats)

 

You asked whether your "Hello world" example can be run under vpython/glowscript. There are two major flavors of VPython:

--

Bruce Sherwood

unread,
Feb 26, 2019, 5:45:17 PM2/26/19
to VPython-users
The GlowScript license is at https://github.com/BruceSherwood/glowscript/blob/master/LICENSE.txt, and it is very non-restrictive. Thanks for the link to a very old license for VPython 6, which I'll remove, as it is way out of date.

Bruce

Bruce Sherwood

unread,
Feb 26, 2019, 5:52:20 PM2/26/19
to VPython-users
That license has been updated. You can also see it at the GitHub repository.

Bruce

John Carlson

unread,
Feb 26, 2019, 10:40:12 PM2/26/19
to vpytho...@googlegroups.com, Don Brutzman, Vincent Marchetti, Leonard Daly, Jeffry Hysong

Here are more examples of where Web3D’s Python X3D API (PyX3D) going, based on your input. Jeffry, time to look at the python in the attached zip and comment on the API (it doesn’t run yet, we’re creating a standard (read design document) for the API first, not the implementation. Jeffry, is there an extension to PyOpenGL to do PyWebGL? Please work with Leonard if he agrees to pick the “best” PyWebGL solution. All: discuss whether API is dependent on X3D V4 or not.  I don’t think it should be based on competing platforms.  PyX3D should be able to use ALL python 3D graphics APIs I believe.  Whether I can do that as a newbie python programmer is questionable.

 

Thanks.

 

  1. Started using the compound([]) def.   Couldn’t get it to work right with Group or Transform yet.  Discuss use of Transform versus “children” below. Suggest deprecating compound().
  2. Still have a lot of “extra” def’s that haven’t been mapped to compound yet.  Plan to use HTML5 attributes and continue to flatten X3D hierarchy, but may not be needed with “children” keyword. Examples need to be looked at for “children” keyword possibilities. Right now, it looks like we can inline a bunch of stuff
  3. Need to revisit DEF/USE to create extra parent links in scene group (or use “children” or variables)

Attached.  Not nicely formatted (sorry).  Probably not legal python yet.

 

Latest API examples uses kwargs in Python for  handing non-positional parameters. New API not generated yet. Need to look at standards for using kwargs.

 

We need to discuss use of transform attributes within X3DShape instances, perhaps.    Seems more natural for expert 3D graphics API users to want separated (not multiplied transforms, but multiplication could be added by API when rendering, instead of when building.  Seems a fundamental approach difference that may not be handled. Don, Vince, Jeffry, ideas?

 

There seems to be a use case for using functions in declarative code, “declarative functional”, although that’s not apparent.  Perhaps we could spend some time converting vpython’s code over to declarative code with his approval of examples chosen, and the physics tags, and presenting it back to Bruce for acceptance into vpython.  Why don’t people buy into a heavy weight framework (when heavy weight means verbose and directed acyclic graph), but then use a translator to convert python to JavaScript to just to get web? Is JavaScript this wonderfully secure thing that will never get repeated in the history of the web?  Or is python the anti-web? I think they better cut that slogan pretty fast now. It looks like JavaScript and Web Assembly are becoming target architectures for python.


I know of PBR (physics based rendering) which may be of interest to Bruce as a physicist. What could we offer Bruce as a physicist to work on enhancing his API with optional features for the support of X3D? I know there’s a lot of Physics components in X3D.  Can we show them off in python with Bruce’s help?

 

Perhaps we should set our requirements for the Python API?

  1. WebGL/OpenGL (possibly implemented in JavaScript)
  2. Do not use JavaScript’s eval().  I don’t know about python’s yet.
  3. Web-based
  4. Python 3.X
  5. Jupyter notebooks
  6. 3D objects (from which profiles?)
  7. Declarative, Hierarchical Transforms
  8. Animation of scenegraph within API, Create, Read, Update, Delete nodes
  9. Metadata

 

The only thing that seems  to be missing on the surface from vpython is declarative, hierarchical transforms, and possibly metadata.

 

I have yet to look at the previously mentioned pythonocc.

http://www.pythonocc.org/

 

Which uses X3DOM. I don’t really want to write another python to JavaScript converter (lets grab one).

There appear to be plenty out there for the web.  Best of breed solutions accepted, along with X3D requirements met.  What are our requirements for a python to JavaScript converter?  Do we need to support such a beast to get Jupyter?    Can you see my ECMAScript colors flying? Should we create a task for analyzing all the “python to javascript converters”? Leonard, can you do this under the auspices of XSeen, or is it “too slow” “not enterprise acceptable” “not standardizable”?

 

From what I’ve seen so far, these tools use JavaScript eval() and not new Function() for getting JavaScript code into the browser.  That would be one requirement. Do not use eval().

 

Don, can you add the requirements to the web3d wiki yet?

 

Next step: Finalize Python API.  Finish analysis of existing 3D APIs, including Panda3D we need a feature comparison comparing all Python 3D APIs.  Get feedback from Bruce (thanks for your previous input. Noted), Jeffry and Leonard. Leonard, do you want to be included in standardizing this Python API for XSeen?  Can we formalize an Python standard for both X3D and XSeen (and other APIs, including PyJNIus X3DJSAIL)?  Going along the lines that everything is going to be included in the Semantic Models anyway? Do we need to include versions in the Semantic Models?

 

Whither PyOpenInventor?

 

Will PyX3D become become the future of X3D? Even with this JavaScript bulge attached to it?

Progress:

 

  1. Have Kwargs version of PythonSerializer.
  2. Have one version back API generator, need to update per vpython API.

 

John

Sent from Mail for Windows 10

 

From: Bruce Sherwood
Sent: Tuesday, February 26, 2019 10:50 AM
To: VPython-users
Subject: Re: Exporting VPython objects to STL (or other 3D file formats)

 

Again, this highly verbose code would seem to be approximately equivalent to the following very brief VPython code:

--

examples.zip
Reply all
Reply to author
Forward
0 new messages