[x3d-public] X3DJSAIL, programs using it, X3dToJava.xslt and setUSE

John Carlson yottzumm at gmail.com
Thu May 2 09:41:00 PDT 2019


Leonard, I saw your message.  To get an idea of how I would solve the multi-parenting issue when translating to Java/JavaScript/Python/C/C#/C++ (DOM -> program, in my case, not scenegraph -> program, and not JSON to STL), take a look at the attached Java code generated by my serializer (serializer link below). I don’t actually have multiple parents, just ProtoInstance variables, but you might get an idea of my approach to solving the issue. If there’s a better approach to serializing from DOM, let me know.

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/JavaSerializer.js

The question is, should we do this?  Note all these programs use the X3DJSAIL API, except for some that currently don’t do anything, or generate some buggy XML.  Does X3DJSAIL handle what’s next?  Would it be useful for programs using X3DJSAIL to not supply USE attributes, only DEF attributes? Currently Don uses setUSE in his HelloWorldProgram.java with either a node or a string variable. Should I do something similar, use an variable pointed to a DEF’ed object, a DEF value, or?   Should I keep a flag in JavaScript for when an object has been serialized, and then not write out attributes except for USE when the object is revisited?  Is setUSE useful?

Will using separate, but equal strings for DEF and USE work with X3DJSAIL to create multiparenting?   Do we need setUSE, or can we merely specify a variable instead of another constructor?

Note that Don’s X3dToJava.xslt does generate separate objects, and uses setUSE with equal, but different strings from the DEF, so we’ll have to update the X3dToJava.xslt stylesheet as well, if X3DJSAIL doesn’t handle it.

Thanks for a sharp eye, Leonard! Looking forward to advice on how to best use X3DJSAIL!

Note that we’re generating DOM, JSON and XML output from these programs, so we’ll have to have USE in that output.  Also, X3DJSONLD.js/.java generates DOM output, so no action there.

Don, let me know how you’re solving this for Java output from X3dToJava.xslt, if at all.  Is this a non-action?  Thanks,

It seems like the issue may be limited to DOM -> Java/JavaScript/Python generating serializers and X3dToJava.xslt at this point, with a potential issue with X3DJSAIL.

My tendency would be to toss the whole thing in Don’s lap, if he’s going to write/modify the Java, JavaScript and Python generating stylesheets.  But perhaps this problem is better solved without XSLT?

Also note that it’s likely that this issue only affects *generated* programs, not handwritten programs.

Note that the Java SAI only supports setUSE(String).   X3DJSAIL supports passing a node.  So we probably can’t pass a node to setUSE if we want to use a standard API. Thus we are limited to passing a reference to the object to the outer method, or constructing a new object, and calling setUSE with a string, not a node.  I vote for constructing a new object, similar to how Don’s X3dToJava.xslt does, then the work for multiparenting will all be centralized in X3DJSAIL, instead of not supporting setUSE at all. (why is setUSE in the SAI???)

So my vote is to support multiple objects in X3DJSAIL with the same DEF/USE value (no action, or fixing bugs in X3DJSAIL), or remove setUSE from the SAI (standards action), or not use setUSE, except in a few cases, where more fields than USE are allowed.  We will need some way to look up a DEF’ed node (findNode? querySelector?) in SAI if not already there.

Sorry, 

John

Sent from Mail for Windows 10

From: Leonard Daly
Sent: Wednesday, May 1, 2019 8:24 PM
To: 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
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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190502/7e24b3ef/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x3domflowers.java
Type: application/octet-stream
Size: 8196 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190502/7e24b3ef/attachment-0001.obj>


More information about the x3d-public mailing list