[x3d-public] x3d.py problem validating MFVec2f (non-specified crossSection) default value
John Carlson
yottzumm at gmail.com
Thu Jun 9 02:21:21 PDT 2022
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/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/20220609/4d27e828/attachment.html>
More information about the x3d-public
mailing list