1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | oExporter plugin Private Beta (see License.txt)
|
---|
4 |
|
---|
5 | FILE: ogreAnimationCompiler.h
|
---|
6 |
|
---|
7 | DESCRIPTION: Contains the OE_XMLScene reader (oe_scene)
|
---|
8 |
|
---|
9 | IMPLEMENTED BY: Lioric
|
---|
10 |
|
---|
11 | HISTORY:
|
---|
12 |
|
---|
13 | Original implementation by Lasse Tassing (Channex)
|
---|
14 | 2005 ITE ApS, Lasse Tassing
|
---|
15 |
|
---|
16 | *> Copyright (c) 2005, All Rights Reserved.
|
---|
17 | **********************************************************************/
|
---|
18 |
|
---|
19 | #include <OgreOSMScene.h>
|
---|
20 |
|
---|
21 | using namespace Ogre;
|
---|
22 |
|
---|
23 | enum {
|
---|
24 | SCENE_SKYPLANE = 1,
|
---|
25 | SCENE_SKYBOX,
|
---|
26 | SCENE_SKYDOME,
|
---|
27 | };
|
---|
28 |
|
---|
29 | #define ENABLE_LOGMANAGER LogManager::getSingleton().setLogDetail(LL_NORMAL);
|
---|
30 | #define DISABLE_LOGMANAGER LogManager::getSingleton().setLogDetail(static_cast<LoggingLevel>(0));
|
---|
31 |
|
---|
32 |
|
---|
33 | OSMScene::OSMScene(SceneManager* pSceneMgr, RenderWindow* win)
|
---|
34 | {
|
---|
35 | mSceneMgr = pSceneMgr;
|
---|
36 | mWindow = win;
|
---|
37 | //mXMLDoc = 0;
|
---|
38 | mCallbacks = 0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | OSMScene::~OSMScene(void)
|
---|
42 | {
|
---|
43 | /*
|
---|
44 | if(mXMLDoc)
|
---|
45 | delete mXMLDoc;
|
---|
46 | */
|
---|
47 | }
|
---|
48 |
|
---|
49 | // Init overloads - use either of them
|
---|
50 | bool OSMScene::initialise(const char* pszXMLFile, OSMSceneCallbacks* pCallbacks)
|
---|
51 | {
|
---|
52 | // Hook up callback interface
|
---|
53 | mCallbacks = pCallbacks;
|
---|
54 |
|
---|
55 | LogManager::getSingleton().logMessage("********************************");
|
---|
56 | LogManager::getSingleton().logMessage("** oScene Loader Lib **");
|
---|
57 | LogManager::getSingleton().logMessage("********************************");
|
---|
58 |
|
---|
59 | String msg("oSceneLoader: Loading '");
|
---|
60 | msg += pszXMLFile;
|
---|
61 | msg += "' file";
|
---|
62 | LogManager::getSingleton().logMessage(msg);
|
---|
63 |
|
---|
64 | // Create new XML document
|
---|
65 | mXMLDoc = TiXmlDocumentPtr(new TiXmlDocument());
|
---|
66 |
|
---|
67 | DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource(pszXMLFile);
|
---|
68 | if(!pStream->size())
|
---|
69 | {
|
---|
70 | mXMLDoc.setNull();
|
---|
71 |
|
---|
72 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
73 | "oSceneLoader: Empty scene file",
|
---|
74 | "OSMScene::initialise");
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 | size_t iSize = pStream->size();
|
---|
79 | char *pBuf = new char[iSize+1];
|
---|
80 | memset(pBuf, 0, iSize+1);
|
---|
81 | pStream->read(pBuf, iSize);
|
---|
82 | pStream.setNull();
|
---|
83 | mXMLDoc->Parse(pBuf);
|
---|
84 | delete[] pBuf;
|
---|
85 |
|
---|
86 | // check for errors
|
---|
87 | if(mXMLDoc->Error())
|
---|
88 | {
|
---|
89 | mXMLDoc.setNull();
|
---|
90 |
|
---|
91 | String errDesc = "oSceneLoader: Failed to load scene file, ";
|
---|
92 | msg += mXMLDoc->ErrorDesc();
|
---|
93 |
|
---|
94 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
|
---|
95 | errDesc.c_str(),
|
---|
96 | "OSMScene::initialise");
|
---|
97 | }
|
---|
98 |
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Declare all resources used in the scene
|
---|
103 | void OSMScene::declareResources(void)
|
---|
104 | {
|
---|
105 | if(!mXMLDoc.isNull())
|
---|
106 | {
|
---|
107 |
|
---|
108 | TiXmlElement* rootElem = mXMLDoc->RootElement();
|
---|
109 |
|
---|
110 | try
|
---|
111 | {
|
---|
112 | // Get mesh filename from entities
|
---|
113 | TiXmlElement *pMeshNode = rootElem->FirstChildElement("entities");
|
---|
114 | if(pMeshNode)
|
---|
115 | {
|
---|
116 | // Iterate all meshes, creating them.
|
---|
117 | for (TiXmlElement* pMeshElem = pMeshNode->FirstChildElement();
|
---|
118 | pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
|
---|
119 | {
|
---|
120 | // Declare mesh resource
|
---|
121 | const char *pszFileName = pMeshElem->Attribute("filename");
|
---|
122 | ResourceGroupManager::getSingleton().declareResource(pszFileName, "Mesh");
|
---|
123 | }
|
---|
124 | }
|
---|
125 | } catch(...)
|
---|
126 | {
|
---|
127 | }
|
---|
128 |
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Create scene, optionally attaching it to a parent node
|
---|
133 | bool OSMScene::createScene(Ogre::SceneNode* pParent)
|
---|
134 | {
|
---|
135 | if(!mXMLDoc.isNull())
|
---|
136 | {
|
---|
137 | String msg("oSceneLoader: Creating scene on '");
|
---|
138 | msg += pParent ? pParent->getName() : "Root";
|
---|
139 | msg += "' node";
|
---|
140 | LogManager::getSingleton().logMessage(msg);
|
---|
141 |
|
---|
142 | TiXmlElement* rootElem = mXMLDoc->RootElement();
|
---|
143 |
|
---|
144 | if(mSceneMgr == NULL)
|
---|
145 | {
|
---|
146 | if(rootElem->FirstChildElement("sceneManager"))
|
---|
147 | setSceneProperties(rootElem);
|
---|
148 | else
|
---|
149 | mSceneMgr = Root::getSingleton().createSceneManager(ST_GENERIC);
|
---|
150 | }
|
---|
151 |
|
---|
152 | if(pParent==NULL)
|
---|
153 | pParent=mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
154 |
|
---|
155 | TiXmlElement* list;
|
---|
156 |
|
---|
157 | try {
|
---|
158 | // Entities
|
---|
159 | list = rootElem->FirstChildElement("entities");
|
---|
160 | if(list)
|
---|
161 | createEntities(list, pParent);
|
---|
162 | } catch(...)
|
---|
163 | {
|
---|
164 | }
|
---|
165 |
|
---|
166 | try {
|
---|
167 | // lights
|
---|
168 | list = rootElem->FirstChildElement("lights");
|
---|
169 | if(list)
|
---|
170 | createLights(list, pParent);
|
---|
171 | } catch(...)
|
---|
172 | {
|
---|
173 | }
|
---|
174 |
|
---|
175 | try {
|
---|
176 | // cameras
|
---|
177 | list = rootElem->FirstChildElement("cameras");
|
---|
178 | if(list)
|
---|
179 | createCameras(list, pParent);
|
---|
180 | } catch(...)
|
---|
181 | {
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | LogManager::getSingleton().logMessage("********************************");
|
---|
186 | LogManager::getSingleton().logMessage("** oSceneLoader: Scene loaded **");
|
---|
187 | LogManager::getSingleton().logMessage("********************************");
|
---|
188 |
|
---|
189 | return true;
|
---|
190 | }
|
---|
191 |
|
---|
192 | return false;
|
---|
193 |
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | // Get list of cameras in this scene
|
---|
198 | OSMScene::CameraList& OSMScene::getCameraList(void)
|
---|
199 | {
|
---|
200 | return mCameras;
|
---|
201 | }
|
---|
202 |
|
---|
203 | // Get list of lights in this scene
|
---|
204 | OSMScene::LightList& OSMScene::getLightList(void)
|
---|
205 | {
|
---|
206 | return mLights;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Get list of lights in this scene
|
---|
210 | OSMScene::EntityList& OSMScene::getEntityList(void)
|
---|
211 | {
|
---|
212 | return mEntities;
|
---|
213 | }
|
---|
214 |
|
---|
215 | Ogre::SceneNode *OSMScene::createNode(TiXmlElement* pElem, Ogre::SceneNode* pSceneRoot)
|
---|
216 | {
|
---|
217 | SceneNode *pNode=0;
|
---|
218 |
|
---|
219 | // Try to find the parent node
|
---|
220 | const char *pszName = pElem->Attribute("name");
|
---|
221 | if(pszName == NULL) return NULL;
|
---|
222 |
|
---|
223 | // Check if this node has a parent
|
---|
224 | const char *pszParent = pElem->Attribute("parent");
|
---|
225 | if(pszParent == NULL)
|
---|
226 | {
|
---|
227 | // Check if the scene node has already been created by a child
|
---|
228 | DISABLE_LOGMANAGER
|
---|
229 |
|
---|
230 | try
|
---|
231 | {
|
---|
232 | pNode = mSceneMgr->getSceneNode(pszName);
|
---|
233 | } catch(...)
|
---|
234 | {
|
---|
235 | pNode = pSceneRoot->createChildSceneNode(pszName);
|
---|
236 | }
|
---|
237 |
|
---|
238 | ENABLE_LOGMANAGER
|
---|
239 |
|
---|
240 | } else
|
---|
241 | {
|
---|
242 | SceneNode *pParent=0;
|
---|
243 | DISABLE_LOGMANAGER
|
---|
244 |
|
---|
245 | try
|
---|
246 | {
|
---|
247 | // Try to find parent scenenode
|
---|
248 | pParent=mSceneMgr->getSceneNode(pszParent);
|
---|
249 | } catch(...)
|
---|
250 | {
|
---|
251 | // We try to create the parent node as child of root node.
|
---|
252 | // Later when the parent (hopefully) is created, we can adjust it,
|
---|
253 | // if it is child of another node.
|
---|
254 | pParent=pSceneRoot->createChildSceneNode(pszParent);
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 | try
|
---|
259 | {
|
---|
260 | // Check if the scene node has already been created by a child
|
---|
261 | // In this case we would have to change the parent.
|
---|
262 | pNode = mSceneMgr->getSceneNode(pszName);
|
---|
263 |
|
---|
264 | // Get old parent (probably scene root)
|
---|
265 | SceneNode *pOldParent=pNode->getParentSceneNode();
|
---|
266 |
|
---|
267 | // Remove this node
|
---|
268 | pOldParent->removeChild(pNode);
|
---|
269 |
|
---|
270 | // Insert us as child on the "real" parent
|
---|
271 | pParent->addChild(pNode);
|
---|
272 | } catch(...)
|
---|
273 | {
|
---|
274 | pNode = pParent->createChildSceneNode(pszName);
|
---|
275 | }
|
---|
276 |
|
---|
277 | ENABLE_LOGMANAGER
|
---|
278 | }
|
---|
279 |
|
---|
280 | // Position
|
---|
281 | TiXmlElement* posElem = pElem->FirstChildElement("position");
|
---|
282 | if(posElem)
|
---|
283 | {
|
---|
284 | Vector3 pos;
|
---|
285 | pos.x = StringConverter::parseReal(posElem->Attribute("x"));
|
---|
286 | pos.y = StringConverter::parseReal(posElem->Attribute("y"));
|
---|
287 | pos.z = StringConverter::parseReal(posElem->Attribute("z"));
|
---|
288 | pNode->setPosition(pos);
|
---|
289 | }
|
---|
290 |
|
---|
291 | // Rotation
|
---|
292 | TiXmlElement* rotElem = pElem->FirstChildElement("rotation");
|
---|
293 | if(rotElem)
|
---|
294 | {
|
---|
295 | pNode->setOrientation(
|
---|
296 | StringConverter::parseReal(rotElem->Attribute("w")),
|
---|
297 | StringConverter::parseReal(rotElem->Attribute("x")),
|
---|
298 | StringConverter::parseReal(rotElem->Attribute("y")),
|
---|
299 | StringConverter::parseReal(rotElem->Attribute("z")));
|
---|
300 |
|
---|
301 | }
|
---|
302 |
|
---|
303 | // Scale
|
---|
304 | TiXmlElement* scaleElem = pElem->FirstChildElement("scale");
|
---|
305 | if(scaleElem)
|
---|
306 | {
|
---|
307 | Vector3 scale;
|
---|
308 | scale.x = StringConverter::parseReal(scaleElem->Attribute("x"));
|
---|
309 | scale.y = StringConverter::parseReal(scaleElem->Attribute("y"));
|
---|
310 | scale.z = StringConverter::parseReal(scaleElem->Attribute("z"));
|
---|
311 | pNode->setScale(scale);
|
---|
312 | }
|
---|
313 |
|
---|
314 | // Notify
|
---|
315 | if(mCallbacks)
|
---|
316 | mCallbacks->OnNodeCreate(pNode, pElem);
|
---|
317 |
|
---|
318 | // Animation
|
---|
319 | TiXmlElement* animList = pElem->FirstChildElement("animations");
|
---|
320 | if(animList)
|
---|
321 | {
|
---|
322 | //
|
---|
323 | for (TiXmlElement* animElem = animList->FirstChildElement();
|
---|
324 | animElem != 0; animElem = animElem->NextSiblingElement())
|
---|
325 | {
|
---|
326 | // Get name of animation
|
---|
327 | const char *pszName = animElem->Attribute("name");
|
---|
328 |
|
---|
329 | Animation *pAnim = 0;
|
---|
330 | DISABLE_LOGMANAGER
|
---|
331 | try
|
---|
332 | {
|
---|
333 | pAnim=mSceneMgr->getAnimation(pszName);
|
---|
334 | } catch(...)
|
---|
335 | {
|
---|
336 | }
|
---|
337 | ENABLE_LOGMANAGER
|
---|
338 |
|
---|
339 | // If this animation has not been created yet, we create it
|
---|
340 | if(pAnim == 0)
|
---|
341 | {
|
---|
342 | float fLength = StringConverter::parseReal(animElem->Attribute("length"));
|
---|
343 | pAnim = mSceneMgr->createAnimation(pszName, fLength);
|
---|
344 | pAnim->setInterpolationMode(Animation::IM_LINEAR);
|
---|
345 | }
|
---|
346 |
|
---|
347 | // Create animation track for this node
|
---|
348 | NodeAnimationTrack *pTrack = pAnim->createNodeTrack(pAnim->getNumNodeTracks()+1, pNode);
|
---|
349 |
|
---|
350 | // Iterate all keyframes for this node
|
---|
351 | for (TiXmlElement* pKeyframeElem = animElem->FirstChildElement();
|
---|
352 | pKeyframeElem != 0; pKeyframeElem = pKeyframeElem->NextSiblingElement())
|
---|
353 | {
|
---|
354 | float fTime=StringConverter::parseReal(pKeyframeElem->Attribute("time"));
|
---|
355 | TransformKeyFrame *pKeyFrame = pTrack->createNodeKeyFrame(fTime);
|
---|
356 |
|
---|
357 | // Position
|
---|
358 | TiXmlElement* posElem = pKeyframeElem->FirstChildElement("position");
|
---|
359 | if(posElem)
|
---|
360 | {
|
---|
361 | Vector3 trans;
|
---|
362 | trans.x = StringConverter::parseReal(posElem->Attribute("x"));
|
---|
363 | trans.y = StringConverter::parseReal(posElem->Attribute("y"));
|
---|
364 | trans.z = StringConverter::parseReal(posElem->Attribute("z"));
|
---|
365 | pKeyFrame->setTranslate(trans);
|
---|
366 | }
|
---|
367 |
|
---|
368 | // Rotation
|
---|
369 | TiXmlElement* rotElem = pKeyframeElem->FirstChildElement("rotation");
|
---|
370 | if(rotElem)
|
---|
371 | {
|
---|
372 | Quaternion qRot;
|
---|
373 | qRot.x = StringConverter::parseReal(rotElem->Attribute("x"));
|
---|
374 | qRot.y = StringConverter::parseReal(rotElem->Attribute("y"));
|
---|
375 | qRot.z = StringConverter::parseReal(rotElem->Attribute("z"));
|
---|
376 | qRot.w = StringConverter::parseReal(rotElem->Attribute("w"));
|
---|
377 | pKeyFrame->setRotation(qRot);
|
---|
378 | }
|
---|
379 |
|
---|
380 | // Scale
|
---|
381 | TiXmlElement* scaleElem = pKeyframeElem->FirstChildElement("scale");
|
---|
382 | if(scaleElem)
|
---|
383 | {
|
---|
384 | Vector3 scale;
|
---|
385 | scale.x = StringConverter::parseReal(scaleElem->Attribute("x"));
|
---|
386 | scale.y = StringConverter::parseReal(scaleElem->Attribute("y"));
|
---|
387 | scale.z = StringConverter::parseReal(scaleElem->Attribute("z"));
|
---|
388 | pKeyFrame->setScale(scale);
|
---|
389 | }
|
---|
390 | }
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 | return pNode;
|
---|
395 | }
|
---|
396 |
|
---|
397 | // Set Scene Properties
|
---|
398 | void OSMScene::setSceneProperties(TiXmlElement* sceneProp) {
|
---|
399 | assert(sceneProp);
|
---|
400 |
|
---|
401 | // Scene manager
|
---|
402 | TiXmlElement* sceneMgrElem = sceneProp->FirstChildElement("sceneManager");
|
---|
403 | int type = Ogre::StringConverter::parseInt(sceneMgrElem->Attribute("type"));
|
---|
404 | Ogre::SceneType sceneType = static_cast<Ogre::SceneType>(1 << (type - 1));
|
---|
405 | mSceneMgr = Ogre::Root::getSingleton().createSceneManager(sceneType);
|
---|
406 | assert(mSceneMgr);
|
---|
407 |
|
---|
408 | const char* worldGeometry = sceneMgrElem->Attribute("worldGeometry");
|
---|
409 | if(worldGeometry != NULL)
|
---|
410 | mSceneMgr->setWorldGeometry(worldGeometry);
|
---|
411 |
|
---|
412 | // Background Color
|
---|
413 | TiXmlElement* colorElem = sceneProp->FirstChildElement("bkgcolor");
|
---|
414 | if(colorElem && mWindow)
|
---|
415 | {
|
---|
416 | Ogre::ColourValue color;
|
---|
417 | color.r = StringConverter::parseReal(colorElem->Attribute("r"));
|
---|
418 | color.g = StringConverter::parseReal(colorElem->Attribute("g"));
|
---|
419 | color.b = StringConverter::parseReal(colorElem->Attribute("b"));
|
---|
420 |
|
---|
421 | mWindow->getViewport(0)->setBackgroundColour(color);
|
---|
422 | }
|
---|
423 |
|
---|
424 | // Ambient light Color
|
---|
425 | colorElem = sceneProp->FirstChildElement("lightColor");
|
---|
426 | if(colorElem)
|
---|
427 | {
|
---|
428 | Ogre::ColourValue color;
|
---|
429 | color.r = StringConverter::parseReal(colorElem->Attribute("r"));
|
---|
430 | color.g = StringConverter::parseReal(colorElem->Attribute("g"));
|
---|
431 | color.b = StringConverter::parseReal(colorElem->Attribute("b"));
|
---|
432 |
|
---|
433 | mSceneMgr->setAmbientLight(color);
|
---|
434 | }
|
---|
435 |
|
---|
436 | // Scene shadows
|
---|
437 | TiXmlElement* shadowsElem = sceneProp->FirstChildElement("shadowTechnique");
|
---|
438 | if(shadowsElem)
|
---|
439 | {
|
---|
440 | int type = Ogre::StringConverter::parseInt(shadowsElem->Attribute("type"));
|
---|
441 | Ogre::ShadowTechnique shadowType = static_cast<Ogre::ShadowTechnique>(type);
|
---|
442 |
|
---|
443 | mSceneMgr->setShadowTechnique(shadowType);
|
---|
444 |
|
---|
445 | int tex_size = Ogre::StringConverter::parseInt(shadowsElem->Attribute("tex_size"));
|
---|
446 | int tex_count = Ogre::StringConverter::parseInt(shadowsElem->Attribute("tex_count"));
|
---|
447 |
|
---|
448 | mSceneMgr->setShadowTextureSettings(tex_size, tex_count);
|
---|
449 |
|
---|
450 | // Shadow Color
|
---|
451 | TiXmlElement* colorElem = shadowsElem->FirstChildElement("color");
|
---|
452 | if(colorElem)
|
---|
453 | {
|
---|
454 | Ogre::ColourValue color;
|
---|
455 | color.r = StringConverter::parseReal(colorElem->Attribute("r"));
|
---|
456 | color.g = StringConverter::parseReal(colorElem->Attribute("g"));
|
---|
457 | color.b = StringConverter::parseReal(colorElem->Attribute("b"));
|
---|
458 |
|
---|
459 | mSceneMgr->setShadowColour(color);
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | // Scene sky
|
---|
464 | TiXmlElement* skyElem = sceneProp->FirstChildElement("skyTechnique");
|
---|
465 | if(skyElem)
|
---|
466 | {
|
---|
467 | int type = Ogre::StringConverter::parseInt(skyElem->Attribute("type"));
|
---|
468 | Ogre::String materialName = skyElem->Attribute("material");
|
---|
469 |
|
---|
470 | if(materialName != " ") {
|
---|
471 | bool drawFirst = Ogre::StringConverter::parseBool(skyElem->Attribute("drawFirst"));
|
---|
472 | float tiling = Ogre::StringConverter::parseReal(skyElem->Attribute("tiling"));
|
---|
473 | float scale = Ogre::StringConverter::parseReal(skyElem->Attribute("scale"));
|
---|
474 | float dist = Ogre::StringConverter::parseReal(skyElem->Attribute("dist"));
|
---|
475 | float bow = Ogre::StringConverter::parseReal(skyElem->Attribute("bow"));
|
---|
476 | int xSegments = Ogre::StringConverter::parseInt(skyElem->Attribute("xSegments"));
|
---|
477 | int ySegments = Ogre::StringConverter::parseInt(skyElem->Attribute("ySegments"));
|
---|
478 | Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
|
---|
479 | Ogre::Plane plane;
|
---|
480 | plane.d = dist;
|
---|
481 | plane.normal = -(Ogre::Vector3::UNIT_Y);
|
---|
482 |
|
---|
483 | switch(type) {
|
---|
484 |
|
---|
485 | case SCENE_SKYPLANE:
|
---|
486 |
|
---|
487 | mSceneMgr->setSkyPlane(true, plane, materialName, scale,
|
---|
488 | tiling, drawFirst, bow, xSegments, ySegments);
|
---|
489 |
|
---|
490 | mSceneMgr->setSkyBox(false, "");
|
---|
491 | mSceneMgr->setSkyDome(false, "");
|
---|
492 |
|
---|
493 | break;
|
---|
494 |
|
---|
495 | case SCENE_SKYBOX:
|
---|
496 |
|
---|
497 | mSceneMgr->setSkyBox(true, materialName, dist, drawFirst, quat);
|
---|
498 | mSceneMgr->setSkyPlane(false, plane, "");
|
---|
499 | mSceneMgr->setSkyDome(false, "");
|
---|
500 |
|
---|
501 | break;
|
---|
502 |
|
---|
503 | case SCENE_SKYDOME:
|
---|
504 |
|
---|
505 | mSceneMgr->setSkyDome(true, materialName, bow, tiling, dist,
|
---|
506 | drawFirst, quat, xSegments, ySegments);
|
---|
507 |
|
---|
508 | mSceneMgr->setSkyPlane(false, plane, "");
|
---|
509 | mSceneMgr->setSkyBox(false, "");
|
---|
510 |
|
---|
511 | break;
|
---|
512 |
|
---|
513 | }
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 | }
|
---|
518 |
|
---|
519 | // Create all entities in scene
|
---|
520 | void OSMScene::createEntities(TiXmlElement* pEntityNode, Ogre::SceneNode* pSceneRoot)
|
---|
521 | {
|
---|
522 | // Iterate all meshes, creating them.
|
---|
523 | for (TiXmlElement* pMeshElem = pEntityNode->FirstChildElement();
|
---|
524 | pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
|
---|
525 | {
|
---|
526 | // Ogre could cast an exception, in which case we just try to
|
---|
527 | // continue reading the other meshes
|
---|
528 | try
|
---|
529 | {
|
---|
530 | const char *pszName = pMeshElem->Attribute("name");
|
---|
531 | const char *pszFileName = pMeshElem->Attribute("filename");
|
---|
532 |
|
---|
533 | // try to create the mesh
|
---|
534 | Entity *pEntity = mSceneMgr->createEntity(pszName, pszFileName);
|
---|
535 | if(pEntity==0) continue;
|
---|
536 |
|
---|
537 | // Check if the object should cast shadows
|
---|
538 | const char *pszCastShadows=pMeshElem->Attribute("CastShadows");
|
---|
539 | if(pszCastShadows && stricmp(pszCastShadows, "no")==0)
|
---|
540 | pEntity->setCastShadows(false);
|
---|
541 | else
|
---|
542 | pEntity->setCastShadows(true);
|
---|
543 |
|
---|
544 | // Create node with full information
|
---|
545 | SceneNode *pObjNode=createNode(pMeshElem, pSceneRoot);
|
---|
546 |
|
---|
547 | // Attach the mesh entity to node
|
---|
548 | pObjNode->attachObject(pEntity);
|
---|
549 |
|
---|
550 | // Notify
|
---|
551 | if(mCallbacks)
|
---|
552 | mCallbacks->OnEntityCreate(pEntity, pMeshElem);
|
---|
553 |
|
---|
554 | // Add to entity list
|
---|
555 | mEntities.push_back(pEntity);
|
---|
556 | } catch(...)
|
---|
557 | {
|
---|
558 | continue;
|
---|
559 | }
|
---|
560 | }
|
---|
561 | }
|
---|
562 |
|
---|
563 | // Create all Lights in scene
|
---|
564 | void OSMScene::createLights(TiXmlElement* pLightNode, Ogre::SceneNode* pSceneRoot)
|
---|
565 | {
|
---|
566 | // Iterate all Lights, creating them. We do not attach them yet, since
|
---|
567 | // we need to make sure all potential parent entities have been created.
|
---|
568 | for (TiXmlElement* pLightElem = pLightNode->FirstChildElement();
|
---|
569 | pLightElem != 0; pLightElem = pLightElem->NextSiblingElement())
|
---|
570 | {
|
---|
571 | // Ogre could cast an exception, in which case we just try to
|
---|
572 | // continue reading the other Lights
|
---|
573 | try
|
---|
574 | {
|
---|
575 | const char *pszName = pLightElem->Attribute("name");
|
---|
576 |
|
---|
577 | Light *pLight = mSceneMgr->createLight(pszName);
|
---|
578 | if(pLight==0) continue;
|
---|
579 |
|
---|
580 | // Figure out which type of light we are using
|
---|
581 | const char *pszType = pLightElem->Attribute("type");
|
---|
582 | if(stricmp(pszType, "omni")==0)
|
---|
583 | {
|
---|
584 | pLight->setType(Light::LT_POINT);
|
---|
585 | } else if(stricmp(pszType, "spot")==0)
|
---|
586 | {
|
---|
587 | pLight->setType(Light::LT_SPOTLIGHT);
|
---|
588 | pLight->setSpotlightRange(
|
---|
589 | Degree(StringConverter::parseReal(pLightElem->Attribute("hotspot"))),
|
---|
590 | Degree(StringConverter::parseReal(pLightElem->Attribute("falloff"))));
|
---|
591 | pLight->setDirection(0,0,-1);
|
---|
592 |
|
---|
593 | } else if(stricmp(pszType, "directional")==0)
|
---|
594 | {
|
---|
595 | pLight->setType(Light::LT_DIRECTIONAL);
|
---|
596 | }
|
---|
597 |
|
---|
598 | // Check if the light should be on
|
---|
599 | const char *pszOn = pLightElem->Attribute("on");
|
---|
600 | if(pszOn!=0 && stricmp(pszOn, "true")==0)
|
---|
601 | pLight->setVisible(true);
|
---|
602 | else
|
---|
603 | pLight->setVisible(false);
|
---|
604 |
|
---|
605 | // Check if the object should cast shadows
|
---|
606 | const char *pszCastShadows = pLightElem->Attribute("CastShadows");
|
---|
607 | if(pszCastShadows && stricmp(pszCastShadows, "no")==0)
|
---|
608 | pLight->setCastShadows(false);
|
---|
609 | else
|
---|
610 | pLight->setCastShadows(true);
|
---|
611 |
|
---|
612 | // Diffuse Color
|
---|
613 | TiXmlElement* colorElem = pLightElem->FirstChildElement("color");
|
---|
614 | if(colorElem)
|
---|
615 | {
|
---|
616 | pLight->setDiffuseColour(
|
---|
617 | StringConverter::parseReal(colorElem->Attribute("r")),
|
---|
618 | StringConverter::parseReal(colorElem->Attribute("g")),
|
---|
619 | StringConverter::parseReal(colorElem->Attribute("b")));
|
---|
620 | }
|
---|
621 |
|
---|
622 | // Specular Color
|
---|
623 | TiXmlElement* specularElem = pLightElem->FirstChildElement("specular");
|
---|
624 | if(specularElem)
|
---|
625 | {
|
---|
626 | pLight->setSpecularColour(
|
---|
627 | StringConverter::parseReal(specularElem->Attribute("r")),
|
---|
628 | StringConverter::parseReal(specularElem->Attribute("g")),
|
---|
629 | StringConverter::parseReal(specularElem->Attribute("b")));
|
---|
630 | }
|
---|
631 |
|
---|
632 | // Attenuation
|
---|
633 | TiXmlElement* attenElem = pLightElem->FirstChildElement("attenuation");
|
---|
634 | if(attenElem) {
|
---|
635 | pLight->setAttenuation(
|
---|
636 | StringConverter::parseReal(attenElem->Attribute("range")),
|
---|
637 | StringConverter::parseReal(attenElem->Attribute("constant")),
|
---|
638 | StringConverter::parseReal(attenElem->Attribute("linear")),
|
---|
639 | StringConverter::parseReal(attenElem->Attribute("quadratic")));
|
---|
640 | }
|
---|
641 |
|
---|
642 | // Create node with full information
|
---|
643 | SceneNode *pLightNode=createNode(pLightElem, pSceneRoot);
|
---|
644 |
|
---|
645 | // Attach the Light entity to node
|
---|
646 | pLightNode->attachObject(pLight);
|
---|
647 |
|
---|
648 | // Target
|
---|
649 | TiXmlElement* targetElem=pLightElem->FirstChildElement("target");
|
---|
650 | if(targetElem)
|
---|
651 | {
|
---|
652 | // Create node with full information
|
---|
653 | SceneNode *pTargetNode=createNode(targetElem, pSceneRoot);
|
---|
654 | pLightNode->setAutoTracking(true, pTargetNode);
|
---|
655 | }
|
---|
656 |
|
---|
657 | // Notify
|
---|
658 | if(mCallbacks)
|
---|
659 | mCallbacks->OnLightCreate(pLight, pLightElem);
|
---|
660 |
|
---|
661 | // Add to light list
|
---|
662 | mLights.push_back(pLight);
|
---|
663 | } catch(...)
|
---|
664 | {
|
---|
665 | continue;
|
---|
666 | }
|
---|
667 | }
|
---|
668 | }
|
---|
669 |
|
---|
670 | // Create all Cameras in scene
|
---|
671 | void OSMScene::createCameras(TiXmlElement* pCameraNode, Ogre::SceneNode* pSceneRoot)
|
---|
672 | {
|
---|
673 | // Iterate all Cameras, creating them. We do not attach them yet, since
|
---|
674 | // we need to make sure all potential parent entities have been created.
|
---|
675 | for (TiXmlElement* pCameraElem = pCameraNode->FirstChildElement();
|
---|
676 | pCameraElem != 0; pCameraElem = pCameraElem->NextSiblingElement())
|
---|
677 | {
|
---|
678 | // Ogre could cast an exception, in which case we just try to
|
---|
679 | // continue reading the other Cameras
|
---|
680 | try
|
---|
681 | {
|
---|
682 | const char *pszName = pCameraElem->Attribute("name");
|
---|
683 |
|
---|
684 | // Create camera
|
---|
685 | Camera *pCamera=mSceneMgr->createCamera(pszName);
|
---|
686 | if(pCamera==0) continue;
|
---|
687 |
|
---|
688 | // Set Field of View on camera
|
---|
689 | pCamera->setFOVy(Radian(StringConverter::parseReal(pCameraElem->Attribute("FOV"))));
|
---|
690 | pCamera->setNearClipDistance(5);
|
---|
691 |
|
---|
692 | // Create node with full information
|
---|
693 | SceneNode *pCameraNode=createNode(pCameraElem, pSceneRoot);
|
---|
694 |
|
---|
695 | // Attach the Camera entity to node
|
---|
696 | pCameraNode->attachObject(pCamera);
|
---|
697 |
|
---|
698 | // Target
|
---|
699 | TiXmlElement* targetElem=pCameraElem->FirstChildElement("target");
|
---|
700 | if(targetElem)
|
---|
701 | {
|
---|
702 | // Create node with full information
|
---|
703 | SceneNode *pTargetNode=createNode(targetElem, pSceneRoot);
|
---|
704 | pCameraNode->setAutoTracking(true, pTargetNode);
|
---|
705 | }
|
---|
706 |
|
---|
707 | // Notify
|
---|
708 | if(mCallbacks)
|
---|
709 | mCallbacks->OnCameraCreate(pCamera, pCameraElem);
|
---|
710 |
|
---|
711 | // Add to camera list
|
---|
712 | mCameras.push_back(pCamera);
|
---|
713 | } catch(...)
|
---|
714 | {
|
---|
715 | continue;
|
---|
716 | }
|
---|
717 | }
|
---|
718 | } |
---|