1 | #include "OgreMaxConfig.h" |
---|
2 | #include <fstream> |
---|
3 | |
---|
4 | namespace OgreMax { |
---|
5 | |
---|
6 | Config::Config() { |
---|
7 | // set defaults |
---|
8 | m_exportSelectedObjects = false; // default to exporting everything in the scene |
---|
9 | m_exportMultipleFiles = true; // default is to export a file per mesh object in the scene |
---|
10 | m_useSingleSkeleton = true; // default for multiple meshes is to reference a single .skeleton file where applicable |
---|
11 | m_rebuildNormals = false; // rebuild the normals before exporting mesh data |
---|
12 | |
---|
13 | m_exportMaterial = true; // default is to export material scripts |
---|
14 | m_defaultMaterialName = "DefaultMaterial"; |
---|
15 | m_2DTexCoord = UV; // default is UV interpretation of 2D tex coords |
---|
16 | |
---|
17 | m_invertNormals = false; // flip normals; will also reorder triangle vertex indices |
---|
18 | m_flipYZ = false; // swap X and Z axes, so that Y becomes the One True Up Vector |
---|
19 | m_exportVertexColors = false; // useful for vertex painting |
---|
20 | m_scale = 1.0f; // export at normal size (scale) -- all vertices get multiplied by this |
---|
21 | |
---|
22 | m_exportSkeleton = false; // initially we don't assume any skeletal data |
---|
23 | |
---|
24 | m_fps = 25.0; // used for controller types (such as Biped) that do not support keyframes directly -- this is the sampling rate |
---|
25 | |
---|
26 | m_exportBinaryMesh = false; |
---|
27 | m_exportXMLMesh = true; |
---|
28 | |
---|
29 | m_generateTangents = false; |
---|
30 | m_edgeLists = true; |
---|
31 | m_generateLod = false; |
---|
32 | m_lodDistance = 0.0f; |
---|
33 | m_numLodLevels = 0; |
---|
34 | m_lodPercent = -1.0f; |
---|
35 | m_lodVertexCount = -1; |
---|
36 | m_endian = NATIVE; // let Ogre figure it out |
---|
37 | m_colourFormat = DIRECT3D; // we can default to this since Max only runs on Windows |
---|
38 | m_optimizeBinaryLayout = true; // why wouldn't we? ;) |
---|
39 | |
---|
40 | // version 2 |
---|
41 | m_mergeMeshes = false; |
---|
42 | } |
---|
43 | |
---|
44 | Config::Config(const Config& config) |
---|
45 | { |
---|
46 | *this = config; |
---|
47 | } |
---|
48 | |
---|
49 | Config& Config::operator=(const Config& rhs) |
---|
50 | { |
---|
51 | m_generateTangents = rhs.m_generateTangents; |
---|
52 | m_edgeLists = rhs.m_edgeLists; |
---|
53 | m_generateLod = rhs.m_generateLod; |
---|
54 | m_lodDistance = rhs.m_lodDistance; |
---|
55 | m_numLodLevels = rhs.m_numLodLevels; |
---|
56 | m_lodPercent = rhs.m_lodPercent; |
---|
57 | m_lodVertexCount = rhs.m_lodVertexCount; |
---|
58 | |
---|
59 | return *this; |
---|
60 | } |
---|
61 | |
---|
62 | Config::~Config() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | void Config::save() { |
---|
67 | // write "this" to file named <basename>.cfg; note that we do not need to do the same massaging of |
---|
68 | // file sizes that we do for reads since this will always output the latest version |
---|
69 | std::ofstream of; |
---|
70 | std::string fname = m_exportBasename + ".cfg"; |
---|
71 | |
---|
72 | // copy strings to buffers |
---|
73 | strcpy(m_bufDefaultMaterialName, m_defaultMaterialName.c_str()); |
---|
74 | strcpy(m_bufExportPath, m_exportPath.c_str()); |
---|
75 | strcpy(m_bufExportBasename, m_exportBasename.c_str()); |
---|
76 | strcpy(m_bufExportFilename, m_exportFilename.c_str()); |
---|
77 | strcpy(m_bufMaterialFilename, m_materialFilename.c_str()); |
---|
78 | strcpy(m_bufSkeletonFilename, m_skeletonFilename.c_str()); |
---|
79 | |
---|
80 | // set version number for sure |
---|
81 | m_version = CURRENTVERSION; |
---|
82 | |
---|
83 | of.open(fname.c_str(), std::ios::binary | std::ios::out); |
---|
84 | if (of.is_open()) { |
---|
85 | of.write((char *)this, offsetof(Config, m_defaultMaterialName)); |
---|
86 | of.close(); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void Config::load() { |
---|
91 | // read "this" from file named <basename>.cfg |
---|
92 | std::ifstream f; |
---|
93 | std::string fname = m_exportBasename + ".cfg"; |
---|
94 | |
---|
95 | f.open(fname.c_str(), std::ios::binary | std::ios::in); |
---|
96 | if (f.is_open()) { |
---|
97 | |
---|
98 | // we need to check the version to see how much to read |
---|
99 | f.read((char*)&m_version, sizeof(unsigned int)); |
---|
100 | |
---|
101 | // default size for latest version |
---|
102 | size_t sz = offsetof(Config, m_defaultMaterialName); |
---|
103 | |
---|
104 | if (m_version < CURRENTVERSION) { |
---|
105 | switch(m_version) { |
---|
106 | case 1: |
---|
107 | sz = offsetof(Config, m_bufSkeletonFilename) + sizeof(m_bufSkeletonFilename); |
---|
108 | break; |
---|
109 | case 2: |
---|
110 | sz = offsetof(Config, m_mergeMeshes) + sizeof(m_mergeMeshes); |
---|
111 | break; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | // read the calculated size, minus the unsigned int we already read |
---|
116 | f.read(((char *)this + sizeof(unsigned int)), sz - sizeof(unsigned int)); |
---|
117 | f.close(); |
---|
118 | |
---|
119 | // make strings from buffers |
---|
120 | m_defaultMaterialName = m_bufDefaultMaterialName; |
---|
121 | m_exportPath = m_bufExportPath; |
---|
122 | m_exportBasename = m_bufExportBasename; |
---|
123 | m_exportFilename = m_bufExportFilename; |
---|
124 | m_materialFilename = m_bufMaterialFilename; |
---|
125 | m_skeletonFilename = m_bufSkeletonFilename; |
---|
126 | } |
---|
127 | |
---|
128 | // if we could not open the config file for any reason, skip it -- more than likely a new export |
---|
129 | } |
---|
130 | |
---|
131 | void Config::setExportPath(const std::string& path) { |
---|
132 | m_exportPath = path; |
---|
133 | } |
---|
134 | |
---|
135 | void Config::setMaterialFilename(const std::string& name) { |
---|
136 | m_materialFilename = name; |
---|
137 | } |
---|
138 | |
---|
139 | void Config::setExportFilename(const std::string& name) { |
---|
140 | // extract the filename and the export path |
---|
141 | std::string filename = name; |
---|
142 | size_t offset = filename.find_last_of('\\'); |
---|
143 | m_exportPath = filename.substr(0, offset); |
---|
144 | m_exportFilename = filename.substr(offset+1); |
---|
145 | |
---|
146 | // strip extension, if any |
---|
147 | offset = m_exportFilename.find_last_of('.'); |
---|
148 | if (m_exportFilename.substr(offset) == ".xml") |
---|
149 | offset = m_exportFilename.substr(0, offset).find_last_of('.'); |
---|
150 | |
---|
151 | // set base filename |
---|
152 | m_exportBasename = m_exportFilename.substr(0, offset); |
---|
153 | } |
---|
154 | |
---|
155 | void Config::setSkeletonFilename(const std::string& name) { |
---|
156 | m_skeletonFilename = name; |
---|
157 | } |
---|
158 | |
---|
159 | void Config::setDefaultMaterialName(const std::string& name) { |
---|
160 | m_defaultMaterialName = name; |
---|
161 | } |
---|
162 | |
---|
163 | void Config::setTexCoord2D(Tex2D texCoord) { |
---|
164 | m_2DTexCoord = texCoord; |
---|
165 | } |
---|
166 | |
---|
167 | void Config::setScale(float scale) { |
---|
168 | m_scale = scale; |
---|
169 | } |
---|
170 | |
---|
171 | void Config::setFPS(float fps) { |
---|
172 | m_fps = fps; |
---|
173 | } |
---|
174 | |
---|
175 | void Config::setInvertYZ(bool invert) |
---|
176 | { |
---|
177 | m_flipYZ = invert; |
---|
178 | } |
---|
179 | |
---|
180 | void Config::setInvertNormals(bool invert) |
---|
181 | { |
---|
182 | m_invertNormals = invert; |
---|
183 | } |
---|
184 | |
---|
185 | void Config::setExportBinaryMesh(bool export) |
---|
186 | { |
---|
187 | m_exportBinaryMesh = export; |
---|
188 | } |
---|
189 | |
---|
190 | void Config::setExportXMLMesh(bool export) |
---|
191 | { |
---|
192 | m_exportXMLMesh = export; |
---|
193 | } |
---|
194 | |
---|
195 | void Config::setRebuildNormals(bool rebuild) |
---|
196 | { |
---|
197 | m_rebuildNormals = rebuild; |
---|
198 | } |
---|
199 | |
---|
200 | void Config::setUseSingleSkeleton(bool useSingle) |
---|
201 | { |
---|
202 | m_useSingleSkeleton = useSingle; |
---|
203 | } |
---|
204 | |
---|
205 | void Config::setExportSkeleton(bool exportSkeleton) |
---|
206 | { |
---|
207 | m_exportSkeleton = exportSkeleton; |
---|
208 | } |
---|
209 | |
---|
210 | void Config::setExportMultipleFiles(bool exportMultiple) |
---|
211 | { |
---|
212 | m_exportMultipleFiles = exportMultiple; |
---|
213 | } |
---|
214 | |
---|
215 | void Config::setExportVertexColours(bool exportVC) |
---|
216 | { |
---|
217 | m_exportVertexColors = exportVC; |
---|
218 | } |
---|
219 | |
---|
220 | void Config::setExportMaterial(bool exportMaterial) |
---|
221 | { |
---|
222 | m_exportMaterial = exportMaterial; |
---|
223 | } |
---|
224 | |
---|
225 | void Config::setBuildEdgeLists(bool buildEdgeLists) |
---|
226 | { |
---|
227 | m_edgeLists = buildEdgeLists; |
---|
228 | } |
---|
229 | |
---|
230 | void Config::setGenerateLod(bool generateLod) |
---|
231 | { |
---|
232 | m_generateLod = generateLod; |
---|
233 | } |
---|
234 | |
---|
235 | void Config::setGenerateTangents(bool generateTangents) |
---|
236 | { |
---|
237 | m_generateTangents = generateTangents; |
---|
238 | } |
---|
239 | |
---|
240 | void Config::setOptmizeBinaryMesh(bool optimize) |
---|
241 | { |
---|
242 | m_optimizeBinaryLayout = optimize; |
---|
243 | } |
---|
244 | |
---|
245 | void Config::setVertexColourFormat(VertexColourFormat format) |
---|
246 | { |
---|
247 | m_colourFormat = format; |
---|
248 | } |
---|
249 | |
---|
250 | void Config::setEndian(Endian endian) |
---|
251 | { |
---|
252 | m_endian = endian; |
---|
253 | } |
---|
254 | |
---|
255 | void Config::setNumLodLevels(unsigned int levels) |
---|
256 | { |
---|
257 | m_numLodLevels = levels; |
---|
258 | } |
---|
259 | |
---|
260 | void Config::setLodDistance(float dist) |
---|
261 | { |
---|
262 | m_lodDistance = dist; |
---|
263 | } |
---|
264 | |
---|
265 | void Config::setLodPercentReduction(float percent) |
---|
266 | { |
---|
267 | m_lodPercent = percent; |
---|
268 | } |
---|
269 | |
---|
270 | void Config::setLodVertexReduction(int count) |
---|
271 | { |
---|
272 | m_lodVertexCount = count; |
---|
273 | } |
---|
274 | |
---|
275 | void Config::setExportSelected(bool selected) |
---|
276 | { |
---|
277 | m_exportSelectedObjects = selected; |
---|
278 | } |
---|
279 | |
---|
280 | // |
---|
281 | // version 2 |
---|
282 | // |
---|
283 | void Config::setMergeMeshes(bool merge) |
---|
284 | { |
---|
285 | m_mergeMeshes = merge; |
---|
286 | } |
---|
287 | |
---|
288 | } |
---|