####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python l_tarsal_distal_phalanx_1.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='Interactive',version='4.0',
  head=head(
    children=[
    meta(content='l_tarsal_distal_phalanx_1.x3d',name='title'),
    meta(content='bone in foot',name='description'),
    meta(content='Don Brutzman, Joe Williams, John Carlson, Damon Hernandez',name='creator'),
    meta(content='Don Brutzman',name='translator'),
    meta(content='5 December 2013',name='created'),
    meta(content='5 March 2026',name='translated'),
    meta(content='23 April 2026',name='modified'),
    meta(content='originals/lfdphal.x3d',name='reference'),
    meta(content='https://en.wikipedia.org/wiki/Phalanx_bone#Distal_phalanx',name='reference'),
    meta(content='https://en.wikipedia.org/wiki/List_of_bones_of_the_human_skeleton',name='reference'),
    meta(content='usage examples https://www.web3d.org/x3d/content/examples/HumanoidAnimation/Medical',name='reference'),
    meta(content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit',name='generator'),
    meta(content='X3D Tidy, https://www.web3d.org/x3d/stylesheets/X3dTidy.html',name='generator'),
    meta(content='https://www.web3d.org/x3d/content/examples/HumanoidAnimation/Bones/l_tarsal_distal_phalanx_1.x3d',name='identifier'),
    meta(content='../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='l_tarsal_distal_phalanx_1.x3d'),
    Background(skyColor=[(0.858824,1,0.94902)]),
    Comment('user hover lights bone and reveals description, user selection/deselection temporarily binds/unbinds close-up hidden viewpoint'),
    TouchSensor(DEF='UserTouchSensor',description='bone l_tarsal_distal_phalanx_1'),
    Transform(DEF='l_tarsal_distal_phalanx_1',translation=(0.0683,0.0052,0.0961),
      children=[
      BooleanToggle(DEF='UserTouchState'),
      ROUTE(fromField='isActive',fromNode='UserTouchSensor',toField='set_boolean',toNode='UserTouchState'),
      Viewpoint(DEF='HiddenViewpoint',nearDistance=0.001,position=(0,0,0.2),retainUserOffsets=True,
        navigationInfo=NavigationInfo(transitionType=["ANIMATE"],type=["EXAMINE"])),
      ROUTE(fromField='toggle',fromNode='UserTouchState',toField='set_bind',toNode='HiddenViewpoint'),
      DirectionalLight(DEF='HiddenLight',ambientIntensity=1,color=(0.1,0.1,1),on=False),
      ROUTE(fromField='toggle',fromNode='UserTouchState',toField='on',toNode='HiddenLight'),
      Transform(DEF='CenterOfRotationForJoint',visible=False,
        children=[
        Comment('insert computations for joint center of rotation here'),
        Inline(DEF='AxesDisplay',description='RGB display axes showing XYZ direction in local coordinate system',url=["AxesDisplay.x3d"],visible=False)]),
      ROUTE(fromField='toggle',fromNode='UserTouchState',toField='visible',toNode='CenterOfRotationForJoint'),
      Shape(
        appearance=Appearance(
          material=Material(DEF='BoneMaterial',ambientIntensity=0.965,diffuseColor=(1,0.9765,0.8667),shininess=0.05,specularColor=(0.349,0.349,0.349))),
        geometry=IndexedFaceSet(DEF='l_tarsal_distal_phalanx_1_geometry',coordIndex=[0,1,2,-1,3,4,5,-1,6,7,8,-1,8,9,6,-1,10,3,5,-1,11,12,13,-1,14,15,16,-1,17,18,19,-1,20,21,22,-1,22,23,20,-1,24,25,26,-1,27,17,24,-1,28,29,30,-1,31,32,33,-1,32,34,33,-1,31,33,35,-1,36,37,38,-1,39,36,38,-1,40,36,41,-1,42,43,44,-1,45,46,44,-1,47,48,49,-1,50,51,52,-1,53,54,55,-1,53,56,54,-1,57,58,59,-1,60,61,62,-1,61,63,62,-1,64,58,65,-1,7,66,64,-1,64,65,7,-1,67,68,1,-1,47,56,69,-1,48,70,71,-1,72,73,74,-1,75,76,77,-1,75,78,63,-1,79,26,25,-1,79,80,26,-1,29,81,82,-1,83,84,85,-1,81,86,87,-1,81,88,86,-1,47,89,48,-1,12,8,90,-1,55,51,50,-1,50,91,55,-1,48,92,49,-1,48,87,92,-1,93,52,94,-1,93,50,52,-1,95,35,29,-1,35,33,29,-1,96,97,98,-1,98,99,96,-1,68,100,101,-1,100,68,102,-1,36,40,37,-1,7,77,76,-1,58,57,103,-1,39,58,104,-1,41,2,105,-1,41,104,2,-1,103,106,107,-1,103,78,106,-1,89,69,108,-1,89,47,69,-1,106,109,107,-1,109,110,107,-1,110,0,2,-1,67,111,112,-1,113,112,111,-1,113,114,112,-1,115,116,117,-1,117,118,115,-1,119,120,121,-1,11,13,14,-1,122,123,124,-1,13,90,85,-1,85,125,13,-1,125,126,127,-1,125,128,126,-1,129,130,21,-1,131,132,133,-1,131,134,132,-1,24,133,27,-1,5,131,10,-1,5,134,131,-1,7,135,77,-1,7,6,135,-1,135,136,137,-1,135,6,136,-1,138,139,140,-1,138,141,139,-1,18,142,138,-1,138,143,18,-1,144,122,145,-1,142,146,138,-1,146,141,138,-1,136,6,9,-1,4,147,148,-1,147,149,148,-1,8,12,9,-1,3,150,71,-1,3,10,150,-1,142,151,146,-1,82,10,80,-1,82,150,10,-1,83,90,8,-1,83,85,90,-1,152,153,16,-1,121,154,155,-1,121,120,154,-1,118,156,115,-1,118,121,156,-1,111,67,157,-1,158,159,160,-1,160,109,158,-1,72,161,73,-1,69,162,72,-1,72,108,69,-1,163,164,162,-1,162,91,163,-1,104,58,107,-1,58,103,107,-1,41,36,104,-1,77,165,75,-1,77,70,165,-1,8,65,58,-1,58,64,59,-1,166,167,37,-1,166,100,167,-1,100,102,167,-1,40,100,166,-1,166,37,40,-1,40,101,100,-1,2,1,105,-1,97,168,98,-1,31,44,32,-1,33,94,169,-1,88,81,169,-1,88,52,170,-1,53,69,56,-1,132,27,133,-1,58,39,8,-1,86,88,170,-1,130,171,21,-1,172,167,173,-1,75,61,174,-1,62,103,57,-1,7,65,8,-1,89,165,48,-1,165,70,48,-1,30,29,82,-1,13,12,90,-1,120,175,154,-1,120,176,175,-1,157,160,177,-1,157,0,160,-1,66,7,76,-1,76,174,66,-1,76,75,174,-1,59,62,57,-1,59,60,62,-1,61,75,63,-1,54,56,47,-1,47,49,54,-1,92,87,86,-1,55,91,53,-1,46,42,44,-1,43,32,44,-1,39,104,36,-1,38,8,39,-1,22,21,126,-1,24,178,25,-1,17,178,24,-1,143,144,129,-1,171,130,145,-1,11,153,179,-1,179,12,11,-1,144,140,122,-1,137,4,3,-1,137,147,4,-1,12,179,9,-1,99,102,112,-1,121,118,119,-1,132,148,151,-1,134,148,132,-1,147,136,180,-1,136,147,137,-1,123,140,139,-1,122,140,123,-1,11,16,153,-1,14,16,11,-1,143,19,18,-1,19,143,129,-1,140,143,138,-1,144,143,140,-1,18,27,142,-1,18,17,27,-1,181,25,23,-1,79,25,181,-1,45,31,182,-1,44,31,45,-1,183,184,128,-1,185,184,183,-1,95,186,35,-1,95,187,186,-1,98,173,167,-1,168,173,98,-1,92,170,188,-1,92,86,170,-1,68,105,1,-1,68,101,105,-1,159,177,160,-1,159,189,177,-1,114,175,96,-1,175,114,154,-1,190,191,192,-1,190,119,191,-1,163,116,164,-1,163,117,116,-1,156,161,115,-1,73,161,156,-1,114,99,112,-1,114,96,99,-1,34,43,176,-1,32,43,34,-1,92,54,49,-1,92,188,54,-1,193,89,108,-1,193,165,89,-1,60,64,66,-1,60,59,64,-1,145,124,171,-1,124,145,122,-1,88,94,52,-1,169,94,88,-1,55,188,51,-1,188,55,54,-1,93,176,190,-1,176,93,34,-1,81,33,169,-1,81,29,33,-1,45,96,46,-1,96,45,97,-1,187,173,186,-1,84,173,187,-1,172,8,38,-1,172,83,8,-1,66,61,60,-1,66,174,61,-1,162,53,91,-1,53,162,69,-1,158,193,74,-1,194,193,158,-1,162,161,72,-1,162,164,161,-1,159,74,73,-1,74,159,158,-1,114,155,154,-1,155,114,113,-1,189,121,155,-1,189,156,121,-1,195,14,13,-1,15,14,195,-1,28,95,29,-1,28,185,95,-1,195,171,124,-1,171,195,127,-1,84,183,85,-1,84,187,183,-1,10,26,80,-1,10,131,26,-1,150,48,71,-1,150,87,48,-1,3,135,137,-1,71,135,3,-1,149,151,148,-1,151,149,146,-1,152,179,153,-1,180,179,152,-1,152,146,149,-1,152,141,146,-1,16,141,152,-1,16,139,141,-1,149,180,152,-1,149,147,180,-1,77,71,70,-1,77,135,71,-1,131,24,26,-1,131,133,24,-1,150,81,87,-1,81,150,82,-1,21,127,126,-1,21,171,127,-1,128,85,183,-1,85,128,125,-1,127,13,125,-1,127,195,13,-1,181,185,28,-1,181,184,185,-1,184,23,22,-1,184,181,23,-1,124,15,195,-1,15,124,123,-1,191,118,117,-1,191,119,118,-1,177,155,113,-1,177,189,155,-1,113,157,177,-1,111,157,113,-1,0,109,160,-1,0,110,109,-1,107,2,104,-1,107,110,2,-1,109,194,158,-1,194,109,106,-1,194,165,193,-1,75,165,194,-1,63,103,62,-1,63,78,103,-1,37,172,38,-1,37,167,172,-1,43,175,176,-1,43,42,175,-1,94,34,93,-1,33,34,94,-1,190,50,93,-1,190,192,50,-1,163,50,192,-1,163,91,50,-1,84,172,173,-1,172,84,83,-1,30,80,79,-1,30,82,80,-1,106,75,194,-1,106,78,75,-1,74,108,72,-1,74,193,108,-1,175,46,96,-1,42,46,175,-1,67,102,68,-1,112,102,67,-1,116,161,164,-1,161,116,115,-1,192,117,163,-1,192,191,117,-1,120,190,176,-1,190,120,119,-1,157,1,0,-1,1,157,67,-1,189,73,156,-1,159,73,189,-1,170,51,188,-1,51,170,52,-1,102,98,167,-1,98,102,99,-1,186,168,182,-1,168,186,173,-1,105,40,41,-1,105,101,40,-1,182,35,186,-1,182,31,35,-1,185,187,95,-1,185,183,187,-1,22,128,184,-1,22,126,128,-1,182,97,45,-1,182,168,97,-1,28,79,181,-1,30,79,28,-1,178,19,20,-1,19,178,17,-1,178,23,25,-1,178,20,23,-1,20,129,21,-1,19,129,20,-1,144,130,129,-1,144,145,130,-1,16,123,139,-1,123,16,15,-1,180,9,179,-1,9,180,136,-1,27,151,142,-1,132,151,27,-1,134,4,148,-1,5,4,134,-1],creaseAngle=1.571,
          coord=Coordinate(DEF='l_tarsal_distal_phalanx_1_coordinate',point=[(0.0027,-0.0014,-0.0107),(0.0049,-0.0004,-0.0113),(0.0052,-0.0012,-0.0108),(0.0029,-0.0032,0.0058),(0.0032,-0.0033,0.0060),(0.0030,-0.0030,0.0060),(0.0052,-0.0021,0.0034),(0.0049,-0.0027,0.0013),(0.0058,-0.0010,0.0003),(0.0062,-0.0012,0.0029),(0.0025,-0.0020,0.0063),(0.0082,-0.0011,0.0034),(0.0068,-0.0007,0.0025),(0.0066,0.0001,0.0033),(0.0085,-0.0007,0.0044),(0.0086,-0.0005,0.0050),(0.0085,-0.0010,0.0049),(0.0063,-0.0015,0.0111),(0.0068,-0.0015,0.0112),(0.0067,-0.0009,0.0113),(0.0056,0.0006,0.0103),(0.0066,0.0013,0.0101),(0.0052,0.0016,0.0082),(0.0042,0.0008,0.0083),(0.0052,-0.0014,0.0092),(0.0038,-0.0000,0.0083),(0.0038,-0.0009,0.0079),(0.0060,-0.0025,0.0100),(0.0020,0.0006,0.0040),(0.0003,0.0003,0.0010),(0.0018,-0.0001,0.0044),(0.0004,0.0037,-0.0039),(-0.0002,0.0050,-0.0050),(-0.0021,0.0015,-0.0025),(-0.0039,0.0026,-0.0048),(0.0009,0.0032,-0.0029),(0.0071,-0.0012,-0.0043),(0.0068,-0.0000,-0.0069),(0.0064,-0.0009,-0.0033),(0.0067,-0.0015,-0.0029),(0.0077,-0.0009,-0.0071),(0.0077,-0.0012,-0.0069),(-0.0001,0.0052,-0.0054),(-0.0003,0.0051,-0.0052),(0.0000,0.0051,-0.0052),(0.0004,0.0051,-0.0052),(0.0003,0.0051,-0.0053),(-0.0040,-0.0049,-0.0006),(-0.0007,-0.0039,0.0019),(-0.0038,-0.0045,0.0000),(-0.0086,-0.0018,-0.0047),(-0.0070,-0.0029,-0.0024),(-0.0066,-0.0025,-0.0020),(-0.0067,-0.0041,-0.0029),(-0.0065,-0.0044,-0.0010),(-0.0070,-0.0036,-0.0026),(-0.0062,-0.0046,-0.0014),(0.0063,-0.0035,-0.0009),(0.0071,-0.0033,-0.0028),(0.0064,-0.0034,-0.0008),(0.0052,-0.0037,0.0005),(0.0032,-0.0042,-0.0003),(0.0052,-0.0039,0.0003),(0.0032,-0.0043,-0.0005),(0.0063,-0.0031,-0.0006),(0.0061,-0.0025,-0.0004),(0.0049,-0.0031,0.0008),(0.0047,-0.0000,-0.0113),(0.0052,-0.0000,-0.0112),(-0.0054,-0.0051,-0.0035),(0.0010,-0.0039,0.0015),(0.0021,-0.0030,0.0048),(-0.0045,-0.0032,-0.0073),(-0.0039,-0.0018,-0.0096),(-0.0028,-0.0030,-0.0077),(0.0016,-0.0043,-0.0024),(0.0029,-0.0038,0.0004),(0.0027,-0.0040,0.0011),(0.0032,-0.0042,-0.0025),(0.0028,0.0002,0.0064),(0.0026,-0.0007,0.0063),(-0.0010,-0.0015,0.0019),(0.0016,-0.0009,0.0045),(0.0044,0.0011,-0.0004),(0.0035,0.0016,-0.0003),(0.0049,0.0009,0.0025),(-0.0040,-0.0031,0.0001),(-0.0013,-0.0030,0.0024),(-0.0047,-0.0024,-0.0009),(-0.0014,-0.0047,-0.0014),(0.0063,-0.0002,0.0025),(-0.0085,-0.0033,-0.0055),(-0.0038,-0.0038,0.0005),(-0.0064,0.0005,-0.0044),(-0.0043,-0.0004,-0.0024),(0.0020,0.0021,0.0000),(0.0019,0.0043,-0.0078),(0.0023,0.0042,-0.0058),(0.0042,0.0023,-0.0069),(0.0044,0.0024,-0.0095),(0.0058,0.0007,-0.0107),(0.0058,-0.0003,-0.0111),(0.0047,0.0020,-0.0097),(0.0050,-0.0040,-0.0028),(0.0063,-0.0019,-0.0068),(0.0057,-0.0006,-0.0111),(0.0024,-0.0037,-0.0057),(0.0042,-0.0026,-0.0058),(-0.0026,-0.0044,-0.0045),(0.0013,-0.0026,-0.0087),(0.0034,-0.0017,-0.0092),(0.0035,0.0005,-0.0102),(0.0044,0.0019,-0.0098),(0.0013,0.0011,-0.0089),(0.0016,0.0040,-0.0083),(-0.0066,-0.0024,-0.0092),(-0.0077,-0.0032,-0.0087),(-0.0090,-0.0027,-0.0076),(-0.0070,-0.0009,-0.0077),(-0.0074,0.0008,-0.0063),(-0.0052,0.0034,-0.0068),(-0.0047,0.0009,-0.0079),(0.0092,-0.0005,0.0092),(0.0091,-0.0006,0.0074),(0.0086,-0.0001,0.0082),(0.0053,0.0012,0.0043),(0.0055,0.0017,0.0081),(0.0066,0.0015,0.0073),(0.0043,0.0020,0.0054),(0.0074,-0.0003,0.0110),(0.0079,0.0010,0.0103),(0.0035,-0.0023,0.0076),(0.0044,-0.0035,0.0088),(0.0049,-0.0027,0.0091),(0.0035,-0.0036,0.0071),(0.0038,-0.0033,0.0040),(0.0054,-0.0019,0.0049),(0.0042,-0.0034,0.0055),(0.0081,-0.0021,0.0097),(0.0090,-0.0012,0.0074),(0.0091,-0.0011,0.0092),(0.0073,-0.0023,0.0078),(0.0067,-0.0027,0.0101),(0.0078,-0.0007,0.0108),(0.0081,-0.0003,0.0107),(0.0085,0.0006,0.0102),(0.0053,-0.0037,0.0086),(0.0043,-0.0035,0.0060),(0.0038,-0.0039,0.0069),(0.0047,-0.0037,0.0068),(0.0014,-0.0022,0.0049),(0.0047,-0.0038,0.0087),(0.0066,-0.0023,0.0062),(0.0081,-0.0016,0.0039),(-0.0015,0.0046,-0.0079),(-0.0016,0.0018,-0.0083),(-0.0041,-0.0013,-0.0097),(0.0025,-0.0009,-0.0108),(-0.0011,-0.0028,-0.0081),(-0.0020,-0.0017,-0.0101),(0.0003,-0.0020,-0.0103),(-0.0064,-0.0028,-0.0092),(-0.0069,-0.0048,-0.0068),(-0.0091,-0.0032,-0.0072),(-0.0077,-0.0037,-0.0086),(0.0001,-0.0045,-0.0019),(0.0067,0.0001,-0.0073),(0.0049,0.0015,-0.0063),(0.0024,0.0033,-0.0045),(-0.0036,-0.0006,-0.0016),(-0.0062,-0.0032,-0.0008),(0.0077,0.0012,0.0092),(0.0047,0.0012,-0.0038),(0.0026,0.0027,-0.0034),(0.0032,-0.0039,-0.0001),(-0.0014,0.0051,-0.0074),(-0.0050,0.0036,-0.0063),(0.0001,-0.0015,-0.0106),(0.0053,-0.0002,0.0102),(0.0067,-0.0010,0.0029),(0.0057,-0.0018,0.0052),(0.0032,0.0010,0.0063),(0.0011,0.0039,-0.0042),(0.0035,0.0016,0.0030),(0.0037,0.0018,0.0058),(0.0029,0.0015,0.0034),(0.0015,0.0033,-0.0033),(0.0027,0.0022,-0.0001),(-0.0066,-0.0038,-0.0008),(-0.0021,-0.0012,-0.0102),(-0.0074,0.0009,-0.0057),(-0.0091,-0.0014,-0.0063),(-0.0093,-0.0016,-0.0058),(-0.0011,-0.0041,-0.0048),(0.0004,-0.0038,-0.0052),(0.0077,0.0005,0.0064)])))])])
)

### X3D model conversion complete ###

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

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