Add scene_data::find_material function
This commit is contained in:
@@ -955,3 +955,17 @@ scene_object_handle scene_data::find_node(scene_object_handle root, std::string_
|
|||||||
// TODO custom exception
|
// TODO custom exception
|
||||||
throw std::runtime_error("Node " + std::string(name) + " not found");
|
throw std::runtime_error("Node " + std::string(name) + " not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<scene_data::material> scene_data::find_material(std::string_view name)
|
||||||
|
{
|
||||||
|
for(auto& mesh:meshes)
|
||||||
|
{
|
||||||
|
for(auto& primitive: mesh.primitives)
|
||||||
|
{
|
||||||
|
if (primitive.material_ && primitive.material_->name == name)
|
||||||
|
return primitive.material_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ struct scene_data
|
|||||||
|
|
||||||
// Set to true to update the descriptor set at the next frame
|
// Set to true to update the descriptor set at the next frame
|
||||||
bool ds_dirty;
|
bool ds_dirty;
|
||||||
|
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vertex
|
struct vertex
|
||||||
@@ -197,6 +199,8 @@ struct scene_data
|
|||||||
scene_object_handle new_node();
|
scene_object_handle new_node();
|
||||||
scene_object_handle find_node(std::string_view name);
|
scene_object_handle find_node(std::string_view name);
|
||||||
scene_object_handle find_node(scene_object_handle parent, std::string_view name);
|
scene_object_handle find_node(scene_object_handle parent, std::string_view name);
|
||||||
|
|
||||||
|
std::shared_ptr<material> find_material(std::string_view name);
|
||||||
};
|
};
|
||||||
|
|
||||||
class scene_loader
|
class scene_loader
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ std::shared_ptr<scene_data::texture> scene_renderer::create_default_texture(vk::
|
|||||||
std::shared_ptr<scene_data::material> scene_renderer::create_default_material(vk::raii::CommandPool & cb_pool)
|
std::shared_ptr<scene_data::material> scene_renderer::create_default_material(vk::raii::CommandPool & cb_pool)
|
||||||
{
|
{
|
||||||
auto default_material = std::make_shared<scene_data::material>();
|
auto default_material = std::make_shared<scene_data::material>();
|
||||||
|
default_material->name = "default";
|
||||||
|
|
||||||
auto cb = std::move(device.allocateCommandBuffers(vk::CommandBufferAllocateInfo{
|
auto cb = std::move(device.allocateCommandBuffers(vk::CommandBufferAllocateInfo{
|
||||||
.commandPool = *cb_pool,
|
.commandPool = *cb_pool,
|
||||||
|
|||||||
Reference in New Issue
Block a user