####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python l_tarsal_middle_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_middle_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/lfmphal.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_3.x3d',name='identifier'),
    meta(content='../license.html',name='license')]),
  Scene=Scene(
    children=[
    WorldInfo(title='l_tarsal_middle_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_middle_phalanx_3'),
    Transform(DEF='l_tarsal_middle_phalanx_3',translation=(0.1094,0.0057,0.0825),
      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_3_geometry',coordIndex=[0,1,2,-1,3,4,5,-1,4,6,5,-1,7,8,9,-1,10,11,12,-1,10,13,11,-1,14,15,16,-1,16,17,14,-1,18,19,20,-1,21,22,23,-1,24,25,26,-1,25,27,16,-1,25,28,27,-1,17,16,27,-1,29,30,18,-1,31,30,32,-1,30,29,32,-1,33,34,35,-1,35,29,33,-1,36,37,38,-1,36,39,37,-1,40,39,41,-1,39,36,41,-1,20,42,43,-1,20,19,42,-1,44,36,45,-1,46,47,48,-1,49,27,21,-1,15,25,16,-1,50,51,4,-1,52,53,3,-1,27,54,21,-1,25,55,26,-1,25,15,55,-1,56,48,57,-1,58,9,46,-1,58,10,9,-1,59,60,61,-1,60,62,61,-1,63,64,65,-1,65,58,63,-1,66,67,68,-1,69,70,71,-1,0,2,40,-1,41,36,72,-1,35,73,32,-1,45,36,74,-1,75,30,76,-1,74,77,45,-1,73,78,79,-1,79,32,73,-1,32,29,35,-1,80,66,81,-1,66,68,81,-1,65,64,13,-1,82,61,83,-1,82,59,61,-1,62,84,61,-1,62,85,84,-1,48,56,46,-1,63,56,24,-1,56,57,24,-1,54,27,28,-1,86,87,88,-1,86,89,87,-1,17,90,14,-1,90,6,14,-1,17,27,49,-1,22,91,69,-1,8,2,70,-1,92,13,64,-1,31,76,30,-1,43,42,38,-1,78,40,41,-1,78,0,40,-1,93,79,72,-1,72,44,93,-1,44,72,36,-1,69,48,47,-1,47,70,69,-1,70,47,8,-1,91,54,28,-1,30,19,18,-1,30,75,19,-1,94,95,96,-1,94,97,95,-1,5,6,87,-1,6,90,87,-1,90,98,87,-1,98,88,87,-1,98,99,88,-1,11,13,67,-1,24,28,25,-1,8,100,2,-1,11,66,60,-1,11,67,66,-1,85,52,101,-1,102,52,85,-1,60,80,62,-1,60,66,80,-1,103,104,105,-1,103,81,104,-1,3,50,4,-1,50,3,53,-1,92,67,13,-1,67,92,68,-1,50,55,51,-1,50,105,55,-1,85,89,84,-1,89,85,101,-1,106,96,95,-1,96,106,86,-1,97,107,108,-1,107,97,94,-1,54,22,21,-1,22,54,91,-1,0,73,109,-1,73,0,78,-1,20,110,108,-1,110,20,43,-1,77,31,93,-1,77,76,31,-1,1,70,2,-1,70,1,71,-1,111,8,112,-1,111,100,8,-1,113,97,114,-1,95,97,113,-1,115,116,99,-1,115,117,116,-1,91,24,57,-1,91,28,24,-1,14,4,51,-1,14,6,4,-1,58,56,63,-1,56,58,46,-1,60,12,11,-1,12,60,59,-1,84,83,61,-1,84,106,83,-1,105,26,55,-1,105,104,26,-1,104,64,26,-1,64,104,92,-1,99,49,115,-1,49,99,98,-1,33,117,34,-1,117,33,116,-1,47,9,8,-1,47,46,9,-1,110,111,114,-1,37,111,110,-1,83,95,113,-1,83,106,95,-1,96,88,99,-1,86,88,96,-1,41,79,78,-1,41,72,79,-1,19,74,42,-1,19,75,74,-1,76,74,75,-1,74,76,77,-1,7,112,8,-1,7,82,112,-1,38,74,36,-1,38,42,74,-1,107,116,33,-1,94,116,107,-1,114,108,110,-1,114,97,108,-1,82,113,112,-1,82,83,113,-1,37,100,111,-1,39,100,37,-1,2,39,40,-1,2,100,39,-1,23,69,71,-1,23,22,69,-1,1,109,118,-1,109,1,0,-1,118,34,117,-1,118,109,34,-1,115,21,23,-1,21,115,49,-1,63,26,64,-1,24,26,63,-1,81,102,80,-1,102,81,103,-1,7,59,82,-1,7,12,59,-1,58,13,10,-1,13,58,65,-1,87,101,5,-1,87,89,101,-1,90,49,98,-1,90,17,49,-1,117,23,118,-1,23,117,115,-1,94,99,116,-1,99,94,96,-1,112,114,111,-1,113,114,112,-1,118,71,1,-1,71,118,23,-1,45,93,44,-1,45,77,93,-1,33,18,107,-1,33,29,18,-1,43,37,110,-1,38,37,43,-1,109,35,34,-1,35,109,73,-1,79,31,32,-1,93,31,79,-1,57,69,91,-1,57,48,69,-1,18,108,107,-1,18,20,108,-1,86,84,89,-1,86,106,84,-1,103,52,102,-1,52,103,53,-1,15,51,55,-1,51,15,14,-1,53,105,50,-1,105,53,103,-1,92,81,68,-1,81,92,104,-1,9,12,7,-1,9,10,12,-1,102,62,80,-1,85,62,102,-1,52,5,101,-1,52,3,5,-1],creaseAngle=1.571,
          coord=Coordinate(DEF='l_tarsal_middle_phalanx_3_coordinate',point=[(-0.0033,-0.0019,-0.0050),(-0.0022,-0.0015,-0.0030),(-0.0038,-0.0001,-0.0026),(0.0035,-0.0017,0.0047),(0.0037,-0.0022,0.0044),(0.0040,-0.0017,0.0042),(0.0040,-0.0021,0.0039),(-0.0015,0.0011,0.0010),(-0.0023,0.0014,-0.0005),(-0.0018,0.0007,0.0009),(-0.0019,0.0003,0.0030),(-0.0021,-0.0001,0.0057),(-0.0017,0.0007,0.0032),(-0.0023,-0.0008,0.0059),(0.0038,-0.0034,0.0030),(0.0024,-0.0033,0.0030),(0.0025,-0.0030,0.0020),(0.0036,-0.0025,0.0018),(0.0026,0.0007,-0.0060),(0.0010,0.0016,-0.0060),(0.0015,0.0020,-0.0063),(0.0016,-0.0022,0.0001),(0.0013,-0.0021,0.0001),(0.0013,-0.0024,-0.0013),(0.0006,-0.0029,0.0034),(0.0012,-0.0030,0.0034),(0.0005,-0.0030,0.0053),(0.0025,-0.0028,0.0016),(0.0011,-0.0026,0.0030),(0.0025,-0.0014,-0.0060),(0.0020,-0.0011,-0.0062),(-0.0011,-0.0014,-0.0063),(-0.0009,-0.0020,-0.0064),(0.0028,-0.0015,-0.0058),(0.0015,-0.0031,-0.0059),(0.0011,-0.0028,-0.0063),(-0.0032,0.0019,-0.0040),(-0.0021,0.0036,-0.0044),(-0.0022,0.0034,-0.0048),(-0.0034,0.0020,-0.0037),(-0.0043,0.0000,-0.0039),(-0.0042,0.0000,-0.0043),(0.0001,0.0024,-0.0058),(0.0004,0.0032,-0.0060),(-0.0030,0.0001,-0.0052),(-0.0021,0.0002,-0.0050),(-0.0018,-0.0006,0.0006),(-0.0021,-0.0005,-0.0003),(-0.0008,-0.0013,0.0005),(0.0034,-0.0024,0.0001),(0.0028,-0.0022,0.0052),(0.0033,-0.0036,0.0043),(0.0032,-0.0006,0.0049),(0.0028,-0.0017,0.0052),(0.0014,-0.0022,0.0020),(0.0018,-0.0035,0.0047),(-0.0010,-0.0019,0.0015),(0.0002,-0.0021,0.0018),(-0.0022,-0.0011,0.0024),(-0.0004,0.0018,0.0037),(-0.0006,0.0016,0.0059),(0.0015,0.0014,0.0034),(0.0014,0.0009,0.0055),(-0.0012,-0.0024,0.0030),(-0.0014,-0.0025,0.0052),(-0.0024,-0.0016,0.0043),(-0.0006,0.0011,0.0064),(-0.0018,-0.0004,0.0062),(-0.0012,-0.0005,0.0064),(-0.0004,-0.0013,0.0001),(-0.0025,-0.0004,-0.0009),(-0.0010,-0.0014,-0.0009),(-0.0035,0.0001,-0.0049),(-0.0011,-0.0028,-0.0063),(-0.0009,0.0006,-0.0052),(-0.0001,0.0002,-0.0055),(-0.0009,-0.0007,-0.0058),(-0.0017,-0.0003,-0.0054),(-0.0034,-0.0018,-0.0054),(-0.0029,-0.0011,-0.0059),(0.0012,0.0005,0.0059),(0.0007,-0.0010,0.0063),(-0.0001,0.0023,0.0011),(0.0019,0.0023,0.0009),(0.0027,0.0010,0.0033),(0.0024,0.0005,0.0050),(0.0041,0.0007,0.0004),(0.0042,-0.0011,0.0025),(0.0041,-0.0007,0.0001),(0.0038,0.0000,0.0030),(0.0042,-0.0015,0.0021),(0.0010,-0.0021,0.0020),(-0.0012,-0.0010,0.0064),(-0.0026,-0.0008,-0.0059),(0.0037,0.0008,-0.0040),(0.0034,0.0021,-0.0014),(0.0043,0.0009,-0.0019),(0.0028,0.0023,-0.0040),(0.0040,-0.0012,0.0001),(0.0041,-0.0010,-0.0019),(-0.0030,0.0018,-0.0024),(0.0036,-0.0003,0.0047),(0.0022,0.0000,0.0054),(0.0016,-0.0014,0.0058),(0.0006,-0.0015,0.0063),(0.0016,-0.0019,0.0058),(0.0031,0.0017,0.0008),(0.0030,0.0008,-0.0058),(0.0020,0.0024,-0.0062),(-0.0009,-0.0030,-0.0059),(0.0006,0.0034,-0.0059),(-0.0014,0.0032,-0.0025),(-0.0004,0.0028,-0.0004),(0.0020,0.0027,-0.0009),(0.0013,0.0032,-0.0038),(0.0033,-0.0026,-0.0015),(0.0035,-0.0013,-0.0040),(0.0025,-0.0029,-0.0038),(0.0002,-0.0027,-0.0038)])))])])
)

### X3D model conversion complete ###

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

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