From c821575ea486213f63007b706073bdc31800142e Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 3 Feb 2022 10:02:26 -0500 Subject: [PATCH] Write new materials from model editor This now uses the same saving function as the regular editor, so now it's no longer constantly out of date with the new material changes. --- tools/modelcompiler/src/modeleditor.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/modelcompiler/src/modeleditor.cpp b/tools/modelcompiler/src/modeleditor.cpp index 4a0152a..bfceade 100755 --- a/tools/modelcompiler/src/modeleditor.cpp +++ b/tools/modelcompiler/src/modeleditor.cpp @@ -410,19 +410,22 @@ void ModelEditor::compile_model() { if(infile.good()) continue; - nlohmann::json j; - - j["version"] = 1; + Material mat; aiColor4D color; aiGetMaterialColor(sc->mMaterials[i], AI_MATKEY_COLOR_DIFFUSE,&color); - j["baseColor"] = prism::float3(color.r, color.g, color.b); - j["metallic"] = 0.0f; - j["roughness"] = 0.5f; + mat.colorProperty.type = DataType::Vector3; + mat.colorProperty.value = prism::float3(color.r, color.g, color.b); - std::ofstream out(path); - out << j; + aiString diffuse_path; + if(aiReturn_SUCCESS == aiGetMaterialTexture(sc->mMaterials[i], aiTextureType_DIFFUSE, 0, &diffuse_path)) { + mat.colorProperty.type = DataType::AssetTexture; + mat.colorProperty.value_tex.handle = new Texture(); + mat.colorProperty.value_tex->path = diffuse_path.C_Str(); + } + + save_material(&mat, path); } }