[x3d-public] MFString in python x3d.py
Brutzman, Donald (Don) (CIV)
brutzman at nps.edu
Wed Jul 19 06:31:36 PDT 2023
Thanks for tackling one of the hardest issues John. Thanks for spot-on
analysis Vince.
Recommendations to keep in mind:
a. Be very precise about your use of single-quote and double-quote
characters. Then your output is simple and correct.
b. Slightly different handling rules for SFString and MFString values,
based on Python [ list ] square brackets.
c. 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/Chapter04ViewingNaviga
tion/NavigationInfoExampleIndex.html
*
https://www.x3dgraphics.com/examples/X3dForWebAuthors/Chapter04ViewingNaviga
tion/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/X
3dForWebAuthors/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/examp
les/build.python.all.log.txt
===================================
create python:
C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForWebAuthors/Chapter04Vie
wingNavigation//NavigationInfoExample.x3d processing with X3dToPython
stylesheet...
C:\x3d-code\www.web3d.org\x3d\content\examples\X3dForWebAuthors/Chapter04Vie
wingNavigation//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:
d. 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 < <mailto:yottzumm at gmail.com>
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>
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>
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-l
iterals
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
<mailto:x3d-public at web3d.org> x3d-public at web3d.org
<http://web3d.org/mailman/listinfo/x3d-public_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/0d85f53a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5464 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230719/0d85f53a/attachment-0001.p7s>
More information about the x3d-public
mailing list