Add normal map importing to model compiler
This commit is contained in:
parent
9ee41d01b6
commit
b94a82b1e1
20 changed files with 54 additions and 31 deletions
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.6000000238418579,"y":0.6000000238418579,"z":0.6000000238418579}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.6000000238418579,"y":0.6000000238418579,"z":0.6000000238418579}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/mramor6x6.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7094119787216187,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/mramor6x6.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7094119787216187,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":1.0,"y":0.11999999731779099,"z":0.10000000149011612}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":1.0,"y":0.11999999731779099,"z":0.10000000149011612}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.784313976764679,"y":0.784313976764679,"z":0.784313976764679}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.784313976764679,"y":0.784313976764679,"z":0.784313976764679}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.44117599725723267,"y":0.10392200201749802,"z":0.04901999980211258}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.44117599725723267,"y":0.10392200201749802,"z":0.04901999980211258}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
||||
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/KAMEN-stup.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
|
@ -1 +1 @@
|
|||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"version":3}
|
||||
{"color":{"asset_value":"textures/kamen.png","float_value":0.0,"name":"","type":2,"value":{"x":0.7341179847717285,"y":0.7305880188941956,"z":0.6741179823875427}},"normal":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}
|
Binary file not shown.
|
@ -42,6 +42,7 @@ struct MaterialProperty {
|
|||
class Material : public Asset {
|
||||
public:
|
||||
MaterialProperty colorProperty;
|
||||
MaterialProperty normalProperty;
|
||||
|
||||
float metallic = 0.0f;
|
||||
float roughness = 0.5f;
|
||||
|
|
|
@ -266,14 +266,23 @@ std::unique_ptr<Material> load_material(const prism::path path) {
|
|||
return mat;
|
||||
}
|
||||
|
||||
auto property = j["color"];
|
||||
mat->colorProperty.value = property["value"];
|
||||
mat->colorProperty.float_value = property["float_value"];
|
||||
mat->colorProperty.type = property["type"];
|
||||
const auto loadProperty = [](nlohmann::json property) -> MaterialProperty {
|
||||
MaterialProperty p;
|
||||
p.value = property["value"];
|
||||
p.float_value = property["float_value"];
|
||||
p.type = property["type"];
|
||||
|
||||
if(!property["asset_value"].get<std::string>().empty()) {
|
||||
mat->colorProperty.value_tex = assetm->get<Texture>(prism::app_domain / property["asset_value"].get<std::string>());
|
||||
}
|
||||
if(!property["asset_value"].get<std::string>().empty()) {
|
||||
p.value_tex = assetm->get<Texture>(prism::app_domain / property["asset_value"].get<std::string>());
|
||||
}
|
||||
|
||||
return p;
|
||||
};
|
||||
|
||||
mat->colorProperty = loadProperty(j["color"]);
|
||||
|
||||
if(j.contains("normal"))
|
||||
mat->normalProperty = loadProperty(j["normal"]);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
@ -285,14 +294,19 @@ void save_material(Material* material, const prism::path path) {
|
|||
nlohmann::json j;
|
||||
j["version"] = 3;
|
||||
|
||||
nlohmann::json p;
|
||||
p["name"] = material->colorProperty.name;
|
||||
p["value"] = material->colorProperty.value;
|
||||
p["asset_value"] = material->colorProperty.value_tex ? material->colorProperty.value_tex->path : "";
|
||||
p["float_value"] = material->colorProperty.float_value;
|
||||
p["type"] = material->colorProperty.type;
|
||||
const auto save_property = [](MaterialProperty& property) -> nlohmann::json {
|
||||
nlohmann::json p;
|
||||
p["name"] = property.name;
|
||||
p["value"] = property.value;
|
||||
p["asset_value"] = property.value_tex ? property.value_tex->path : "";
|
||||
p["float_value"] = property.float_value;
|
||||
p["type"] = property.type;
|
||||
|
||||
j["color"] = p;
|
||||
return p;
|
||||
};
|
||||
|
||||
j["color"] = save_property(material->colorProperty);
|
||||
j["normal"] = save_property(material->normalProperty);
|
||||
|
||||
std::ofstream out(path);
|
||||
out << j;
|
||||
|
|
|
@ -436,6 +436,14 @@ void ModelEditor::compile_model() {
|
|||
mat.colorProperty.type = DataType::AssetTexture;
|
||||
}
|
||||
|
||||
aiString normal_path;
|
||||
if(aiReturn_SUCCESS == aiGetMaterialTexture(sc->mMaterials[i], aiTextureType_NORMALS, 0, &normal_path)) {
|
||||
mat.normalProperty.type = DataType::AssetTexture;
|
||||
mat.normalProperty.value_tex.handle = new Texture();
|
||||
mat.normalProperty.value_tex->path = std::string("textures/") + normal_path.C_Str();
|
||||
mat.normalProperty.type = DataType::AssetTexture;
|
||||
}
|
||||
|
||||
save_material(&mat, path);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue