/** * This source file is part of OgreColladaPlugin * an addon for OGRE (Object-oriented Graphics Rendering Engine) * For the latest info, see http://www.ogre3d.org/ * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA, or go to * http://www.gnu.org/copyleft/lesser.txt. * * @author Philipp Hartl * @see README */ #ifndef __COLLADA_GEOMETRY_H__ #define __COLLADA_GEOMETRY_H__ #include "OgreColladaPrerequisites.h" #include "OgreColladaEntity.h" namespace Ogre { struct ColladaGeometryPolygon; struct ColladaGeometryInputData; struct ColladaGeometrySource; struct ColladaGeometryOgreMesh; struct ColladaGeometryIndexData; typedef std::vector ColladaGeometryPolygonPtrVector; typedef std::vector ColladaGeometryInputDataPtrVector; typedef std::vector ColladaGeometrySourcePtrVector; typedef std::vector ColladaGeometryOgreMeshIndexData; namespace ColladaGeometrySpecific { /** * */ enum Semantic { POSITION = 0, VERTEX, NORMAL, TEXCOORD, COLOR, UV, UNKNOWN = -1 }; /** * compare the string with collada syntax * * @param s the semantic string we have * @return the corresponding semantic type */ Semantic getSemantic(const String &s); } /** * a geometry object * holds information about: collada node * id, name, vertices, polygons, ... */ class ColladaGeometry : public ColladaEntity { public: ColladaGeometry(ColladaDocument *doc, xmlNode *n); virtual ~ColladaGeometry(void); // ogre instance virtual MovableObject *getOgreInstance(void) const; /** * import node * * @see base class */ virtual bool doImport(void); virtual EntityTypes getEntityType(void) const { return GEOMETRY; } /** * reset the bounding box for the manually created mesh * iff b != NULL * * @param b the boundingbox from the collada scene node, see ColladaScene * @return void */ void setBoundingBox(ColladaBoundingBox *b); /** * the name of an entity in a scene graph should be unique * (e.g. there could be more than one geometry instance with the same MeshPtr reference) * this function should be called before ogre instantiation * * @param s the unique name of the entity * @return void */ void setEntityName(const String &s) { mEntityName = s; } private: // the primitives render operation type enum RenderType { POLYGONS, TRIANGLES }; ColladaGeometryPolygonPtrVector mPolygons; ColladaGeometrySourcePtrVector mSources; ColladaGeometryInputDataPtrVector mVertexInputs; RenderType mType; String mEntityName; // this name must be unique in the scene graph ColladaBoundingBox *mBB; bool mBBReset; // if AABB was resetted by collada scene node ColladaGeometryOgreMesh *mOgreMesh; /** * calculate AABB from imported vertex data * the triangulated ogremesh could be greater than the vertices from collada * * @param none * @return none */ void calcBoundingBox(void); /** * create and load an ogre mesh instance * * @param none * @return void */ void createOgreMesh(void) const; /** * convert all vertex and index data from collada * primitves into ogre triangle list * currently only and primitives are supported * * @param void * @return void */ void createTriangleList(void); /** * import extra information of geometry * * @param node node * @return void */ void importExtra(xmlNode *extraNode); /** * import all geometry data * including vertices, normals, texcoords, indices, ... * currently only polygons are implemented * * @param node node * @return true if all sub-imports succeeds */ bool importMesh(xmlNode *meshNode); /** * look for or nodes * dependent on param primitive * fill up the mInputPolygonsDataList * * @param meshNode node * @param primitive polygons or triangles * @return true if imported */ bool importPolygonsNodes(xmlNode *meshNode, const String &primitive); /** * import nodes (vertices, normals, texcoords, ...) * * @param sourceNode node to load * @return a pointer at loaded source record, NULL otherwise */ ColladaGeometrySource *importSourceNode(xmlNode *sourceNode); /** * look for node * fill up mVertexInputs * * @param meshNode node * @return true if imported */ bool importVerticesNode(xmlNode *meshNode); /** * only for debugging purpose * to see the values */ void printIndices(void); void printVertices(const unsigned short x); }; /** * holds data * if child of then idx and indices are not used */ struct ColladaGeometryInputData { uint idx; // unique index, used for indices offset intVector indices; // indices (vertex, normal, texcoord, ...) ColladaGeometrySource *source; // pointer at source record, accessed by indices, for VERTEX it is NULL ColladaGeometrySpecific::Semantic semantic; // semantic type }; /** * holds data */ struct ColladaGeometryPolygon { bool setMaterial; // can material be attached? ColladaMaterial *material; // a ColladaMaterial pointer, with assigned name uint primitiveCount; // the total amount of polygon primitives uint vertexCount; // the number of vertices used by a polygon primitive uint inputCount; // the total amount of inputs ColladaGeometryInputDataPtrVector inputs; // a vector with polygon }; /** * holds data */ struct ColladaGeometrySource { String id; // the source identifier uint count; // the number of times the array is accessed uint stride; // the number of values to access per count iteration floatVector data; // the floating data vector }; /** * indices and material properties * needed by ColladaGeometryOgreMesh */ struct ColladaGeometryIndexData { String material; uint count; unsigned short *indices; }; /** * optimized ogre mesh data for hardware buffers * there is only one meshdata, but there could be more index data, mutlimaterial e.g. */ struct ColladaGeometryOgreMesh { bool drawNormals, drawTexCoords; uint vertexCount; // the number of vertices float *vertices; // vertices, [normals], [texcoords] ColladaGeometryOgreMeshIndexData indices; }; } #endif // __COLLADA_GEOMETRY_H__