14#include <lagrange/ui/Entity.h>
15#include <lagrange/ui/api.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,
86set_colormap(Registry& r, Entity meshrender_entity, std::shared_ptr<Texture> texture);
88LA_UI_API
void set_colormap_range(
90 Entity meshrender_entity,
91 const Eigen::Vector4f& range_min,
92 const Eigen::Vector4f& range_max);
95LA_UI_API
void set_colormap_range(
97 Entity meshrender_entity,
98 const std::pair<Eigen::VectorXf, Eigen::VectorXf>&
range);
101LA_UI_API std::shared_ptr<Material> get_material(Registry& r, Entity meshrender_entity);
103inline Transform& get_transform(Registry& r, Entity e)
109template <
typename Derived>
110inline Eigen::Affine3f& set_transform(Registry& r, Entity e,
const Derived& local_transform)
117template <
typename Derived>
118inline Eigen::Affine3f& apply_transform(Registry& r, Entity e,
const Derived& local_transform)
122 return set_transform(r, e, t * get_transform(r, e).local);
128template <
typename MeshType>
131 std::shared_ptr<MeshType> mesh,
132 const std::string& name =
"Unnamed mesh",
133 StringID shader = DefaultShaders::PBR)
135 auto mesh_geometry = register_mesh<MeshType>(r, std::move(mesh));
136 auto mesh_view = show_mesh(r, mesh_geometry, shader);
137 ui::set_name(r, mesh_geometry, name);
138 ui::set_name(r, mesh_view, name);
142template <
typename MeshType>
145 std::unique_ptr<MeshType> mesh,
146 const std::string& name =
"Unnamed mesh",
147 StringID shader = DefaultShaders::PBR)
149 return add_mesh(r,
to_shared_ptr(std::move(mesh)), name, shader);
152template <
typename MeshType>
155 const lagrange::fs::path& path_to_obj,
156 bool load_materials =
true,
157 const std::string& name =
"Unnamed mesh",
158 StringID shader = DefaultShaders::PBR)
160 if (!load_materials) {
163 auto e = show_mesh(r, me, shader);
164 ui::set_name(r, e, name);
170 if (!r.valid(me))
return NullEntity;
172 if (mats.size() <= 1) {
173 auto e = show_mesh(r, me, shader);
174 ui::set_name(r, e, name);
175 if (mats.size() == 1) ui::set_material(r, e, mats.front());
178 auto e = create_scene_node(r, name);
179 for (
auto mat_index = 0; mat_index < mats.size(); mat_index++) {
180 auto sub = ui::show_submesh(r, me, mats[mat_index], mat_index);
194LA_UI_API
void set_mesh_vertices_dirty(Registry& r, Entity mesh_entity);
195LA_UI_API
void set_mesh_normals_dirty(Registry& r, Entity mesh_entity);
196LA_UI_API
void set_mesh_dirty(Registry& r, Entity mesh_entity);
198LA_UI_API
void set_show_attribute_dirty(Registry& r, Entity scene_entity);
199LA_UI_API
void set_mesh_attribute_dirty(
203 const std::string& name);
205LA_UI_API Entity get_meshdata_entity(Registry& r, Entity scene_entity);
206LA_UI_API
MeshData& get_meshdata(Registry& r, Entity scene_or_mesh_entity);
212std::shared_ptr<Material> LA_UI_API
213create_material(Registry& r, entt::id_type shader_id,
const ShaderDefines& shader_defines = {});
220LA_UI_API
void clear_scene(Registry& r);
225LA_UI_API std::optional<std::pair<Entity, RayFacetHit>>
intersect_ray(
227 const Eigen::Vector3f& origin,
228 const Eigen::Vector3f& dir,
229 ui::Entity root = ui::NullEntity,
Camera class.
Definition Camera.h:38
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:23
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
std::pair< Entity, std::vector< std::shared_ptr< Material > > > load_obj_with_materials(Registry &r, const fs::path &path, const io::MeshLoaderParams ¶ms=io::MeshLoaderParams())
Loads obj as a single mesh and materials.
Definition io.h:73
Entity load_obj(Registry &r, const fs::path &path, const io::MeshLoaderParams ¶ms=io::MeshLoaderParams())
Loads obj as a single mesh.
Definition io.h:43
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.
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:88