[x3d-public] Possible issue with X3dToPython.xslt, newly tested file from X3D4WA: need x3d.py python support for Script CDATA

John Carlson yottzumm at gmail.com
Tue Jan 11 06:08:50 PST 2022


Aye, I've been working with #sourceText for a long time. I wasn't aware 
that it wasn't already addressed.  I'm sure there's many references all 
over my code and examples. Just recall it applies to shaders too! We 
don't have too many examples of shaders in the archives, but it impacts 
me individually a lot.  Also be aware that any changes to #sourceText 
affect things like JSONParser.js in X_ITE and X3DOM!

For a flavor of the impact if modifying #sourceText:

~/x_ite$ find . -type f -print0 -name '*js'|xargs -0 grep -l sourceText
./src/x_ite/Parser/JSONParser.js
./dist/x_ite.min.js
./dist/x_ite.js

~/x3dom$ find . -type f -print0 |xargs -0 grep sourceText
./src/util/json/JSONParser.js:        else if ( key === "#sourceText" )
./src/util/json/PrototypeExpander.js:            newobject[ p ][ 
"#sourceText" ] = data.split( /\r?\n/ );

~/X3DJSONLD/src/main/node$ grep -l sourceText *.js
AframeSerializer.js
DOM2JSONSerializer.js
JSONSerializer.js
loader-bundle.js
PrototypeExpander.js
Script.js
Standard.js
test_json.js
Three2Serializer.js
X3DJSONLD.js


~/X3DJSONLD/src/main/python$ grep -l sourceText *.py
dom2json.py
etgenerateJSONschema2019-09.py
etgenerateJSONschema2020-12.py
etgenerateJSONschema.py

_/*Please provide an adequate and informed migration path if 
X3dToJson.xslt is modified.*/_

Thanks!

John

On 1/11/22 01:03, Brutzman, Donald (Don) (CIV) wrote:
> 1. Following some initial testing, am happy to report that this approach to embed source code in Script nodes seems consistently feasible for X3DUOM, Python, Java and X3D Ontology all at once.
>
> It will take a little work to fully implement, but it should improve the expressive power (meaning "fix a hole") in each of our programming-language bindings.
>
> ------
>
> 2. In some sense embedding script code is already possible - you can put such a program in first string contained in a Script url list - but in practice that tends to be quite difficult because then all sorts of obfuscating escaping of special characters has to take place.
>
> So having a separate place for source-code blocks is very helpful.  The X3D Architecture recognizes this possibility and defines corresponding behaviors.  Further details can be found in X3D XML Encoding.
>
> * X3D4 Architecture, clause 19 Scripting component, 29.4.1 Script
> *https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-CD1/Part01/components/scripting.html#Script
>
> * X3D4 Architecture, 9.2.3 Scripting language protocols
>     https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-CD1/Part01/components/networking.html#ScriptingLanguageProtocols
>
> * X3D XML Encoding, Clause 4 Concepts, 4.3.13 Encapsulating Script node code
>     https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/concepts.html#EncapsulatingScriptNodeCode
>
>     "If both a url field and a CDATA clause are encountered, the url field is processed first. Thus, the CDATA construct can also be considered equivalent to one additional value appended to the url MFString array. This ordering allows an online script code url to take priority over fallback default script code in the CDATA construct. This ordering also allows run-time updates if a viewer is connected to the network, if so desired by the originating author."
>
> ------
>
> 3. Next - naming.  "CDATA" is pretty obscure as a field name, especially since that is an XML datatype (for Character Data).  Thus am thinking "sourceCode" might be a better name...  what do you think?
>
> The ability to embed safe scripting code within any X3D Script is a powerful capability that also improves security possibilities for advanced X3D... it is easier to secure and safely transport an embedded script than it is to have multiple files handled safely.
>
> John, it looks like we already did something just like this in the JSON encoding, we called it "sourceText", excerpt follows.  (Excessive string quoting was necessary to pass JSON parsing rules for multiline text.)
>
> ----------------------------------------------------------------------------------------------------------------------------------------------
> *https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter14Prototypes/MaterialModulator.json
>
>                      { "Script":
>                        {
> [....]
>                          "#sourceText":[
> "",
> "",
> "ecmascript:",
> "function initialize ()",
> "{",
> "    newColor = diffuseColor; // start with original color",
> "}",
> "function clockTrigger (timeValue)",
> "{",
> "    if (!enabled) return;",
> "    red   = newColor.r;",
> "    green = newColor.g;",
> "    blue  = newColor.b;",
> "",
> "    // note different modulation rates for each color component, % is modulus operator",
> "    newColor = new SFColor ((red + 0.02) % 1, (green + 0.03) % 1, (blue + 0.04) % 1);",
> "\tif (enabled)",
> "\t{",
> "\t\tBrowser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\n');",
> "\t}",
> "}",
> "function set_enabled (newValue)",
> "{",
> "\tenabled = newValue;",
> "}",
> "",
> ""
> ]
> ----------------------------------------------------------------------------------------------------------------------------------------------
> Which in the .x3d XML CDATA simply looks like
>
>          <Script DEF='MaterialModulatorScript'>
>            <field accessType='inputOutput' name='enabled' type='SFBool'/>
>            <field accessType='inputOutput' name='diffuseColor' type='SFColor'/>
>            <field accessType='outputOnly' name='newColor' type='SFColor'/>
>            <field accessType='inputOnly' name='clockTrigger' type='SFTime'/>
>            <IS>
>              <connect nodeField='enabled' protoField='enabled'/>
>              <connect nodeField='diffuseColor' protoField='diffuseColor'/>
>            </IS>
>            <![CDATA[
> ecmascript:
> function initialize ()
> {
>      newColor = diffuseColor; // start with original color
> }
> function clockTrigger (timeValue)
> {
>      if (!enabled) return;
>      red   = newColor.r;
>      green = newColor.g;
>      blue  = newColor.b;
>      
>      // note different modulation rates for each color component, % is modulus operator
>      newColor = new SFColor ((red + 0.02) % 1, (green + 0.03) % 1, (blue + 0.04) % 1);
> 	if (enabled)
> 	{
> 		Browser.print ('diffuseColor=(' + red +',' + green + ',' + blue + ') newColor=' + newColor.toString() + '\n');
> 	}
> }
> function set_enabled (newValue)
> {
> 	enabled = newValue;
> }
> ]]>
>          </Script>
>
> ----------------------------------------------------------------------------------------------------------------------------------------------
>
> So this possibility is a cool prospect, again thanks for flagging it.  I'll work further on X3DUOM and Python, Java, OWL compatibility next.
>
> Have fun with X3D!  8)
>
> all the best, Don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220111/c81abd10/attachment.html>


More information about the x3d-public mailing list