####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python r_tarsal_middle_phalanx_2.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='r_tarsal_middle_phalanx_2.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/rfmphal4.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/r_tarsal_middle_phalanx_2.x3d',name='identifier'),
    meta(content='../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='r_tarsal_middle_phalanx_2.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 r_tarsal_middle_phalanx_2'),
    Transform(DEF='r_tarsal_middle_phalanx_2',translation=(-0.0945,0.0056,0.0925),
      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',scale=(0.5,0.5,0.5),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='r_tarsal_middle_phalanx_2_geometry',coordIndex=[0,1,2,-1,3,4,5,-1,6,7,8,-1,9,10,11,-1,9,12,10,-1,13,14,15,-1,14,16,15,-1,17,18,19,-1,17,20,18,-1,21,22,23,-1,24,25,26,-1,25,27,26,-1,28,29,30,-1,28,31,29,-1,32,33,34,-1,33,35,34,-1,36,23,37,-1,36,38,23,-1,39,40,9,-1,36,41,42,-1,36,37,41,-1,13,15,43,-1,44,45,39,-1,44,46,45,-1,47,48,49,-1,50,51,52,-1,50,53,51,-1,54,55,56,-1,54,57,55,-1,49,3,58,-1,59,10,60,-1,10,12,60,-1,61,62,63,-1,64,8,65,-1,64,11,8,-1,66,67,68,-1,69,70,71,-1,71,72,69,-1,73,74,75,-1,76,77,78,-1,79,80,32,-1,32,34,79,-1,32,80,81,-1,80,82,81,-1,63,62,83,-1,62,4,83,-1,84,85,86,-1,85,87,86,-1,88,89,90,-1,88,91,89,-1,92,93,94,-1,94,95,92,-1,43,19,13,-1,96,97,98,-1,99,100,101,-1,44,39,9,-1,7,65,8,-1,102,22,103,-1,102,23,22,-1,92,104,93,-1,105,106,107,-1,108,68,67,-1,5,58,3,-1,109,89,91,-1,3,49,48,-1,26,110,24,-1,26,111,110,-1,112,77,113,-1,75,114,115,-1,116,117,118,-1,119,120,24,-1,24,110,119,-1,69,121,122,-1,123,124,62,-1,62,61,123,-1,125,126,127,-1,126,128,127,-1,129,130,131,-1,129,132,130,-1,10,53,133,-1,10,59,53,-1,38,134,135,-1,38,136,134,-1,9,11,44,-1,11,64,44,-1,1,61,63,-1,0,109,91,-1,137,21,135,-1,135,60,137,-1,7,16,65,-1,16,138,65,-1,95,43,92,-1,98,139,96,-1,101,140,99,-1,72,121,69,-1,8,133,6,-1,141,38,36,-1,37,23,142,-1,81,143,32,-1,143,33,32,-1,144,27,70,-1,27,25,70,-1,69,122,145,-1,146,147,148,-1,104,7,6,-1,6,93,104,-1,133,11,10,-1,133,8,11,-1,40,12,9,-1,75,74,149,-1,149,108,75,-1,75,108,114,-1,108,67,114,-1,150,72,151,-1,150,121,72,-1,107,150,105,-1,149,152,127,-1,152,149,74,-1,125,78,84,-1,125,153,78,-1,154,112,145,-1,154,155,112,-1,107,121,150,-1,121,107,122,-1,151,71,90,-1,151,72,71,-1,123,156,120,-1,123,88,156,-1,119,5,124,-1,118,5,119,-1,84,77,85,-1,84,78,77,-1,118,58,5,-1,118,117,58,-1,29,157,30,-1,29,158,157,-1,29,52,158,-1,52,29,159,-1,6,94,93,-1,6,50,94,-1,7,15,16,-1,104,15,7,-1,160,54,56,-1,97,54,160,-1,96,45,161,-1,139,45,96,-1,40,100,137,-1,100,40,101,-1,39,101,40,-1,140,101,39,-1,71,25,156,-1,70,25,71,-1,162,144,76,-1,162,27,144,-1,152,162,153,-1,163,162,152,-1,164,143,81,-1,164,165,143,-1,166,167,168,-1,166,169,167,-1,170,146,148,-1,170,171,146,-1,142,102,172,-1,142,23,102,-1,141,136,38,-1,2,136,141,-1,173,158,174,-1,157,158,173,-1,105,151,175,-1,105,150,151,-1,138,132,176,-1,132,138,130,-1,46,161,45,-1,161,46,177,-1,104,43,15,-1,92,43,104,-1,178,43,95,-1,178,179,43,-1,34,47,79,-1,28,47,34,-1,98,140,139,-1,140,98,99,-1,180,181,182,-1,183,181,180,-1,184,102,103,-1,184,171,102,-1,138,64,65,-1,138,176,64,-1,99,22,100,-1,99,103,22,-1,59,135,134,-1,59,60,135,-1,43,17,19,-1,43,179,17,-1,185,131,186,-1,129,131,185,-1,84,126,125,-1,126,84,86,-1,168,187,166,-1,168,188,187,-1,132,57,177,-1,132,129,57,-1,136,51,134,-1,136,174,51,-1,167,186,165,-1,167,185,186,-1,189,126,188,-1,126,189,128,-1,89,151,90,-1,89,175,151,-1,141,42,109,-1,42,141,36,-1,116,119,110,-1,118,119,116,-1,116,114,117,-1,116,115,114,-1,145,113,69,-1,112,113,145,-1,113,76,144,-1,76,113,77,-1,115,110,111,-1,115,116,110,-1,73,26,163,-1,73,111,26,-1,28,48,47,-1,30,48,28,-1,189,81,82,-1,189,164,81,-1,166,190,148,-1,190,166,187,-1,181,148,190,-1,148,181,170,-1,37,191,41,-1,191,37,142,-1,172,191,142,-1,183,191,172,-1,109,2,141,-1,109,0,2,-1,66,58,67,-1,66,49,58,-1,192,108,149,-1,108,192,68,-1,106,154,107,-1,154,106,180,-1,124,4,62,-1,4,124,5,-1,147,55,169,-1,147,56,55,-1,174,52,51,-1,158,52,174,-1,137,12,40,-1,60,12,137,-1,14,131,130,-1,131,14,18,-1,35,17,179,-1,35,33,17,-1,177,54,161,-1,54,177,57,-1,53,6,133,-1,50,6,53,-1,135,23,38,-1,23,135,21,-1,160,171,184,-1,146,171,160,-1,165,20,143,-1,165,186,20,-1,178,29,31,-1,29,178,159,-1,61,88,123,-1,61,91,88,-1,182,85,155,-1,85,182,87,-1,128,149,127,-1,128,192,149,-1,157,63,83,-1,157,173,63,-1,41,106,105,-1,191,106,41,-1,106,183,180,-1,106,191,183,-1,190,182,181,-1,190,87,182,-1,87,187,86,-1,190,187,87,-1,128,82,192,-1,128,189,82,-1,192,80,68,-1,192,82,80,-1,80,66,68,-1,79,66,80,-1,75,111,73,-1,115,111,75,-1,69,144,70,-1,113,144,69,-1,74,163,152,-1,74,73,163,-1,175,109,42,-1,175,89,109,-1,164,188,168,-1,188,164,189,-1,1,173,2,-1,1,63,173,-1,185,169,55,-1,185,167,169,-1,86,188,126,-1,188,86,187,-1,129,55,57,-1,129,185,55,-1,186,18,20,-1,131,18,186,-1,159,95,94,-1,95,159,178,-1,134,53,59,-1,53,134,51,-1,97,184,98,-1,97,160,184,-1,44,176,46,-1,64,176,44,-1,98,103,99,-1,98,184,103,-1,170,183,172,-1,170,181,183,-1,155,180,182,-1,180,155,154,-1,66,47,49,-1,66,79,47,-1,179,31,35,-1,31,179,178,-1,176,177,46,-1,177,176,132,-1,14,138,16,-1,130,138,14,-1,42,105,175,-1,42,41,105,-1,174,2,173,-1,174,136,2,-1,171,172,102,-1,172,171,170,-1,148,169,166,-1,148,147,169,-1,165,168,167,-1,168,165,164,-1,35,28,34,-1,35,31,28,-1,24,156,25,-1,120,156,24,-1,163,27,162,-1,26,27,163,-1,76,153,162,-1,78,153,76,-1,22,137,100,-1,22,21,137,-1,45,140,39,-1,140,45,139,-1,161,97,96,-1,161,54,97,-1,56,146,160,-1,147,146,56,-1,17,143,20,-1,17,33,143,-1,14,19,18,-1,19,14,13,-1,52,94,50,-1,52,159,94,-1,48,4,3,-1,83,4,48,-1,83,30,157,-1,30,83,48,-1,91,1,0,-1,61,1,91,-1,117,67,58,-1,117,114,67,-1,123,119,124,-1,123,120,119,-1,156,90,71,-1,156,88,90,-1,154,122,107,-1,122,154,145,-1,112,85,77,-1,112,155,85,-1,127,153,125,-1,127,152,153,-1],creaseAngle=1.571,
          coord=Coordinate(DEF='r_tarsal_middle_phalanx_2_coordinate',point=[(0.0009,-0.0035,-0.0021),(0.0011,-0.0035,-0.0020),(0.0000,-0.0034,0.0003),(0.0049,-0.0034,-0.0049),(0.0045,-0.0039,-0.0050),(0.0053,-0.0036,-0.0071),(0.0015,-0.0035,0.0077),(0.0011,-0.0028,0.0085),(0.0000,-0.0036,0.0078),(-0.0037,-0.0041,0.0066),(-0.0018,-0.0038,0.0069),(-0.0019,-0.0039,0.0073),(-0.0035,-0.0041,0.0062),(0.0011,-0.0006,0.0077),(0.0004,-0.0003,0.0078),(0.0010,-0.0014,0.0084),(0.0004,-0.0015,0.0087),(0.0015,-0.0004,0.0046),(0.0005,0.0002,0.0064),(0.0011,-0.0002,0.0064),(0.0009,0.0001,0.0045),(-0.0037,-0.0036,0.0032),(-0.0040,-0.0034,0.0032),(-0.0035,-0.0033,0.0018),(0.0027,-0.0019,-0.0075),(0.0016,-0.0019,-0.0076),(0.0022,0.0005,-0.0071),(0.0011,0.0004,-0.0071),(0.0024,-0.0022,0.0009),(0.0020,-0.0030,0.0030),(0.0023,-0.0031,0.0009),(0.0020,-0.0024,0.0030),(0.0023,0.0001,0.0008),(0.0018,-0.0003,0.0028),(0.0024,-0.0010,0.0008),(0.0020,-0.0012,0.0028),(-0.0019,-0.0037,-0.0003),(-0.0027,-0.0034,-0.0006),(-0.0024,-0.0035,0.0021),(-0.0055,-0.0034,0.0066),(-0.0049,-0.0043,0.0057),(-0.0020,-0.0034,-0.0030),(-0.0012,-0.0039,-0.0026),(0.0018,-0.0016,0.0063),(-0.0042,-0.0030,0.0072),(-0.0058,-0.0018,0.0070),(-0.0046,-0.0015,0.0072),(0.0032,-0.0020,-0.0012),(0.0031,-0.0032,-0.0012),(0.0053,-0.0019,-0.0043),(0.0016,-0.0036,0.0062),(0.0004,-0.0036,0.0044),(0.0016,-0.0033,0.0046),(0.0003,-0.0037,0.0059),(-0.0047,0.0002,0.0055),(-0.0032,0.0005,0.0040),(-0.0040,0.0002,0.0039),(-0.0038,0.0003,0.0056),(0.0060,-0.0019,-0.0057),(-0.0015,-0.0036,0.0057),(-0.0030,-0.0041,0.0050),(0.0023,-0.0034,-0.0055),(0.0034,-0.0044,-0.0053),(0.0018,-0.0037,-0.0018),(-0.0024,-0.0026,0.0076),(-0.0006,-0.0027,0.0083),(0.0046,-0.0000,-0.0036),(0.0056,0.0008,-0.0057),(0.0046,0.0018,-0.0036),(-0.0005,-0.0018,-0.0077),(0.0006,-0.0019,-0.0077),(0.0007,-0.0033,-0.0085),(-0.0005,-0.0034,-0.0085),(0.0032,0.0026,-0.0070),(0.0031,0.0037,-0.0071),(0.0049,0.0027,-0.0066),(-0.0012,0.0026,-0.0071),(-0.0022,0.0024,-0.0071),(-0.0015,0.0036,-0.0073),(0.0032,-0.0007,-0.0012),(0.0033,0.0010,-0.0011),(0.0018,0.0010,0.0007),(0.0024,0.0019,-0.0013),(0.0027,-0.0036,-0.0013),(-0.0018,0.0038,-0.0070),(-0.0026,0.0024,-0.0068),(-0.0014,0.0031,-0.0046),(-0.0025,0.0020,-0.0048),(0.0019,-0.0037,-0.0085),(0.0004,-0.0045,-0.0059),(0.0007,-0.0038,-0.0083),(0.0018,-0.0034,-0.0056),(0.0020,-0.0025,0.0071),(0.0019,-0.0030,0.0074),(0.0020,-0.0032,0.0063),(0.0019,-0.0025,0.0063),(-0.0056,-0.0007,0.0061),(-0.0051,-0.0002,0.0053),(-0.0051,-0.0017,0.0052),(-0.0048,-0.0030,0.0048),(-0.0046,-0.0039,0.0045),(-0.0052,-0.0039,0.0054),(-0.0035,-0.0023,0.0019),(-0.0042,-0.0026,0.0033),(0.0015,-0.0024,0.0083),(-0.0016,-0.0040,-0.0062),(-0.0022,-0.0024,-0.0064),(-0.0022,-0.0026,-0.0073),(0.0053,0.0025,-0.0061),(-0.0001,-0.0039,-0.0024),(0.0038,-0.0017,-0.0071),(0.0034,0.0007,-0.0071),(-0.0024,-0.0001,-0.0070),(-0.0013,-0.0001,-0.0071),(0.0054,0.0007,-0.0063),(0.0050,0.0007,-0.0065),(0.0051,-0.0017,-0.0067),(0.0058,-0.0018,-0.0063),(0.0053,-0.0031,-0.0075),(0.0043,-0.0035,-0.0080),(0.0028,-0.0034,-0.0085),(-0.0012,-0.0030,-0.0082),(-0.0017,-0.0022,-0.0077),(0.0028,-0.0037,-0.0084),(0.0043,-0.0040,-0.0078),(-0.0001,0.0046,-0.0070),(0.0000,0.0039,-0.0043),(0.0012,0.0046,-0.0069),(0.0013,0.0036,-0.0042),(-0.0025,0.0004,0.0059),(-0.0010,-0.0001,0.0074),(-0.0008,0.0003,0.0062),(-0.0027,-0.0001,0.0068),(0.0001,-0.0037,0.0074),(-0.0012,-0.0035,0.0042),(-0.0028,-0.0038,0.0035),(-0.0009,-0.0034,0.0027),(-0.0042,-0.0042,0.0045),(-0.0010,-0.0013,0.0082),(-0.0060,-0.0018,0.0065),(-0.0057,-0.0031,0.0063),(-0.0013,-0.0038,-0.0001),(-0.0030,-0.0029,-0.0005),(0.0013,0.0003,0.0027),(0.0000,0.0001,-0.0070),(-0.0021,-0.0013,-0.0074),(-0.0037,-0.0001,0.0023),(-0.0035,0.0003,0.0024),(-0.0032,0.0007,0.0000),(0.0032,0.0040,-0.0067),(-0.0014,-0.0035,-0.0078),(-0.0005,-0.0038,-0.0082),(0.0013,0.0043,-0.0073),(0.0000,0.0043,-0.0074),(-0.0027,-0.0013,-0.0068),(-0.0029,-0.0002,-0.0065),(0.0019,-0.0034,-0.0087),(0.0019,-0.0035,0.0008),(0.0016,-0.0033,0.0030),(0.0019,-0.0030,0.0046),(-0.0044,-0.0004,0.0038),(-0.0054,-0.0005,0.0066),(0.0005,0.0026,-0.0072),(0.0018,0.0026,-0.0071),(0.0004,0.0015,0.0006),(0.0000,0.0007,0.0026),(-0.0021,0.0013,0.0002),(-0.0015,0.0010,0.0025),(-0.0010,0.0018,0.0004),(-0.0026,0.0007,0.0025),(-0.0033,-0.0009,-0.0004),(-0.0038,-0.0012,0.0020),(-0.0031,-0.0019,-0.0005),(0.0011,-0.0036,0.0006),(0.0006,-0.0035,0.0029),(-0.0007,-0.0046,-0.0060),(-0.0028,-0.0012,0.0074),(-0.0043,-0.0003,0.0067),(0.0019,-0.0025,0.0046),(0.0019,-0.0014,0.0046),(-0.0025,-0.0013,-0.0060),(-0.0029,-0.0006,-0.0028),(-0.0029,-0.0001,-0.0057),(-0.0026,-0.0015,-0.0029),(-0.0045,-0.0015,0.0036),(-0.0020,0.0007,0.0042),(-0.0004,0.0005,0.0044),(-0.0015,0.0020,-0.0020),(-0.0005,0.0025,-0.0017),(0.0009,0.0023,-0.0015),(-0.0025,0.0014,-0.0024),(-0.0025,-0.0025,-0.0029),(0.0031,0.0030,-0.0039)])))])])
)

### X3D model conversion complete ###

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

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