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:
@@ -52,6 +52,7 @@ std::string KRInstance::getElementName() {
|
|||||||
tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent)
|
tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
|
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
|
||||||
|
e->SetAttribute("mesh_name", m_model_name.c_str());
|
||||||
e->SetAttribute("lightmap", m_shadowMap.c_str());
|
e->SetAttribute("lightmap", m_shadowMap.c_str());
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ tinyxml2::XMLElement *KRLight::saveXML( tinyxml2::XMLNode *parent)
|
|||||||
return e;
|
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) {
|
void KRLight::setIntensity(float intensity) {
|
||||||
m_intensity = intensity;
|
m_intensity = intensity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public:
|
|||||||
virtual ~KRLight();
|
virtual ~KRLight();
|
||||||
virtual std::string getElementName() = 0;
|
virtual std::string getElementName() = 0;
|
||||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||||
|
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||||
|
|
||||||
void setIntensity(float intensity);
|
void setIntensity(float intensity);
|
||||||
float getIntensity();
|
float getIntensity();
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#import "KRNode.h"
|
#import "KRNode.h"
|
||||||
|
#import "KRPointLight.h"
|
||||||
|
#import "KRSpotLight.h"
|
||||||
|
#import "KRDirectionalLight.h"
|
||||||
|
|
||||||
|
|
||||||
KRNode::KRNode(std::string name)
|
KRNode::KRNode(std::string name)
|
||||||
@@ -51,6 +54,32 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
|
|||||||
return e;
|
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) {
|
void KRNode::setLocalTranslation(const KRVector3 &v) {
|
||||||
m_localTranslation = v;
|
m_localTranslation = v;
|
||||||
}
|
}
|
||||||
@@ -75,3 +104,26 @@ std::string KRNode::getElementName() {
|
|||||||
return "node";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public:
|
|||||||
virtual ~KRNode();
|
virtual ~KRNode();
|
||||||
|
|
||||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||||
|
static KRNode *LoadXML(tinyxml2::XMLElement *e);
|
||||||
|
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||||
|
|
||||||
virtual std::string getElementName();
|
virtual std::string getElementName();
|
||||||
|
|
||||||
void addChild(KRNode *child);
|
void addChild(KRNode *child);
|
||||||
|
|||||||
@@ -152,5 +152,10 @@ KRScene *KRScene::LoadXML(const std::string& path)
|
|||||||
doc.LoadFile(path.c_str());
|
doc.LoadFile(path.c_str());
|
||||||
KRScene *new_scene = new KRScene(KRResource::GetFileBase(path));
|
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;
|
return new_scene;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ KRSceneManager::~KRSceneManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::loadScene(const char *szName, const char *szPath) {
|
KRScene *KRSceneManager::loadScene(const char *szName, const char *szPath) {
|
||||||
KRScene *pScene = KRScene::LoadXML(szName);
|
KRScene *pScene = KRScene::LoadXML(szPath);
|
||||||
m_scenes[szName] = pScene;
|
m_scenes[szName] = pScene;
|
||||||
return pScene;
|
return pScene;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ tinyxml2::XMLElement *KRSpotLight::saveXML( tinyxml2::XMLNode *parent)
|
|||||||
return e;
|
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() {
|
float KRSpotLight::getInnerAngle() {
|
||||||
return m_innerAngle;
|
return m_innerAngle;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ public:
|
|||||||
|
|
||||||
virtual std::string getElementName();
|
virtual std::string getElementName();
|
||||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||||
|
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||||
|
|
||||||
|
|
||||||
float getInnerAngle();
|
float getInnerAngle();
|
||||||
float getOuterAngle();
|
float getOuterAngle();
|
||||||
|
|||||||
@@ -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];
|
KRModelManager *pModelManager = [renderEngine getModelManager];
|
||||||
//m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
|
//m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
|
||||||
//m_scene.addInstance(pModelManager->getModel("ballroom"), KRMat4());
|
//m_scene.addInstance(pModelManager->getModel("ballroom"), KRMat4());
|
||||||
|
|||||||
Reference in New Issue
Block a user