Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
modelfile.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "graphics/core/vertex.h"
27 #include "graphics/core/material.h"
28 
29 #include "math/vector.h"
30 
31 #include <string>
32 #include <vector>
33 #include <iostream>
34 
35 
36 
37 // Graphics module namespace
38 namespace Gfx {
39 
40 
48 {
49  LOD_Constant = -1,
50  LOD_Low = 1,
51  LOD_Medium = 2,
52  LOD_High = 4
53 };
54 
60 {
70  std::string tex1Name;
72  std::string tex2Name;
78  int state;
79 
81  {
82  variableTex2 = true;
84  state = 0;
85  }
86 };
87 
88 
96 {
97 public:
98  CModelFile();
99  ~CModelFile();
100 
102  bool ReadTextModel(const std::string &fileName);
104  bool ReadTextModel(std::istream &stream);
105 
107  bool WriteTextModel(const std::string &fileName);
109  bool WriteTextModel(std::ostream &stream);
110 
112  bool ReadBinaryModel(const std::string &fileName);
114  bool ReadBinaryModel(std::istream &stream);
115 
117  bool WriteBinaryModel(const std::string &fileName);
119  bool WriteBinaryModel(std::ostream &stream);
120 
123  bool ReadModel(const std::string &fileName);
126  bool ReadModel(std::istream &stream);
129  bool WriteModel(const std::string &fileName);
132  bool WriteModel(std::ostream &stream);
133 
135  int GetTriangleCount();
136 
138  const std::vector<ModelTriangle>& GetTriangles();
139 
141  void SetPrintDebugInfo(bool printDebugInfo);
142 
143 protected:
145  LODLevel MinMaxToLodLevel(float min, float max);
147  void LODLevelToMinMax(LODLevel lodLevel, float& min, float& max);
149 
150 protected:
152  std::vector<ModelTriangle> m_triangles;
153  bool m_printDebugInfo;
154 };
155 
156 }; // namespace Gfx
157 
int GetTriangleCount()
Returns the number of triangles in model.
Definition: modelfile.cpp:1202
int state
Rendering state to be set.
Definition: modelfile.h:78
void SetPrintDebugInfo(bool printDebugInfo)
Controls printing of debug information.
Definition: modelfile.cpp:1207
Material struct.
std::vector< ModelTriangle > m_triangles
Model triangles.
Definition: modelfile.h:152
bool variableTex2
If true, 2nd texture will be taken from current engine setting.
Definition: modelfile.h:74
Vertex with secondary texture coordinates.
Definition: vertex.h:107
Material material
Material.
Definition: modelfile.h:68
const std::vector< ModelTriangle > & GetTriangles()
Returns the triangle vector.
Definition: modelfile.cpp:1197
triangle is visible at farthest distance (lowest quality)
Definition: modelfile.h:50
triangle is visible at closest distance (highest quality)
Definition: modelfile.h:52
LODLevel
Level-of-detail.
Definition: modelfile.h:47
bool ReadBinaryModel(const std::string &fileName)
Reads a model in new binary format from file.
Definition: modelfile.cpp:1021
Material of a surface.
Definition: material.h:41
triangle is always visible, no matter at what distance
Definition: modelfile.h:49
VertexTex2 p3
3rd vertex
Definition: modelfile.h:66
bool WriteBinaryModel(const std::string &fileName)
Writes the model in binary format to a file.
Definition: modelfile.cpp:1126
bool WriteModel(const std::string &fileName)
Definition: modelfile.cpp:644
Vertex structs.
VertexTex2 p2
2nd vertex
Definition: modelfile.h:64
bool WriteTextModel(const std::string &fileName)
Writes the model in text format to a file.
Definition: modelfile.cpp:939
triangle is visible at medium distance (medium quality)
Definition: modelfile.h:51
Vector struct and related functions.
bool ReadModel(const std::string &fileName)
Definition: modelfile.cpp:431
Triangle of a 3D model.
Definition: modelfile.h:59
LODLevel lodLevel
LOD level.
Definition: modelfile.h:76
LODLevel MinMaxToLodLevel(float min, float max)
Definition: modelfile.cpp:724
std::string tex2Name
Name of 2nd texture.
Definition: modelfile.h:72
std::string tex1Name
Name of 1st texture.
Definition: modelfile.h:70
bool ReadTextModel(const std::string &fileName)
Reads a model in text format from file.
Definition: modelfile.cpp:824
VertexTex2 p1
1st vertex
Definition: modelfile.h:62
Model file reader/writer.
Definition: modelfile.h:95