Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

c3ds.h

Go to the documentation of this file.
00001 /************************************
00002  * 3ds C++ File Loader                          *
00003  * Author: Andrea Ingegneri                     *
00004  * Date: 16/12/2001                                     *
00005  * Distribution: LGPL (www.gnu.org) *
00006  ************************************/
00007 
00008 
00009 extern char *gVersion;
00010 
00011 class C3dsFileFormat
00012 {
00013 public:
00014         C3dsFileFormat() {}
00015 protected:
00016 #pragma pack(2)
00017         typedef struct _chunk3ds
00018         {
00019                 unsigned short  Flag;
00020                 long                    Size;
00021         } chunk3ds;
00022 #pragma pack()
00023 
00024 typedef struct _Transform3dsMatrix
00025 {
00026         float _11, _12, _13;
00027         float _21, _22, _23;
00028         float _31, _32, _33;
00029 } Transform3dsMatrix;
00030 
00031 typedef struct _Translate3dsMatrix
00032 {
00033         float _11, _12, _13;
00034 } Translate3dsMatrix;
00035 
00036 class ViewPortLayout
00037 {
00038 public:
00039         ViewPortLayout(unsigned short Style, short Active, short Unknow1, short Swap, 
00040                                    short Unknow2, short Swap_prior, short Swap_view) : style(Style),
00041                                                                                                                                            active(Active),
00042                                                                                                                                            unknow1(Unknow1),
00043                                                                                                                                            swap(Swap),
00044                                                                                                                                            unknow2(Unknow2),
00045                                                                                                                                            swap_prior(Swap_prior),
00046                                                                                                                                            swap_view(Swap_view) {}
00047         unsigned short  style;
00048     short                       active;
00049         short                   unknow1;
00050     short                       swap;
00051         short                   unknow2;
00052     short                       swap_prior;
00053     short                       swap_view;
00054 };
00055 
00056 enum {CameraNameSize = 11};
00057 
00058 class ViewPortData
00059 {
00060 public:
00061         ViewPortData(short Flags, short Axis_lockout, short Win_x, short Win_y, short Win_w, short Win_h,
00062                                  short Win_view, float Zoom, float Worldcenter_x, float Worldcenter_y, float Worldcenter_z,
00063                                  float Horiz_ang, float Vert_ang, char *CameraName) : flags(Flags), axis_lockout(Axis_lockout),
00064                                                                                                                                           win_x(Win_x), win_y(Win_y),
00065                                                                                                                                           win_w(Win_w), win_h(Win_h),
00066                                                                                                                                           win_view(Win_view), zoom(Zoom),
00067                                                                                                                                           worldcenter_x(Worldcenter_x),
00068                                                                                                                                           worldcenter_y(Worldcenter_y),
00069                                                                                                                                           worldcenter_z(Worldcenter_z),
00070                                                                                                                                           horiz_ang(Horiz_ang), vert_ang(Vert_ang),
00071                                                                                                                                           camera_name(CameraName) {}
00072         short   flags, axis_lockout;
00073         short   win_x, win_y, win_w, win_h, win_view;
00074         float   zoom; 
00075         float   worldcenter_x, worldcenter_y, worldcenter_z;
00076         float   horiz_ang, vert_ang;
00077         string  camera_name;
00078 };
00079 
00080 enum {
00081         CHUNK_VERSION   = 0x0002,
00082     CHUNK_RGBF      = 0x0010,
00083     CHUNK_RGBB      = 0x0011,
00084 
00085         CHUNK_PERCENTW  = 0x0030,
00086         CHUNK_PERCENTF  = 0x0031,
00087 
00088     CHUNK_PRJ       = 0xC23D,
00089     CHUNK_MLI       = 0x3DAA,
00090 
00091     CHUNK_MAIN      = 0x4D4D,
00092         CHUNK_OBJMESH   = 0x3D3D,
00093                         CHUNK_ONEUNIT   = 0x0100,
00094             CHUNK_BKGCOLOR  = 0x1200,
00095             CHUNK_AMBCOLOR  = 0x2100,
00096                         CHUNK_DEFAULT_VIEW = 0x3000,
00097                                 CHUNK_VIEW_TOP = 0x3010,
00098                                 CHUNK_VIEW_BOTTOM = 0x3020,
00099                                 CHUNK_VIEW_LEFT = 0x3030,
00100                                 CHUNK_VIEW_RIGHT = 0x3040,
00101                                 CHUNK_VIEW_FRONT = 0x3050,
00102                                 CHUNK_VIEW_BACK = 0x3060,
00103                                 CHUNK_VIEW_USER = 0x3070,
00104                                 CHUNK_VIEW_CAMERA = 0x3080,
00105             CHUNK_OBJBLOCK  = 0x4000,
00106                 CHUNK_TRIMESH   = 0x4100,
00107                     CHUNK_VERTLIST  = 0x4110,
00108                     CHUNK_VERTFLAGS = 0x4111,
00109                     CHUNK_FACELIST  = 0x4120,
00110                     CHUNK_FACEMAT   = 0x4130,
00111                     CHUNK_MAPLIST   = 0x4140,
00112                     CHUNK_SMOOLIST  = 0x4150,
00113                     CHUNK_TRMATRIX  = 0x4160,
00114                     CHUNK_MESHCOLOR = 0x4165,
00115                     CHUNK_TXTINFO   = 0x4170,
00116                 CHUNK_LIGHT     = 0x4600,
00117                     CHUNK_SPOTLIGHT = 0x4610,
00118                 CHUNK_CAMERA    = 0x4700,
00119                 CHUNK_HIERARCHY = 0x4F00,
00120 
00121         CHUNK_VIEWPORT_LAYOUT_OLD       = 0x7000,
00122                         CHUNK_VIEWPORT_DATA_OLD = 0x7010,
00123                                 CHUNK_VIEWPORT_SIZE = 0x7020,
00124                                         CHUNK_NETWORK_VIEW = 0X7030,
00125 
00126         CHUNK_VIEWPORT_LAYOUT   = 0x7001,
00127                         CHUNK_VIEWPORT_DATA     = 0x7011,
00128                         CHUNK_VIEWPORT_DATA3 = 0x7012,
00129 
00130                 CHUNK_MATERIAL  = 0xAFFF,
00131             CHUNK_MATNAME   = 0xA000,
00132             CHUNK_AMBIENT   = 0xA010,
00133             CHUNK_DIFFUSE   = 0xA020,
00134             CHUNK_SPECULAR  = 0xA030,
00135             CHUNK_TEXTURE   = 0xA200,
00136             CHUNK_BUMPMAP   = 0xA230,
00137             CHUNK_MAPFILE   = 0xA300,
00138         CHUNK_KEYFRAMER = 0xB000,
00139             CHUNK_AMBIENTKEY    = 0xB001,
00140             CHUNK_TRACKINFO = 0xB002,
00141                 CHUNK_TRACKOBJNAME  = 0xB010,
00142                 CHUNK_TRACKPIVOT    = 0xB013,
00143                 CHUNK_TRACKPOS      = 0xB020,
00144                 CHUNK_TRACKROTATE   = 0xB021,
00145                 CHUNK_TRACKSCALE    = 0xB022,
00146                 CHUNK_TRACKMORPH    = 0xB026,
00147                 CHUNK_TRACKHIDE     = 0xB029,
00148                 CHUNK_OBJNUMBER     = 0xB030,
00149             CHUNK_TRACKCAMERA = 0xB003,
00150                 CHUNK_TRACKFOV  = 0xB023,
00151                 CHUNK_TRACKROLL = 0xB024,
00152             CHUNK_TRACKCAMTGT = 0xB004,
00153             CHUNK_TRACKLIGHT  = 0xB005,
00154             CHUNK_TRACKLIGTGT = 0xB006,
00155             CHUNK_TRACKSPOTL  = 0xB007,
00156             CHUNK_FRAMES    = 0xB008,
00157         };
00158 };
00159 
00160 class C3dsFileLoader : public C3dsFileFormat
00161 {
00162 public:
00163 // Constructor
00164         C3dsFileLoader() : C3dsFileFormat(), PC(0), mFileSize(0) {}
00165 // Methods
00166         void            ProcessFile(string FileName);
00167 private:
00168         void            movePC(long forward);
00169         bool            ParseChunks();
00170         bool            ReadBlock(char *dest, long size);
00171         float           ReadRealNumber();
00172         bool            SkipChunk(chunk3ds &chunk);
00173         void            FileSize();
00174         bool            isOk();
00175         void            ReadASCIIZ(char *dest);
00176         void            ReadRGBF();
00177         void            ReadRGBB();
00178         void            ReadObjBlock();
00179         void            ReadVertList();
00180         void            ReadFaceList();
00181         void            ReadFaceMat();
00182         void            ReadMapList();
00183         void            ReadSmoothList();
00184         void            ReadTrMatrix();
00185         void            ReadLight();
00186         void            ReadSpotLight();
00187         void            ReadCamera();
00188         void            ReadMatName();
00189         void            ReadMapFile();
00190         void            ReadFrames();
00191         void            ReadTrackObjName();
00192         void            ReadTrackPos();
00193         void            ReadTrackRot();
00194         void            ReadTrackScale();
00195         void            ReadObjNumber();
00196         void            ReadObjChunk();
00197         void            ReadOneUnit();
00198         void            ReadViewPortData();
00199         void            ReadViewUser();
00200         void            ReadViewTop();
00201         void            ReadViewBottom();
00202         void            ReadViewLeft();
00203         void            ReadViewRight();
00204         void            ReadViewFront();
00205         void            ReadViewBack();
00206         void            ReadViewCamera();
00207         void            ReadViewPortLayout();
00208         void            ReadViewPortSize();
00209         void            EndReading();
00210         
00211         ifstream        mInputFile;
00212 protected:
00213         long            PC;             // File Pointer
00214         long            mFileSize;
00215 // Inheritable functions for polymorphism
00216         virtual void            User3dVert(float x, float y, float z);
00217         virtual void            User3dFace(unsigned short A, unsigned short B, unsigned short C, unsigned short Flags);
00218         virtual void            UserCamera(float px, float py, float pz,
00219                                                                    float tx, float ty, float tz,
00220                                                                    float Bank, float Lens);
00221         virtual void            UserFaceMaterial(string Name, int Number);
00222         virtual void            UserMapVertex(float U, float V);
00223         virtual void            UserTransformMatrix(const Transform3dsMatrix &Transform, const Translate3dsMatrix &Translate);
00224         virtual void            UserLight(float x, float y, float z);
00225         virtual void            UserSpotLight(float x, float y, float z, float HotSpot, float FallOff);
00226         virtual void            UserMatName(const string Name);
00227         virtual void            UserMapFile(const string FileName);
00228         virtual void            UserFrames(long Start, long End);
00229         virtual void            UserTrackObjectName(const string Name, int Key1, int Key2, int Key3);
00230         virtual void            UserTrackPos(int Frame, long Flags, float x, float y, float z);
00231         virtual void            UserTrackRot(int Frame, long Flags, float DegX, float DegY, float DegZ);
00232         virtual void            UserTrackScale(int Frame, long Flags, float ScaleX, float ScaleY, float ScaleZ);
00233         virtual void            UserObjNumber(int ObjNumber);
00234         virtual void            UserObjName(string Name);
00235         virtual void            UserChunkObj();
00236         virtual void            UserOneUnit(float Unit);
00237         virtual void            UserViewPortLayout(ViewPortLayout &Layout);
00238         virtual void            UserViewPortSize(int PosX, int PosY, int Width, int Height);
00239         virtual void            UserViewPortData(ViewPortData &Data);
00240         virtual void            UserViewUser(float x, float y, float z, float Width, float XYangle, float YZangle, float BackAngle);
00241         virtual void            UserViewCamera(string CameraName);
00242         virtual void            UserEndOfFile();
00243 };

Generated on Thu May 23 17:51:00 2002 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001