










(*****************************************************************************)
(* $Id: types.ml,v 1.17 1997/05/01 17:59:10 doub Exp $                       *)
(* Types for VRcaML                                                          *)
(*****************************************************************************)

(*****************************************************************************)
(* Basic types                                                               *)
(*****************************************************************************)

type vect2D = float * float ;;
type vect3D = float * float * float ;;

type rotation = vect3D * float ;;

type color = float * float * float ;;

type time = float ;;

type frame =
{ height : float * float ; (* y axis *)
  width  : float * float ; (* x axis *)
  depth  : float * float   (* z axis *)
} ;;

type clip =
{ clip_loop       : bool ;
  clip_start_time : time ;
  clip_stop_time  : time ;
  clip_urls       : string list
} ;;

type fontStyle =
{ family        : string ;
  horizontal    : bool ;
  justify       : string list ;
  language      : string ;
  left_to_right : bool ;
  size          : float ; (* height, in obj space units *)
  spacing       : float ;
  style         : string ;
  top_to_bottom : bool
} ;;

type image =
{ image_width      : int ;
  image_height     : int ;
  image_components : int ;
  image_pixels     : int list  (* pixel list length = (width * height) *)
} ;;


(*****************************************************************************)
(* Textures                                                                  *)
(*****************************************************************************)

type textureCoordinate = vect2D list ;;

type movieTexture =
{ movieTexture_speed : float ;
  movieTexture_clip  : clip
} ;;

type textureType =
  ImageTexture of string list
| MovieTexture of movieTexture
| PixelTexture of image
;;

type textureItem = 
{ texture_repeatS     : bool ;
  texture_repeatT     : bool ;
  texture_type        : textureType ;
  (* VRML "TextureTransform" node *)
  texture_center      : vect2D ;
  texture_rotation    : float ;
  texture_scale       : vect2D ;
  texture_translation : vect2D
} ;;

type texture = 
  NoTexture
| Texture of textureItem
;;


(*****************************************************************************)
(* Material                                                                  *)
(*****************************************************************************)

type materialItem =
{ ambient_intensity : float ;
  diffuse_color     : color ;
  emissive_color    : color ;
  shininess         : float ;
  specular_color    : color ;
  transparency      : float
} ;;

type material =
  NoMaterial
| Material of materialItem
;;


(*****************************************************************************)
(* Unlit geometric objects                                                   *)
(*****************************************************************************)

type point =
{ point_color      : color ;
  point_coordinate : vect3D
} ;;

type pointSet = point list ;;

type line =
{ line_point1 : vect3D ;
  line_point2 : vect3D ;
  line_color  : color
} ;;

type lineSet = line list ;;

type unlitGeometric =
  LineSet of lineSet
| PointSet of pointSet
;;


(*****************************************************************************)
(* Shapes                                                                    *)
(*****************************************************************************)

type box = { box_size : vect3D } ;;

type cone =
{ cone_bottom_radius : float ;
  cone_height        : float ;
  cone_side          : bool ;
  cone_bottom        : bool
} ;;

type cylinder =
{ cylinder_bottom : bool ;
  cylinder_height : float ;
  cylinder_radius : float ;
  cylinder_side   : bool ;
  cylinder_top    : bool
} ;;

type elevationGrid =
{ grid_color              : color list ;
  grid_texture_coordinate : textureCoordinate ;
  grid_height             : float list ;
  grid_ccw                : bool ;
  grid_color_per_vertex   : bool ;
  grid_solid              : bool ;
  grid_x_dimension        : int ;
  grid_x_spacing          : float ;
  grid_z_dimension        : int ;
  grid_z_spacing          : float
} ;;

type extrusion =
{ extrusion_begin_cap     : bool ;
  extrusion_ccw           : bool ;
  extrusion_convex        : bool ;
  extrusion_cross_section : vect2D list ;    (* 2D shape *)
  extrusion_end_cap       : bool ;
  extrusion_orientation   : rotation list ;
  extrusion_scale         : vect2D list ;
  extrusion_solid         : bool ;
  extrusion_spine         : vect3D list 
} ;;

type sphere = { sphere_radius : float } ;;


type text =
{ content    : string list ; (* "string" field in VRML Text node *)
  font_style : fontStyle ;
  length     : float list ;
  max_extent : float
} ;;


type face = vect3D list ;;

type faceSet =
{ faceSet_faces                    : face list ;
  faceSet_texture_coordinate       : textureCoordinate ;
  faceSet_ccw                      : bool ;
  faceSet_convex                   : bool ;
  faceSet_solid                    : bool ;
  faceSet_texture_coordinate_index : int list
} ;;


type shape =
  Box of box
| Cone of cone
| Cylinder of cylinder
| ElevationGrid of elevationGrid
| Extrusion of extrusion
| FaceSet of faceSet
| Sphere of sphere
| Text of text
;;


(*****************************************************************************)
(* Lights                                                                    *)
(*****************************************************************************)

type directionalLight = { directionalLight_direction : vect3D } ;;

type pointLight =
{ pointLight_attenuation : vect3D ;
  pointLight_radius      : float
} ;;

type spotLight =
{ spotLight_attenuation   : vect3D ;
  spotLight_beam_width    : float ;
  spotLight_cut_off_angle : float ;
  spotLight_direction     : vect3D ;
  spotLight_radius        : float
} ;;

type lightType = 
  DirectionalLight of directionalLight
| PointLight of pointLight
| SpotLight of spotLight
;;

type light =
{ light_ambient_intensity : float ;
  light_color             : color ;
  light_intensity         : float ;
  light_type              : lightType
} ;;

  
(*****************************************************************************)
(* Geometric objects                                                         *)
(*****************************************************************************)

type geometric =
{ shape    : shape ;
  material : material ;
  texture  : texture
} ;;


(*****************************************************************************)
(* View point                                                                *)
(*****************************************************************************)

(* NOTA : no "position" field in VRcaML, but one in VRML ! *)

type viewPoint =
{ viewPoint_field_of_view    : float ;
  viewPoint_jump             : bool ;
  viewPoint_description      : string ;
  (* Begin of NavigationInfo part *)
  navigation_avatar_size      : float list ;
  navigation_headlight        : bool ;
  navigation_speed            : float ;
  navigation_type             : string list ; 
                              (* "type" field of NavigationInfo node *)
  navigation_visibility_limit : float
} ;;


(*****************************************************************************)
(* Sound                                                                     *)
(*****************************************************************************)

type sound =
{ sound_direction   : vect3D ;
  sound_intensity   : float ;
  sound_max_back    : float ;
  sound_max_front   : float ;
  sound_min_back    : float ;
  sound_min_front   : float ;
  sound_priority    : float ;
  sound_spatialize  : bool ;
  (* "source" field of Sound node = AudioClip node *)
  sound_description : string ;
  sound_pitch       : float ;
  sound_clip        : clip
} ;;


(*****************************************************************************)
(* Non-positionable objects : background and fog                             *)
(*****************************************************************************)

(* Background *)

type background =
{ ground_angle : float list ;
  ground_color : color list ;
  back_url     : string list ;
  bottom_url   : string list ;
  front_url    : string list ;
  left_url     : string list ;
  right_url    : string list ;
  top_url      : string list ;
  sky_angle    : float list ;
  sky_color    : color list
} ;;


(* Fog *)

type fog =
{ fog_color            : color ;
  fog_type             : string ;
  fog_visibility_range : float
} ;;


(* Non-positionable objects definition *)

type vrml_special =
  Background of background
| Fog of fog
;;


(*****************************************************************************)
(* VRML objects properties : anchor, billboard and collision                 *)
(*****************************************************************************)

(* Anchor *)

type anchorItem =
{ anchor_description  : string ;
  anchor_parameters   : string list ;
  anchor_urls         : string list
} ;;

type anchor =
  NoAnchor
| Anchor of anchorItem
;;


(* Billboard *)

type billboardItem = { axis_of_rotation : vect3D } ;;

type billboard =
  NoBillboard
| Billboard of billboardItem
;;


(* Collision Box *)
(* NOTA : collisionBox can be used both for a special collisionable area *)
(*        and the definition of the collision property of a VRML obj. *)

type collisionBox =
{ collide     : bool ;
  bbox_center : vect3D ;
  bbox_size   : vect3D
  (* No "proxy" field *)
} ;;

type collision =
  NoCollision
| Collision of collisionBox
;;


(*****************************************************************************)
(* Proximity box                                                             *)
(*****************************************************************************)

type proximityBox =
{ proximity_center : vect3D ;
  proximity_size   : vect3D
} ;;


(*****************************************************************************)
(* VRML objects, positionable objects and Level Of Detail                    *)
(*****************************************************************************)

type vrml_object = 
{ objects    : vrml_positionable list ;
  children   : vrml_object list ;
  position   : vect3D ;
  rotation   : rotation ;
  scale      : vect3D ;
  frame      : frame ;
  unique     : bool ;
  anchor     : anchor ;
  billboard  : billboard ;
  collision  : collision }

and vrml_positionable =
    Geometric of geometric
  | UnlitGeometric of unlitGeometric
  | CollisionBox of collisionBox
  | Light of light
  | LOD of lod
  | Sound of sound
  | ViewPoint of viewPoint

and lod =
{ lod_levels : vrml_object list ; (* n *)
  (* lod_center : vect3D ; *)
  lod_ranges : float list }       (* n-1 *) 
;;


(*****************************************************************************)
(* Animations                                                                *)
(*****************************************************************************)

type changing = 
     Translation of (float list * vect3D list) 
   | Rotation of (float list * rotation list) 
   | Scale of (float list * vect3D list)
   | ChangeColor
;;

type trigger = 
     Instant of time 
   | Click of vrml_object 
   | Enter of (proximityBox * vrml_object) 
   | Exit of (proximityBox * vrml_object)
;;

type animation =
{ target        : vrml_object ;
  start_trigger : trigger list ;
  stop_trigger  : trigger list ;
  loop          : bool ;
  duration      : float ;
  memory        : bool ;
  movie         : changing list
} ;;



(*****************************************************************************)
(* VRML world                                                                *)
(*****************************************************************************)

type vrml_world =
{ info       : string list ;
  title      : string ;
  tree       : vrml_object ;
  specials   : vrml_special list ;
  animations : animation list
} ;;












