[x3d-public] X3DJSAIL apps. Generating and compiling Java: new stylesheet X3dToJava.xslt

Don Brutzman brutzman at nps.edu
Thu Mar 23 23:22:54 PDT 2017


John, I'm mimicing your playbook with java source code generation.

Rather than write Javaa source-code generation within X3DJSAIL, I elected to adapt one of the stylesheets instead.  More portable.

	http://www.web3d.org/x3d/stylesheets/X3dToJava.xslt

Datatype detection of contained attribute values is still heuristic, and so might have errors.  Am considering how to achieve a better approach.

Attached is a test scene and interesting source output.  As you have seen, only one semicolon needed to build a whole model!  Declarative approach is quite terse, one might even say it is getting elegant.

Instead of value arrays, am using field objects to emphasize type.  That could be an output option - want to get datatype determination locked down first.

More to follow as this work progresses, more options are always good for all of us.  This sustained progress is great! It really bodes well for other programming language APIs for X3D, other tools adding X3D support, and a rock-solid object model as we continue progressing towards X3D v4.  Enjoy!  8)

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
package test123;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;
import org.web3d.x3d.jsail.Texturing.*;

/*
   <meta name="generator" content="X3dToJava.xslt stylesheet to create X3DJSAIL Java program from X3D source." />
   <meta name="url"       content="http://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" />
   <meta name="reference" content="X3DJSAIL, http://www.web3d.org/specifications/java/X3DJSAIL.html" />
*/
 
public class HelloWorldTest
{
  /* comment preceding root node */
  X3DObject x3dModelObjectTree = new X3DObject().setProfile("Immersive").setVersion("3.3")
    .setHead(new headObject()
      .setMeta(new metaObject().setContent("HelloWorld.x3d").setName("title"))
      .setMeta(new metaObject().setContent("Simple X3D scene example: Hello World!").setName("description"))
      .setMeta(new metaObject().setContent("30 October 2000").setName("created"))
      .setMeta(new metaObject().setContent("23 November 2014").setName("modified"))
      .setMeta(new metaObject().setContent("Don Brutzman").setName("creator"))
      .setMeta(new metaObject().setContent("HelloWorld.tall.png").setName("Image"))
      .setMeta(new metaObject().setContent("http://en.wikipedia.org/wiki/Hello_world").setName("reference"))
      .setMeta(new metaObject().setContent("en.wikipedia.org/wiki/Hello#\"Hello,_World\"_computer_program").setName("reference"))
      .setMeta(new metaObject().setContent("http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world").setName("reference"))
      .setMeta(new metaObject().setContent("http://www.HelloWorldExample.net").setName("reference"))
      .setMeta(new metaObject().setContent("http://www.web3D.org").setName("reference"))
      .setMeta(new metaObject().setContent("http://www.web3d.org/realtime-3d/news/internationalization-x3d").setName("reference"))
      .setMeta(new metaObject().setContent("http://www.web3d.org/x3d/content/examples/HelloWorld.x3d").setName("reference"))
      .setMeta(new metaObject().setContent("http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes").setName("reference"))
      .setMeta(new metaObject().setContent("http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d").setName("identifier"))
      .setMeta(new metaObject().setContent("http://www.web3d.org/x3d/content/examples/license.html").setName("license"))
      .setMeta(new metaObject().setContent("X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit").setName("generator"))
      .addComments("Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D Compressed Binary Encoding (CBE), X3DOM, JSON")
      .setMeta(new metaObject().setContent("HelloWorld.wrl").setName("reference"))
      .setMeta(new metaObject().setContent("HelloWorld.x3dv").setName("reference"))
      .setMeta(new metaObject().setContent("HelloWorld.x3db").setName("reference"))
      .setMeta(new metaObject().setContent("HelloWorld.xhtml").setName("reference"))
      .setMeta(new metaObject().setContent("HelloWorld.json").setName("reference")))
    .setScene(new SceneObject()
      .addComments("Example scene to illustrate X3D nodes and fields (XML elements and attributes)")
      .addChild(new GroupObject()
        .addChild(new ViewpointObject("ViewUpClose").setCenterOfRotation(new SFVec3fObject(0,-1,0)).setPosition(new SFVec3fObject(0,-1,7)).setDescription("Hello world!"))
        .addChild(new TransformObject().setRotation(new SFRotationObject(0,1,0,3))
          .addChild(new ShapeObject()
            .setGeometry(new SphereObject())
            .setAppearance(new AppearanceObject()
              .setMaterial(new MaterialObject("MaterialLightBlue").setDiffuseColor(new SFColorObject(0.1,0.5,1)))
              .setTexture(new ImageTextureObject("ImageCloudlessEarth").setUrl("\"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\"")))))
        .addChild(new TransformObject().setTranslation(new SFVec3fObject(0,-2,0))
          .addChild(new ShapeObject()
            .setGeometry(new TextObject("TextMessage").setString("\"Hello\" \"world!\"")
              .setFontStyle(new FontStyleObject().setJustify("\"MIDDLE\" \"MIDDLE\"")))
            .setAppearance(new AppearanceObject()
              .setMaterial(new MaterialObject().setUSE("MaterialLightBlue")))))));
  /* comment following root node */
}
-------------- next part --------------
{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"HelloWorld.x3d"
          },
          {
            "@name":"description",
            "@content":"Simple X3D scene example: Hello World!"
          },
          {
            "@name":"created",
            "@content":"30 October 2000"
          },
          {
            "@name":"modified",
            "@content":"23 November 2014"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"Image",
            "@content":"HelloWorld.tall.png"
          },
          {
            "@name":"reference",
            "@content":"http://en.wikipedia.org/wiki/Hello_world"
          },
          {
            "@name":"reference",
            "@content":"en.wikipedia.org/wiki/Hello#\"Hello,_World\"_computer_program"
          },
          {
            "@name":"reference",
            "@content":"http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world"
          },
          {
            "@name":"reference",
            "@content":"http://www.HelloWorldExample.net"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3D.org"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/realtime-3d/news/internationalization-x3d"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/x3d/content/examples/HelloWorld.x3d"
          },
          {
            "@name":"reference",
            "@content":"http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes"
          },
          {
            "@name":"identifier",
            "@content":"http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d"
          },
          {
            "@name":"license",
            "@content":"http://www.web3d.org/x3d/content/examples/license.html"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.wrl"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.x3dv"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.x3db"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.xhtml"
          },
          {
            "@name":"reference",
            "@content":"HelloWorld.json"
          },
          {
            "@name":"translated",
            "@content":"18 March 2017"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"warning",
            "@content":"An experimental version of X3D JSON encoding is used for this scene.  Status online at http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ],
        "-children":[
          {
            "#comment":"Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D Compressed Binary Encoding (CBE), X3DOM, JSON"
          }
        ]
    },
    "Scene": {
        "-children":[
          {
            "#comment":"Example scene to illustrate X3D nodes and fields (XML elements and attributes)"
          },
          { "Group":
            {
              "-children":[
                { "Viewpoint":
                  {
                    "@DEF":"ViewUpClose",
                    "@centerOfRotation":[0,-1,0],
                    "@description":"Hello world!",
                    "@position":[0,-1,7]
                  }
                },
                { "Transform":
                  {
                    "@rotation":[0,1,0,3],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":
                            { "Sphere":
                              {
                              }
                            },
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@DEF":"MaterialLightBlue",
                                      "@diffuseColor":[0.1,0.5,1]
                                    }
                                  },
                                "-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"]
                                    }
                                  }
                              }
                            }
                        }
                      }
                    ]
                  }
                },
                { "Transform":
                  {
                    "@translation":[0,-2,0],
                    "-children":[
                      { "Shape":
                        {
                          "-geometry":
                            { "Text":
                              {
                                "@DEF":"TextMessage",
                                "@string":["Hello","world!"],
                                "-fontStyle":
                                  { "FontStyle":
                                    {
                                      "@justify":["MIDDLE","MIDDLE"]
                                    }
                                  }
                              }
                            },
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@USE":"MaterialLightBlue"
                                    }
                                  }
                              }
                            }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
    }
  }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorld.x3d
Type: model/x3d+xml
Size: 3304 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170323/761c03cb/attachment.x3d>


More information about the x3d-public mailing list