[x3d-public] MFString in python x3d.py

John Carlson yottzumm at gmail.com
Wed Jul 19 15:00:12 PDT 2023


Here are the changes I've made to X3duomToX3dPythonPackage.xslt to make a
further advancement in JSON output (hopefully, I've changed nothing else).
I suggest running your unit tests on the results before distribution, or
tell me what ant targets to run.  I've provided the full stylesheet
(attached) at this point.

In particular, see the stuff I've done with JSONListHelper at a minimum.

The license under x3d-code/www.web3d.org/x3d/stylesheets/license.html on
sourceforge.net applies to my work.

The main advances are what I've done with Comments under head, and the
JSONListHelper sorting head statements by class, also used with MFNodes).
The rest is probably brace and comma twiddling, though I admit that head
looks a lot better than the rest, and I don't think that braces even match
up at this point.  The JSON output does not currently work with JSON
parsing at all, but it does create a pretty nice head.

I currently take output from x3djsonld.py (still under development, working
on round tripping JSON)  X3DJSONLD/src/main/python/x3djsonld.py at master ·
coderextreme/X3DJSONLD (github.com)
<https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py>

I would typically run x3djsonld.py like this, piping output from output to
remove the welcome header from x3d.py into tail to take it off, then
writing to a JSON file.

$ py x3djsonld.py HelloWorldProgramOutputCanonical.json | py |tail +2 | less

I like using Git for Bash/Git for Windows as my shell instead of cmd or
powershell.

Thanks!

John



On Wed, Jul 19, 2023 at 2:04 PM John Carlson <yottzumm at gmail.com> wrote:

> I have many changes to contribute to x3d.py JSON output.  I would not get
> carried away without my changes!
>
> I have the whole head statement worked out right now.  I have not had to
> make many changes to x3djson.py.
>
> Be aware that I spent a lot of time getting the Comment class working, at
> least initially, and I have a JSONListHelper function, which makes it easy
> to sort through children, I hope
>
> On Wed, Jul 19, 2023 at 8:31 AM Brutzman, Donald (Don) (CIV) <
> brutzman at nps.edu> wrote:
>
>> Thanks for tackling one of the hardest issues John.  Thanks for spot-on
>> analysis Vince.
>>
>>
>>
>> Recommendations to keep in mind:
>>
>>    1. Be very precise about your use of single-quote and double-quote
>>    characters.  Then your output is simple and correct.
>>    2. Slightly different handling rules for SFString and MFString
>>    values, based on Python [ list ] square brackets.
>>    3. Utility methods in x3d.py permit substituting a simple string for
>>    an MFString, but you have to be careful not to smash a list into a single
>>    value (as Vince points out).
>>
>>
>>
>> Excerpt from
>>
>>    - *X3D Example Archives: X3D4WA, X3D for Web Authors, Chapter 04
>>    Viewing Navigation, Navigation Info Example*
>>    -
>>    https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExampleIndex.html
>>    -
>>    https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNavigation/NavigationInfoExample.py
>>
>>
>>
>> Suggested python encoding excerpted with highlights, autogenerated:
>>
>>
>>
>>                # […]
>>
>>
>>
>>   Scene=Scene(
>>
>>     #  Because these NavigationInfo nodes are here in the parent scene,
>> the first one is bound at load time, and thus governs the active navigation
>> modes
>>
>>     #  Note that an author can control what choices a user has available,
>> and initial type selected, while the user can select among navigation
>> choices from available options
>>
>>     #  Author TODO: Experiment by swapping order of these NavigationInfo
>> nodes, first one is bound at load time
>>
>>     children=[
>>
>>     WorldInfo(title='NavigationInfo.x3d'),
>>
>>     NavigationInfo(DEF='DEFAULT_EXAMINE_FIRST'),
>>
>>     NavigationInfo(DEF='FLY_FIRST',type=*'"FLY" "ANY"'*),
>>
>>     NavigationInfo(DEF='SIT_TIGHT',type='"NONE"'),
>>
>>     #  Also note that this scene does not provide a way to select a
>> different NavigationInfo node during run time
>>
>>     Inline(url=["../HelloWorld.x3d",
>> https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.x3d
>> ,"../HelloWorld.wrl",*https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.wrl
>> <https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/HelloWorld.wrl>*
>> ])])
>>
>> ) # X3D model complete
>>
>>
>>
>> Checking on compilation and execution during unit tests:
>>
>>
>>
>>    -
>>    https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/build.python.all.log.txt
>>
>>
>>
>> ===================================
>>
>> create python:
>>
>> C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForWebAuthors/Chapter04ViewingNavigation//NavigationInfoExample.x3d
>> processing with X3dToPython stylesheet...
>>
>> C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForWebAuthors/Chapter04ViewingNavigation//NavigationInfoExample.py
>> self-validation tests...
>>
>> validate python:
>>
>> x3d.py package 4.0.64.0 loaded, have fun with X3D Graphics!
>>
>> Self-test diagnostics for NavigationInfoExample.py:
>>
>> meta info: Contained Inline scene has profile Immersive
>>
>> Python-to-XML well-formed XML document  test of XML output complete
>>
>> Python-to-XML X3D 3.3 schema validation test of XML output complete
>>
>> Python-to-VRML export of VRML output successful
>>
>> Python-to-JSON export of JSON output successful (under development)
>>
>> python NavigationInfoExample.py load and self-test diagnostics complete.
>>
>> ===================================
>>
>>
>>
>> However am seeing two errors:
>>
>>
>>
>>    1. Looks like the example excerpt is helpful but also has two
>>    mistakes:
>>
>>
>>
>>    - NavigationInfo(DEF='FLY_FIRST',type='"FLY" "ANY"'),
>>
>> should be
>>
>>    - NavigationInfo(DEF='FLY_FIRST',type=["FLY","ANY"]),
>>
>>
>>
>>    - Last value in url MFString list is *unquoted* (scroll way-way-way
>>    to the right to find it)
>>
>>
>>
>> I will work on the *X3dToPython.xslt* conversion stylesheet to address
>> these two conversion errors (be patient please).
>>
>>
>>
>> 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
>> https://faculty.nps.edu/brutzman
>>
>>
>>
>> -----Original Message-----
>> From: x3d-public <x3d-public-bounces at web3d.org> On Behalf Of Vincent
>> Marchetti
>> Sent: Wednesday, July 19, 2023 5:48 AM
>> To: John Carlson <yottzumm at gmail.com>; X3D-Public <x3d-public at web3d.org>
>> Subject: Re: [x3d-public] MFString in python x3d.py
>>
>>
>>
>> > On Jul 19, 2023, at 5:40 AM, John Carlson <yottzumm at gmail.com> wrote:
>>
>> >
>>
>> > First off, I realize x3d.py JSON is under development.
>>
>> >
>>
>> > I'm trying to output an MFString to JSON in x3d.py and I'm kind of
>> stuck?  I've been modifying x3d.py to JSON output, but I've spent way too
>> much time on it and it's dang frustrating.
>>
>> >
>>
>> > I have the code:
>>
>> >
>>
>> > ImageTexture(url=["images/X3dJavaSceneAccessInterfaceSaiLibrary.png","
>>
>> > http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA
>>
>> > ccessInterfaceSaiLibrary.png"])
>>
>> >
>>
>> > Don has:
>>
>> >
>>
>> > ImageTexture(url=["images/X3dJavaSceneAccessInterfaceSaiLibrary.png","
>>
>> > http://www.web3d.org/specifications/java/examples/images/X3dJavaSceneA
>>
>> > ccessInterfaceSaiLibrary.png"])
>>
>> >
>>
>>
>>
>> Yes, those two declarations of the ImageTexture node are the same.
>>
>> Can you show what the resulting json encoding of this node is, and what
>> problems are occurring with that encoding?
>>
>>
>>
>> > The same, right?
>>
>> >
>>
>> > I'm wondering if I should try this approach:
>>
>> >
>>
>> > NavigationInfo(type="\"EXAMINE\" \"FLY\" \"ANY\""),
>>
>> >
>>
>>
>>
>> I would recommend against this.
>>
>>
>>
>> This approach is mixing up the details of several different encodings at
>> once.
>>
>>
>>
>> The expression you have there, in particular the \" constructions, is
>> going to be interpreted according to the rules of the Python Lexical parser
>> https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
>>
>> and, if done just right, gives you the single python string with value
>> "EXAMINE""FLY""ANY"
>>
>> This string only works as to represent an MFString value, when used to
>> form an XML attribute in the XML encoding of X3D. It has little to do with
>> json.
>>
>>
>>
>> > John
>>
>> >
>>
>>
>>
>> Vince Marchetti
>>
>> _______________________________________________
>>
>> x3d-public mailing list
>>
>> x3d-public at web3d.org
>>
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230719/c95fd644/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: X3duomToX3dPythonPackage.xslt.zip
Type: application/x-zip-compressed
Size: 36675 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230719/c95fd644/attachment-0001.bin>


More information about the x3d-public mailing list