Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

3ds.h

00001 #ifndef _3DS_H
00002 #define _3DS_H
00003 
00004 #include <iostream>
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 
00008 # include <string>
00009 # include <vector>
00010 
00011 #include "constants.h"
00012 
00013 using namespace std;
00014 
00015 //>------ Primary Chunk, at the beginning of each file
00016 #define PRIMARY       0x4D4D
00017 
00018 //>------ Main Chunks
00019 #define OBJECTINFO    0x3D3D                // This gives the version of the mesh and is found right before the material and object information
00020 #define VERSION       0x0002                // This gives the version of the .3ds file
00021 #define EDITKEYFRAME  0xB000                // This is the header for all of the key frame info
00022 
00023 //>------ sub defines of OBJECTINFO
00024 #define MATERIAL      0xAFFF                // This stored the texture info
00025 #define OBJECT        0x4000                // This stores the faces, vertices, etc...
00026 
00027 //>------ sub defines of MATERIAL
00028 #define MATNAME       0xA000                // This holds the material name
00029 #define MATDIFFUSE    0xA020                // This holds the color of the object/material
00030 #define MATMAP        0xA200                // This is a header for a new material
00031 #define MATMAPFILE    0xA300                // This holds the file name of the texture
00032 
00033 #define OBJECT_MESH   0x4100                // This lets us know that we are reading a new object
00034 
00035 //>------ sub defines of OBJECT_MESH
00036 #define OBJECT_VERTICES     0x4110          // The objects vertices
00037 #define OBJECT_FACES        0x4120          // The objects faces
00038 #define OBJECT_MATERIAL     0x4130          // This is found if the object has a material, either texture map or color
00039 #define OBJECT_UV           0x4140          // The UV texture coordinates
00040 
00041 
00042 // Here is our structure for our 3DS indicies (since .3DS stores 4 unsigned shorts)
00043 struct tIndices {                           
00044 
00045     unsigned short a, b, c, bVisible;       // This will hold point1, 2, and 3 index's into the vertex array plus a visible flag
00046 };
00047 
00048 // This holds the chunk info
00049 struct tChunk
00050 {
00051     unsigned short int ID;                  // The chunk's ID       
00052     unsigned int length;                    // The length of the chunk
00053     unsigned int bytesRead;                 // The amount of bytes read within that chunk
00054 };
00055 
00056 // This class handles all of the loading code
00057 class CLoad3DS
00058 {
00059 public:
00060     CLoad3DS();                             // This inits the data members
00061 
00062     // This is the function that you call to load the 3DS
00063     bool Import3DS(t3DModel *pModel, char *strFileName);
00064 
00065 private:
00066     // This reads in a string and saves it in the char array passed in
00067     int GetString(char *);
00068 
00069     // This reads the next chunk
00070     void ReadChunk(tChunk *);
00071 
00072     // This reads the next large chunk
00073     void ProcessNextChunk(t3DModel *pModel, tChunk *);
00074 
00075     // This reads the object chunks
00076     void ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *);
00077 
00078     // This reads the material chunks
00079     void ProcessNextMaterialChunk(t3DModel *pModel, tChunk *);
00080 
00081     // This reads the RGB value for the object's color
00082     void ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk);
00083 
00084     // This reads the objects vertices
00085     void ReadVertices(t3DObject *pObject, tChunk *);
00086 
00087     // This reads the objects face information
00088     void ReadVertexIndices(t3DObject *pObject, tChunk *);
00089 
00090     // This reads the texture coodinates of the object
00091     void ReadUVCoordinates(t3DObject *pObject, tChunk *);
00092 
00093     // This reads in the material name assigned to the object and sets the materialID
00094     void ReadObjectMaterial(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk);
00095     
00096     // This computes the vertex normals for the object (used for lighting)
00097     //void ComputeNormals(t3DModel *pModel);
00098 
00099     // This frees memory and closes the file
00100     void CleanUp();
00101     
00102     // The file pointer
00103     FILE *m_FilePointer;
00104     
00105     // These are used through the loading process to hold the chunk information
00106     tChunk *m_CurrentChunk;
00107     tChunk *m_TempChunk;
00108 };
00109 
00110 
00111 #endif
00112 
00113 
00115 //
00116 // * QUICK NOTES * 
00117 // 
00118 // This file is created in the hopes that you can just plug it into your code
00119 // easily.  You will probably want to query more chunks though for animation, etc..
00120 //
00121 // 
00122 // Ben Humphrey (DigiBen)
00123 // Game Programmer
00124 // DigiBen@GameTutorials.com
00125 // Co-Web Host of www.GameTutorials.com
00126 //
00127 //

Generated on Thu Jun 16 21:50:42 2005 for scourge by  doxygen 1.4.0