Code: Select all
<level>
<Property isWorld="0"/>
<Property x="-10" y="-10" z="-10" x2="10" y2="10" z2="10"/>
<room>
<Property name = "room"/>
<Property visible = "1"/>
<display>
<Mesh file="HALL.3ds" scale="10" position_x="0" position_y="0" position_z="0" rotation_x="0" rotation_y="0" rotation_z="0" material="0"/>
<Mesh file="HALL_LIT.3ds" scale="10" position_x="0" position_y="0" position_z="0" rotation_x="0" rotation_y="0" rotation_z="0" material="1"/>
</display>
</room>
</level>
the function is here:
Code: Select all
void cLevelManager::loadFromXML(irr::IrrlichtDevice* device, char* filename)
{
bool visible;
char* name;
printf("loading \n");
int scale, pos[2], rot[2];
irr::io::IXMLReader* m_pXMLreader =device->getFileSystem()->createXMLReader(filename);
if (m_pXMLreader == 0)
{
printf("error in level file \n");
return;
}else printf("reading \n");
while(m_pXMLreader->read())
{
printf("searching... \n");
if(m_pXMLreader->getNodeType() == irr::io::EXN_ELEMENT)
{
printf("found node \n");
if(core::stringw("level") == m_pXMLreader->getNodeName())
if (core::stringw("Property") == m_pXMLreader->getNodeName())
{
printf("found level property \n");
if (m_pXMLreader->getAttributeValueAsInt(L"isWorld") == 0) m_bIsWorldMap = false; else m_bIsWorldMap = true;
Level_AABB = irr::core::aabbox3df(m_pXMLreader->getAttributeValueAsFloat (L"x"), m_pXMLreader->getAttributeValueAsFloat (L"y"), m_pXMLreader->getAttributeValueAsFloat (L"z"), m_pXMLreader->getAttributeValueAsFloat (L"x2"), m_pXMLreader->getAttributeValueAsFloat (L"y2"), m_pXMLreader->getAttributeValueAsFloat (L"z2"));
}
if(core::stringw("room") == m_pXMLreader->getNodeName())
{
printf("found room \n");
if (core::stringw("Property") == m_pXMLreader->getNodeName())
{
printf("found room property \n");
name = (char*)m_pXMLreader->getAttributeValue(L"name");
if (m_pXMLreader->getAttributeValueAsInt (L"visible") == 0) visible=false; else visible=true;
}
addRoom(name, visible);
}
if (core::stringw(L"display") == m_pXMLreader->getNodeName())
{
printf("found display \n");
if (core::stringw(L"Mesh") == m_pXMLreader->getNodeName())
{
printf("found mesh \n");
name = (char*)m_pXMLreader->getAttributeValue(L"filename");
scale = m_pXMLreader->getAttributeValueAsInt(L"scale");
pos[0] = m_pXMLreader->getAttributeValueAsInt(L"position_x");
pos[1] = m_pXMLreader->getAttributeValueAsInt(L"position_y");
pos[2] = m_pXMLreader->getAttributeValueAsInt(L"position_z");
rot[0] = m_pXMLreader->getAttributeValueAsInt(L"rotation_x");
rot[1] = m_pXMLreader->getAttributeValueAsInt(L"rotation_y");
rot[2] = m_pXMLreader->getAttributeValueAsInt(L"rotation_z");
scale=m_pXMLreader->getAttributeValueAsInt(L"material");
switch (scale)
{
case 0: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_SOLID); break;
case 1: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_TRANSPARENT_ADD_COLOR); break;
case 2: m_cuRoomArray[m_cuRoomArray.size()-1]->addVisibleMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale), irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL); break;
}
}
}
if (core::stringw(L"collision") == m_pXMLreader->getNodeName())
{
printf("found collision \n");
if (core::stringw(L"Mesh") == m_pXMLreader->getNodeName())
{
printf("found col mesh \n");
name = (char*)m_pXMLreader->getAttributeValue(L"filename");
scale = m_pXMLreader->getAttributeValueAsInt(L"scale");
pos[0] = m_pXMLreader->getAttributeValueAsInt(L"position_x");
pos[1] = m_pXMLreader->getAttributeValueAsInt(L"position_y");
pos[2] = m_pXMLreader->getAttributeValueAsInt(L"position_z");
rot[0] = m_pXMLreader->getAttributeValueAsInt(L"rotation_x");
rot[1] = m_pXMLreader->getAttributeValueAsInt(L"rotation_y");
rot[2] = m_pXMLreader->getAttributeValueAsInt(L"rotation_z");
m_cuRoomArray[m_cuRoomArray.size()-1]->addCollisionMesh(name, irr::core::vector3df(pos[0], pos[1], pos[2]), irr::core::vector3df(rot[0], rot[1], rot[2]), irr::core::vector3df(scale, scale, scale));
}
}
}
}
//TO DO: de continuat cu citirea fisierului XML
printf("done \n \n");
delete m_pXMLreader;
}