Implemented persistence of lighting information through XML files

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4034
This commit is contained in:
kearwood
2012-04-12 01:27:30 +00:00
parent 4215bf8b22
commit d4b80212cc
10 changed files with 90 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ std::string KRInstance::getElementName() {
tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent)
{
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
e->SetAttribute("mesh_name", m_model_name.c_str());
e->SetAttribute("lightmap", m_shadowMap.c_str());
return e;
}

View File

@@ -31,6 +31,18 @@ tinyxml2::XMLElement *KRLight::saveXML( tinyxml2::XMLNode *parent)
return e;
}
void KRLight::loadXML(tinyxml2::XMLElement *e) {
KRNode::loadXML(e);
float x,y,z;
e->QueryFloatAttribute("color_r", &x);
e->QueryFloatAttribute("color_g", &y);
e->QueryFloatAttribute("color_b", &z);
m_color = KRVector3(x,y,z);
e->QueryFloatAttribute("intensity", &m_intensity);
e->QueryFloatAttribute("decay_start", &m_decayStart);
}
void KRLight::setIntensity(float intensity) {
m_intensity = intensity;
}

View File

@@ -17,6 +17,7 @@ public:
virtual ~KRLight();
virtual std::string getElementName() = 0;
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
virtual void loadXML(tinyxml2::XMLElement *e);
void setIntensity(float intensity);
float getIntensity();

View File

@@ -9,6 +9,9 @@
#include <iostream>
#import "KRNode.h"
#import "KRPointLight.h"
#import "KRSpotLight.h"
#import "KRDirectionalLight.h"
KRNode::KRNode(std::string name)
@@ -51,6 +54,32 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
return e;
}
void KRNode::loadXML(tinyxml2::XMLElement *e) {
m_name = e->Attribute("name");
float x,y,z;
e->QueryFloatAttribute("translate_x", &x);
e->QueryFloatAttribute("translate_y", &y);
e->QueryFloatAttribute("translate_z", &z);
m_localTranslation = KRVector3(x,y,z);
e->QueryFloatAttribute("scale_x", &x);
e->QueryFloatAttribute("scale_y", &y);
e->QueryFloatAttribute("scale_z", &z);
m_localScale = KRVector3(x,y,z);
e->QueryFloatAttribute("rotate_x", &x);
e->QueryFloatAttribute("rotate_y", &y);
e->QueryFloatAttribute("rotate_z", &z);
m_localRotation = KRVector3(x,y,z);
for(tinyxml2::XMLElement *child_element=e->FirstChildElement(); child_element != NULL; child_element = child_element->NextSiblingElement()) {
KRNode *child_node = KRNode::LoadXML(child_element);
if(child_node) {
addChild(child_node);
}
}
}
void KRNode::setLocalTranslation(const KRVector3 &v) {
m_localTranslation = v;
}
@@ -75,3 +104,26 @@ std::string KRNode::getElementName() {
return "node";
}
KRNode *KRNode::LoadXML(tinyxml2::XMLElement *e) {
KRNode *new_node = NULL;
const char *szElementName = e->Name();
const char *szName = e->Attribute("name");
if(strcmp(szElementName, "node") == 0) {
new_node = new KRNode(szName);
} else if(strcmp(szElementName, "point_light") == 0) {
new_node = new KRPointLight(szName);
} else if(strcmp(szElementName, "directional_light") == 0) {
new_node = new KRDirectionalLight(szName);
} else if(strcmp(szElementName, "spot_light") == 0) {
new_node = new KRSpotLight(szName);
} else if(strcmp(szElementName, "mesh") == 0) {
}
if(new_node) {
new_node->loadXML(e);
}
return new_node;
}

View File

@@ -20,6 +20,9 @@ public:
virtual ~KRNode();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
static KRNode *LoadXML(tinyxml2::XMLElement *e);
virtual void loadXML(tinyxml2::XMLElement *e);
virtual std::string getElementName();
void addChild(KRNode *child);

View File

@@ -152,5 +152,10 @@ KRScene *KRScene::LoadXML(const std::string& path)
doc.LoadFile(path.c_str());
KRScene *new_scene = new KRScene(KRResource::GetFileBase(path));
KRNode *n = KRNode::LoadXML(doc.RootElement()->FirstChildElement());
if(n) {
new_scene->getRootNode()->addChild(n);
}
return new_scene;
}

View File

@@ -42,7 +42,7 @@ KRSceneManager::~KRSceneManager() {
}
KRScene *KRSceneManager::loadScene(const char *szName, const char *szPath) {
KRScene *pScene = KRScene::LoadXML(szName);
KRScene *pScene = KRScene::LoadXML(szPath);
m_scenes[szName] = pScene;
return pScene;
}

View File

@@ -31,6 +31,12 @@ tinyxml2::XMLElement *KRSpotLight::saveXML( tinyxml2::XMLNode *parent)
return e;
}
void KRSpotLight::loadXML(tinyxml2::XMLElement *e) {
KRLight::loadXML(e);
e->QueryFloatAttribute("inner_angle", &m_innerAngle);
e->QueryFloatAttribute("outer_angle", &m_outerAngle);
}
float KRSpotLight::getInnerAngle() {
return m_innerAngle;

View File

@@ -18,6 +18,8 @@ public:
virtual std::string getElementName();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
virtual void loadXML(tinyxml2::XMLElement *e);
float getInnerAngle();
float getOuterAngle();

View File

@@ -136,6 +136,13 @@
}
}
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".krscene"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[renderEngine loadResource: path];
}
}
KRModelManager *pModelManager = [renderEngine getModelManager];
//m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
//m_scene.addInstance(pModelManager->getModel("ballroom"), KRMat4());