Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Merged cylonspy's pull request by hand
Browse files Browse the repository at this point in the history
  • Loading branch information
ZelconGames committed Feb 4, 2012
1 parent f64ee63 commit 60a3489
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
54 changes: 44 additions & 10 deletions src/SceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Graphics/MeshComponent.hpp"
#include "Graphics/LightComponent.hpp"

#include <OGRE/OgreSubEntity.h>
#include <OgreProcedural.h>

Scene* SceneLoader::LoadScene(string path)
{
Expand All @@ -15,6 +15,8 @@ Scene* SceneLoader::LoadScene(string path)
if(result)
{
scene = new Scene(path.c_str());
OgreProcedural::Root::getInstance()->sceneManager = scene->GetSceneManager();

xml_node root = doc.child(SL_SCENE);

for(xml_node node = root.first_child(); node; node = node.next_sibling())
Expand Down Expand Up @@ -81,7 +83,6 @@ void SceneLoader::_LoadMesh(Scene* scene, const xml_node& node)
xml_node pos = node.child(SL_POS);
xml_node rot = node.child(SL_ROT);
xml_node scale = node.child(SL_SCALE);
xml_node entity = node.child(SL_ENTITY);

dt_node->SetPosition(pos.attribute(SL_X).as_float(), pos.attribute(SL_Y).as_float(),
pos.attribute(SL_Z).as_float());
Expand All @@ -90,18 +91,51 @@ void SceneLoader::_LoadMesh(Scene* scene, const xml_node& node)
dt_node->SetScale(Ogre::Vector3(scale.attribute(SL_X).as_float(), scale.attribute(SL_Y).as_float(),
scale.attribute(SL_Z).as_float()));

MeshComponent* mesh = dt_node->AddComponent<MeshComponent>(new MeshComponent(
entity.attribute(SL_MESH_HANDLE).value(), "",
entity.attribute(SL_NAME).value()));
//entity
xml_node entity = node.child(SL_ENTITY);
if(!entity.empty())
{
MeshComponent* mesh = dt_node->AddComponent<MeshComponent>(new MeshComponent(
entity.attribute(SL_MESH_HANDLE).value(), "",
entity.attribute(SL_NAME).value()));

for(xml_node mat = entity.first_child(); mat; mat = mat.next_sibling())
{
auto material_handle = mat.attribute(SL_MATERIALNAME).value();
//
// Todo: Add the material loading logic here. Just fill it!!!!
//
}

mesh->SetCastShadows(entity.attribute(SL_CAST_SHADOWS).as_bool());
}

for(xml_node mat = entity.first_child(); mat; mat = mat.next_sibling())
//plane
xml_node plane = node.child(SL_PLANE);
if(!plane.empty())
{
auto material_handle = mat.attribute(SL_MATERIAL).value();
auto index = mat.attribute(SL_INDEX).as_uint();
//create mesh
OgreProcedural::PlaneGenerator()
.setSizeX(plane.attribute(SL_SIZEX).as_float())
.setSizeY(plane.attribute(SL_SIZEY).as_float())
.setEnableNormals(plane.attribute(SL_ENABLENORMALS).as_bool())
.setNumSegX(plane.attribute(SL_SEGMENTSX).as_int())
.setNumSegY(plane.attribute(SL_SEGMENTSY).as_int())
//.setNumTexCoordSet(plane.attribute(SL_NUMTEXCOORD).as_int())
// .setUTile(plane.attribute(SL_UTILE).as_float())
//.setVTile(plane.attribute(SL_VTILE).as_float())
.setNormal(Ogre::Vector3( plane.child(SL_NORMAL).attribute(SL_X).as_float(),
plane.child(SL_NORMAL).attribute(SL_Y).as_float(),
plane.child(SL_NORMAL).attribute(SL_Z).as_float() ))
.realizeMesh(plane.attribute(SL_NAME).value());

mesh->GetOgreEntity()->getSubEntity(index)->setMaterialName(material_handle);
//add entity
MeshComponent* mesh = dt_node->AddComponent<MeshComponent>(new MeshComponent(
plane.attribute(SL_NAME).value(),
plane.attribute(SL_MATERIAL).value(),
plane.attribute(SL_NAME).value() ));
}

mesh->SetCastShadows(entity.attribute(SL_CAST_SHADOWS).as_bool());

}
}
14 changes: 12 additions & 2 deletions src/SceneLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ using namespace dt;
#define SL_MESH "node"
#define SL_MESH_HANDLE "meshFile"
#define SL_CAST_SHADOWS "castShadows"
#define SL_MATERIAL "materialName"
#define SL_MATERIALNAME "materialName"
#define SL_MATERIAL "material"
#define SL_CAMERA "camera"
#define SL_LIGHT "light"
#define SL_DIRECTION "directionVector"
#define SL_ENTITY "entity"
#define SL_INDEX "index"
#define SL_PLANE "plane"
#define SL_SIZEX "height"
#define SL_SIZEY "width"
#define SL_NORMAL "normal"
#define SL_ENABLENORMALS "hasNormals"
#define SL_SEGMENTSX "xSegments"
#define SL_SEGMENTSY "ySegments"
#define SL_NUMTEXCOORD "numTexCoordSets"
#define SL_UTILE "uTile"
#define SL_VTILE "vTile"

class SceneLoader
{
Expand Down
4 changes: 2 additions & 2 deletions src/SceneLoaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <Core/ResourceManager.hpp>

void Main::OnInitialize() {
dt::ResourceManager::Get()->AddDataPath(QDir("D:\\"));
dt::ResourceManager::Get()->AddDataPath(QDir("C:\\users\\EnterUserNameHere\\Facade\\bin\\debug\\data\\"));
dt::ResourceManager::Get()->AddResourceLocation("","FileSystem");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

dt::Scene* scene = nullptr;
scene = SceneLoader::LoadScene("D:\\test.scene");
scene = SceneLoader::LoadScene("C:\\users\\EnterUserNameHere\\Facade\\bin\\debug\\data\\test.scene");
if(scene)
AddScene(scene);
}
Expand Down

0 comments on commit 60a3489

Please sign in to comment.