#VRML V2.0 utf8
Configuration {
  accumulation Accumulation { enabled TRUE }
  stencilBits 8
}
ColorBackground {
  color 1 1 1 1
  clearStencil TRUE
}
NavigationInfo { type [ "EXAMINE" "ANY" ] }
Viewpoint {
  type "ORTHOGONAL"
}

DEF TRANSFORMER_NAV NavigationInfo { type [ "TRANSFORM" ] }

DEF DRAW_OPAQUE_KEY SingleKeySensor { key "o" }
DEF DRAW_HALOED_KEY SingleKeySensor { key "l" state TRUE }
DEF DRAW_SURFACE_KEY SingleKeySensor { key "b" state TRUE }
DEF EXPORT_KEY SingleKeySensor { key "O" }
DEF SNAP_KEY SingleKeySensor { key "S" }

DEF VERTEX_SHAPE_KEY SingleKeySensor {
  key "v"
  boolean FALSE
  numberOfStates 5
  intState 2 # disc
}

DEF EDGE_SHAPE_KEY SingleKeySensor {
  key "e"
  boolean FALSE
  numberOfStates 4
  intState 2 # strip
}

DEF HIDE_SINGULARITIES_KEY SingleKeySensor {
  boolean FALSE
  key "s"
}

DEF HIDE_DISCONTINUITY_KEY SingleKeySensor {
  boolean FALSE
  key "d"
}

DEF SNAP Snapshot {
  image Image { }
  fileFormat "jpg"
  sequence FALSE
  dirName "."
  fileName "spherical_overlay"
}

Transform {
  rotation 1 0 0 -1.5708
  bboxCenter 0 0 0
  children [
    Shape {
      drawDepth FALSE
      appearance Appearance {
        material Material {
          diffuseColor 0.5 0.5 0.5
          ambientIntensity 0.7
          specularColor 0.5 0.5 0.5
        }
      }
      geometry Sphere {
        slices 32
        stacks 32
      }
    }
    Switch {
      whichChoice -1
      children [
        Shape {
          appearance Appearance {
            material Material {
              transparency 0.0001
            }
          }
          geometry DEF GEOM1 ArrangementOnSphereMarked {
            drawSurface FALSE
            # drawOpaque TRUE
            drawHaloed TRUE
            aosEdgeStyle "strip"
            aosEdgeRadius 0.03
            aosEdgeColor 0 0 1
            aosEdgeLineWidth 3
            aosVertexStyle "disc"
            aosVertexRadius 0.1
            aosVertexPointSize 6
            aosIsolatedVertexStyle "disc"
            # insertionStrategy "increment"
            aosMarkedEdgeIndex 100
            aosMarkedVertexIndex 0
            aosMarkedVertexStyle "none"
            coord DEF COORD EpecCoordinate {
              exactPoint [-1 0 0, 0 -1 0]
            }
            normal EpecNormal {
              exactVector [0 0 1]
            }
            curveIndex [0 1 1 0]
            normalIndex[0 0]
          }
        }
       ]
    }
    Switch {
      whichChoice -1
      children [
        Shape {
          appearance Appearance {
            material Material {
              transparency 0.0001
            }
          }
          geometry DEF GEOM2 ArrangementOnSphereMarked {
            drawSurface FALSE
            # drawOpaque TRUE
            drawHaloed TRUE
            aosEdgeStyle "strip"
            aosEdgeRadius 0.03
            aosEdgeColor 0 1 0
            aosEdgeLineWidth 3
            aosVertexStyle "disc"
            aosVertexRadius 0.1
            aosVertexPointSize 6
            aosIsolatedVertexStyle "disc"
            # insertionStrategy "increment"
            aosMarkedEdgeIndex 100
            aosMarkedVertexIndex 0
            aosMarkedVertexStyle "none"
            coord DEF COORD2 EpecCoordinate {
              exactPoint [-1 0 0, 0 1 0]
            }
            normal EpecNormal {
              exactVector [0 0 -1]
            }
            curveIndex [0 1 1 0]
            normalIndex[0 0]
          }
        }
       ]
    }

    Switch {
      whichChoice 0
      children [
        Shape {
          appearance Appearance {
            material Material {
              transparency 0.0001
            }
          }
          geometry ArrangementOnSphereMarked {
            drawSurface FALSE
            # drawOpaque TRUE
            drawHaloed TRUE
            aosEdgeStyle "strip"
            aosEdgeColor 0 0.5 0.5
            aosEdgeRadius 0.03
            aosEdgeLineWidth 3
            aosVertexStyle "disc"
            aosVertexRadius 0.1
            aosVertexPointSize 6
            aosIsolatedVertexStyle "disc"
            aosVertexColor 0.6 0.6 0
            aosBoundaryVertexColor 0.5 0 0
            # insertionStrategy "increment"
            aosMarkedVertexIndex 0
            aosMarkedVertexStyle "none"
            overlay [USE GEOM1
                     USE GEOM2
                    ]
          }
        }
       ]
    }

    # The singularity points:
    DEF SINGULARITIES_SWITCH Switch {
      whichChoice 0
      children [
	Group {
	  children [
	    Shape {
	      appearance DEF BOUNDARY_APP Appearance {
	        material Material {
		  # ambientIntensity 1
		  diffuseColor 0.4 0.4 0.4
		  # specularColor 0.8 0.8 0.8
		  # transparency 0.0001
		}
	      }
	      geometry Sphere {
    	        center 0 0 1
	        radius 0.05
	      }
	    }
	    Shape {
              appearance DEF AXES_APP Appearance {
                material Material {
                  # ambientIntensity 1
                  diffuseColor 0.4 0.4 0.4
                  # specularColor 0.3 0.3 0.3
                  # transparency 0.0001
                }
              }
	      geometry Sphere {
    	        center 0 0 -1
	        radius 0.05
	      }
	    }
	   ]
	}
      ]
    }

    # The discontinuity arc:
    DEF DISCONTINUITY_SWITCH Switch {
      whichChoice 0
      children [
        Shape {
	  appearance USE BOUNDARY_APP
	  geometry Extrusion {
	    creaseAngle 2.0
	    beginCap TRUE
	    endCap TRUE
	    loop FALSE
	    crossSectionRadius 0.01
	    spine [
		   0 0 1,
		   -0.0980171 0 0.995185,
		   -0.19509 0 0.980785,
		   -0.290285 0 0.95694,
		   -0.382683 0 0.92388,
		   -0.471397 0 0.881921,
		   -0.55557 0 0.83147,
		   -0.634393 0 0.77301,
		   -0.707107 0 0.707107,
		   -0.77301 0 0.634393,
		   -0.83147 0 0.55557,
		   -0.881921 0 0.471397,
		   -0.92388 0 0.382683,
		   -0.95694 0 0.290285,
		   -0.980785 0 0.19509,
		   -0.995185 0 0.0980171,
		   -1 0 0,
		   -0.995185 0 -0.0980171,
		   -0.980785 0 -0.19509,
		   -0.95694 0 -0.290285,
		   -0.92388 0 -0.382683,
		   -0.881921 0 -0.471397,
		   -0.83147 0 -0.55557,
		   -0.77301 0 -0.634393,
		   -0.707107 0 -0.707107,
		   -0.634393 0 -0.77301,
		   -0.55557 0 -0.83147,
		   -0.471397 0 -0.881921,
		   -0.382683 0 -0.92388,
		   -0.290285 0 -0.95694,
		   -0.19509 0 -0.980785,
		   -0.0980171 0 -0.995185,
		   0 0 -1,
		  ]
	  }
	}
       ]
    }

    # The axes:
    DEF AXES Transform {
      scale 0.1 0.1 0.1
      children [
	Shape {
          appearance USE AXES_APP
	  geometry Sphere { radius 0.1 }
	}
	DEF CS_AXIS Transform {
	  translation 0 1.5 0
	  children [
	    Shape {
	      appearance USE AXES_APP
	      geometry Cylinder {
		radius 0.1
		height 3
		set_is_bottom_visible FALSE
		set_is_top_visible FALSE
	      }
	    }
	    Transform {
	      translation 0 1.7 0
	      children [
		Shape {
		  appearance USE AXES_APP
		  geometry Cone {
		    bottomRadius 0.2
		    height 0.4
		  }
		}
	       ]
	    }
	   ]
	}
	Transform {
	  rotation 0 0 -1 1.57
	  children [ USE CS_AXIS ]
	}
	Transform {
	  rotation 1 0 0 1.57
	  children [ USE CS_AXIS ]
	}
       ]
    }
#     Transform {
#       translation 2 0 0
#       children [
#         USE ARRANGMENT
#        ]
#     }
   ]
}

ROUTE DRAW_OPAQUE_KEY.state TO GEOM1.drawOpaque
ROUTE DRAW_HALOED_KEY.state TO GEOM1.drawHaloed

ROUTE VERTEX_SHAPE_KEY.intState TO GEOM1.aosVertexStyleId
ROUTE EDGE_SHAPE_KEY.intState TO GEOM1.aosEdgeStyleId

ROUTE SNAP_KEY.state TO SNAP.trigger
# ROUTE EXPORT_KEY.press TO GEOM.export

ROUTE HIDE_DISCONTINUITY_KEY.intState TO DISCONTINUITY_SWITCH.whichChoice
ROUTE HIDE_SINGULARITIES_KEY.intState TO SINGULARITIES_SWITCH.whichChoice
