#include <mesh.h>
Inheritance diagram for Mesh:


|
|
Definition at line 128 of file mesh.h. 00129 {
00130 TriList = 0,
00131 TriStrip = 1,
00132 TriFan = 2,
00133 LineList = 3,
00134 LineStrip = 4,
00135 PointList = 5,
00136 PrimitiveTypeMax = 6,
00137 InvalidPrimitiveGroupType = -1
00138 };
|
|
|
Definition at line 105 of file mesh.h. 00106 {
00107 DiffuseMap = 0,
00108 NormalMap = 1,
00109 SpecularMap = 2,
00110 EmissiveMap = 3,
00111 TextureSemanticMax = 4,
00112 InvalidTextureSemantic = -1,
00113 };
|
|
|
Definition at line 42 of file mesh.h. 00043 {
00044 Float1 = 0,
00045 Float2 = 1,
00046 Float3 = 2,
00047 Float4 = 3,
00048 UByte4 = 4,
00049 FormatMax = 5,
00050 InvalidFormat = -1,
00051 };
|
|
|
Definition at line 27 of file mesh.h. 00028 {
00029 Position = 0,
00030 Color0 = 1,
00031 Color1 = 2,
00032 Normal = 3,
00033 Tangent = 4,
00034 Texture0 = 5,
00035 Texture1 = 6,
00036 Texture2 = 7,
00037 Texture3 = 8,
00038 SemanticMax = 9,
00039 InvalidSemantic = -1,
00040 };
|
|
|
Definition at line 173 of file mesh.cpp. References nVertices, vbInitialized, vbObject, vertexDesc, and vertices. 00173 : 00174 vertexDesc(0, 0, NULL), 00175 nVertices(0), 00176 vertices(NULL), 00177 vbObject(0), 00178 vbInitialized(false) 00179 { 00180 }
|
|
|
Definition at line 183 of file mesh.cpp. References glx::glDeleteBuffersARB, groups, vbObject, and vertices. 00184 {
00185 for (vector<PrimitiveGroup*>::iterator iter = groups.begin();
00186 iter != groups.end(); iter++)
00187 {
00188 delete *iter;
00189 }
00190
00191 if (vertices != NULL)
00192 delete vertices;
00193
00194 if (vbObject != 0)
00195 {
00196 glx::glDeleteBuffersARB(1, &vbObject);
00197 }
00198 }
|
|
||||||||||||||||||||
|
Definition at line 246 of file mesh.cpp. References addGroup(), Mesh::PrimitiveGroup::indices, Mesh::PrimitiveGroup::materialIndex, Mesh::PrimitiveGroup::nIndices, and Mesh::PrimitiveGroup::prim. 00250 {
00251 PrimitiveGroup* g = new PrimitiveGroup();
00252 g->prim = prim;
00253 g->materialIndex = materialIndex;
00254 g->nIndices = nIndices;
00255 g->indices = indices;
00256
00257 return addGroup(g);
00258 }
|
|
|
Definition at line 238 of file mesh.cpp. References groups. Referenced by addGroup(), addGroupWithOffset(), Convert3DSMesh(), SphereMesh::convertToMesh(), ConvertVertexListToMesh(), generateNormals(), generateTangents(), BinaryModelLoader::loadMesh(), and AsciiModelLoader::loadMesh().
|
|
|
Definition at line 262 of file mesh.cpp. References groups. 00263 {
00264 for (vector<PrimitiveGroup*>::iterator iter = groups.begin();
00265 iter != groups.end(); iter++)
00266 {
00267 delete *iter;
00268 }
00269
00270 groups.clear();
00271 }
|
|
|
Definition at line 495 of file mesh.cpp. References Float3, Mesh::VertexAttribute::format, Mesh::VertexDescription::getAttribute(), AxisAlignedBox::include(), nVertices, Mesh::VertexAttribute::offset, Position, Mesh::VertexDescription::stride, vertexDesc, and vertices. 00496 {
00497 AxisAlignedBox bbox;
00498
00499 // Return an empty box if there's no position info
00500 if (vertexDesc.getAttribute(Position).format != Float3)
00501 return bbox;
00502
00503 char* vdata = reinterpret_cast<char*>(vertices) + vertexDesc.getAttribute(Position).offset;
00504
00505 for (uint32 i = 0; i < nVertices; i++, vdata += vertexDesc.stride)
00506 bbox.include(Point3f(reinterpret_cast<float*>(vdata)));
00507
00508 return bbox;
00509 }
|
|
|
Definition at line 228 of file mesh.cpp. References groups. Referenced by generateNormals(), generateTangents(), main(), and mergeModelMeshes(). 00229 {
00230 if (index >= groups.size())
00231 return NULL;
00232 else
00233 return groups[index];
00234 }
|
|
|
Definition at line 275 of file mesh.cpp. References name. 00276 {
00277 return name;
00278 }
|
|
|
Definition at line 610 of file mesh.cpp. References Float1, Float2, Float3, Float4, and UByte4. Referenced by augmentVertexDescription(), BinaryModelLoader::loadVertexDescription(), AsciiModelLoader::loadVertexDescription(), and AsciiModelLoader::loadVertices(). 00611 {
00612 switch (fmt)
00613 {
00614 case Float1:
00615 case UByte4:
00616 return 4;
00617 case Float2:
00618 return 8;
00619 case Float3:
00620 return 12;
00621 case Float4:
00622 return 16;
00623 default:
00624 return 0;
00625 }
00626 }
|
|
|
Definition at line 179 of file mesh.h. References nVertices. Referenced by generateNormals(), generateTangents(), and mergeModelMeshes(). 00179 { return nVertices; }
|
|
|
Definition at line 178 of file mesh.h. References vertices. Referenced by mergeModelMeshes(). 00178 { return vertices; }
|
|
|
Definition at line 221 of file mesh.cpp. References vertexDesc. Referenced by generateNormals(), and generateTangents(). 00222 {
00223 return vertexDesc;
00224 }
|
|
|
Definition at line 180 of file mesh.h. References Mesh::VertexDescription::stride, and vertexDesc. 00180 { return vertexDesc.stride; }
|
|
|
Definition at line 530 of file mesh.cpp. References InvalidPrimitiveGroupType, LineList, LineStrip, name, PointList, TriFan, TriList, and TriStrip. Referenced by AsciiModelLoader::loadMesh(). 00531 {
00532 if (name == "trilist")
00533 return TriList;
00534 else if (name == "tristrip")
00535 return TriStrip;
00536 else if (name == "trifan")
00537 return TriFan;
00538 else if (name == "linelist")
00539 return LineList;
00540 else if (name == "linestrip")
00541 return LineStrip;
00542 else if (name == "points")
00543 return PointList;
00544 else
00545 return InvalidPrimitiveGroupType;
00546 }
|
|
|
Definition at line 594 of file mesh.cpp. References DiffuseMap, EmissiveMap, InvalidTextureSemantic, name, NormalMap, and SpecularMap. Referenced by AsciiModelLoader::loadMaterial(). 00595 {
00596 if (name == "texture0")
00597 return DiffuseMap;
00598 else if (name == "normalmap")
00599 return NormalMap;
00600 else if (name == "specularmap")
00601 return SpecularMap;
00602 else if (name == "emissivemap")
00603 return EmissiveMap;
00604 else
00605 return InvalidTextureSemantic;
00606 }
|
|
|
Definition at line 576 of file mesh.cpp. References Float1, Float2, Float3, Float4, InvalidFormat, name, and UByte4. Referenced by AsciiModelLoader::loadVertexDescription(). 00577 {
00578 if (name == "f1")
00579 return Float1;
00580 else if (name == "f2")
00581 return Float2;
00582 else if (name == "f3")
00583 return Float3;
00584 else if (name == "f4")
00585 return Float4;
00586 else if (name == "ub4")
00587 return UByte4;
00588 else
00589 return InvalidFormat;
00590 }
|
|
|
Definition at line 550 of file mesh.cpp. References Color0, Color1, InvalidSemantic, name, Normal, Position, Tangent, Texture0, Texture1, Texture2, and Texture3. Referenced by AsciiModelLoader::loadVertexDescription(). 00551 {
00552 if (name == "position")
00553 return Position;
00554 else if (name == "normal")
00555 return Normal;
00556 else if (name == "color0")
00557 return Color0;
00558 else if (name == "color1")
00559 return Color1;
00560 else if (name == "tangent")
00561 return Tangent;
00562 else if (name == "texcoord0")
00563 return Texture0;
00564 else if (name == "texcoord1")
00565 return Texture1;
00566 else if (name == "texcoord2")
00567 return Texture2;
00568 else if (name == "texcoord3")
00569 return Texture3;
00570 else
00571 return InvalidSemantic;
00572 }
|
|
||||||||||||
|
Definition at line 304 of file mesh.cpp. References distance(), Float3, Mesh::VertexAttribute::format, Mesh::VertexDescription::getAttribute(), groups, Mesh::VertexAttribute::offset, Position, Mesh::VertexAttribute::semantic, Mesh::VertexDescription::stride, TriFan, TriList, TriStrip, vertexDesc, and vertices. 00305 {
00306 double maxDistance = 1.0e30;
00307 double closest = maxDistance;
00308
00309 // Pick will automatically fail without vertex positions--no reasonable
00310 // mesh should lack these.
00311 if (vertexDesc.getAttribute(Position).semantic != Position ||
00312 vertexDesc.getAttribute(Position).format != Float3)
00313 {
00314 return false;
00315 }
00316
00317 uint posOffset = vertexDesc.getAttribute(Position).offset;
00318 char* vdata = reinterpret_cast<char*>(vertices);
00319
00320 // Iterate over all primitive groups in the mesh
00321 for (vector<PrimitiveGroup*>::const_iterator iter = groups.begin();
00322 iter != groups.end(); iter++)
00323 {
00324 Mesh::PrimitiveGroupType primType = (*iter)->prim;
00325 uint32 nIndices = (*iter)->nIndices;
00326
00327 // Only attempt to compute the intersection of the ray with triangl
00328 // groups.
00329 if ((primType == TriList || primType == TriStrip || primType == TriFan) &&
00330 (nIndices >= 3) &&
00331 !(primType == TriList && nIndices % 3 != 0))
00332 {
00333 uint32 index = 0;
00334 uint32 i0 = (*iter)->indices[0];
00335 uint32 i1 = (*iter)->indices[1];
00336 uint32 i2 = (*iter)->indices[2];
00337
00338 // Iterate over the triangles in the primitive group
00339 do
00340 {
00341 // Get the triangle vertices v0, v1, and v2
00342 float* f0 = reinterpret_cast<float*>(vdata + i0 * vertexDesc.stride + posOffset);
00343 float* f1 = reinterpret_cast<float*>(vdata + i1 * vertexDesc.stride + posOffset);
00344 float* f2 = reinterpret_cast<float*>(vdata + i2 * vertexDesc.stride + posOffset);
00345 Point3d v0(f0[0], f0[1], f0[2]);
00346 Point3d v1(f1[0], f1[1], f1[2]);
00347 Point3d v2(f2[0], f2[1], f2[2]);
00348
00349 // Compute the edge vectors e0 and e1, and the normal n
00350 Vec3d e0 = v1 - v0;
00351 Vec3d e1 = v2 - v0;
00352 Vec3d n = e0 ^ e1;
00353
00354 // c is the cosine of the angle between the ray and triangle normal
00355 double c = n * ray.direction;
00356
00357 // If the ray is parallel to the triangle, it either misses the
00358 // triangle completely, or is contained in the triangle's plane.
00359 // If it's contained in the plane, we'll still call it a miss.
00360 if (c != 0.0)
00361 {
00362 double t = (n * (v0 - ray.origin)) / c;
00363 if (t < closest && t > 0.0)
00364 {
00365 double m00 = e0 * e0;
00366 double m01 = e0 * e1;
00367 double m10 = e1 * e0;
00368 double m11 = e1 * e1;
00369 double det = m00 * m11 - m01 * m10;
00370 if (det != 0.0)
00371 {
00372 Point3d p = ray.point(t);
00373 Vec3d q = p - v0;
00374 double q0 = e0 * q;
00375 double q1 = e1 * q;
00376 double d = 1.0 / det;
00377 double s0 = (m11 * q0 - m01 * q1) * d;
00378 double s1 = (m00 * q1 - m10 * q0) * d;
00379 if (s0 >= 0.0 && s1 >= 0.0 && s0 + s1 <= 1.0)
00380 closest = t;
00381 }
00382 }
00383 }
00384
00385 // Get the indices for the next triangle
00386 if (primType == TriList)
00387 {
00388 index += 3;
00389 if (index < nIndices)
00390 {
00391 i0 = (*iter)->indices[index + 0];
00392 i1 = (*iter)->indices[index + 1];
00393 i2 = (*iter)->indices[index + 2];
00394 }
00395 }
00396 else if (primType == TriStrip)
00397 {
00398 index += 1;
00399 if (index < nIndices)
00400 {
00401 i0 = i1;
00402 i1 = i2;
00403 i2 = (*iter)->indices[index];
00404 // TODO: alternate orientation of triangles in a strip
00405 }
00406 }
00407 else // primType == TriFan
00408 {
00409 index += 1;
00410 if (index < nIndices)
00411 {
00412 index += 1;
00413 i1 = i2;
00414 i2 = (*iter)->indices[index];
00415 }
00416 }
00417
00418 } while (index < nIndices);
00419 }
00420 }
00421
00422 if (closest != maxDistance)
00423 {
00424 distance = closest;
00425 return true;
00426 }
00427 else
00428 {
00429 return false;
00430 }
00431 }
|
|
|
|
|
|
Definition at line 289 of file mesh.cpp. References groups, and Mesh::PrimitiveGroup::indices. 00290 {
00291 for (vector<PrimitiveGroup*>::iterator iter = groups.begin();
00292 iter != groups.end(); iter++)
00293 {
00294 PrimitiveGroup* group = *iter;
00295 for (uint32 i = 0; i < group->nIndices; i++)
00296 {
00297 group->indices[i] = indexMap[group->indices[i]];
00298 }
00299 }
00300 }
|
|
||||||||||||
|
Definition at line 435 of file mesh.cpp. References GL_ARRAY_BUFFER_ARB, GL_STATIC_DRAW_ARB, glx::glBindBufferARB, glx::glBufferDataARB, glx::glGenBuffersARB, groups, isVBOSupported(), MinVBOSize, nVertices, Mesh::VertexDescription::stride, vbInitialized, vbObject, vertexDesc, and vertices. Referenced by Model::render(). 00437 {
00438 // The first time the mesh is rendered, we will try and place the
00439 // vertex data in a vertex buffer object and potentially get a huge
00440 // rendering performance boost. This can consume a great deal of
00441 // memory, since we're duplicating the vertex data. TODO: investigate
00442 // the possibility of deleting the original data. We can always map
00443 // read-only later on for things like picking, but this could be a low
00444 // performance path.
00445 if (!vbInitialized && isVBOSupported())
00446 {
00447 vbInitialized = true;
00448
00449 if (nVertices * vertexDesc.stride > MinVBOSize)
00450 {
00451 glx::glGenBuffersARB(1, &vbObject);
00452 if (vbObject != 0)
00453 {
00454 glx::glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbObject);
00455 glx::glBufferDataARB(GL_ARRAY_BUFFER_ARB,
00456 nVertices * vertexDesc.stride,
00457 vertices,
00458 GL_STATIC_DRAW_ARB);
00459 }
00460 }
00461 }
00462
00463 if (vbObject != 0)
00464 {
00465 glx::glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbObject);
00466 rc.setVertexArrays(vertexDesc, NULL);
00467 }
00468 else
00469 {
00470 rc.setVertexArrays(vertexDesc, vertices);
00471 }
00472
00473 uint32 lastMaterial = ~0;
00474
00475 // Iterate over all primitive groups in the mesh
00476 for (vector<PrimitiveGroup*>::const_iterator iter = groups.begin();
00477 iter != groups.end(); iter++)
00478 {
00479 // Set up the material
00480 const Material* mat = NULL;
00481 uint32 materialIndex = (*iter)->materialIndex;
00482 if (materialIndex != lastMaterial && materialIndex < materials.size())
00483 mat = materials[materialIndex];
00484
00485 rc.setMaterial(mat);
00486 rc.drawGroup(**iter);
00487 }
00488
00489 if (vbObject != 0)
00490 glx::glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
00491 }
|
|
|
Definition at line 282 of file mesh.cpp. References name. Referenced by Convert3DSMesh(). 00283 {
00284 name = _name;
00285 }
|
|
|
Definition at line 210 of file mesh.cpp. References vertexDesc. Referenced by Convert3DSMesh(), SphereMesh::convertToMesh(), ConvertVertexListToMesh(), generateNormals(), generateTangents(), BinaryModelLoader::loadMesh(), AsciiModelLoader::loadMesh(), and mergeModelMeshes(). 00211 {
00212 if (!desc.validate())
00213 return false;
00214
00215 vertexDesc = desc;
00216
00217 return true;
00218 }
|
|
||||||||||||
|
Definition at line 202 of file mesh.cpp. References nVertices, and vertices. Referenced by Convert3DSMesh(), SphereMesh::convertToMesh(), ConvertVertexListToMesh(), generateNormals(), generateTangents(), BinaryModelLoader::loadMesh(), AsciiModelLoader::loadMesh(), and mergeModelMeshes().
|
|
||||||||||||
|
Definition at line 513 of file mesh.cpp. References Float3, Mesh::VertexAttribute::format, Mesh::VertexDescription::getAttribute(), nVertices, Mesh::VertexAttribute::offset, Position, Mesh::VertexDescription::stride, vertexDesc, vertices, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. 00514 {
00515 if (vertexDesc.getAttribute(Position).format != Float3)
00516 return;
00517
00518 char* vdata = reinterpret_cast<char*>(vertices) + vertexDesc.getAttribute(Position).offset;
00519 for (uint32 i = 0; i < nVertices; i++, vdata += vertexDesc.stride)
00520 {
00521 Vec3f tv = (Vec3f(reinterpret_cast<float*>(vdata)) + translation) * scale;
00522 reinterpret_cast<float*>(vdata)[0] = tv.x;
00523 reinterpret_cast<float*>(vdata)[1] = tv.y;
00524 reinterpret_cast<float*>(vdata)[2] = tv.z;
00525 }
00526 }
|
|
|
Definition at line 199 of file mesh.h. Referenced by addGroup(), clearGroups(), getGroup(), pick(), remapIndices(), render(), and ~Mesh(). |
|
|
Definition at line 201 of file mesh.h. Referenced by getName(), parsePrimitiveGroupType(), parseTextureSemantic(), parseVertexAttributeFormat(), parseVertexAttributeSemantic(), and setName(). |
|
|
Definition at line 194 of file mesh.h. Referenced by getBoundingBox(), getVertexCount(), Mesh(), render(), setVertices(), and transform(). |
|
|
|
|
|
|
|
|
Definition at line 192 of file mesh.h. Referenced by getBoundingBox(), getVertexDescription(), getVertexStride(), Mesh(), pick(), render(), setVertexDescription(), and transform(). |
|
|
Definition at line 195 of file mesh.h. Referenced by getBoundingBox(), getVertexData(), Mesh(), pick(), render(), setVertices(), transform(), and ~Mesh(). |
1.4.1