####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python ClaudeCodeSimpleModel.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='Immersive',version='4.0',
  head=head(
    children=[
    meta(content='ClaudeCodeSimpleModel.x3d',name='title'),
    meta(content='Model generated by Claude Code, with small cleanups: Orbiting Primitives with no textures, showing four colored 3D primitives — sphere, box, cone, cylinder — orbiting on an animated platform.',name='description'),
    meta(content='Claude (Anthropic)',name='author'),
    meta(content='Don Brutzman',name='translator'),
    meta(content='27 February 2026',name='created'),
    meta(content='28 February 2026',name='modified'),
    meta(content='ClaudeCodeExampleChatLog.pdf',name='documentation'),
    meta(content='original model produced by LLM, careful review and precautions are warranted',name='warning'),
    meta(content='Claude Sonnet 4.6',name='generator'),
    meta(content='https://claude.ai/new',name='reference'),
    meta(content='X3DOM version originals/x3d_scene.html',name='reference'),
    meta(content='ClaudeCodeSimpleModelHtmlX3DOM.png',name='Image'),
    meta(content='ClaudeCodeSimpleModelScreenshots.png',name='Image'),
    meta(content='ClaudeCodeSimpleModelScreenshotCastle.png',name='Image'),
    meta(content='History of initial changes at https://sourceforge.net/p/x3d/code/38626/log/?path=/www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/LLM',name='reference'),
    meta(content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit',name='generator'),
    meta(content='https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/LargeLanguageModels/ClaudeCodeSimpleModel.x3d',name='identifier'),
    meta(content='https://creativecommons.org/licenses/by/4.0/',name='license')]),
  Scene=Scene(
    children=[
    Background(skyColor=[(0.05,0.05,0.1)]),
    NavigationInfo(),
    Viewpoint(description='Default',orientation=(1,0,0,-0.22),position=(0,2,9)),
    Comment(' Lighting '),
    DirectionalLight(color=(0.8,0.85,1.0),direction=(-1,-2,-1),intensity=0.8),
    PointLight(attenuation=(0,0,0.1),color=(0.5,0.6,1.0),intensity=1.5,location=(3,5,3),radius=25),
    Comment(' Animated orbit group '),
    Transform(DEF='ORBIT_GROUP',
      children=[
      TimeSensor(DEF='TIMER',cycleInterval=7,loop=True),
      OrientationInterpolator(DEF='SPINNER',key=[0,0.5,1],keyValue=[(0,1,0,0),(0,1,0,3.14159),(0,1,0,6.28318)]),
      ROUTE(fromField='fraction_changed',fromNode='TIMER',toField='set_fraction',toNode='SPINNER'),
      ROUTE(fromField='value_changed',fromNode='SPINNER',toField='set_rotation',toNode='ORBIT_GROUP'),
      Comment(' Central Sphere '),
      Transform(
        children=[
        Shape(
          appearance=Appearance(
            material=Material(diffuseColor=(0.2,0.4,0.9),emissiveColor=(0.02,0.05,0.2),shininess=0.85,specularColor=(0.7,0.8,1.0))),
          geometry=Sphere(radius=0.85))]),
      Comment(' Red Box '),
      Transform(translation=(2.4,0,0),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(diffuseColor=(0.9,0.2,0.35),emissiveColor=(0.15,0.01,0.04),shininess=0.75,specularColor=(1.0,0.6,0.7))),
          geometry=Box(size=(0.6,0.6,0.6)))]),
      Comment(' Green Cone '),
      Transform(translation=(-2.4,0,0),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(diffuseColor=(0.15,0.85,0.5),emissiveColor=(0.01,0.12,0.04),shininess=0.7,specularColor=(0.5,1.0,0.7))),
          geometry=Cone(bottomRadius=0.45,height=1.0))]),
      Comment(' Yellow Cylinder '),
      Transform(translation=(0,0,2.4),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(diffuseColor=(1.0,0.75,0.1),emissiveColor=(0.15,0.1,0.0),shininess=0.8,specularColor=(1.0,0.95,0.6))),
          geometry=Cylinder(height=0.75,radius=0.3))])]),
    Comment(' Ground disc '),
    Transform(translation=(0,-1.4,0),
      children=[
      Shape(
        appearance=Appearance(
          material=Material(diffuseColor=(0.1,0.15,0.45),shininess=0.5,specularColor=(0.3,0.4,0.8),transparency=0.35)),
        geometry=Cylinder(height=0.05,radius=3.5))])])
)

### X3D model conversion complete ###

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

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