[x3d-public] Python puzzle related to tupleSize in x3djsonld.py

Brutzman, Donald (Don) (CIV) brutzman at nps.edu
Mon Jun 13 07:52:43 PDT 2022


Initial definitions for a <field> declaration have default type SFString for
maximum flexibility of values.

 

Author definitions of a <field> declaration (within a Script or
ProtoInterface) might well vary, so the library needs to support such author
overrides.

 

Looking at X3D Examples is always a good approach to see what works.  The
build logs for various language conversions are helpfully verbose so that
you can see what the baseline versions are doing.

 

Have fun with X3D!  8)

 

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

 

From: John Carlson <yottzumm at gmail.com> 
Sent: Monday, June 13, 2022 7:09 AM
To: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>
Cc: Peitso, Loren (CIV) <lepeitso at nps.edu>; Vincent Marchetti
<vmarchetti at kshell.com>; X3D Graphics public mailing list
<x3d-public at web3d.org>
Subject: Re: Python puzzle related to tupleSize in x3djsonld.py

 

NPS WARNING: *external sender* verify before acting.

 

 

 

On Mon, Jun 13, 2022 at 7:59 AM John Carlson <yottzumm at gmail.com
<mailto:yottzumm at gmail.com> > wrote:

This temporary patch, just for MFVec3f fields, fixed the arc4.py output from
x3djsonld.py. 

 

More research is needed for broader issues and figure out if an x3djsonld.py
or x3d.py *patch* would be better.

 

$ git diff x3djsonld.py
diff --git a/src/main/python/x3djsonld.py b/src/main/python/x3djsonld.py
index ac2b7eacf..9d6bfc665 100644
--- a/src/main/python/x3djsonld.py
+++ b/src/main/python/x3djsonld.py
@@ -44,6 +44,8 @@ def parseArray(lead, trail, grandparent, parent, data,
indent, fieldType=None):
     if fieldType is None:
         fieldType = fieldInfo["fieldType"]
     tupleSize = fieldInfo["tupleSize"]
+    if fieldType == "MFVec3f":
+        tupleSize = 3
     #if tupleSize > 1:
     #    print("'''"+str(fieldType)+"
"+grandparent+"."+parent+"["+str(tupleSize)+"]'''", file=sys.stderr)
     for d in data:

 

Explanations as to why the patch is needed is welcome.  Vince?

 

Unpatched code is here:

 

X3DJSONLD/x3djsonld.py at master
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.co
m%2Fcoderextreme%2FX3DJSONLD%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fpython%2Fx3djson
ld.py&data=05%7C01%7Cbrutzman%40nps.edu%7Cd989f3064a794c20e28908da4d464dd1%7
C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637907261615365289%7CUnknown%7CT
WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
D%7C3000%7C%7C%7C&sdata=lfayOhKWKGukuH6obvZWuagQHjwxHAlT%2B9k5z%2F4rE%2FE%3D
&reserved=0> . coderextreme/X3DJSONLD (github.com)

 

Data file passed as an argument is here:

 

X3DJSONLD/arc4.json at master
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.co
m%2Fcoderextreme%2FX3DJSONLD%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fdata%2Farc4.json
&data=05%7C01%7Cbrutzman%40nps.edu%7Cd989f3064a794c20e28908da4d464dd1%7C6d93
6231a51740ea9199f7578963378e%7C0%7C0%7C637907261615365289%7CUnknown%7CTWFpbG
Zsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3
000%7C%7C%7C&sdata=5TVn5c1SGmH4TbTLFIA2LLrQLZdlttdnK%2BMXpfYuGAc%3D&reserved
=0> . coderextreme/X3DJSONLD (github.com)

 

Is it because the value field originally has type SFString?

 

>From field statement .value in X3DUOM:

 

            <field name="value"
                    type="SFString"
                    accessType="inputOutput"
                    description="Provide default initialization value for
this field variable (which may be re-initialized later by instantiation
value of a named ProtoInstance fieldValue)."/>
            <ContentModel>

 

Also, /class field/ in x3d.py has no TUPLE_SIZE method, and value field is

        ('value', '', FieldType.SFString, AccessType.inputOutput, 'field'),

 

confirming the X3DUOM.

 

It looks like I need some metamojo in x3djsonld.py

 

Help!

 

John

 

On Mon, Jun 13, 2022 at 7:24 AM John Carlson <yottzumm at gmail.com
<mailto:yottzumm at gmail.com> > wrote:

This patch fixed it, problem is in x3djsonld.py (not x3d.py that I know of).

 

diff --git a/src/main/python/net/coderextreme/data/arc4.py
b/src/main/python/net/coderextreme/data/arc4.py
index bdb08b22b..c7e330572 100644
--- a/src/main/python/net/coderextreme/data/arc4.py
+++ b/src/main/python/net/coderextreme/data/arc4.py
@@ -21,7 +21,7 @@ PositionInterpolator(DEF="DECLpoint_G1_PI1",
key=[float(0),float(1)], keyValue=[
 Script(DEF="DECLpoint_G1_MB1", field=[field(name="translation",
accessType="inputOutput", type="SFVec3f", value=(0,0,0)),
 field(name="old", accessType="inputOutput", type="SFVec3f", value=(0,0,0)),
 field(name="set_location", accessType="inputOnly", type="SFTime"),
-field(name="keyValue", accessType="inputOutput", type="MFVec3f",
value=[0,0,0,0,5,0])
+field(name="keyValue", accessType="inputOutput", type="MFVec3f",
value=[(0,0,0),(0,5,0)])
 ],
 #['', 'ecmascript:', '\t\tfunction set_location(value) {', '
old = translation;', '\t\t    translation = new SFVec3f(Math.random()*10-5,
Math.random()*10-5, Math.random()*10-5);', '                    keyValue =
new MFVec3f([old, translation]);', '\t\t    // Browser.println(keyValue);',
'\t\t}', '', '', '']
 ),
@@ -42,7 +42,7 @@ PositionInterpolator(DEF="DECLpoint_G2_PI1",
key=[float(0),float(1)], keyValue=[
 Script(DEF="DECLpoint_G2_MB1", field=[field(name="translation",
accessType="inputOutput", type="SFVec3f", value=(0,0,0)),
 field(name="old", accessType="inputOutput", type="SFVec3f", value=(0,0,0)),
 field(name="set_location", accessType="inputOnly", type="SFTime"),
-field(name="keyValue", accessType="inputOutput", type="MFVec3f",
value=[0,0,0,0,5,0])
+field(name="keyValue", accessType="inputOutput", type="MFVec3f",
value=[(0,0,0),(0,5,0)])
 ],
 #['', 'ecmascript:', '\t\tfunction set_location(value) {', '
old = translation;', '\t\t    translation = new SFVec3f(Math.random()*10-5,
Math.random()*10-5, Math.random()*10-5);', '                    keyValue =
new MFVec3f([old, translation]);', '\t\t    // Browser.println(keyValue);',
'\t\t}', '', '', '']
 ),

 

On Mon, Jun 13, 2022 at 7:19 AM John Carlson <yottzumm at gmail.com
<mailto:yottzumm at gmail.com> > wrote:

Follow-on report, I will look into arc4.py 

 

python ../python/x3djsonld.py ../data/arc4.json
../python/net/coderextreme/data/arc4.py
Traceback (most recent call last):
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 4961, in
assertValidMFVec3f
    MFVec3f(value)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9559, in
__init__
    self.value = value
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9581, in value
    value = [(x, y, z) for x, y, z in value]
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9581, in
<listcomp>
    value = [(x, y, z) for x, y, z in value]
TypeError: cannot unpack non-iterable int object

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File
"C:\Users\john\X3DJSONLD\src\main\python\net\coderextreme\data\arc4.py",
line 24, in <module>
    field(name="keyValue", accessType="inputOutput", type="MFVec3f",
value=[0,0,0,0,5,0])
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 12272, in
__init__
    self.value = value
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 12342, in
value
    assertValidFieldInitializationValue(self.name
<https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fself.name%
2F&data=05%7C01%7Cbrutzman%40nps.edu%7Cd989f3064a794c20e28908da4d464dd1%7C6d
936231a51740ea9199f7578963378e%7C0%7C0%7C637907261615365289%7CUnknown%7CTWFp
bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7
C3000%7C%7C%7C&sdata=U6wkh3VcbgIWUpFTyeRRxNj4%2FY6ceMgqZu8zuAJ%2Bapg%3D&rese
rved=0> , self.type, value, parent='field/@value')
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 5413, in
assertValidFieldInitializationValue
    assertValidMFVec3f(value)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 4965, in
assertValidMFVec3f
    raise X3DTypeError(str(value)[:100] + ' has type ' + str(type(value)) +
' but is not a valid MFVec3f') from error
x3d.X3DTypeError: [0, 0, 0, 0, 5, 0] has type <class 'list'> but is not a
valid MFVec3f
Error: ../python/net/coderextreme/data/arc4.py failed to parse

 

On Sun, Jun 12, 2022 at 8:40 PM Brutzman, Donald (Don) (CIV)
<brutzman at nps.edu <mailto:brutzman at nps.edu> > wrote:

John, thanks for various problem reports and example corrections, very
helpful.


Am happy to report integration of multiple fixes, and deployment of new
version.

 

a.	I eventually figured out how to fix the upgrade to Saxon HE 11.3 not
working, which required addition of xmlresolver jar to CLASSPATH entries.
This unblocked many mysterious build problems. Apparently followed a
solution path you had figured out too.  Details at

 

*	https://saxonica.plan.io/boards/3/topics/8478?r=8480
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsaxonica.
plan.io%2Fboards%2F3%2Ftopics%2F8478%3Fr%3D8480&data=05%7C01%7Cbrutzman%40np
s.edu%7Cd989f3064a794c20e28908da4d464dd1%7C6d936231a51740ea9199f7578963378e%
7C0%7C0%7C637907261615365289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJ
QIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=LnmBATXNZB
fI4XgRo9sUaP%2B3eA1F7MdgZLELCOADngI%3D&reserved=0> 
*	https://sourceforge.net/p/x3d/code/33141
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsourcefor
ge.net%2Fp%2Fx3d%2Fcode%2F33141&data=05%7C01%7Cbrutzman%40nps.edu%7Cd989f306
4a794c20e28908da4d464dd1%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637907
261615365289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJ
BTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=YrvLo2VaX580ISJgoI2%2B2eZN
jNt3xiIJdBAWmEeMbQE%3D&reserved=0> 

 

b.	You correctly reported missing HANIMVERSIONCHOICES and
assertValidHanimVersion() in the updated build.  Cause was our recently
disallowing HAnim version 1.0 in X3D4 since several internal design issues
were incompatible in HAnim 2.0 and thus X3D4.  Thus only HAnim version 2.0
is now allowed.  This was previously fixed in X3D Schema, now also fixed in
X3D DTD and X3D Tooltips and X3DUOM.  The generator stylesheet for x3d now
included enumeration lists with only one value, restoring these HANIM
version constructs.

*	Mantis 641: 26.3.2 - HAnim version number restriction
*	https://www.web3d.org/member-only/mantis/view.php?id=641
*
https://www.web3d.org/specifications/X3dDoctypeDocumentation4.0.html#HAnimHu
manoid
*
https://www.web3d.org/specifications/X3dSchemaDocumentation4.0/x3d-4.0_HAnim
Humanoid.html#Link45B
*
https://www.web3d.org/x3d/tooltips/X3dTooltips.html#HAnimHumanoid.version

 

c.	Also thanks for following report.  The x3d.py problem validating
default values for MFVec2f (such as Extrusion crossSection) and other MFVec
default values (such as Extrusion spine) is now fixed in the X3DPSAIL
autogeneration of x3d.py.  Excerpt follows, hopefully fixing the test cases
you have.  I believe such conversions from long arrays to arrays of typed
tuples is already working in X3dToJson.xslt conversions, so this resolution
improved x3d.py itself.

*	class Extrusion(_X3DGeometryNode):

[.]

('crossSection', [(1, 1), (1, -1), (-1, -1), (-1, 1), (1, 1)],
FieldType.MFVec2f, AccessType.initializeOnly, 'Extrusion'),

[.]

('spine', [(0, 0, 0), (0, 1, 0)], FieldType.MFVec3f,
AccessType.initializeOnly, 'Extrusion'),

[.]

crossSection = [(1, 1), (1, -1), (-1, -1), (-1, 1), (1, 1)] # default

[.]

spine = [(0, 0, 0), (0, 1, 0)] # default

*	etc.

 

d.	Not yet announced broadly, pending ISO/IEC confirmation of
acceptance, but have changed internal documentation links in X3DUOM and
related products for X3D4 Architecture to change from Committee Draft 1
(CD1) to Draft International Specification (DIS).  Note that all of the
effective specification prose is functionally identical, and all
Mantis-driven changes for 4.0 are resolved.  The only document modification
is removal of CSS-styled markings of proposed additions and proposed
deletions.

*
https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-CD1/Part01/
Architecture.html

to

*
https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-DIS/Part01/
Architecture.html

 

e.	Pylint log still reports some warnings, but "code has been rated at
9.97/10" and yesterday's overnight build to convert all X3D models in X3D
Examples Archive was pretty clean.  Steady improvement.  8)

*	https://www.web3d.org/x3d/stylesheets/python/build.pylint.log.txt
*	https://www.web3d.org/x3d/content/examples/build.python.all.log.txt

 

f.	Am using Python 3.10.4.  Have checked in all X3DPSAIL improvements
and deployed new x3d.py package version 4.0.64.1, passing acceptance tests
on this end.  Hopefully working well for you too.  The TODO section seems
mostly current, further improvements always welcome.

*	https://pypi.org/project/x3d
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpypi.org%
2Fproject%2Fx3d&data=05%7C01%7Cbrutzman%40nps.edu%7Cd989f3064a794c20e28908da
4d464dd1%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C637907261615365289%7CU
nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJ
XVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H4AV3p82Xw9RKZ8DWIW%2FnekQEusPV9uaTUw3IlYz
4AQ%3D&reserved=0> 
*	https://www.web3d.org/x3d/stylesheets/python/python.html
*	https://www.web3d.org/x3d/stylesheets/python/python.html#TODO

 

g.	Just noticed that Python itself issued a new release 3.10.5 a week
ago.  Will post again when that upgrade is tested.

*	Python 3.10.5. Release Date: June 6, 2022 
*	https://www.python.org/downloads/release/python-3105
<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.pytho
n.org%2Fdownloads%2Frelease%2Fpython-3105&data=05%7C01%7Cbrutzman%40nps.edu%
7Cd989f3064a794c20e28908da4d464dd1%7C6d936231a51740ea9199f7578963378e%7C0%7C
0%7C637907261615365289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV
2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XDVH%2BjVoStjZ7h
Va%2BRYpOj5S5shPXqp4r2sztu75s8g%3D&reserved=0> 

 

Again thanks for your excellent problem reports and example fixes.  Have fun
with X3D Python!  8)

 

all the best, Don

-- 

Don Brutzman  Naval Postgraduate School, Code USW/Br        brutzman at nps.edu
<mailto: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 <http://faculty.nps.edu/brutzman> 

 

From: John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com> > 
Sent: Thursday, June 9, 2022 2:21 AM
To: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu <mailto:brutzman at nps.edu>
>; X3D Graphics public mailing list <x3d-public at web3d.org
<mailto:x3d-public at web3d.org> >
Subject: x3d.py problem validating MFVec2f (non-specified crossSection)
default value

 

The most important thing is last in this email, problems validating default
MFVec2f crossSection field in x3d.py.  The rest of the email is background. 

 

To get x3d.py (x3djsonld.py) to handle HelloWorldProgramOutput.json,  I had
to remove Extrusions from the example, and change to Spheres. 

 

Below is the change to the example to make it work:

 

diff
/c/x3d-code/www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOut
put.json
<http://www.web3d.org/x3d/stylesheets/java/examples/HelloWorldProgramOutput.
json>  HelloWorldProgramOutput.json
1135c1135
<                 { "Extrusion":
---
>                 { "Sphere":
2392c2392
<                 { "Extrusion":
---
>                 { "Sphere":
2693c2693
< }
\ No newline at end of file
---
> }

============================================================

If one does not make the change to the JSON file, the following error
appears.  x3djsonld.py is in X3DJSONLD/src/main/python.

 

$ python x3djsonld.py
'''
x3d.py package 4.0.63.7 loaded, have fun with X3D Graphics!
'''
from x3d import *
from x3d import SFBool
print(
Traceback (most recent call last):
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 4668, in
assertValidMFVec2f
    MFVec2f(value)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9184, in
__init__
    self.value = value
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9206, in value
    value = [(x, y) for x, y, in value]
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 9206, in
<listcomp>
    value = [(x, y) for x, y, in value]
ValueError: too many values to unpack (expected 2)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 256, in
<module>
    print(parseObject("X3D", data, 0))
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 178, in
parseObject
    out += parseObject(k, v,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 163, in
parseObject
    out += parseObject(k, v,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 192, in
parseObject
    out += parseArray("[", "]", parent, key, v,indent+1, fieldType)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 57, in
parseArray
    out += parseObject(parent, d,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 178, in
parseObject
    out += parseObject(k, v,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 175, in
parseObject
    out += parseObject(k, v,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 178, in
parseObject
    out += parseObject(k, v,indent+1)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 125, in
parseObject
    fieldInfo = getField(parent, key)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3djsonld.py", line 14, in
getField
    cls = eval(grandparent)()
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 38948, in
__init__
    self.crossSection = crossSection
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 39005, in
crossSection
    assertValidMFVec2f(crossSection)
  File "C:\Users\john\X3DJSONLD\src\main\python\x3d.py", line 4672, in
assertValidMFVec2f
    raise X3DTypeError(str(value)[:100] + ' has type ' + str(type(value)) +
' but is not a valid MFVec2f') from error
x3d.X3DTypeError: [(1, 1, 1, -1, -1, -1, -1, 1, 1, 1)] has type <class
'list'> but is not a valid MFVec2f

============================================================

What's wrong with the is handling the Extrusion when crossSection is not
set, thus x3d.py:

 

    @crossSection.setter
    def crossSection(self, crossSection):
        if  crossSection is None:
            crossSection = [(1, 1, 1, -1, -1, -1, -1, 1, 1, 1)] # default
        assertValidMFVec2f(crossSection)
        self.__crossSection = crossSection

 

Note that crossSection's default is not correct.

 

Thanks for any fixes to x3d.py.  I will try to fix it now.

 

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220613/0163f5dd/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5353 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220613/0163f5dd/attachment-0001.p7s>


More information about the x3d-public mailing list