#ifndef __SCOP_OBJ_LOADER__ #define __SCOP_OBJ_LOADER__ #include #include #include #include #include #include #include #include #include #include namespace Scop { struct ObjData { struct FaceVertex { FaceVertex() : v(-1), t(-1), n(-1) {} std::int32_t v; std::int32_t t; std::int32_t n; inline bool operator<(const FaceVertex& rhs) const { return (v < rhs.v) || (v == rhs.v && t < rhs.t ) || (v == rhs.v && t == rhs.t && n < rhs.n); } inline bool operator==(const FaceVertex& rhs) const { return (v == rhs.v && t == rhs.t && n == rhs.n); } }; using FaceList = std::pair, std::vector>; std::vector color; std::vector vertex; std::vector normal; std::vector tex_coord; std::map faces; }; struct ObjModel { std::vector color; std::vector vertex; std::vector normal; std::vector tex_coord; std::map> faces; }; std::optional LoadObjFromFile(const std::filesystem::path& path); void TesselateObjData(ObjData& data); ObjModel ConvertObjDataToObjModel(const ObjData& data); template inline std::istream& operator>>(std::istream& in, std::vector& vec); template inline std::istream& operator>>(std::istream& in, std::set& vec); inline std::istream& operator>>(std::istream& in, ObjData::FaceVertex& f); } #include #endif