[x3d-public] questions on X3DJSAIL usage.

Brutzman, Donald (Don) (CIV) brutzman at nps.edu
Mon May 6 00:18:30 PDT 2019


On 5/4/2019 4:15 PM, John Carlson wrote:
> I’m waiting for a response on whether I should stop using setUSE() (except in cases where > 1 fields are used in a node) in programs using X3DJSAIL.
> 
> Thanks!
> 
> John

Hmmm, perhaps I'm not understanding your question... but here is an attempt at a simple answer.  Plus some additional syntactic sugar.

1. I think a programmer utilizes setUSE() whenever you need to set a USE value on a node.

Example excerpts:
http://x3dgraphics.com/examples/X3dForWebAuthors/Chapter01TechnicalOverview

HelloWorld.x3d

       <Transform translation='0 -2 0'>
         <Shape>
           <Text DEF='TextMessage' string='"Hello" "world!"'>
             <FontStyle justify='"MIDDLE" "MIDDLE"'/>
           </Text>
           <Appearance>
             <Material USE='MaterialLightBlue'/>
           </Appearance>
         </Shape>
       </Transform>

HelloWorld.java

       .addChild(new TransformObject().setTranslation(0.0f,-2.0f,0.0f)
         .addChild(new ShapeObject()
           .setGeometry(new TextObject("TextMessage").setString(new MFStringObject("\"Hello\" \"world!\""))
             .setFontStyle(new FontStyleObject().setJustify(FontStyleObject.JUSTIFY_MIDDLE_MIDDLE)))
           .setAppearance(new AppearanceObject()
             .setMaterial(new MaterialObject().setUSE("MaterialLightBlue")))))));

HelloWorld.py

      .addChild(Transform() \
       .setTranslation(SFVec3f([0,-2,0])) \
       .addChild(Shape() \
        .setGeometry(Text() \
         .setDEF(SFString("TextMessage")) \
         .setString(MFString(["Hello","world!"])) \
         .setFontStyle(FontStyle() \
          .setJustify(MFString(["MIDDLE","MIDDLE"])) \
         ) \
        ) \
        .setAppearance(Appearance() \
         .setMaterial(Material() \
          .setUSE(SFString("MaterialLightBlue")) \
         ) \
        ) \
       ) \
      )

2. Note that if we start putting field adjustments on the same line, the structure for .java and .py are nearly identical.

Other syntax tightening is further possible in .py version:
- no apparent need to wrap SFString() in python syntax
- I suspect that MFString() wrapping is also superfluous, hopefully we can just use ["Hello","world!"]
- Similarly might try replacing SFVec3f([0,-2,0]) with [0,-2,0] - we're getting more Pythonic now!
- indenting with two space characters makes scene-graph structure more evident.

3. Spent the day refactoring the X3D Examples Archive projects from Netbeans plain-old freeform projects to Netbeans Java freeform projects.  This doesn't limit any functionality but it does make Java experimentation much simpler... menu items now include Compile/Run/Debug options.

4. Am further noticing from above that the following single-string .java construct

	.setString(new MFStringObject("\"Hello\" \"world!\""))

is more readable as a String array instead:

	.setString(new MFStringObject(new String[] {"Hello","world!"}))

or even more simply as:

	.setString(new String[] {"Hello","world!"})

Have improved X3dToJava.xslt conversions to simplify accordingly.  Will rerun all java conversions tonight and hopefully redeploy Web3D example archives tomorrow.  Then retest python build tomorrow night.

Also will redeploy X3DJSAIL with this improvement tonight.  Have also added initial PointProperties validation for X3Dv4, included source in full.jar for IDE javadoc/debugging, and fixed a number of X3DLoaderDOM geospatial errors.

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


More information about the x3d-public mailing list