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