####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python l_tarsal_distal_phalanx_3.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_3.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/lfdphal3.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_3.x3d',name='identifier'),
    meta(content='../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='l_tarsal_distal_phalanx_3.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_3'),
    Transform(DEF='l_tarsal_distal_phalanx_3',translation=(0.1109,0.0049,0.0921),
      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_3_geometry',coordIndex=[0,1,2,-1,3,4,5,-1,6,0,7,-1,8,9,10,-1,11,4,12,-1,13,14,15,-1,14,16,15,-1,17,18,19,-1,20,21,22,-1,23,24,25,-1,26,27,28,-1,29,30,24,-1,31,22,21,-1,24,23,32,-1,33,34,9,-1,34,10,9,-1,35,2,12,-1,36,37,38,-1,39,40,14,-1,14,41,39,-1,42,43,44,-1,45,46,47,-1,46,48,47,-1,49,37,50,-1,49,51,37,-1,2,52,0,-1,11,53,54,-1,51,55,8,-1,8,56,51,-1,57,34,33,-1,57,58,34,-1,20,59,21,-1,60,40,18,-1,27,61,23,-1,18,39,62,-1,63,64,65,-1,64,66,65,-1,67,68,69,-1,67,70,68,-1,15,71,72,-1,15,73,71,-1,74,75,76,-1,76,77,74,-1,75,78,79,-1,79,76,75,-1,80,81,82,-1,81,83,82,-1,84,85,86,-1,84,87,85,-1,88,46,84,-1,88,48,46,-1,89,90,91,-1,68,71,69,-1,68,72,71,-1,48,88,63,-1,92,24,32,-1,26,61,27,-1,17,60,18,-1,8,55,9,-1,11,54,36,-1,2,35,52,-1,54,53,93,-1,53,94,93,-1,55,51,49,-1,49,95,55,-1,65,96,48,-1,48,63,65,-1,59,17,21,-1,41,97,39,-1,89,78,98,-1,89,79,78,-1,58,99,100,-1,58,43,99,-1,42,5,4,-1,34,58,100,-1,34,100,10,-1,101,12,3,-1,12,4,3,-1,102,22,103,-1,104,105,29,-1,106,28,27,-1,28,107,108,-1,29,105,109,-1,109,30,29,-1,27,23,25,-1,24,92,29,-1,21,17,19,-1,18,40,39,-1,16,14,40,-1,40,110,16,-1,59,20,82,-1,20,80,82,-1,92,111,112,-1,112,113,92,-1,83,85,114,-1,83,81,85,-1,56,8,10,-1,10,100,56,-1,53,2,94,-1,2,1,94,-1,1,115,94,-1,0,52,116,-1,116,7,0,-1,35,12,101,-1,117,96,118,-1,38,11,36,-1,119,5,120,-1,119,3,5,-1,101,52,35,-1,52,101,116,-1,12,53,11,-1,12,2,53,-1,38,4,11,-1,38,99,4,-1,66,121,122,-1,66,64,121,-1,69,123,67,-1,124,123,69,-1,73,125,71,-1,73,90,125,-1,126,127,128,-1,126,91,127,-1,129,130,131,-1,130,129,132,-1,86,81,133,-1,86,85,81,-1,114,131,83,-1,131,114,129,-1,134,112,135,-1,134,113,112,-1,60,136,137,-1,60,17,136,-1,138,23,70,-1,32,23,138,-1,17,82,136,-1,17,59,82,-1,13,72,26,-1,72,13,15,-1,138,92,32,-1,111,92,138,-1,109,139,30,-1,139,109,140,-1,28,141,107,-1,28,106,141,-1,31,103,22,-1,103,31,142,-1,139,27,25,-1,139,106,27,-1,97,62,39,-1,62,97,143,-1,144,142,31,-1,144,145,142,-1,142,105,103,-1,109,105,142,-1,116,3,119,-1,116,101,3,-1,6,118,96,-1,6,7,118,-1,65,123,146,-1,123,65,66,-1,99,42,4,-1,43,42,99,-1,147,78,50,-1,98,78,147,-1,126,89,91,-1,126,79,89,-1,136,83,131,-1,83,136,82,-1,148,74,77,-1,149,74,148,-1,117,48,96,-1,48,117,47,-1,113,29,92,-1,113,104,29,-1,150,94,115,-1,94,150,93,-1,50,75,49,-1,50,78,75,-1,151,149,152,-1,149,151,153,-1,95,9,55,-1,95,153,9,-1,147,54,93,-1,36,54,147,-1,51,38,37,-1,51,56,38,-1,45,44,57,-1,47,44,45,-1,102,113,134,-1,113,102,104,-1,26,108,13,-1,26,28,108,-1,144,21,19,-1,144,31,21,-1,107,143,97,-1,107,141,143,-1,140,142,145,-1,140,109,142,-1,88,86,154,-1,86,88,84,-1,125,155,124,-1,155,125,156,-1,89,150,156,-1,150,89,98,-1,16,73,15,-1,73,16,127,-1,121,112,111,-1,121,157,112,-1,6,155,115,-1,6,146,155,-1,46,87,84,-1,46,152,87,-1,135,81,80,-1,135,133,81,-1,85,148,114,-1,85,87,148,-1,137,131,130,-1,137,136,131,-1,76,126,132,-1,76,79,126,-1,130,110,137,-1,128,110,130,-1,77,132,129,-1,132,77,76,-1,152,148,87,-1,152,149,148,-1,157,135,112,-1,157,133,135,-1,111,122,121,-1,122,111,138,-1,156,90,89,-1,90,156,125,-1,156,115,155,-1,115,156,150,-1,124,146,123,-1,146,124,155,-1,63,154,64,-1,63,88,154,-1,141,145,143,-1,141,140,145,-1,108,97,41,-1,97,108,107,-1,18,144,19,-1,144,18,62,-1,108,14,13,-1,14,108,41,-1,22,134,20,-1,134,22,102,-1,43,57,44,-1,43,58,57,-1,151,57,33,-1,151,45,57,-1,120,42,44,-1,120,5,42,-1,44,117,120,-1,117,44,47,-1,153,33,9,-1,153,151,33,-1,74,49,75,-1,74,95,49,-1,98,93,150,-1,93,98,147,-1,115,0,6,-1,115,1,0,-1,45,152,46,-1,151,152,45,-1,74,153,95,-1,153,74,149,-1,77,114,148,-1,77,129,114,-1,127,110,128,-1,16,110,127,-1,36,50,37,-1,147,50,36,-1,67,138,70,-1,67,122,138,-1,96,146,6,-1,146,96,65,-1,7,119,118,-1,7,116,119,-1,103,104,102,-1,103,105,104,-1,144,143,145,-1,144,62,143,-1,25,30,139,-1,30,25,24,-1,106,140,141,-1,106,139,140,-1,61,70,23,-1,70,61,68,-1,40,137,110,-1,40,60,137,-1,20,135,80,-1,20,134,135,-1,68,26,72,-1,61,26,68,-1,154,133,157,-1,154,86,133,-1,132,128,130,-1,132,126,128,-1,127,90,73,-1,91,90,127,-1,71,124,69,-1,125,124,71,-1,123,122,67,-1,123,66,122,-1,64,157,121,-1,64,154,157,-1,99,56,100,-1,56,99,38,-1,120,118,119,-1,120,117,118,-1],creaseAngle=1.571,
          coord=Coordinate(DEF='l_tarsal_distal_phalanx_3_coordinate',point=[(-0.0004,-0.0007,0.0018),(-0.0004,-0.0014,0.0017),(0.0000,-0.0022,0.0030),(0.0001,-0.0018,0.0042),(0.0013,-0.0026,0.0046),(0.0004,-0.0016,0.0044),(-0.0008,-0.0004,0.0010),(-0.0004,-0.0006,0.0019),(0.0037,-0.0015,0.0030),(0.0037,-0.0007,0.0021),(0.0038,-0.0011,0.0034),(0.0013,-0.0030,0.0044),(0.0011,-0.0028,0.0044),(-0.0019,-0.0028,-0.0043),(-0.0007,-0.0029,-0.0046),(-0.0019,-0.0032,-0.0040),(-0.0005,-0.0034,-0.0044),(0.0021,-0.0010,-0.0045),(0.0010,-0.0014,-0.0044),(0.0012,-0.0007,-0.0043),(0.0019,0.0011,-0.0043),(0.0012,0.0001,-0.0040),(0.0007,0.0009,-0.0039),(-0.0036,0.0003,-0.0030),(-0.0022,0.0009,-0.0031),(-0.0024,-0.0001,-0.0031),(-0.0029,-0.0018,-0.0037),(-0.0025,-0.0007,-0.0033),(-0.0022,-0.0015,-0.0036),(-0.0017,0.0016,-0.0031),(-0.0019,0.0007,-0.0031),(0.0004,0.0001,-0.0036),(-0.0034,0.0009,-0.0030),(0.0035,0.0003,0.0023),(0.0038,-0.0004,0.0037),(-0.0001,-0.0022,0.0035),(0.0009,-0.0034,0.0023),(0.0019,-0.0034,0.0022),(0.0021,-0.0027,0.0042),(0.0001,-0.0019,-0.0043),(0.0007,-0.0026,-0.0046),(-0.0006,-0.0023,-0.0043),(0.0013,-0.0007,0.0044),(0.0018,-0.0006,0.0043),(0.0010,0.0009,0.0032),(0.0018,0.0013,0.0017),(0.0014,0.0016,0.0008),(0.0005,0.0009,0.0018),(0.0001,0.0013,0.0011),(0.0019,-0.0020,0.0010),(0.0012,-0.0028,0.0008),(0.0028,-0.0028,0.0022),(-0.0004,-0.0016,0.0030),(0.0001,-0.0025,0.0028),(0.0004,-0.0030,0.0026),(0.0035,-0.0018,0.0020),(0.0028,-0.0022,0.0038),(0.0027,0.0011,0.0028),(0.0031,-0.0001,0.0041),(0.0025,-0.0001,-0.0043),(0.0017,-0.0016,-0.0046),(-0.0038,-0.0004,-0.0031),(0.0001,-0.0013,-0.0039),(-0.0007,0.0019,0.0004),(-0.0016,0.0029,-0.0007),(-0.0014,0.0006,0.0003),(-0.0028,0.0009,-0.0013),(-0.0034,0.0003,-0.0022),(-0.0038,-0.0004,-0.0028),(-0.0035,-0.0006,-0.0024),(-0.0037,0.0003,-0.0027),(-0.0027,-0.0023,-0.0031),(-0.0029,-0.0021,-0.0034),(-0.0016,-0.0032,-0.0036),(0.0018,-0.0011,-0.0001),(0.0013,-0.0018,-0.0003),(0.0014,-0.0021,-0.0015),(0.0018,-0.0011,-0.0012),(0.0008,-0.0025,-0.0002),(0.0006,-0.0028,-0.0015),(0.0025,0.0016,-0.0039),(0.0025,0.0017,-0.0027),(0.0030,-0.0001,-0.0038),(0.0029,-0.0003,-0.0031),(0.0011,0.0020,-0.0002),(0.0024,0.0014,-0.0019),(0.0013,0.0031,-0.0013),(0.0020,0.0013,-0.0008),(-0.0001,0.0020,0.0002),(-0.0004,-0.0029,-0.0015),(-0.0015,-0.0031,-0.0030),(-0.0005,-0.0034,-0.0033),(-0.0026,0.0024,-0.0029),(-0.0002,-0.0023,0.0012),(-0.0003,-0.0016,0.0016),(0.0023,-0.0011,0.0010),(-0.0007,0.0004,0.0012),(-0.0007,-0.0018,-0.0040),(0.0000,-0.0028,-0.0002),(0.0020,-0.0023,0.0044),(0.0029,-0.0016,0.0041),(-0.0001,-0.0022,0.0037),(0.0001,0.0019,-0.0037),(-0.0002,0.0011,-0.0035),(-0.0009,0.0019,-0.0035),(-0.0010,0.0013,-0.0033),(-0.0021,-0.0009,-0.0033),(-0.0015,-0.0016,-0.0037),(-0.0016,-0.0021,-0.0039),(-0.0012,0.0006,-0.0030),(0.0008,-0.0032,-0.0043),(-0.0025,0.0029,-0.0023),(-0.0008,0.0032,-0.0031),(-0.0010,0.0027,-0.0035),(0.0026,-0.0004,-0.0024),(-0.0008,-0.0011,0.0007),(-0.0004,-0.0015,0.0031),(-0.0002,0.0001,0.0020),(-0.0003,-0.0001,0.0020),(-0.0004,-0.0007,0.0033),(-0.0003,-0.0004,0.0035),(-0.0019,0.0032,-0.0014),(-0.0032,0.0010,-0.0020),(-0.0029,0.0003,-0.0016),(-0.0030,-0.0006,-0.0019),(-0.0024,-0.0023,-0.0026),(0.0007,-0.0032,-0.0031),(-0.0005,-0.0036,-0.0040),(0.0009,-0.0032,-0.0038),(0.0023,-0.0014,-0.0026),(0.0020,-0.0023,-0.0037),(0.0025,-0.0014,-0.0034),(0.0018,-0.0023,-0.0029),(0.0013,0.0032,-0.0021),(0.0006,0.0026,-0.0041),(0.0009,0.0031,-0.0037),(0.0026,-0.0013,-0.0041),(0.0021,-0.0023,-0.0043),(-0.0034,0.0010,-0.0025),(-0.0020,-0.0001,-0.0030),(-0.0014,-0.0003,-0.0030),(-0.0014,-0.0010,-0.0033),(-0.0005,0.0003,-0.0032),(-0.0007,-0.0011,-0.0036),(0.0002,-0.0007,-0.0037),(-0.0007,-0.0004,-0.0033),(-0.0016,-0.0001,0.0000),(0.0004,-0.0029,0.0008),(0.0020,-0.0001,-0.0010),(0.0021,-0.0001,0.0001),(-0.0007,-0.0021,0.0003),(0.0025,0.0006,0.0013),(0.0020,0.0009,0.0003),(0.0025,-0.0003,0.0011),(-0.0002,0.0032,-0.0010),(-0.0016,-0.0009,-0.0003),(-0.0014,-0.0020,-0.0008),(-0.0003,0.0035,-0.0017)])))])])
)

### X3D model conversion complete ###

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

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