|
class PutWavefrontOBJ
{
protected:
virtual ~PutWavefrontOBJ();
public:
virtual void putVertex ( double x, double y, double z ) = 0;
virtual void putNormal ( double x, double y, double z ) = 0;
virtual void putFacet ( nat nv, const nat * vert, const nat * norm ) = 0;
};
bool loadOBJ ( class IReadFile & file, PutWavefrontOBJ & obj );
А также класс GetWavefrontOBJ и функция saveOBJ для записи в файл:
class GetWavefrontOBJ
{
protected:
virtual ~GetWavefrontOBJ();
public:
virtual void start ( nat & nv, nat & nn, nat & nf ) const = 0;
virtual bool getVertex ( nat i, double & x, double & y, double & z ) const = 0;
virtual bool getNormal ( nat i, double & x, double & y, double & z ) const = 0;
virtual bool getFacet ( nat i, nat & nv, const nat * & vert, const nat * & norm ) const = 0;
};
bool saveOBJ ( class IWriteFile & file, const GetWavefrontOBJ & obj, nat prec );
Для того, чтобы записать данные объекта типа Polyhedron в файл и обратно предназначены следующие классы:
class PutWavefrontOBJ_Polyhedron : public PutWavefrontOBJ
{
struct IndexArray
{
nat nv;
DynArray<nat> index;
};
nat vsize, vcount;
Vector3d * vert;
nat fsize, fcount;
IndexArray * face;
bool err;
public:
PutWavefrontOBJ_Polyhedron ();
void putVertex ( double x, double y, double z );
void putNormal ( double x, double y, double z );
void putFacet ( nat nv, const nat * vert, const nat * norm );
bool give_to ( Shev::Polyhedron & poly );
};
class GetWavefrontOBJ_Polyhedron : public GetWavefrontOBJ
{
mutable nat nbuf;
mutable nat * vbuf;
const Shev::Polyhedron & poly;
public:
GetWavefrontOBJ_Polyhedron ( const Shev::Polyhedron & p ) : poly(p), nbuf(0), vbuf(0) {}
~GetWavefrontOBJ_Polyhedron ();
void start ( nat & nv, nat & nn, nat & nf ) const;
bool getVertex ( nat i, double & x, double & y, double & z ) const;
bool getNormal ( nat i, double & x, double & y, double & z ) const;
bool getFacet ( nat i, nat & nv, const nat * & vert, const nat * & norm ) const;
};
В приложении DEMO ( начиная с версии 4 ) показано, как применять эти классы. Исходники этих функций находятся в файлах fileOBJ.cpp и fileOBJplh.cpp. О классах IReadFile и IWriteFile смотрите здесь. Коллекция OBJ-файлов. Наверх |