####################################################################################################
#
# Invoking X3D model self-test:
#
#   $ python ClaudeCodeSimpleModelTextured.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='ClaudeCodeSimpleModelTextured.x3d',name='title'),
    meta(content='Model generated by Claude Code, with small cleanups: Orbiting Primitives with Textures, using url links to open-source Wikimedia, only one of which worked. Four textured 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='originals/scene_textured.x3d',name='reference'),
    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/ClaudeCodeSimpleModelTextured.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(direction=(-1,-2,-1),intensity=0.9),
    PointLight(attenuation=(0,0,0.05),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 — Earth texture '),
      Transform(
        children=[
        Shape(
          appearance=Appearance(
            material=Material(shininess=0.4,specularColor=(0.3,0.3,0.3)),
            texture=ImageTexture(url=["https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Land_ocean_ice_2048.jpg/1024px-Land_ocean_ice_2048.jpg"])),
          geometry=Sphere(radius=0.85))]),
      Comment(' Red Box — brick texture '),
      Transform(translation=(2.4,0,0),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(specularColor=(0.2,0.2,0.2)),
            texture=ImageTexture(url=["https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Brick_-_Upper_Merion_Township_Building.jpg/512px-Brick_-_Upper_Merion_Township_Building.jpg"]),
            textureTransform=TextureTransform(scale=(2,2))),
          geometry=Box(size=(0.6,0.6,0.6)))]),
      Comment(' Green Cone — wood texture '),
      Transform(translation=(-2.4,0,0),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(shininess=0.3,specularColor=(0.3,0.2,0.1)),
            texture=ImageTexture(url=["https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Aa_wooden_texture.jpg/512px-Aa_wooden_texture.jpg"]),
            textureTransform=TextureTransform(scale=(1,2))),
          geometry=Cone(bottomRadius=0.45,height=1.0))]),
      Comment(' Cylinder — marble texture '),
      Transform(translation=(0,0,2.4),
        children=[
        Shape(
          appearance=Appearance(
            material=Material(shininess=0.8,specularColor=(0.6,0.6,0.6)),
            texture=ImageTexture(url=["https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/White_marble_texture.jpg/512px-White_marble_texture.jpg"]),
            textureTransform=TextureTransform(scale=(1,2))),
          geometry=Cylinder(height=0.75,radius=0.3))])]),
    Comment(' Ground disc — stone/concrete texture '),
    Transform(translation=(0,-1.4,0),
      children=[
      Shape(
        appearance=Appearance(
          material=Material(specularColor=(0.2,0.2,0.2),transparency=0.1),
          texture=ImageTexture(url=["https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Concrete_Rough_003_COLOR.jpg/512px-Concrete_Rough_003_COLOR.jpg"]),
          textureTransform=TextureTransform(scale=(4,4))),
        geometry=Cylinder(height=0.05,radius=3.5))])])
)

### X3D model conversion complete ###

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

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