-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDotSceneLoader.cpp
888 lines (738 loc) · 23.7 KB
/
DotSceneLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
/*
* OpenHMD - Free and Open Source API and drivers for immersive technology.
* Copyright (C) 2013 Fredrik Hultin.
* Copyright (C) 2013 Jakob Bornecrantz.
* OpenHMDDemo is designed and written by Joey Ferwerda from Thorworks game development studio.
* Dotsceneloader contributed by the Ogre community
* Distributed under the Boost 1.0 licence, see LICENSE for full text.
*/
#include "DotSceneLoader.h"
#include "tinyxml.h"
#include <Ogre.h>
using namespace std;
using namespace Ogre;
void DotSceneLoader::parseDotScene(const String &SceneName, const String &groupName, SceneManager *yourSceneMgr, SceneNode *pAttachNode, const String &sPrependNode)
{
// set up shared object values
m_sGroupName = groupName;
mSceneMgr = yourSceneMgr;
m_sPrependNode = sPrependNode;
staticObjects.clear();
dynamicObjects.clear();
TiXmlDocument *XMLDoc = 0;
TiXmlElement *XMLRoot;
try
{
// Strip the path
Ogre::String basename, path;
Ogre::StringUtil::splitFilename(SceneName, basename, path);
DataStreamPtr pStream = ResourceGroupManager::getSingleton().
openResource( basename, groupName );
//DataStreamPtr pStream = ResourceGroupManager::getSingleton().
// openResource( SceneName, groupName );
String data = pStream->getAsString();
// Open the .scene File
XMLDoc = new TiXmlDocument();
XMLDoc->Parse( data.c_str() );
pStream->close();
pStream.setNull();
if( XMLDoc->Error() )
{
//We'll just log, and continue on gracefully
LogManager::getSingleton().logMessage("[DotSceneLoader] The TiXmlDocument reported an error");
delete XMLDoc;
return;
}
}
catch(...)
{
//We'll just log, and continue on gracefully
LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating TiXmlDocument");
delete XMLDoc;
return;
}
// Validate the File
XMLRoot = XMLDoc->RootElement();
if( String( XMLRoot->Value()) != "scene" ) {
LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" );
delete XMLDoc;
return;
}
// figure out where to attach any nodes we create
mAttachNode = pAttachNode;
if(!mAttachNode)
mAttachNode = mSceneMgr->getRootSceneNode();
// Process the scene
processScene(XMLRoot);
// Close the XML File
delete XMLDoc;
}
void DotSceneLoader::processScene(TiXmlElement *XMLRoot)
{
// Process the scene parameters
String version = getAttrib(XMLRoot, "formatVersion", "unknown");
String message = "[DotSceneLoader] Parsing dotScene file with version " + version;
if(XMLRoot->Attribute("ID"))
message += ", id " + String(XMLRoot->Attribute("ID"));
if(XMLRoot->Attribute("sceneManager"))
message += ", scene manager " + String(XMLRoot->Attribute("sceneManager"));
if(XMLRoot->Attribute("minOgreVersion"))
message += ", min. Ogre version " + String(XMLRoot->Attribute("minOgreVersion"));
if(XMLRoot->Attribute("author"))
message += ", author " + String(XMLRoot->Attribute("author"));
LogManager::getSingleton().logMessage(message);
TiXmlElement *pElement;
// Process nodes (?)
pElement = XMLRoot->FirstChildElement("nodes");
if(pElement)
processNodes(pElement);
// Process externals (?)
pElement = XMLRoot->FirstChildElement("externals");
if(pElement)
processExternals(pElement);
// Process environment (?)
pElement = XMLRoot->FirstChildElement("environment");
if(pElement)
processEnvironment(pElement);
// Process terrain (?)
pElement = XMLRoot->FirstChildElement("terrain");
if(pElement)
processTerrain(pElement);
// Process userDataReference (?)
pElement = XMLRoot->FirstChildElement("userDataReference");
if(pElement)
processUserDataReference(pElement);
// Process octree (?)
pElement = XMLRoot->FirstChildElement("octree");
if(pElement)
processOctree(pElement);
// Process light (?)
pElement = XMLRoot->FirstChildElement("light");
if(pElement)
processLight(pElement);
// Process camera (?)
pElement = XMLRoot->FirstChildElement("camera");
if(pElement)
processCamera(pElement);
}
void DotSceneLoader::processNodes(TiXmlElement *XMLNode)
{
TiXmlElement *pElement;
// Process node (*)
pElement = XMLNode->FirstChildElement("node");
while(pElement)
{
processNode(pElement);
pElement = pElement->NextSiblingElement("node");
}
// Process position (?)
pElement = XMLNode->FirstChildElement("position");
if(pElement)
{
mAttachNode->setPosition(parseVector3(pElement));
mAttachNode->setInitialState();
}
// Process rotation (?)
pElement = XMLNode->FirstChildElement("rotation");
if(pElement)
{
mAttachNode->setOrientation(parseQuaternion(pElement));
mAttachNode->setInitialState();
}
// Process scale (?)
pElement = XMLNode->FirstChildElement("scale");
if(pElement)
{
mAttachNode->setScale(parseVector3(pElement));
mAttachNode->setInitialState();
}
}
void DotSceneLoader::processExternals(TiXmlElement *XMLNode)
{
//! @todo Implement this
}
void DotSceneLoader::processEnvironment(TiXmlElement *XMLNode)
{
TiXmlElement *pElement;
// Process fog (?)
pElement = XMLNode->FirstChildElement("fog");
if(pElement)
processFog(pElement);
// Process skyBox (?)
pElement = XMLNode->FirstChildElement("skyBox");
if(pElement)
processSkyBox(pElement);
// Process skyDome (?)
pElement = XMLNode->FirstChildElement("skyDome");
if(pElement)
processSkyDome(pElement);
// Process skyPlane (?)
pElement = XMLNode->FirstChildElement("skyPlane");
if(pElement)
processSkyPlane(pElement);
// Process clipping (?)
pElement = XMLNode->FirstChildElement("clipping");
if(pElement)
processClipping(pElement);
// Process colourAmbient (?)
pElement = XMLNode->FirstChildElement("colourAmbient");
if(pElement)
mSceneMgr->setAmbientLight(parseColour(pElement));
// Process colourBackground (?)
//! @todo Set the background colour of all viewports (RenderWindow has to be provided then)
pElement = XMLNode->FirstChildElement("colourBackground");
if(pElement)
;//mSceneMgr->set(parseColour(pElement));
// Process userDataReference (?)
pElement = XMLNode->FirstChildElement("userDataReference");
if(pElement)
processUserDataReference(pElement);
}
void DotSceneLoader::processTerrain(TiXmlElement *XMLNode)
{
//! @todo Implement this
}
void DotSceneLoader::processUserDataReference(TiXmlElement *XMLNode, SceneNode *pParent)
{
//! @todo Implement this
}
void DotSceneLoader::processOctree(TiXmlElement *XMLNode)
{
//! @todo Implement this
}
void DotSceneLoader::processLight(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
// Create the light
Light *pLight = mSceneMgr->createLight(name);
if(pParent)
pParent->attachObject(pLight);
String sValue = getAttrib(XMLNode, "type");
if(sValue == "point")
pLight->setType(Light::LT_POINT);
else if(sValue == "directional")
pLight->setType(Light::LT_DIRECTIONAL);
else if(sValue == "spot")
pLight->setType(Light::LT_SPOTLIGHT);
else if(sValue == "radPoint")
pLight->setType(Light::LT_POINT);
pLight->setVisible(getAttribBool(XMLNode, "visible", true));
pLight->setCastShadows(getAttribBool(XMLNode, "castShadows", true));
TiXmlElement *pElement;
// Process position (?)
pElement = XMLNode->FirstChildElement("position");
if(pElement)
pLight->setPosition(parseVector3(pElement));
// Process normal (?)
pElement = XMLNode->FirstChildElement("normal");
if(pElement)
pLight->setDirection(parseVector3(pElement));
// Process colourDiffuse (?)
pElement = XMLNode->FirstChildElement("colourDiffuse");
if(pElement)
pLight->setDiffuseColour(parseColour(pElement));
// Process colourSpecular (?)
pElement = XMLNode->FirstChildElement("colourSpecular");
if(pElement)
pLight->setSpecularColour(parseColour(pElement));
// Process lightRange (?)
pElement = XMLNode->FirstChildElement("lightRange");
if(pElement)
processLightRange(pElement, pLight);
// Process lightAttenuation (?)
pElement = XMLNode->FirstChildElement("lightAttenuation");
if(pElement)
processLightAttenuation(pElement, pLight);
// Process userDataReference (?)
pElement = XMLNode->FirstChildElement("userDataReference");
if(pElement)
;//processUserDataReference(pElement, pLight);
}
void DotSceneLoader::processCamera(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
Real fov = getAttribReal(XMLNode, "fov", 45);
Real aspectRatio = getAttribReal(XMLNode, "aspectRatio", 1.3333);
String projectionType = getAttrib(XMLNode, "projectionType", "perspective");
// Create the camera
Camera *pCamera = mSceneMgr->createCamera(name);
if(pParent)
pParent->attachObject(pCamera);
// Set the field-of-view
//! @todo Is this always in degrees?
pCamera->setFOVy(Ogre::Degree(fov));
// Set the aspect ratio
pCamera->setAspectRatio(aspectRatio);
// Set the projection type
if(projectionType == "perspective")
pCamera->setProjectionType(PT_PERSPECTIVE);
else if(projectionType == "orthographic")
pCamera->setProjectionType(PT_ORTHOGRAPHIC);
TiXmlElement *pElement;
// Process clipping (?)
pElement = XMLNode->FirstChildElement("clipping");
if(pElement)
{
Real nearDist = getAttribReal(pElement, "near");
pCamera->setNearClipDistance(nearDist);
Real farDist = getAttribReal(pElement, "far");
pCamera->setFarClipDistance(farDist);
}
// Process position (?)
pElement = XMLNode->FirstChildElement("position");
if(pElement)
pCamera->setPosition(parseVector3(pElement));
// Process rotation (?)
pElement = XMLNode->FirstChildElement("rotation");
if(pElement)
pCamera->setOrientation(parseQuaternion(pElement));
// Process normal (?)
pElement = XMLNode->FirstChildElement("normal");
if(pElement)
;//!< @todo What to do with this element?
// Process lookTarget (?)
pElement = XMLNode->FirstChildElement("lookTarget");
if(pElement)
;//!< @todo Implement the camera look target
// Process trackTarget (?)
pElement = XMLNode->FirstChildElement("trackTarget");
if(pElement)
;//!< @todo Implement the camera track target
// Process userDataReference (?)
pElement = XMLNode->FirstChildElement("userDataReference");
if(pElement)
;//!< @todo Implement the camera user data reference
}
void DotSceneLoader::processNode(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Construct the node's name
String name = m_sPrependNode + getAttrib(XMLNode, "name");
// Create the scene node
SceneNode *pNode;
if(name.empty())
{
// Let Ogre choose the name
if(pParent)
pNode = pParent->createChildSceneNode();
else
pNode = mAttachNode->createChildSceneNode();
}
else
{
// Provide the name
if(pParent)
pNode = pParent->createChildSceneNode(name);
else
pNode = mAttachNode->createChildSceneNode(name);
}
// Process other attributes
String id = getAttrib(XMLNode, "id");
bool isTarget = getAttribBool(XMLNode, "isTarget");
TiXmlElement *pElement;
// Process position (?)
pElement = XMLNode->FirstChildElement("position");
if(pElement)
{
pNode->setPosition(parseVector3(pElement));
pNode->setInitialState();
}
// Process rotation (?)
pElement = XMLNode->FirstChildElement("rotation");
if(pElement)
{
pNode->setOrientation(parseQuaternion(pElement));
pNode->setInitialState();
}
// Process scale (?)
pElement = XMLNode->FirstChildElement("scale");
if(pElement)
{
pNode->setScale(parseVector3(pElement));
pNode->setInitialState();
}
// Process lookTarget (?)
pElement = XMLNode->FirstChildElement("lookTarget");
if(pElement)
processLookTarget(pElement, pNode);
// Process trackTarget (?)
pElement = XMLNode->FirstChildElement("trackTarget");
if(pElement)
processTrackTarget(pElement, pNode);
// Process node (*)
pElement = XMLNode->FirstChildElement("node");
while(pElement)
{
processNode(pElement, pNode);
pElement = pElement->NextSiblingElement("node");
}
// Process entity (*)
pElement = XMLNode->FirstChildElement("entity");
while(pElement)
{
processEntity(pElement, pNode);
pElement = pElement->NextSiblingElement("entity");
}
// Process light (*)
pElement = XMLNode->FirstChildElement("light");
while(pElement)
{
processLight(pElement, pNode);
pElement = pElement->NextSiblingElement("light");
}
// Process camera (*)
pElement = XMLNode->FirstChildElement("camera");
while(pElement)
{
processCamera(pElement, pNode);
pElement = pElement->NextSiblingElement("camera");
}
// Process particleSystem (*)
pElement = XMLNode->FirstChildElement("particleSystem");
while(pElement)
{
processParticleSystem(pElement, pNode);
pElement = pElement->NextSiblingElement("particleSystem");
}
// Process billboardSet (*)
pElement = XMLNode->FirstChildElement("billboardSet");
while(pElement)
{
processBillboardSet(pElement, pNode);
pElement = pElement->NextSiblingElement("billboardSet");
}
// Process plane (*)
pElement = XMLNode->FirstChildElement("plane");
while(pElement)
{
processPlane(pElement, pNode);
pElement = pElement->NextSiblingElement("plane");
}
// Process userDataReference (?)
pElement = XMLNode->FirstChildElement("userDataReference");
if(pElement)
processUserDataReference(pElement, pNode);
}
void DotSceneLoader::processLookTarget(TiXmlElement *XMLNode, SceneNode *pParent)
{
//! @todo Is this correct? Cause I don't have a clue actually
// Process attributes
String nodeName = getAttrib(XMLNode, "nodeName");
Node::TransformSpace relativeTo = Node::TS_PARENT;
String sValue = getAttrib(XMLNode, "relativeTo");
if(sValue == "local")
relativeTo = Node::TS_LOCAL;
else if(sValue == "parent")
relativeTo = Node::TS_PARENT;
else if(sValue == "world")
relativeTo = Node::TS_WORLD;
TiXmlElement *pElement;
// Process position (?)
Vector3 position;
pElement = XMLNode->FirstChildElement("position");
if(pElement)
position = parseVector3(pElement);
// Process localDirection (?)
Vector3 localDirection = Vector3::NEGATIVE_UNIT_Z;
pElement = XMLNode->FirstChildElement("localDirection");
if(pElement)
localDirection = parseVector3(pElement);
// Setup the look target
try
{
if(!nodeName.empty())
{
SceneNode *pLookNode = mSceneMgr->getSceneNode(nodeName);
position = pLookNode->_getDerivedPosition();
}
pParent->lookAt(position, relativeTo, localDirection);
}
catch(Ogre::Exception &/*e*/)
{
LogManager::getSingleton().logMessage("[DotSceneLoader] Error processing a look target!");
}
}
void DotSceneLoader::processTrackTarget(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Process attributes
String nodeName = getAttrib(XMLNode, "nodeName");
TiXmlElement *pElement;
// Process localDirection (?)
Vector3 localDirection = Vector3::NEGATIVE_UNIT_Z;
pElement = XMLNode->FirstChildElement("localDirection");
if(pElement)
localDirection = parseVector3(pElement);
// Process offset (?)
Vector3 offset = Vector3::ZERO;
pElement = XMLNode->FirstChildElement("offset");
if(pElement)
offset = parseVector3(pElement);
// Setup the track target
try
{
SceneNode *pTrackNode = mSceneMgr->getSceneNode(nodeName);
pParent->setAutoTracking(true, pTrackNode, localDirection, offset);
}
catch(Ogre::Exception &/*e*/)
{
LogManager::getSingleton().logMessage("[DotSceneLoader] Error processing a track target!");
}
}
void DotSceneLoader::processEntity(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
String meshFile = getAttrib(XMLNode, "meshFile");
String materialFile = getAttrib(XMLNode, "materialFile");
bool isStatic = getAttribBool(XMLNode, "static", false);;
bool castShadows = getAttribBool(XMLNode, "castShadows", true);
// TEMP: Maintain a list of static and dynamic objects
if(isStatic)
staticObjects.push_back(name);
else
dynamicObjects.push_back(name);
TiXmlElement *pElement;
// Process vertexBuffer (?)
pElement = XMLNode->FirstChildElement("vertexBuffer");
if(pElement)
;//processVertexBuffer(pElement);
// Process indexBuffer (?)
pElement = XMLNode->FirstChildElement("indexBuffer");
if(pElement)
;//processIndexBuffer(pElement);
// Create the entity
Entity *pEntity = 0;
try
{
MeshManager::getSingleton().load(meshFile, m_sGroupName);
pEntity = mSceneMgr->createEntity(name, meshFile);
pEntity->setCastShadows(castShadows);
pParent->attachObject(pEntity);
if(!materialFile.empty())
pEntity->setMaterialName(materialFile);
}
catch(Ogre::Exception &/*e*/)
{
LogManager::getSingleton().logMessage("[DotSceneLoader] Error loading an entity!");
}
// Process userDataReference (?)
pElement = XMLNode->FirstChildElement("userDataReference");
if(pElement)
processUserDataReference(pElement, pEntity);
}
void DotSceneLoader::processParticleSystem(TiXmlElement *XMLNode, SceneNode *pParent)
{
// Process attributes
String name = getAttrib(XMLNode, "name");
String id = getAttrib(XMLNode, "id");
String file = getAttrib(XMLNode, "file");
// Create the particle system
try
{
ParticleSystem *pParticles = mSceneMgr->createParticleSystem(name, file);
pParent->attachObject(pParticles);
}
catch(Ogre::Exception &/*e*/)
{
LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating a particle system!");
}
}
void DotSceneLoader::processBillboardSet(TiXmlElement *XMLNode, SceneNode *pParent)
{
//! @todo Implement this
}
void DotSceneLoader::processPlane(TiXmlElement *XMLNode, SceneNode *pParent)
{
//! @todo Implement this
}
void DotSceneLoader::processFog(TiXmlElement *XMLNode)
{
// Process attributes
Real expDensity = getAttribReal(XMLNode, "expDensity", 0.001);
Real linearStart = getAttribReal(XMLNode, "linearStart", 0.0);
Real linearEnd = getAttribReal(XMLNode, "linearEnd", 1.0);
FogMode mode = FOG_NONE;
String sMode = getAttrib(XMLNode, "mode");
if(sMode == "none")
mode = FOG_NONE;
else if(sMode == "exp")
mode = FOG_EXP;
else if(sMode == "exp2")
mode = FOG_EXP2;
else if(sMode == "linear")
mode = FOG_LINEAR;
TiXmlElement *pElement;
// Process colourDiffuse (?)
ColourValue colourDiffuse = ColourValue::White;
pElement = XMLNode->FirstChildElement("colourDiffuse");
if(pElement)
colourDiffuse = parseColour(pElement);
// Setup the fog
mSceneMgr->setFog(mode, colourDiffuse, expDensity, linearStart, linearEnd);
}
void DotSceneLoader::processSkyBox(TiXmlElement *XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material");
Real distance = getAttribReal(XMLNode, "distance", 5000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);
TiXmlElement *pElement;
// Process rotation (?)
Quaternion rotation = Quaternion::IDENTITY;
pElement = XMLNode->FirstChildElement("rotation");
if(pElement)
rotation = parseQuaternion(pElement);
// Setup the sky box
mSceneMgr->setSkyBox(true, material, distance, drawFirst, rotation, m_sGroupName);
}
void DotSceneLoader::processSkyDome(TiXmlElement *XMLNode)
{
// Process attributes
String material = XMLNode->Attribute("material");
Real curvature = getAttribReal(XMLNode, "curvature", 10);
Real tiling = getAttribReal(XMLNode, "tiling", 8);
Real distance = getAttribReal(XMLNode, "distance", 4000);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);
TiXmlElement *pElement;
// Process rotation (?)
Quaternion rotation = Quaternion::IDENTITY;
pElement = XMLNode->FirstChildElement("rotation");
if(pElement)
rotation = parseQuaternion(pElement);
// Setup the sky dome
mSceneMgr->setSkyDome(true, material, curvature, tiling, distance, drawFirst, rotation, 16, 16, -1, m_sGroupName);
}
void DotSceneLoader::processSkyPlane(TiXmlElement *XMLNode)
{
// Process attributes
String material = getAttrib(XMLNode, "material");
Real planeX = getAttribReal(XMLNode, "planeX", 0);
Real planeY = getAttribReal(XMLNode, "planeY", -1);
Real planeZ = getAttribReal(XMLNode, "planeX", 0);
Real planeD = getAttribReal(XMLNode, "planeD", 5000);
Real scale = getAttribReal(XMLNode, "scale", 1000);
Real bow = getAttribReal(XMLNode, "bow", 0);
Real tiling = getAttribReal(XMLNode, "tiling", 10);
bool drawFirst = getAttribBool(XMLNode, "drawFirst", true);
// Setup the sky plane
Plane plane;
plane.normal = Vector3(planeX, planeY, planeZ);
plane.d = planeD;
mSceneMgr->setSkyPlane(true, plane, material, scale, tiling, drawFirst, bow, 1, 1, m_sGroupName);
}
void DotSceneLoader::processClipping(TiXmlElement *XMLNode)
{
//! @todo Implement this
// Process attributes
Real fNear = getAttribReal(XMLNode, "near", 0);
Real fFar = getAttribReal(XMLNode, "far", 1);
}
void DotSceneLoader::processLightRange(TiXmlElement *XMLNode, Light *pLight)
{
// Process attributes
Real inner = getAttribReal(XMLNode, "inner");
Real outer = getAttribReal(XMLNode, "outer");
Real falloff = getAttribReal(XMLNode, "falloff", 1.0);
// Setup the light range
pLight->setSpotlightRange(Angle(inner), Angle(outer), falloff);
}
void DotSceneLoader::processLightAttenuation(TiXmlElement *XMLNode, Light *pLight)
{
// Process attributes
Real range = getAttribReal(XMLNode, "range");
Real constant = getAttribReal(XMLNode, "constant");
Real linear = getAttribReal(XMLNode, "linear");
Real quadratic = getAttribReal(XMLNode, "quadratic");
// Setup the light attenuation
pLight->setAttenuation(range, constant, linear, quadratic);
}
String DotSceneLoader::getAttrib(TiXmlElement *XMLNode, const String &attrib, const String &defaultValue)
{
if(XMLNode->Attribute(attrib.c_str()))
return XMLNode->Attribute(attrib.c_str());
else
return defaultValue;
}
Real DotSceneLoader::getAttribReal(TiXmlElement *XMLNode, const String &attrib, Real defaultValue)
{
if(XMLNode->Attribute(attrib))
return StringConverter::parseReal(XMLNode->Attribute(attrib.c_str()));
else
return defaultValue;
}
bool DotSceneLoader::getAttribBool(TiXmlElement *XMLNode, const String &attrib, bool defaultValue)
{
if(!XMLNode->Attribute(attrib))
return defaultValue;
if(String(XMLNode->Attribute(attrib.c_str())) == "true")
return true;
return false;
}
Vector3 DotSceneLoader::parseVector3(TiXmlElement *XMLNode)
{
return Vector3(
StringConverter::parseReal(XMLNode->Attribute("x")),
StringConverter::parseReal(XMLNode->Attribute("y")),
StringConverter::parseReal(XMLNode->Attribute("z"))
);
}
Quaternion DotSceneLoader::parseQuaternion(TiXmlElement *XMLNode)
{
//! @todo Fix this crap!
Quaternion orientation;
if(XMLNode->Attribute("qx"))
{
orientation.x = StringConverter::parseReal(XMLNode->Attribute("qx"));
orientation.y = StringConverter::parseReal(XMLNode->Attribute("qy"));
orientation.z = StringConverter::parseReal(XMLNode->Attribute("qz"));
orientation.w = StringConverter::parseReal(XMLNode->Attribute("qw"));
}
else if(XMLNode->Attribute("axisX"))
{
Vector3 axis;
axis.x = StringConverter::parseReal(XMLNode->Attribute("axisX"));
axis.y = StringConverter::parseReal(XMLNode->Attribute("axisY"));
axis.z = StringConverter::parseReal(XMLNode->Attribute("axisZ"));
Real angle = StringConverter::parseReal(XMLNode->Attribute("angle"));;
orientation.FromAngleAxis(Ogre::Angle(angle), axis);
}
else if(XMLNode->Attribute("angleX"))
{
Vector3 axis;
axis.x = StringConverter::parseReal(XMLNode->Attribute("angleX"));
axis.y = StringConverter::parseReal(XMLNode->Attribute("angleY"));
axis.z = StringConverter::parseReal(XMLNode->Attribute("angleZ"));
//orientation.FromAxes(&axis);
//orientation.F
}
return orientation;
}
ColourValue DotSceneLoader::parseColour(TiXmlElement *XMLNode)
{
return ColourValue(
StringConverter::parseReal(XMLNode->Attribute("r")),
StringConverter::parseReal(XMLNode->Attribute("g")),
StringConverter::parseReal(XMLNode->Attribute("b")),
XMLNode->Attribute("a") != NULL ? StringConverter::parseReal(XMLNode->Attribute("a")) : 1
);
}
String DotSceneLoader::getProperty(const String &ndNm, const String &prop)
{
for ( unsigned int i = 0 ; i < nodeProperties.size(); i++ )
{
if ( nodeProperties[i].nodeName == ndNm && nodeProperties[i].propertyNm == prop )
{
return nodeProperties[i].valueName;
}
}
return "";
}
void DotSceneLoader::processUserDataReference(TiXmlElement *XMLNode, Entity *pEntity)
{
String str = XMLNode->Attribute("id");
pEntity->setUserAny(Any(str));
}