Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9829 in orxonox.OLD for branches/new_class_id


Ignore:
Timestamp:
Sep 26, 2006, 1:09:35 PM (18 years ago)
Author:
bensch
Message:

new static_model_data added

Location:
branches/new_class_id/src/lib/graphics/importer
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/importer/Makefile.am

    r9824 r9829  
    1111                grid.cc \
    1212                static_model.cc \
     13                static_model_data.cc \
    1314                objModel.cc \
    1415                primitive_model.cc \
     
    5758                grid.h \
    5859                static_model.h \
     60                static_model_data.h \
    5961                objModel.h \
    6062                primitive_model.h \
  • branches/new_class_id/src/lib/graphics/importer/static_model_data.cc

    r9827 r9829  
    1818#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
    1919
    20 #include "static_model.h"
     20#include "static_model_data.h"
    2121
    2222#include "debug.h"
     
    134134/// MODEL ///
    135135/////////////
    136 ObjectListDefinition(StaticModel);
     136ObjectListDefinition(StaticModelData);
    137137
    138138/**
     
    141141 * assigns it a Name and a Type
    142142 */
    143 StaticModel::StaticModel(const std::string& modelName)
    144 {
    145   this->registerObject(this, StaticModel::_objectList);
     143StaticModelData::StaticModelData(const std::string& modelName)
     144{
     145  this->registerObject(this, StaticModelData::_objectList);
    146146  PRINTF(4)("new 3D-Model is being created\n");
    147147  this->setName(modelName);
     
    162162 * Looks if any from model allocated space is still in use, and if so deleted it.
    163163 */
    164 StaticModel::~StaticModel()
     164StaticModelData::~StaticModelData()
    165165{
    166166  PRINTF(4)("Deleting Model ");
     
    189189    delete (*modMat);
    190190  }
    191 
    192   // mark this stuff as beeing deleted
    193   this->pModelInfo.pVertices = NULL;
    194   this->pModelInfo.pNormals = NULL;
    195   this->pModelInfo.pTexCoor = NULL;
    196191}
    197192
     
    199194 * @brief Finalizes an Object. This can be done outside of the Class.
    200195 */
    201 void StaticModel::finalize()
     196void StaticModelData::finalize()
    202197{
    203198  // this creates the display List.
     
    205200  this->buildTriangleList();
    206201
    207   // write out the modelInfo data used for the collision detection!
    208   this->pModelInfo.pVertices = &this->vertices[0];
    209   this->pModelInfo.pNormals = &this->normals[0];
    210   this->pModelInfo.pTexCoor = &this->vTexture[0];
    211 
    212202  this->finalized = true;
    213203}
     
    216206 * @brief rebuild the Model from the Information we got.
    217207 */
    218 void StaticModel::rebuild()
     208void StaticModelData::rebuild()
    219209{
    220210  PRINTF(3)("Rebuilding Model '%s'\n", this->getCName());
     
    230220 * It does this by just calling the Lists that must have been created earlier.
    231221 */
    232 void StaticModel::draw () const
     222void StaticModelData::draw () const
    233223{
    234224  PRINTF(4)("drawing the 3D-Models\n");
     
    249239 * It does this by just calling the List that must have been created earlier.
    250240 */
    251 void StaticModel::draw (int groupNumber) const
     241void StaticModelData::draw (int groupNumber) const
    252242{
    253243  if (unlikely(groupNumber >= this->groupCount))
     
    281271 * It does this by just calling the List that must have been created earlier.
    282272 */
    283 void StaticModel::draw (const std::string& groupName) const
     273void StaticModelData::draw (const std::string& groupName) const
    284274{
    285275  PRINTF(4)("drawing the requested 3D-Models if found.\n");
     
    310300 * This will be applied at the end of the importing Process.
    311301*/
    312 bool StaticModel::cleanup()
     302bool StaticModelData::cleanup()
    313303{
    314304  PRINTF(4)("cleaning up the 3D-Model to save Memory.\n");
     
    328318 * with this option set the Materials will not be deleted with the Model.
    329319 */
    330 Material* StaticModel::addMaterial(Material* material)
     320Material* StaticModelData::addMaterial(Material* material)
    331321{
    332322  if (material == NULL)
     
    344334 * @returns the added material
    345335 */
    346 Material* StaticModel::addMaterial(const std::string& materialName)
     336Material* StaticModelData::addMaterial(const std::string& materialName)
    347337{
    348338  ModelMaterial* modMat = new ModelMaterial;
     
    360350 * @returns the Material if found, NULL otherwise
    361351 */
    362 Material* StaticModel::findMaterialByName(const std::string& materialName)
     352Material* StaticModelData::findMaterialByName(const std::string& materialName)
    363353{
    364354  std::list<ModelMaterial*>::iterator modMat;
     
    376366 * With it you should be able to create Models with more than one SubModel inside
    377367 */
    378 bool StaticModel::addGroup(const std::string& groupString)
     368bool StaticModelData::addGroup(const std::string& groupString)
    379369{
    380370  PRINTF(5)("Read Group: %s.\n", groupString.c_str());
     
    399389 *  If a vertex line is found this function will inject it into the vertex-Array
    400390 */
    401 bool StaticModel::addVertex (const std::string& vertexString)
     391bool StaticModelData::addVertex (const std::string& vertexString)
    402392{
    403393  float subbuffer1;
     
    408398  this->vertices.push_back(subbuffer2*scaleFactor);
    409399  this->vertices.push_back(subbuffer3*scaleFactor);
    410   this->pModelInfo.numVertices++;
    411400  return true;
    412401}
     
    418407 * @param z the Z-coordinate of the Vertex to add.
    419408 */
    420 bool StaticModel::addVertex(float x, float y, float z)
     409bool StaticModelData::addVertex(float x, float y, float z)
    421410{
    422411  PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
     
    424413  this->vertices.push_back(y*scaleFactor);
    425414  this->vertices.push_back(z*scaleFactor);
    426   this->pModelInfo.numVertices++;
    427415  return true;
    428416}
     
    434422 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    435423 */
    436 bool StaticModel::addVertexNormal (const std::string& normalString)
     424bool StaticModelData::addVertexNormal (const std::string& normalString)
    437425{
    438426  float subbuffer1;
     
    443431  this->normals.push_back(subbuffer2);
    444432  this->normals.push_back(subbuffer3);
    445   this->pModelInfo.numNormals++;
    446433  return true;
    447434}
     
    455442 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    456443 */
    457 bool StaticModel::addVertexNormal(float x, float y, float z)
     444bool StaticModelData::addVertexNormal(float x, float y, float z)
    458445{
    459446  PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
     
    461448  this->normals.push_back(y);
    462449  this->normals.push_back(z);
    463   this->pModelInfo.numNormals++;
    464450  return true;
    465451}
     
    474460 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
    475461 */
    476 bool StaticModel::addVertexTexture (const std::string& vTextureString)
     462bool StaticModelData::addVertexTexture (const std::string& vTextureString)
    477463{
    478464  float subbuffer1;
     
    481467  this->vTexture.push_back(subbuffer1);
    482468  this->vTexture.push_back(1 - subbuffer2);
    483   this->pModelInfo.numTexCoor++;
    484469  return true;
    485470}
     
    493478 *  inject it into the TextureCoordinate-Array
    494479 */
    495 bool StaticModel::addVertexTexture(float u, float v)
     480bool StaticModelData::addVertexTexture(float u, float v)
    496481{
    497482  PRINTF(5)("found vertex-Texture %f, %f\n", u, v);
    498483  this->vTexture.push_back(u);
    499484  this->vTexture.push_back(v);
    500   this->pModelInfo.numTexCoor++;
    501485  return true;
    502486}
     
    513497 * @TODO make it std::string conform
    514498 */
    515 bool StaticModel::addFace (const std::string& faceStringInput)
     499bool StaticModelData::addFace (const std::string& faceStringInput)
    516500{
    517501  const char* faceString = faceStringInput.c_str();
     
    571555 * @param type The information Passed with each Vertex
    572556*/
    573 bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
     557bool StaticModelData::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
    574558{
    575559  if (this->currentGroup->faceCount > 0)
     
    604588 * @param matString the Material that will be set.
    605589*/
    606 bool StaticModel::setMaterial(const std::string& matString)
     590bool StaticModelData::setMaterial(const std::string& matString)
    607591{
    608592  if (this->currentGroup->faceCount > 0)
     
    620604 * @param mtl the Material that will be set.
    621605*/
    622 bool StaticModel::setMaterial(Material* mtl)
     606bool StaticModelData::setMaterial(Material* mtl)
    623607{
    624608  if (this->currentGroup->faceCount > 0)
     
    641625 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
    642626 */
    643 bool StaticModel::buildVertexNormals ()
     627bool StaticModelData::buildVertexNormals ()
    644628{
    645629  PRINTF(4)("Normals are being calculated.\n");
     
    721705 *  reads and includes the Faces/Materials into the openGL state Machine
    722706*/
    723 bool StaticModel::importToDisplayList()
     707bool StaticModelData::importToDisplayList()
    724708{
    725709  // finalize the Arrays
     
    811795 *  builds an array of triangles, that can later on be used for obb separation and octree separation
    812796 */
    813 bool StaticModel::buildTriangleList()
    814 {
    815   if( unlikely(this->pModelInfo.pTriangles != NULL))
     797bool StaticModelData::buildTriangleList()
     798{
     799  if( unlikely(!this->triangles.empty()))
    816800    return true;
    817801  /* make sure, that all the arrays are finalized */
     
    823807  ModelFace*         tmpFace;              //!< the temporary face referece
    824808
     809  unsigned int numTriangles = 0;
    825810  bool warned = false;
    826 
    827   this->pModelInfo.numTriangles = 0;
    828811
    829812  /* count the number of triangles */
     
    836819    {
    837820      /* if its a triangle just add it to the list */
    838       if( tmpFace->vertexCount == 3){
    839         ++this->pModelInfo.numTriangles;
     821      if( tmpFace->vertexCount == 3)
     822      {
     823        ++numTriangles;
    840824      } /* if the polygon is a quad */
    841       else if( tmpFace->vertexCount == 4) {
    842         this->pModelInfo.numTriangles += 2;
     825      else if( tmpFace->vertexCount == 4)
     826      {
     827        numTriangles += 2;
    843828      }
    844       else if( tmpFace->vertexCount > 4) {
    845         if (!warned)        {
     829      else if( tmpFace->vertexCount > 4)
     830      {
     831        if (!warned)
     832        {
    846833          PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName());
    847834          warned = true;
     
    853840  }
    854841
    855   PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);
     842  PRINTF(3)("got %i triangles, %i vertices\n", numTriangles, this->vertices.size());
    856843
    857844
     
    859846
    860847  /* allocate memory for the new triangle structures */
    861   if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)
    862   {
    863     PRINTF(1)("Could not allocate memory for triangle list\n");
    864     return false;
    865   }
     848  this->triangles.reserve(numTriangles);
    866849
    867850  /* now iterate through all groups and build up the triangle list */
     
    879862        for( int j = 0; j < 3; ++j)
    880863        {
    881           this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;
    882           this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;
    883           this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;
     864          this->triangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;
     865          this->triangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;
     866          this->triangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;
    884867          tmpElem = tmpElem->next;
    885868
     
    890873      {
    891874
    892         this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    893         this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    894         this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    895 
    896         this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
    897         this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
    898         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
     875        this->triangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     876        this->triangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     877        this->triangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
     878
     879        this->triangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     880        this->triangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     881        this->triangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    899882        tmpElem = tmpElem->next;
    900883
    901         this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    902         this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    903         this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
     884        this->triangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     885        this->triangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     886        this->triangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    904887        tmpElem = tmpElem->next;
    905888
    906         this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    907         this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    908         this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    909 
    910         this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
    911         this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
    912         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
     889        this->triangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     890        this->triangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     891        this->triangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
     892
     893        this->triangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     894        this->triangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     895        this->triangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    913896        tmpElem = tmpElem->next;
    914897
    915         this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
    916         this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
    917         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
     898        this->triangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     899        this->triangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     900        this->triangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    918901
    919902        index += 2;
     
    937920   merging this information, the face will be drawn.
    938921*/
    939 bool StaticModel::addGLElement (ModelFaceElement* elem)
     922bool StaticModelData::addGLElement (ModelFaceElement* elem)
    940923{
    941924  PRINTF(5)("importing grafical Element to openGL.\n");
     
    943926  if (elem->texCoordNumber > -1)
    944927  {
    945     if (likely((unsigned int)elem->texCoordNumber < this->pModelInfo.numTexCoor))
     928    if (likely((unsigned int)elem->texCoordNumber < this->vTexture.size()))
    946929      glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
    947930    else
    948931      PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
    949                 elem->texCoordNumber, this->pModelInfo.numTexCoor);
     932                elem->texCoordNumber, this->vTexture.size());
    950933  }
    951934  if (elem->normalNumber > -1)
    952935  {
    953     if (likely((unsigned int)elem->normalNumber < this->pModelInfo.numNormals))
     936    if (likely((unsigned int)elem->normalNumber < this->normals.size()))
    954937      glNormal3fv(&this->normals[0] + elem->normalNumber * 3);
    955938    else
    956939      PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
    957                 elem->normalNumber, this->pModelInfo.numNormals);
     940                elem->normalNumber, this->normals.size());
    958941  }
    959942  if (elem->vertexNumber > -1)
    960943  {
    961     if (likely((unsigned int)elem->vertexNumber < this->pModelInfo.numVertices))
     944    if (likely((unsigned int)elem->vertexNumber < this->vertices.size()))
    962945      glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
    963946    else
    964947      PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
    965                 elem->vertexNumber, this->pModelInfo.numVertices);
     948                elem->vertexNumber, this->vertices.size());
    966949  }
    967950
     
    974957   This will inject a Cube, because this is the most basic model.
    975958*/
    976 void StaticModel::cubeModel()
     959void StaticModelData::cubeModel()
    977960{
    978961  this->addVertex (-0.5, -0.5, 0.5);
  • branches/new_class_id/src/lib/graphics/importer/static_model_data.h

    r9827 r9829  
    9090 * All the objects are rendered with glLists
    9191 */
    92 class StaticModel : public Model
     92class StaticModelData : public BaseObject
    9393{
    94   ObjectListDeclaration(StaticModel);
     94  ObjectListDeclaration(StaticModelData);
    9595  public:
    96   StaticModel(const std::string& modelName = "");
    97   virtual ~StaticModel();
     96  StaticModelData(const std::string& modelName = "");
     97  virtual ~StaticModelData();
    9898
    9999  virtual void draw() const;
     
    153153  std::vector<GLfloat>       vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    154154
     155  std::vector<sTriangleExt>  triangles;       //!< The Triangles if built.
     156
    155157  ModelGroup*                firstGroup;      //!< The first of all groups.
    156158  ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
Note: See TracChangeset for help on using the changeset viewer.