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

### X3D model conversion complete ###

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

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