From 063f79a644617acb7568b81bc3eb0ee24c8d0a43 Mon Sep 17 00:00:00 2001 From: Wolfgang Steiner Date: Wed, 5 Jul 2023 15:13:13 +0100 Subject: [PATCH 1/8] Update to handle change to FBX embedded image storage --- src/assimp/assimp.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index bec8263..a3c05ad 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -249,10 +249,8 @@ SamplerData SceneConverter::convertTexture(const aiMaterial& material, aiTexture { SamplerData samplerImage; - if (texPath.data[0] == '*') + if (auto texture = scene->GetEmbeddedTexture(texPath.C_Str())) { - const auto texIndex = std::atoi(texPath.C_Str() + 1); - const auto texture = scene->mTextures[texIndex]; if (texture->mWidth > 0 && texture->mHeight == 0) { auto imageOptions = vsg::Options::create(*options); From 98839d9b1720d997b54f6e2e086b43074415c602 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Jul 2023 16:22:57 +0100 Subject: [PATCH 2/8] Added handling of texture->mHeight != 0 case. --- src/assimp/assimp.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index a3c05ad..dc5de2e 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -251,12 +251,40 @@ SamplerData SceneConverter::convertTexture(const aiMaterial& material, aiTexture if (auto texture = scene->GetEmbeddedTexture(texPath.C_Str())) { - if (texture->mWidth > 0 && texture->mHeight == 0) + // check embedded texture has no width so must be invalid + if (texture->mWidth == 0) return {}; + + if (texture->mHeight == 0) { + // texture is a compressed format, defer to the VSG's vsg::read() to convert the block of data to vsg::Data image. auto imageOptions = vsg::Options::create(*options); imageOptions->extensionHint = vsg::Path(".") + texture->achFormatHint; - if (samplerImage.data = vsg::read_cast(reinterpret_cast(texture->pcData), texture->mWidth, imageOptions); !samplerImage.data.valid()) + samplerImage.data = vsg::read_cast(reinterpret_cast(texture->pcData), texture->mWidth, imageOptions); + + // if no data assigned return null + if (!samplerImage.data) return {}; + } + else + { + // assimp's texture.h comments suggest format is always ARGB8888, which would imply texture->achFormatHint = "argb8888" + // so check the achFormatHint matches what is expected. + if (std::strncmp(texture->achFormatHint, "argb8888", 8) != 0) + { + vsg::warn("Embedded texture format not supported, texture->achFormatHint = ", texture->achFormatHint); return {}; + } + + // Vulkan doesn't support this format we have to reorder it to RGBA + auto image = vsg::ubvec4Array2D::create(texture->mWidth, texture->mHeight, vsg::Data::Properties{VK_FORMAT_R8G8B8A8_UNORM}); + auto src = reinterpret_cast(texture->pcData); + for(auto& c : *image) + { + c.a = *(src++); + c.r = *(src++); + c.g = *(src++); + c.b = *(src++); + } + samplerImage.data = image; } } else From 246b746bd37c716fee3279a30a5656e401359472 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Jul 2023 18:29:05 +0100 Subject: [PATCH 3/8] Fixed mapping of Assimp colour to VSG colour. --- src/assimp/assimp.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index dc5de2e..27fca07 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -140,6 +140,8 @@ struct SceneConverter using CameraMap = std::map>; using LightMap = std::map>; + vsg::Path filename; + vsg::ref_ptr options; const aiScene* scene = nullptr; CameraMap cameraMap; @@ -256,6 +258,8 @@ SamplerData SceneConverter::convertTexture(const aiMaterial& material, aiTexture if (texture->mHeight == 0) { + vsg::debug("filename = ", filename, " : Embedded compressed format texture->achFormatHint = ", texture->achFormatHint); + // texture is a compressed format, defer to the VSG's vsg::read() to convert the block of data to vsg::Data image. auto imageOptions = vsg::Options::create(*options); imageOptions->extensionHint = vsg::Path(".") + texture->achFormatHint; @@ -266,34 +270,28 @@ SamplerData SceneConverter::convertTexture(const aiMaterial& material, aiTexture } else { - // assimp's texture.h comments suggest format is always ARGB8888, which would imply texture->achFormatHint = "argb8888" - // so check the achFormatHint matches what is expected. - if (std::strncmp(texture->achFormatHint, "argb8888", 8) != 0) - { - vsg::warn("Embedded texture format not supported, texture->achFormatHint = ", texture->achFormatHint); - return {}; - } + vsg::debug("filename = ", filename, " : Embedded raw format texture->achFormatHint = ", texture->achFormatHint); // Vulkan doesn't support this format we have to reorder it to RGBA auto image = vsg::ubvec4Array2D::create(texture->mWidth, texture->mHeight, vsg::Data::Properties{VK_FORMAT_R8G8B8A8_UNORM}); - auto src = reinterpret_cast(texture->pcData); - for(auto& c : *image) + auto src = texture->pcData; + for(auto& dest_c : *image) { - c.a = *(src++); - c.r = *(src++); - c.g = *(src++); - c.b = *(src++); + auto& src_c = *(src++); + dest_c.r = src_c.r; + dest_c.g = src_c.g; + dest_c.b = src_c.b; + dest_c.a = src_c.a; } samplerImage.data = image; } } else { - auto filename = vsg::findFile(texPath.C_Str(), options); - - if (samplerImage.data = vsg::read_cast(filename, options); !samplerImage.data.valid()) + auto textureFilename = vsg::findFile(texPath.C_Str(), options); + if (samplerImage.data = vsg::read_cast(textureFilename, options); !samplerImage.data.valid()) { - vsg::warn("Failed to load texture: ", filename, " texPath = ", texPath.C_Str()); + vsg::warn("Failed to load texture: ", textureFilename, " texPath = ", texPath.C_Str()); return {}; } } @@ -1044,6 +1042,7 @@ vsg::ref_ptr assimp::Implementation::read(const vsg::Path& filename opt->paths.insert(opt->paths.begin(), vsg::filePath(filenameToUse)); SceneConverter converter; + converter.filename = filename; return converter.visit(scene, opt, ext); } else From cc1e95c1f290374f4be1e8bd8cde704c1984a283 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Jul 2023 18:33:30 +0100 Subject: [PATCH 4/8] Bumped version number in prep for the next vsgXchange release --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d487129..5e8ec01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.7) project(vsgXchange - VERSION 1.0.3 + VERSION 1.0.4 DESCRIPTION "VulkanSceneGraph 3rd party data integration library" LANGUAGES CXX C ) set(VSGXCHANGE_SOVERSION 1) -SET(VSGXCHANGE_RELEASE_CANDIDATE 0) +SET(VSGXCHANGE_RELEASE_CANDIDATE 1) set(VSGXCHANGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Root source directory of vsgXchange.") set(VSGXCHANGE_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "Root binary directory of vsgXchange.") From 5c93a8a8b2d5e01ec74222c951debae001f2a656 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Jul 2023 13:20:03 +0100 Subject: [PATCH 5/8] Updated to use the new API in DescriptorConfiguratrion. --- src/assimp/assimp.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index 27fca07..e5698cf 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -484,14 +484,10 @@ void SceneConverter::convert(const aiMaterial* material, vsg::DescriptorConfigur if (sharedObjects) { - sharedObjects->share(convertedMaterial.descriptors); - } - - auto descriptorSetLayout = vsg::DescriptorSetLayout::create(convertedMaterial.descriptorBindings); - convertedMaterial.descriptorSet = vsg::DescriptorSet::create(descriptorSetLayout, convertedMaterial.descriptors); - if (sharedObjects) - { - sharedObjects->share(convertedMaterial.descriptorSet); + for(auto& ds : convertedMaterial.descriptorSets) + { + if (ds) sharedObjects->share(ds); + } } } @@ -679,10 +675,10 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) } // pass DescriptorSetLaout to config - if (material.descriptorSet) + for(auto& ds : material.descriptorSets) { - config->descriptorSetLayout = material.descriptorSet->setLayout; - config->descriptorBindings = material.descriptorBindings; + config->descriptorSetLayout = ds->setLayout; + config->descriptorBindings = ds->setLayout->bindings; } // set up ViewDependentState @@ -707,12 +703,14 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) auto stateGroup = vsg::StateGroup::create(); stateGroup->add(config->bindGraphicsPipeline); - if (material.descriptorSet) + for(uint32_t set = 0; set < static_cast(material.descriptorSets.size()); ++set) { - auto bindDescriptorSet = vsg::BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, config->layout, 0, material.descriptorSet); - if (sharedObjects) sharedObjects->share(bindDescriptorSet); - - stateGroup->add(bindDescriptorSet); + if (auto& ds = material.descriptorSets[set]) + { + auto bindDescriptorSet = vsg::BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, config->layout, set, ds); + if (sharedObjects) sharedObjects->share(bindDescriptorSet); + stateGroup->add(bindDescriptorSet); + } } if (useViewDependentState) From 266e9f9ef90498a26b32d6e6d378dab90be6471c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Jul 2023 15:45:29 +0100 Subject: [PATCH 6/8] Added sharing of descriptors --- src/assimp/assimp.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index e5698cf..f8c0e5a 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -486,7 +486,11 @@ void SceneConverter::convert(const aiMaterial* material, vsg::DescriptorConfigur { for(auto& ds : convertedMaterial.descriptorSets) { - if (ds) sharedObjects->share(ds); + if (ds) + { + sharedObjects->share(ds->descriptors); + sharedObjects->share(ds); + } } } } From 41e6cfa5835854441abe6d7b8438a9124aa1a4e9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 14 Jul 2023 15:38:20 +0100 Subject: [PATCH 7/8] Updates to work with changes to vsg::GraphcisPipelineConfigurator --- src/assimp/assimp.cpp | 53 ++++++------------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/src/assimp/assimp.cpp b/src/assimp/assimp.cpp index f8c0e5a..f024684 100644 --- a/src/assimp/assimp.cpp +++ b/src/assimp/assimp.cpp @@ -548,7 +548,7 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) } std::string name = mesh->mName.C_Str(); - auto& material = *convertedMaterials[mesh->mMaterialIndex]; + auto material = convertedMaterials[mesh->mMaterialIndex]; // count the number of indices of each type uint32_t numTriangleIndices = 0; @@ -606,8 +606,8 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) return; } - auto config = vsg::GraphicsPipelineConfigurator::create(material.shaderSet); - config->shaderHints->defines = material.defines; + auto config = vsg::GraphicsPipelineConfigurator::create(material->shaderSet); + config->descriptorConfigurator = material; config->inputAssemblyState->topology = topology; auto indices = createIndices(mesh, numIndicesPerFace, numIndices); @@ -665,7 +665,7 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) vid->instanceCount = 1; if (!name.empty()) vid->setValue("name", name); - if (material.blending) + if (material->blending) { config->colorBlendState->attachments = vsg::ColorBlendState::ColorBlendAttachments{ {true, VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD, VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_SUBTRACT, VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT}}; @@ -673,63 +673,24 @@ void SceneConverter::convert(const aiMesh* mesh, vsg::ref_ptr& node) if (sharedObjects) sharedObjects->share(config->colorBlendState); } - if (material.two_sided) + if (material->two_sided) { config->rasterizationState->cullMode = VK_CULL_MODE_NONE; } - // pass DescriptorSetLaout to config - for(auto& ds : material.descriptorSets) - { - config->descriptorSetLayout = ds->setLayout; - config->descriptorBindings = ds->setLayout->bindings; - } - - // set up ViewDependentState - if (useViewDependentState) - { - vsg::ref_ptr vdsl; - if (sharedObjects) - vdsl = sharedObjects->shared_default(); - else - vdsl = vsg::ViewDescriptorSetLayout::create(); - config->additionalDescriptorSetLayout = vdsl; - } - if (sharedObjects) sharedObjects->share(config, [](auto gpc) { gpc->init(); }); else config->init(); - if (sharedObjects) sharedObjects->share(config->bindGraphicsPipeline); - // create StateGroup as the root of the scene/command graph to hold the GraphicsProgram, and binding of Descriptors to decorate the whole graph auto stateGroup = vsg::StateGroup::create(); - stateGroup->add(config->bindGraphicsPipeline); - - for(uint32_t set = 0; set < static_cast(material.descriptorSets.size()); ++set) - { - if (auto& ds = material.descriptorSets[set]) - { - auto bindDescriptorSet = vsg::BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, config->layout, set, ds); - if (sharedObjects) sharedObjects->share(bindDescriptorSet); - stateGroup->add(bindDescriptorSet); - } - } - - if (useViewDependentState) - { - auto bindViewDescriptorSets = vsg::BindViewDescriptorSets::create(VK_PIPELINE_BIND_POINT_GRAPHICS, config->layout, 1); - if (sharedObjects) sharedObjects->share(bindViewDescriptorSets); - stateGroup->add(bindViewDescriptorSets); - } - // assign any custom ArrayState that may be required. - stateGroup->prototypeArrayState = config->shaderSet->getSuitableArrayState(config->shaderHints->defines); + config->copyTo(stateGroup, sharedObjects); stateGroup->addChild(vid); - if (material.blending) + if (material->blending) { vsg::ComputeBounds computeBounds; vid->accept(computeBounds); From 9a0e9919a02e2cdf1860fec408659c6340a9bc0f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 Jul 2023 11:12:39 +0100 Subject: [PATCH 8/8] Bumped required VSG version to 1.0.8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e8ec01..d76bcd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ if (VULKAN_SDK) set(ENV{VULKAN_SDK} ${VULKAN_SDK}) endif() -set(VSG_MIN_VERSION 1.0.3) +set(VSG_MIN_VERSION 1.0.8) find_package(vsg ${VSG_MIN_VERSION}) vsg_setup_dir_vars()