Files
OrcaSlicer/src/libslic3r/Format/OBJ.hpp
T
2026-08-23 22:43:41 +08:00

57 lines
2.1 KiB
C++

#ifndef slic3r_Format_OBJ_hpp_
#define slic3r_Format_OBJ_hpp_
#include "libslic3r/Color.hpp"
#include "objparser.hpp"
#include <unordered_map>
namespace Slic3r {
class TriangleMesh;
class Model;
class ModelObject;
// Load an OBJ file into a provided model.
struct ObjInfo {
std::vector<RGBA> vertex_colors;
std::vector<RGBA> face_colors;
bool is_single_mtl{false};
std::string lost_material_name{""};
std::vector<std::array<Vec2f,3>> uvs;
std::string obj_dircetory;
std::map<std::string,bool> pngs;
std::unordered_map<int, std::string> uv_map_pngs;
bool has_uv_png{false};
std::vector<ObjParser::ObjUseMtl> usemtls; // material spans, for texture import
};
struct ObjDialogInOut
{ // input:colors array
std::vector<RGBA> input_colors;
bool is_single_color{false};
// colors array output:
std::vector<unsigned char> filament_ids;
unsigned char first_extruder_id;
bool deal_vertex_color;
Model * model{nullptr};
std::string lost_material_name{""};
};
typedef std::function<void(ObjDialogInOut &in_out)> ObjImportColorFn;
extern bool load_obj(const char *path, TriangleMesh *mesh, ObjInfo &vertex_colors, std::string &message, ObjParser::MtlData *out_mtl = nullptr);
extern bool load_obj(const char *path, Model *model, ObjInfo &vertex_colors, std::string &message, const char *object_name = nullptr, ObjParser::MtlData *out_mtl = nullptr);
struct TexturedMesh;
// Build a TexturedMesh (vertices + per-face UVs + the texture files named by map_Kd) from a
// parsed OBJ plus its material table, so the texture-to-color importer can sample face colours.
extern bool obj_to_textured_mesh(
const ObjInfo& obj_info,
const indexed_triangle_set& its,
const ObjParser::MtlData& mtl_data,
const std::string& obj_directory,
TexturedMesh& out);
extern bool store_obj(const char *path, TriangleMesh *mesh);
extern bool store_obj(const char *path, ModelObject *model);
extern bool store_obj(const char *path, Model *model);
}; // namespace Slic3r
#endif /* slic3r_Format_OBJ_hpp_ */