forked from zaki/irrlicht
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ioScene.cpp
132 lines (111 loc) · 3.93 KB
/
ioScene.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
// Copyright (C) 2008-2012 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
// Tests save scene.
static bool saveScene(void)
{
IrrlichtDevice *device = createDevice( EDT_NULL, dimension2d<u32>(160, 120), 32);
assert_log(device);
if (!device)
return false;
ISceneManager * smgr = device->getSceneManager();
ISkinnedMesh* mesh = (ISkinnedMesh*)smgr->getMesh("../media/ninja.b3d");
if (!mesh)
return false;
IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode(mesh);
if (node1)
{
node1->setPosition(vector3df(-3, -3, 10));
node1->setMaterialFlag(EMF_LIGHTING, false);
node1->setAnimationSpeed(0.f);
node1->setCurrentFrame(10.f);
node1->setDebugDataVisible(irr::scene::EDS_BBOX_BUFFERS);
}
ISkinnedMesh* mesh2 = (ISkinnedMesh*)smgr->getMesh(device->getFileSystem()->getAbsolutePath("../media/dwarf.x"));
if (!mesh2)
return false;
IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode(mesh2);
if (node2)
{
node2->setPosition(vector3df(33, -93, 120));
node2->setMaterialFlag(EMF_LIGHTING, false);
node2->setAnimationSpeed(10.f);
node2->setCurrentFrame(2.f);
}
IAnimatedMeshSceneNode* node3 = smgr->addAnimatedMeshSceneNode(mesh2, node2);
if (node3)
{
node3->setPosition(vector3df(-88, -300, 150));
node3->setMaterialFlag(EMF_LIGHTING, false);
node3->setAnimationSpeed(0.f);
node3->setCurrentFrame(12.f);
}
smgr->addCameraSceneNode();
logTestString("Test scene.irr");
smgr->saveScene("results/scene.irr");
bool result = xmlCompareFiles(device->getFileSystem(), "results/scene.irr", "media/scene.irr");
logTestString("Test scene2.irr");
smgr->saveScene("results/scene2.irr", 0, node3);
result &= xmlCompareFiles(device->getFileSystem(), "results/scene2.irr", "media/scene2.irr");
device->closeDevice();
device->run();
device->drop();
return result;
}
static bool loadScene(void)
{
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
core::dimension2du(160,120), 32);
if (!device)
return false;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
// load scene from example, with correct relative path
device->getFileSystem()->changeWorkingDirectoryTo("results");
smgr->loadScene("../../media/example.irr");
smgr->addCameraSceneNode(0, core::vector3df(0,0,-50));
device->getFileSystem()->changeWorkingDirectoryTo("..");
bool result = false;
device->run();
device->getTimer()->setTime(666); // scene has animations and current scene seems to be saved at that time ... really - best result with just that number :-)
if (driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0, 80, 80, 80)))
{
smgr->drawAll();
driver->endScene();
// we need to be very sloppy, because the animators will produce a different
// start depending on the actual loading time. 97% seems to be safe, as removing
// an object produces values around 95%
result = takeScreenshotAndCompareAgainstReference(driver, "-loadScene.png", 97.4f);
if (!result)
logTestString("Rendering the loaded scene failed.\n");
}
ISceneNode* node = smgr->getSceneNodeFromId(128);
if (!node)
result=false;
else if (result) // only check if scene was correctly loaded
{
result &= (node->getChildren().size()==0);
if (!result)
logTestString("Node has an illegal child node.\n");
device->getSceneManager()->loadScene("results/scene2.irr", 0, node);
result &= (node->getChildren().size()!=0);
if (!result)
logTestString("Loading second scene as child failed.\n");
}
device->closeDevice();
device->run();
device->drop();
return result;
}
bool ioScene(void)
{
bool result = saveScene();
result &= loadScene();
return result;
}