5 changed files with 167 additions and 33 deletions
@ -0,0 +1,58 @@
|
||||
{ |
||||
"camera" : { |
||||
"position" : { |
||||
"x" : 0, |
||||
"y" : 0, |
||||
"z" : 0 |
||||
}, |
||||
|
||||
"rotation" : { |
||||
"x" : 0, |
||||
"y" : 0, |
||||
"z" : 0, |
||||
"w" : 0 |
||||
} |
||||
}, |
||||
|
||||
"hex_grid" : { |
||||
"layout_type" : "hexagon", |
||||
"hex_size" : 10, |
||||
"hex_radius" : 20 |
||||
}, |
||||
|
||||
"entities" : [ |
||||
{ |
||||
"name" : "catepillar 1", |
||||
"model_file" : "catepillar.dae", |
||||
"position" : { |
||||
"x" : 0, |
||||
"y" : 0, |
||||
"z" : 0 |
||||
}, |
||||
|
||||
"rotation" : { |
||||
"x" : 0, |
||||
"y" : 0, |
||||
"z" : 0, |
||||
"w" : 0 |
||||
} |
||||
} |
||||
], |
||||
|
||||
"lights" : [ |
||||
{ |
||||
"intensity" : 1.0, |
||||
"color" : { |
||||
"r" : 0, |
||||
"g" : 0, |
||||
"b" : 0 |
||||
}, |
||||
|
||||
"position" : { |
||||
"x" : 0, |
||||
"y" : 0, |
||||
"z" : 0 |
||||
} |
||||
} |
||||
] |
||||
} |
||||
@ -0,0 +1,52 @@
|
||||
|
||||
#include <glm/glm.hpp> |
||||
#include "rapidjson/document.h" |
||||
#include "rapidjson/writer.h" |
||||
#include "rapidjson/stringbuffer.h" |
||||
|
||||
#include "aixlog.hpp" |
||||
|
||||
#include "entity.h" |
||||
#include "mesh.h" |
||||
#include "util.h" |
||||
#include "scene_loader.h" |
||||
|
||||
bool |
||||
slLoadFile(const char* file_name, Entity* entity_array, uint& entity_count, uint max_entities) |
||||
{ |
||||
if (entity_array == nullptr) { |
||||
LOG(ERROR) << "entity array not initialized\n"; |
||||
return false; |
||||
} |
||||
|
||||
rapidjson::Document doc; |
||||
char* contents = utilDumpTextFile(file_name); |
||||
|
||||
if (contents == nullptr) { |
||||
LOG(ERROR) << "Error reading file: " << file_name << "\n"; |
||||
return false; |
||||
} |
||||
|
||||
if (doc.Parse(contents).HasParseError() || !doc.IsObject()) { |
||||
LOG(ERROR) << "Error parrsing scene file: " << file_name << "\n"; |
||||
return false; |
||||
} |
||||
|
||||
// entities
|
||||
|
||||
if (doc.HasMember("entities")) { |
||||
const rapidjson::Value& e = doc["entities"]; |
||||
assert (e.IsArray()); |
||||
|
||||
for (uint i = 0; i < e.Size(); i++) { |
||||
assert(e[i].HasMember("name")); |
||||
assert(e[i]["name"].IsString()); |
||||
assert(i < max_entities); |
||||
|
||||
std::string s = e[i]["name"].GetString(); |
||||
LOG(INFO) << "e[" << i << "][\"name\"]: " << s << "\n"; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
Loading…
Reference in new issue