| [21] | 1 | /** |
|---|
| 2 | * This source file is part of OgreColladaPlugin |
|---|
| 3 | * an addon for OGRE (Object-oriented Graphics Rendering Engine) |
|---|
| 4 | * For the latest info, see http://www.ogre3d.org/ |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify it under |
|---|
| 7 | * the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 8 | * Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 9 | * version. |
|---|
| 10 | |
|---|
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 13 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | * You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 16 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 17 | * Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 18 | * http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 19 | * |
|---|
| 20 | * @author Philipp Hartl |
|---|
| 21 | * @see README |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #ifndef __COLLADA_LIBRARY_H__ |
|---|
| 25 | #define __COLLADA_LIBRARY_H__ |
|---|
| 26 | |
|---|
| 27 | #include "OgreColladaPrerequisites.h" |
|---|
| 28 | |
|---|
| 29 | namespace Ogre |
|---|
| 30 | { |
|---|
| 31 | namespace ColladaLibrarySpecific |
|---|
| 32 | { |
|---|
| 33 | /** |
|---|
| 34 | * <library type="..."> |
|---|
| 35 | */ |
|---|
| 36 | enum Type |
|---|
| 37 | { |
|---|
| 38 | ANIMATION = 0, |
|---|
| 39 | CAMERA, |
|---|
| 40 | CODE, |
|---|
| 41 | CONTROLLER, |
|---|
| 42 | GEOMETRY, |
|---|
| 43 | IMAGE, |
|---|
| 44 | LIGHT, |
|---|
| 45 | MATERIAL, |
|---|
| 46 | PROGRAM, |
|---|
| 47 | TEXTURE, |
|---|
| 48 | |
|---|
| 49 | UNKNOWN = -1 |
|---|
| 50 | }; |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * compare the string with collada syntax |
|---|
| 54 | * |
|---|
| 55 | * @param s the semantic string we have |
|---|
| 56 | * @return the corresponding library type |
|---|
| 57 | */ |
|---|
| 58 | Type getType(const String &s); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * a template libray class |
|---|
| 63 | * used by all possible library types |
|---|
| 64 | * holds all entities of the library type T |
|---|
| 65 | */ |
|---|
| 66 | template <class T> |
|---|
| 67 | class ColladaLibrary |
|---|
| 68 | { |
|---|
| 69 | public: |
|---|
| 70 | ColladaLibrary(); |
|---|
| 71 | ~ColladaLibrary(); |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * create new instance of library type |
|---|
| 75 | * for each instance importId() is called |
|---|
| 76 | * |
|---|
| 77 | * @param doc everything belongs to the document |
|---|
| 78 | * @param node the library node we want to import |
|---|
| 79 | * @return void |
|---|
| 80 | */ |
|---|
| 81 | void initialise(ColladaDocument *doc, xmlNode *node); |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * find library entity by identifier and return a pointer on it |
|---|
| 85 | * |
|---|
| 86 | * @param id the string identifier |
|---|
| 87 | * @return a pointer at existing instance or NULL |
|---|
| 88 | */ |
|---|
| 89 | T *getEntity(const String &id) const; |
|---|
| 90 | |
|---|
| 91 | private: |
|---|
| 92 | typedef std::vector<T *> ColladaLibraryVector; |
|---|
| 93 | |
|---|
| 94 | ColladaLibraryVector mEntities; // a vector with all entities of <library> |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * library container |
|---|
| 99 | * holds all <library> nodes in collada document |
|---|
| 100 | */ |
|---|
| 101 | class ColladaLibraryContainer |
|---|
| 102 | { |
|---|
| 103 | public: |
|---|
| 104 | ColladaLibraryContainer(ColladaDocument *doc); |
|---|
| 105 | ~ColladaLibraryContainer(void); |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * import the <library> node, identified by its id |
|---|
| 109 | * look in possible library entities, CAMERA, GEOMETRY, LIGHT, ... |
|---|
| 110 | * |
|---|
| 111 | * @param id the string identifier |
|---|
| 112 | * @return a pointer on the successfully imported node, NULL otherwise |
|---|
| 113 | */ |
|---|
| 114 | ColladaEntity *importInstance(const String &id); |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * import <library> node and fill up the specific library entity |
|---|
| 118 | * by the type, which can be: CAMERA, GEOMETRY, LIGHT, MATERIAL, TEXTURE, ... |
|---|
| 119 | * in first step we only want to know the id and name of the node |
|---|
| 120 | * |
|---|
| 121 | * @param node the library node we want to import |
|---|
| 122 | * @return void |
|---|
| 123 | */ |
|---|
| 124 | void doImport(xmlNode *node); |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * find the entity by its identifier |
|---|
| 128 | * |
|---|
| 129 | * @param id the string identifier we are looking for |
|---|
| 130 | * @return a pointer on it, NULL otherwise |
|---|
| 131 | */ |
|---|
| 132 | ColladaCamera *getCamera(const String &id) const; |
|---|
| 133 | ColladaImage *getImage(const String &id) const; |
|---|
| 134 | ColladaLight *getLight(const String &id) const; |
|---|
| 135 | ColladaMaterial *getMaterial(const String &id) const; |
|---|
| 136 | ColladaTexture *getTexture(const String &id) const; |
|---|
| 137 | |
|---|
| 138 | private: |
|---|
| 139 | ColladaDocument *mDoc; |
|---|
| 140 | |
|---|
| 141 | // library entities |
|---|
| 142 | ColladaLibrary<ColladaCamera> *mCameras; |
|---|
| 143 | ColladaLibrary<ColladaGeometry> *mGeometries; |
|---|
| 144 | ColladaLibrary<ColladaImage> *mImages; |
|---|
| 145 | ColladaLibrary<ColladaLight> *mLights; |
|---|
| 146 | ColladaLibrary<ColladaMaterial> *mMaterials; |
|---|
| 147 | ColladaLibrary<ColladaTexture> *mTextures; |
|---|
| 148 | }; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | #endif // __COLLADA_LIBRARY_H__ |
|---|