Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10147 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Dec 25, 2006, 1:30:44 PM (18 years ago)
Author:
patrick
Message:

merged the mount_point branche back to trunk to use the new std::* based obj file importer

Location:
trunk/src/lib/graphics/importer
Files:
8 edited
5 copied

Legend:

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

    r10033 r10147  
    2525                \
    2626                obj/objModel.cc \
     27                \
     28                oif/object_information_file.cc \
     29                oif/resource_oif.cc \
    2730                \
    2831                bsp/bsp_manager.cc \
     
    7982                obj/objModel.h \
    8083                \
     84                oif/object_information_file.h \
     85                oif/resource_oif.h \
     86                \
    8187                md2/md2Model.h \
    8288                md2/resource_md2.h \
  • trunk/src/lib/graphics/importer/model.h

    r9869 r10147  
    8383    inline unsigned int getTriangleCount() const { return this->pModelInfo.numTriangles; };
    8484
     85    /** function to extract the mount points from the model data */
     86    virtual void extractMountPoints() {}
     87
     88
    8589  protected:
    8690    Model();
  • trunk/src/lib/graphics/importer/obj/objModel.cc

    r10033 r10147  
    4444
    4545  this->finalize();
     46
     47  this->extractMountPoints();
    4648}
    4749
     
    138140          this->addVertexTexture(buffer+3);
    139141        }
    140       // case group
    141       else if (!strncmp(buffer, "g ", 2))
     142      // case group or object (depends on the exporter program)
     143      else if (!strncmp(buffer, "g ", 2) || !strncmp(buffer, "o ", 2))
    142144        {
    143145          this->addGroup (buffer+2);
  • trunk/src/lib/graphics/importer/obj/objModel.h

    r10033 r10147  
    1616  OBJModel(const std::string& fileName, float scaling = 1.0);
    1717  virtual ~OBJModel();
     18
    1819
    1920private:
  • trunk/src/lib/graphics/importer/static_model.cc

    r9869 r10147  
    9191  this->updateBase();
    9292}
     93
     94
     95
     96/**
     97 * extract the mount points from this file: looking at each group and checking if the group realy is a mountpoint marker
     98 * if so get place and orientation
     99 */
     100void StaticModel::extractMountPoints()
     101{
     102
     103  // go through all groups and check if they are mounts
     104  std::vector<StaticModelData::Group>::const_iterator groupIt = this->data->getGroups().begin();
     105  for( ; groupIt != this->data->getGroups().end(); groupIt++)
     106  {
     107    //PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     108
     109    // get the name of this group and check if it's a mout point identifier
     110    std::string groupName = (*groupIt).name;
     111    std::vector<Vector> vertices;
     112
     113    if( groupName.find("MP.", 0) != std::string::npos)
     114    {
     115      PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     116
     117      // now check if it is a mount point identifier
     118      if( this->data->getGroups().size() != 5) {
     119        PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object\n", groupName.c_str());
     120      }
     121
     122      // now extract the direction from the length:
     123      std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin();
     124      for( ; faceIt < (*groupIt)._faces.end(); faceIt++)
     125      {
     126        // now go through all modelfaceelements
     127        std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin();
     128        for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++)
     129        {
     130          int vert = (*faceElementIt).vertexNumber;
     131          vertices.push_back(Vector(this->data->getVertices()[vert*3],
     132                             this->data->getVertices()[vert*3 + 1],
     133                             this->data->getVertices()[vert*3 + 2]));
     134        }
     135      }
     136
     137      // vertex with the max count is the up-point
     138      std::vector<Vector>::const_iterator it = vertices.begin();
     139      Vector tmpPoint;
     140      int tmpCount;
     141      Vector upPoint;
     142      int maxCount = 0;
     143      for( ; it < vertices.end(); it++)
     144      {
     145        tmpCount = 0;
     146        tmpPoint = (*it);
     147        //
     148        std::vector<Vector>::const_iterator it2 = vertices.begin();
     149        for( ; it2 < vertices.end(); it2++)
     150          if( tmpPoint == *it2)
     151            tmpCount++;
     152
     153        // if this is the vertex with the most surrounding vertices
     154        if( tmpCount > maxCount)
     155        {
     156          upPoint = tmpPoint;
     157          maxCount = tmpCount;
     158        }
     159      }
     160
     161      // now get the center of the object
     162      Vector center;
     163      it = vertices.begin();
     164      for( ; it < vertices.end(); it++)
     165        center += (*it);
     166      // scale
     167      center /= vertices.size();
     168
     169
     170    }
     171
     172  }
     173
     174
     175}
     176
     177
    93178
    94179/**
  • trunk/src/lib/graphics/importer/static_model.h

    r10141 r10147  
    5858
    5959  void finalize();
     60  void extractMountPoints();
    6061
    6162  void acquireData(const StaticModelData::Pointer& data);
  • trunk/src/lib/graphics/importer/static_model_data.cc

    r10141 r10147  
    276276bool StaticModelData::addGroup(const std::string& groupString)
    277277{
    278   PRINTF(5)("Read Group: %s.\n", groupString.c_str());
     278  PRINTF(4)("Read Group: %s.\n", groupString.c_str());
    279279  if (!_modelGroups.empty() && !_modelGroups.back()._faces.empty())
    280280    _modelGroups.push_back(Group());
    281281
    282   if (groupString == "default")
    283     _modelGroups.back().name = groupString;
    284   // setting the group name if not default.
     282  _modelGroups.back().name = groupString;
    285283  return true;
    286284}
  • trunk/src/lib/graphics/importer/static_model_data.h

    r10141 r10147  
    129129  ///! HACK SOLUTION sTriangleExt should be const in the modelInfo.
    130130  sTriangleExt* getTrianglesExt() { return &this->triangles[0]; };
     131  const std::vector<Group>& getGroups() { return this->_modelGroups; }
    131132
    132133  float getScaleFactor() const  { return scaleFactor; }
Note: See TracChangeset for help on using the changeset viewer.