Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ColladaPlugin/include/OgreColladaDocument.h @ 61

Last change on this file since 61 was 21, checked in by nicolasc, 17 years ago

added ogreode and Colladaplugin

File size: 7.1 KB
RevLine 
[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_DOCUMENT_H__
25#define __COLLADA_DOCUMENT_H__
26
27#include "OgreColladaPrerequisites.h"
28
29#include "OgreResource.h"
30#include "OgreQuaternion.h"
31
32namespace Ogre
33{
34        // Forward declaration
35        class COLLADADocumentPtr;
36
37        /**
38         * class ColladaDocument
39         */
40        class _OgreColladaExport ColladaDocument : public Resource
41        {
42        friend class ColladaManager;
43
44        public:
45        /** Constructor - use resource manager's create method rather than this.
46        */
47                ColladaDocument(ResourceManager* creator, const String& name, ResourceHandle handle,
48                        const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
49
50                ~ColladaDocument();
51
52        /**
53         * Set the active Ogre scene manager that will be used when converting Collada resources to Ogre resource.
54         * @param   scenemgr    the scene manager that will be used to display the Collada scene.
55        */
56        void setSceneManager(SceneManager *scenemgr);
57
58                /**
59                 * import a Collada XML Document (*.dae ascii file) in Ogre
60                 * parse the file and build up a scene with Ogre specific functions and elements
61                 *
62                 * @param       filename        the name of the file to import, it should ends with ".dae"
63                 * @param       options         an option string, each option is separated by ";" (not yet implemented)
64                 * @return                              true if it succeeds, false otherwise
65                 */
66                bool doImport(const String &filename, const String &options = "");
67
68                /**
69                 * export mesh/scene to Collada XML File
70                 * not yet implemented! (maybe it could be combined or used with XMLConverter?)
71                 *
72                 * @param       none
73                 * @return      void
74                 */
75                void doExport(void);
76
77                ColladaSceneNode                *getScene(void) const { return mScene; }
78                ColladaLibraryContainer *getLibrary(void) const { return mLibrary; }
79        /** Get the Ogre scenemanager currently being used by the Collada document.
80        */
81                SceneManager                    *getSceneManager(void) const { return mSceneMgr; }
82        /** Get the quaternion rotation that will convert the Collada up orientation to Ogre orientation.
83            Orge's up axis is equivalent to Collada Y_UP so the quaternion would be unity in this case.
84        */
85        const Quaternion& getUpRotation() const { return mUpRotation; }
86        /** Get the up Axis indicator for all the Collada assets in the document.
87        */
88        UpAxis getUpAxis() const;
89        /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same
90         *  orientation as the COLLADA document.
91         * @param vec is a reference to an Ogre::Vector3 that will get rotated to the corrected axis
92         */
93        void correctAxis(Vector3& vec) const;
94        /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same
95         *  orientation as the COLLADA document.
96         * @param vec is a pointer to an array of 3 Ogre::Reals that will get rotated to the corrected axis
97         */
98        void correctAxis(Real* vec) const;
99        /** corrects the vector axis alignment based on the documents up axis so that the ogre display matches the same
100         *  orientation as the COLLADA document.
101         * @param quat is a reference to a Ogre::Quaternion that will be rotated to the corrected axis
102         */
103        void correctAxis(Quaternion& quat) const;
104
105
106    protected:
107        /** Overridden from Resource.
108                */
109                void loadImpl(void);
110
111                /** Unloads the material, frees resources etc.
112                @see
113                Resource
114                */
115                void unloadImpl(void);
116                /// @copydoc Resource::calculateSize
117                size_t calculateSize(void) const { return 0; } // Default to 0 for now
118
119
120        private:
121                xmlDocPtr                               mXmlDoc;                // the parsed collada (xml) document tree
122                SceneManager                    *mSceneMgr;             // the ogre scene manager
123
124                ColladaLibraryContainer *mLibrary;              // a container with all libraries
125                ColladaSceneNode                *mScene;                // the scene root node (DAG graph)
126        ColladaAsset            *mAsset;        // the asset element node for the document
127        Quaternion               mUpRotation;   // rotation required to re-orientate collada axis to Ogre
128
129                /**
130                 * import asset information
131                 * common document information, like authors, coordinates direction
132                 *
133                 * @param       node    <asset> node
134                 * @return      void
135                 */
136                void importAsset(xmlNode *node);
137
138                /**
139                 * import <COLLADA> XML document
140                 * the <COLLADA> element is the document entity (root element) in a COLLADA instance document
141                 * child elements (in order and occurrence ([minOccur, maxOccur]))
142                 *      asset           [1,1]
143         *      library         [0,*]
144                 *      scene           [0,1]
145                 *
146                 * @param       element <COLLADA> root element
147                 * @return      true if succeeds, false otherwise
148                 */
149                bool importCollada(xmlNode *element);
150        };
151
152
153        /** Specialisation of SharedPtr to allow SharedPtr to be assigned to COLLADADocumentPtr
154        @note Has to be a subclass since we need operator=.
155        We could templatise this instead of repeating per Resource subclass,
156        except to do so requires a form VC6 does not support i.e.
157        ResourceSubclassPtr<T> : public SharedPtr<T>
158        */
159        class _OgreColladaExport ColladaDocumentPtr : public SharedPtr<ColladaDocument> 
160        {
161        public:
162                ColladaDocumentPtr() : SharedPtr<ColladaDocument>() {}
163                explicit ColladaDocumentPtr(ColladaDocument* rep) : SharedPtr<ColladaDocument>(rep) {}
164                ColladaDocumentPtr(const ColladaDocumentPtr& r) : SharedPtr<ColladaDocument>(r) {} 
165                ColladaDocumentPtr(const ResourcePtr& r) : SharedPtr<ColladaDocument>()
166                {
167                        // lock & copy other mutex pointer
168                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
169                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
170                        pRep = static_cast<ColladaDocument*>(r.getPointer());
171                        pUseCount = r.useCountPointer();
172                        if (pUseCount)
173                        {
174                                ++(*pUseCount);
175                        }
176                }
177
178                /// Operator used to convert a ResourcePtr to a MaterialPtr
179                ColladaDocumentPtr& operator=(const ResourcePtr& r)
180                {
181                        if (pRep == static_cast<ColladaDocument*>(r.getPointer()))
182                                return *this;
183                        release();
184                        // lock & copy other mutex pointer
185                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
186                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
187                        pRep = static_cast<ColladaDocument*>(r.getPointer());
188                        pUseCount = r.useCountPointer();
189                        if (pUseCount)
190                        {
191                                ++(*pUseCount);
192                        }
193                        return *this;
194                }
195        };
196}
197
198#endif // __COLLADA_DOCUMENT_H__
Note: See TracBrowser for help on using the repository browser.