#################################################################################################### # # Invoking X3D model self-test: # # $ python SupertankerMediumDetail.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. # #################################################################################################### from x3d import * newModel=X3D(profile='Immersive',version='3.0', head=head( children=[ meta(content='SupertankerMediumDetail.x3d',name='title'), meta(content='Andrew Wiest',name='creator'), meta(content='6 May 2001',name='created'), meta(content='20 October 2019',name='modified'), meta(content='Supertanker model based on Exxon Valdez, medium detail.',name='description'), meta(content='https://savage.nps.edu/Savage/ShipsCivilian/Supertanker/SupertankerMediumDetail.x3d',name='identifier'), meta(content='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit',name='generator'), meta(content='../../license.html',name='license')]), Scene=Scene( children=[ WorldInfo(title='SupertankerMediumDetail.x3d'), Background(skyColor=[(.7,.8,.95)]), Viewpoint(description='Supertanker Medium Detail',orientation=(-0.429808,0.899118,0.0827735,0.422004),position=(150,50,250)), NavigationInfo(speed=10), Transform(DEF='ShipSUpertankerMasterNode', children=[ Transform(DEF='MainHull', children=[ Shape(DEF='HE1', appearance=Appearance( material=Material(DEF='GreyBlack',diffuseColor=(.3,.3,.3),shininess=.1,specularColor=(.1,.1,.1))), geometry=Extrusion(creaseAngle=.785,crossSection=[(169.8,0),(166.8,-9.1),(160.7,-15.2),(154.6,-21.2),(145.6,-24.3),(-103.1,-24.3),(-112.2,-21.3),(-118.3,-15.2),(-122.5,-9.3),(-124.3,0),(-122.5,9.3),(-118.3,15.2),(-112.2,21.3),(-103.1,24.3),(145.6,24.3),(154.6,21.2),(160.7,15.2),(166.8,9.1),(169.8,0)],endCap=False,scale=[(1,1),(1.018,1)],solid=False,spine=[(0,0,0),(0,9.1,0)])), Shape(DEF='HE2', appearance=Appearance( material=Material(DEF='Rustyred',diffuseColor=(.8,.3,.2),shininess=.1,specularColor=(.3,.1,.05))), geometry=Extrusion(creaseAngle=.785,crossSection=[(169.8,0),(166.8,-9.1),(160.7,-15.2),(154.6,-21.2),(145.6,-24.3),(-103.1,-24.3),(-112.2,-21.3),(-118.3,-15.2),(-122.5,-9.3),(-124.3,0),(-122.5,9.3),(-118.3,15.2),(-112.2,21.3),(-103.1,24.3),(145.6,24.3),(154.6,21.2),(160.7,15.2),(166.8,9.1),(169.8,0)],endCap=False,scale=[(0.66,0.7),(0.8,0.8),(1,1)],solid=False,spine=[(0.0,-19.66,0.0),(0,-15,0),(0,0,0)])), Transform(rotation=(0,1,0,.7),translation=(153,3,23.7), children=[ Shape( geometry=Text(string=["Exxon Valdez"], fontStyle=FontStyle(size=2.2,style_='BOLD')), appearance=Appearance( material=Material(diffuseColor=(1,1,1)))), Viewpoint(description='Starboard ship name',orientation=(-0.365482,0.92973,0.0449929,0.263289),position=(7,2,20))]), Transform(rotation=(0,1,0,2.47),translation=(153,3,-23.5), children=[ Shape( geometry=Text(string=["Exxon Valdez"], fontStyle=FontStyle(justify=["END","MIDDLE"],size=2.2,style_='BOLD')), appearance=Appearance( material=Material(diffuseColor=(1,1,1)))), Viewpoint(description='Port ship name',orientation=(0,1,0,.5),position=(7,3,20))])]), Transform(DEF='HE4BowUnderWater',scale=(.98,.999,.835),translation=(133,-.1,0), children=[ Shape(DEF='HE4', appearance=Appearance( material=Material(diffuseColor=(.8,.3,.2),shininess=.1,specularColor=(.3,.1,.05))), geometry=Extrusion(creaseAngle=1.3,crossSection=[(42.4,0),(40.6,-6.1),(36.3,-17.0),(30.3,-24.3),(-40.4,-24.3),(-40.4,24.3),(30.3,24.3),(36.3,17.0),(40.6,6.1),(42.4,0)],endCap=False,scale=[(0.8,0.8),(0.95,0.95),(1.0,1.0),(0.95,0.95),(0.8,0.7)],spine=[(0,-19.66,0),(0,-15,0),(0,-10,0),(0,-5,0),(0,6,0)]))]), Transform(DEF='HE3Topside',translation=(157.6,9.1,0), children=[ Shape(DEF='HE3', appearance=Appearance( material=Material(USE='GreyBlack')), geometry=Extrusion(beginCap=False,creaseAngle=.785,crossSection=[(-13.93,24.3),(-9.53,24.3),(-0.33,21.2),(5.87,15.2),(12.07,9.1),(15.17,0),(12.07,-9.1),(5.87,-15.2),(-0.33,-21.2),(-9.53,-24.3),(-13.93,-24.3)],endCap=False,orientation=[(0,0,1,0.86),(0,0,1,0.86)],solid=False,spine=[(0,-.2,0),(5,4.0,0)]))]), Transform(DEF='Deck',scale=(1.01,1.0,1.0),translation=(0,7,0), children=[ Shape( appearance=Appearance( material=Material(DEF='Rustyreddeck',diffuseColor=(.8,.3,.2),shininess=.1,specularColor=(.3,.1,.05))), geometry=IndexedFaceSet(coordIndex=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,0],creaseAngle=1.5, coord=Coordinate(point=[(169.8,0,0),(166.8,0,-9.1),(160.7,0,-15.2),(154.6,0,-21.2),(145.6,0,-24.3),(-103.1,0,-24.3),(-112.2,0,-21.3),(-118.3,0,-15.2),(-122.5,0,-9.3),(-124.3,0,0),(-122.5,0,9.3),(-118.3,0,15.2),(-112.2,0,21.3),(-103.1,0,24.3),(145.6,0,24.3),(154.6,0,21.2),(160.7,0,15.2),(166.8,0,9.1)]))), Transform(DEF='cranes', children=[ Transform(translation=(10,0,-20), children=[ Transform(DEF='portcrane', children=[ Transform( children=[ Transform(scale=(3,1,3),translation=(0,-1,0), children=[ Shape(DEF='yellowcylinderpiece', geometry=Cylinder(height=15,radius=.2), appearance=Appearance(DEF='yellowstuff', material=Material(diffuseColor=(1,.8,.3),shininess=.1,specularColor=(.2,.2,0))))]), Transform(rotation=(0,0,1,-1.571),scale=(2,.7,2),translation=(4,6,0), children=[ Shape(USE='yellowcylinderpiece')])])])]), Transform(DEF='stbdcrane',translation=(10,0,20), children=[ Transform(USE='portcrane')]), Transform(translation=(150,5,0), children=[ Shape(USE='yellowcylinderpiece'), Transform(translation=(0,-5,0), children=[ Shape( appearance=Appearance( material=Material(USE='Rustyreddeck')), geometry=Box(size=(10,5,10)))])]), Transform(translation=(40,0,-15), children=[ Shape(USE='yellowcylinderpiece')]), Transform(translation=(40,0,15), children=[ Shape(USE='yellowcylinderpiece')]), Transform(translation=(100,0,-15), children=[ Shape(USE='yellowcylinderpiece')]), Transform(translation=(100,0,15), children=[ Shape(USE='yellowcylinderpiece')])])]), Transform(DEF='superstructure', children=[ Transform(DEF='SS1',translation=(-86.9,12.1,0), children=[ Shape( appearance=Appearance( material=Material(DEF='offwhite',diffuseColor=(.98,.98,.98))), geometry=Box(size=(18.2,24.3,24.3)))]), Transform(DEF='SS2',translation=(-85.8,26.4,0), children=[ Shape( appearance=Appearance( material=Material(USE='offwhite')), geometry=Box(size=(17,4.2,12.1))), Viewpoint(description='Bridge view',orientation=(0,1,0,-1.57),position=(-30,10,0)), Transform(DEF='mastassembly',center=(-86,27,0), children=[ Transform(DEF='leftsidemast',rotation=(1,0,0,.3), children=[ Transform(DEF='leftfrontleg',rotation=(0,0,1,.6),translation=(2.2,0,-2), children=[ Shape(USE='yellowcylinderpiece')]), Transform(DEF='leftrearleg',translation=(-2,-1,-2), children=[ Shape(USE='yellowcylinderpiece')])]), Transform(DEF='rightsidemast',rotation=(1,0,0,-.3), children=[ Transform(DEF='rightrearleg',translation=(-2,-1,2), children=[ Shape(USE='yellowcylinderpiece')]), Transform(DEF='righfrontleg',rotation=(0,0,1,.6),translation=(2.2,0,2), children=[ Shape(USE='yellowcylinderpiece')])]), Transform(DEF='uppermastarea',translation=(-2.2,-3.4,0), children=[ Transform(rotation=(1,0,0,1.571),translation=(0,10,0), children=[ Transform(scale=(1,.5,1), children=[ Shape(USE='yellowcylinderpiece')])]), Transform(rotation=(0,1,0,1.571), children=[ Transform(rotation=(1,0,0,1.571),translation=(0,10,0), children=[ Transform(scale=(1,.5,1), children=[ Shape(USE='yellowcylinderpiece')])])]), Transform(scale=(1,.7,1),translation=(-4,12,0), children=[ Transform(scale=(1,.5,1), children=[ Shape(USE='yellowcylinderpiece')])]), Transform(scale=(1,1.1,1),translation=(0,9,0), children=[ Transform(scale=(1,.5,1), children=[ Shape(USE='yellowcylinderpiece')])] # OK ), Transform(rotation=(1,0,0,1.571),scale=(1,.4,1),translation=(0,13,0), children=[ Transform(scale=(1,.5,1), children=[ Shape(USE='yellowcylinderpiece')])] # OK )])])]), Transform(DEF='bridgewings',center=(-75.9,25.8,0),scale=(1,1.03,1),translation=(-5,-.2,0), children=[ Shape( appearance=Appearance( material=Material(USE='offwhite')), geometry=IndexedFaceSet(coordIndex=[0,1,2,3,4,5,6,7,-1,8,9,10,11,12,13,14,15,-1,0,1,9,8,-1,1,2,10,9,-1,2,3,11,10,-1,3,4,12,11,-1,4,5,13,12,-1,5,6,14,13,-1,6,7,15,14,-1,7,0,8,15],solid=False, coord=Coordinate(point=[(-72.8,27.3,-24.3),(-76.4,27.3,-24.3),(-78.9,27.3,-12.1),(-78.9,27.3,12.1),(-76.4,27.3,24.3),(-72.8,27.3,24.3),(-72.8,27.3,12.2),(-72.8,27.3,-12.2),(-72.8,25.3,-24.3),(-76.4,25.3,-24.3),(-78.9,24.3,-12.1),(-78.9,24.3,12.1),(-76.4,25.3,24.3),(-72.8,25.3,24.3),(-72.8,24.3,12.2),(-72.8,24.3,-12.2)]))), Transform(DEF='antennas',translation=(-76,29,0), children=[ Transform(translation=(0,0,10), children=[ Transform(DEF='antennanode', children=[ Shape( geometry=Cone(DEF='genericantenna',bottomRadius=.1,height=20), appearance=Appearance( material=Material(USE='offwhite')))])]), Transform(translation=(0,0,-10), children=[ Transform(USE='antennanode')]), Transform(scale=(1,.5,1),translation=(0,4,20), children=[ Transform(USE='antennanode')]), Transform(scale=(1,.5,1),translation=(0,4,-20), children=[ Transform(USE='antennanode')]), Viewpoint(description='look at the masts',orientation=(-0.413724,0.810966,0.413724,1.77881),position=(40,70,0))]), Transform(DEF='radar',translation=(-77,28,5), children=[ Transform(DEF='radarPost', children=[ Shape( geometry=Cylinder(bottom=False,height=5,radius=.2,top=False), appearance=Appearance(USE='yellowstuff'))]), Transform(DEF='RadarHousing',translation=(0,3,0), children=[ Transform(translation=(0,.5,0), children=[ Shape( geometry=Sphere(), appearance=Appearance( material=Material(USE='offwhite')))]), Transform( children=[ Shape( geometry=Cylinder(height=1.2,top=False), appearance=Appearance( material=Material(USE='offwhite')))])])])]), Transform(DEF='leftsupport',translation=(-80.8,12.1,-18.2), children=[ Shape(DEF='bridgewingsupport', appearance=Appearance( material=Material(USE='offwhite')), geometry=Cylinder(bottom=False,height=24.9,radius=.5,top=False))]), Transform(DEF='rightsupport',translation=(-80.8,12.1,18.2), children=[ Shape(USE='bridgewingsupport')]), Transform(DEF='SS3',translation=(-89.9,12.1,0), children=[ Shape( appearance=Appearance( material=Material(USE='offwhite')), geometry=Box(size=(12.2,24.3,28.3)))]), Transform(DEF='smokestackbase',translation=(-109,9.1,0), children=[ Shape( appearance=Appearance( material=Material(USE='offwhite')), geometry=Box(size=(12.1,14,20)))]), Transform(DEF='smokestack', children=[ Shape( appearance=Appearance(DEF='smakestackblack', material=Material(diffuseColor=(.1,.1,.1),shininess=.3,specularColor=(.1,.1,.1))), geometry=Extrusion(crossSection=[(4.85,-6.1),(-6.1,-6.1),(-6.1,6.1),(4.85,6.1),(4.85,-6.1)],scale=[(.8,.8),(.6,.6)],spine=[(-108,16,0),(-107.5,32,0)])), Transform(DEF='smokestackexhaust',translation=(-107,33,0), children=[ Shape( geometry=Cylinder(height=4,radius=1.8), appearance=Appearance(USE='smakestackblack'))])])])])]) ) # X3D model complete #################################################################################################### # Self-test diagnostics #################################################################################################### print('Self-test diagnostics for SupertankerMediumDetail.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 SupertankerMediumDetail.py load and self-test diagnostics complete.")