<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">For example:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><a href="http://www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/TimeOfDay.json" class="">www.web3d.org/x3d/content/examples/Savage/Environment/TimeOfDay/TimeOfDay.json</a></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">has 3 set_boolean functions and in 3 different scripts. It would seem like I should treat these differently. I was thinking about adding a numbered object around the functions to create some scope for the function, but I think I’ll have to deal with fields, and routes to those fields etc. etc. If cobweb can handle multiple functions with the same name (can it?), can we use it? I’m pretty sure ordinary JavaScript will overwrite the function declaration if it sees another one.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">I will try a basic load for right now. I think we’ll need something more complex.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">John</div><div><blockquote type="cite" class=""><div class="">On Nov 20, 2015, at 10:35 AM, John Carlson <<a href="mailto:yottzumm@gmail.com" class="">yottzumm@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><p dir="ltr" class="">Which is why I brought up name scopes. Should we try a JSON -> Cobweb loader instead of a JSON -> X3DOM loader?</p>
<div class="gmail_quote">On Nov 20, 2015 9:07 AM, "Leonard Daly" <<a href="mailto:web3d@realism.com" class="">web3d@realism.com</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000" class="">
<div class="">I think trying to figure out the
encoding of a Script node is getting a little ahead of things. <br class="">
<br class="">
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 class="">
<br class="">
<br class="">
Leonard Daly<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
</div>
<blockquote type="cite" class="">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 class="">
<br class="">
<a href="http://www.web3d.org/x3d/stylesheets/X3dToJson.html#Options" target="_blank" class="">http://www.web3d.org/x3d/stylesheets/X3dToJson.html#Options</a>
<br class="">
<a href="https://savage.nps.edu/X3D-Edit/#new" target="_blank" class="">https://savage.nps.edu/X3D-Edit/#new</a>
<br class="">
<a href="https://savage.nps.edu/X3D-Edit/images/X3dToJsonConversionPanel.png" target="_blank" class="">https://savage.nps.edu/X3D-Edit/images/X3dToJsonConversionPanel.png</a>
<br class="">
<br class="">
On 11/18/2015 4:43 PM, Don Brutzman wrote:
<br class="">
<blockquote type="cite" class="">OK and now for the next level for Script
source code in JSON form...
<br class="">
<br class="">
"When you come to a fork in the road, take it." Yogi Berra
<br class="">
<br class="">
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 class="">
<br class="">
as before, but in consistent ["string-array"] form:
<br class="">
<br class="">
- array of one plaintext block string.
<br class="">
- array of one single-line string with all linefeeds and tabs
escaped as \n and \t.
<br class="">
- array of multiple one-line strings as shown below.
<br class="">
<br class="">
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 class="">
<br class="">
Pretty exciting that a no-lose approach might exist to cope with
this situation! 8)
<br class="">
<br class="">
So I will change stylesheet support for the three alternatives
to all be string _array_ and rebuild the examples.
<br class="">
<br class="">
I hope this fine tuning doesn't interrupt your loader efforts.
<br class="">
<br class="">
p.s. cosmetic: maybe we should rename #source to #sourceText or
somesuch - a more descriptive key name might also be preferable.
<br class="">
<br class="">
<br class="">
On 11/17/2015 10:17 PM, Don Brutzman wrote:
<br class="">
<blockquote type="cite" class="">[summary: from plaintext block to total
escapism and now to string array for #source block]
<br class="">
<br class="">
On 11/17/2015 7:21 AM, John Carlson wrote:
<br class="">
<blockquote type="cite" class="">Why isn't an array of strings
acceptable?
<br class="">
</blockquote>
<br class="">
On 11/17/2015 7:23 AM, John Carlson wrote:
<br class="">
<blockquote type="cite" class="">It's a typical javascript pattern to
create arrays of strings and then join them.
<br class="">
</blockquote>
<br class="">
glad to hear it!
<br class="">
<br class="">
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 class="">
<br class="">
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 class="">
<br class="">
Example attached, excerpt follows. Hmmm, not too bad, and
certainly not confusable.
<br class="">
<br class="">
I will again regenerate all examples in that form if opinions
are leaning that way.
<br class="">
<br class="">
==========================================
<br class="">
"-children":[
<br class="">
{ "Script":
<br class="">
[...snip...]
<br class="">
"#source":[
<br class="">
"ecmascript:",
<br class="">
"function initialize ()",
<br class="">
"{",
<br class="">
" checkCoordinatePoints ();",
<br class="">
"}",
<br class="">
"function checkCoordinatePoints ()",
<br class="">
"{",
<br class="">
" // A parallelepiped has three sets of four parallel
edges; the edges within each set are of equal length.",
<br class="">
" // Quality assurance: check that lengths of corresponding
sides match.",
<br class="">
" ",
<br class="">
" edge01 = length2(point[0], point[1]); // top",
<br class="">
" edge12 = length2(point[1], point[2]);",
<br class="">
" edge23 = length2(point[2], point[3]);",
<br class="">
" edge30 = length2(point[3], point[0]);",
<br class="">
" edge45 = length2(point[4], point[5]); // bottom",
<br class="">
" edge56 = length2(point[5], point[6]);",
<br class="">
" edge67 = length2(point[6], point[7]);",
<br class="">
" edge74 = length2(point[7], point[4]);",
<br class="">
" edge04 = length2(point[0], point[4]); // sides",
<br class="">
" edge15 = length2(point[1], point[5]);",
<br class="">
" edge26 = length2(point[2], point[6]);",
<br class="">
" edge37 = length2(point[3], point[7]);",
<br class="">
" ",
<br class="">
" epsilon = edge01 * 0.001;",
<br class="">
" ",
<br class="">
" if ((Math.abs(edge01 - edge23) > epsilon) ||",
<br class="">
" (Math.abs(edge23 - edge67) > epsilon) ||",
<br class="">
" (Math.abs(edge67 - edge45) > epsilon) ||",
<br class="">
" (Math.abs(edge45 - edge01) > epsilon))",
<br class="">
" Browser.println ('Warning, mismatched parallelopiped
sides 02/33/45/67');",
<br class="">
" else if ((Math.abs(edge30 - edge12) > epsilon) ||",
<br class="">
" (Math.abs(edge12 - edge56) > epsilon) ||",
<br class="">
" (Math.abs(edge56 - edge74) > epsilon) ||",
<br class="">
" (Math.abs(edge74 - edge30) > epsilon))",
<br class="">
" Browser.println ('Warning, mismatched parallelopiped
sides 30/12/56/74');",
<br class="">
" else if ((Math.abs(edge04 - edge15) > epsilon) ||",
<br class="">
" (Math.abs(edge15 - edge26) > epsilon) ||",
<br class="">
" (Math.abs(edge26 - edge37) > epsilon) ||",
<br class="">
" (Math.abs(edge37 - edge04) > epsilon))",
<br class="">
" Browser.println ('Warning, mismatched parallelopiped
sides 04/15/26/37');",
<br class="">
"}",
<br class="">
"function length2 (pointA, pointB)",
<br class="">
"{ ",
<br class="">
" return Math.sqrt((pointA.x - pointB.x)*(pointA.x -
pointB.x) +",
<br class="">
" (pointA.y - pointB.y)*(pointA.y -
pointB.y) +",
<br class="">
" (pointA.z - pointB.z)*(pointA.z -
pointB.z));",
<br class="">
"}",
<br class="">
"function set_point (eventValue)",
<br class="">
"{",
<br class="">
" // input eventValue received for inputOutput field",
<br class="">
" point = eventValue;",
<br class="">
" checkCoordinatePoints ();",
<br class="">
"}"
<br class="">
]
<br class="">
}
<br class="">
}
<br class="">
]
<br class="">
==========================================
<br class="">
<br class="">
Example reassembly to join strings back together in
javascript:
<br class="">
<br class="">
<a href="http://stackoverflow.com/questions/2392766/multiline-strings-in-json" target="_blank" class="">http://stackoverflow.com/questions/2392766/multiline-strings-in-json</a>
<br class="">
<blockquote type="cite" class="">Once parsed, I just use
myData.modify_head.join('\n') or myData.modify_head.join(),
<br class="">
depending upon whether I want a line break after each string
or not.
<br class="">
</blockquote>
<br class="">
Wondering, what would that join() code specifically look like
for an X3D JSON loader?
<br class="">
<br class="">
Looking forward: seems like a group/community decision if we
want to specify a string array as X3D JSON default for #source
blocks.
<br class="">
</blockquote>
</blockquote>
<br class="">
all the best, Don
<br class="">
<br class="">
<fieldset class=""></fieldset>
<br class="">
<pre class="">_______________________________________________
x3d-public mailing list
<a href="mailto:x3d-public@web3d.org" target="_blank" class="">x3d-public@web3d.org</a>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" target="_blank" class="">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a>
</pre>
</blockquote>
<br class="">
<br class="">
<div class="">-- <br class="">
<font color="#333366" class="">
<font size="+1" class=""><b class="">Leonard Daly</b></font><br class="">
X3D Co-Chair<br class="">
Cloud Consultant<br class="">
President, Daly Realism - <i class="">Creating the Future</i>
</font></div>
</div>
<br class="">_______________________________________________<br class="">
x3d-public mailing list<br class="">
<a href="mailto:x3d-public@web3d.org" class="">x3d-public@web3d.org</a><br class="">
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank" class="">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br class="">
<br class=""></blockquote></div>
</div></blockquote></div><br class=""></div></body></html>