/** * 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_DOCUMENT_H__ #define __COLLADA_DOCUMENT_H__ #include "OgreColladaPrerequisites.h" #include "OgreResource.h" #include "OgreQuaternion.h" namespace Ogre { // Forward declaration class COLLADADocumentPtr; /** * class ColladaDocument */ class _OgreColladaExport ColladaDocument : public Resource { friend class ColladaManager; public: /** Constructor - use resource manager's create method rather than this. */ ColladaDocument(ResourceManager* creator, const String& name, ResourceHandle handle, const String& group, bool isManual = false, ManualResourceLoader* loader = 0); ~ColladaDocument(); /** * Set the active Ogre scene manager that will be used when converting Collada resources to Ogre resource. * @param scenemgr the scene manager that will be used to display the Collada scene. */ void setSceneManager(SceneManager *scenemgr); /** * import a Collada XML Document (*.dae ascii file) in Ogre * parse the file and build up a scene with Ogre specific functions and elements * * @param filename the name of the file to import, it should ends with ".dae" * @param options an option string, each option is separated by ";" (not yet implemented) * @return true if it succeeds, false otherwise */ bool doImport(const String &filename, const String &options = ""); /** * export mesh/scene to Collada XML File * not yet implemented! (maybe it could be combined or used with XMLConverter?) * * @param none * @return void */ void doExport(void); ColladaSceneNode *getScene(void) const { return mScene; } ColladaLibraryContainer *getLibrary(void) const { return mLibrary; } /** Get the Ogre scenemanager currently being used by the Collada document. */ SceneManager *getSceneManager(void) const { return mSceneMgr; } /** Get the quaternion rotation that will convert the Collada up orientation to Ogre orientation. Orge's up axis is equivalent to Collada Y_UP so the quaternion would be unity in this case. */ const Quaternion& getUpRotation() const { return mUpRotation; } /** Get the up Axis indicator for all the Collada assets in the document. */ UpAxis getUpAxis() const; /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same * orientation as the COLLADA document. * @param vec is a reference to an Ogre::Vector3 that will get rotated to the corrected axis */ void correctAxis(Vector3& vec) const; /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same * orientation as the COLLADA document. * @param vec is a pointer to an array of 3 Ogre::Reals that will get rotated to the corrected axis */ void correctAxis(Real* vec) const; /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same * orientation as the COLLADA document. * @param quat is a reference to a Ogre::Quaternion that will be rotated to the corrected axis */ void correctAxis(Quaternion& quat) const; protected: /** Overridden from Resource. */ void loadImpl(void); /** Unloads the material, frees resources etc. @see Resource */ void unloadImpl(void); /// @copydoc Resource::calculateSize size_t calculateSize(void) const { return 0; } // Default to 0 for now private: xmlDocPtr mXmlDoc; // the parsed collada (xml) document tree SceneManager *mSceneMgr; // the ogre scene manager ColladaLibraryContainer *mLibrary; // a container with all libraries ColladaSceneNode *mScene; // the scene root node (DAG graph) ColladaAsset *mAsset; // the asset element node for the document Quaternion mUpRotation; // rotation required to re-orientate collada axis to Ogre /** * import asset information * common document information, like authors, coordinates direction * * @param node node * @return void */ void importAsset(xmlNode *node); /** * import XML document * the element is the document entity (root element) in a COLLADA instance document * child elements (in order and occurrence ([minOccur, maxOccur])) * asset [1,1] * library [0,*] * scene [0,1] * * @param element root element * @return true if succeeds, false otherwise */ bool importCollada(xmlNode *element); }; /** Specialisation of SharedPtr to allow SharedPtr to be assigned to COLLADADocumentPtr @note Has to be a subclass since we need operator=. We could templatise this instead of repeating per Resource subclass, except to do so requires a form VC6 does not support i.e. ResourceSubclassPtr : public SharedPtr */ class _OgreColladaExport ColladaDocumentPtr : public SharedPtr { public: ColladaDocumentPtr() : SharedPtr() {} explicit ColladaDocumentPtr(ColladaDocument* rep) : SharedPtr(rep) {} ColladaDocumentPtr(const ColladaDocumentPtr& r) : SharedPtr(r) {} ColladaDocumentPtr(const ResourcePtr& r) : SharedPtr() { // lock & copy other mutex pointer OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) pRep = static_cast(r.getPointer()); pUseCount = r.useCountPointer(); if (pUseCount) { ++(*pUseCount); } } /// Operator used to convert a ResourcePtr to a MaterialPtr ColladaDocumentPtr& operator=(const ResourcePtr& r) { if (pRep == static_cast(r.getPointer())) return *this; release(); // lock & copy other mutex pointer OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) pRep = static_cast(r.getPointer()); pUseCount = r.useCountPointer(); if (pUseCount) { ++(*pUseCount); } return *this; } }; } #endif // __COLLADA_DOCUMENT_H__