[2035] | 1 | #ifndef _3DS_H |
---|
| 2 | #define _3DS_H |
---|
| 3 | |
---|
| 4 | //>------ Primary Chunk, at the beginning of each file |
---|
| 5 | #define PRIMARY 0x4D4D |
---|
| 6 | |
---|
| 7 | //>------ Main Chunks |
---|
| 8 | #define OBJECTINFO 0x3D3D // This gives the version of the mesh and is found right before the material and object information |
---|
| 9 | #define VERSION 0x0002 // This gives the version of the .3ds file |
---|
| 10 | #define EDITKEYFRAME 0xB000 // This is the header for all of the key frame info |
---|
| 11 | |
---|
| 12 | //>------ sub defines of OBJECTINFO |
---|
| 13 | #define MATERIAL 0xAFFF // This stored the texture info |
---|
| 14 | #define OBJECT 0x4000 // This stores the faces, vertices, etc... |
---|
| 15 | |
---|
| 16 | //>------ sub defines of MATERIAL |
---|
| 17 | #define MATNAME 0xA000 // This holds the material name |
---|
| 18 | #define MATDIFFUSE 0xA020 // This holds the color of the object/material |
---|
| 19 | #define MATMAP 0xA200 // This is a header for a new material |
---|
| 20 | #define MATMAPFILE 0xA300 // This holds the file name of the texture |
---|
| 21 | |
---|
| 22 | #define OBJECT_MESH 0x4100 // This lets us know that we are reading a new object |
---|
| 23 | |
---|
| 24 | //>------ sub defines of OBJECT_MESH |
---|
| 25 | #define OBJECT_VERTICES 0x4110 // The objects vertices |
---|
| 26 | #define OBJECT_FACES 0x4120 // The objects faces |
---|
| 27 | #define OBJECT_MATERIAL 0x4130 // This is found if the object has a material, either texture map or color |
---|
| 28 | #define OBJECT_UV 0x4140 // The UV texture coordinates |
---|
| 29 | |
---|
| 30 | #include "3dStructs.h" |
---|
| 31 | |
---|
| 32 | // Here is our structure for our 3DS indicies (since .3DS stores 4 unsigned shorts) |
---|
| 33 | struct tIndices { |
---|
| 34 | |
---|
| 35 | unsigned short a, b, c, bVisible; // This will hold point1, 2, and 3 index's into the vertex array plus a visible flag |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | // This holds the chunk info |
---|
| 39 | struct tChunk |
---|
| 40 | { |
---|
| 41 | unsigned short int ID; // The chunk's ID |
---|
| 42 | unsigned int length; // The length of the chunk |
---|
| 43 | unsigned int bytesRead; // The amount of bytes read within that chunk |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | // This class handles all of the loading code |
---|
| 47 | class CLoad3ds |
---|
| 48 | { |
---|
| 49 | public: |
---|
| 50 | CLoad3ds(); // This inits the data members |
---|
| 51 | |
---|
| 52 | // This is the function that you call to load the 3DS |
---|
| 53 | bool Import3DS(C3dModel *pModel, char *strFileName); |
---|
| 54 | |
---|
| 55 | private: |
---|
| 56 | // This reads in a string and saves it in the char array passed in |
---|
| 57 | int GetString(char *); |
---|
| 58 | |
---|
| 59 | // This reads the next chunk |
---|
| 60 | void ReadChunk(tChunk *); |
---|
| 61 | |
---|
| 62 | // This reads the next large chunk |
---|
| 63 | void ProcessNextChunk(C3dModel *pModel, tChunk *); |
---|
| 64 | |
---|
| 65 | // This reads the object chunks |
---|
| 66 | void ProcessNextObjectChunk(C3dModel *pModel, t3dObject *pObject, tChunk *); |
---|
| 67 | |
---|
| 68 | // This reads the material chunks |
---|
| 69 | void ProcessNextMaterialChunk(C3dModel *pModel, tChunk *); |
---|
| 70 | |
---|
| 71 | // This reads the RGB value for the object's color |
---|
| 72 | void ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk); |
---|
| 73 | |
---|
| 74 | // This reads the objects vertices |
---|
| 75 | void ReadVertices(t3dObject *pObject, tChunk *); |
---|
| 76 | |
---|
| 77 | // This reads the objects face information |
---|
| 78 | void ReadVertexIndices(t3dObject *pObject, tChunk *); |
---|
| 79 | |
---|
| 80 | // This reads the texture coodinates of the object |
---|
| 81 | void ReadUVCoordinates(t3dObject *pObject, tChunk *); |
---|
| 82 | |
---|
| 83 | // This reads in the material name assigned to the object and sets the materialID |
---|
| 84 | void ReadObjectMaterial(C3dModel *pModel, t3dObject *pObject, tChunk *pPreviousChunk); |
---|
| 85 | |
---|
| 86 | // This computes the vertex normals for the object (used for lighting) |
---|
| 87 | void ComputeNormals(C3dModel *pModel); |
---|
| 88 | |
---|
| 89 | // This frees memory and closes the file |
---|
| 90 | void CleanUp(); |
---|
| 91 | |
---|
| 92 | // The file pointer |
---|
| 93 | FILE *m_FilePointer; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | #endif |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 101 | // |
---|
| 102 | // * QUICK NOTES * |
---|
| 103 | // |
---|
| 104 | // This file is created in the hopes that you can just plug it into your code |
---|
| 105 | // easily. You will probably want to query more chunks though for animation, etc.. |
---|
| 106 | // |
---|
| 107 | // |
---|
| 108 | // Ben Humphrey (DigiBen) |
---|
| 109 | // Game Programmer |
---|
| 110 | // DigiBen@GameTutorials.com |
---|
| 111 | // Co-Web Host of www.GameTutorials.com |
---|
| 112 | // |
---|
| 113 | // |
---|