//------------------------------------------------------------------------------
// File: LWO.cpp
//
// Desc: Class for Newtek LightWave [6] Object loader
//
//
// Copyright (C) 2001 Alexander Sokolov A.K.A. Z-Mechanic
// E-mail: cis@vsmpo.ru
//------------------------------------------------------------------------------

#pragma warn -csu

#include <system.hpp>
#include <classes.hpp>
#include <stdio>
#include <fcntl>
#include <math>
#include <math3d.h>
#include <debugconsole.h>
#include <kernel.h>

#ifndef __LWO_H
#define __LWO_H

class LWO {
  private:

    struct lwo_color {
      float r, g, b;
    };

    struct lwo_each_surf {
      short uv_map;
      short image;
      unsigned int GL_ref;
    };

    struct lwo_surf {
      char *name;
      lwo_color color;
      lwo_color diffuse;
      unsigned char count;
      lwo_each_surf *prop;
    };

    struct lwo_uv_point {
      float x, y;
    };

    typedef lwo_uv_point *lwo_uv_matrix;

    struct lwo_uv_tag {
      char *name;
      lwo_uv_matrix *data;
      bool uv_full;
    };

    KERNEL                     *kernel;
    unsigned short             LWO_PolCnt;
    TStringList                *LWO_ImgNames;
    point_3D                   *LWO_Pnts;
    unsigned short             *LWO_Poly;
    point_3D                   *LWO_BBox;
    unsigned short             *LWO_Text;
    lwo_surf                   *LWO_Surf;
    lwo_uv_tag                 *LWO_Vmap;
    point_3D                   *LWO_Normals;
    bool CompareChunk(char *mustbe, char *whatget);
    unsigned int ChunkToUInt(char *input);
    float ChunkToFloat(char *input);
    unsigned short ChunkToUShort(char *input);
    void CalcNormals();
    void Optimize();
  public:
    LWO();
    ~LWO();
    void LoadFromFile(AnsiString FileName);
    unsigned short PolygonCount();
    unsigned short SurfaceCount();
    point_3D* Points();
    unsigned short* Polygons();
    point_3D* BoundingBox();
    unsigned short* Textures();
    lwo_surf* Surfaces();
    lwo_uv_tag* UVmap();
    TStringList* Images();
    point_3D* Normals();
    unsigned int Optimizer[5];
};

#endif
