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.
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")
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:
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
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:
--
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:
--
May I forward the PDF to Don Brutzman and Vince Marchetti? Thanks,
John
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:
--
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.
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?
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.
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:
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:
--