[x3d-public] Report on X3DJSONLD, X3DJSAIL conversion work. PLYSTL <-> JSON conversions. Future plans. Program -> DOM

Leonard Daly Leonard.Daly at realism.com
Thu May 2 08:36:26 PDT 2019


John,

I was wondering how you converted X3D to DOM (X3D can be expressed in 
JSON as you and Don have been working on for a few years).

There are two issues. I can't follow your discussion below so this may 
be answered (in a manner that I do not understand). Can you provide 
simple answers for each of these points?

 1. DOM is not a file format, but an API. X3D (in JSON or XML) is a file
    format. How do you handle conversion of a file format to an API? Is
    the result something that populates the DOM tree? Is it something
    else? Note that XML -> DOM is a well-defined conversion (and
    built-in to web browsers) that populates the DOM tree with the data
    from the XML document. DOM contains data, structure, and methods
    that are not present in the XML document; but are part of the
    standard DOM and DOM-tree definition.

 2. DOM very explicitly does not allow multi-parents. I think I
    understand your statements that when converting from a multi-parent
    structure to one that only allows single parent, you create a copy
    of the original. This resolves the multi-parent issue into one that
    may break run-time. As I understand your description: if A & B are
    parents of node-subtrees and X is DEFed in the A tree and USEd in
    the B tree; then the A and B trees have distinct copies of X (called
    X and X'). Do you add mechanisms so that runtime changes to X also
    change X'?


Unreal (and perhaps Unity) get around this issue (node reuse in a 
single-parent environment) by making X a class and having each USE of X 
to be a new instance of that class. Changes to the X class are 
propagated to all instances. Each instance may define instance-specific 
methods/data that override those from the inherited class. It is also 
possible to sub-class X' and add in instance-specific methods/data.


Leonard Daly



> Jeff, stop work, I think the X3D Program -> DOM problem is solved with 
> Jupyter notebook. We just need to write or find a kernel for Jupyter 
> notebook. Kernels are found here: 
> https://github.com/jupyter/jupyter/wiki/Jupyter-kernels Jupyter is 
> very cool.  Alexander, can you install a JavaScript and Java kernels 
> in our Jupyter, along with the Python? Sheesh, I am behind the times.
>
> Leonard if that doesn’t satisfy you, I think you were focused on 
> following:
>
> To handle multi-parenting in languages that don’t support 
> multi-parenting, I will use DEF/USE as an 
> attribute/property/field/slot, or duplicate that portion of the tree.  
> I believe I am conforming to how X3D XML is handled. For languages 
> that have multi-parents, I should be handling that, and generating 
> multi-parents and multiple variables (sigh).
>
> For example, in  JSON -> STL, that would be an issue.
>
>
> I believe for JSON -> STL,  I search backwards through previously 
> processed nodes, looking for DEFs, and keep a transform stack, so I 
> generate unique data for each DEF/USE in a different transform.  I 
> forget the details.  You’re welcome to look at the code:
>
> https://github.com/coderextreme/X3DJSONLD/src/main/node/convertJsonToStl.js
>
> It would likely be possible to do multi-parenting based on using 
> something like what JSON -> STL does, looking up DEFs.  That would 
> mess up my and Don’s pretty indented trees though!  I have solved a 
> similar before by separating out ProtoInstance(just one tag) into 
> separate variables (in my Java serializer, I think).
>
> If you have some suggestions for changing my serializers to use more 
> than one variable (some already do use more than one variable, and 
> they can be changed, I would welcome that.  That is, I would do, 
> .addChild(variable) instead of .addChild(constructor().setUSE(…), In 
> many cases, it would just be  matter of finding or keeping track of 
> the DEFs, then inserting the variable associate with that DEF into the 
> children list. TODO.
>
> Thanks for the attention. I have not been trying to solve the 
> scenegraph issue in DOM. It’s very possible to solve it with 
> JavaScript, Java and Python (not DOM, XML, EXI, PLY, STL or JSON) by 
> using a DEF value to variable map.  Did I answer your question?  I 
> think your question had more to do with translating to DOM. I believe 
> I would have variable names or DEFs from the source syntax to use for 
> DEFs.  Note that I don’t translate from JavaScript, Java or Python yet 
> to DOM (and probably won’t), I use the X3DJSAIL API for those 
> languages, which translates to XML first.
>
> *Don, might the same issue Leonard brings up be in the stylesheet 
> conversion to Java?  Do you solve it there?*
>
> Leonard, I believe you were addressing this:
>
> “I believe I will start work (we probably already have) on Java->DOM, 
> Python->DOM, C/C#/C++->DOM and JavaScript->DOM transpilers. For people 
> who don’t want a full weight of X3DJSAIL or X3DPSAIL. This will be a 
> valuable addition to X3DJSAIL, should it choose to accept it.  I will 
> call it “PRESAIL”  for now.”
>
> This work has been cancelled (above), in favor of Jupyter notebook.  
> Is there a remaining action when a Program (not data) is the target of 
> a serializer or stylesheet?  Should I (and maybe Don) follow through 
> on the above multiparenting with our serializers to Java, JavaScript 
> and Python (and probably later in C/C#/C++)?
>
> Don, can you run X3DJSAIL inside Jupyter? Jupyter is inside Anaconda, 
> and I think you can install kernels with pip.
>
> Thanks,
>
> John
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
> *From: *Leonard Daly <mailto:Leonard.Daly at realism.com>
> *Sent: *Wednesday, May 1, 2019 8:24 PM
> *To: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *Re: [x3d-public] Report on X3DJSONLD, X3DJSAIL conversion 
> work. PLYSTL <-> JSON conversions. Future plans. Program -> DOM
>
> John,
>
> I presume that this is a conversion of X3D content between these 
> various formats. In which case, how can anything convert to DOM because
>
>  1. DOM is a language-neutral interface (see https://www.w3.org/DOM/#what)
>  2. DOM does not support elements with multiple parents. Each element
>     can have at most one parent (see second paragraph at
>     https://dom.spec.whatwg.org/#trees or if you don't want the living
>     spec then use https://www.w3.org/TR/dom/#trees).
>
> X3D explicitly allows multi-parenting (through the use of DEF/USE). 
> How does this application resolve the conflict?
>
> Leonard Daly
>
>     X3DJSONLD does the following conversions:
>
>     JSON->DOM
>
>     DOM->XML (borrowed)
>
>     XML->DOM (borrowed)
>
>     DOM->JSON
>
>     DOM->Java
>
>     DOM->Python
>
>     DOM->JavaScript
>
>     PLY->JSON
>
>     STL->JSON
>
>     JSON->STL (not done, not always triangles, needs someone who wants
>     to do tessellation, or can provide a JavaScript library)
>
>     JSON->EXI
>
>     EXI->JSON
>
>     XD3JSAIL/SourceForge X3D does the following conversions that were
>     added by me
>
>     JSON->DOM (Java version of X3DJSONLD)
>
>     X3DJSAIL->JavaScript
>
>     DOM->Python (X3DPSAIL)
>
>     DOM->Python (Pure Python—doesn’t do anything)
>
>     X3DJSAIL does:
>
>     X3DJSAIL->XML
>
>     X3DJSAIL->JSON
>
>     X3DJSAIL->X3D
>
>     X3DJSAIL->ClassicVRML
>
>     X3DJSAIL->VRML97
>
>     X3DJSAIL->HTML
>
>     X3DJSAIL->Java
>
>     X3DJSAIL->ModelMetaMarkdown
>
>     X3DJSAIL->X3dTidy
>
>     X3DJSAIL->X3DOM
>
>     X3DJSAIL->X_ITE
>
>     X3DJSAIL->Cobweb
>
>     X3DJSAIL->EXI
>
>     X3DJSAIL->GZIP
>
>     X3DJSAIL->ZIP
>
>     Don will likely add toFileJavaScript (replacing my work—I think
>     there may already be a start on a stylesheet) and toFilePython
>     stylesheet conversions to X3DJSAIL.  Is that OK, Don?
>
>     Probably I will retain maintenance of all JSON->DOM conversions
>     (JavaScript, Java, C++, X3DJSAIL, X3DOM, X_ITE). (Don uses a
>     stylesheet or strings to generate XML).  I am open to developing
>     JSON->DOM for other languages and improving the C++ version if
>     people are interested.  You should be willing to provide example
>     JSON files (possibly converted with X3D-Edit).   Recommend you use
>     Everit or Ajv for JSON Schema validation, if not X3DJSONLD’s
>     validator (based on Ajv).
>
>     Ideally I think, Don will take over all serializers, except my
>     DOM->JSON serializer.  I also use a javascript serializer on my
>     web page.
>
>     ================================================================================================================
>
>     What X3DJSONLD could provide for X3DJSAIL and X3DPSAIL (JavaScript)
>
>     PLY->JSON
>
>     STL->JSON
>
>     JSON->STL
>
>     These conversions are stored under ~/X3DJSONLD/src/main/node:
>
>     convertJsonToStl.js
>
>     convertPlyToJson.js
>
>     convertStlToJson.js
>
>     The JSON to STL conversion looks at the following X3D JSON indexes
>
>     IndexedFaceSet : function(obj, LDNode) {
>
>     Group : function(obj, LDNode) {
>
>     Shape : function(obj, LDNode) {
>
>     Box : function(obj, LDNode) {
>
>     IndexedTriangleSet : function(obj, LDNode) {
>
>     IndexedTriangleStripSet : function(obj, LDNode) {
>
>     IndexedTriangleFanSet : function(obj, LDNode) {
>
>                   IndexedLineSet : function(obj, LDNode) {
>
>     Normal : function(obj, LDNode) {
>
>     Coordinate : function(obj, LDNode) {
>
>     Transform : function(obj, LDNode) {
>
>     "@scale" : function(obj, LDNode) {
>
>     "@rotation" : function(obj, LDNode) {
>
>     "@translation" : function(obj, LDNode) {
>
>     "@normalPerVertex" : function(obj, LDNode) {
>
>     "@size" : function(obj, LDNode) {
>
>             "@vector" : function(obj, LDNode) {
>
>     "@point" : function(obj, LDNode) {
>
>     "@normalIndex" : function(obj, LDNode) {
>
>     "@coordIndex" : function(obj, LDNode) {
>
>     "@index" : function(obj, LDNode) {
>
>     Note:  There are no colors or textures.
>
>     Note: Sometimes I create more complex polygons than triangles.
>     This is not in the STL “specification”
>
>     Suggestions for additional shapes to translate are welcome:
>
>     Arc2D ArcClose2D Circle2D Disk2D Polyline2D Polypoint2D
>     Rectangle2D TriangleSet2D
>
>     Cone, Cylinder,
>     ElevationGrid,Extrusion,Sphere,Text,GeoElevationGrid
>     (why?),QuadSet,IndexedQuadSet
>
>     LineSet PointSet TriangleFanSet TriangleSet TriangleStripSet HAnim
>
>     I won’t translate the 2D geometry, I think.  I will not translate
>     Points or Lines
>
>     I don’t yet know how to translate Cone,
>     Cylinder,*ElevationGrid,Extrusion,Sphere,Text,HAnim (will the
>     standard help?) Help! I can probably handle the other ones.
>     Volunteers are welcome!  Pull requests are welcome! Suggestions
>     for JavaScript libraries accepted.
>
>     The ones I can handle, I think are QuadSet, IndexedQuadSet,
>     TriangleFanSet, TriangleSet and TriangleStripSet.
>
>     Would it be better to take a scenegraph from X3DOM or X_ITE?   Is
>     there documentation for the scenegraphs?
>
>     The STL to JSON creates a single IndexedFaceSet for all polygons
>     found in the STL file.  No color is handled from the STL file
>
>     The PLY to JSON file creates IndexedFaceSets and IndexedLineSets. 
>     Any more suggestions or PLY files you want translated?
>
>     Is there any requirement for JSON -> PLY?
>
>     Note: I just discovered https://cadexchanger.com/x3d for X3D to
>     STL conversions.   Add to X3D resources?   I haven’t tried it yet.
>     CADExchanger already mentioned here:
>     http://www.web3d.org/wiki/index.php/STEP_X3D_Translation#Open_Cascade_and_PythonOCC
>
>     Is there any need for STL conversion beyond CADExchanger (And
>     others)? I will delete my STL conversions.
>
>     For my JSON->DOM converter, should I create a python version.
>
>     I believe I will start work (we probably already have) on
>     Java->DOM, Python->DOM, C/C#/C++->DOM and JavaScript->DOM
>     transpilers. For people who don’t want a full weight of X3DJSAIL
>     or X3DPSAIL.  This will be a valuable addition to X3DJSAIL, should
>     it choose to accept it.  I will call it “PRESAIL”  for now.
>
>
>
>     _______________________________________________
>
>     x3d-public mailing list
>
>     x3d-public at web3d.org  <mailto:x3d-public at web3d.org>
>
>     http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
> -- 
> *Leonard Daly*
> 3D Systems & Cloud Consultant
> LA ACM SIGGRAPH Past Chair
> President, Daly Realism - /Creating the Future/
>

-- 
*Leonard Daly*
3D Systems & Cloud Consultant
LA ACM SIGGRAPH Past Chair
President, Daly Realism - /Creating the Future/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190502/cb4f37f3/attachment-0001.html>


More information about the x3d-public mailing list