BruceSherwood / glowscript

This repository has been moved to https://github.com/vpython/glowscript
50 stars 17 forks source link

ISO standard graphics API for python. Possible examples #201

Closed coderextreme closed 5 years ago

coderextreme commented 5 years ago

I am working on an ISO standards graphics API for python. I have just discovered glowscript. Here are some examples:

unnested form:

from X3Dpackage import *
X3D0 =  X3D()
X3D0.setProfile("Immersive")
X3D0.setVersion("3.3")

head1 = head()

meta2 = meta()
meta2.setName("title")
meta2.setContent("abox.x3d")

head1.addMeta(meta2)
meta3 = meta()
meta3.setName("creator")
meta3.setContent("John Carlson")

head1.addMeta(meta3)
meta4 = meta()
meta4.setName("generator")
meta4.setContent("manual")

head1.addMeta(meta4)
meta5 = meta()
meta5.setName("identifier")
meta5.setContent("https://coderextreme.net/X3DJSONLD/abox.x3d")

head1.addMeta(meta5)
meta6 = meta()
meta6.setName("description")
meta6.setContent("a box")

head1.addMeta(meta6)
X3D0.setHead(head1)
Scene7 = Scene()

ProtoDeclare8 = ProtoDeclare()
ProtoDeclare8.setName("anyShape")

ProtoInterface9 = ProtoInterface()

field10 = field()
field10.setType(field.TYPE_MFNODE)
field10.setName("myShape")
field10.setAccessType(field.ACCESSTYPE_INPUTOUTPUT)

Shape11 = Shape()

Sphere12 = Sphere()

Shape11.setGeometry(Sphere12)
field10.addChild(Shape11)
ProtoInterface9.addField(field10)
ProtoDeclare8.setProtoInterface(ProtoInterface9)
ProtoBody13 = ProtoBody()

Transform14 = Transform()

IS15 = IS()

connect16 = connect()
connect16.setNodeField("children")
connect16.setProtoField("myShape")

IS15.addConnect(connect16)
Transform14.setIS(IS15)
ProtoBody13.addChild(Transform14)
ProtoDeclare8.setProtoBody(ProtoBody13)
Scene7.addChild(ProtoDeclare8)
ProtoDeclare17 = ProtoDeclare()
ProtoDeclare17.setName("one")

ProtoInterface18 = ProtoInterface()

field19 = field()
field19.setType(field.TYPE_MFNODE)
field19.setName("myShape")
field19.setAccessType(field.ACCESSTYPE_INPUTOUTPUT)

Shape20 = Shape()

Cylinder21 = Cylinder()

Shape20.setGeometry(Cylinder21)
field19.addChild(Shape20)
ProtoInterface18.addField(field19)
ProtoDeclare17.setProtoInterface(ProtoInterface18)
ProtoBody22 = ProtoBody()

Transform23 = Transform()

ProtoInstance24 = ProtoInstance()
ProtoInstance24.setName("anyShape")

IS25 = IS()

connect26 = connect()
connect26.setNodeField("myShape")
connect26.setProtoField("myShape")

IS25.addConnect(connect26)
ProtoInstance24.setIS(IS25)
Transform23.addChild(ProtoInstance24)
ProtoBody22.addChild(Transform23)
ProtoDeclare17.setProtoBody(ProtoBody22)
Scene7.addChild(ProtoDeclare17)
ProtoInstance27 = ProtoInstance()
ProtoInstance27.setName("one")

fieldValue28 = fieldValue()
fieldValue28.setName("myShape")

Shape29 = Shape()

Box30 = Box()
Box30.setSize([140,140,140])

Shape29.setGeometry(Box30)
fieldValue28.addChild(Shape29)
ProtoInstance27.addFieldValue(fieldValue28)
Scene7.addChild(ProtoInstance27)
X3D0.setScene(Scene7)

X3D0.toFileX3D("/x3d-code/www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/data/abox.new.x3d")
coderextreme commented 5 years ago

nested form:

from X3Dpackage import *
X3D0 = X3D() \
   .setProfile("Immersive") \
   .setVersion("3.3") \
   .setHead(head() \
    .addMeta(meta() \
     .setName("title") \
     .setContent("abox.x3d") \
    ) \
    .addMeta(meta() \
     .setName("creator") \
     .setContent("John Carlson") \
    ) \
    .addMeta(meta() \
     .setName("generator") \
     .setContent("manual") \
    ) \
    .addMeta(meta() \
     .setName("identifier") \
     .setContent("https://coderextreme.net/X3DJSONLD/abox.x3d") \
    ) \
    .addMeta(meta() \
     .setName("description") \
     .setContent("a box") \
    ) \
   ) \
   .setScene(Scene() \
    .addChild(ProtoDeclare() \
     .setName("anyShape") \
     .setProtoInterface(ProtoInterface() \
      .addField(field() \
       .setType(field.TYPE_MFNODE) \
       .setName("myShape") \
       .setAccessType(field.ACCESSTYPE_INPUTOUTPUT) \
       .addChild(Shape() \
        .setGeometry(Sphere() \
        ) \
       ) \
      ) \
     ) \
     .setProtoBody(ProtoBody() \
      .addChild(Transform() \
       .setIS(IS() \
        .addConnect(connect() \
         .setNodeField("children") \
         .setProtoField("myShape") \
        ) \
       ) \
      ) \
     ) \
    ) \
    .addChild(ProtoDeclare() \
     .setName("one") \
     .setProtoInterface(ProtoInterface() \
      .addField(field() \
       .setType(field.TYPE_MFNODE) \
       .setName("myShape") \
       .setAccessType(field.ACCESSTYPE_INPUTOUTPUT) \
       .addChild(Shape() \
        .setGeometry(Cylinder() \
        ) \
       ) \
      ) \
     ) \
     .setProtoBody(ProtoBody() \
      .addChild(Transform() \
       .addChild(ProtoInstance() \
        .setName("anyShape") \
        .setIS(IS() \
         .addConnect(connect() \
          .setNodeField("myShape") \
          .setProtoField("myShape") \
         ) \
        ) \
       ) \
      ) \
     ) \
    ) \
    .addChild(ProtoInstance() \
     .setName("one") \
     .addFieldValue(fieldValue() \
      .setName("myShape") \
      .addChild(Shape() \
       .setGeometry(Box() \
        .setSize([140,140,140]) \
       ) \
      ) \
     ) \
    ) \
   ) \

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

I have the opportunity to make the 3D API more like glowscript/vpython. I suggest we collaborate. I can be right near the start of my API creation, which can make it a lot like glowscript (so you can leverage X3DOM and X_ITE on the web, or other X3D browsers in a glowscript fashion as the python API is rolled out to various browsers), or I can leverage pyjnius to create something like the above (which works for the "flat" mode, but not for the "nested" mode, and currently is rendered at XML). I have a "unified object model" here (I hope this is understandable), which I use to create the API: http://www.web3d.org/specifications/X3DUOM.html If you could create a Python API from this, with my help, I think we could be along the path to a ISO "standards compliant" 3D visual system for python. Here is the current state of my API generator: https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/java/src/python/pythonapi/packagemaker.py I can well proceed with the task as newbie graphics and python programmer. If you collaborate, your code will need to be a member of the Web3D consortium. Carefully read the IPR rules. http://www.web3d.org/join

You could also take the unified object model and go play in your own corner provide X3D back-end support to your API. However, I suggest that leveraging X3DOM, X_ITE and other X3D browsers may be in your users best interest. See well documented Java API here: http://www.web3d.org/specifications/java/javadoc/index.html Essentially we will be providing a "middle" road. We won't be using a dict to specify the whole scenegraph (we already have a JSON version practically ready for the presses, so a python dict wouldn't be hard), possibly making interactivity and animation hard (but X3D is pretty good at this), and we won't be buying into the crappy Java POJO verbose syntax.

I'd like to provide this to the community at Web3D 2019. Thanks. We can also discuss converting Proto code to glowscript.

BruceSherwood commented 5 years ago

Knowing nothing about X3d, I don't understand your intent in posting your examples; I have no way of understanding the significance of that code. I did look at web3d.org and can see that X3d could be a useful tool for someone to build tools to import 3D models to a GlowScript program, or to export a 3D model from GlowScript. However, GlowScript itself is aimed not at the expert programmers who use X3d but rather at people who may not be expert programmers, or not expert in computer graphics, who are enabled by GlowScript to write programs in Python (or JavaScript, a much less used option) that generate navigable real-time 3D animations as a side effect of calculations. Given the huge difference in expertise of users of GlowScript and users of X3d, I don't see any useful connections between these two worlds other than import and export, though of course this may simply be ignorance on my part.

coderextreme commented 5 years ago

Brian, start at paragraph 2.

We should be able to plot a course with the X3D Python API, given the support of HTML5 attributes for hanging various attributes off DOM. I’d like to something much more along the lines of something very pythonic than very verbose, and I think the python community will agree (or go to Blender, or Panda3D for their 3D graphics). The thing about getting something to ISO standardization, is you have to hope through hoops. You have to include everyone’s favorite widget from the previous standard, or branch out on your own. These take years to develop. But I just need some good examples at this point, written in python. I am suggesting using one of my PythonSerializers (I have 3 now) which take JSON/XML and produce to develop a new Python serializer which will generate vpython code. The thing is, it’s X3DJSON and X3DXML and we don’t have vypythonJSON and vypythonXML to make the translation between object models smooth. So how do we provide a smooth API conversion between my application code and your service code? I don’t really know the answer to this question perfectly, and I’m imagining you or your team could just blurt out the solution. XSLT? We can do it. We have a super-duper expert XSLT programmer. He wrote the code that converts from our unified object model to our Java API. How else besides XSLT? Frankly, something like MAPFORCE comes to mind https://www.altova.com/mapforce (output is XSLT 1.0 and XSLT 2.0) DANG! Not XML again. I want python! Meanwhile my mind oogles over: https://stackoverflow.com/questions/1618038/xslt-equivalent-for-json.

Here’s what we want. 1) implement the X3D Unified Object Model in X3D Semantic Model. 2) implement VPython in the X3D Semantic Model. Develop or get a Semantic Model Transformation mapping library and specification. Develop a map using the mapping library and to map between 1 and 2 (and back hopefully). Develop a map using the previously generated to map between instances of 1 and 2. Arg! The brain muscles are pulsating. I think that’s it, but it will take 2 MIT graduates 3 years to develop. It’s quicker to write a programming language. Thus: We create a core interpreter and domain specific classes for translation, Then we get an MIT intern to write the translation between instances of 1 and instances of 2. One Google SOC, and deathly boring for student. Arg. Use mechanical turk to convert small snippets of instance of 1 to instance of 2. Build up a larger and larger library. Use deep learning to create an AI to do the translation. Arg. We already have the instances. Let’s convert the instances using standard techniques (serializers, XSLT, XML, JSON) and feed into deep/meta/optimized learning http://people.idsia.ch/~juergen/ AI to create converter. Bingo, BIG WIN! So we don’t really need semantic for anything. We just need examples, dang good examples.

Brian, was this your vision for the universal translator (paragraph 2)? Pretty good vision, and very hard to articulate. Implementation is left to MIT grads (We’ll pay them a nice stipend to keep quiet).

It would be good to provide both low-level and high-level APIs. There’s a certain point of complexity where things start getting simpler (see d3.js) that I’d like to hit with 3D graphics visualizations. Does glowscript include d3.js? Also, we need not duplicate python at all, since you already do that with Rapyd.

In other words, there are very few python programmers using X3D from an API (H3d?) I think, probably most of them are using Python export to-> X3DOM or X_ITE. You may want to port your glowscript to X3DOM or X_ITE, if you don’t like low-level code (but physicists like atoms). I’m not sure why programmers refuse to use someone else’s low-level code. I want to use your code Bruce, and get others to use rely on it. But I am an application programmer, I want to include python for X3DOM, python for X_ITE and python for vpython. How do I do it? How do I turn a python encoded H-Anim model into WebGL? That’s why I’m asking you to step away from the atoms for a bit and see the molecules, DNA, cells, organs, body of a H-Anim python model displayed in 3 different software systems. Imagine developing a model of a human being in glow script or vpython as it now stands. You would have to write a shit ton of code write. Well X3DOM and X_ITE have already written that shit ton of JavaScript code. And you’re on the right course for it too, if you implement these classes: http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/HAnim/package-summary.html

I would like to put your vpython/glowscript toolkit front and center for python development of HAnim, use the WebGL you’ve developed for animating human models. So biologists can use Jupyter notebook and the rest of python for showing human models. To improve science about the human body.

Thus we are trying to X3D develop examples in your vpython API that are similar to other encodings we already have to provide a way to map between APIs and encoding. We sell everything to google translate for big bucks, and retire from coding, so we just have to run the server that provides between any format, encoding, language, API, UI, DUI, GUI known to man and MapForce and all the other tools and programmers are put out of business. End of computing as we know it.

Now, how do get get dang good examples as mentioned above? Mechanical Turk? Train hordes of X3D programmers? No. We take the X3DBigBang tool and start it off on a tabla rasa. It should generate one test case example based on the X3D Schema or Unified Object Model (X3DUOM). Then we run Code Coverage on the test cases and get the remaining 0% covered nodes and fields. We pick a 0% node or field that is either a leaf of the X3D Schema or X3DUOM and work inward, or start moving outward from the root of the X3D or JSON schema and create a new test case. We keep on using X3DBigBang in a generator fashion of the X3D resource examples until all nodes and fields are at > 0% coverage and we have thousands of autogenerated examples from our various convererters and serializers of the test cases. Then we give all our examples to Google Translate in the cloud. We keep X3DBigBang, selling it to Web3D members only.

I want to develop X3DBigBang, the organic generator.

There are only so many formats. There are infinite numbers of examples of those formats. It’s better to be in the example generating business than the format generating business. We’re only in the format generating business as long as it can create good examples. I am fairly sure X3DBigBang can do it.

X3DBigBang is patentable I believe. Does anyone else want to hear the key development behind X3DBigBang? I didn’t get much interest from X3D. On to the next party who will support my business. Dang, I despise being a marketer.

Alex, Chandu, here’s how we make our first million, selling dang good examples to neural network developers. The second million will be selling their neural networks back to them. Then you can start tackling google if they haven’t bought you out. Study ONNX closely and learn how to extend it for marketing purposes.

John “Shopping Theories is my Business. I’m a mathematician” Carlson

BruceSherwood commented 5 years ago

John, I have no idea what you are talking about, as I know nothing about the kinds of tools and examples that interest you. The only benefit I can see for the GlowScript community from the X3D community is that someone might use X3D tools to create convenient mechanisms for importing 3D models into a VPython program, and/or to export from a VPython program a 3D model that was created using VPython. I do not see any value in trying to make some kind of hybrid of VPython and X3D, nor do I see a basis for collaboration; our interests and the interests of the communities we serve are just way too different. You are of course welcome to use any of the GlowScript code base, as it is open source with a very permissive license (not the old one you came across, which has been updated).

coderextreme commented 5 years ago

We want to use your API on different backends (replace WebGL with a JavaScript library that itself uses WebGL—we have a couple of these, X3DOM and X_ITE). Or we want to write vpython script inside a script node in an HTML page (with routes), as a choice of scripting language. Currently our only viable embedded scripting language is VRML. JavaScript must be used “externally.” Basically, we want to provide a Python API to our customers. That’s it. We can do import/export too, but we want an authoring API (here’s where you may lack) where you can edit the scenegraph.

John

Sent from Mail for Windows 10

From: BruceSherwood Sent: Tuesday, February 26, 2019 4:56 PM To: BruceSherwood/glowscript Cc: John Carlson; Author Subject: Re: [BruceSherwood/glowscript] ISO standard graphics API for python.Possible examples (#201)

John, I have no idea what you are talking about, as I know nothing about the kinds of tools and examples that interest you. The only benefit I can see for the GlowScript community from the X3D community is that someone might use X3D tools to create convenient mechanisms for importing 3D models into a VPython program, and/or to export from a VPython program a 3D model that was created using VPython. I do not see any value in trying to make some kind of hybrid of VPython and X3D, nor do I see a basis for collaboration; our interests and the interests of the communities we serve are just way too different. You are of course welcome to use any of the GlowScript code base, as it is open source with a very permissive license (not the old one you came across, which has been updated). — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

coderextreme commented 5 years ago

I’m actually just looking to create a lookalike or common API for both vpython and X3D development, so that vpython and X3D programs at least look similar, so users of vpython (or python) can come up to speed quickly on X3D scripting in an X3D browser like FreeWRL or Castle Game Engine or the other ones I mentioned. Just like you were struck by the amazing verbosity, our python users would have been amazed too. That’s it. If you want to play in your own court, that’s okay too. Import/Export has a different purpose, namely, static graphics. We’re talking about transforming the scenegraph here, I think. If your goal isn’t transforming the scenegraph by use of an API, then I’m in the wrong court. I think I could probably use your WebGL and Rapyd-ng tools, if I want to run inside a web browser. The point is with you help we could extend your python scripting to FreeWRL, Castle Game Engine, and other environments that python programmers may want to use for declarative 3D graphics. This is an ISO standard, with many implemented browsers, languages, formats and encodings. It’s a chance to say how 3D python API’s will be created in the future on a variety of platforms—so if you ever want to use a different 3D API in Python, you will find a comfy landing spot.

Plus I do not have a WebGL or any rendering background for Python yet. Was hoping for leg up.

As you can see, we modified the API from a very clunky Java-like API to a pythonic one in a couple of iterations, thanks for your help.

I will try to keep your “low verbosity” ideas. I at least need to add compound() to my Python serializer. We will probably maintain our vocabulary, as that’s our main IP.

Normally, X3D – the scenegraph “wraps” the scripting language, instead of vica versa. We try to do both.

Here’s the examples, maybe I missed a paste: http://www.web3d.org/x3d/content/examples/X3dResources.html#Examples

Thanks,

John

Sent from Mail for Windows 10

From: BruceSherwood Sent: Tuesday, February 26, 2019 4:56 PM To: BruceSherwood/glowscript Cc: John Carlson; Author Subject: Re: [BruceSherwood/glowscript] ISO standard graphics API for python.Possible examples (#201)

John, I have no idea what you are talking about, as I know nothing about the kinds of tools and examples that interest you. The only benefit I can see for the GlowScript community from the X3D community is that someone might use X3D tools to create convenient mechanisms for importing 3D models into a VPython program, and/or to export from a VPython program a 3D model that was created using VPython. I do not see any value in trying to make some kind of hybrid of VPython and X3D, nor do I see a basis for collaboration; our interests and the interests of the communities we serve are just way too different. You are of course welcome to use any of the GlowScript code base, as it is open source with a very permissive license (not the old one you came across, which has been updated). — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

coderextreme commented 5 years ago

I can take the HelloWorld example (the last one I created that was much less verbose) and use it to create a new serializer that I can export many more examples to in a matter of minutes to an API similar to yours, I am fairly sure (but the verbose meta will still be there, I need to maintain roundtrip back to the XML encoding. Please give me a chance. Don’t judge a book by its cover. I’ve been doing more emailing than coding and code speaks words.

John

Sent from Mail for Windows 10

From: BruceSherwood Sent: Tuesday, February 26, 2019 9:03 AM To: BruceSherwood/glowscript Cc: John Carlson; Author Subject: Re: [BruceSherwood/glowscript] ISO standard graphics API for python.Possible examples (#201)

Knowing nothing about X3d, I don't understand your intent in posting your examples; I have no way of understanding the significance of that code. I did look at web3d.org and can see that X3d could be a useful tool for someone to build tools to import 3D models to a GlowScript program, or to export a 3D model from GlowScript. However, GlowScript itself is aimed not at the expert programmers who use X3d but rather at people who may not be expert programmers, or not expert in computer graphics, who are enabled by GlowScript to write programs in Python (or JavaScript, a much less used option) that generate navigable real-time 3D animations as a side effect of calculations. Given the huge difference in expertise of users of GlowScript and users of X3d, I don't see any useful connections between these two worlds other than import and export, though of course this may simply be ignorance on my part. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

BruceSherwood commented 5 years ago

John, please stop posting to the VPython web sites; it's a distraction. I still have no idea what you're talking about, nor is it clear that there's any useful connection with GlowScript. You seem to have glimpsed some utility, as I think you mentioned that you don't have a WebGL engine. If you do see some use for the GlowScript library in your own work, here is where to seek information about that library:

1) At glowscript.org, click Help for detailed documentation of the API, including videos and tutorials on how to write VPython programs.

2) At glowscript.org, click Example programs to run and view a variety of VPython programs.

3) Write some small VPython programs yourself, either at glowscript.org or by installing Python and the vpython module (see vpython.org).

4) In this GitHub repository (github.com/BruceSherwood/glowscript), in the docs directory, the file "GlowScriptOverview.txt" describes in some detail the architecture of GlowScript.

5) I believe you've already seen vpython.org/contents/VPythonArchitecture.pdf

There is a precedent for people using the GlowScript library for their own purposes. The group developing the very interesting site trinket.io uses the library in an innovative way that places on a web page, surrounded by text and figures, side-by-side edit and run windows for VPython code. At trinket.io one can create a GlowScript "trinket", then choose whether to use their Blocks version or the Python version.

If you do develop some interesting use of the GlowScript library in your own work, I would be pleased to see it, but not until and unless you have something concrete to show.

I've closed this issue.

Bruce

coderextreme commented 5 years ago

➢ I've closed this issue. Hi Bruce,

If you want inspiration for vpython, go here: http://worrydream.com/#!/DrawingDynamicVisualizationsTalk

John