Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tools/XSIExport/include/OgreXSIHelper.h @ 11

Last change on this file since 11 was 6, checked in by anonymous, 17 years ago

=…

File size: 6.7 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __XSIHELPER_H__
30#define __XSIHELPER_H__
31
32#include <xsi_application.h>
33#include <xsi_string.h>
34#include <xsi_x3dobject.h>
35#include <xsi_vertexcolor.h>
36#include <xsi_math.h>
37#include <xsi_ref.h>
38#include <xsi_actionsource.h>
39#include <xsi_animationsourceitem.h>
40#include <xsi_progressbar.h>
41#include <xsi_uitoolkit.h>
42#include <xsi_shader.h>
43#include <xsi_value.h>
44
45#include <stdlib.h>
46#include "OgrePrerequisites.h"
47#include "OgreString.h"
48#include "OgreColourValue.h"
49#include "OgreLogManager.h"
50#include "OgreStringVector.h"
51#include "OgreSingleton.h"
52#include "OgreVector3.h"
53#include "OgreQuaternion.h"
54#include "OgreHardwareVertexBuffer.h"
55
56#define OGRE_XSI_NUM_MESH_STEPS 200
57
58/// Useful function to convert XSI CValue to an Ogre String
59/*
60inline Ogre::String XSItoOgre(const XSI::CValue& xsival)
61{
62
63        switch(xsival.m_t)
64        {
65        case XSI::CValue::siString:
66                return XSItoOgre(XSI::CString(xsival));
67        case XSI::CValue::siVector3:
68                return XSItoOgre(XSI::MATH::CVector3(xsival));
69        default:
70                return XSItoOgre(XSI::CString(xsival.GetAsText()));
71        };
72
73}
74*/
75
76/// Useful function to convert an XSI CString to an Ogre String
77inline Ogre::String XSItoOgre(const XSI::CString& xsistr)
78{
79    // XSI CString is wide character
80
81    if (xsistr.IsEmpty())
82    {
83        return Ogre::StringUtil::BLANK;
84    }
85
86    // first find out the size required
87    size_t c = ::wcstombs(0, xsistr.GetWideString(), 2048);
88    // temp character string (add one for terminator)
89    char* tmp = new char[c+1];
90    // do the real conversion
91    ::wcstombs(tmp, xsistr.GetWideString(), c);
92        tmp[c] = '\0';
93    Ogre::String ret(tmp);
94    delete [] tmp;
95
96    return ret;
97}
98/// Useful function to convert an Ogre String to an XSI CString
99inline XSI::CString OgretoXSI(const Ogre::String& str)
100{
101    // XSI CString is wide character
102
103    if (str.empty())
104    {
105        return XSI::CString();
106    }
107
108    // first find out the size required
109    size_t c = ::mbstowcs(0, str.c_str(), 2048);
110    // temp character string (add one for terminator)
111    wchar_t* tmp = new wchar_t[c+1];
112    // do the real conversion
113    ::mbstowcs(tmp, str.c_str(), c);
114        tmp[c] = '\0';
115
116    XSI::CString ret(tmp);
117    delete [] tmp;
118
119    return ret;
120}
121
122inline Ogre::Vector3 XSItoOgre(const XSI::MATH::CVector3& xsiVec)
123{
124    return Ogre::Vector3(xsiVec.GetX(), xsiVec.GetY(), xsiVec.GetZ());
125}
126inline Ogre::Quaternion XSItoOgre(const XSI::MATH::CQuaternion& xsiQuat)
127{
128        return Ogre::Quaternion(xsiQuat.GetW(), xsiQuat.GetX(), xsiQuat.GetY(), xsiQuat.GetZ());
129}
130
131inline Ogre::RGBA XSItoOgre(const XSI::CVertexColor& xsiColour)
132{
133        Ogre::ColourValue col(xsiColour.r / 255.0f, xsiColour.g / 255.0f, 
134                xsiColour.b / 255.0f, xsiColour.a / 255.0f);
135        return Ogre::VertexElement::convertColourValue(col, 
136                Ogre::VertexElement::getBestColourVertexElementType());
137}
138
139inline void LogOgreAndXSI(const Ogre::String& msg)
140{
141        static XSI::Application app;
142        Ogre::LogManager::getSingleton().logMessage(msg);
143        app.LogMessage(OgretoXSI(msg));
144
145}
146
147inline void LogOgreAndXSI(const XSI::CString& msg)
148{
149        static XSI::Application app;
150        Ogre::LogManager::getSingleton().logMessage(XSItoOgre(msg));
151        app.LogMessage(msg);
152
153}
154
155
156namespace Ogre {
157
158        class ProgressManager : public Singleton<ProgressManager>
159        {
160        protected:
161                XSI::ProgressBar mProgressBar;
162                size_t mNumberOfStages;
163                size_t mProgress;
164
165        public:
166                ProgressManager(size_t numberOfStages);
167                virtual ~ProgressManager();
168                       
169                void progress(void);
170
171                static ProgressManager& getSingleton(void);
172                static ProgressManager* getSingletonPtr(void);
173
174        };
175
176        enum XSITrackType
177        {
178                XTT_POS_X = 0,
179                XTT_POS_Y = 1,
180                XTT_POS_Z = 2,
181                XTT_ROT_X = 3,
182                XTT_ROT_Y = 4,
183                XTT_ROT_Z = 5,
184                XTT_SCL_X = 6,
185                XTT_SCL_Y = 7,
186                XTT_SCL_Z = 8,
187                XTT_COUNT = 9
188        };
189        /** An entry for a Deformer - need original index because this will be boneID */
190        class DeformerEntry
191        {
192        public:
193                unsigned short boneID;
194                XSI::X3DObject obj;
195                String parentName;
196                StringVector childNames;
197                bool hasVertexAssignments;
198                bool parentIsChainEndEffector;
199                bool hasAnyTracks;
200                Bone* pBone;
201                bool ikSample;
202                double ikSampleInterval;
203                XSI::MATH::CTransformation initialXform;
204                // lists of action source items (probably only one per param?)
205                XSI::AnimationSourceItem xsiTrack[XTT_COUNT];
206
207                DeformerEntry(unsigned short theboneID, XSI::X3DObject& theobj)
208                        :boneID(theboneID), obj(theobj), hasVertexAssignments(false), 
209                        parentIsChainEndEffector(false), hasAnyTracks(false), pBone(0)
210                       
211                {
212                }
213
214        };
215        /// Map from deformer name to deformer entry
216        typedef std::map<String,DeformerEntry*> DeformerMap;
217
218
219        /** An entry for animation; allows the userto split the timeline into
220                multiple separate animations.
221        */
222        struct AnimationEntry
223        {
224                String animationName;
225                long startFrame; 
226                long endFrame; 
227                double ikSampleInterval; // skeletal only
228        };
229        /// List of animations
230        typedef std::list<AnimationEntry> AnimationList;
231
232        /** Record of an XSI GL shader material. */
233        struct MaterialEntry
234        {
235                String name;
236                XSI::Shader xsiShader;
237        };
238        /// Map from material name to material entry
239        typedef std::map<String, MaterialEntry*> MaterialMap;
240
241        /** Record of XSI details that are to become a pass */
242        struct PassEntry
243        {
244                XSI::CRefArray shaders;
245        };
246        typedef std::deque<PassEntry*> PassQueue;
247
248        /// Map from texture projection name to index
249        typedef std::map<String, int> TextureProjectionMap;
250
251        /** Platform-independent file copy (destination folder must exist)
252                Maybe use Boost::filesystem if this gets out of hand
253        */
254        void copyFile(const String& src, const String& dest);
255
256}
257#endif
258
Note: See TracBrowser for help on using the repository browser.