Archived
1
Fork 0

Add sibenik scene to example app

* Sourced from McGuire Computer Graphics Archive
* New compiled materials from models are pointed to the textures directory by default
* New models are given a "material hint" for easier authoring, will be an seperate option later on
* Introduced model version 7
This commit is contained in:
Joshua Goins 2022-02-03 10:49:02 -05:00
parent c821575ea4
commit aa8968625b
27 changed files with 72 additions and 19 deletions

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.6000000238418579,"y":0.6000000238418579,"z":0.6000000238418579}},"version":3}

View file

@ -0,0 +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}

View file

@ -0,0 +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}

View file

@ -0,0 +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}

View file

@ -0,0 +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}

View file

@ -0,0 +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}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":1.0,"y":0.11999999731779099,"z":0.10000000149011612}},"version":3}

View file

@ -0,0 +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}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.784313976764679,"y":0.784313976764679,"z":0.784313976764679}},"version":3}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.44117599725723267,"y":0.10392200201749802,"z":0.04901999980211258}},"version":3}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}

View file

@ -0,0 +1 @@
{"color":{"asset_value":"","float_value":0.0,"name":"","type":0,"value":{"x":0.0,"y":0.0,"z":0.0}},"version":3}

View file

@ -0,0 +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}

View file

@ -0,0 +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}

BIN
data/models/sibenik.model Normal file

Binary file not shown.

4
data/sibenik-license.txt Normal file
View file

@ -0,0 +1,4 @@
The Sibenik model bundled with this program is licensed under CC BY-NC. Original copyright © 2002 Marko Dabrovic.
Sourced from:
Morgan McGuire, Computer Graphics Archive, July 2017 (https://casual-effects.com/data)

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

BIN
data/textures/kamen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
data/textures/mramor6x6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

View file

@ -83,6 +83,7 @@ public:
uint32_t index_offset = 0, vertex_offset = 0, index_count = 0; uint32_t index_offset = 0, vertex_offset = 0, index_count = 0;
int32_t material_override = -1; int32_t material_override = -1;
std::string material_hint;
}; };
std::vector<Part> parts; std::vector<Part> parts;

View file

@ -27,7 +27,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
int version = 0; int version = 0;
file->read(&version); file->read(&version);
if(version == 5 || version == 6) { if(version == 5 || version == 6 || version == 7) {
} else { } else {
prism::log("{} failed the mesh version check! reported version = {}", path.string(), version); prism::log("{} failed the mesh version check! reported version = {}", path.string(), version);
return nullptr; return nullptr;
@ -51,7 +51,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
const auto read_buffer = [&f = file.value(), numVertices](unsigned int size) -> GFXBuffer* { const auto read_buffer = [&f = file.value(), numVertices](unsigned int size) -> GFXBuffer* {
auto buffer = engine->get_gfx()->create_buffer(nullptr, size * static_cast<unsigned int>(numVertices), false, GFXBufferUsage::Vertex); auto buffer = engine->get_gfx()->create_buffer(nullptr, size * static_cast<unsigned int>(numVertices), false, GFXBufferUsage::Vertex);
auto buffer_ptr = reinterpret_cast<unsigned char*>(engine->get_gfx()->get_buffer_contents(buffer)); auto buffer_ptr = reinterpret_cast<unsigned char*>(engine->get_gfx()->get_buffer_contents(buffer));
f.read(buffer_ptr, size * static_cast<unsigned int>(numVertices)); f.read(buffer_ptr, size * static_cast<unsigned int>(numVertices));
@ -154,7 +154,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
file->read_string(p.name); file->read_string(p.name);
if(version == 6) { if(version >= 6) {
file->read(&p.bounding_box); file->read(&p.bounding_box);
} }
@ -176,6 +176,10 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
file->read(&p.material_override); file->read(&p.material_override);
if(version == 7) {
file->read_string(p.material_hint);
}
vertexOffset += numVerts; vertexOffset += numVerts;
indexOffset += p.index_count; indexOffset += p.index_count;
} }
@ -265,6 +269,7 @@ std::unique_ptr<Material> load_material(const prism::path path) {
auto property = j["color"]; auto property = j["color"];
mat->colorProperty.value = property["value"]; mat->colorProperty.value = property["value"];
mat->colorProperty.float_value = property["float_value"]; mat->colorProperty.float_value = property["float_value"];
mat->colorProperty.type = property["type"];
if(!property["asset_value"].get<std::string>().empty()) { if(!property["asset_value"].get<std::string>().empty()) {
mat->colorProperty.value_tex = assetm->get<Texture>(prism::app_domain / property["asset_value"].get<std::string>()); mat->colorProperty.value_tex = assetm->get<Texture>(prism::app_domain / property["asset_value"].get<std::string>());
@ -285,6 +290,7 @@ void save_material(Material* material, const prism::path path) {
p["value"] = material->colorProperty.value; p["value"] = material->colorProperty.value;
p["asset_value"] = material->colorProperty.value_tex ? material->colorProperty.value_tex->path : ""; p["asset_value"] = material->colorProperty.value_tex ? material->colorProperty.value_tex->path : "";
p["float_value"] = material->colorProperty.float_value; p["float_value"] = material->colorProperty.float_value;
p["type"] = material->colorProperty.type;
j["color"] = p; j["color"] = p;

View file

@ -24,15 +24,30 @@ void ExampleApp::initialize_render() {
auto sun_obj = scene->add_object(); auto sun_obj = scene->add_object();
auto& sun = scene->add<Light>(sun_obj); auto& sun = scene->add<Light>(sun_obj);
sun.type = Light::Type::Sun; sun.type = Light::Type::Point;
auto& sun_trans = scene->get<Transform>(sun_obj); auto& sun_trans = scene->get<Transform>(sun_obj);
sun_trans.position = {5, 5, 5}; sun_trans.position = {0, 5, -3};
auto second_sun_obj = scene->add_object();
auto& second_sun = scene->add<Light>(second_sun_obj);
second_sun.type = Light::Type::Point;
second_sun.color = {1, 0, 0};
scene->get<Transform>(second_sun_obj).position = {2, 3, 3};
auto sphere_obj = scene->add_object(); auto sphere_obj = scene->add_object();
auto& sphere_render = scene->add<Renderable>(sphere_obj); auto& sphere_render = scene->add<Renderable>(sphere_obj);
sphere_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/sphere.model")); sphere_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/sphere.model"));
sphere_render.materials = { assetm->get<Material>(prism::path(prism::app_domain / "materials/Material.material")) }; sphere_render.materials = { assetm->get<Material>(prism::path(prism::app_domain / "materials/Material.material")) };
auto sibenik_obj = scene->add_object();
auto& sibenik_render = scene->add<Renderable>(sibenik_obj);
sibenik_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/sibenik.model"));
scene->get<Transform>(sibenik_obj).position.y = 13.5;
for(auto& part : sibenik_render.mesh->parts) {
sibenik_render.materials.push_back(assetm->get<Material>(prism::path(prism::app_domain / "materials" / (part.material_hint + ".material"))));
}
auto probe_obj = scene->add_object(); auto probe_obj = scene->add_object();
scene->add<EnvironmentProbe>(probe_obj); scene->add<EnvironmentProbe>(probe_obj).is_sized = false;
} }

View file

@ -141,7 +141,20 @@ aiVector3D getBoneScale(const aiScene* scene, const aiBone* bone) {
void write_string(FILE* file, const aiString& str) { void write_string(FILE* file, const aiString& str) {
fwrite(&str.length, sizeof(unsigned int), 1, file); fwrite(&str.length, sizeof(unsigned int), 1, file);
fwrite(str.C_Str(), sizeof(char) * str.length, 1, file); if(str.length > 0) {
fwrite(str.C_Str(), sizeof(char) * str.length, 1, file);
prism::log("writing string {}", str.C_Str());
}
}
void write_string(FILE* file, const std::string& str) {
unsigned int len = str.length();
fwrite(&len, sizeof(unsigned int), 1, file);
if(str.length() > 0) {
fwrite(str.c_str(), sizeof(char) * len, 1, file);
prism::log("writing string {}", str.c_str());
}
} }
void ModelEditor::compile_model() { void ModelEditor::compile_model() {
@ -196,7 +209,7 @@ void ModelEditor::compile_model() {
FILE* file = fopen((data_path + "/models/" + name + ".model").c_str(), "wb"); FILE* file = fopen((data_path + "/models/" + name + ".model").c_str(), "wb");
int version = 6; int version = 7;
fwrite(&version, sizeof(int), 1, file); fwrite(&version, sizeof(int), 1, file);
std::vector<std::string> meshToMaterial; std::vector<std::string> meshToMaterial;
@ -299,11 +312,11 @@ void ModelEditor::compile_model() {
} }
}; };
write_buffer(positions, sizeof(aiVector3D)); write_buffer(positions, sizeof(prism::float3));
write_buffer(normals, sizeof(aiVector3D)); write_buffer(normals, sizeof(prism::float3));
write_buffer(texture_coords, sizeof(aiVector2D)); write_buffer(texture_coords, sizeof(prism::float2));
write_buffer(tangents, sizeof(aiVector3D)); write_buffer(tangents, sizeof(prism::float3));
write_buffer(bitangents, sizeof(aiVector3D)); write_buffer(bitangents, sizeof(prism::float3));
if(mesh_type == MeshType::Skinned) if(mesh_type == MeshType::Skinned)
write_buffer(bone_vertex_data, sizeof(BoneVertexData)); write_buffer(bone_vertex_data, sizeof(BoneVertexData));
@ -397,6 +410,8 @@ void ModelEditor::compile_model() {
int material_override = matNameToIndex[meshToMaterial[i]]; int material_override = matNameToIndex[meshToMaterial[i]];
fwrite(&material_override, sizeof(int), 1, file); fwrite(&material_override, sizeof(int), 1, file);
write_string(file, meshToMaterial[i]);
} }
fclose(file); fclose(file);
@ -405,11 +420,6 @@ void ModelEditor::compile_model() {
for(int i = 0; i < sc->mNumMaterials; i++) { for(int i = 0; i < sc->mNumMaterials; i++) {
auto path = data_path + "/materials/" + sc->mMaterials[i]->GetName().C_Str() + ".material"; auto path = data_path + "/materials/" + sc->mMaterials[i]->GetName().C_Str() + ".material";
// skip materials that already exist
std::ifstream infile(path);
if(infile.good())
continue;
Material mat; Material mat;
aiColor4D color; aiColor4D color;
@ -422,7 +432,8 @@ void ModelEditor::compile_model() {
if(aiReturn_SUCCESS == aiGetMaterialTexture(sc->mMaterials[i], aiTextureType_DIFFUSE, 0, &diffuse_path)) { if(aiReturn_SUCCESS == aiGetMaterialTexture(sc->mMaterials[i], aiTextureType_DIFFUSE, 0, &diffuse_path)) {
mat.colorProperty.type = DataType::AssetTexture; mat.colorProperty.type = DataType::AssetTexture;
mat.colorProperty.value_tex.handle = new Texture(); mat.colorProperty.value_tex.handle = new Texture();
mat.colorProperty.value_tex->path = diffuse_path.C_Str(); mat.colorProperty.value_tex->path = std::string("textures/") + diffuse_path.C_Str();
mat.colorProperty.type = DataType::AssetTexture;
} }
save_material(&mat, path); save_material(&mat, path);