import classpath
from org.web3d.x3d.jsail.Core.X3DObject import X3DObject as X3D
from org.web3d.x3d.jsail.fields.SFStringObject import SFStringObject as SFString
from org.web3d.x3d.jsail.Core.headObject import headObject as head
from org.web3d.x3d.jsail.Core.metaObject import metaObject as meta
from org.web3d.x3d.jsail.Core.SceneObject import SceneObject as Scene
from org.web3d.x3d.jsail.Core.ProtoDeclareObject import ProtoDeclareObject as ProtoDeclare
from org.web3d.x3d.jsail.Core.ProtoInterfaceObject import ProtoInterfaceObject as ProtoInterface
from org.web3d.x3d.jsail.Core.fieldObject import fieldObject as field
from org.web3d.x3d.jsail.Core.ProtoBodyObject import ProtoBodyObject as ProtoBody
from org.web3d.x3d.jsail.Grouping.TransformObject import TransformObject as Transform
from org.web3d.x3d.jsail.fields.SFRotationObject import SFRotationObject as SFRotation
from org.web3d.x3d.jsail.Core.ISObject import ISObject as IS
from org.web3d.x3d.jsail.Core.connectObject import connectObject as connect
from org.web3d.x3d.jsail.Shape.ShapeObject import ShapeObject as Shape
from org.web3d.x3d.jsail.Shape.AppearanceObject import AppearanceObject as Appearance
from org.web3d.x3d.jsail.Shape.MaterialObject import MaterialObject as Material
from org.web3d.x3d.jsail.Texturing.ImageTextureObject import ImageTextureObject as ImageTexture
from org.web3d.x3d.jsail.Geometry3D.ExtrusionObject import ExtrusionObject as Extrusion
from org.web3d.x3d.jsail.fields.SFFloatObject import SFFloatObject as SFFloat
from org.web3d.x3d.jsail.fields.MFVec2fObject import MFVec2fObject as MFVec2f
from org.web3d.x3d.jsail.fields.MFVec3fObject import MFVec3fObject as MFVec3f
from org.web3d.x3d.jsail.fields.SFVec3fObject import SFVec3fObject as SFVec3f
from org.web3d.x3d.jsail.fields.SFColorObject import SFColorObject as SFColor
from org.web3d.x3d.jsail.Geometry3D.SphereObject import SphereObject as Sphere
from org.web3d.x3d.jsail.Geometry3D.IndexedFaceSetObject import IndexedFaceSetObject as IndexedFaceSet
from org.web3d.x3d.jsail.fields.MFInt32Object import MFInt32Object as MFInt32
from org.web3d.x3d.jsail.fields.SFBoolObject import SFBoolObject as SFBool
from org.web3d.x3d.jsail.Rendering.CoordinateObject import CoordinateObject as Coordinate
from org.web3d.x3d.jsail.Grouping.GroupObject import GroupObject as Group
from org.web3d.x3d.jsail.Time.TimeSensorObject import TimeSensorObject as TimeSensor
from org.web3d.x3d.jsail.fields.SFTimeObject import SFTimeObject as SFTime
from org.web3d.x3d.jsail.Interpolation.CoordinateInterpolatorObject import CoordinateInterpolatorObject as CoordinateInterpolator
from org.web3d.x3d.jsail.fields.MFFloatObject import MFFloatObject as MFFloat
from org.web3d.x3d.jsail.Core.ROUTEObject import ROUTEObject as ROUTE
from org.web3d.x3d.jsail.Interpolation.OrientationInterpolatorObject import OrientationInterpolatorObject as OrientationInterpolator
from org.web3d.x3d.jsail.fields.MFRotationObject import MFRotationObject as MFRotation
from org.web3d.x3d.jsail.Interpolation.PositionInterpolatorObject import PositionInterpolatorObject as PositionInterpolator
from org.web3d.x3d.jsail.Core.ProtoInstanceObject import ProtoInstanceObject as ProtoInstance
X3D0 = X3D() \
   .setProfile(SFString("Immersive")) \
   .setVersion(SFString("3.3")) \
   .setHead(head() \
    .addMeta(meta() \
     .setContent(SFString("CircleFishPrototype.x3d")) \
     .setName(SFString("title")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("This is a prototype for a CircleFish, which is also used by CircleFishLod. Default fish size: length is 1 m (Y-axis), max Height is 1 m (Z-axis), max Width is 10 cm (X-axis).")) \
     .setName(SFString("description")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("Ildeniz Duman")) \
     .setName(SFString("creator")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("Scott Tufts")) \
     .setName(SFString("translator")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("1 May 1998")) \
     .setName(SFString("created")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("11 December 2001")) \
     .setName(SFString("translated")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("1 April 2007")) \
     .setName(SFString("modified")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("http://X3dGraphics.com/examples/X3dForWebAuthors/KelpForestExhibit/CircleFishPrototype.x3d")) \
     .setName(SFString("reference")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter05AppearanceMaterialTextures/CircleFishPrototype.x3d")) \
     .setName(SFString("identifier")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit")) \
     .setName(SFString("generator")) \
    ) \
    .addMeta(meta() \
     .setContent(SFString("../license.html")) \
     .setName(SFString("license")) \
    ) \
   ) \
   .setScene(Scene() \
    .addChild(ProtoDeclare() \
     .setName(SFString("CircleFish")) \
     .setProtoInterface(ProtoInterface() \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("skinTextureUrl")) \
       .setType(SFString("MFString")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("fishScale")) \
       .setType(SFString("SFVec3f")) \
       .setValue(SFString("1 1 1")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("fishColor")) \
       .setType(SFString("SFColor")) \
       .setValue(SFString("0.5 0.5 0.5")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("finColor")) \
       .setType(SFString("SFColor")) \
       .setValue(SFString("0.5 0.5 0.5")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("positionKey")) \
       .setType(SFString("MFFloat")) \
       .setValue(SFString("0.0 0.125 0.25 0.375 0.5 0.625 0.750 0.8751")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("positionKeyValue")) \
       .setType(SFString("MFVec3f")) \
       .setValue(SFString("1.5 2 0 1.5 0 -1.0 0 -1 -1.0 -1.5 0 -1.0 -1.5 2 0 -1.5 0 1.0 0 -2 1.0 1.5 0 1.0 1.5 2 0")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("orientationKey")) \
       .setType(SFString("MFFloat")) \
       .setValue(SFString("0.0 0.25 0.5 0.750 1")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("orientationKeyValue")) \
       .setType(SFString("MFRotation")) \
       .setValue(SFString("0 1 0 0 0 1 0 -1.57 0 1 0 -3.14 0 1 0 -4.71 0 1 0 -6.28")) \
      ) \
      .addField(field() \
       .setAccessType(SFString("inputOutput")) \
       .setName(SFString("orbitTime")) \
       .setType(SFString("SFTime")) \
       .setValue(SFString("90")) \
      ) \
     ) \
     .setProtoBody(ProtoBody() \
      .addChild(Transform() \
       .setDEF(SFString("Way")) \
       .addChild(Transform() \
        .setRotation(SFRotation([1,0,0,1.395])) \
        .addChild(Transform() \
         .setDEF(SFString("FishTransform")) \
         .setIS(IS() \
          .addConnect(connect() \
           .setNodeField(SFString("scale")) \
           .setProtoField(SFString("fishScale")) \
          ) \
         ) \
         .addChild(Shape() \
          .setAppearance(Appearance() \
           .setMaterial(Material() \
            .setDEF(SFString("FishColor")) \
            .setIS(IS() \
             .addConnect(connect() \
              .setNodeField(SFString("diffuseColor")) \
              .setProtoField(SFString("fishColor")) \
             ) \
            ) \
           ) \
           .setTexture(ImageTexture() \
            .setDEF(SFString("FishTexture")) \
            .setIS(IS() \
             .addConnect(connect() \
              .setNodeField(SFString("url")) \
              .setProtoField(SFString("skinTextureUrl")) \
             ) \
            ) \
           ) \
          ) \
          .setGeometry(Extrusion() \
           .setDEF(SFString("FishBodyExtrusion")) \
           .setCreaseAngle(SFFloat(0.57)) \
           .setCrossSection(MFVec2f([-0.1,1.0,0.1,1,0.5,0.5,0.5,-0.5,0.1,-1,-0.1,-1,-0.5,-0.5,-0.5,0.5,-0.1,1])) \
           .setScale(MFVec2f([0.03,0.03,0.05,0.3,0.05,0.45,0.1,0.5,0.05,0.45,0.05,0.2,0.03,0.4])) \
           .setSpine(MFVec3f([0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0,0.2,0,0,0,0])) \
          ) \
         ) \
         .addChild(Shape() \
          .setAppearance(Appearance() \
           .setDEF(SFString("FinSkin")) \
           .setMaterial(Material() \
            .setDEF(SFString("FinColor")) \
            .setTransparency(SFFloat(0.2)) \
            .setIS(IS() \
             .addConnect(connect() \
              .setNodeField(SFString("diffuseColor")) \
              .setProtoField(SFString("finColor")) \
             ) \
            ) \
           ) \
          ) \
         ) \
         .addChild(Transform() \
          .setTranslation(SFVec3f([0.015,0.8,-0.2])) \
          .addChild(Shape() \
           .setDEF(SFString("Eye")) \
           .setAppearance(Appearance() \
            .setMaterial(Material() \
             .setDiffuseColor(SFColor([0.5,0.5,0.5])) \
             .setShininess(SFFloat(1)) \
             .setSpecularColor(SFColor([0.3,0.3,0.3])) \
            ) \
           ) \
           .setGeometry(Sphere() \
            .setRadius(SFFloat(0.03)) \
           ) \
          ) \
         ) \
         .addChild(Transform() \
          .setTranslation(SFVec3f([-0.015,0.8,-0.2])) \
          .addChild(Shape() \
           .setUSE(SFString("Eye")) \
          ) \
         ) \
         .addChild(Transform() \
          .setScale(SFVec3f([1,1,0.7])) \
          .setTranslation(SFVec3f([0,0.98,0])) \
          .addChild(Shape() \
           .setUSE(SFString("Eye")) \
          ) \
         ) \
         .addChild(Transform() \
          .setDEF(SFString("LeftPectoral")) \
          .setTranslation(SFVec3f([0.04,0.4,0.3])) \
          .addChild(Shape() \
           .setAppearance(Appearance() \
            .setUSE(SFString("FinSkin")) \
           ) \
           .setGeometry(IndexedFaceSet() \
            .setCoordIndex(MFInt32([0,1,2,-1])) \
            .setSolid(SFBool(False)) \
            .setCoord(Coordinate() \
             .setPoint(MFVec3f([0,0,0,0,0.2,0,0.2,0.1,0])) \
            ) \
           ) \
          ) \
         ) \
         .addChild(Transform() \
          .setDEF(SFString("RightPectoral")) \
          .setTranslation(SFVec3f([-0.04,0.4,0.3])) \
          .addChild(Shape() \
           .setAppearance(Appearance() \
            .setUSE(SFString("FinSkin")) \
           ) \
           .setGeometry(IndexedFaceSet() \
            .setCoordIndex(MFInt32([0,1,2,-1])) \
            .setSolid(SFBool(False)) \
            .setCoord(Coordinate() \
             .setPoint(MFVec3f([0,0,0,0,0.2,0,-0.2,0.1,0])) \
            ) \
           ) \
          ) \
         ) \
        ) \
       ) \
       .addChild(Group() \
        .setDEF(SFString("AnimationGroup")) \
        .addChild(TimeSensor() \
         .setDEF(SFString("Timer")) \
         .setCycleInterval(SFTime(5)) \
         .setLoop(SFBool(True)) \
        ) \
        .addChild(CoordinateInterpolator() \
         .setDEF(SFString("Waggler")) \
         .setKey(MFFloat([0.0,0.15,0.28,0.4,0.55,0.7,0.85,1])) \
         .setKeyValue(MFVec3f([0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0,0.2,0,0,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0.05,0.3,0,0.1,0.2,0,0.2,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0,0.2,0,0,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,-0.05,0.3,0,-0.1,0.2,0,-0.2,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0.0,0.2,0,0,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0.05,0.3,0,0.1,0.2,0,0.2,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0,0.2,0,0,0,0,0,1,0,0,0.8,0,0,0.6,0,0,0.5,0,0,0.3,0,0,0.2,0,0,0,0])) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("fraction_changed")) \
         .setFromNode(SFString("Timer")) \
         .setToField(SFString("set_fraction")) \
         .setToNode(SFString("Waggler")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("value_changed")) \
         .setFromNode(SFString("Waggler")) \
         .setToField(SFString("set_spine")) \
         .setToNode(SFString("FishBodyExtrusion")) \
        ) \
        .addChild(OrientationInterpolator() \
         .setDEF(SFString("LeftPectoralRotation")) \
         .setKey(MFFloat([0,0.3,0.7,1])) \
         .setKeyValue(MFRotation([0,1,0,-.349,0,1,0,0,0,1,0,0,0,1,0,-.349])) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("fraction_changed")) \
         .setFromNode(SFString("Timer")) \
         .setToField(SFString("set_fraction")) \
         .setToNode(SFString("LeftPectoralRotation")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("value_changed")) \
         .setFromNode(SFString("LeftPectoralRotation")) \
         .setToField(SFString("set_rotation")) \
         .setToNode(SFString("LeftPectoral")) \
        ) \
        .addChild(OrientationInterpolator() \
         .setDEF(SFString("RightPectoralRotation")) \
         .setKey(MFFloat([0,0.3,0.7,1])) \
         .setKeyValue(MFRotation([0,1,0,.349,0,1,0,0,0,1,0,0,0,1,0,.349])) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("fraction_changed")) \
         .setFromNode(SFString("Timer")) \
         .setToField(SFString("set_fraction")) \
         .setToNode(SFString("RightPectoralRotation")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("value_changed")) \
         .setFromNode(SFString("RightPectoralRotation")) \
         .setToField(SFString("set_rotation")) \
         .setToNode(SFString("RightPectoral")) \
        ) \
        .addChild(TimeSensor() \
         .setDEF(SFString("OrbitClock")) \
         .setLoop(SFBool(True)) \
         .setIS(IS() \
          .addConnect(connect() \
           .setNodeField(SFString("cycleInterval")) \
           .setProtoField(SFString("orbitTime")) \
          ) \
         ) \
        ) \
        .addChild(PositionInterpolator() \
         .setDEF(SFString("CirclefishPath")) \
         .setIS(IS() \
          .addConnect(connect() \
           .setNodeField(SFString("key")) \
           .setProtoField(SFString("positionKey")) \
          ) \
          .addConnect(connect() \
           .setNodeField(SFString("keyValue")) \
           .setProtoField(SFString("positionKeyValue")) \
          ) \
         ) \
        ) \
        .addChild(OrientationInterpolator() \
         .setDEF(SFString("CircleFishAngle")) \
         .setIS(IS() \
          .addConnect(connect() \
           .setNodeField(SFString("key")) \
           .setProtoField(SFString("orientationKey")) \
          ) \
          .addConnect(connect() \
           .setNodeField(SFString("keyValue")) \
           .setProtoField(SFString("orientationKeyValue")) \
          ) \
         ) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("fraction_changed")) \
         .setFromNode(SFString("OrbitClock")) \
         .setToField(SFString("set_fraction")) \
         .setToNode(SFString("CirclefishPath")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("fraction_changed")) \
         .setFromNode(SFString("OrbitClock")) \
         .setToField(SFString("set_fraction")) \
         .setToNode(SFString("CircleFishAngle")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("value_changed")) \
         .setFromNode(SFString("CirclefishPath")) \
         .setToField(SFString("set_translation")) \
         .setToNode(SFString("Way")) \
        ) \
        .addChild(ROUTE() \
         .setFromField(SFString("value_changed")) \
         .setFromNode(SFString("CircleFishAngle")) \
         .setToField(SFString("set_rotation")) \
         .setToNode(SFString("Way")) \
        ) \
       ) \
      ) \
     ) \
    ) \
# ==================== 
    .addChild(ProtoInstance() \
     .setName(SFString("CircleFish")) \
    ) \
   ) \

X3D0.toFileX3D("/x3d-code/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter05AppearanceMaterialTextures//CircleFishPrototype_RoundTrip.x3d")
