00001 // ** 00002 // ** coded by gip [ Gorka Lertxundi Osa -glertxundi@terra.es- ] 00003 // ** for your pleasure. :) 00004 // ** 00005 // ** TAseLoader: C++ class for reading .ase 3D file format 00006 // ** Copyright (C) 03/08/2002 [ 23:28 x) ] Gorka Lertxundi Osa 00007 // ** 00008 // ** <english version> [http://www.gnu.org/copyleft/gpl.html] 00009 // ** It is distributed under GPL license: 00010 // ** This program is free software; you can redistribute it and/or 00011 // ** modify it under the terms of the GNU General Public License 00012 // ** as published by the Free Software Foundation; either version 2 00013 // ** of the License, or (at your option) any later version. 00014 // ** 00015 // ** This program is distributed in the hope that it will be useful, 00016 // ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // ** GNU General Public License for more details. 00019 // ** <spanish version> [http://gugs.sindominio.net/gnu-gpl/gples.html] 00020 // ** 00021 00022 #ifndef _TASELOADER_H__ 00023 #define _TASELOADER_H__ 00024 00025 #define ASEHEADER "*3DSMAX_ASCIIEXPORT" 00026 #define GOBJECT "*GEOMOBJECT" 00027 #define OBJNAME "*NODE_NAME" 00028 #define NUM_VERTEX "*MESH_NUMVERTEX" 00029 #define NUM_FACES "*MESH_NUMFACES" 00030 #define NUM_TVERTEX "*MESH_NUMTVERTEX" 00031 #define NUM_TFACES "*MESH_NUMTVFACES" 00032 #define VERTEX "*MESH_VERTEX" 00033 #define FACE "*MESH_FACE" 00034 #define TVERTEX "*MESH_TVERT" 00035 #define TFACE "*MESH_TFACE" 00036 #define ID_MATERIAL "*MATERIAL_REF" 00037 #define NUM_MATERIALES "*MATERIAL_COUNT" 00038 #define MATERIAL "*MATERIAL" 00039 #define NOMBRE_MATERIAL "*MATERIAL_NAME" 00040 #define MAT_DIFFUSE "*MATERIAL_DIFFUSE" 00041 #define TEXTURE "*BITMAP" 00042 #define COBJECT "*CAMERAOBJECT" 00043 #define LOBJECT "*LIGHTOBJECT" 00044 00045 // Light3D 00046 #define SPOT 1 00047 #define OMNI 2 00048 00049 #ifdef WIN32 00050 #include <windows.h> 00051 #endif 00052 00053 #include <math.h> 00054 #include <string> 00055 #include <fstream> 00056 #include <iostream> 00057 #include <iomanip> 00058 00059 using namespace std; 00060 00061 typedef unsigned int uint; 00062 00063 // 3D scene structs.... wops :) 00064 00065 typedef struct ColorRGB 00066 { 00067 float r; 00068 float g; 00069 float b; 00070 }ColorRGB; 00071 00072 typedef struct Vertex2D 00073 { 00074 float u; 00075 float v; 00076 }Vertex2D; 00077 00078 typedef struct Vertex3D 00079 { 00080 float x; 00081 float y; 00082 float z; 00083 }Vertex3D; 00084 00085 typedef struct Triangle 00086 { 00087 unsigned int a; 00088 unsigned int b; 00089 unsigned int c; 00090 }Triangle; 00091 00092 typedef struct Face 00093 { 00094 Vertex3D vertex[3]; 00095 Vertex3D vertex_normal[3]; 00096 Vertex3D face_normal; 00097 Vertex2D tex_coords[3]; 00098 }Face; 00099 00100 typedef struct Shape3D 00101 { 00102 char *name; 00103 int NumOfKnot; 00104 Vertex3D *knot; 00105 }Shape3D; 00106 00107 typedef struct Object3D 00108 { 00109 Face *faces; 00110 char *name; 00111 int NumOfVertex; 00112 int NumOfFaces; 00113 bool tex_read; 00114 }Object3D; 00115 00116 typedef struct Camera3D 00117 { 00118 char *name; 00119 Vertex3D eye; 00120 Vertex3D center; 00121 Vertex3D up_vector; 00122 float fov; 00123 float Near; 00124 float Far; 00125 }Camera3D; 00126 00127 typedef struct Light3D 00128 { 00129 char *name; 00130 int type; 00131 Vertex3D eye; 00132 Vertex3D center; 00133 ColorRGB color; 00134 float falloff; 00135 }Light3D; 00136 00137 typedef struct Scene3D 00138 { 00139 int NumberOfObjects; 00140 int NumberOfCameras; 00141 int NumberOfLights; 00142 int NumberOfShapes; 00143 Object3D *objs; 00144 Camera3D *cams; 00145 Light3D *lights; 00146 Shape3D *shapes; 00147 }Scene3D; 00148 00149 typedef struct SceneInfo 00150 { 00151 unsigned int ObjsNum; 00152 unsigned int CamsNum; 00153 unsigned int LightsNum; 00154 unsigned int ShapesNum; 00155 }SceneInfo; 00156 00157 class TAseLoader 00158 { 00159 public: 00160 // Constructor 00161 TAseLoader() 00162 { 00163 normals_read = false; 00164 }; 00165 // Destructor 00166 ~TAseLoader() 00167 { 00168 // freeing.... wops :) 00169 00170 }; 00171 uint LoadFile(char *filename); 00172 Scene3D* GetScene(void); 00173 Object3D* GetObject(int obj_num); 00174 Camera3D* GetCamera(int cam_num); 00175 Light3D* GetLight(int light_num); 00176 Shape3D* GetShape(int shape_num); 00177 uint GetObjectsNum(void); 00178 uint GetCamerasNum(void); 00179 uint GetLightsNum(void); 00180 char* GetAsciiVersion(void); 00181 void DumpInfoToFile(char *file); 00182 protected: 00183 Vertex3D ReadVertex(char *lstring); 00184 Triangle ReadTriangle(char *lstring); 00185 Vertex3D ReadUV(char *lstring); 00186 Triangle ReadUVFaces(char *lstring); 00187 Vertex3D ReadFaceNormal(char *lstring); 00188 Vertex3D ReadVertexNormal(char *lstring); 00189 Vertex3D ReadTmPos(char *lstring); 00190 int ReadLightType(char *lstring); 00191 ColorRGB ReadLightColor(char *lstring); 00192 float ReadLightFallOff(char *lstring); 00193 float ReadCameraFov(char *lstring); 00194 float ReadCameraNear(char *lstring); 00195 float ReadCameraFar(char *lstring); 00196 uint ReadShapeVertexCount(char *lstring); 00197 Vertex3D ReadShapeKNOT(char *lstring); 00198 SceneInfo* ReadSceneInfo(char *filename); 00199 00200 // var's 00201 char* ascii_version; 00202 Scene3D* ase_scene; 00203 // + checker var's =) 00204 bool normals_read; 00205 }; 00206 00207 #endif