Add support for initial values in json file
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"models": [
|
"models": [
|
||||||
|
{
|
||||||
|
"unique_name": "fallback",
|
||||||
|
"path": "res/models/fallback.ffo"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"unique_name": "backpack",
|
"unique_name": "backpack",
|
||||||
"path": "res/models/backpack.ffo",
|
"path": "res/models/backpack.ffo"
|
||||||
|
|
||||||
"position": ["0.0", "0.0", "0.0"],
|
|
||||||
"rotation": ["0.0", "0.0", "0.0"]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unique_name": "ground",
|
"unique_name": "ground",
|
||||||
@@ -20,12 +21,15 @@
|
|||||||
{
|
{
|
||||||
"unique_name": "backpack",
|
"unique_name": "backpack",
|
||||||
"model": "backpack",
|
"model": "backpack",
|
||||||
"shaderProgram": "defaultProgram"
|
"shaderProgram": "defaultProgram",
|
||||||
|
"position": [0.0, 1.0, 0.0],
|
||||||
|
"rotation": [0.0, 0.0, 0.0],
|
||||||
|
"scale": 0.6
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unique_name": "ground",
|
"unique_name": "ground",
|
||||||
"model": "ground",
|
"model": "ground",
|
||||||
"shaderProgram": "defaultProgram"
|
"shaderProgram": "defaultProgram",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unique_name": "light",
|
"unique_name": "light",
|
||||||
|
|||||||
@@ -276,11 +276,11 @@ void Controller::renderImGui(World &world, PointLight *pointLight, glm::vec3 *li
|
|||||||
ImGui::Checkbox("Rotate Object", rotateEntity);
|
ImGui::Checkbox("Rotate Object", rotateEntity);
|
||||||
|
|
||||||
Entity *mainObject = world.getEntityById(0);
|
Entity *mainObject = world.getEntityById(0);
|
||||||
mainObject->setPosition(glm::vec3(translation[0], translation[1], translation[2]));
|
//mainObject->setPosition(glm::vec3(translation[0], translation[1], translation[2]));
|
||||||
if (!*rotateEntity) {
|
if (!*rotateEntity) {
|
||||||
mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), rotation);
|
//mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), rotation);
|
||||||
}
|
}
|
||||||
mainObject->setScale(scale);
|
//mainObject->setScale(scale);
|
||||||
|
|
||||||
// color picker
|
// color picker
|
||||||
ImGui::Text("\nLight Source");
|
ImGui::Text("\nLight Source");
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
|
|||||||
std::string entity_name = entitiesJson[index]["unique_name"].asString();
|
std::string entity_name = entitiesJson[index]["unique_name"].asString();
|
||||||
std::string entity_model = entitiesJson[index]["model"].asString();
|
std::string entity_model = entitiesJson[index]["model"].asString();
|
||||||
std::string entity_shaderProgram = entitiesJson[index]["shaderProgram"].asString();
|
std::string entity_shaderProgram = entitiesJson[index]["shaderProgram"].asString();
|
||||||
|
glm::vec3 entitiy_position = {}, entity_rotation = {};
|
||||||
|
float entity_scale = 1.0f;
|
||||||
|
|
||||||
ShaderProgram *shaderProgram = nullptr;
|
ShaderProgram *shaderProgram = nullptr;
|
||||||
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
|
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
|
||||||
@@ -73,7 +75,27 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
|
|||||||
if(!current_model)
|
if(!current_model)
|
||||||
std::cout << "[Warning] Model could not be found by unique name \"" << entity_model << "\"" << std::endl;
|
std::cout << "[Warning] Model could not be found by unique name \"" << entity_model << "\"" << std::endl;
|
||||||
|
|
||||||
|
const Json::Value positionJson = entitiesJson[index]["position"];
|
||||||
|
const Json::Value rotationJson = entitiesJson[index]["rotation"];
|
||||||
|
const Json::Value scaleJson = entitiesJson[index]["scale"];
|
||||||
|
if(!positionJson.empty()) {
|
||||||
|
entitiy_position.x = positionJson[0].asFloat();
|
||||||
|
entitiy_position.y = positionJson[1].asFloat();
|
||||||
|
entitiy_position.z = positionJson[2].asFloat();
|
||||||
|
}
|
||||||
|
if(!rotationJson.empty()) {
|
||||||
|
entity_rotation.s = rotationJson[0].asFloat();
|
||||||
|
entity_rotation.t = rotationJson[1].asFloat();
|
||||||
|
entity_rotation.p = rotationJson[2].asFloat();
|
||||||
|
}
|
||||||
|
if(!scaleJson.empty()) {
|
||||||
|
entity_scale = scaleJson.asFloat();
|
||||||
|
}
|
||||||
|
|
||||||
Entity *current_entity = new Entity(entity_name, current_model, shaderProgram);
|
Entity *current_entity = new Entity(entity_name, current_model, shaderProgram);
|
||||||
|
current_entity->setPosition(entitiy_position);
|
||||||
|
current_entity->setRotation(entity_rotation);
|
||||||
|
current_entity->setScale(entity_scale);
|
||||||
temp_entities.push_back(current_entity);
|
temp_entities.push_back(current_entity);
|
||||||
std::cout << "Loaded Entity \"" << entity_name << "\" with model \"" << entity_model << "\"" << std::endl;
|
std::cout << "Loaded Entity \"" << entity_name << "\" with model \"" << entity_model << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user