####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python .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.0',
  head=head(
    children=[
    meta(content='COMDESRON31',name='title'),
    meta(content='Thumb_COMDESRON31_x3d58303181148874576.jpg',name='Vizthumbnail'),
    meta(content='../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(info=["This Web3D World was created with Vizx3D, a Web3D authoring tool","www.vizx3d.com"],title='DESRON31Starboard'),
    Transform(DEF='dad_GROUND',
      children=[
      Group(DEF='GROUND',
        children=[
        Transform(DEF='dad_DESRON32',rotation=(-1,0,0,1.571),
          children=[
          Shape(DEF='DESRON32',
            appearance=Appearance(
              texture=ImageTexture(repeatS=False,repeatT=False,url=["COMDESRON31/newsealtest.jpg"]),
              textureTransform=TextureTransform(center=(-1.092,-.057),scale=(.912,.981),translation=(-.086,.009)),
              material=Material(DEF='Red_mat',diffuseColor=(1,0,0))),
            geometry=IndexedFaceSet(coordIndex=[0,32,1,-1,1,32,2,-1,2,32,3,-1,3,32,4,-1,4,32,5,-1,5,32,6,-1,6,32,7,-1,7,32,8,-1,8,32,9,-1,9,32,10,-1,10,32,11,-1,11,32,12,-1,12,32,13,-1,13,32,14,-1,14,32,15,-1,15,32,16,-1,16,32,17,-1,17,32,18,-1,18,32,19,-1,19,32,20,-1,20,32,21,-1,21,32,22,-1,22,32,23,-1,23,32,24,-1,24,32,25,-1,25,32,26,-1,26,32,27,-1,27,32,28,-1,28,32,29,-1,29,32,30,-1,30,32,31,-1,31,32,0,-1,34,65,33,-1,35,65,34,-1,36,65,35,-1,37,65,36,-1,38,65,37,-1,39,65,38,-1,40,65,39,-1,41,65,40,-1,42,65,41,-1,43,65,42,-1,44,65,43,-1,45,65,44,-1,46,65,45,-1,47,65,46,-1,48,65,47,-1,49,65,48,-1,50,65,49,-1,51,65,50,-1,52,65,51,-1,53,65,52,-1,54,65,53,-1,55,65,54,-1,56,65,55,-1,57,65,56,-1,58,65,57,-1,59,65,58,-1,60,65,59,-1,61,65,60,-1,62,65,61,-1,63,65,62,-1,64,65,63,-1,33,65,64,-1,0,34,33,-1,34,0,1,-1,1,35,34,-1,35,1,2,-1,2,36,35,-1,36,2,3,-1,3,37,36,-1,37,3,4,-1,4,38,37,-1,38,4,5,-1,5,39,38,-1,39,5,6,-1,6,40,39,-1,40,6,7,-1,7,41,40,-1,41,7,8,-1,8,42,41,-1,42,8,9,-1,9,43,42,-1,43,9,10,-1,10,44,43,-1,44,10,11,-1,11,45,44,-1,45,11,12,-1,12,46,45,-1,46,12,13,-1,13,47,46,-1,47,13,14,-1,14,48,47,-1,48,14,15,-1,15,49,48,-1,49,15,16,-1,16,50,49,-1,50,16,17,-1,17,51,50,-1,51,17,18,-1,18,52,51,-1,52,18,19,-1,19,53,52,-1,53,19,20,-1,20,54,53,-1,54,20,21,-1,21,55,54,-1,55,21,22,-1,22,56,55,-1,56,22,23,-1,23,57,56,-1,57,23,24,-1,24,58,57,-1,58,24,25,-1,25,59,58,-1,59,25,26,-1,26,60,59,-1,60,26,27,-1,27,61,60,-1,61,27,28,-1,28,62,61,-1,62,28,29,-1,29,63,62,-1,63,29,30,-1,30,64,63,-1,64,30,31,-1,31,33,64,-1,33,31,0,-1],creaseAngle=0.524,texCoordIndex=[0,32,1,-1,1,32,2,-1,2,32,3,-1,3,32,4,-1,4,32,5,-1,5,32,6,-1,6,32,7,-1,7,32,8,-1,8,32,9,-1,9,32,10,-1,10,32,11,-1,11,32,12,-1,12,32,13,-1,13,32,14,-1,14,32,15,-1,15,32,16,-1,16,32,17,-1,17,32,18,-1,18,32,19,-1,19,32,20,-1,20,32,21,-1,21,32,22,-1,22,32,23,-1,23,32,24,-1,24,32,25,-1,25,32,26,-1,26,32,27,-1,27,32,28,-1,28,32,29,-1,29,32,30,-1,30,32,31,-1,31,32,0,-1,15,32,16,-1,14,32,15,-1,13,32,14,-1,12,32,13,-1,11,32,12,-1,10,32,11,-1,9,32,10,-1,8,32,9,-1,7,32,8,-1,6,32,7,-1,5,32,6,-1,4,32,5,-1,3,32,4,-1,2,32,3,-1,1,32,2,-1,0,32,1,-1,31,32,0,-1,30,32,31,-1,29,32,30,-1,28,32,29,-1,27,32,28,-1,26,32,27,-1,25,32,26,-1,24,32,25,-1,23,32,24,-1,22,32,23,-1,21,32,22,-1,20,32,21,-1,19,32,20,-1,18,32,19,-1,17,32,18,-1,16,32,17,-1,33,67,66,-1,67,33,34,-1,34,68,67,-1,68,34,35,-1,35,69,68,-1,69,35,36,-1,36,70,69,-1,70,36,37,-1,37,71,70,-1,71,37,38,-1,38,72,71,-1,72,38,39,-1,39,73,72,-1,73,39,40,-1,40,74,73,-1,74,40,41,-1,41,75,74,-1,75,41,42,-1,42,76,75,-1,76,42,43,-1,43,77,76,-1,77,43,44,-1,44,78,77,-1,78,44,45,-1,45,79,78,-1,79,45,46,-1,46,80,79,-1,80,46,47,-1,47,81,80,-1,81,47,48,-1,48,82,81,-1,82,48,49,-1,49,83,82,-1,83,49,50,-1,50,84,83,-1,84,50,51,-1,51,85,84,-1,85,51,52,-1,52,86,85,-1,86,52,53,-1,53,87,86,-1,87,53,54,-1,54,88,87,-1,88,54,55,-1,55,89,88,-1,89,55,56,-1,56,90,89,-1,90,56,57,-1,57,91,90,-1,91,57,58,-1,58,92,91,-1,92,58,59,-1,59,93,92,-1,93,59,60,-1,60,94,93,-1,94,60,61,-1,61,95,94,-1,95,61,62,-1,62,96,95,-1,96,62,63,-1,63,97,96,-1,97,63,64,-1,64,98,97,-1,98,64,65,-1],
              coord=Coordinate(point=[(0,.05,-.8),(.16,.05,-.78),(.31,.05,-.74),(.44,.05,-.67),(.57,.05,-.57),(.67,.05,-.44),(.74,.05,-.31),(.78,.05,-.16),(.8,.05,0),(.78,.05,.16),(.74,.05,.31),(.67,.05,.44),(.57,.05,.57),(.44,.05,.67),(.31,.05,.74),(.16,.05,.78),(-0,.05,.8),(-.16,.05,.78),(-.31,.05,.74),(-.44,.05,.67),(-.57,.05,.57),(-.67,.05,.44),(-.74,.05,.31),(-.78,.05,.16),(-.8,.05,-0),(-.78,.05,-.16),(-.74,.05,-.31),(-.67,.05,-.44),(-.57,.05,-.57),(-.44,.05,-.67),(-.31,.05,-.74),(-.16,.05,-.78),(0,.05,0),(0,-.05,-.8),(.16,-.05,-.78),(.31,-.05,-.74),(.44,-.05,-.67),(.57,-.05,-.57),(.67,-.05,-.44),(.74,-.05,-.31),(.78,-.05,-.16),(.8,-.05,0),(.78,-.05,.16),(.74,-.05,.31),(.67,-.05,.44),(.57,-.05,.57),(.44,-.05,.67),(.31,-.05,.74),(.16,-.05,.78),(-0,-.05,.8),(-.16,-.05,.78),(-.31,-.05,.74),(-.44,-.05,.67),(-.57,-.05,.57),(-.67,-.05,.44),(-.74,-.05,.31),(-.78,-.05,.16),(-.8,-.05,-0),(-.78,-.05,-.16),(-.74,-.05,-.31),(-.67,-.05,-.44),(-.57,-.05,-.57),(-.44,-.05,-.67),(-.31,-.05,-.74),(-.16,-.05,-.78),(0,-.05,0)]),
              texCoord=TextureCoordinate(point=[(.5,1),(.598,.99),(.691,.962),(.778,.916),(.854,.854),(.916,.778),(.962,.691),(.99,.598),(1,.5),(.99,.402),(.962,.309),(.916,.222),(.854,.146),(.778,.084),(.691,.038),(.598,.01),(.5,0),(.402,.01),(.309,.038),(.222,.084),(.146,.146),(.084,.222),(.038,.309),(.01,.402),(0,.5),(.01,.598),(.038,.691),(.084,.778),(.146,.854),(.222,.916),(.309,.962),(.402,.99),(.5,.5),(1,1),(.969,1),(.938,1),(.906,1),(.875,1),(.844,1),(.813,1),(.781,1),(.75,1),(.719,1),(.688,1),(.656,1),(.625,1),(.594,1),(.563,1),(.531,1),(.5,1),(.469,1),(.438,1),(.406,1),(.375,1),(.344,1),(.313,1),(.281,1),(.25,1),(.219,1),(.188,1),(.156,1),(.125,1),(.094,1),(.063,1),(.031,1),(0,1),(1,0),(.969,0),(.938,0),(.906,0),(.875,0),(.844,0),(.813,0),(.781,0),(.75,0),(.719,0),(.688,0),(.656,0),(.625,0),(.594,0),(.563,0),(.531,0),(.5,0),(.469,0),(.438,0),(.406,0),(.375,0),(.344,0),(.313,0),(.281,0),(.25,0),(.219,0),(.188,0),(.156,0),(.125,0),(.094,0),(.063,0),(.031,0),(0,0)])))])])])])
)

### X3D model conversion complete ###

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

print('Self-test diagnostics for .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 .py load and self-test diagnostics complete.")
