Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Model Class Reference

#include <model.h>

List of all members.

Public Member Functions

uint32 addMaterial (const Mesh::Material *)
uint32 addMesh (Mesh *)
const Mesh::MaterialgetMaterial (uint32) const
MeshgetMesh (uint32) const
 Model ()
void normalize (const Vec3f &centerOffset)
bool pick (const Ray3d &r, double &distance) const
void render (RenderContext &)
 Render the model in the current OpenGL context.
void sortMeshes (const MeshComparator &)
bool usesTextureType (Mesh::TextureSemantic) const
 ~Model ()

Private Attributes

std::vector< const Mesh::Material * > materials
std::vector< Mesh * > meshes
bool textureUsage [Mesh::TextureSemanticMax]

Classes

class  MeshComparator
class  OpacityComparator


Detailed Description

Model is the standard geometry object in Celestia. A Model consists of a library of materials together with a list of meshes. Each mesh object contains a pool of vertices and a set of primitive groups. A primitive groups consists of a a primitive group type and a list of vertex indices. This structure is exactly the one used in Celestia model (.cmod) files.

Definition at line 24 of file model.h.


Constructor & Destructor Documentation

Model::Model  ) 
 

Definition at line 41 of file model.cpp.

References textureUsage.

00042 {
00043     for (int i = 0; i < Mesh::TextureSemanticMax; i++)
00044         textureUsage[i] = false;
00045 }

Model::~Model  ) 
 

Definition at line 48 of file model.cpp.

References materials, and meshes.

00049 {
00050     {
00051         for (vector<Mesh*>::iterator iter = meshes.begin();
00052              iter != meshes.end(); iter++)
00053             delete *iter;
00054     }
00055 
00056 #if 0
00057     {
00058         for (vector<const Mesh::Material*>::iterator iter = materials.begin();
00059              iter != materials.end(); iter++)
00060             delete *iter;
00061     }
00062 #endif
00063 }


Member Function Documentation

uint32 Model::addMaterial const Mesh::Material  ) 
 

Add a new material to the model's material library; the return value is the number of materials in the model.

Definition at line 77 of file model.cpp.

References InvalidResource, materials, and textureUsage.

Referenced by Convert3DSModel(), BinaryModelLoader::load(), AsciiModelLoader::load(), main(), and mergeModelMeshes().

00078 {
00079     // Update the texture map usage information for the model.  Since
00080     // the material being added isn't necessarily used by a mesh within
00081     // the model, we could potentially end up with false positives--this
00082     // won't cause any rendering troubles, but could hurt performance
00083     // if it forces multipass rendering when it's not required.
00084     for (int i = 0; i < Mesh::TextureSemanticMax; i++)
00085     {
00086         if (m->maps[i] != InvalidResource)
00087             textureUsage[i] = true;
00088     }
00089 
00090     materials.push_back(m);
00091     return materials.size();
00092 }

uint32 Model::addMesh Mesh  ) 
 

Add a new mesh to the model; the return value is the total number of meshes in the model.

Definition at line 106 of file model.cpp.

References meshes.

Referenced by Convert3DSModel(), BinaryModelLoader::load(), AsciiModelLoader::load(), LoadCelestiaMesh(), main(), and mergeModelMeshes().

00107 {
00108     meshes.push_back(m);
00109     return meshes.size();
00110 }

const Mesh::Material * Model::getMaterial uint32   )  const
 

Return the material with the specified index, or NULL if the index is out of range.

Definition at line 67 of file model.cpp.

References materials.

Referenced by Model::OpacityComparator::getOpacity(), and main().

00068 {
00069     if (index < materials.size())
00070         return materials[index];
00071     else
00072         return NULL;
00073 }

Mesh * Model::getMesh uint32   )  const
 

Return the mesh with the specified index, or NULL if the index is out of range.

Definition at line 96 of file model.cpp.

References meshes.

Referenced by main().

00097 {
00098     if (index < meshes.size())
00099         return meshes[index];
00100     else
00101         return NULL;
00102 }

void Model::normalize const Vec3f centerOffset  ) 
 

Apply a uniform scale to the model so that it fits into a box with a center at centerOffset and a maximum side length of one.

Definition at line 151 of file model.cpp.

References AxisAlignedBox::getCenter(), AxisAlignedBox::getExtents(), AxisAlignedBox::include(), meshes, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by ModelInfo::load().

00152 {
00153     AxisAlignedBox bbox;
00154 
00155     vector<Mesh*>::const_iterator iter;
00156     for (iter = meshes.begin(); iter != meshes.end(); iter++)
00157         bbox.include((*iter)->getBoundingBox());
00158 
00159     Point3f center = bbox.getCenter() + centerOffset;
00160     Vec3f extents = bbox.getExtents();
00161     float maxExtent = extents.x;
00162     if (extents.y > maxExtent)
00163         maxExtent = extents.y;
00164     if (extents.z > maxExtent)
00165         maxExtent = extents.z;
00166 
00167     for (iter = meshes.begin(); iter != meshes.end(); iter++)
00168         (*iter)->transform(Point3f(0, 0, 0) - center, 2.0f / maxExtent);
00169 
00170 #if 0
00171     for (i = vertexLists.begin(); i != vertexLists.end(); i++)
00172         (*i)->transform(Point3f(0, 0, 0) - center, 2.0f / maxExtent);
00173 #endif
00174 }

bool Model::pick const Ray3d r,
double &  distance
const
 

Find the closest intersection between the ray and the model. If the ray intersects the model, return true and set distance; otherwise return false and leave distance unmodified.

Definition at line 114 of file model.cpp.

References distance(), and meshes.

Referenced by Body::computeLocations(), and ExactPlanetPickTraversal().

00115 {
00116     double maxDistance = 1.0e30;
00117     double closest = maxDistance;
00118 
00119     for (vector<Mesh*>::const_iterator iter = meshes.begin();
00120          iter != meshes.end(); iter++)
00121     {
00122         double d = maxDistance;
00123         if ((*iter)->pick(r, d) && d < closest)
00124             closest = d;
00125     }    
00126 
00127     if (closest != maxDistance)
00128     {
00129         distance = closest;
00130         return true;
00131     }
00132     else
00133     {
00134         return false;
00135     }
00136 }

void Model::render RenderContext  ) 
 

Render the model in the current OpenGL context.

Definition at line 140 of file model.cpp.

References materials, meshes, and Mesh::render().

Referenced by Nebula::render().

00141 {
00142     for (vector<Mesh*>::const_iterator iter = meshes.begin();
00143          iter != meshes.end(); iter++)
00144     {
00145         (*iter)->render(materials, rc);
00146     }
00147 }

void Model::sortMeshes const MeshComparator  ) 
 

Sort the model's meshes in place.

Definition at line 235 of file model.cpp.

References meshes.

Referenced by ModelInfo::load().

00236 {
00237     sort(meshes.begin(), meshes.end(), MeshComparatorAdapter(comparator));
00238 }

bool Model::usesTextureType Mesh::TextureSemantic   )  const
 

Return true if the specified texture map type is used at all within a mesh. This information is used to decide if multiple rendering passes are required.

Definition at line 178 of file model.cpp.

References textureUsage.

00179 {
00180     return textureUsage[static_cast<int>(t)];
00181 }


Member Data Documentation

std::vector<const Mesh::Material*> Model::materials [private]
 

Definition at line 104 of file model.h.

Referenced by addMaterial(), getMaterial(), render(), and ~Model().

std::vector<Mesh*> Model::meshes [private]
 

Definition at line 105 of file model.h.

Referenced by addMesh(), getMesh(), normalize(), pick(), render(), sortMeshes(), and ~Model().

bool Model::textureUsage[Mesh::TextureSemanticMax] [private]
 

Definition at line 107 of file model.h.

Referenced by addMaterial(), Model(), and usesTextureType().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:28 2006 for Celestia by  doxygen 1.4.1