14#include <lagrange/ui/Entity.h>
15#include <lagrange/ui/api.h>
16#include <lagrange/ui/components/MeshData.h>
17#include <lagrange/ui/components/MeshGeometry.h>
18#include <lagrange/ui/types/AABB.h>
19#include <lagrange/ui/types/Frustum.h>
20#include <lagrange/ui/types/RayFacetHit.h>
21#include <lagrange/ui/utils/math.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>
58lagrange::Mesh<V, F>& cast_mesh(
MeshData& mesh_data);
59template <
typename V,
typename F>
60lagrange::Mesh<V, F>& cast_mesh(
MeshData& mesh_data);
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
79get_mesh_attribute(
const MeshData& d, IndexingMode mode,
const std::string& name);
80std::pair<Eigen::VectorXf, Eigen::VectorXf> LA_UI_API
81get_mesh_attribute_range(
const MeshData& d, IndexingMode mode,
const std::string& name);
89LA_UI_API
void ensure_uv(
MeshData& d);
90LA_UI_API
void ensure_normal(
MeshData& d);
91LA_UI_API
void ensure_tangent_bitangent(
MeshData& d);
92LA_UI_API
void ensure_is_selected_attribute(
MeshData& d);
93LA_UI_API
void map_indexed_attribute_to_corner_attribute(
MeshData& d,
const std::string& name);
94LA_UI_API
void map_corner_attribute_to_vertex_attribute(
MeshData& d,
const std::string& name);
104upload_mesh_vertex_attribute(
const MeshData& d,
const RowMajorMatrixXf& data,
GPUBuffer& gpu);
106upload_mesh_corner_attribute(
const MeshData& d,
const RowMajorMatrixXf& data,
GPUBuffer& gpu);
108upload_mesh_facet_attribute(
const MeshData& d,
const RowMajorMatrixXf& data,
GPUBuffer& gpu);
110upload_mesh_edge_attribute(
const MeshData& d,
const RowMajorMatrixXf& data,
GPUBuffer& gpu);
112LA_UI_API std::unordered_map<entt::id_type, std::shared_ptr<GPUBuffer>> upload_submesh_indices(
114 const std::string& facet_attrib_name);
119LA_UI_API
bool has_mesh_vertex_attribute(
const MeshData& d,
const std::string& name);
120LA_UI_API
bool has_mesh_corner_attribute(
const MeshData& d,
const std::string& name);
121LA_UI_API
bool has_mesh_facet_attribute(
const MeshData& d,
const std::string& name);
122LA_UI_API
bool has_mesh_edge_attribute(
const MeshData& d,
const std::string& name);
123LA_UI_API
bool has_mesh_indexed_attribute(
const MeshData& d,
const std::string& name);
130LA_UI_API std::optional<RayFacetHit>
133select_facets_in_frustum(
MeshData& d, SelectionBehavior sel_behavior,
const Frustum& frustum);
135select_vertices_in_frustum(
MeshData& d, SelectionBehavior sel_behavior,
const Frustum& frustum);
137select_edges_in_frustum(
MeshData& d, SelectionBehavior sel_behavior,
const Frustum& frustum);
138LA_UI_API
void propagate_corner_selection(
MeshData& d,
const std::string& attrib_name);
139LA_UI_API
void propagate_vertex_selection(
MeshData& d,
const std::string& attrib_name);
140LA_UI_API
void propagate_facet_selection(
MeshData& d,
const std::string& attrib_name);
141LA_UI_API
void combine_vertex_and_corner_selection(
MeshData& d,
const std::string& attrib_name);
142LA_UI_API
void select_facets_by_color(
144 const std::string& attrib_name,
145 SelectionBehavior sel_behavior,
146 const unsigned char* color_bytes,
147 size_t colors_byte_size);
148LA_UI_API
void select_edges_by_color(
150 const std::string& attrib_name,
151 SelectionBehavior sel_behavior,
152 const unsigned char* color_bytes,
153 size_t colors_byte_size);
154LA_UI_API
void select_vertices_by_color(
156 const std::string& attrib_name,
157 SelectionBehavior sel_behavior,
158 const unsigned char* color_bytes,
159 size_t colors_byte_size);
161select_facets(
MeshData& d, SelectionBehavior sel_behavior,
const std::vector<int>& facet_indices);
163LA_UI_API
void filter_closest_vertex(
165 const std::string& attrib_name,
166 SelectionBehavior sel_behavior,
168 const Eigen::Vector2i& viewport_pos);
170template <
typename V,
typename F>
171lagrange::Mesh<V, F>& cast_mesh(
const Registry& r, Entity e)
173 return cast_mesh<V, F>(r.get<
const MeshData>(e));
177template <
typename V,
typename F>
178lagrange::Mesh<V, F>& cast_mesh(
MeshData& mesh_data)
180 using MeshType = lagrange::Mesh<V, F>;
182 mesh_data.type == entt::type_id<MeshType>() && mesh_data.mesh,
183 "Incorrect mesh type");
184 return reinterpret_cast<MeshType&
>(*mesh_data.mesh);
187template <
typename MeshType>
188MeshType& get_mesh(Registry& r, Entity e)
191 return cast_mesh<typename MeshType::VertexArray, typename MeshType::FacetArray>(
195inline Entity get_mesh_entity(Registry& r, Entity e)
197 if (r.all_of<
MeshData>(e))
return e;
Camera class.
Definition Camera.h:38
Frustum defined using 6 planes.
Definition Frustum.h:43
#define la_runtime_assert(...)
Runtime assertion check.
Definition assert.h:174
Lagrange UI Viewer and mini 3D engine.
Definition AcceleratedPicking.h:23
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 VertexBuffer.h:145
Definition MeshGeometry.h:20