14#include <lagrange/ui/api.h>
15#include <lagrange/ui/Entity.h>
16#include <lagrange/ui/default_components.h>
17#include <lagrange/ui/default_shaders.h>
18#include <lagrange/ui/utils/io.h>
19#include <lagrange/ui/utils/treenode.h>
24LA_UI_API
void set_material(Registry& r, Entity meshrender_entity, std::shared_ptr<Material> mat);
26LA_UI_API Entity show_mesh(
28 const Entity& mesh_entity,
29 StringID shader = DefaultShaders::PBR,
30 const ShaderDefines& shader_defines = {});
31LA_UI_API Entity show_submesh(
33 const Entity& mesh_entity,
34 std::shared_ptr<Material> material,
35 entt::id_type submesh_id);
37LA_UI_API Entity show_mesh(
40 Entity scene_node_entity,
41 StringID shader = DefaultShaders::PBR,
42 const ShaderDefines& shader_defines = {});
44LA_UI_API Entity show_mesh(
47 Entity scene_node_entity,
48 std::shared_ptr<Material> material);
54LA_UI_API Entity show_vertex_attribute(
56 const Entity& mesh_entity,
57 const std::string& attribute,
60LA_UI_API Entity show_facet_attribute(
62 const Entity& mesh_entity,
63 const std::string& attribute,
66LA_UI_API Entity show_edge_attribute(
68 const Entity& mesh_entity,
69 const std::string& attribute,
72LA_UI_API Entity show_corner_attribute(
74 const Entity& mesh_entity,
75 const std::string& attribute,
78LA_UI_API Entity show_indexed_attribute(
80 const Entity& mesh_entity,
81 const std::string& attribute,
85LA_UI_API
void set_colormap(Registry& r, Entity meshrender_entity, std::shared_ptr<Texture> texture);
87LA_UI_API
void set_colormap_range(
89 Entity meshrender_entity,
90 const Eigen::Vector4f& range_min,
91 const Eigen::Vector4f& range_max);
94LA_UI_API
void set_colormap_range(
96 Entity meshrender_entity,
97 const std::pair<Eigen::VectorXf, Eigen::VectorXf>&
range);
100LA_UI_API std::shared_ptr<Material> get_material(Registry& r, Entity meshrender_entity);
102inline Transform& get_transform(Registry& r, Entity e)
104 return r.get<Transform>(e);
108template <
typename Derived>
109inline Eigen::Affine3f& set_transform(Registry& r, Entity e,
const Derived& local_transform)
111 auto& t = r.get<Transform>(e).local;
116template <
typename Derived>
117inline Eigen::Affine3f& apply_transform(Registry& r, Entity e,
const Derived& local_transform)
121 return set_transform(r, e, t * get_transform(r, e).local);
127template <
typename MeshType>
130 std::shared_ptr<MeshType> mesh,
131 const std::string& name =
"Unnamed mesh",
132 StringID shader = DefaultShaders::PBR)
134 auto mesh_geometry = register_mesh<MeshType>(r, std::move(mesh));
135 auto mesh_view = show_mesh(r, mesh_geometry, shader);
136 ui::set_name(r, mesh_geometry, name);
137 ui::set_name(r, mesh_view, name);
141template <
typename MeshType>
144 std::unique_ptr<MeshType> mesh,
145 const std::string& name =
"Unnamed mesh",
146 StringID shader = DefaultShaders::PBR)
148 return add_mesh(r,
to_shared_ptr(std::move(mesh)), name, shader);
151template <
typename MeshType>
154 const lagrange::fs::path& path_to_obj,
155 bool load_materials =
true,
156 const std::string& name =
"Unnamed mesh",
157 StringID shader = DefaultShaders::PBR)
159 if (!load_materials) {
160 auto me = load_obj<MeshType>(r, path_to_obj);
162 auto e = show_mesh(r, me, shader);
163 ui::set_name(r, e, name);
167 auto [me, mats] = load_obj_with_materials<MeshType>(r, path_to_obj);
169 if (!r.valid(me))
return NullEntity;
171 if (mats.size() <= 1) {
172 auto e = show_mesh(r, me, shader);
173 ui::set_name(r, e, name);
174 if (mats.size() == 1) ui::set_material(r, e, mats.front());
177 auto e = create_scene_node(r, name);
178 for (
auto mat_index = 0; mat_index < mats.size(); mat_index++) {
179 auto sub = ui::show_submesh(r, me, mats[mat_index], mat_index);
193LA_UI_API
void set_mesh_vertices_dirty(Registry& r, Entity mesh_entity);
194LA_UI_API
void set_mesh_normals_dirty(Registry& r, Entity mesh_entity);
195LA_UI_API
void set_mesh_dirty(Registry& r, Entity mesh_entity);
197LA_UI_API
void set_show_attribute_dirty(Registry& r, Entity scene_entity);
198LA_UI_API
void set_mesh_attribute_dirty(
202 const std::string& name);
204LA_UI_API Entity get_meshdata_entity(Registry& r, Entity scene_entity);
205LA_UI_API MeshData& get_meshdata(Registry& r, Entity scene_or_mesh_entity);
211std::shared_ptr<Material>
212LA_UI_API create_material(Registry& r, entt::id_type shader_id,
const ShaderDefines& shader_defines = {});
219LA_UI_API
void clear_scene(Registry& r);
224LA_UI_API std::optional<std::pair<Entity, RayFacetHit>>
intersect_ray(
226 const Eigen::Vector3f& origin,
227 const Eigen::Vector3f& dir,
228 ui::Entity root = ui::NullEntity,
229 Layer visible_layers = Layer(
true),
230 Layer hidden_layers = Layer(
false));
static Camera default_camera(float width, float height, Type type=Type::PERSPECTIVE)
Initializes default view.
Definition: Camera.cpp:29
internal::Range< Index > range(Index end)
Returns an iterable object representing the range [0, end).
Definition: range.h:176
std::string string_format(fmt::format_string< Args... > format, Args &&... args)
Format args according to the format string fmt, and return the result as a string.
Definition: strings.h:103
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API void set_parent(Registry ®istry, Entity child, Entity new_parent)
Sets new_parent as as child's new parent.
Definition: treenode.cpp:155
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
std::shared_ptr< T > to_shared_ptr(std::unique_ptr< T > &&ptr)
Helper for automatic type deduction for unique_ptr to shared_ptr conversion.
Definition: common.h:84