<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">I think trying to figure out the
encoding of a Script node is getting a little ahead of things. <br>
<br>
JSON code is typically executed to create the data structure(s).
In this case it appears that the result will be to put the script
code into a variable that needs to be executed again. Unless JSON
is to be used as another encoding for storage and transport, I
think the use within HTML needs to be settled first.<br>
<br>
<br>
Leonard Daly<br>
<br>
<br>
<br>
<br>
</div>
<blockquote cite="mid:564E77D3.5090203@nps.edu" type="cite">The
3-way option for Script #source is now deployed in the examples,
described on the X3dToJson stylesheet page, and implemented in
X3D-Edit to facilitate testing. Conversion parameters panel
screenshot attached.
<br>
<br>
<a class="moz-txt-link-freetext" href="http://www.web3d.org/x3d/stylesheets/X3dToJson.html#Options">http://www.web3d.org/x3d/stylesheets/X3dToJson.html#Options</a>
<br>
<a class="moz-txt-link-freetext" href="https://savage.nps.edu/X3D-Edit/#new">https://savage.nps.edu/X3D-Edit/#new</a>
<br>
<a class="moz-txt-link-freetext" href="https://savage.nps.edu/X3D-Edit/images/X3dToJsonConversionPanel.png">https://savage.nps.edu/X3D-Edit/images/X3dToJsonConversionPanel.png</a>
<br>
<br>
On 11/18/2015 4:43 PM, Don Brutzman wrote:
<br>
<blockquote type="cite">OK and now for the next level for Script
source code in JSON form...
<br>
<br>
"When you come to a fork in the road, take it." Yogi Berra
<br>
<br>
John: let's make the #source content a string array, and then
authors/tools/files can use any of the three forms
equivalently. first 2 out of 3 pass jslint, likely 3 out of 3
just plain work.
<br>
<br>
as before, but in consistent ["string-array"] form:
<br>
<br>
- array of one plaintext block string.
<br>
- array of one single-line string with all linefeeds and tabs
escaped as \n and \t.
<br>
- array of multiple one-line strings as shown below.
<br>
<br>
A commonly acceptable solution for each of the alternatives
takes all the sting out of any choice, we don't have to worry
about tradeoff advantages/disadvantages.
<br>
<br>
Pretty exciting that a no-lose approach might exist to cope with
this situation! 8)
<br>
<br>
So I will change stylesheet support for the three alternatives
to all be string _array_ and rebuild the examples.
<br>
<br>
I hope this fine tuning doesn't interrupt your loader efforts.
<br>
<br>
p.s. cosmetic: maybe we should rename #source to #sourceText or
somesuch - a more descriptive key name might also be preferable.
<br>
<br>
<br>
On 11/17/2015 10:17 PM, Don Brutzman wrote:
<br>
<blockquote type="cite">[summary: from plaintext block to total
escapism and now to string array for #source block]
<br>
<br>
On 11/17/2015 7:21 AM, John Carlson wrote:
<br>
<blockquote type="cite">Why isn't an array of strings
acceptable?
<br>
</blockquote>
<br>
On 11/17/2015 7:23 AM, John Carlson wrote:
<br>
<blockquote type="cite">It's a typical javascript pattern to
create arrays of strings and then join them.
<br>
</blockquote>
<br>
glad to hear it!
<br>
<br>
If arrays of json strings are typical and acceptable and not
an undue complication for plain old javascript programmers,
then it is certainly fine with me. I strongly believe that
human readability is important. Quoted strings are surely
better than garble.
<br>
<br>
It is no trouble for me to export .x3d to .json #source that
way as well. I have added another option to the stylesheet
switch tonight to produce that alternative.
<br>
<br>
Example attached, excerpt follows. Hmmm, not too bad, and
certainly not confusable.
<br>
<br>
I will again regenerate all examples in that form if opinions
are leaning that way.
<br>
<br>
==========================================
<br>
"-children":[
<br>
{ "Script":
<br>
[...snip...]
<br>
"#source":[
<br>
"ecmascript:",
<br>
"function initialize ()",
<br>
"{",
<br>
" checkCoordinatePoints ();",
<br>
"}",
<br>
"function checkCoordinatePoints ()",
<br>
"{",
<br>
" // A parallelepiped has three sets of four parallel
edges; the edges within each set are of equal length.",
<br>
" // Quality assurance: check that lengths of corresponding
sides match.",
<br>
" ",
<br>
" edge01 = length2(point[0], point[1]); // top",
<br>
" edge12 = length2(point[1], point[2]);",
<br>
" edge23 = length2(point[2], point[3]);",
<br>
" edge30 = length2(point[3], point[0]);",
<br>
" edge45 = length2(point[4], point[5]); // bottom",
<br>
" edge56 = length2(point[5], point[6]);",
<br>
" edge67 = length2(point[6], point[7]);",
<br>
" edge74 = length2(point[7], point[4]);",
<br>
" edge04 = length2(point[0], point[4]); // sides",
<br>
" edge15 = length2(point[1], point[5]);",
<br>
" edge26 = length2(point[2], point[6]);",
<br>
" edge37 = length2(point[3], point[7]);",
<br>
" ",
<br>
" epsilon = edge01 * 0.001;",
<br>
" ",
<br>
" if ((Math.abs(edge01 - edge23) > epsilon) ||",
<br>
" (Math.abs(edge23 - edge67) > epsilon) ||",
<br>
" (Math.abs(edge67 - edge45) > epsilon) ||",
<br>
" (Math.abs(edge45 - edge01) > epsilon))",
<br>
" Browser.println ('Warning, mismatched parallelopiped
sides 02/33/45/67');",
<br>
" else if ((Math.abs(edge30 - edge12) > epsilon) ||",
<br>
" (Math.abs(edge12 - edge56) > epsilon) ||",
<br>
" (Math.abs(edge56 - edge74) > epsilon) ||",
<br>
" (Math.abs(edge74 - edge30) > epsilon))",
<br>
" Browser.println ('Warning, mismatched parallelopiped
sides 30/12/56/74');",
<br>
" else if ((Math.abs(edge04 - edge15) > epsilon) ||",
<br>
" (Math.abs(edge15 - edge26) > epsilon) ||",
<br>
" (Math.abs(edge26 - edge37) > epsilon) ||",
<br>
" (Math.abs(edge37 - edge04) > epsilon))",
<br>
" Browser.println ('Warning, mismatched parallelopiped
sides 04/15/26/37');",
<br>
"}",
<br>
"function length2 (pointA, pointB)",
<br>
"{ ",
<br>
" return Math.sqrt((pointA.x - pointB.x)*(pointA.x -
pointB.x) +",
<br>
" (pointA.y - pointB.y)*(pointA.y -
pointB.y) +",
<br>
" (pointA.z - pointB.z)*(pointA.z -
pointB.z));",
<br>
"}",
<br>
"function set_point (eventValue)",
<br>
"{",
<br>
" // input eventValue received for inputOutput field",
<br>
" point = eventValue;",
<br>
" checkCoordinatePoints ();",
<br>
"}"
<br>
]
<br>
}
<br>
}
<br>
]
<br>
==========================================
<br>
<br>
Example reassembly to join strings back together in
javascript:
<br>
<br>
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/2392766/multiline-strings-in-json">http://stackoverflow.com/questions/2392766/multiline-strings-in-json</a>
<br>
<blockquote type="cite">Once parsed, I just use
myData.modify_head.join('\n') or myData.modify_head.join(),
<br>
depending upon whether I want a line break after each string
or not.
<br>
</blockquote>
<br>
Wondering, what would that join() code specifically look like
for an X3D JSON loader?
<br>
<br>
Looking forward: seems like a group/community decision if we
want to specify a string array as X3D JSON default for #source
blocks.
<br>
</blockquote>
</blockquote>
<br>
all the best, Don
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
x3d-public mailing list
<a class="moz-txt-link-abbreviated" href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a>
<a class="moz-txt-link-freetext" href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a>
</pre>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<font class="tahoma,arial,helvetica san serif" color="#333366">
<font size="+1"><b>Leonard Daly</b></font><br>
X3D Co-Chair<br>
Cloud Consultant<br>
President, Daly Realism - <i>Creating the Future</i>
</font></div>
</body>
</html>