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