Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
modelfile.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/core/vertex.h"
29 #include "graphics/core/material.h"
30 
31 #include "math/vector.h"
32 
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 
37 
38 
39 // Graphics module namespace
40 namespace Gfx {
41 
42 
50 {
51  LOD_Constant = -1,
52  LOD_Low = 1,
53  LOD_Medium = 2,
54  LOD_High = 4
55 };
56 
62 {
72  std::string tex1Name;
74  std::string tex2Name;
80  int state;
81 
83  {
84  variableTex2 = true;
85  lodLevel = LOD_Constant;
86  state = 0;
87  }
88 };
89 
90 
98 {
99 public:
100  CModelFile();
101  ~CModelFile();
102 
104  bool ReadTextModel(const std::string &fileName);
106  bool ReadTextModel(std::istream &stream);
107 
109  bool WriteTextModel(const std::string &fileName);
111  bool WriteTextModel(std::ostream &stream);
112 
114  bool ReadBinaryModel(const std::string &fileName);
116  bool ReadBinaryModel(std::istream &stream);
117 
119  bool WriteBinaryModel(const std::string &fileName);
121  bool WriteBinaryModel(std::ostream &stream);
122 
125  bool ReadModel(const std::string &fileName);
128  bool ReadModel(std::istream &stream);
131  bool WriteModel(const std::string &fileName);
134  bool WriteModel(std::ostream &stream);
135 
137  int GetTriangleCount();
138 
140  const std::vector<ModelTriangle>& GetTriangles();
141 
143  void SetPrintDebugInfo(bool printDebugInfo);
144 
145 protected:
147  LODLevel MinMaxToLodLevel(float min, float max);
149  void LODLevelToMinMax(LODLevel lodLevel, float& min, float& max);
151 
152 protected:
154  std::vector<ModelTriangle> m_triangles;
155  bool m_printDebugInfo;
156 };
157 
158 }; // namespace Gfx
159 
int GetTriangleCount()
Returns the number of triangles in model.
Definition: modelfile.cpp:1238
int state
Rendering state to be set.
Definition: modelfile.h:80
void SetPrintDebugInfo(bool printDebugInfo)
Controls printing of debug information.
Definition: modelfile.cpp:1243
Material struct.
std::vector< ModelTriangle > m_triangles
Model triangles.
Definition: modelfile.h:154
bool variableTex2
If true, 2nd texture will be taken from current engine setting.
Definition: modelfile.h:76
Vertex with secondary texture coordinates.
Definition: vertex.h:112
Material material
Material.
Definition: modelfile.h:70
const std::vector< ModelTriangle > & GetTriangles()
Returns the triangle vector.
Definition: modelfile.cpp:1233
triangle is visible at farthest distance (lowest quality)
Definition: modelfile.h:52
triangle is visible at closest distance (highest quality)
Definition: modelfile.h:54
LODLevel
Level-of-detail.
Definition: modelfile.h:49
bool ReadBinaryModel(const std::string &fileName)
Reads a model in new binary format from file.
Definition: modelfile.cpp:1047
Material of a surface.
Definition: material.h:44
triangle is always visible, no matter at what distance
Definition: modelfile.h:51
VertexTex2 p3
3rd vertex
Definition: modelfile.h:68
bool WriteBinaryModel(const std::string &fileName)
Writes the model in binary format to a file.
Definition: modelfile.cpp:1162
bool WriteModel(const std::string &fileName)
Definition: modelfile.cpp:660
Vertex structs.
VertexTex2 p2
2nd vertex
Definition: modelfile.h:66
bool WriteTextModel(const std::string &fileName)
Writes the model in text format to a file.
Definition: modelfile.cpp:965
triangle is visible at medium distance (medium quality)
Definition: modelfile.h:53
Namespace for (new) graphics code.
Definition: app.h:49
Vector struct and related functions.
bool ReadModel(const std::string &fileName)
Definition: modelfile.cpp:437
Triangle of a 3D model.
Definition: modelfile.h:61
LODLevel lodLevel
LOD level.
Definition: modelfile.h:78
LODLevel MinMaxToLodLevel(float min, float max)
Definition: modelfile.cpp:740
std::string tex2Name
Name of 2nd texture.
Definition: modelfile.h:74
std::string tex1Name
Name of 1st texture.
Definition: modelfile.h:72
bool ReadTextModel(const std::string &fileName)
Reads a model in text format from file.
Definition: modelfile.cpp:840
VertexTex2 p1
1st vertex
Definition: modelfile.h:64
Model file reader/writer.
Definition: modelfile.h:97