support now face coords for OM reader/writer
This commit is contained in:
@@ -152,6 +152,9 @@ public:
|
|||||||
// set incident face handle for given halfedge
|
// set incident face handle for given halfedge
|
||||||
virtual void set_face(HalfedgeHandle _heh, FaceHandle _fh) = 0;
|
virtual void set_face(HalfedgeHandle _heh, FaceHandle _fh) = 0;
|
||||||
|
|
||||||
|
// request texture coordinate property
|
||||||
|
virtual void request_face_texcoords2D() = 0;
|
||||||
|
|
||||||
// set vertex texture coordinate
|
// set vertex texture coordinate
|
||||||
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
|
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -285,6 +285,11 @@ public:
|
|||||||
mesh_.set_face_handle(_heh, _fh);
|
mesh_.set_face_handle(_heh, _fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void request_face_texcoords2D() override
|
||||||
|
{
|
||||||
|
if(!mesh_.has_halfedge_texcoords2D())
|
||||||
|
mesh_.request_halfedge_texcoords2D();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) override
|
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -182,7 +182,6 @@ bool _OMReader_::read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while (!_is.eof()) {
|
while (!_is.eof()) {
|
||||||
bytes_ += restore(_is, chunk_header_, swap);
|
bytes_ += restore(_is, chunk_header_, swap);
|
||||||
|
|
||||||
@@ -661,6 +660,28 @@ bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi
|
|||||||
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_hprop(property_name_), 2 * header_.n_edges_, _swap);
|
bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_hprop(property_name_), 2 * header_.n_edges_, _swap);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------
|
||||||
|
case Chunk::Type_Texcoord:
|
||||||
|
{
|
||||||
|
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec2f::dim()));
|
||||||
|
|
||||||
|
//fileOptions_ += OpenMesh::IO::Options::FaceTexCoord;
|
||||||
|
|
||||||
|
if (_opt.face_has_texcoord())
|
||||||
|
{
|
||||||
|
_bi.request_face_texcoords2D();
|
||||||
|
}
|
||||||
|
OpenMesh::Vec2f v2f;
|
||||||
|
for (size_t e_idx = 0; e_idx < header_.n_edges_*2; ++e_idx)
|
||||||
|
{
|
||||||
|
bytes_ += vector_restore(_is, v2f, _swap);
|
||||||
|
if (_opt.face_has_texcoord())
|
||||||
|
_bi.set_texcoord(HalfedgeHandle(int(e_idx)), v2f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------
|
||||||
case Chunk::Type_Topology:
|
case Chunk::Type_Topology:
|
||||||
{
|
{
|
||||||
std::vector<HalfedgeHandle> next_halfedges;
|
std::vector<HalfedgeHandle> next_halfedges;
|
||||||
|
|||||||
@@ -303,7 +303,6 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
|||||||
chunk_header.dim_ = OMFormat::dim(t);
|
chunk_header.dim_ = OMFormat::dim(t);
|
||||||
chunk_header.bits_ = OMFormat::bits(t[0]);
|
chunk_header.bits_ = OMFormat::bits(t[0]);
|
||||||
|
|
||||||
// std::clog << chunk_header << std::endl;
|
|
||||||
bytes += store(_os, chunk_header, swap);
|
bytes += store(_os, chunk_header, swap);
|
||||||
|
|
||||||
for (i = 0, nV = header.n_vertices_; i < nV; ++i)
|
for (i = 0, nV = header.n_vertices_; i < nV; ++i)
|
||||||
@@ -337,6 +336,30 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------- write face texture coords
|
||||||
|
if (_OMWriter_::version_ > OMFormat::mk_version(2,1) && _be.n_edges() && _opt.check(Options::FaceTexCoord))
|
||||||
|
{
|
||||||
|
|
||||||
|
t = _be.texcoord(HalfedgeHandle(0));
|
||||||
|
|
||||||
|
chunk_header.name_ = false;
|
||||||
|
chunk_header.entity_ = OMFormat::Chunk::Entity_Halfedge;
|
||||||
|
chunk_header.type_ = OMFormat::Chunk::Type_Texcoord;
|
||||||
|
chunk_header.signed_ = OMFormat::is_signed(t[0]);
|
||||||
|
chunk_header.float_ = OMFormat::is_float(t[0]);
|
||||||
|
chunk_header.dim_ = OMFormat::dim(t);
|
||||||
|
chunk_header.bits_ = OMFormat::bits(t[0]);
|
||||||
|
|
||||||
|
bytes += store(_os, chunk_header, swap);
|
||||||
|
|
||||||
|
int nHE;
|
||||||
|
for (i = 0, nHE = header.n_edges_*2; i < nHE; ++i)
|
||||||
|
bytes += vector_store(_os, _be.texcoord(HalfedgeHandle(i)), swap);
|
||||||
|
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
// ---------- write vertex topology (outgoing halfedge)
|
// ---------- write vertex topology (outgoing halfedge)
|
||||||
if (_be.n_vertices())
|
if (_be.n_vertices())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1711,8 +1711,14 @@ TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshWithPropertiesCurrentVersion) {
|
|||||||
|
|
||||||
add_all_properties(mesh_);
|
add_all_properties(mesh_);
|
||||||
|
|
||||||
|
mesh_.request_halfedge_texcoords2D();
|
||||||
|
|
||||||
std::string file_name_2_2 = "cube_tri_with_properties_2_2.om";
|
std::string file_name_2_2 = "cube_tri_with_properties_2_2.om";
|
||||||
OpenMesh::IO::Options ops(OpenMesh::IO::Options::Custom);
|
OpenMesh::IO::Options ops(OpenMesh::IO::Options::Custom);
|
||||||
|
ops += OpenMesh::IO::Options::FaceTexCoord;
|
||||||
|
|
||||||
|
std::cout << "ops has facetexcoords: " << ops.face_has_texcoord() << std::endl;
|
||||||
|
|
||||||
OpenMesh::IO::write_mesh(mesh_, file_name_2_2, ops);
|
OpenMesh::IO::write_mesh(mesh_, file_name_2_2, ops);
|
||||||
|
|
||||||
Mesh new_mesh;
|
Mesh new_mesh;
|
||||||
@@ -1720,6 +1726,7 @@ TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshWithPropertiesCurrentVersion) {
|
|||||||
OpenMesh::IO::read_mesh(new_mesh, file_name_2_2, ops);
|
OpenMesh::IO::read_mesh(new_mesh, file_name_2_2, ops);
|
||||||
|
|
||||||
check_all_properties(new_mesh);
|
check_all_properties(new_mesh);
|
||||||
|
EXPECT_TRUE(new_mesh.has_halfedge_texcoords2D());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user