Skip to content
Snippets Groups Projects
Commit e006dbe6 authored by Mara Vogt's avatar Mara Vogt
Browse files

[#63] fixed a bug and filled materials struct

materials can now be loaded
parent d5bd938c
No related branches found
No related tags found
1 merge request!51Resolve "Laden mehrer Meshes mit Materials und Textures"
Pipeline #25453 passed
......@@ -282,6 +282,7 @@ int loadScene(const std::string &path, Scene &scene){
for(int j = 0; j < objectMesh.primitives.size(); j++){
fx::gltf::Primitive const &objectPrimitive = objectMesh.primitives[j];
vertexAttributes.clear();
vertexAttributes.reserve(objectPrimitive.attributes.size());
for (auto const & attrib : objectPrimitive.attributes) {
......@@ -419,7 +420,39 @@ int loadScene(const std::string &path, Scene &scene){
}
}
// TODO fill materials struct and vector
if (sceneObjects.materials.size() > 0){
materials.reserve(sceneObjects.materials.size());
for (int l = 0; l < sceneObjects.materials.size(); l++){
fx::gltf::Material material = sceneObjects.materials[l];
materials.push_back({
0, // TODO; macros not yet defined
material.pbrMetallicRoughness.baseColorTexture.index,
material.pbrMetallicRoughness.metallicRoughnessTexture.index,
material.normalTexture.index,
material.occlusionTexture.index,
material.emissiveTexture.index,
{
material.pbrMetallicRoughness.baseColorFactor[0],
material.pbrMetallicRoughness.baseColorFactor[1],
material.pbrMetallicRoughness.baseColorFactor[2],
material.pbrMetallicRoughness.baseColorFactor[3]
},
material.pbrMetallicRoughness.metallicFactor,
material.pbrMetallicRoughness.roughnessFactor,
material.normalTexture.scale,
material.occlusionTexture.strength,
{
material.emissiveFactor[0],
material.emissiveFactor[1],
material.emissiveFactor[2]
}
});
printf("baseColor index=%d normal=%d metallic factor=%f\n",
materials[l].baseColor, materials[l].normal, materials[l].metallicFactor);
}
}
scene = {
meshes,
......
......@@ -46,19 +46,19 @@ int main(int argc, const char** argv) {
assert(mesh.vertexGroups.size() > 0);
auto vertexBuffer = core.createBuffer<uint8_t>(
vkcv::BufferType::VERTEX,
mesh.vertexGroups[0].vertexBuffer.data.size(),
mesh.vertexGroups[2].vertexBuffer.data.size(),
vkcv::BufferMemoryType::DEVICE_LOCAL
);
vertexBuffer.fill(mesh.vertexGroups[0].vertexBuffer.data);
vertexBuffer.fill(mesh.vertexGroups[2].vertexBuffer.data);
auto indexBuffer = core.createBuffer<uint8_t>(
vkcv::BufferType::INDEX,
mesh.vertexGroups[0].indexBuffer.data.size(),
mesh.vertexGroups[2].indexBuffer.data.size(),
vkcv::BufferMemoryType::DEVICE_LOCAL
);
indexBuffer.fill(mesh.vertexGroups[0].indexBuffer.data);
indexBuffer.fill(mesh.vertexGroups[2].indexBuffer.data);
// an example attachment for passes that output to the window
const vkcv::AttachmentDescription present_color_attachment(
......@@ -93,7 +93,7 @@ int main(int argc, const char** argv) {
triangleShaderProgram.reflectShader(vkcv::ShaderStage::VERTEX);
triangleShaderProgram.reflectShader(vkcv::ShaderStage::FRAGMENT);
auto& attributes = mesh.vertexGroups[0].vertexBuffer.attributes;
auto& attributes = mesh.vertexGroups[2].vertexBuffer.attributes;
std::sort(attributes.begin(), attributes.end(), [](const vkcv::VertexAttribute& x, const vkcv::VertexAttribute& y) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
......@@ -116,7 +116,7 @@ int main(int argc, const char** argv) {
windowWidth,
windowHeight,
trianglePass,
mesh.vertexGroups[0].vertexBuffer.attributes,
mesh.vertexGroups[2].vertexBuffer.attributes,
{ core.getDescriptorSetLayout(set, 0) });
vkcv::PipelineHandle trianglePipeline = core.createGraphicsPipeline(trianglePipelineDefinition);
......@@ -127,7 +127,7 @@ int main(int argc, const char** argv) {
// FIXME There should be a test here to make sure there is at least 1
// texture in the mesh.
vkcv::asset::Texture &tex = mesh.textures[0];
vkcv::asset::Texture &tex = mesh.textures[2];
vkcv::Image texture = core.createImage(vk::Format::eR8G8B8A8Srgb, tex.w, tex.h);
texture.fill(tex.data.data());
......@@ -139,9 +139,9 @@ int main(int argc, const char** argv) {
);
std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
{ mesh.vertexGroups[0].vertexBuffer.attributes[0].offset, vertexBuffer.getHandle() },
{ mesh.vertexGroups[0].vertexBuffer.attributes[1].offset, vertexBuffer.getHandle() },
{ mesh.vertexGroups[0].vertexBuffer.attributes[2].offset, vertexBuffer.getHandle() }
{ mesh.vertexGroups[2].vertexBuffer.attributes[0].offset, vertexBuffer.getHandle() },
{ mesh.vertexGroups[2].vertexBuffer.attributes[1].offset, vertexBuffer.getHandle() },
{ mesh.vertexGroups[2].vertexBuffer.attributes[2].offset, vertexBuffer.getHandle() }
};
vkcv::DescriptorWrites setWrites;
......@@ -168,7 +168,7 @@ int main(int argc, const char** argv) {
&mvp,
vertexBufferBindings,
indexBuffer.getHandle(),
mesh.vertexGroups[0].numIndices,
mesh.vertexGroups[2].numIndices,
set,
0
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment