Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6008 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Dec 10, 2005, 3:52:33 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some more functionality in the abstractModel class

Location:
trunk/src/lib/graphics/importer
Files:
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/abstract_model.h

    r5790 r6008  
    113113  unsigned int     numTriangles;         //!< number of triangles in the Model
    114114  unsigned int     numNormals;           //!< how many Normals in the Model
    115   unsigned int     numTexCoor;
     115  unsigned int     numTexCoor;           //!< how many Texture Coordinates in the Model
    116116
    117117  const float*     pVertices;            //!< array of the Vertives
     
    131131    virtual ~AbstractModel() { }
    132132
    133     inline const modelInfo* getModelInfo() const { return this->pModelInfo; }
     133    inline const modelInfo* getModelInfo() const { return &this->pModelInfo; }
    134134
     135    /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
     136    inline const float* getVertexArray() const { return this->pModelInfo.pVertices; };
     137    /** @returns the VertexCount of this Model */
     138    inline unsigned int getVertexCount() const { return this->pModelInfo.numVertices; };
     139
     140    /** @returns a Pointer to the Normals-Array, if it was deleted it returns NULL */
     141    inline const float* getNormalsArray() const { return this->pModelInfo.pNormals; };
     142    /** @returns the NormalsCount of this Model */
     143    inline unsigned int getNormalsCount() const { return this->pModelInfo.numNormals; };
     144
     145    /** @returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */
     146    inline const float* getTexCoordArray() const { return this->pModelInfo.pTexCoor; };
     147    /** @returns the TexCoord-Count of this Model */
     148    inline unsigned int getTexCoordCount() const { return this->pModelInfo.numTexCoor; };
     149
     150    /** @returns the Array of triangles */
     151    inline sTriangleExt* getTriangles() const { return this->pModelInfo.pTriangles; };
     152    /** @returns the Count of Faces of this Model */
     153    inline unsigned int getFaceCount() const { return this->pModelInfo.numTriangles; };
    135154
    136155  protected:
    137     modelInfo*     pModelInfo;      //!< Reference to the modelInfo
     156    modelInfo      pModelInfo;      //!< Reference to the modelInfo
    138157};
    139158
  • trunk/src/lib/graphics/importer/model.cc

    r5790 r6008  
    158158  this->triangleCount = 0;
    159159  this->triangles = NULL;
    160   this->pModelInfo = NULL;
    161160
    162161  this->scaleFactor = 1;
     
    205204    delete (*modMat);
    206205  }
    207   delete this->pModelInfo;
    208206}
    209207
     
    223221
    224222  /* load the ModelInfo */
    225   this->pModelInfo = new modelInfo;
    226   this->pModelInfo->numVertices = this->vertexCount;
    227   this->pModelInfo->pVertices = this->vertices->getArray();
    228   this->pModelInfo->numTriangles = this->triangleCount;
    229   this->pModelInfo->pTriangles = this->triangles;
    230   this->pModelInfo->numNormals = this->normalCount;
    231   this->pModelInfo->pNormals = this->normals->getArray();
    232   this->pModelInfo->numTexCoor = this->vTexture->getCount();
    233   this->pModelInfo->pTexCoor = this->vTexture->getArray();
     223  this->pModelInfo.numVertices = this->vertexCount;
     224  this->pModelInfo.pVertices = this->vertices->getArray();
     225  this->pModelInfo.numTriangles = this->triangleCount;
     226  this->pModelInfo.pTriangles = this->triangles;
     227  this->pModelInfo.numNormals = this->normalCount;
     228  this->pModelInfo.pNormals = this->normals->getArray();
     229  this->pModelInfo.numTexCoor = this->vTexture->getCount();
     230  this->pModelInfo.pTexCoor = this->vTexture->getArray();
    234231
    235232  this->finalized = true;
  • trunk/src/lib/graphics/importer/vertex_list_model.cc

    r6006 r6008  
    1818#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
    1919
    20 #include "model.h"
     20#include "vertex_list_model.h"
    2121
    2222#include "stdlibincl.h"
     
    2626
    2727using namespace std;
    28 
    29 
    30 ////////////////////
    31 /// SUB-Elements ///
    32 ////////////////////
    33 /**
    34  *  creates a new ModelFaceElement
    35 */
    36 ModelFaceElement::ModelFaceElement()
    37 {
    38   this->vertexNumber = -1;
    39   this->normalNumber = -1;
    40   this->texCoordNumber = -1;
    41 
    42   this->next = NULL;
    43 }
    44 
    45 /**
    46  *  destroys a ModelFaceElement
    47 */
    48 ModelFaceElement::~ModelFaceElement()
    49 {
    50   if (this->next)
    51     delete this->next;
    52 }
    53 
    54 /**
    55  *  creates a new ModelFace
    56 */
    57 ModelFace::ModelFace()
    58 {
    59   this->vertexCount = 0;
    60 
    61   this->firstElem = NULL;
    62 
    63   this->material = NULL;
    64 
    65   this->next = NULL;
    66 }
    67 
    68 /**
    69  *  deletes a ModelFace
    70 */
    71 ModelFace::~ModelFace()
    72 {
    73   PRINTF(5)("Cleaning up Face\n");
    74 
    75   if (this->firstElem != NULL)
    76     delete this->firstElem;
    77 
    78   if (this->next != NULL)
    79     delete this->next;
    80 }
    81 
    82 /**
    83  *  Creates a new ModelGroup
    84 */
    85 ModelGroup::ModelGroup()
    86 {
    87   PRINTF(4)("Adding new Group\n");
    88   this->name = "";
    89   this->faceMode = -1;
    90   this->faceCount = 0;
    91   this->next = NULL;
    92   this->listNumber = 0;
    93 
    94   this->firstFace = new ModelFace;
    95   this->currentFace = this->firstFace;
    96 }
    97 
    98 /**
    99  *  deletes a ModelGroup
    100 */
    101 ModelGroup::~ModelGroup()
    102 {
    103   PRINTF(5)("Cleaning up group\n");
    104   if (this->firstFace != NULL)
    105     delete this->firstFace;
    106 
    107   // deleting the glList
    108   if (this->listNumber != 0)
    109     glDeleteLists(this->listNumber, 1);
    110 
    111   if (this->name[0] != '\0')
    112     delete[] this->name;
    113 
    114   if (this->next !=NULL)
    115     delete this->next;
    116 
    117 }
    11828
    11929/**
  • trunk/src/lib/graphics/importer/vertex_list_model.h

    r6006 r6008  
    1717template<class T> class tArray;
    1818
    19 
    20 //! an enumerator fot the different Model Types.
    21 /**
    22    MODEL_DISPLAY_LIST means, that a DisplayList will be built out of the model. This model will be STATIC, meaning it cannot be changed after initialisation.
    23    MODEL_VERTEX_ARRAY means, that a VertexArray will be built out of the model. This moel will be DYNAMIX, meaning that one can change the properties from outside of the model.
    24  * @todo implement this stuff
    25 */
    26 typedef enum MODEL_TYPE {
    27   MODEL_DISPLAY_LIST,
    28   MODEL_VERTEX_ARRAY
    29 };
    30 
    31 
    32 // definition of different modes for setting up Faces
    33 #define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
    34 #define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
    35 #define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
    36 
    37 //! an enumerator for VERTEX_FORMAT
    38 typedef enum VERTEX_FORMAT {
    39   VERTEX_ONLY = VERTEX,
    40   VERTEX_NORMAL = NORMAL,
    41   VERTEX_TEXCOORD = TEXCOORD,
    42   VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD
    43 };
    44 
    45 ////////////////////
    46 /// SUB-ELEMENTS ///
    47 ////////////////////
    48 //! This is the placeholder of one Vertex beloning to a Face.
    49 class ModelFaceElement
    50 {
    51  public:
    52   ModelFaceElement();
    53   ~ModelFaceElement();
    54 
    55   int                 vertexNumber;         //!< The number of the Vertex out of the Array* vertices, this vertex points to.
    56   int                 normalNumber;         //!< The number of the Normal out of the Array* normals, this vertex points to.
    57   int                 texCoordNumber;       //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
    58 
    59   ModelFaceElement*   next;                 //!< Point to the next FaceElement in this List.
    60 };
    61 
    62 //! This is the placeholder of a Face belonging to a Group of Faces.
    63 class ModelFace
    64 {
    65  public:
    66   ModelFace();
    67   ~ModelFace();
    68 
    69   unsigned int        vertexCount;     //!< The Count of vertices this Face has.
    70   ModelFaceElement*   firstElem;       //!< Points to the first Vertex (FaceElement) of this Face.
    71   Material*           material;        //!< The Material to use.
    72 
    73   ModelFace*          next;            //!< Pointer to the next Face.
    74 };
    75 
    76 //! Group to handle multiple Models per obj-file.
    77 class ModelGroup
    78 {
    79  public:
    80   ModelGroup();
    81   ~ModelGroup();
    82 
    83   void cleanup();
    84 
    85   char*        name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
    86   GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
    87   GLuint       listNumber;     //!< The number of the GL-List this Group gets.
    88   ModelFace*   firstFace;      //!< The first Face in this group.
    89   ModelFace*   currentFace;    //!< The current Face in this Group (the one we are currently working with.)
    90   int          faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM...
    91   int          faceCount;      //!< The Number of Faces this Group holds.
    92 
    93   ModelGroup*  next;           //!< Pointer to the next Group.
    94 };
    95 
    96 struct ModelMaterial
    97 {
    98   Material* material;
    99   bool external;
    100 };
    101 
    10219/////////////
    10320/// MODEL ///
     
    11128
    11229  void draw() const;
    113   void draw(int groupNumber) const;
    114   void draw(char* groupName) const;
    115 
    116   void rebuild();
    117 
    118   /** @returns Count of the Models (Groups) in this File */
    119   inline int getGroupCount() const { return this->groupCount; };
    12030
    12131  /** @returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */
     
    14151  Material* addMaterial(const char* materialName);
    14252
     53
     54  bool addVertex(float x, float y, float z);
     55
     56  bool addVertexNormal(float x, float y, float z);
     57
     58  bool addVertexTexture(float u, float v);
     59
     60  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
     61
    14362  bool addGroup(const char* groupString);
    144   bool addVertex(const char* vertexString);
    145   bool addVertex(float x, float y, float z);
    146   bool addFace(const char* faceString);
    147   bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
    148   bool addVertexNormal(const char* normalString);
    149   bool addVertexNormal(float x, float y, float z);
    150   bool addVertexTexture(const char* vTextureString);
    151   bool addVertexTexture(float u, float v);
    152   bool setMaterial(const char* mtlString);
     63
    15364  bool setMaterial(Material* mtl);
     65
    15466  void finalize();
    15567
    15668
    157  protected:
    158   void cubeModel();
     69 private:
     70  bool buildTriangleList();
    15971
    160   Material* findMaterialByName(const char* materialName);
    161 
    162 
    163  protected:
    164   float            scaleFactor;     //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation
    165 
    166  private:
    167   bool buildVertexNormals();
    168 
    169   bool importToDisplayList();
    170   bool buildTriangleList();
    17172  bool addGLElement(ModelFaceElement* elem);
    17273
     
    17778
    17879 private:
    179   MODEL_TYPE                 type;            //!< A type for the Model
    18080  bool                       finalized;       //!< Sets the Object to be finalized.
    18181
    182   unsigned int               vertexCount;     //!< A modelwide Counter for vertices.
    183   unsigned int               normalCount;     //!< A modelwide Counter for the normals.
    184   unsigned int               texCoordCount;   //!< A modelwide Counter for the texCoord.
    185   unsigned int               faceCount;       //!< A modelwide Counter for the faces
    186   unsigned int               triangleCount;   //!< Number of triangles >= faceCount
    187   tArray<GLfloat>*           vertices;        //!< The Array that handles the Vertices.
    188   tArray<GLfloat>*           normals;         //!< The Array that handles the Normals.
    189   tArray<GLfloat>*           vTexture;        //!< The Array that handles the VertexTextureCoordinates.
    190   sTriangleExt*              triangles;       //!< The Array of triangles in the abstract_model.h style
     82  tArray<GLfloat>            vertices;        //!< The Array that handles the Vertices.
     83  tArray<GLfloat>            normals;         //!< The Array that handles the Normals.
     84  tArray<GLfloat>            textures;        //!< The Array that handles the VertexTextureCoordinates.
    19185
    192   ModelGroup*                firstGroup;      //!< The first of all groups.
    193   ModelGroup*                currentGroup;    //!< The currentGroup. this is the one we will work with.
    194   int                        groupCount;      //!< The Count of Groups.
     86  tArray<GLfloat>            indices;         //!< The Array that tells us what Vertex is connected to which other one.
    19587
    19688  std::list<ModelMaterial*>  materialList;    //!< A list for all the Materials in this Model
Note: See TracChangeset for help on using the changeset viewer.