Skip to content
Snippets Groups Projects
Commit 4c66b4bd authored by sdegrande's avatar sdegrande
Browse files

Can now get a single property from the import.json of a 3D model.

Add a std::string 'property' 3rd parameter to
Model3DImport::getImportProperties().

If 'property' is empty, we keep the former behavior, else the method
returns the Json::Value of that 'property'.
parent 233e3edb
Branches
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@
* @author degrande
**/
#include <filesystem>
#include "Model3DImport.hpp"
#include <assimp/Importer.hpp>
......@@ -126,30 +128,36 @@ Model3DImport::MaterialMaps* Model3DImport::getMaterialMaps(const std::string& m
* If there is no import.json or if no properties are defined for the model,
* use the instance default properties.
**/
void Model3DImport::getImportProperties(const std::string& modelName, const std::string& modelPath)
Json::Value Model3DImport::getImportProperties(const std::string& modelName, const std::string& modelPath,
const std::string& property)
{
Json::Value jsImportConfig {};
std::string jsConfigPath = modelPath;
jsConfigPath.erase(jsConfigPath.rfind('/'));
if (loadJson(jsConfigPath + std::string("/import.json"s), &jsImportConfig, false)) return;
if (loadJson(jsConfigPath + std::string("/import.json"s), &jsImportConfig, false)) return {};
// Extract flavor
auto&& [nonFlavoredModelName, flavor] = AssetManager::getInstance()->extractFlavor(modelName);
// We first load the properties from the 'default' entry, if one exists.
if (jsImportConfig.isMember("*")) {
getImportPropertiesFor("*", jsImportConfig);
}
// We import and merge properties from the most generic entry to the most specific one
std::string nonFlavoredModelBaseName { std::filesystem::path(nonFlavoredModelName).filename() };
std::string modelBaseName { std::filesystem::path(modelName).filename() };
std::vector<std::string> keys { "*", nonFlavoredModelBaseName, nonFlavoredModelName, modelBaseName, modelName };
// Then we load the non-flavored model's properties
if (jsImportConfig.isMember(nonFlavoredModelName)) {
getImportPropertiesFor(nonFlavoredModelName, jsImportConfig);
if (property.empty()) {
// Load all the 'standard' import properties
for (const auto& key : keys) {
getImportPropertiesFor(key, jsImportConfig);
}
return {};
}
// Finally, we load the flavored model's specific properties
if (jsImportConfig.isMember(modelName)) {
getImportPropertiesFor(modelName, jsImportConfig);
// Get the value of a specific import property
Json::Value value {};
for (const auto& key : keys) {
if (jsImportConfig[key][property]) value = jsImportConfig[key][property];
}
return value;
}
/**
......
......@@ -76,6 +76,9 @@ public:
// Still used by export_3Dmodel (which must be rewritten !)
void getTextureTransform(const std::string& textureName, glm::vec2& textureScale);
Json::Value getImportProperties(const std::string& modelName, const std::string& modelPath,
const std::string& property = {});
private:
std::string modelFilePath {};
......@@ -112,7 +115,6 @@ private:
Assimp::Importer importer {};
unsigned int readFlags {};
void getImportProperties(const std::string& modelName, const std::string& modelPath);
void getImportPropertiesFor(const std::string& modelName, const Json::Value& jsImportConfig);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment