[692] | 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 | #include "OgreHardwareVertexBuffer.h"
|
---|
| 50 |
|
---|
| 51 | #define OGRE_XSI_NUM_MESH_STEPS 200
|
---|
| 52 |
|
---|
| 53 | /// Useful function to convert an XSI CString to an Ogre String
|
---|
| 54 | inline Ogre::String XSItoOgre(const XSI::CString& xsistr)
|
---|
| 55 | {
|
---|
| 56 | // XSI CString is wide character
|
---|
| 57 |
|
---|
| 58 | if (xsistr.IsEmpty())
|
---|
| 59 | {
|
---|
| 60 | return Ogre::StringUtil::BLANK;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // first find out the size required
|
---|
| 64 | size_t c = ::wcstombs(0, xsistr.GetWideString(), 2048);
|
---|
| 65 | // temp character string (add one for terminator)
|
---|
| 66 | char* tmp = new char[c+1];
|
---|
| 67 | // do the real conversion
|
---|
| 68 | ::wcstombs(tmp, xsistr.GetWideString(), c);
|
---|
| 69 | tmp[c] = '\0';
|
---|
| 70 | Ogre::String ret(tmp);
|
---|
| 71 | delete [] tmp;
|
---|
| 72 |
|
---|
| 73 | return ret;
|
---|
| 74 | }
|
---|
| 75 | /// Useful function to convert an Ogre String to an XSI CString
|
---|
| 76 | inline XSI::CString OgretoXSI(const Ogre::String& str)
|
---|
| 77 | {
|
---|
| 78 | // XSI CString is wide character
|
---|
| 79 |
|
---|
| 80 | if (str.empty())
|
---|
| 81 | {
|
---|
| 82 | return XSI::CString();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | // first find out the size required
|
---|
| 86 | size_t c = ::mbstowcs(0, str.c_str(), 2048);
|
---|
| 87 | // temp character string (add one for terminator)
|
---|
| 88 | wchar_t* tmp = new wchar_t[c+1];
|
---|
| 89 | // do the real conversion
|
---|
| 90 | ::mbstowcs(tmp, str.c_str(), c);
|
---|
| 91 | tmp[c] = '\0';
|
---|
| 92 |
|
---|
| 93 | XSI::CString ret(tmp);
|
---|
| 94 | delete [] tmp;
|
---|
| 95 |
|
---|
| 96 | return ret;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | inline Ogre::Vector3 XSItoOgre(const XSI::MATH::CVector3& xsiVec)
|
---|
| 100 | {
|
---|
| 101 | return Ogre::Vector3(xsiVec.GetX(), xsiVec.GetY(), xsiVec.GetZ());
|
---|
| 102 | }
|
---|
| 103 | inline Ogre::Quaternion XSItoOgre(const XSI::MATH::CQuaternion& xsiQuat)
|
---|
| 104 | {
|
---|
| 105 | return Ogre::Quaternion(xsiQuat.GetW(), xsiQuat.GetX(), xsiQuat.GetY(), xsiQuat.GetZ());
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | inline Ogre::RGBA XSItoOgre(const XSI::CVertexColor& xsiColour)
|
---|
| 109 | {
|
---|
| 110 | Ogre::ColourValue col(xsiColour.r, xsiColour.g, xsiColour.b, xsiColour.a);
|
---|
| 111 | return Ogre::VertexElement::convertColourValue(col,
|
---|
| 112 | Ogre::VertexElement::getBestColourVertexElementType());
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | inline void LogOgreAndXSI(const Ogre::String& msg)
|
---|
| 116 | {
|
---|
| 117 | static XSI::Application app;
|
---|
| 118 | Ogre::LogManager::getSingleton().logMessage(msg);
|
---|
| 119 | app.LogMessage(OgretoXSI(msg));
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | inline void LogOgreAndXSI(const XSI::CString& msg)
|
---|
| 124 | {
|
---|
| 125 | static XSI::Application app;
|
---|
| 126 | Ogre::LogManager::getSingleton().logMessage(XSItoOgre(msg));
|
---|
| 127 | app.LogMessage(msg);
|
---|
| 128 |
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | namespace Ogre {
|
---|
| 133 |
|
---|
| 134 | class ProgressManager : public Singleton<ProgressManager>
|
---|
| 135 | {
|
---|
| 136 | protected:
|
---|
| 137 | XSI::ProgressBar mProgressBar;
|
---|
| 138 | size_t mNumberOfStages;
|
---|
| 139 | size_t mProgress;
|
---|
| 140 |
|
---|
| 141 | public:
|
---|
| 142 | ProgressManager(size_t numberOfStages);
|
---|
| 143 | virtual ~ProgressManager();
|
---|
| 144 |
|
---|
| 145 | void progress(void);
|
---|
| 146 |
|
---|
| 147 | static ProgressManager& getSingleton(void);
|
---|
| 148 | static ProgressManager* getSingletonPtr(void);
|
---|
| 149 |
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 | enum XSITrackType
|
---|
| 153 | {
|
---|
| 154 | XTT_POS_X = 0,
|
---|
| 155 | XTT_POS_Y = 1,
|
---|
| 156 | XTT_POS_Z = 2,
|
---|
| 157 | XTT_ROT_X = 3,
|
---|
| 158 | XTT_ROT_Y = 4,
|
---|
| 159 | XTT_ROT_Z = 5,
|
---|
| 160 | XTT_SCL_X = 6,
|
---|
| 161 | XTT_SCL_Y = 7,
|
---|
| 162 | XTT_SCL_Z = 8,
|
---|
| 163 | XTT_COUNT = 9
|
---|
| 164 | };
|
---|
| 165 | /** An entry for a Deformer - need original index because this will be boneID */
|
---|
| 166 | class DeformerEntry
|
---|
| 167 | {
|
---|
| 168 | public:
|
---|
| 169 | unsigned short boneID;
|
---|
| 170 | XSI::X3DObject obj;
|
---|
| 171 | String parentName;
|
---|
| 172 | StringVector childNames;
|
---|
| 173 | bool hasVertexAssignments;
|
---|
| 174 | bool parentIsChainEndEffector;
|
---|
| 175 | bool hasAnyTracks;
|
---|
| 176 | Bone* pBone;
|
---|
| 177 | bool ikSample;
|
---|
| 178 | double ikSampleInterval;
|
---|
| 179 | XSI::MATH::CTransformation initialXform;
|
---|
| 180 | // lists of action source items (probably only one per param?)
|
---|
| 181 | XSI::AnimationSourceItem xsiTrack[XTT_COUNT];
|
---|
| 182 |
|
---|
| 183 | DeformerEntry(unsigned short theboneID, XSI::X3DObject& theobj)
|
---|
| 184 | :boneID(theboneID), obj(theobj), hasVertexAssignments(false),
|
---|
| 185 | parentIsChainEndEffector(false), hasAnyTracks(false), pBone(0)
|
---|
| 186 |
|
---|
| 187 | {
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | };
|
---|
| 191 | /// Map from deformer name to deformer entry
|
---|
| 192 | typedef std::map<String,DeformerEntry*> DeformerMap;
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | /** An entry for animation; allows the userto split the timeline into
|
---|
| 196 | multiple separate animations.
|
---|
| 197 | */
|
---|
| 198 | struct AnimationEntry
|
---|
| 199 | {
|
---|
| 200 | String animationName;
|
---|
| 201 | long startFrame;
|
---|
| 202 | long endFrame;
|
---|
| 203 | double ikSampleInterval; // skeletal only
|
---|
| 204 | };
|
---|
| 205 | /// List of animations
|
---|
| 206 | typedef std::list<AnimationEntry> AnimationList;
|
---|
| 207 |
|
---|
| 208 | /** Record of an XSI GL shader material. */
|
---|
| 209 | struct MaterialEntry
|
---|
| 210 | {
|
---|
| 211 | String name;
|
---|
| 212 | XSI::Shader xsiShader;
|
---|
| 213 | };
|
---|
| 214 | /// Map from material name to material entry
|
---|
| 215 | typedef std::map<String, MaterialEntry*> MaterialMap;
|
---|
| 216 |
|
---|
| 217 | /** Record of XSI details that are to become a pass */
|
---|
| 218 | struct PassEntry
|
---|
| 219 | {
|
---|
| 220 | XSI::CRefArray shaders;
|
---|
| 221 | };
|
---|
| 222 | typedef std::deque<PassEntry*> PassQueue;
|
---|
| 223 |
|
---|
| 224 | /// Map from texture projection name to index
|
---|
| 225 | typedef std::map<String, int> TextureProjectionMap;
|
---|
| 226 |
|
---|
| 227 | /** Platform-independent file copy (destination folder must exist)
|
---|
| 228 | Maybe use Boost::filesystem if this gets out of hand
|
---|
| 229 | */
|
---|
| 230 | void copyFile(const String& src, const String& dest);
|
---|
| 231 |
|
---|
| 232 | }
|
---|
| 233 | #endif
|
---|
| 234 |
|
---|