[x3d-public] Bad ECMAScript in X3DJSAIL JSON output: #sourceText handling

Don Brutzman brutzman at nps.edu
Mon Mar 19 06:53:18 PDT 2018


On 3/19/2018 4:33 AM, John Carlson wrote:
> Where should I update my stylesheets?  Look at this ECMAScript in JSON.  This will never work.   The whole function body is commented out.

Agreed that putting all contained source into a single line will not work because any // comment characters will hide all following code.

> Please make multistring array.  Thanks.
> 
>                      "#sourceText":[
> 
> "ecmascript: function colorInput (eventValue) // Example source code { colorsOutput = new MFColor(eventValue); // assigning value sends output event // Browser.print('colorInput=' + eventValue + ', colorsOutput=' + colorsOutput + '\n'); }"
> 
> ]
> 
> I do not know why I am not communicating
Um, well you are sending but sometimes at a different rate than I can receive... both are required for communication.

Sorry, am proceeding as best possible.  Hopefully preceding change last night worked OK, so let's take a further look.

The #sourceText problem and options for sourceText conversion are described as follows.  (Just made and committed/deployed a few touchups to this page.)

=============================================================
=============================================================
http://www.web3d.org/x3d/stylesheets/X3dToJson.html#DataTypes

------
Nomenclature comparison:
*X3D,
*XML,
*JSON
------
* Embedded source code for Script, ShaderPart and ShaderProgram nodes
* CDATA (Character DATA) section <[CDATA[ "world wild Web!" ]]>
*"#sourceText" string array containing original code, possibly escaped

=============================================================
=============================================================
http://www.web3d.org/x3d/stylesheets/X3dToJson.html#DesignCorrespondences

* #sourceText preservation of character data (e.g. source code contained in a Script, ShaderPart and ShaderProgram node)

* Embedded #sourceText code (for X3D Script, ShaderPart and ShaderProgram nodes) must follow JSON rules that demand replacement of line feeds as \n literals and tabs as \t literals (discussion). A significant reduction in readability occurs but apparently is required. A stylesheet switch allows an author to retain multiline strings without such obfuscation.

=============================================================
=============================================================
http://www.web3d.org/x3d/stylesheets/X3dToJson.html#Options
Options and Invocation

Stylesheet options and default values:

     <xsl:param name="stripComments"><xsl:text>false</xsl:text></xsl:param>
     <xsl:param name="stripDefaultAttributes"><xsl:text>true</xsl:text></xsl:param>
     <xsl:param name="indentEnabled"><xsl:text>true</xsl:text></xsl:param>
     <xsl:param name="sourceText"><xsl:text>strings</xsl:text></xsl:param> <!-- escaped | strings | plaintext -->
     <xsl:param name="traceEnabled"><xsl:text>false</xsl:text></xsl:param>
     <xsl:param name="traceScripts"><xsl:text>false</xsl:text></xsl:param>

X3D-Edit conversion pane The sourceText options govern the output mode of #sourceText code embedded in Script, ShaderPart and ShaderProgram nodes.

       escaped: line feeds replaced by \n character, thus a single line results
         strings: array of single-line strings that are reassembled into original text
     plaintext: no modifications, line feed and tab characters remain unmodified

Note that converted JavaScript source can be broken if it contains // comment characters since any subsequent source code is effectively ignored if stuffed into a single line.

Note that X3D-Edit has an X3D Conversions: X3D to JSON panel that offers configuration of several options for testing.
https://savage.nps.edu/X3D-Edit/images/X3dToJsonConversionPanel.png

XSLT stylesheets are reusable and can be invoked by a wide variety of tools and programming languages.
=============================================================
=============================================================

Next. Am looking at the X3dToJson.xslt stylesheet.  As you note below, this parameter setting has the following default parameter:

	<xsl:param name="sourceText"><xsl:text>strings</xsl:text></xsl:param> <!-- escaped | strings | plaintext -->

Found the following example:
http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptEvents.x3d
http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptEvents.json

Current version online looks OK:
================================
  "#sourceText":[
"ecmascript:",
"",
"//  this input function receives the currently interpolated rotation angle value,",
"//  and then computes the position and orientation of each of the cones.",
"",
"function angle (value)",
"{",
"  positionRed       = new SFVec3f (Math.cos (value), 1.5 * Math.sin(value), 0.5);",
"  positionGreen     = new SFVec3f (Math.cos (value+2.094), 1.5 * Math.sin(value+2.094),    0);",
"  positionTurquoise = new SFVec3f (Math.cos (value+4.189), 1.5 * Math.sin(value+4.189), -0.5);",
"",
"  // The values 2.094 and 4.189 are 1/3 and 2/3 of 2*pi radians.",
"  orientationRed       = new SFRotation (0, 0, 1, -2*value);",
"  orientationGreen     = new SFRotation (0, 0, 1, -2*(value+2.094));",
"  orientationTurquoise = new SFRotation (0, 0, 1, -2*(value+4.189));",
"}"
]
================================

However the version on my system (converted last night) is all one long line.

I looked at the corresponding build.xml target

	<target name="processScenes.json"
		description="convert each .x3d scene to Javascript Object Notation .json version"
		depends="get.saxon">

but it is not modifying sourceText default setting.

So, not sure why my local sourceText is getting smashed together.  Further debugging will be necessary another time to see what has changed.

> John
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Saturday, March 17, 2018 5:03 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>; x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *RE: Bad ECMAScript in X3DJSAIL JSON output
> 
> Possibly related to this patch…what do you think?   Web site appears okay, so I am confused.  My local build has problems, ran ant all in x3d/stylesheets/java.   Files not updating in java/examples, so puzzled.  Website appears okay.  Files in x3d/stylesheets/java/classes up to date, but still have same issue.  Hmm.  May try flipping this back.   Most successful with my DOM2JSONSerializer (no stylesheet).  Worst time going through a Java X3DJSAIL program to produce JSON.
> 
> What process generates the JSON on the website for java/examples? http://www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.json  that looks ideal, AFAICT.
> 
> John
> 
> $ svn diff X3d*
> 
> Index: X3dToJson.xslt
> 
> ===================================================================
> 
> --- X3dToJson.xslt      (revision 26501)
> 
> +++ X3dToJson.xslt      (working copy)
> 
> @@ -73,7 +73,7 @@
> 
>       <xsl:param name="stripComments"><xsl:text>false</xsl:text></xsl:param>
> 
>       <xsl:param name="stripDefaultAttributes"><xsl:text>true</xsl:text></xsl:param>
> 
>       <xsl:param name="indentEnabled"><xsl:text>true</xsl:text></xsl:param>
> 
> -    <xsl:param name="normalizeCommentWhitespace"><xsl:text>true</xsl:text></xsl:param>
> 
> +    <xsl:param name="normalizeCommentWhitespace"><xsl:text>false</xsl:text></xsl:param>
> 
>       <xsl:param name="sourceText"><xsl:text>strings</xsl:text></xsl:param> <!-- escaped | strings | plaintext -->
> 
>       <xsl:param name="traceEnabled" ><xsl:text>false</xsl:text></xsl:param>
> 
>       <xsl:param name="traceScripts" ><xsl:text>false</xsl:text></xsl:param>
> 
> John
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 
> *From: *John Carlson <mailto:yottzumm at gmail.com>
> *Sent: *Saturday, March 17, 2018 3:33 PM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>; x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> *Subject: *Bad ECMAScript in X3DJSAIL JSON output
> 
> See overrunning comments in ECMAScript in x3d-code/www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.json
> 
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
> 


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