####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python Two.py
#
# Python package x3d.py package is available on PyPI for import.
#   This approach simplifies Python X3D deployment and use.
#   https://pypi.org/project/x3d
#
# Installation:
#       pip install x3d
# or
#       python -m pip install x3d
#
# Developer options for loading x3d package in other Python programs:
#
#    from x3d import *  # preferred approach, terser source that avoids x3d.* class prefixes
#
# or
#    import x3d         # traditional way to subclass x3d package, all classes require x3d.* prefix,
#                       # but python source is very verbose, for example x3d.Material x3d.Shape etc.
#                       # X3dToPython.xslt stylesheet insertPackagePrefix=true supports this option.
#
# Project home page:    # X3D Python Scene Access Interface Library (X3DPSAIL)
#                       # https://www.web3d.org/x3d/stylesheets/python/python.html
# Conversion generator: # https://www.web3d.org/x3d/stylesheets/X3dToPython.xslt
#
####################################################################################################

from x3d import *

newModel=X3D(profile='Immersive',version='3.1',
  head=head(
    children=[
    meta(content='Two.x3d',name='title'),
    meta(content='3D Hull Number',name='description'),
    meta(content='Patrick Sullivan',name='creator'),
    meta(content='20 February 2006',name='created'),
    meta(content='20 October 2019',name='modified'),
    meta(content='1.0',name='version'),
    meta(content='Hull Numbers, ship markings',name='subject'),
    meta(content='https://www.web3d.org/x3d/content/examples/Savage/ModelDetailing/HullNumbers/Two.x3d',name='identifier'),
    meta(content='../../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='Two.x3d'),
    Group(DEF='Two',
      children=[
      Transform(DEF='dad_HullNumber2_copy13',
        children=[
        Shape(DEF='HullNumber2_copy13',
          appearance=Appearance(
            material=Material(DEF='white2_mat',ambientIntensity=1,diffuseColor=(1,1,1),shininess=0,specularColor=(1,1,1))),
          geometry=IndexedFaceSet(coordIndex=[0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,5,-1,0,5,6,-1,0,6,7,-1,0,7,1,-1,1,8,2,-1,1,7,9,-1,1,9,8,-1,8,9,10,-1,8,10,2,-1,2,10,11,-1,2,11,3,-1,3,12,13,-1,3,13,14,-1,3,14,15,-1,3,15,4,-1,3,11,16,-1,3,16,12,-1,12,17,18,-1,12,18,13,-1,12,16,19,-1,12,19,17,-1,17,20,18,-1,17,19,21,-1,17,21,20,-1,20,22,23,-1,20,23,18,-1,20,21,24,-1,20,24,22,-1,22,25,26,-1,22,26,23,-1,22,24,27,-1,22,27,25,-1,25,28,29,-1,25,29,26,-1,25,27,30,-1,25,30,28,-1,28,31,29,-1,28,30,32,-1,28,32,31,-1,31,33,34,-1,31,34,29,-1,31,32,35,-1,31,35,33,-1,33,36,37,-1,33,37,34,-1,33,35,38,-1,33,38,36,-1,36,39,37,-1,36,38,40,-1,36,40,39,-1,39,41,42,-1,39,42,37,-1,39,40,43,-1,39,43,41,-1,41,44,42,-1,41,43,45,-1,41,45,44,-1,44,46,47,-1,44,47,42,-1,44,45,48,-1,44,48,46,-1,46,49,50,-1,46,50,47,-1,46,48,51,-1,46,51,49,-1,49,52,53,-1,49,53,50,-1,49,51,54,-1,49,54,52,-1,52,55,56,-1,52,56,53,-1,52,54,57,-1,52,57,55,-1,55,58,56,-1,55,57,59,-1,55,59,58,-1,58,60,61,-1,58,61,56,-1,58,59,62,-1,58,62,60,-1,60,63,64,-1,60,64,65,-1,60,65,66,-1,60,66,61,-1,60,62,67,-1,60,67,63,-1,63,67,68,-1,63,68,64,-1,64,68,69,-1,64,69,65,-1,65,69,70,-1,65,70,66,-1,66,70,71,-1,66,71,61,-1,61,71,72,-1,61,72,56,-1,56,72,73,-1,56,73,53,-1,53,73,74,-1,53,74,50,-1,50,74,75,-1,50,75,47,-1,47,75,76,-1,47,76,42,-1,42,76,77,-1,42,77,37,-1,37,77,78,-1,37,78,34,-1,34,78,79,-1,34,79,29,-1,29,79,80,-1,29,80,26,-1,26,80,81,-1,26,81,23,-1,23,81,82,-1,23,82,18,-1,18,82,83,-1,18,83,13,-1,13,83,84,-1,13,84,14,-1,14,84,85,-1,14,85,15,-1,15,86,4,-1,15,85,87,-1,15,87,86,-1,86,87,5,-1,86,5,4,-1,6,10,7,-1,6,5,11,-1,6,11,10,-1,7,10,9,-1,11,84,83,-1,11,83,16,-1,11,5,85,-1,11,85,84,-1,16,83,82,-1,16,82,19,-1,19,82,21,-1,21,82,81,-1,21,81,24,-1,24,81,80,-1,24,80,27,-1,27,80,79,-1,27,79,30,-1,30,79,32,-1,32,79,78,-1,32,78,35,-1,35,78,77,-1,35,77,38,-1,38,77,40,-1,40,77,76,-1,40,76,43,-1,43,76,45,-1,45,76,75,-1,45,75,48,-1,48,75,74,-1,48,74,51,-1,51,74,73,-1,51,73,54,-1,54,73,72,-1,54,72,57,-1,57,72,59,-1,59,72,71,-1,59,71,62,-1,62,69,68,-1,62,68,67,-1,62,71,70,-1,62,70,69,-1,85,5,87,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(.51891,.01793,-.04102),(.51891,.18004,-.04102),(.20836,.34215,-.04102),(-.10219,.34215,-.04102),(-.07777,.01793,-.04102),(-.08779,.01475,-.2),(.50889,.01475,-.2),(.50889,.17686,-.2),(.51891,.34215,-.04102),(.50889,.33896,-.2),(.19834,.33896,-.2),(-.11221,.33896,-.2),(-.05104,.39073,-.04102),(-.4004,.52025,-.04102),(-.54994,.35045,-.04102),(-.63307,.18944,-.04102),(-.06106,.38755,-.2),(-.00697,.42906,-.04102),(-.1598,.71812,-.04102),(-.01699,.42588,-.2),(.05345,.47472,-.04102),(.04343,.47153,-.2),(.15367,.54527,-.04102),(-.01649,.83238,-.04102),(.14365,.54209,-.2),(.32445,.68199,-.04102),(.06383,.91539,-.04102),(.31443,.67881,-.2),(.43248,.80699,-.04102),(.10045,.98106,-.04102),(.42246,.80381,-.2),(.48998,.92906,-.04102),(.47996,.92588,-.2),(.50914,1.05699,-.04102),(.11266,1.04332,-.04102),(.49912,1.05381,-.2),(.49242,1.17406,-.04102),(.10057,1.10399,-.04102),(.4824,1.17087,-.2),(.44225,1.27916,-.04102),(.43223,1.27598,-.2),(.3629,1.36546,-.04102),(.06432,1.15514,-.04102),(.35288,1.36228,-.2),(.25865,1.42613,-.04102),(.24863,1.42295,-.2),(.11864,1.46202,-.04102),(.00975,1.18993,-.04102),(.10862,1.45884,-.2),(-.06801,1.47398,-.04102),(-.05726,1.20152,-.04102),(-.07803,1.4708,-.2),(-.24733,1.46141,-.04102),(-.12648,1.18956,-.04102),(-.25735,1.45823,-.2),(-.38295,1.42369,-.04102),(-.18178,1.15367,-.04102),(-.39297,1.42051,-.2),(-.4839,1.36241,-.04102),(-.49392,1.35923,-.2),(-.55922,1.27916,-.04102),(-.22218,1.08751,-.04102),(-.56924,1.27598,-.2),(-.61195,1.16649,-.04102),(-.64516,1.01695,-.04102),(-.44594,1.00084,-.04102),(-.24672,.98473,-.04102),(-.62197,1.16331,-.2),(-.65518,1.01377,-.2),(-.45596,.99766,-.2),(-.25674,.98154,-.2),(-.2322,1.08433,-.2),(-.1918,1.15049,-.2),(-.1365,1.18638,-.2),(-.06729,1.19834,-.2),(-.00027,1.18674,-.2),(.0543,1.15195,-.2),(.09055,1.10081,-.2),(.10264,1.04014,-.2),(.09043,.97788,-.2),(.05381,.91221,-.2),(-.02652,.8292,-.2),(-.16983,.71494,-.2),(-.41043,.51707,-.2),(-.55996,.34726,-.2),(-.64309,.18625,-.2),(-.67445,.01793,-.04102),(-.68447,.01475,-.2)])))]),
      Transform(DEF='dad_HullNumber2',
        children=[
        Shape(DEF='HullNumber2',
          appearance=Appearance(
            material=Material(DEF='main_mat',ambientIntensity=0.001,diffuseColor=(.001,.001,.001),shininess=0,specularColor=(.001,.001,.001))),
          geometry=IndexedFaceSet(coordIndex=[0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,5,-1,0,5,6,-1,0,6,7,-1,0,7,1,-1,1,8,2,-1,1,7,9,-1,1,9,8,-1,8,9,10,-1,8,10,2,-1,2,10,11,-1,2,11,3,-1,3,12,13,-1,3,13,14,-1,3,14,15,-1,3,15,4,-1,3,11,16,-1,3,16,12,-1,12,17,18,-1,12,18,13,-1,12,16,19,-1,12,19,17,-1,17,20,18,-1,17,19,21,-1,17,21,20,-1,20,22,23,-1,20,23,18,-1,20,21,24,-1,20,24,22,-1,22,25,26,-1,22,26,23,-1,22,24,27,-1,22,27,25,-1,25,28,29,-1,25,29,26,-1,25,27,30,-1,25,30,28,-1,28,31,29,-1,28,30,32,-1,28,32,31,-1,31,33,34,-1,31,34,29,-1,31,32,35,-1,31,35,33,-1,33,36,37,-1,33,37,34,-1,33,35,38,-1,33,38,36,-1,36,39,37,-1,36,38,40,-1,36,40,39,-1,39,41,42,-1,39,42,37,-1,39,40,43,-1,39,43,41,-1,41,44,42,-1,41,43,45,-1,41,45,44,-1,44,46,47,-1,44,47,42,-1,44,45,48,-1,44,48,46,-1,46,49,50,-1,46,50,47,-1,46,48,51,-1,46,51,49,-1,49,52,53,-1,49,53,50,-1,49,51,54,-1,49,54,52,-1,52,55,56,-1,52,56,53,-1,52,54,57,-1,52,57,55,-1,55,58,56,-1,55,57,59,-1,55,59,58,-1,58,60,61,-1,58,61,56,-1,58,59,62,-1,58,62,60,-1,60,63,64,-1,60,64,65,-1,60,65,66,-1,60,66,61,-1,60,62,67,-1,60,67,63,-1,63,67,68,-1,63,68,64,-1,64,68,69,-1,64,69,65,-1,65,69,70,-1,65,70,66,-1,66,70,71,-1,66,71,61,-1,61,71,72,-1,61,72,56,-1,56,72,73,-1,56,73,53,-1,53,73,74,-1,53,74,50,-1,50,74,75,-1,50,75,47,-1,47,75,76,-1,47,76,42,-1,42,76,77,-1,42,77,37,-1,37,77,78,-1,37,78,34,-1,34,78,79,-1,34,79,29,-1,29,79,80,-1,29,80,26,-1,26,80,81,-1,26,81,23,-1,23,81,82,-1,23,82,18,-1,18,82,83,-1,18,83,13,-1,13,83,84,-1,13,84,14,-1,14,84,85,-1,14,85,15,-1,15,86,4,-1,15,85,87,-1,15,87,86,-1,86,87,5,-1,86,5,4,-1,6,10,7,-1,6,5,11,-1,6,11,10,-1,7,10,9,-1,11,84,83,-1,11,83,16,-1,11,5,85,-1,11,85,84,-1,16,83,82,-1,16,82,19,-1,19,82,21,-1,21,82,81,-1,21,81,24,-1,24,81,80,-1,24,80,27,-1,27,80,79,-1,27,79,30,-1,30,79,32,-1,32,79,78,-1,32,78,35,-1,35,78,77,-1,35,77,38,-1,38,77,40,-1,40,77,76,-1,40,76,43,-1,43,76,45,-1,45,76,75,-1,45,75,48,-1,48,75,74,-1,48,74,51,-1,51,74,73,-1,51,73,54,-1,54,73,72,-1,54,72,57,-1,57,72,59,-1,59,72,71,-1,59,71,62,-1,62,69,68,-1,62,68,67,-1,62,71,70,-1,62,70,69,-1,85,5,87,-1],creaseAngle=0.524,
            coord=Coordinate(point=[(.66427,.00318,-.08798),(.66427,.16529,-.08798),(.35372,.3274,-.08798),(.04318,.3274,-.08798),(.06759,.00318,-.08798),(.05757,0,-.24696),(.65425,0,-.24696),(.65425,.16211,-.24696),(.66427,.3274,-.08798),(.65425,.32422,-.24696),(.3437,.32422,-.24696),(.03315,.32422,-.24696),(.09432,.37599,-.08798),(-.25504,.5055,-.08798),(-.40458,.3357,-.08798),(-.48771,.17469,-.08798),(.0843,.3728,-.24696),(.13839,.41432,-.08798),(-.01444,.70338,-.08798),(.12837,.41113,-.24696),(.19881,.45997,-.08798),(.18879,.45679,-.24696),(.29903,.53053,-.08798),(.12887,.81764,-.08798),(.28901,.52734,-.24696),(.46981,.66725,-.08798),(.20919,.90064,-.08798),(.45979,.66406,-.24696),(.57784,.79225,-.08798),(.24581,.96632,-.08798),(.56782,.78906,-.24696),(.63534,.91432,-.08798),(.62532,.91113,-.24696),(.6545,1.04225,-.08798),(.25802,1.02857,-.08798),(.64448,1.03906,-.24696),(.63778,1.15931,-.08798),(.24593,1.08924,-.08798),(.62776,1.15613,-.24696),(.58761,1.26441,-.08798),(.57759,1.26123,-.24696),(.50826,1.35072,-.08798),(.20968,1.14039,-.08798),(.49824,1.34753,-.24696),(.40402,1.41139,-.08798),(.39399,1.4082,-.24696),(.264,1.44728,-.08798),(.15511,1.17518,-.08798),(.25398,1.44409,-.24696),(.07735,1.45924,-.08798),(.0881,1.18678,-.08798),(.06733,1.45605,-.24696),(-.10197,1.44666,-.08798),(.01888,1.17481,-.08798),(-.11199,1.44348,-.24696),(-.23759,1.40895,-.08798),(-.03641,1.13893,-.08798),(-.24761,1.40576,-.24696),(-.33854,1.34767,-.08798),(-.34856,1.34448,-.24696),(-.41386,1.26441,-.08798),(-.07682,1.07276,-.08798),(-.42388,1.26123,-.24696),(-.46659,1.15174,-.08798),(-.49979,1.00221,-.08798),(-.30057,.98609,-.08798),(-.10136,.96998,-.08798),(-.47661,1.14856,-.24696),(-.50982,.99902,-.24696),(-.3106,.98291,-.24696),(-.11138,.9668,-.24696),(-.08684,1.06958,-.24696),(-.04644,1.13574,-.24696),(.00886,1.17163,-.24696),(.07807,1.18359,-.24696),(.14509,1.172,-.24696),(.19966,1.13721,-.24696),(.23591,1.08606,-.24696),(.248,1.02539,-.24696),(.23579,.96313,-.24696),(.19917,.89746,-.24696),(.11885,.81445,-.24696),(-.02446,.7002,-.24696),(-.26507,.50232,-.24696),(-.4146,.33252,-.24696),(-.49773,.17151,-.24696),(-.52909,.00318,-.08798),(-.53911,0,-.24696)])))])])])
)

### X3D model conversion complete ###

####################################################################################################
# Self-test diagnostics
####################################################################################################

print('Self-test diagnostics for Two.py:')
if        metaDiagnostics(newModel): # built-in utility method in X3D class
    print(metaDiagnostics(newModel)) # display meta info, hint, warning, error, TODO values in this model
# print('check newModel.XML() serialization...')
newModelXML= newModel.XML() # test export method XML() for exceptions during export
newModel.XMLvalidate()
# print(newModelXML) # diagnostic

try:
#   print('check newModel.VRML() serialization...')
    newModelVRML=newModel.VRML() # test export method VRML() for exceptions during export
    # print(prependLineNumbers(newModelVRML)) # debug
    print("Python-to-VRML export of VRML output successful", flush=True)
except Exception as err: # usually BaseException
    # https://stackoverflow.com/questions/18176602/how-to-get-the-name-of-an-exception-that-was-caught-in-python
    print("*** Python-to-VRML export of VRML output failed:", type(err).__name__, err)
    if newModelVRML: # may have failed to generate
        print(prependLineNumbers(newModelVRML, err.lineno))

try:
#   print('check newModel.JSON() serialization...')
    newModelJSON=newModel.JSON() # test export method JSON() for exceptions during export
#   print(prependLineNumbers(newModelJSON)) # debug
    print("Python-to-JSON export of JSON output successful (under development)")
except Exception as err: # usually SyntaxError
    print("*** Python-to-JSON export of JSON output failed:", type(err).__name__, err)
    if newModelJSON: # may have failed to generate
        print(prependLineNumbers(newModelJSON,err.lineno))

print("python Two.py load and self-test diagnostics complete.")
