[x3d-public] x3d.py users...quick question and answer. SFColor...MFColorRGBA smoke tests
    Brutzman, Donald (Don) (CIV) 
    brutzman at nps.edu
       
    Mon Jan 31 14:19:21 PST 2022
    
    
  
Hi John.  Answers to many x3d.py syntax questions can be found in the Smoke Tests example:
  *   https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/python/examples/PythonX3dSmokeTests.py
For example, SFColor takes three parameters and SFColorRGBA takes four parameters.  Excerpted source and results follow.
p.s.  NOW HEAR THIS department:  draconian intolerance of incorrect invocations is what makes Python strictness so reliable and repeatable.  Enjoy!   8)
print ('- - - - - - - - - -')
print ('SFColor().NAME()         = ' +     SFColor().NAME());
print ('SFColor().DEFAULT_VALUE()= ' + str(SFColor().DEFAULT_VALUE()));
print ('SFColor().ARRAY_TYPE()   = ' + str(SFColor().ARRAY_TYPE()));
print ('SFColor().TUPLE_SIZE()   = ' + str(SFColor().TUPLE_SIZE()));
print ('SFColor().REGEX_XML()    = ' + str(SFColor().REGEX_XML()));
print ('SFColor().TOOLTIP_URL()  = ' + str(SFColor().TOOLTIP_URL()));
test = SFColor()
#test.value = (0, .5, 1, 5) # 4 elements, illegal tupleSize
#test.value = (0, .5, 5)    # illegal value 5
test = SFColor((0, .5, 1)) # commas required
test.value = (0, .5, 1)    # commas required
print ('SFColor test       =', test)
print ('SFColor test.value =', test.value)
print ('SFColor test.XML() =', test.XML())
print ('SFColor test.VRML()=', test.VRML())
print ('SFColor test.JSON()=', test.JSON())
print ('SFColor     isValidSFColor(test)=' + str(isValidSFColor(test)), flush=True)
print ('SFColor assertValidSFColor(test)'); assertValidSFColor(test)
print ('- - - - - - - - - -')
print ('MFColor().NAME()         = ' +     MFColor().NAME());
print ('MFColor().DEFAULT_VALUE()= ' + str(MFColor().DEFAULT_VALUE()));
print ('MFColor().ARRAY_TYPE()   = ' + str(MFColor().ARRAY_TYPE()));
print ('MFColor().TUPLE_SIZE()   = ' + str(MFColor().TUPLE_SIZE()));
print ('MFColor().REGEX_XML()    = ' + str(MFColor().REGEX_XML()));
print ('MFColor().TOOLTIP_URL()  = ' + str(MFColor().TOOLTIP_URL()));
test = MFColor()
test = MFColor([(0, .5, 1),(1, .5, 0)]) # commas required
test.value =   [(0, .5, 1),(1, .5, 0)]  # commas required
# test.value = (0, .5, 1, 5)    # illegal value 5
# test = MFColor([0, .5, 1, 1, .5, 0]) # TODO
print ('MFColor test       =', test)
print ('MFColor test.value =', test.value)
print ('MFColor test.XML() =', test.XML())
print ('MFColor test.VRML()=', test.VRML())
print ('MFColor test.JSON()=', test.JSON())
print ('MFColor     isValidMFColor(test)=' + str(isValidMFColor(test)), flush=True)
print ('MFColor assertValidMFColor(test)'); assertValidMFColor(test)
print ('- - - - - - - - - -')
print ('SFColorRGBA().NAME()         = ' +     SFColorRGBA().NAME());
print ('SFColorRGBA().DEFAULT_VALUE()= ' + str(SFColorRGBA().DEFAULT_VALUE()));
print ('SFColorRGBA().ARRAY_TYPE()   = ' + str(SFColorRGBA().ARRAY_TYPE()));
print ('SFColorRGBA().TUPLE_SIZE()   = ' + str(SFColorRGBA().TUPLE_SIZE()));
print ('SFColorRGBA().REGEX_XML()    = ' + str(SFColorRGBA().REGEX_XML()));
print ('SFColorRGBA().TOOLTIP_URL()  = ' + str(SFColorRGBA().TOOLTIP_URL()));
test = SFColorRGBA()
test = SFColorRGBA((0, .5, 1, 0.75)) # commas required
test.value = (0, .5, 1, 0.75)    # commas required
print ('SFColorRGBA test       =', test)
print ('SFColorRGBA test.value =', test.value)
print ('SFColorRGBA test.XML() =', test.XML())
print ('SFColorRGBA test.VRML()=', test.VRML())
print ('SFColorRGBA test.JSON()=', test.JSON())
print ('SFColorRGBA     isValidSFColorRGBA(test)=' + str(isValidSFColorRGBA(test)), flush=True)
print ('SFColorRGBA assertValidSFColorRGBA(test)'); assertValidSFColorRGBA(test)
print ('MFColorRGBA().NAME()         = ' +     MFColorRGBA().NAME());
print ('MFColorRGBA().DEFAULT_VALUE()= ' + str(MFColorRGBA().DEFAULT_VALUE()));
print ('MFColorRGBA().ARRAY_TYPE()   = ' + str(MFColorRGBA().ARRAY_TYPE()));
print ('MFColorRGBA().TUPLE_SIZE()   = ' + str(MFColorRGBA().TUPLE_SIZE()));
print ('MFColorRGBA().REGEX_XML()    = ' + str(MFColorRGBA().REGEX_XML()));
print ('MFColorRGBA().TOOLTIP_URL()  = ' + str(MFColorRGBA().TOOLTIP_URL()));
test = MFColorRGBA()
test = MFColorRGBA([(0, .5, 1, 0.75),(1, .5, 0, 0.75)]) # commas required
test.value =   [(0, .5, 1, 0.75),(1, .5, 0, 0.75)]  # commas required
# test = MFColorRGBA( 0, .5, 1, 0.75, 1, .5, 0, 0.75 ) # TODO
print ('MFColorRGBA test       =', test)
print ('MFColorRGBA test.value =', test.value)
print ('MFColorRGBA test.XML() =', test.XML())
print ('MFColorRGBA test.VRML()=', test.VRML())
print ('MFColorRGBA test.JSON()=', test.JSON())
print ('MFColorRGBA     isValidMFColorRGBA(test)=' + str(isValidMFColorRGBA(test)), flush=True)
print ('MFColorRGBA assertValidMFColorRGBA(test)'); assertValidMFColorRGBA(test)
print ('- - - - - - - - - -')
Results are found at
  *   https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/python/build.examples.log.txt
- - - - - - - - - -
SFColor().NAME()         = SFColor
SFColor().DEFAULT_VALUE()= (0, 0, 0)
SFColor().ARRAY_TYPE()   = False
SFColor().TUPLE_SIZE()   = 3
SFColor().REGEX_XML()    = (\s)*(([+]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)+){2}([+]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)*
SFColor().TOOLTIP_URL()  = https://www.web3d.org/x3d/tooltips/X3dTooltips.html#SFColor
SFColor test       = (0, 0.5, 1)
SFColor test.value = (0, 0.5, 1)
SFColor test.XML() = 0 0.5 1
SFColor test.VRML()= 0 0.5 1
SFColor test.JSON()= 0 0.5 1
SFColor     isValidSFColor(test)=True
SFColor assertValidSFColor(test)
- - - - - - - - - -
MFColor().NAME()         = MFColor
MFColor().DEFAULT_VALUE()= []
MFColor().ARRAY_TYPE()   = True
MFColor().TUPLE_SIZE()   = 3
MFColor().REGEX_XML()    = (\s)*((([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)+){2}([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s*,?\s*)*
MFColor().TOOLTIP_URL()  = https://www.web3d.org/x3d/tooltips/X3dTooltips.html#MFColor
MFColor test       = [(0, 0.5, 1), (1, 0.5, 0)]
MFColor test.value = [(0, 0.5, 1), (1, 0.5, 0)]
MFColor test.XML() = 0 0.5 1 1 0.5 0
MFColor test.VRML()= [0 0.5 1 1 0.5 0]
MFColor test.JSON()= 0 0.5 1 1 0.5 0
MFColor     isValidMFColor(test)=True
MFColor assertValidMFColor(test)
- - - - - - - - - -
SFColorRGBA().NAME()         = SFColorRGBA
SFColorRGBA().DEFAULT_VALUE()= (0, 0, 0, 0)
SFColorRGBA().ARRAY_TYPE()   = False
SFColorRGBA().TUPLE_SIZE()   = 4
SFColorRGBA().REGEX_XML()    = (\s)*(([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)+){3}([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)*
SFColorRGBA().TOOLTIP_URL()  = https://www.web3d.org/x3d/tooltips/X3dTooltips.html#SFColorRGBA
SFColorRGBA test       = (0, 0.5, 1, 0.75)
SFColorRGBA test.value = (0, 0.5, 1, 0.75)
SFColorRGBA test.XML() = 0 0.5 1 0.75
SFColorRGBA test.VRML()= 0 0.5 1 0.75
SFColorRGBA test.JSON()= 0 0.5 1 0.75
SFColorRGBA     isValidSFColorRGBA(test)=True
SFColorRGBA assertValidSFColorRGBA(test)
MFColorRGBA().NAME()         = MFColorRGBA
MFColorRGBA().DEFAULT_VALUE()= []
MFColorRGBA().ARRAY_TYPE()   = True
MFColorRGBA().TUPLE_SIZE()   = 4
MFColorRGBA().REGEX_XML()    = (\s)*((([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)(\s)+){3}([+-]?((0(\.[0-9]*)?|\.[0-9]+)|1(\.0*)?)([Ee][+-]?[0-9]+)?)\s*,?\s*)*
MFColorRGBA().TOOLTIP_URL()  = https://www.web3d.org/x3d/tooltips/X3dTooltips.html#MFColorRGBA
MFColorRGBA test       = [(0, 0.5, 1, 0.75), (1, 0.5, 0, 0.75)]
MFColorRGBA test.value = [(0, 0.5, 1, 0.75), (1, 0.5, 0, 0.75)]
MFColorRGBA test.XML() = 0 0.5 1 0.75 1 0.5 0 0.75
MFColorRGBA test.VRML()= [0 0.5 1 0.75 1 0.5 0 0.75]
MFColorRGBA test.JSON()= 0 0.5 1 0.75 1 0.5 0 0.75
MFColorRGBA     isValidMFColorRGBA(test)=True
MFColorRGBA assertValidMFColorRGBA(test)
- - - - - - - - - -
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, January 31, 2022 1:21 PM
To: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>; Vincent Marchetti <vmarchetti at kshell.com>; X3D Graphics public mailing list <x3d-public at web3d.org>
Subject: x3d.py users...quick question and answer.
I'm guessing I have to so something like
value=SFColor((0.9,0.9,0.9))
??  No!
I will look through examples of generated JSON from X3dToPython.xslt, found in flower2.py.  I will try the following:
flowers2.py:          field(name='diffuseColor',accessType='inputOutput',type='SFColor',value=(1,0.5,0)),
flowers2.py:          field(name='specularColor',accessType='inputOutput',type='SFColor',value=(1,0.5,0)),
Looks like it works, for anyone confused why you can't pass 3 (actually 4) values to SFColor!
I'm approaching near completion of x3djsonld.py, except for HAnim it appears.  I might call you Joe, so prepare to video (on Zoom?).  I haven't looked into these issues yet, so let me do that first.
X3dToPython.xslt is still preferred, as I haven't handled children (comments) and value in Shape and Text.
Note:  I am reading in JSON.
Traceback (most recent call last):
  File "C:\Users\john\X3DJSONLD\src\main\python\net\coderextreme\data\ViewFrustumPrototype.py", line 17, in <module>
    field(name="lineColor", accessType="inputOutput", appinfo="RGB color of ViewFrustum outline, default value 0.9 0.9 0.9", type="SFColor", value=SFColor(0.9,0.9,0.9)),
TypeError: SFColor.__init__() takes from 1 to 2 positional arguments but 4 were given
Error: ../python/net/coderextreme/data/ViewFrustumPrototype.py failed to parse
python ../python/x3djsonld.py ../data/x3dconnector.json ../python/net/coderextreme/data/x3dconnector.py
../python/net/coderextreme/data/x3dconnector.py
python ../python/x3djsonld.py ../data/x3dconnectorProto.json ../python/net/coderextreme/data/x3dconnectorProto.py
../python/net/coderextreme/data/x3dconnectorProto.py
python ../python/x3djsonld.py ../data/X3dHeaderPrototypeSyntaxExamples.json ../python/net/coderextreme/data/X3dHeaderPrototypeSyntaxExamples.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220131/d4a239f2/attachment-0001.html>
    
    
More information about the x3d-public
mailing list