le3d - LightEngine 3D
A straightforward C++ 3D software engine for real-time graphics
objfile.h
Go to the documentation of this file.
1 
33 #ifndef LE_OBJFILE_H
34 #define LE_OBJFILE_H
35 
36 #include "global.h"
37 #include "config.h"
38 
39 #include "geometry.h"
40 #include "color.h"
41 #include "mesh.h"
42 
43 #include <stdio.h>
44 #include <string.h>
45 
46 /*****************************************************************************/
52 {
57  float shininess;
58  float transparency;
62  {
63  strcpy(name, "default");
64  ambient = LeColor(255, 255, 255, 0);
65  diffuse = LeColor(255, 255, 255, 0);
66  specular = LeColor(255, 255, 255, 0);
67  shininess = 0.0f;
68  transparency = 0.0f;
69  texture[0] = '\0';
70  }
71 };
72 
73 /*****************************************************************************/
78 class LeObjFile
79 {
80 public:
81  LeObjFile(const char * filename);
82  ~LeObjFile();
83 
84  int getNoMeshes();
85  const char * getMeshName(int index);
86 
87  LeMesh * load(int index);
88  void save(const LeMesh * mesh);
89 
90 private:
91  void importMeshAllocate(FILE * file, LeMesh * mesh);
92  void importMeshData(FILE * file, LeMesh * mesh);
93 
94  void exportHeader(FILE * file, const LeMesh * mesh);
95  void exportVertexes(FILE * file, const LeMesh * mesh);
96  void exportNormals(FILE * file, const LeMesh * mesh);
97  void exportTexCoords(FILE * file, const LeMesh * mesh);
98  void exportTriangles(FILE * file, const LeMesh * mesh);
99  void exportMaterials(FILE * file, const LeMesh * mesh);
100 
101  void loadMaterialLibraries(FILE * file);
102  void importMaterialAllocate(FILE * file);
103  void importMaterialData(FILE * file);
104  LeObjMaterial * getMaterialFromName(const char * name);
105 
106  void readVertex(LeMesh * mesh, int index);
107  void readNormal(LeMesh * mesh, int index);
108  void readTriangle(LeMesh * mesh, int index);
109  void readTexCoord(LeMesh * mesh, int index);
110  void readColor(const char * buffer, LeColor & color);
111 
112  char * path;
114  LeObjMaterial * materials;
115  LeObjMaterial * curMaterial;
116  int noMaterials;
118  LeVertex * normals;
119  int noNormals;
121  int readLine(FILE * file);
122  char line[LE_OBJ_MAX_LINE+1];
123 };
124 
125 #endif // LE_OBJFILE_H
LeObjMaterial()
Definition: objfile.h:61
LeColor ambient
Definition: objfile.h:54
LightEngine 3D: Mesh container and manipulator.
LightEngine 3D: General engine configuration file.
LeColor specular
Definition: objfile.h:56
float shininess
Definition: objfile.h:57
LightEngine 3D: Global helpers and definitions.
LeMesh * load(int index)
Load the mesh of the given index from the file.
Definition: objfile.cpp:66
~LeObjFile()
Definition: objfile.cpp:54
#define LE_OBJ_MAX_LINE
Definition: config.h:52
int getNoMeshes()
Get the number of meshes in the file.
Definition: objfile.cpp:263
Represent an RGBA color.
Definition: color.h:42
void save(const LeMesh *mesh)
Load the mesh of the given index from the file.
Definition: objfile.cpp:100
Represent a vertex in 3D space.
Definition: geometry_scalar.h:46
LightEngine 3D: Color implementation.
LeObjFile(const char *filename)
Definition: objfile.cpp:45
Load 3D meshes in Wavefront object format.
Definition: objfile.h:78
char name[LE_OBJ_MAX_NAME+1]
Definition: objfile.h:53
LeColor diffuse
Definition: objfile.h:55
Contain and manage Wavefront object files materials.
Definition: objfile.h:51
#define LE_OBJ_MAX_NAME
Definition: config.h:51
LightEngine 3D: Vertex / axis / plane / matrix objects.
char texture[LE_OBJ_MAX_NAME+1]
Definition: objfile.h:59
const char * getMeshName(int index)
Get the name of the mesh of the given index.
Definition: objfile.cpp:284
float transparency
Definition: objfile.h:58
Contain and manage a 3D mesh.
Definition: mesh.h:47