1 | #include "GeoMesh.h"
|
---|
2 |
|
---|
3 | using namespace Geometry;
|
---|
4 | using namespace std;
|
---|
5 |
|
---|
6 | //---------------------------------------------------------------------------
|
---|
7 | // Cosntructor.
|
---|
8 | //---------------------------------------------------------------------------
|
---|
9 | Mesh::Mesh():
|
---|
10 | mVertexBuffer(0), mSubMeshCount(0), mSubMesh(0), hasSkeleton(false)
|
---|
11 | {
|
---|
12 | mMeshBounds.maxX = 0.0;
|
---|
13 | mMeshBounds.maxY = 0.0;
|
---|
14 | mMeshBounds.maxZ = 0.0;
|
---|
15 | mMeshBounds.minX = 0.0;
|
---|
16 | mMeshBounds.minY = 0.0;
|
---|
17 | mMeshBounds.minZ = 0.0;
|
---|
18 | mMeshBounds.scaleFactor = 0.0;
|
---|
19 | }
|
---|
20 |
|
---|
21 | //---------------------------------------------------------------------------
|
---|
22 | // Destroyer.
|
---|
23 | //---------------------------------------------------------------------------
|
---|
24 | Mesh::~Mesh()
|
---|
25 | {
|
---|
26 | delete [] mSubMesh;
|
---|
27 | delete mVertexBuffer;
|
---|
28 | }
|
---|
29 |
|
---|
30 | //---------------------------------------------------------------------------
|
---|
31 | // Copy constructor.
|
---|
32 | //---------------------------------------------------------------------------
|
---|
33 | Mesh::Mesh(const Mesh &mesh)
|
---|
34 | {
|
---|
35 | mVertexBuffer = new VertexBuffer();
|
---|
36 | mSubMeshCount = mesh.mSubMeshCount;
|
---|
37 | mSubMesh = new SubMesh[mesh.mSubMeshCount];
|
---|
38 |
|
---|
39 | // Fill up bounding box settings.
|
---|
40 | mMeshBounds.maxX = mesh.mMeshBounds.maxX;
|
---|
41 | mMeshBounds.maxY = mesh.mMeshBounds.maxY;
|
---|
42 | mMeshBounds.maxZ = mesh.mMeshBounds.maxZ;
|
---|
43 | mMeshBounds.minX = mesh.mMeshBounds.minX;
|
---|
44 | mMeshBounds.minY = mesh.mMeshBounds.minY;
|
---|
45 | mMeshBounds.minZ = mesh.mMeshBounds.minZ;
|
---|
46 | mMeshBounds.radius = mesh.mMeshBounds.radius;
|
---|
47 | mMeshBounds.scaleFactor = mesh.mMeshBounds.scaleFactor;
|
---|
48 |
|
---|
49 | // For each submesh.
|
---|
50 | for (size_t i = 0; i < mesh.mSubMeshCount; i++)
|
---|
51 | {
|
---|
52 | mSubMesh[i].mSharedVertexBuffer = false;
|
---|
53 | mSubMesh[i].mVertexBuffer = new VertexBuffer();
|
---|
54 | mSubMesh[i].mVertexBuffer->mPosition = new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
55 | mSubMesh[i].mVertexBuffer->mNormal = new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
56 | mSubMesh[i].mVertexBuffer->mTexCoords = new Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
57 | mSubMesh[i].mVertexBuffer->mVertexCount = mesh.mSubMesh[i].mVertexBuffer->mVertexCount;
|
---|
58 | mSubMesh[i].mVertexBuffer->mVertexInfo = mesh.mSubMesh[i].mVertexBuffer->mVertexInfo;
|
---|
59 | mSubMesh[i].mType = mesh.mSubMesh[i].mType;
|
---|
60 |
|
---|
61 | strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName);
|
---|
62 |
|
---|
63 | if (mesh.mSubMesh[i].mSharedVertexBuffer)
|
---|
64 | {
|
---|
65 | for (size_t s = 0;
|
---|
66 | s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount;
|
---|
67 | s++)
|
---|
68 | {
|
---|
69 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION)
|
---|
70 | {
|
---|
71 | mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mVertexBuffer->mPosition[s].x;
|
---|
72 | mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mVertexBuffer->mPosition[s].y;
|
---|
73 | mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mVertexBuffer->mPosition[s].z;
|
---|
74 | }
|
---|
75 |
|
---|
76 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL)
|
---|
77 | {
|
---|
78 | mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mVertexBuffer->mNormal[s].x;
|
---|
79 | mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mVertexBuffer->mNormal[s].y;
|
---|
80 | mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mVertexBuffer->mNormal[s].z;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)
|
---|
84 | {
|
---|
85 | mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mVertexBuffer->mTexCoords[s].x;
|
---|
86 | mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mVertexBuffer->mTexCoords[s].y;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | mesh.mSubMesh[i].mSharedVertexBuffer = false;
|
---|
91 | }
|
---|
92 | else
|
---|
93 | {
|
---|
94 | for (size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++)
|
---|
95 | {
|
---|
96 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION)
|
---|
97 | {
|
---|
98 | mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x;
|
---|
99 | mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y;
|
---|
100 | mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z;
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL)
|
---|
104 | {
|
---|
105 | mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x;
|
---|
106 | mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y;
|
---|
107 | mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z;
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)
|
---|
111 | {
|
---|
112 | mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x;
|
---|
113 | mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 | // Copy indices.
|
---|
120 | mSubMesh[i].mIndexCount = mesh.mSubMesh[i].mIndexCount;
|
---|
121 | mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount];
|
---|
122 |
|
---|
123 | memcpy( mSubMesh[i].mIndex,
|
---|
124 | mesh.mSubMesh[i].mIndex,
|
---|
125 | mesh.mSubMesh[i].mIndexCount * sizeof(Index));
|
---|
126 |
|
---|
127 | // Copy strips.
|
---|
128 | // offset between memory positions.
|
---|
129 | __w64 int offset = 0;
|
---|
130 | mSubMesh[i].mStripCount = mesh.mSubMesh[i].mStripCount;
|
---|
131 |
|
---|
132 | if (mesh.mSubMesh[i].mStripCount > 0)
|
---|
133 | {
|
---|
134 | mSubMesh[i].mStrip = new Index*[mesh.mSubMesh[i].mStripCount];
|
---|
135 |
|
---|
136 | offset = &(mSubMesh[i].mIndex[0]) - &(mesh.mSubMesh[i].mIndex[0]);
|
---|
137 |
|
---|
138 | for (size_t j = 0; j < mesh.mSubMesh[i].mStripCount; j++)
|
---|
139 | {
|
---|
140 | mSubMesh[i].mStrip[j] = mesh.mSubMesh[i].mStrip[j] + offset;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Copy submesh bones.
|
---|
145 | if (!mesh.mSubMesh[i].mBones.empty())
|
---|
146 | {
|
---|
147 | for (unsigned int j = 0; j < mesh.mSubMesh[i].mBones.size(); j++)
|
---|
148 | {
|
---|
149 | mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]);
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Copy skeleton name.
|
---|
155 | if (mesh.hasSkeleton)
|
---|
156 | {
|
---|
157 | hasSkeleton = true;
|
---|
158 |
|
---|
159 | strcpy(mSkeletonName, mesh.mSkeletonName);
|
---|
160 | }
|
---|
161 |
|
---|
162 | // Copy mesh bones.
|
---|
163 | if (!mesh.mBones.empty())
|
---|
164 | {
|
---|
165 | for (unsigned int j = 0; j < mesh.mBones.size(); j++)
|
---|
166 | {
|
---|
167 | mBones.push_back(mesh.mBones[j]);
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | }
|
---|
172 |
|
---|
173 | //---------------------------------------------------------------------------
|
---|
174 | // Assignment operator.
|
---|
175 | //---------------------------------------------------------------------------
|
---|
176 | Mesh &Mesh::operator =(const Mesh &mesh)
|
---|
177 | {
|
---|
178 | bool copied = false;
|
---|
179 | mVertexBuffer = new VertexBuffer();
|
---|
180 | mSubMeshCount = mesh.mSubMeshCount;
|
---|
181 | mSubMesh = new Geometry::SubMesh[mesh.mSubMeshCount];
|
---|
182 |
|
---|
183 | // Fill up bounding box settings.
|
---|
184 | mMeshBounds.maxX = mesh.mMeshBounds.maxX;
|
---|
185 | mMeshBounds.maxY = mesh.mMeshBounds.maxY;
|
---|
186 | mMeshBounds.maxZ = mesh.mMeshBounds.maxZ;
|
---|
187 | mMeshBounds.minX = mesh.mMeshBounds.minX;
|
---|
188 | mMeshBounds.minY = mesh.mMeshBounds.minY;
|
---|
189 | mMeshBounds.minZ = mesh.mMeshBounds.minZ;
|
---|
190 | mMeshBounds.radius = mesh.mMeshBounds.radius;
|
---|
191 | mMeshBounds.scaleFactor = mesh.mMeshBounds.scaleFactor;
|
---|
192 |
|
---|
193 | // For each submesh.
|
---|
194 | for(size_t i = 0; i < mesh.mSubMeshCount; i++)
|
---|
195 | {
|
---|
196 | mSubMesh[i].mSharedVertexBuffer = mesh.mSubMesh[i].mSharedVertexBuffer; //.false;
|
---|
197 | mSubMesh[i].mVertexBuffer = new Geometry::VertexBuffer();
|
---|
198 | mSubMesh[i].mVertexBuffer->mPosition = new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
199 | mSubMesh[i].mVertexBuffer->mNormal = new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
200 | mSubMesh[i].mVertexBuffer->mTexCoords = new Geometry::Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount];
|
---|
201 | mSubMesh[i].mVertexBuffer->mVertexCount = mesh.mSubMesh[i].mVertexBuffer->mVertexCount;
|
---|
202 | mSubMesh[i].mVertexBuffer->mVertexInfo = mesh.mSubMesh[i].mVertexBuffer->mVertexInfo;
|
---|
203 | mSubMesh[i].mType = mesh.mSubMesh[i].mType;
|
---|
204 | strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName);
|
---|
205 |
|
---|
206 | if (mesh.mSubMesh[i].mSharedVertexBuffer && !copied)
|
---|
207 | {
|
---|
208 | mVertexBuffer = mSubMesh[i].mVertexBuffer;
|
---|
209 | copied = true;
|
---|
210 | }
|
---|
211 |
|
---|
212 | for(size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++)
|
---|
213 | {
|
---|
214 | mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x;
|
---|
215 | mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y;
|
---|
216 | mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z;
|
---|
217 |
|
---|
218 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
|
---|
219 | {
|
---|
220 | mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x;
|
---|
221 | mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y;
|
---|
222 | mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z;
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
|
---|
226 | {
|
---|
227 | mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x;
|
---|
228 | mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | // Copy indices.
|
---|
233 | mSubMesh[i].mIndexCount = mesh.mSubMesh[i].mIndexCount;
|
---|
234 | mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount];
|
---|
235 |
|
---|
236 | memcpy( mSubMesh[i].mIndex,
|
---|
237 | mesh.mSubMesh[i].mIndex,
|
---|
238 | mesh.mSubMesh[i].mIndexCount*sizeof(Geometry::Index));
|
---|
239 |
|
---|
240 | // Copy strips.
|
---|
241 | __w64 offset = 0;
|
---|
242 | mSubMesh[i].mStripCount = mesh.mSubMesh[i].mStripCount;
|
---|
243 |
|
---|
244 | if (mesh.mSubMesh[i].mStripCount > 0)
|
---|
245 | {
|
---|
246 | mSubMesh[i].mStrip = new Index*[mesh.mSubMesh[i].mStripCount];
|
---|
247 |
|
---|
248 | offset = &(mSubMesh[i].mIndex[0])
|
---|
249 | -
|
---|
250 | &(mesh.mSubMesh[i].mIndex[0]);
|
---|
251 |
|
---|
252 | for (size_t j = 0; j < mesh.mSubMesh[i].mStripCount; j++)
|
---|
253 | {
|
---|
254 | mSubMesh[i].mStrip[j] = mesh.mSubMesh[i].mStrip[j] + offset;
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | // Copy submesh bones.
|
---|
259 | if (!mesh.mSubMesh[i].mBones.empty())
|
---|
260 | {
|
---|
261 | for (unsigned int j = 0; j < mesh.mSubMesh[i].mBones.size(); j++)
|
---|
262 | {
|
---|
263 | mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]);
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | // Copy skeleton name.
|
---|
269 | if (mesh.hasSkeleton)
|
---|
270 | {
|
---|
271 | hasSkeleton = true;
|
---|
272 |
|
---|
273 | strcpy(mSkeletonName, mesh.mSkeletonName);
|
---|
274 | }
|
---|
275 |
|
---|
276 | // Copy mesh bones.
|
---|
277 | if (!mesh.mBones.empty())
|
---|
278 | {
|
---|
279 | for (unsigned int j = 0; j < mesh.mBones.size(); j++)
|
---|
280 | {
|
---|
281 | mBones.push_back(mesh.mBones[j]);
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | return *this;
|
---|
286 | }
|
---|
287 |
|
---|
288 | //---------------------------------------------------------------------------
|
---|
289 | // Load mesh.
|
---|
290 | //---------------------------------------------------------------------------
|
---|
291 | void Mesh::Load(Serializer &s)
|
---|
292 | {
|
---|
293 | bool sharedVertexBuffer = false;
|
---|
294 |
|
---|
295 | // Clear Data.
|
---|
296 | delete [] mSubMesh;
|
---|
297 |
|
---|
298 | mSubMesh = 0;
|
---|
299 |
|
---|
300 | delete mVertexBuffer;
|
---|
301 |
|
---|
302 | mVertexBuffer = 0;
|
---|
303 | mSubMeshCount = 0;
|
---|
304 |
|
---|
305 | s.ReadArray(&sharedVertexBuffer,1);
|
---|
306 |
|
---|
307 | if (sharedVertexBuffer)
|
---|
308 | {
|
---|
309 | mVertexBuffer = new VertexBuffer;
|
---|
310 | mVertexBuffer->Load(s);
|
---|
311 | }
|
---|
312 |
|
---|
313 | s.ReadArray(&mSubMeshCount, 1);
|
---|
314 |
|
---|
315 | mSubMesh = new SubMesh[mSubMeshCount];
|
---|
316 |
|
---|
317 | for(size_t i = 0; i < mSubMeshCount; i++)
|
---|
318 | {
|
---|
319 | mSubMesh[i].Load(s);
|
---|
320 |
|
---|
321 | if (mSubMesh[i].mSharedVertexBuffer && sharedVertexBuffer)
|
---|
322 | {
|
---|
323 | mSubMesh[i].mVertexBuffer = mVertexBuffer;
|
---|
324 | }
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | //---------------------------------------------------------------------------
|
---|
329 | // Save mesh.
|
---|
330 | //---------------------------------------------------------------------------
|
---|
331 | void Mesh::Save(Serializer &s)
|
---|
332 | {
|
---|
333 | bool sharedVertexBuffer = (mVertexBuffer != 0);
|
---|
334 |
|
---|
335 | s.WriteArray(&sharedVertexBuffer, 1);
|
---|
336 |
|
---|
337 | if (sharedVertexBuffer)
|
---|
338 | {
|
---|
339 | mVertexBuffer->Save(s);
|
---|
340 | }
|
---|
341 |
|
---|
342 | s.WriteArray(&mSubMeshCount,1);
|
---|
343 |
|
---|
344 | for(size_t i = 0; i < mSubMeshCount; i++)
|
---|
345 | {
|
---|
346 | mSubMesh[i].Save(s);
|
---|
347 | }
|
---|
348 | }
|
---|
349 |
|
---|
350 | //---------------------------------------------------------------------------
|
---|
351 | // Export to obj mesh.
|
---|
352 | //---------------------------------------------------------------------------
|
---|
353 | void Mesh::exportToOBJ(char *fileName)
|
---|
354 | {
|
---|
355 | std::ofstream obj(fileName);
|
---|
356 |
|
---|
357 | obj << "begin" << std::endl;
|
---|
358 |
|
---|
359 | // Vertices.
|
---|
360 | for (size_t i = 0; i < mSubMeshCount; i++)
|
---|
361 | {
|
---|
362 | for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++)
|
---|
363 | {
|
---|
364 | obj << "v "
|
---|
365 | << mSubMesh[i].mVertexBuffer->mPosition[j].x
|
---|
366 | << " "
|
---|
367 | << mSubMesh[i].mVertexBuffer->mPosition[j].y
|
---|
368 | << " "
|
---|
369 | << mSubMesh[i].mVertexBuffer->mPosition[j].z
|
---|
370 | << " "
|
---|
371 | << std::endl;
|
---|
372 | }
|
---|
373 | }
|
---|
374 |
|
---|
375 | // Faces.
|
---|
376 | for (size_t i = 0; i < mSubMeshCount; i++)
|
---|
377 | {
|
---|
378 | for (size_t j = 0; j < mSubMesh[i].mIndexCount; j = j + 3)
|
---|
379 | {
|
---|
380 | obj << "f "
|
---|
381 | << mSubMesh[i].mIndex[j] + 1
|
---|
382 | << " "
|
---|
383 | << mSubMesh[i].mIndex[j + 1] + 1
|
---|
384 | << " "
|
---|
385 | << mSubMesh[i].mIndex[j + 2] + 1
|
---|
386 | << std::endl;
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | obj << "end" << std::endl;
|
---|
391 |
|
---|
392 | obj.close();
|
---|
393 | }
|
---|
394 |
|
---|
395 | //---------------------------------------------------------------------------
|
---|
396 | // Transform to shared vertex mesh.
|
---|
397 | //---------------------------------------------------------------------------
|
---|
398 | Mesh *Mesh::toSharedVertex()
|
---|
399 | {
|
---|
400 | // Move all vertex to the shared vertex buffer.
|
---|
401 | Mesh *mesh = new Mesh();
|
---|
402 |
|
---|
403 | if (mSubMesh[0].mSharedVertexBuffer)
|
---|
404 | {
|
---|
405 | *mesh = *this;
|
---|
406 |
|
---|
407 | return mesh;
|
---|
408 | }
|
---|
409 |
|
---|
410 | mesh->mVertexBuffer = new VertexBuffer();
|
---|
411 | mesh->mSubMeshCount = mSubMeshCount;
|
---|
412 | mesh->mSubMesh = new SubMesh[mSubMeshCount];
|
---|
413 |
|
---|
414 | // Fill up bounding box settings.
|
---|
415 | mesh->mMeshBounds.maxX = mMeshBounds.maxX;
|
---|
416 | mesh->mMeshBounds.maxY = mMeshBounds.maxY;
|
---|
417 | mesh->mMeshBounds.maxZ = mMeshBounds.maxZ;
|
---|
418 | mesh->mMeshBounds.minX = mMeshBounds.minX;
|
---|
419 | mesh->mMeshBounds.minY = mMeshBounds.minY;
|
---|
420 | mesh->mMeshBounds.minZ = mMeshBounds.minZ;
|
---|
421 | mesh->mMeshBounds.radius = mMeshBounds.radius;
|
---|
422 | mesh->mMeshBounds.scaleFactor = mMeshBounds.scaleFactor;
|
---|
423 |
|
---|
424 | // construcción de los submeshes
|
---|
425 | long int acumVerts = 0;
|
---|
426 |
|
---|
427 | for (size_t i = 0; i < mesh->mSubMeshCount; i++)
|
---|
428 | {
|
---|
429 | mesh->mSubMesh[i].mSharedVertexBuffer = true;
|
---|
430 | mesh->mSubMesh[i].mVertexBuffer = mesh->mVertexBuffer;
|
---|
431 | mesh->mSubMesh[i].mStripCount = 0;
|
---|
432 | mesh->mSubMesh[i].mStrip = NULL;
|
---|
433 | mesh->mSubMesh[i].mType = mSubMesh[i].mType;
|
---|
434 |
|
---|
435 | strcpy(mesh->mSubMesh[i].mMaterialName,mSubMesh[i].mMaterialName);
|
---|
436 |
|
---|
437 | // Copy indices.
|
---|
438 | mesh->mSubMesh[i].mIndexCount = mSubMesh[i].mIndexCount;
|
---|
439 | mesh->mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount];
|
---|
440 |
|
---|
441 | for (size_t j = 0; j < mSubMesh[i].mIndexCount; j++)
|
---|
442 | {
|
---|
443 | mesh->mSubMesh[i].mIndex[j] = mSubMesh[i].mIndex[j]+acumVerts;
|
---|
444 | }
|
---|
445 |
|
---|
446 | acumVerts += long(mSubMesh[i].mVertexBuffer->mVertexCount);
|
---|
447 |
|
---|
448 | // Copy strips.
|
---|
449 | int offset = 0;
|
---|
450 |
|
---|
451 | mesh->mSubMesh[i].mStripCount = mSubMesh[i].mStripCount;
|
---|
452 |
|
---|
453 | if (mSubMesh[i].mStripCount > 0)
|
---|
454 | {
|
---|
455 | mesh->mSubMesh[i].mStrip = new Index*[mSubMesh[i].mStripCount];
|
---|
456 |
|
---|
457 | offset = int(&(mesh->mSubMesh[i].mIndex[0]) - &(mSubMesh[i].mIndex[0]));
|
---|
458 |
|
---|
459 | for (size_t j = 0; j < mSubMesh[i].mStripCount; j++)
|
---|
460 | {
|
---|
461 | mesh->mSubMesh[i].mStrip[j] = mSubMesh[i].mStrip[j] + offset;
|
---|
462 | }
|
---|
463 | }
|
---|
464 | }
|
---|
465 |
|
---|
466 | mesh->mVertexBuffer->mVertexCount = acumVerts;
|
---|
467 | mesh->mVertexBuffer->mVertexInfo = mSubMesh[0].mVertexBuffer->mVertexInfo;
|
---|
468 |
|
---|
469 | mesh->mVertexBuffer->mPosition = new Vector3[mesh->mVertexBuffer->mVertexCount];
|
---|
470 | mesh->mVertexBuffer->mNormal = new Vector3[mesh->mVertexBuffer->mVertexCount];
|
---|
471 | mesh->mVertexBuffer->mTexCoords = new Vector2[mesh->mVertexBuffer->mVertexCount];
|
---|
472 |
|
---|
473 | acumVerts = 0;
|
---|
474 |
|
---|
475 | size_t newIndex;
|
---|
476 |
|
---|
477 | for (size_t i = 0; i < mSubMeshCount; i++)
|
---|
478 | {
|
---|
479 | for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++)
|
---|
480 | {
|
---|
481 | newIndex = acumVerts + j;
|
---|
482 |
|
---|
483 | mesh->mVertexBuffer->
|
---|
484 | mPosition[newIndex].x = mSubMesh[i].mVertexBuffer->
|
---|
485 | mPosition[j].x;
|
---|
486 |
|
---|
487 | mesh->mVertexBuffer->
|
---|
488 | mPosition[newIndex].y = mSubMesh[i].mVertexBuffer->
|
---|
489 | mPosition[j].y;
|
---|
490 |
|
---|
491 | mesh->mVertexBuffer->
|
---|
492 | mPosition[newIndex].z = mSubMesh[i].mVertexBuffer->
|
---|
493 | mPosition[j].z;
|
---|
494 |
|
---|
495 | mesh->mVertexBuffer->
|
---|
496 | mNormal[newIndex].x = mSubMesh[i].mVertexBuffer->
|
---|
497 | mNormal[j].x;
|
---|
498 |
|
---|
499 | mesh->mVertexBuffer->
|
---|
500 | mNormal[newIndex].y = mSubMesh[i].mVertexBuffer->
|
---|
501 | mNormal[j].y;
|
---|
502 |
|
---|
503 | mesh->mVertexBuffer->
|
---|
504 | mNormal[newIndex].z = mSubMesh[i].mVertexBuffer->
|
---|
505 | mNormal[j].z;
|
---|
506 |
|
---|
507 | mesh->mVertexBuffer->
|
---|
508 | mTexCoords[newIndex].x = mSubMesh[i].mVertexBuffer->
|
---|
509 | mTexCoords[j].x;
|
---|
510 |
|
---|
511 | mesh->mVertexBuffer->
|
---|
512 | mTexCoords[newIndex].y = mSubMesh[i].mVertexBuffer->
|
---|
513 | mTexCoords[j].y;
|
---|
514 | }
|
---|
515 |
|
---|
516 | // Shared bones.
|
---|
517 | if (!mSubMesh[i].mBones.empty())
|
---|
518 | {
|
---|
519 | for (unsigned int j = 0; j < mSubMesh[i].mBones.size(); j++)
|
---|
520 | {
|
---|
521 | mesh->mBones.push_back(mSubMesh[i].mBones[j]);
|
---|
522 |
|
---|
523 | mesh->mBones.back().vertexIndex += acumVerts;
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 | acumVerts += long(mSubMesh[i].mVertexBuffer->mVertexCount);
|
---|
528 | }
|
---|
529 |
|
---|
530 | // Copy skeleton name.
|
---|
531 | if (hasSkeleton)
|
---|
532 | {
|
---|
533 | mesh->hasSkeleton = true;
|
---|
534 |
|
---|
535 | strcpy(mesh->mSkeletonName,mSkeletonName);
|
---|
536 | }
|
---|
537 |
|
---|
538 | /*
|
---|
539 | // Copy mesh bones.
|
---|
540 | if (!mBones.empty())
|
---|
541 | {
|
---|
542 | for (unsigned int j = 0; j < mBones.size(); j++)
|
---|
543 | {
|
---|
544 | mesh->mBones.push_back(mBones[j]);
|
---|
545 | }
|
---|
546 | }
|
---|
547 | */
|
---|
548 |
|
---|
549 | return mesh;
|
---|
550 | }
|
---|
551 |
|
---|