Skip to content

Commit

Permalink
adding an objects_by_name routine to vierkant::Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
crocdialer committed Mar 28, 2024
1 parent d7cc982 commit a3364c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/vierkant/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Scene
*/
[[nodiscard]] Object3D* object_by_id(uint32_t object_id) const;

[[nodiscard]] std::vector<Object3D*> objects_by_name(const std::string_view &name) const;

[[nodiscard]] Object3DPtr pick(const Ray &ray) const;

[[nodiscard]] inline const Object3DPtr &root() const { return m_root; };
Expand Down
12 changes: 12 additions & 0 deletions src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ Object3D *Scene::object_by_id(uint32_t object_id) const
return object_ptr ? *object_ptr : nullptr;
}

std::vector<Object3D *> Scene::objects_by_name(const std::string_view &name) const
{
std::vector<Object3D *> ret;
auto view = m_registry->view<Object3D *>();
for(const auto &[entity, object]: view.each())
{
if(object->name == name) { ret.push_back(object); }
}
return ret;
}

Object3DPtr Scene::pick(const Ray &ray) const
{
Object3DPtr ret;
Expand Down Expand Up @@ -101,6 +112,7 @@ void Scene::set_environment(const vierkant::ImagePtr &img)
if(!img) { return; }
m_skybox = img;
}

}// namespace vierkant

size_t std::hash<vierkant::id_entry_t>::operator()(vierkant::id_entry_t const &key) const
Expand Down

0 comments on commit a3364c4

Please sign in to comment.