14#include <lagrange/Logger.h>
15#include <lagrange/ui/api.h>
16#include <lagrange/ui/Entity.h>
17#include <lagrange/ui/components/MeshData.h>
18#include <lagrange/ui/types/Texture.h>
19#include <lagrange/ui/utils/io_assimp.h>
21#include <lagrange/io/load_mesh_ext.h>
28LA_UI_API std::shared_ptr<Texture> load_texture(
30 const Texture::Params& params = Texture::Params());
36LA_UI_API std::shared_ptr<Material>
37convert_material(Registry& r,
const fs::path& base_dir,
const tinyobj::material_t& tinymat);
42template <
typename MeshType>
46 const io::MeshLoaderParams& params = io::MeshLoaderParams())
48 if (path.extension() !=
".obj") {
49 lagrange::logger().error(
"wrong file format '{}' for load_obj", path.extension().string());
56 p.load_materials =
false;
59 auto res = lagrange::io::load_mesh_ext<MeshType>(path, params);
60 if (!res.success)
return NullEntity;
63 auto e = register_mesh<MeshType>(r, std::dynamic_pointer_cast<MeshType>(mesh));
64 ui::set_name(r, e, path.filename().string());
72template <
typename MeshType>
76 const io::MeshLoaderParams& params = io::MeshLoaderParams())
78 if (path.extension() !=
".obj") {
79 lagrange::logger().error(
"wrong file format '{}' for load_obj", path.extension().string());
80 return {NullEntity, {}};
86 p.load_materials =
true;
89 auto res = lagrange::io::load_mesh_ext<MeshType>(path, params);
90 if (!res.success)
return {NullEntity, {}};
93 auto e = register_mesh<MeshType>(r, std::dynamic_pointer_cast<MeshType>(mesh));
94 ui::set_name(r, e, path.filename().string());
96 std::vector<std::shared_ptr<Material>> mats;
98 base_dir.remove_filename();
100 for (
auto& tinymat : res.materials) {
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
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::shared_ptr< Material > convert_material(Registry &r, const fs::path &base_dir, const tinyobj::material_t &tinymat)
Convertrs tinyobj's material_t to UI's Material.
Definition: io.cpp:97
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