let OMReader and OMWriter read and write double positions and normals
This commit is contained in:
@@ -297,6 +297,7 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
|
||||
assert( chunk_header_.entity_ == Chunk::Entity_Vertex);
|
||||
|
||||
OpenMesh::Vec3f v3f;
|
||||
OpenMesh::Vec3d v3d;
|
||||
OpenMesh::Vec2f v2f;
|
||||
OpenMesh::Vec3uc v3uc; // rgb
|
||||
OpenMesh::Attributes::StatusInfo status;
|
||||
@@ -306,15 +307,34 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
|
||||
size_t vidx = 0;
|
||||
switch (chunk_header_.type_) {
|
||||
case Chunk::Type_Pos:
|
||||
if (chunk_header_.bits_ == OMFormat::bits(0.0f)) // read floats
|
||||
{
|
||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
||||
|
||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||
bytes_ += vector_restore(_is, v3f, _swap);
|
||||
_bi.add_vertex(v3f);
|
||||
}
|
||||
}
|
||||
else if (chunk_header_.bits_ == OMFormat::bits(0.0)) // read doubles
|
||||
{
|
||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3d::dim()));
|
||||
|
||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||
bytes_ += vector_restore(_is, v3d, _swap);
|
||||
_bi.add_vertex(v3d);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
omerr() << "unknown Vector size" << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
case Chunk::Type_Normal:
|
||||
|
||||
if (chunk_header_.bits_ == OMFormat::bits(0.0f)) // read floats
|
||||
{
|
||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
||||
|
||||
fileOptions_ += Options::VertexNormal;
|
||||
@@ -323,6 +343,18 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
|
||||
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
|
||||
_bi.set_normal(VertexHandle(int(vidx)), v3f);
|
||||
}
|
||||
}
|
||||
else if (chunk_header_.bits_ == OMFormat::bits(0.0)) // read doubles
|
||||
{
|
||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3d::dim()));
|
||||
|
||||
fileOptions_ += Options::VertexNormal;
|
||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||
bytes_ += vector_restore(_is, v3d, _swap);
|
||||
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
|
||||
_bi.set_normal(VertexHandle(int(vidx)), v3d);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Chunk::Type_Texcoord:
|
||||
|
||||
@@ -81,7 +81,7 @@ _OMWriter_& OMWriter() { return __OMWriterInstance; }
|
||||
|
||||
|
||||
const OMFormat::uchar _OMWriter_::magic_[3] = "OM";
|
||||
const OMFormat::uint8 _OMWriter_::version_ = OMFormat::mk_version(2,0);
|
||||
const OMFormat::uint8 _OMWriter_::version_ = OMFormat::mk_version(2,1);
|
||||
|
||||
|
||||
_OMWriter_::
|
||||
@@ -181,6 +181,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
||||
|
||||
unsigned int i, nV, nF;
|
||||
Vec3f v;
|
||||
Vec3d vd;
|
||||
Vec2f t;
|
||||
|
||||
// -------------------- write header
|
||||
@@ -211,12 +212,26 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
||||
chunk_header.name_ = false;
|
||||
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
|
||||
chunk_header.type_ = OMFormat::Chunk::Type_Pos;
|
||||
if (_be.is_point_double())
|
||||
{
|
||||
chunk_header.signed_ = OMFormat::is_signed(vd[0]);
|
||||
chunk_header.float_ = OMFormat::is_float(vd[0]);
|
||||
chunk_header.dim_ = OMFormat::dim(vd);
|
||||
chunk_header.bits_ = OMFormat::bits(vd[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk_header.signed_ = OMFormat::is_signed(v[0]);
|
||||
chunk_header.float_ = OMFormat::is_float(v[0]);
|
||||
chunk_header.dim_ = OMFormat::dim(v);
|
||||
chunk_header.bits_ = OMFormat::bits(v[0]);
|
||||
}
|
||||
|
||||
bytes += store( _os, chunk_header, swap );
|
||||
if (_be.is_point_double())
|
||||
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
||||
bytes += vector_store( _os, _be.pointd(VertexHandle(i)), swap );
|
||||
else
|
||||
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
||||
bytes += vector_store( _os, _be.point(VertexHandle(i)), swap );
|
||||
}
|
||||
@@ -226,18 +241,34 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be,
|
||||
if (_be.n_vertices() && _opt.check( Options::VertexNormal ))
|
||||
{
|
||||
Vec3f n = _be.normal(VertexHandle(0));
|
||||
Vec3d nd = _be.normald(VertexHandle(0));
|
||||
|
||||
chunk_header.name_ = false;
|
||||
chunk_header.entity_ = OMFormat::Chunk::Entity_Vertex;
|
||||
chunk_header.type_ = OMFormat::Chunk::Type_Normal;
|
||||
if (_be.is_normal_double())
|
||||
{
|
||||
chunk_header.signed_ = OMFormat::is_signed(nd[0]);
|
||||
chunk_header.float_ = OMFormat::is_float(nd[0]);
|
||||
chunk_header.dim_ = OMFormat::dim(nd);
|
||||
chunk_header.bits_ = OMFormat::bits(nd[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk_header.signed_ = OMFormat::is_signed(n[0]);
|
||||
chunk_header.float_ = OMFormat::is_float(n[0]);
|
||||
chunk_header.dim_ = OMFormat::dim(n);
|
||||
chunk_header.bits_ = OMFormat::bits(n[0]);
|
||||
}
|
||||
|
||||
bytes += store( _os, chunk_header, swap );
|
||||
if (_be.is_normal_double())
|
||||
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
||||
bytes += vector_store( _os, _be.normald(VertexHandle(i)), swap );
|
||||
else
|
||||
for (i=0, nV=header.n_vertices_; i<nV; ++i)
|
||||
bytes += vector_store( _os, _be.normal(VertexHandle(i)), swap );
|
||||
|
||||
}
|
||||
|
||||
// ---------- write vertex color
|
||||
|
||||
Reference in New Issue
Block a user