diff --git a/include/limitless/loaders/gltf_model_loader.hpp b/include/limitless/loaders/gltf_model_loader.hpp index 77b805e4..e07a8b4b 100644 --- a/include/limitless/loaders/gltf_model_loader.hpp +++ b/include/limitless/loaders/gltf_model_loader.hpp @@ -26,8 +26,19 @@ namespace Limitless { public: std::set options; float scale_factor {1.0f}; + InstanceTypes additional_instance_types; auto isPresent(ModelLoaderOption option) const { return options.count(option) != 0; } + + ModelLoaderFlags& additionalInstanceTypes(InstanceTypes _additional_instance_types) { + additional_instance_types = _additional_instance_types; + return *this; + } + + ModelLoaderFlags& instanced() { + additional_instance_types.emplace(InstanceType::Instanced); + return *this; + } }; class GltfModelLoader { diff --git a/include/limitless/ms/material_builder.hpp b/include/limitless/ms/material_builder.hpp index f87dae62..3bdadecd 100644 --- a/include/limitless/ms/material_builder.hpp +++ b/include/limitless/ms/material_builder.hpp @@ -36,7 +36,7 @@ namespace Limitless::ms { std::string global_snippet; std::string shading_snippet; - bool _skybox; + bool _skybox {false}; UniqueMaterial getMaterialType() const noexcept; void checkRequirements(); diff --git a/include/limitless/scene.hpp b/include/limitless/scene.hpp index 3c66e87f..b53b8cc4 100644 --- a/include/limitless/scene.hpp +++ b/include/limitless/scene.hpp @@ -53,6 +53,9 @@ namespace Limitless { std::shared_ptr& getSkybox() noexcept; void setSkybox(const std::shared_ptr& skybox); + /** + * Return visible scene instances. + */ Instances getInstances() const noexcept; void update(const Camera& camera); diff --git a/src/limitless/instances/instanced_instance.cpp b/src/limitless/instances/instanced_instance.cpp index 1500c766..9e523240 100644 --- a/src/limitless/instances/instanced_instance.cpp +++ b/src/limitless/instances/instanced_instance.cpp @@ -38,7 +38,8 @@ void InstancedInstance::add(const std::shared_ptr& instance) { } void InstancedInstance::remove(uint64_t id){ - [[maybe_unused]] auto res = std::remove_if(instances.begin(), instances.end(), [&] (auto& i) { return i->getId() == id; }); + auto it = std::remove_if(instances.begin(), instances.end(), [&] (auto& i) { return i->getId() == id; }); + instances.erase(it, instances.end()); } void InstancedInstance::updateInstanceBuffer() { diff --git a/src/limitless/loaders/gltf_model_loader.cpp b/src/limitless/loaders/gltf_model_loader.cpp index 81b4d37b..18fc3e70 100644 --- a/src/limitless/loaders/gltf_model_loader.cpp +++ b/src/limitless/loaders/gltf_model_loader.cpp @@ -872,15 +872,16 @@ static std::shared_ptr loadMaterial( builder.color(toVec4(pbr_mr.base_color_factor)); } - auto* mr_tex = pbr_mr.metallic_roughness_texture.texture; - if (mr_tex && mr_tex->image) { - // These values MUST be encoded with a linear transfer function. - const auto flags = TextureLoaderFlags(TextureLoaderFlags::Space::Linear); + // TODO: load as metallic-roughness texture. + // auto* mr_tex = pbr_mr.metallic_roughness_texture.texture; + // if (mr_tex && mr_tex->image) { + // // These values MUST be encoded with a linear transfer function. + // const auto flags = TextureLoaderFlags(TextureLoaderFlags::Space::Linear); - builder.orm(*loadTextureFrom(*mr_tex, material_name + "_orm", flags)); - builder.metallic(pbr_mr.metallic_factor); - builder.roughness(pbr_mr.roughness_factor); - } + // builder.orm(*loadTextureFrom(*mr_tex, material_name + "_orm", flags)); + // builder.metallic(pbr_mr.metallic_factor); + // builder.roughness(pbr_mr.roughness_factor); + // } auto* normal_tex = material.normal_texture.texture; if (normal_tex && normal_tex->image) { @@ -1036,7 +1037,8 @@ static SkeletalModel* loadSkeletalModel( auto bone_indices_tree = makeBoneIndiceTrees(root_nodes, bone_map); - const InstanceTypes instance_types {InstanceType::Skeletal}; + InstanceTypes instance_types = flags.additional_instance_types; + instance_types.emplace(InstanceType::Skeletal); auto loaded_materials = loadMaterials(model_name, assets, instance_types, path, src, flags); std::vector> meshes; @@ -1079,7 +1081,8 @@ static Model* loadPlainModel( ) { std::vector> meshes; std::vector> mesh_materials; - const InstanceTypes instance_types {InstanceType::Model}; + InstanceTypes instance_types = flags.additional_instance_types; + instance_types.emplace(InstanceType::Model); auto loaded_materials = loadMaterials(model_name, assets, instance_types, path, src, flags); diff --git a/src/limitless/scene.cpp b/src/limitless/scene.cpp index 80a67450..9ca90f6e 100644 --- a/src/limitless/scene.cpp +++ b/src/limitless/scene.cpp @@ -141,6 +141,10 @@ Instances Scene::getInstances() const noexcept { for (const auto& [_, instance] : instances) { visitor(instance); + if (instance->isHidden()) { + continue; + } + visitor(instance); } return wrappers;