14#include <lagrange/ui/Entity.h>
15#include <lagrange/ui/components/MeshData.h>
16#include <lagrange/ui/components/MeshGeometry.h>
17#include <lagrange/ui/types/AABB.h>
18#include <lagrange/ui/types/Frustum.h>
19#include <lagrange/ui/types/RayFacetHit.h>
20#include <lagrange/ui/utils/math.h>
21#include <lagrange/ui/api.h>
34template <
typename MeshType>
35Entity register_mesh(Registry& r, std::shared_ptr<MeshType> mesh)
40 d.type = entt::type_id<MeshType>();
41 r.emplace<MeshData>(e, std::move(d));
45template <
typename MeshType>
46Entity register_mesh(Registry& r, std::unique_ptr<MeshType> mesh)
48 return register_mesh(r, std::shared_ptr<MeshType>(mesh.release()));
57template <
typename V,
typename F>
59template <
typename V,
typename F>
61template <
typename MeshType>
62MeshType& get_mesh(Registry& r, Entity e);
64LA_UI_API MeshData& get_mesh_data(Registry& r, Entity e);
65LA_UI_API
const MeshData& get_mesh_data(
const Registry& r, Entity e);
67LA_UI_API
bool has_mesh_component(
const Registry& r, Entity e);
69LA_UI_API
size_t get_num_vertices(
const MeshData& d);
70LA_UI_API
size_t get_num_facets(
const MeshData& d);
71LA_UI_API
size_t get_num_edges(
const MeshData& d);
72LA_UI_API RowMajorMatrixXf get_mesh_vertices(
const MeshData& d);
73LA_UI_API RowMajorMatrixXi get_mesh_facets(
const MeshData& d);
74LA_UI_API RowMajorMatrixXf get_mesh_vertex_attribute(
const MeshData& d,
const std::string& name);
75LA_UI_API RowMajorMatrixXf get_mesh_corner_attribute(
const MeshData& d,
const std::string& name);
76LA_UI_API RowMajorMatrixXf get_mesh_facet_attribute(
const MeshData& d,
const std::string& name);
77LA_UI_API RowMajorMatrixXf get_mesh_edge_attribute(
const MeshData& d,
const std::string& name);
78LA_UI_API RowMajorMatrixXf get_mesh_attribute(
const MeshData& d, IndexingMode mode,
const std::string& name);
79std::pair<Eigen::VectorXf, Eigen::VectorXf>
80LA_UI_API get_mesh_attribute_range(
const MeshData& d, IndexingMode mode,
const std::string& name);
81LA_UI_API AABB get_mesh_bounds(
const MeshData& d);
88LA_UI_API
void ensure_uv(MeshData& d);
89LA_UI_API
void ensure_normal(MeshData& d);
90LA_UI_API
void ensure_tangent_bitangent(MeshData& d);
91LA_UI_API
void ensure_is_selected_attribute(MeshData& d);
92LA_UI_API
void map_indexed_attribute_to_corner_attribute(MeshData& d,
const std::string& name);
93LA_UI_API
void map_corner_attribute_to_vertex_attribute(MeshData& d,
const std::string& name);
99LA_UI_API
void upload_mesh_vertices(
const MeshData& d, GPUBuffer& gpu);
100LA_UI_API
void upload_mesh_triangles(
const MeshData& d, GPUBuffer& gpu);
102LA_UI_API
void upload_mesh_vertex_attribute(
const MeshData& d,
const RowMajorMatrixXf& data, GPUBuffer& gpu);
103LA_UI_API
void upload_mesh_corner_attribute(
const MeshData& d,
const RowMajorMatrixXf& data, GPUBuffer& gpu);
104LA_UI_API
void upload_mesh_facet_attribute(
const MeshData& d,
const RowMajorMatrixXf& data, GPUBuffer& gpu);
105LA_UI_API
void upload_mesh_edge_attribute(
const MeshData& d,
const RowMajorMatrixXf& data, GPUBuffer& gpu);
107LA_UI_API std::unordered_map<entt::id_type, std::shared_ptr<GPUBuffer>> upload_submesh_indices(
109 const std::string& facet_attrib_name);
114LA_UI_API
bool has_mesh_vertex_attribute(
const MeshData& d,
const std::string& name);
115LA_UI_API
bool has_mesh_corner_attribute(
const MeshData& d,
const std::string& name);
116LA_UI_API
bool has_mesh_facet_attribute(
const MeshData& d,
const std::string& name);
117LA_UI_API
bool has_mesh_edge_attribute(
const MeshData& d,
const std::string& name);
118LA_UI_API
bool has_mesh_indexed_attribute(
const MeshData& d,
const std::string& name);
125LA_UI_API std::optional<RayFacetHit>
126intersect_ray(
const MeshData& d,
const Eigen::Vector3f& origin,
const Eigen::Vector3f& dir);
128LA_UI_API
void select_vertices_in_frustum(
130 SelectionBehavior sel_behavior,
131 const Frustum& frustum);
132LA_UI_API
void select_edges_in_frustum(MeshData& d, SelectionBehavior sel_behavior,
const Frustum& frustum);
133LA_UI_API
void propagate_corner_selection(MeshData& d,
const std::string& attrib_name);
134LA_UI_API
void propagate_vertex_selection(MeshData& d,
const std::string& attrib_name);
135LA_UI_API
void propagate_facet_selection(MeshData& d,
const std::string& attrib_name);
136LA_UI_API
void combine_vertex_and_corner_selection(MeshData& d,
const std::string& attrib_name);
137LA_UI_API
void select_facets_by_color(
139 const std::string& attrib_name,
140 SelectionBehavior sel_behavior,
141 const unsigned char* color_bytes,
142 size_t colors_byte_size);
143LA_UI_API
void select_edges_by_color(
145 const std::string& attrib_name,
146 SelectionBehavior sel_behavior,
147 const unsigned char* color_bytes,
148 size_t colors_byte_size);
149LA_UI_API
void select_vertices_by_color(
151 const std::string& attrib_name,
152 SelectionBehavior sel_behavior,
153 const unsigned char* color_bytes,
154 size_t colors_byte_size);
155LA_UI_API
void select_facets(
157 SelectionBehavior sel_behavior,
158 const std::vector<int>& facet_indices);
160LA_UI_API
void filter_closest_vertex(
162 const std::string& attrib_name,
163 SelectionBehavior sel_behavior,
164 const Camera& camera,
165 const Eigen::Vector2i& viewport_pos);
167template <
typename V,
typename F>
170 return cast_mesh<V, F>(r.get<
const MeshData>(e));
174template <
typename V,
typename F>
179 mesh_data.type == entt::type_id<MeshType>() && mesh_data.mesh,
180 "Incorrect mesh type");
181 return reinterpret_cast<MeshType&
>(*mesh_data.mesh);
184template <
typename MeshType>
185MeshType& get_mesh(Registry& r, Entity e)
188 return cast_mesh<typename MeshType::VertexArray, typename MeshType::FacetArray>(
192inline Entity get_mesh_entity(Registry& r, Entity e)
194 if (r.all_of<MeshData>(e))
return e;
195 if (r.all_of<MeshGeometry>(e))
return r.get<MeshGeometry>(e).entity;
bool select_facets_in_frustum(SurfaceMesh< Scalar, Index > &mesh, const Frustum< Scalar > &frustum, const FrustumSelectionOptions &options={})
Select all facets that intersect the cone/frustrum bounded by 4 planes defined by (n_i,...
Definition: select_facets_in_frustum.cpp:32
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API std::optional< std::pair< Entity, RayFacetHit > > intersect_ray(Registry &r, const Eigen::Vector3f &origin, const Eigen::Vector3f &dir, ui::Entity root=ui::NullEntity, Layer visible_layers=Layer(true), Layer hidden_layers=Layer(false))
Intersect ray with meshes in root's hierarchy Returns a pair of intersected entity and the correspond...
Definition: default_entities.cpp:502
Main namespace for Lagrange.
Definition: AABBIGL.h:30