diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp | 1744 |
1 files changed, 872 insertions, 872 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp index 048fb01..353ab5e 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CCSMLoader.cpp | |||
@@ -1,872 +1,872 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | // | 4 | // |
5 | // This file was written by Saurav Mohapatra and modified by Nikolaus Gebhardt. | 5 | // This file was written by Saurav Mohapatra and modified by Nikolaus Gebhardt. |
6 | // See CCSMLoader.h for details. | 6 | // See CCSMLoader.h for details. |
7 | 7 | ||
8 | #include "IrrCompileConfig.h" | 8 | #include "IrrCompileConfig.h" |
9 | #ifdef _IRR_COMPILE_WITH_CSM_LOADER_ | 9 | #ifdef _IRR_COMPILE_WITH_CSM_LOADER_ |
10 | 10 | ||
11 | #include "CCSMLoader.h" | 11 | #include "CCSMLoader.h" |
12 | #include "os.h" | 12 | #include "os.h" |
13 | #include "IFileSystem.h" | 13 | #include "IFileSystem.h" |
14 | #include "IReadFile.h" | 14 | #include "IReadFile.h" |
15 | #include "ISceneManager.h" | 15 | #include "ISceneManager.h" |
16 | #include "IAttributes.h" | 16 | #include "IAttributes.h" |
17 | #include "SMesh.h" | 17 | #include "SMesh.h" |
18 | #include "IVideoDriver.h" | 18 | #include "IVideoDriver.h" |
19 | #include "SAnimatedMesh.h" | 19 | #include "SAnimatedMesh.h" |
20 | #include "SMeshBufferLightMap.h" | 20 | #include "SMeshBufferLightMap.h" |
21 | 21 | ||
22 | #ifdef _DEBUG | 22 | #ifdef _DEBUG |
23 | #define _IRR_DEBUG_CSM_LOADER_ | 23 | #define _IRR_DEBUG_CSM_LOADER_ |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | namespace irr | 26 | namespace irr |
27 | { | 27 | { |
28 | namespace scene | 28 | namespace scene |
29 | { | 29 | { |
30 | // | 30 | // |
31 | // the CSM data types | 31 | // the CSM data types |
32 | // | 32 | // |
33 | struct color_rgb_t | 33 | struct color_rgb_t |
34 | { | 34 | { |
35 | s32 red; | 35 | s32 red; |
36 | s32 green; | 36 | s32 green; |
37 | s32 blue; | 37 | s32 blue; |
38 | 38 | ||
39 | color_rgb_t() : red(0), green(0), blue(0) {} | 39 | color_rgb_t() : red(0), green(0), blue(0) {} |
40 | void clear() { red=0; green=0; blue=0; } | 40 | void clear() { red=0; green=0; blue=0; } |
41 | video::SColor toSColor() const { return video::SColor(255, red, green, blue); } | 41 | video::SColor toSColor() const { return video::SColor(255, red, green, blue); } |
42 | }; | 42 | }; |
43 | 43 | ||
44 | 44 | ||
45 | // | 45 | // |
46 | // A Binary File Reader | 46 | // A Binary File Reader |
47 | // | 47 | // |
48 | struct BinaryFileReader | 48 | struct BinaryFileReader |
49 | { | 49 | { |
50 | BinaryFileReader(io::IReadFile* pFile) : file(pFile) { } | 50 | BinaryFileReader(io::IReadFile* pFile) : file(pFile) { } |
51 | 51 | ||
52 | s32 readBuffer(void* buffer, s32 len) | 52 | s32 readBuffer(void* buffer, s32 len) |
53 | { | 53 | { |
54 | return file->read(buffer,len); | 54 | return file->read(buffer,len); |
55 | } | 55 | } |
56 | 56 | ||
57 | s32 readLong(); | 57 | s32 readLong(); |
58 | f32 readFloat(); | 58 | f32 readFloat(); |
59 | 59 | ||
60 | void readString(core::stringc &str); | 60 | void readString(core::stringc &str); |
61 | void readVec3f(core::vector3df* v); | 61 | void readVec3f(core::vector3df* v); |
62 | void readVec2f(core::vector2df* v); | 62 | void readVec2f(core::vector2df* v); |
63 | void readColorRGB(color_rgb_t* color); | 63 | void readColorRGB(color_rgb_t* color); |
64 | 64 | ||
65 | io::IReadFile *file; | 65 | io::IReadFile *file; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | // | 68 | // |
69 | // The file header | 69 | // The file header |
70 | // | 70 | // |
71 | class Header | 71 | class Header |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | 74 | ||
75 | enum E_CSM_VERSION | 75 | enum E_CSM_VERSION |
76 | { | 76 | { |
77 | VERSION_4 = 4, | 77 | VERSION_4 = 4, |
78 | VERSION_4_1 = 5 | 78 | VERSION_4_1 = 5 |
79 | }; | 79 | }; |
80 | 80 | ||
81 | Header(){ clear(); } | 81 | Header(){ clear(); } |
82 | 82 | ||
83 | s32 getVersion() const { return version; } | 83 | s32 getVersion() const { return version; } |
84 | void clear(){ version = 0; } | 84 | void clear(){ version = 0; } |
85 | void load(BinaryFileReader* pReader) | 85 | void load(BinaryFileReader* pReader) |
86 | { | 86 | { |
87 | version = pReader->readLong(); | 87 | version = pReader->readLong(); |
88 | } | 88 | } |
89 | 89 | ||
90 | private: | 90 | private: |
91 | 91 | ||
92 | s32 version; | 92 | s32 version; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | 95 | ||
96 | // | 96 | // |
97 | // The groups | 97 | // The groups |
98 | // | 98 | // |
99 | class Group | 99 | class Group |
100 | { | 100 | { |
101 | public: | 101 | public: |
102 | 102 | ||
103 | Group(){ clear(); } | 103 | Group(){ clear(); } |
104 | ~Group(){ clear(); } | 104 | ~Group(){ clear(); } |
105 | 105 | ||
106 | void clear(); | 106 | void clear(); |
107 | void load(BinaryFileReader* pReader); | 107 | void load(BinaryFileReader* pReader); |
108 | 108 | ||
109 | s32 getFlags() const { return flags; } | 109 | s32 getFlags() const { return flags; } |
110 | s32 getParentGroupID() const { return parentGroup; } | 110 | s32 getParentGroupID() const { return parentGroup; } |
111 | const core::stringc& getProperties() const { return props; } | 111 | const core::stringc& getProperties() const { return props; } |
112 | video::SColor getColor() const { return color.toSColor(); } | 112 | video::SColor getColor() const { return color.toSColor(); } |
113 | 113 | ||
114 | private: | 114 | private: |
115 | 115 | ||
116 | s32 flags; | 116 | s32 flags; |
117 | s32 parentGroup; | 117 | s32 parentGroup; |
118 | core::stringc props; | 118 | core::stringc props; |
119 | color_rgb_t color; | 119 | color_rgb_t color; |
120 | }; | 120 | }; |
121 | 121 | ||
122 | 122 | ||
123 | // | 123 | // |
124 | // The visgroups | 124 | // The visgroups |
125 | // | 125 | // |
126 | class VisGroup | 126 | class VisGroup |
127 | { | 127 | { |
128 | public: | 128 | public: |
129 | 129 | ||
130 | VisGroup(){ clear(); } | 130 | VisGroup(){ clear(); } |
131 | ~VisGroup(){ clear(); } | 131 | ~VisGroup(){ clear(); } |
132 | void clear(); | 132 | void clear(); |
133 | void load(BinaryFileReader* pReader); | 133 | void load(BinaryFileReader* pReader); |
134 | 134 | ||
135 | s32 getFlags() const{ return flags; } | 135 | s32 getFlags() const{ return flags; } |
136 | const core::stringc& getName() const{ return name; } | 136 | const core::stringc& getName() const{ return name; } |
137 | video::SColor getColor() const{ return color.toSColor(); } | 137 | video::SColor getColor() const{ return color.toSColor(); } |
138 | 138 | ||
139 | private: | 139 | private: |
140 | 140 | ||
141 | core::stringc name; | 141 | core::stringc name; |
142 | s32 flags; | 142 | s32 flags; |
143 | color_rgb_t color; | 143 | color_rgb_t color; |
144 | }; | 144 | }; |
145 | 145 | ||
146 | 146 | ||
147 | // | 147 | // |
148 | // Lightmaps | 148 | // Lightmaps |
149 | // | 149 | // |
150 | class LightMap | 150 | class LightMap |
151 | { | 151 | { |
152 | public: | 152 | public: |
153 | 153 | ||
154 | LightMap() : pixelData(0){ clear(); } | 154 | LightMap() : pixelData(0){ clear(); } |
155 | ~LightMap(){ clear(); } | 155 | ~LightMap(){ clear(); } |
156 | void clear(); | 156 | void clear(); |
157 | void load(BinaryFileReader* pReader); | 157 | void load(BinaryFileReader* pReader); |
158 | s32 getWidth() const{ return width; } | 158 | s32 getWidth() const{ return width; } |
159 | s32 getHeight() const{ return height; } | 159 | s32 getHeight() const{ return height; } |
160 | s32* getPixelData() const{ return pixelData; } | 160 | s32* getPixelData() const{ return pixelData; } |
161 | 161 | ||
162 | private: | 162 | private: |
163 | 163 | ||
164 | s32 width; | 164 | s32 width; |
165 | s32 height; | 165 | s32 height; |
166 | s32* pixelData; | 166 | s32* pixelData; |
167 | }; | 167 | }; |
168 | 168 | ||
169 | struct Triangle | 169 | struct Triangle |
170 | { | 170 | { |
171 | s32 a,b,c; | 171 | s32 a,b,c; |
172 | }; | 172 | }; |
173 | 173 | ||
174 | 174 | ||
175 | struct Line | 175 | struct Line |
176 | { | 176 | { |
177 | s32 a,b; | 177 | s32 a,b; |
178 | }; | 178 | }; |
179 | 179 | ||
180 | 180 | ||
181 | class Vertex | 181 | class Vertex |
182 | { | 182 | { |
183 | public: | 183 | public: |
184 | 184 | ||
185 | Vertex(){ clear(); } | 185 | Vertex(){ clear(); } |
186 | ~Vertex(){ clear(); } | 186 | ~Vertex(){ clear(); } |
187 | void clear(); | 187 | void clear(); |
188 | void load(BinaryFileReader* pReader); | 188 | void load(BinaryFileReader* pReader); |
189 | 189 | ||
190 | const core::vector3df& getPosition() const { return position; } | 190 | const core::vector3df& getPosition() const { return position; } |
191 | const core::vector3df& getNormal() const { return normal; } | 191 | const core::vector3df& getNormal() const { return normal; } |
192 | video::SColor getColor() const { return color.toSColor(); } | 192 | video::SColor getColor() const { return color.toSColor(); } |
193 | const core::vector3df& getTextureCoordinates() const { return texCoords; } | 193 | const core::vector3df& getTextureCoordinates() const { return texCoords; } |
194 | const core::vector3df& getLightMapCoordinates() const { return lmapCoords; } | 194 | const core::vector3df& getLightMapCoordinates() const { return lmapCoords; } |
195 | 195 | ||
196 | private: | 196 | private: |
197 | 197 | ||
198 | core::vector3df position; | 198 | core::vector3df position; |
199 | core::vector3df normal; | 199 | core::vector3df normal; |
200 | color_rgb_t color; | 200 | color_rgb_t color; |
201 | core::vector3df texCoords; | 201 | core::vector3df texCoords; |
202 | core::vector3df lmapCoords; | 202 | core::vector3df lmapCoords; |
203 | }; | 203 | }; |
204 | 204 | ||
205 | 205 | ||
206 | class Surface | 206 | class Surface |
207 | { | 207 | { |
208 | public: | 208 | public: |
209 | 209 | ||
210 | Surface() { clear(); } | 210 | Surface() { clear(); } |
211 | ~Surface(){ clear(); } | 211 | ~Surface(){ clear(); } |
212 | 212 | ||
213 | void clear(); | 213 | void clear(); |
214 | void load(BinaryFileReader *pReader); | 214 | void load(BinaryFileReader *pReader); |
215 | 215 | ||
216 | s32 getFlags() const{ return flags; } | 216 | s32 getFlags() const{ return flags; } |
217 | const core::stringc& getTextureName() const{ return textureName; } | 217 | const core::stringc& getTextureName() const{ return textureName; } |
218 | s32 getLightMapId() const{ return lightMapId; } | 218 | s32 getLightMapId() const{ return lightMapId; } |
219 | const core::vector2df* getUVOffset() const{ return &uvOffset; } | 219 | const core::vector2df* getUVOffset() const{ return &uvOffset; } |
220 | const core::vector2df* getUVScale() const{ return &uvScale; } | 220 | const core::vector2df* getUVScale() const{ return &uvScale; } |
221 | f32 getUVRotation() const{ return uvRotation; } | 221 | f32 getUVRotation() const{ return uvRotation; } |
222 | 222 | ||
223 | u32 getVertexCount() const{ return vertices.size(); } | 223 | u32 getVertexCount() const{ return vertices.size(); } |
224 | const Vertex& getVertexAt(const s32 index) const{ return vertices[index]; } | 224 | const Vertex& getVertexAt(const s32 index) const{ return vertices[index]; } |
225 | 225 | ||
226 | u32 getTriangleCount() const{ return triangles.size(); } | 226 | u32 getTriangleCount() const{ return triangles.size(); } |
227 | const Triangle& getTriangleAt(const s32 index) const{ return triangles[index]; } | 227 | const Triangle& getTriangleAt(const s32 index) const{ return triangles[index]; } |
228 | 228 | ||
229 | private: | 229 | private: |
230 | 230 | ||
231 | s32 flags; | 231 | s32 flags; |
232 | core::stringc textureName; | 232 | core::stringc textureName; |
233 | s32 lightMapId; | 233 | s32 lightMapId; |
234 | core::vector2df uvOffset; | 234 | core::vector2df uvOffset; |
235 | core::vector2df uvScale; | 235 | core::vector2df uvScale; |
236 | f32 uvRotation; | 236 | f32 uvRotation; |
237 | core::array<Vertex> vertices; | 237 | core::array<Vertex> vertices; |
238 | core::array<Triangle> triangles; | 238 | core::array<Triangle> triangles; |
239 | core::array<Line> lines; | 239 | core::array<Line> lines; |
240 | }; | 240 | }; |
241 | 241 | ||
242 | class Mesh | 242 | class Mesh |
243 | { | 243 | { |
244 | public: | 244 | public: |
245 | 245 | ||
246 | Mesh(){ clear(); } | 246 | Mesh(){ clear(); } |
247 | ~Mesh(){ clear(); } | 247 | ~Mesh(){ clear(); } |
248 | 248 | ||
249 | void clear(); | 249 | void clear(); |
250 | void load(BinaryFileReader* pReader, bool bReadVisGroups); | 250 | void load(BinaryFileReader* pReader, bool bReadVisGroups); |
251 | 251 | ||
252 | s32 getFlags() const { return flags; } | 252 | s32 getFlags() const { return flags; } |
253 | s32 getGroupID() const { return groupId; } | 253 | s32 getGroupID() const { return groupId; } |
254 | const core::stringc& getProperties() const { return props; } | 254 | const core::stringc& getProperties() const { return props; } |
255 | video::SColor getColor() const { return color.toSColor(); } | 255 | video::SColor getColor() const { return color.toSColor(); } |
256 | const core::vector3df* getPosition() const { return &position; } | 256 | const core::vector3df* getPosition() const { return &position; } |
257 | s32 getVisgroupID() const { return visgroupId; } | 257 | s32 getVisgroupID() const { return visgroupId; } |
258 | s32 getSurfaceCount() const { return surfaces.size(); } | 258 | s32 getSurfaceCount() const { return surfaces.size(); } |
259 | const Surface* getSurfaceAt(const s32 index) const { return surfaces[index]; } | 259 | const Surface* getSurfaceAt(const s32 index) const { return surfaces[index]; } |
260 | 260 | ||
261 | private: | 261 | private: |
262 | 262 | ||
263 | s32 flags; | 263 | s32 flags; |
264 | s32 groupId; | 264 | s32 groupId; |
265 | core::stringc props; | 265 | core::stringc props; |
266 | color_rgb_t color; | 266 | color_rgb_t color; |
267 | core::vector3df position; | 267 | core::vector3df position; |
268 | s32 visgroupId; | 268 | s32 visgroupId; |
269 | 269 | ||
270 | core::array<Surface*> surfaces; | 270 | core::array<Surface*> surfaces; |
271 | }; | 271 | }; |
272 | 272 | ||
273 | class Entity | 273 | class Entity |
274 | { | 274 | { |
275 | public: | 275 | public: |
276 | 276 | ||
277 | Entity() { clear(); } | 277 | Entity() { clear(); } |
278 | ~Entity() { clear(); } | 278 | ~Entity() { clear(); } |
279 | 279 | ||
280 | void clear(); | 280 | void clear(); |
281 | void load(BinaryFileReader* pReader); | 281 | void load(BinaryFileReader* pReader); |
282 | s32 getVisgroupID() const { return visgroupId; } | 282 | s32 getVisgroupID() const { return visgroupId; } |
283 | s32 getGroupID() const { return groupId; } | 283 | s32 getGroupID() const { return groupId; } |
284 | const core::stringc& getProperties() const { return props; } | 284 | const core::stringc& getProperties() const { return props; } |
285 | const core::vector3df* getPosition() const { return &position; } | 285 | const core::vector3df* getPosition() const { return &position; } |
286 | 286 | ||
287 | private: | 287 | private: |
288 | 288 | ||
289 | s32 visgroupId; | 289 | s32 visgroupId; |
290 | s32 groupId; | 290 | s32 groupId; |
291 | core::stringc props; | 291 | core::stringc props; |
292 | core::vector3df position; | 292 | core::vector3df position; |
293 | }; | 293 | }; |
294 | 294 | ||
295 | 295 | ||
296 | class CameraData | 296 | class CameraData |
297 | { | 297 | { |
298 | public: | 298 | public: |
299 | 299 | ||
300 | CameraData(){ clear(); } | 300 | CameraData(){ clear(); } |
301 | ~CameraData(){ clear(); } | 301 | ~CameraData(){ clear(); } |
302 | 302 | ||
303 | void clear(); | 303 | void clear(); |
304 | void load(BinaryFileReader* pReader); | 304 | void load(BinaryFileReader* pReader); |
305 | 305 | ||
306 | const core::vector3df* getPosition(){ return &position; } | 306 | const core::vector3df* getPosition(){ return &position; } |
307 | f32 getPitch(){ return pitch; } | 307 | f32 getPitch(){ return pitch; } |
308 | f32 getYaw(){ return yaw; } | 308 | f32 getYaw(){ return yaw; } |
309 | 309 | ||
310 | private: | 310 | private: |
311 | 311 | ||
312 | core::vector3df position; | 312 | core::vector3df position; |
313 | f32 pitch; | 313 | f32 pitch; |
314 | f32 yaw; | 314 | f32 yaw; |
315 | }; | 315 | }; |
316 | 316 | ||
317 | // | 317 | // |
318 | // A CSM File | 318 | // A CSM File |
319 | // | 319 | // |
320 | class CSMFile | 320 | class CSMFile |
321 | { | 321 | { |
322 | public: | 322 | public: |
323 | 323 | ||
324 | CSMFile(){ clear(); } | 324 | CSMFile(){ clear(); } |
325 | ~CSMFile(){ clear(); } | 325 | ~CSMFile(){ clear(); } |
326 | void clear(); | 326 | void clear(); |
327 | void load(BinaryFileReader* pReader); | 327 | void load(BinaryFileReader* pReader); |
328 | 328 | ||
329 | const Header* getHeader() const{ return &header; } | 329 | const Header* getHeader() const{ return &header; } |
330 | 330 | ||
331 | u32 getGroupCount() const{ return groups.size(); } | 331 | u32 getGroupCount() const{ return groups.size(); } |
332 | const Group* getGroupAt(const s32 index) const{ return groups[index]; } | 332 | const Group* getGroupAt(const s32 index) const{ return groups[index]; } |
333 | 333 | ||
334 | u32 getVisGroupCount() const{ return visgroups.size(); } | 334 | u32 getVisGroupCount() const{ return visgroups.size(); } |
335 | const VisGroup* getVisGroupAt(const s32 index) const{ return visgroups[index]; } | 335 | const VisGroup* getVisGroupAt(const s32 index) const{ return visgroups[index]; } |
336 | 336 | ||
337 | u32 getLightMapCount() const{ return lightmaps.size(); } | 337 | u32 getLightMapCount() const{ return lightmaps.size(); } |
338 | const LightMap* getLightMapAt(const s32 index) const { return lightmaps[index]; } | 338 | const LightMap* getLightMapAt(const s32 index) const { return lightmaps[index]; } |
339 | 339 | ||
340 | u32 getMeshCount() const{ return meshes.size(); } | 340 | u32 getMeshCount() const{ return meshes.size(); } |
341 | const Mesh* getMeshAt(const s32 index) const{ return meshes[index]; } | 341 | const Mesh* getMeshAt(const s32 index) const{ return meshes[index]; } |
342 | 342 | ||
343 | u32 getEntityCount() const{ return entities.size(); } | 343 | u32 getEntityCount() const{ return entities.size(); } |
344 | const Entity* getEntityAt(const s32 index) const{ return entities[index]; } | 344 | const Entity* getEntityAt(const s32 index) const{ return entities[index]; } |
345 | 345 | ||
346 | const CameraData* getCameraData() const{ return &cameraData; } | 346 | const CameraData* getCameraData() const{ return &cameraData; } |
347 | 347 | ||
348 | private: | 348 | private: |
349 | 349 | ||
350 | Header header; | 350 | Header header; |
351 | core::array<Group*> groups; | 351 | core::array<Group*> groups; |
352 | core::array<VisGroup*> visgroups; | 352 | core::array<VisGroup*> visgroups; |
353 | core::array<LightMap*> lightmaps; | 353 | core::array<LightMap*> lightmaps; |
354 | core::array<Mesh*> meshes; | 354 | core::array<Mesh*> meshes; |
355 | core::array<Entity*> entities; | 355 | core::array<Entity*> entities; |
356 | CameraData cameraData; | 356 | CameraData cameraData; |
357 | }; | 357 | }; |
358 | 358 | ||
359 | CCSMLoader::CCSMLoader(scene::ISceneManager* manager, io::IFileSystem* fs) | 359 | CCSMLoader::CCSMLoader(scene::ISceneManager* manager, io::IFileSystem* fs) |
360 | : FileSystem(fs), SceneManager(manager) | 360 | : FileSystem(fs), SceneManager(manager) |
361 | { | 361 | { |
362 | 362 | ||
363 | #ifdef _DEBUG | 363 | #ifdef _DEBUG |
364 | setDebugName("CCSMLoader"); | 364 | setDebugName("CCSMLoader"); |
365 | #endif | 365 | #endif |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | //! returns true if the file maybe is able to be loaded by this class | 369 | //! returns true if the file maybe is able to be loaded by this class |
370 | //! based on the file extension (e.g. ".bsp") | 370 | //! based on the file extension (e.g. ".bsp") |
371 | bool CCSMLoader::isALoadableFileExtension(const io::path& filename) const | 371 | bool CCSMLoader::isALoadableFileExtension(const io::path& filename) const |
372 | { | 372 | { |
373 | return core::hasFileExtension ( filename, "csm" ); | 373 | return core::hasFileExtension ( filename, "csm" ); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | //! creates/loads an animated mesh from the file. | 377 | //! creates/loads an animated mesh from the file. |
378 | IAnimatedMesh* CCSMLoader::createMesh(io::IReadFile* file) | 378 | IAnimatedMesh* CCSMLoader::createMesh(io::IReadFile* file) |
379 | { | 379 | { |
380 | scene::IMesh* m = createCSMMesh(file); | 380 | scene::IMesh* m = createCSMMesh(file); |
381 | 381 | ||
382 | if (!m) | 382 | if (!m) |
383 | return 0; | 383 | return 0; |
384 | 384 | ||
385 | SAnimatedMesh* am = new SAnimatedMesh(); | 385 | SAnimatedMesh* am = new SAnimatedMesh(); |
386 | am->Type = EAMT_CSM; | 386 | am->Type = EAMT_CSM; |
387 | am->addMesh(m); | 387 | am->addMesh(m); |
388 | m->drop(); | 388 | m->drop(); |
389 | 389 | ||
390 | am->recalculateBoundingBox(); | 390 | am->recalculateBoundingBox(); |
391 | return am; | 391 | return am; |
392 | } | 392 | } |
393 | 393 | ||
394 | scene::IMesh* CCSMLoader::createCSMMesh(io::IReadFile* file) | 394 | scene::IMesh* CCSMLoader::createCSMMesh(io::IReadFile* file) |
395 | { | 395 | { |
396 | if (!file) | 396 | if (!file) |
397 | return 0; | 397 | return 0; |
398 | 398 | ||
399 | BinaryFileReader reader(file); | 399 | BinaryFileReader reader(file); |
400 | CSMFile csmFile; | 400 | CSMFile csmFile; |
401 | csmFile.load(&reader); | 401 | csmFile.load(&reader); |
402 | 402 | ||
403 | return createIrrlichtMesh(&csmFile, | 403 | return createIrrlichtMesh(&csmFile, |
404 | SceneManager->getParameters()->getAttributeAsString(CSM_TEXTURE_PATH), | 404 | SceneManager->getParameters()->getAttributeAsString(CSM_TEXTURE_PATH), |
405 | file->getFileName()); | 405 | file->getFileName()); |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 | ||
409 | scene::IMesh* CCSMLoader::createIrrlichtMesh(const CSMFile* csmFile, | 409 | scene::IMesh* CCSMLoader::createIrrlichtMesh(const CSMFile* csmFile, |
410 | const core::stringc& textureRoot, const io::path& lmprefix) | 410 | const core::stringc& textureRoot, const io::path& lmprefix) |
411 | { | 411 | { |
412 | scene::SMesh *pMesh = new scene::SMesh(); | 412 | scene::SMesh *pMesh = new scene::SMesh(); |
413 | video::IVideoDriver* driver = SceneManager->getVideoDriver(); | 413 | video::IVideoDriver* driver = SceneManager->getVideoDriver(); |
414 | 414 | ||
415 | for(u32 l = 0; l<csmFile->getLightMapCount(); l++) | 415 | for(u32 l = 0; l<csmFile->getLightMapCount(); l++) |
416 | { | 416 | { |
417 | const LightMap* lmap = csmFile->getLightMapAt(l); | 417 | const LightMap* lmap = csmFile->getLightMapAt(l); |
418 | 418 | ||
419 | io::path lmapName = lmprefix; | 419 | io::path lmapName = lmprefix; |
420 | lmapName += "LMAP_"; | 420 | lmapName += "LMAP_"; |
421 | lmapName += io::path(l+1); | 421 | lmapName += io::path(l+1); |
422 | os::Printer::log("CCSMLoader loading light map", lmapName.c_str()); | 422 | os::Printer::log("CCSMLoader loading light map", lmapName.c_str()); |
423 | 423 | ||
424 | video::IImage* lmapImg = driver->createImageFromData( | 424 | video::IImage* lmapImg = driver->createImageFromData( |
425 | video::ECF_A8R8G8B8, | 425 | video::ECF_A8R8G8B8, |
426 | core::dimension2d<u32>(lmap->getWidth(),lmap->getHeight()), | 426 | core::dimension2d<u32>(lmap->getWidth(),lmap->getHeight()), |
427 | lmap->getPixelData()); | 427 | lmap->getPixelData()); |
428 | 428 | ||
429 | driver->addTexture(lmapName.c_str(), lmapImg); | 429 | driver->addTexture(lmapName.c_str(), lmapImg); |
430 | lmapImg->drop(); | 430 | lmapImg->drop(); |
431 | } | 431 | } |
432 | 432 | ||
433 | for(u32 m = 0; m<csmFile->getMeshCount(); m++) | 433 | for(u32 m = 0; m<csmFile->getMeshCount(); m++) |
434 | { | 434 | { |
435 | const Mesh* mshPtr = csmFile->getMeshAt(m); | 435 | const Mesh* mshPtr = csmFile->getMeshAt(m); |
436 | 436 | ||
437 | for(s32 s = 0; s < mshPtr->getSurfaceCount(); s++) | 437 | for(s32 s = 0; s < mshPtr->getSurfaceCount(); s++) |
438 | { | 438 | { |
439 | const Surface* surface = mshPtr->getSurfaceAt(s); | 439 | const Surface* surface = mshPtr->getSurfaceAt(s); |
440 | 440 | ||
441 | core::stringc texName; | 441 | core::stringc texName; |
442 | if (textureRoot.size()) | 442 | if (textureRoot.size()) |
443 | { | 443 | { |
444 | texName += textureRoot; | 444 | texName += textureRoot; |
445 | texName += "/"; | 445 | texName += "/"; |
446 | } | 446 | } |
447 | texName+= surface->getTextureName(); | 447 | texName+= surface->getTextureName(); |
448 | 448 | ||
449 | video::ITexture* texture = 0; | 449 | video::ITexture* texture = 0; |
450 | if (texName.size()) | 450 | if (texName.size()) |
451 | { | 451 | { |
452 | if (FileSystem->existFile(texName)) | 452 | if (FileSystem->existFile(texName)) |
453 | texture = driver->getTexture(texName); | 453 | texture = driver->getTexture(texName); |
454 | else if (FileSystem->existFile(surface->getTextureName())) | 454 | else if (FileSystem->existFile(surface->getTextureName())) |
455 | texture = driver->getTexture(surface->getTextureName()); | 455 | texture = driver->getTexture(surface->getTextureName()); |
456 | else if (FileSystem->existFile(FileSystem->getFileBasename(surface->getTextureName()))) | 456 | else if (FileSystem->existFile(FileSystem->getFileBasename(surface->getTextureName()))) |
457 | texture = driver->getTexture(FileSystem->getFileBasename(surface->getTextureName())); | 457 | texture = driver->getTexture(FileSystem->getFileBasename(surface->getTextureName())); |
458 | else if (FileSystem->existFile(FileSystem->getFileDir(lmprefix)+"/"+surface->getTextureName())) | 458 | else if (FileSystem->existFile(FileSystem->getFileDir(lmprefix)+"/"+surface->getTextureName())) |
459 | texture = driver->getTexture(FileSystem->getFileDir(lmprefix)+"/"+surface->getTextureName()); | 459 | texture = driver->getTexture(FileSystem->getFileDir(lmprefix)+"/"+surface->getTextureName()); |
460 | else | 460 | else |
461 | texture = driver->getTexture(FileSystem->getFileDir(lmprefix)+"/"+FileSystem->getFileBasename(surface->getTextureName())); | 461 | texture = driver->getTexture(FileSystem->getFileDir(lmprefix)+"/"+FileSystem->getFileBasename(surface->getTextureName())); |
462 | } | 462 | } |
463 | 463 | ||
464 | //material | 464 | //material |
465 | io::path lmapName = lmprefix; | 465 | io::path lmapName = lmprefix; |
466 | lmapName += "LMAP_"; | 466 | lmapName += "LMAP_"; |
467 | lmapName += io::path(surface->getLightMapId()); | 467 | lmapName += io::path(surface->getLightMapId()); |
468 | 468 | ||
469 | scene::SMeshBufferLightMap *buffer = new scene::SMeshBufferLightMap(); | 469 | scene::SMeshBufferLightMap *buffer = new scene::SMeshBufferLightMap(); |
470 | buffer->Material.setTexture(0, texture); | 470 | buffer->Material.setTexture(0, texture); |
471 | if (surface->getLightMapId()) | 471 | if (surface->getLightMapId()) |
472 | { | 472 | { |
473 | buffer->Material.setTexture(1, driver->getTexture(lmapName)); | 473 | buffer->Material.setTexture(1, driver->getTexture(lmapName)); |
474 | buffer->Material.Lighting = false; | 474 | buffer->Material.Lighting = false; |
475 | buffer->Material.MaterialType = video::EMT_LIGHTMAP_ADD; | 475 | buffer->Material.MaterialType = video::EMT_LIGHTMAP_ADD; |
476 | } | 476 | } |
477 | 477 | ||
478 | buffer->Vertices.reallocate(surface->getVertexCount()); | 478 | buffer->Vertices.reallocate(surface->getVertexCount()); |
479 | for(u32 v = 0; v < surface->getVertexCount(); ++v) | 479 | for(u32 v = 0; v < surface->getVertexCount(); ++v) |
480 | { | 480 | { |
481 | const Vertex& vtxPtr = surface->getVertexAt(v); | 481 | const Vertex& vtxPtr = surface->getVertexAt(v); |
482 | video::S3DVertex2TCoords vtx; | 482 | video::S3DVertex2TCoords vtx; |
483 | vtx.Pos = vtxPtr.getPosition(); | 483 | vtx.Pos = vtxPtr.getPosition(); |
484 | vtx.Normal = vtxPtr.getPosition(); | 484 | vtx.Normal = vtxPtr.getPosition(); |
485 | vtx.Color=vtxPtr.getColor(); | 485 | vtx.Color=vtxPtr.getColor(); |
486 | vtx.TCoords.set(vtxPtr.getTextureCoordinates().X, 1.f-vtxPtr.getTextureCoordinates().Y); | 486 | vtx.TCoords.set(vtxPtr.getTextureCoordinates().X, 1.f-vtxPtr.getTextureCoordinates().Y); |
487 | vtx.TCoords2.set(vtxPtr.getLightMapCoordinates().X, 1.f-vtxPtr.getLightMapCoordinates().Y); | 487 | vtx.TCoords2.set(vtxPtr.getLightMapCoordinates().X, 1.f-vtxPtr.getLightMapCoordinates().Y); |
488 | 488 | ||
489 | buffer->Vertices.push_back(vtx); | 489 | buffer->Vertices.push_back(vtx); |
490 | } | 490 | } |
491 | 491 | ||
492 | buffer->Indices.reallocate(surface->getTriangleCount()*3); | 492 | buffer->Indices.reallocate(surface->getTriangleCount()*3); |
493 | for(u32 t = 0; t < surface->getTriangleCount(); ++t) | 493 | for(u32 t = 0; t < surface->getTriangleCount(); ++t) |
494 | { | 494 | { |
495 | const Triangle& tri = surface->getTriangleAt(t); | 495 | const Triangle& tri = surface->getTriangleAt(t); |
496 | buffer->Indices.push_back(tri.c); | 496 | buffer->Indices.push_back(tri.c); |
497 | buffer->Indices.push_back(tri.b); | 497 | buffer->Indices.push_back(tri.b); |
498 | buffer->Indices.push_back(tri.a); | 498 | buffer->Indices.push_back(tri.a); |
499 | } | 499 | } |
500 | 500 | ||
501 | buffer->recalculateBoundingBox(); | 501 | buffer->recalculateBoundingBox(); |
502 | pMesh->addMeshBuffer(buffer); | 502 | pMesh->addMeshBuffer(buffer); |
503 | buffer->drop(); | 503 | buffer->drop(); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | pMesh->recalculateBoundingBox(); | 507 | pMesh->recalculateBoundingBox(); |
508 | return pMesh; | 508 | return pMesh; |
509 | } | 509 | } |
510 | 510 | ||
511 | void Group::clear() | 511 | void Group::clear() |
512 | { | 512 | { |
513 | color.clear(); | 513 | color.clear(); |
514 | flags = 0; | 514 | flags = 0; |
515 | parentGroup = 0; | 515 | parentGroup = 0; |
516 | props = ""; | 516 | props = ""; |
517 | } | 517 | } |
518 | 518 | ||
519 | void Group::load(BinaryFileReader* pReader) | 519 | void Group::load(BinaryFileReader* pReader) |
520 | { | 520 | { |
521 | flags = pReader->readLong(); | 521 | flags = pReader->readLong(); |
522 | parentGroup = pReader->readLong(); | 522 | parentGroup = pReader->readLong(); |
523 | pReader->readString(props); | 523 | pReader->readString(props); |
524 | pReader->readColorRGB(&color); | 524 | pReader->readColorRGB(&color); |
525 | } | 525 | } |
526 | 526 | ||
527 | void VisGroup::clear() | 527 | void VisGroup::clear() |
528 | { | 528 | { |
529 | color.clear(); | 529 | color.clear(); |
530 | flags = 0; | 530 | flags = 0; |
531 | name = ""; | 531 | name = ""; |
532 | } | 532 | } |
533 | 533 | ||
534 | void VisGroup::load(BinaryFileReader* pReader) | 534 | void VisGroup::load(BinaryFileReader* pReader) |
535 | { | 535 | { |
536 | pReader->readString(name); | 536 | pReader->readString(name); |
537 | flags = pReader->readLong(); | 537 | flags = pReader->readLong(); |
538 | pReader->readColorRGB(&color); | 538 | pReader->readColorRGB(&color); |
539 | } | 539 | } |
540 | 540 | ||
541 | void LightMap::clear() | 541 | void LightMap::clear() |
542 | { | 542 | { |
543 | delete[] pixelData; | 543 | delete[] pixelData; |
544 | pixelData = 0; | 544 | pixelData = 0; |
545 | width = height = 0; | 545 | width = height = 0; |
546 | } | 546 | } |
547 | 547 | ||
548 | void LightMap::load(BinaryFileReader* pReader) | 548 | void LightMap::load(BinaryFileReader* pReader) |
549 | { | 549 | { |
550 | width = pReader->readLong(); | 550 | width = pReader->readLong(); |
551 | height = pReader->readLong(); | 551 | height = pReader->readLong(); |
552 | pixelData = new s32[width * height]; | 552 | pixelData = new s32[width * height]; |
553 | pReader->readBuffer(pixelData, width * height * sizeof(s32)); | 553 | pReader->readBuffer(pixelData, width * height * sizeof(s32)); |
554 | } | 554 | } |
555 | 555 | ||
556 | void Mesh::clear() | 556 | void Mesh::clear() |
557 | { | 557 | { |
558 | flags = 0; | 558 | flags = 0; |
559 | groupId = 0; | 559 | groupId = 0; |
560 | visgroupId = 0; | 560 | visgroupId = 0; |
561 | props = ""; | 561 | props = ""; |
562 | color.clear(); | 562 | color.clear(); |
563 | position.set(0,0,0); | 563 | position.set(0,0,0); |
564 | 564 | ||
565 | for(u32 s = 0; s < surfaces.size(); s++) | 565 | for(u32 s = 0; s < surfaces.size(); s++) |
566 | { | 566 | { |
567 | delete surfaces[s]; | 567 | delete surfaces[s]; |
568 | } | 568 | } |
569 | surfaces.clear(); | 569 | surfaces.clear(); |
570 | } | 570 | } |
571 | 571 | ||
572 | void Mesh::load(BinaryFileReader* pReader, bool bReadVisGroups) | 572 | void Mesh::load(BinaryFileReader* pReader, bool bReadVisGroups) |
573 | { | 573 | { |
574 | flags = pReader->readLong(); | 574 | flags = pReader->readLong(); |
575 | groupId = pReader->readLong(); | 575 | groupId = pReader->readLong(); |
576 | pReader->readString(props); | 576 | pReader->readString(props); |
577 | pReader->readColorRGB(&color); | 577 | pReader->readColorRGB(&color); |
578 | pReader->readVec3f(&position); | 578 | pReader->readVec3f(&position); |
579 | if(bReadVisGroups) | 579 | if(bReadVisGroups) |
580 | visgroupId = pReader->readLong(); | 580 | visgroupId = pReader->readLong(); |
581 | else | 581 | else |
582 | visgroupId = 0; | 582 | visgroupId = 0; |
583 | 583 | ||
584 | s32 count = pReader->readLong(); | 584 | s32 count = pReader->readLong(); |
585 | 585 | ||
586 | for(s32 i = 0; i < count; i++) | 586 | for(s32 i = 0; i < count; i++) |
587 | { | 587 | { |
588 | Surface* surf = new Surface(); | 588 | Surface* surf = new Surface(); |
589 | surf->load(pReader); | 589 | surf->load(pReader); |
590 | surfaces.push_back(surf); | 590 | surfaces.push_back(surf); |
591 | } | 591 | } |
592 | } | 592 | } |
593 | 593 | ||
594 | void Surface::clear() | 594 | void Surface::clear() |
595 | { | 595 | { |
596 | flags = 0; | 596 | flags = 0; |
597 | lightMapId = 0; | 597 | lightMapId = 0; |
598 | textureName = ""; | 598 | textureName = ""; |
599 | uvOffset.set(0.0f,0.0f); | 599 | uvOffset.set(0.0f,0.0f); |
600 | uvScale.set(0.0f,0.0f); | 600 | uvScale.set(0.0f,0.0f); |
601 | uvRotation = 0.0f; | 601 | uvRotation = 0.0f; |
602 | triangles.clear(); | 602 | triangles.clear(); |
603 | lines.clear(); | 603 | lines.clear(); |
604 | vertices.clear(); | 604 | vertices.clear(); |
605 | } | 605 | } |
606 | 606 | ||
607 | void Surface::load(BinaryFileReader* pReader) | 607 | void Surface::load(BinaryFileReader* pReader) |
608 | { | 608 | { |
609 | flags = pReader->readLong(); | 609 | flags = pReader->readLong(); |
610 | pReader->readString(textureName); | 610 | pReader->readString(textureName); |
611 | textureName.replace('\\', '/'); | 611 | textureName.replace('\\', '/'); |
612 | 612 | ||
613 | lightMapId = pReader->readLong(); | 613 | lightMapId = pReader->readLong(); |
614 | pReader->readVec2f(&uvOffset); | 614 | pReader->readVec2f(&uvOffset); |
615 | pReader->readVec2f(&uvScale); | 615 | pReader->readVec2f(&uvScale); |
616 | uvRotation = pReader->readFloat(); | 616 | uvRotation = pReader->readFloat(); |
617 | s32 vtxCount = pReader->readLong(); | 617 | s32 vtxCount = pReader->readLong(); |
618 | s32 triCount = pReader->readLong(); | 618 | s32 triCount = pReader->readLong(); |
619 | s32 lineCount = pReader->readLong(); | 619 | s32 lineCount = pReader->readLong(); |
620 | 620 | ||
621 | for(s32 v = 0; v < vtxCount; v++) | 621 | for(s32 v = 0; v < vtxCount; v++) |
622 | { | 622 | { |
623 | vertices.push_back(Vertex()); | 623 | vertices.push_back(Vertex()); |
624 | vertices.getLast().load(pReader); | 624 | vertices.getLast().load(pReader); |
625 | } | 625 | } |
626 | 626 | ||
627 | for(s32 t = 0; t < triCount; t++) | 627 | for(s32 t = 0; t < triCount; t++) |
628 | { | 628 | { |
629 | Triangle tri; | 629 | Triangle tri; |
630 | pReader->readBuffer(&tri, sizeof(tri)); | 630 | pReader->readBuffer(&tri, sizeof(tri)); |
631 | triangles.push_back(tri); | 631 | triangles.push_back(tri); |
632 | } | 632 | } |
633 | 633 | ||
634 | for(s32 l = 0; l < lineCount; l++) | 634 | for(s32 l = 0; l < lineCount; l++) |
635 | { | 635 | { |
636 | Line line; | 636 | Line line; |
637 | pReader->readBuffer(&line,sizeof(line)); | 637 | pReader->readBuffer(&line,sizeof(line)); |
638 | lines.push_back(line); | 638 | lines.push_back(line); |
639 | 639 | ||
640 | } | 640 | } |
641 | 641 | ||
642 | } | 642 | } |
643 | 643 | ||
644 | void Vertex::clear() | 644 | void Vertex::clear() |
645 | { | 645 | { |
646 | position.set(0,0,0); | 646 | position.set(0,0,0); |
647 | normal.set(0,0,0); | 647 | normal.set(0,0,0); |
648 | color.clear(); | 648 | color.clear(); |
649 | texCoords.set(0,0,0); | 649 | texCoords.set(0,0,0); |
650 | lmapCoords.set(0,0,0); | 650 | lmapCoords.set(0,0,0); |
651 | } | 651 | } |
652 | 652 | ||
653 | void Vertex::load(BinaryFileReader* pReader) | 653 | void Vertex::load(BinaryFileReader* pReader) |
654 | { | 654 | { |
655 | pReader->readVec3f(&position); | 655 | pReader->readVec3f(&position); |
656 | pReader->readVec3f(&normal); | 656 | pReader->readVec3f(&normal); |
657 | pReader->readColorRGB(&color); | 657 | pReader->readColorRGB(&color); |
658 | pReader->readVec3f(&texCoords); | 658 | pReader->readVec3f(&texCoords); |
659 | pReader->readVec3f(&lmapCoords); | 659 | pReader->readVec3f(&lmapCoords); |
660 | } | 660 | } |
661 | 661 | ||
662 | void Entity::clear() | 662 | void Entity::clear() |
663 | { | 663 | { |
664 | visgroupId = groupId = 0; | 664 | visgroupId = groupId = 0; |
665 | props = ""; | 665 | props = ""; |
666 | position.set(0,0,0); | 666 | position.set(0,0,0); |
667 | } | 667 | } |
668 | 668 | ||
669 | void Entity::load(BinaryFileReader* pReader) | 669 | void Entity::load(BinaryFileReader* pReader) |
670 | { | 670 | { |
671 | visgroupId = pReader->readLong(); | 671 | visgroupId = pReader->readLong(); |
672 | groupId = pReader->readLong(); | 672 | groupId = pReader->readLong(); |
673 | pReader->readString(props); | 673 | pReader->readString(props); |
674 | pReader->readVec3f(&position); | 674 | pReader->readVec3f(&position); |
675 | } | 675 | } |
676 | 676 | ||
677 | void CameraData::clear() | 677 | void CameraData::clear() |
678 | { | 678 | { |
679 | position.set(0,0,0); | 679 | position.set(0,0,0); |
680 | pitch = 0; | 680 | pitch = 0; |
681 | yaw = 0; | 681 | yaw = 0; |
682 | } | 682 | } |
683 | 683 | ||
684 | void CameraData::load(BinaryFileReader* pReader) | 684 | void CameraData::load(BinaryFileReader* pReader) |
685 | { | 685 | { |
686 | pReader->readVec3f(&position); | 686 | pReader->readVec3f(&position); |
687 | pitch = pReader->readFloat(); | 687 | pitch = pReader->readFloat(); |
688 | yaw = pReader->readFloat(); | 688 | yaw = pReader->readFloat(); |
689 | } | 689 | } |
690 | 690 | ||
691 | void CSMFile::clear() | 691 | void CSMFile::clear() |
692 | { | 692 | { |
693 | header.clear(); | 693 | header.clear(); |
694 | cameraData.clear(); | 694 | cameraData.clear(); |
695 | 695 | ||
696 | u32 x =0; | 696 | u32 x =0; |
697 | for( x= 0; x < groups.size(); x++) | 697 | for( x= 0; x < groups.size(); x++) |
698 | delete groups[x]; | 698 | delete groups[x]; |
699 | 699 | ||
700 | groups.clear(); | 700 | groups.clear(); |
701 | 701 | ||
702 | for(x= 0; x < visgroups.size(); x++) | 702 | for(x= 0; x < visgroups.size(); x++) |
703 | delete visgroups[x]; | 703 | delete visgroups[x]; |
704 | 704 | ||
705 | visgroups.clear(); | 705 | visgroups.clear(); |
706 | 706 | ||
707 | for(x= 0; x < lightmaps.size(); x++) | 707 | for(x= 0; x < lightmaps.size(); x++) |
708 | delete lightmaps[x]; | 708 | delete lightmaps[x]; |
709 | 709 | ||
710 | lightmaps.clear(); | 710 | lightmaps.clear(); |
711 | 711 | ||
712 | for(x= 0; x < meshes.size(); x++) | 712 | for(x= 0; x < meshes.size(); x++) |
713 | delete meshes[x]; | 713 | delete meshes[x]; |
714 | 714 | ||
715 | meshes.clear(); | 715 | meshes.clear(); |
716 | 716 | ||
717 | for(x= 0; x < entities.size(); x++) | 717 | for(x= 0; x < entities.size(); x++) |
718 | delete entities[x]; | 718 | delete entities[x]; |
719 | 719 | ||
720 | entities.clear(); | 720 | entities.clear(); |
721 | } | 721 | } |
722 | 722 | ||
723 | void CSMFile::load(BinaryFileReader* pReader) | 723 | void CSMFile::load(BinaryFileReader* pReader) |
724 | { | 724 | { |
725 | clear(); | 725 | clear(); |
726 | 726 | ||
727 | header.load(pReader); | 727 | header.load(pReader); |
728 | 728 | ||
729 | //groups | 729 | //groups |
730 | { | 730 | { |
731 | const s32 count = pReader->readLong(); | 731 | const s32 count = pReader->readLong(); |
732 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 732 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
733 | os::Printer::log("CSM Version", core::stringc(header.getVersion()).c_str()); | 733 | os::Printer::log("CSM Version", core::stringc(header.getVersion()).c_str()); |
734 | os::Printer::log("Loading groups. Count", core::stringc(count)); | 734 | os::Printer::log("Loading groups. Count", core::stringc(count)); |
735 | #endif | 735 | #endif |
736 | 736 | ||
737 | groups.reallocate(count); | 737 | groups.reallocate(count); |
738 | for (s32 i = 0; i < count; i++) | 738 | for (s32 i = 0; i < count; i++) |
739 | { | 739 | { |
740 | Group* grp = new Group(); | 740 | Group* grp = new Group(); |
741 | grp->load(pReader); | 741 | grp->load(pReader); |
742 | groups.push_back(grp); | 742 | groups.push_back(grp); |
743 | } | 743 | } |
744 | } | 744 | } |
745 | const bool bHasVGroups = (header.getVersion() == Header::VERSION_4_1); | 745 | const bool bHasVGroups = (header.getVersion() == Header::VERSION_4_1); |
746 | 746 | ||
747 | if (bHasVGroups) | 747 | if (bHasVGroups) |
748 | { | 748 | { |
749 | //visgroups | 749 | //visgroups |
750 | const s32 count = pReader->readLong(); | 750 | const s32 count = pReader->readLong(); |
751 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 751 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
752 | os::Printer::log("Loading visgroups. Count", core::stringc(count)); | 752 | os::Printer::log("Loading visgroups. Count", core::stringc(count)); |
753 | #endif | 753 | #endif |
754 | 754 | ||
755 | visgroups.reallocate(count); | 755 | visgroups.reallocate(count); |
756 | for (s32 i = 0; i < count; i++) | 756 | for (s32 i = 0; i < count; i++) |
757 | { | 757 | { |
758 | VisGroup* grp = new VisGroup(); | 758 | VisGroup* grp = new VisGroup(); |
759 | grp->load(pReader); | 759 | grp->load(pReader); |
760 | visgroups.push_back(grp); | 760 | visgroups.push_back(grp); |
761 | } | 761 | } |
762 | } | 762 | } |
763 | 763 | ||
764 | //lightmaps | 764 | //lightmaps |
765 | { | 765 | { |
766 | const s32 count = pReader->readLong(); | 766 | const s32 count = pReader->readLong(); |
767 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 767 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
768 | os::Printer::log("Loading lightmaps. Count", core::stringc(count)); | 768 | os::Printer::log("Loading lightmaps. Count", core::stringc(count)); |
769 | #endif | 769 | #endif |
770 | 770 | ||
771 | lightmaps.reallocate(count); | 771 | lightmaps.reallocate(count); |
772 | for(s32 i = 0; i < count; i++) | 772 | for(s32 i = 0; i < count; i++) |
773 | { | 773 | { |
774 | LightMap* lm = new LightMap(); | 774 | LightMap* lm = new LightMap(); |
775 | lm->load(pReader); | 775 | lm->load(pReader); |
776 | lightmaps.push_back(lm); | 776 | lightmaps.push_back(lm); |
777 | } | 777 | } |
778 | } | 778 | } |
779 | 779 | ||
780 | //meshes | 780 | //meshes |
781 | { | 781 | { |
782 | const s32 count = pReader->readLong(); | 782 | const s32 count = pReader->readLong(); |
783 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 783 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
784 | os::Printer::log("Loading meshes. Count", core::stringc(count)); | 784 | os::Printer::log("Loading meshes. Count", core::stringc(count)); |
785 | #endif | 785 | #endif |
786 | 786 | ||
787 | meshes.reallocate(count); | 787 | meshes.reallocate(count); |
788 | for(s32 i = 0; i < count; i++) | 788 | for(s32 i = 0; i < count; i++) |
789 | { | 789 | { |
790 | Mesh* mesh = new Mesh(); | 790 | Mesh* mesh = new Mesh(); |
791 | mesh->load(pReader,bHasVGroups); | 791 | mesh->load(pReader,bHasVGroups); |
792 | meshes.push_back(mesh); | 792 | meshes.push_back(mesh); |
793 | } | 793 | } |
794 | } | 794 | } |
795 | 795 | ||
796 | //entities | 796 | //entities |
797 | { | 797 | { |
798 | const s32 count = pReader->readLong(); | 798 | const s32 count = pReader->readLong(); |
799 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 799 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
800 | os::Printer::log("Loading entitites. Count", core::stringc(count)); | 800 | os::Printer::log("Loading entitites. Count", core::stringc(count)); |
801 | #endif | 801 | #endif |
802 | 802 | ||
803 | entities.reallocate(count); | 803 | entities.reallocate(count); |
804 | for(s32 i = 0; i < count; i++) | 804 | for(s32 i = 0; i < count; i++) |
805 | { | 805 | { |
806 | Entity* ent = new Entity(); | 806 | Entity* ent = new Entity(); |
807 | ent->load(pReader); | 807 | ent->load(pReader); |
808 | entities.push_back(ent); | 808 | entities.push_back(ent); |
809 | } | 809 | } |
810 | } | 810 | } |
811 | 811 | ||
812 | //camera data | 812 | //camera data |
813 | #ifdef _IRR_DEBUG_CSM_LOADER_ | 813 | #ifdef _IRR_DEBUG_CSM_LOADER_ |
814 | os::Printer::log("Loading camera data."); | 814 | os::Printer::log("Loading camera data."); |
815 | #endif | 815 | #endif |
816 | cameraData.load(pReader); | 816 | cameraData.load(pReader); |
817 | } | 817 | } |
818 | 818 | ||
819 | s32 BinaryFileReader::readLong() | 819 | s32 BinaryFileReader::readLong() |
820 | { | 820 | { |
821 | int ret = 0; | 821 | int ret = 0; |
822 | readBuffer(&ret,sizeof(int)); | 822 | readBuffer(&ret,sizeof(int)); |
823 | #ifdef __BIG_ENDIAN__ | 823 | #ifdef __BIG_ENDIAN__ |
824 | ret = os::Byteswap::byteswap(ret); | 824 | ret = os::Byteswap::byteswap(ret); |
825 | #endif | 825 | #endif |
826 | return ret; | 826 | return ret; |
827 | } | 827 | } |
828 | 828 | ||
829 | f32 BinaryFileReader::readFloat() | 829 | f32 BinaryFileReader::readFloat() |
830 | { | 830 | { |
831 | float ret = 0; | 831 | float ret = 0; |
832 | readBuffer(&ret,sizeof(float)); | 832 | readBuffer(&ret,sizeof(float)); |
833 | #ifdef __BIG_ENDIAN__ | 833 | #ifdef __BIG_ENDIAN__ |
834 | ret = os::Byteswap::byteswap(ret); | 834 | ret = os::Byteswap::byteswap(ret); |
835 | #endif | 835 | #endif |
836 | return ret; | 836 | return ret; |
837 | } | 837 | } |
838 | 838 | ||
839 | void BinaryFileReader::readString(core::stringc &str) | 839 | void BinaryFileReader::readString(core::stringc &str) |
840 | { | 840 | { |
841 | str = ""; | 841 | str = ""; |
842 | c8 c; | 842 | c8 c; |
843 | readBuffer(&c,sizeof(char)); | 843 | readBuffer(&c,sizeof(char)); |
844 | while(c != 0) | 844 | while(c != 0) |
845 | { | 845 | { |
846 | str += c; | 846 | str += c; |
847 | readBuffer(&c,sizeof(char)); | 847 | readBuffer(&c,sizeof(char)); |
848 | } | 848 | } |
849 | } | 849 | } |
850 | 850 | ||
851 | void BinaryFileReader::readVec3f(core::vector3df* v) | 851 | void BinaryFileReader::readVec3f(core::vector3df* v) |
852 | { | 852 | { |
853 | v->X = readFloat(); | 853 | v->X = readFloat(); |
854 | v->Y = readFloat(); | 854 | v->Y = readFloat(); |
855 | v->Z = readFloat(); | 855 | v->Z = readFloat(); |
856 | } | 856 | } |
857 | 857 | ||
858 | void BinaryFileReader::readVec2f(core::vector2df* v) | 858 | void BinaryFileReader::readVec2f(core::vector2df* v) |
859 | { | 859 | { |
860 | v->X = readFloat(); | 860 | v->X = readFloat(); |
861 | v->Y = readFloat(); | 861 | v->Y = readFloat(); |
862 | } | 862 | } |
863 | 863 | ||
864 | void BinaryFileReader::readColorRGB(color_rgb_t* color) | 864 | void BinaryFileReader::readColorRGB(color_rgb_t* color) |
865 | { | 865 | { |
866 | readBuffer(color,sizeof(color_rgb_t)); | 866 | readBuffer(color,sizeof(color_rgb_t)); |
867 | } | 867 | } |
868 | 868 | ||
869 | } // end namespace | 869 | } // end namespace |
870 | } // end namespace | 870 | } // end namespace |
871 | 871 | ||
872 | #endif // _IRR_COMPILE_WITH_CSM_LOADER_ | 872 | #endif // _IRR_COMPILE_WITH_CSM_LOADER_ |