X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fsg_binobj.cxx;h=1c604a28b39fb7e2555324050b3197c026071cae;hb=8d93206dd33ed0079af6670a0ecd41a3b203d9a0;hp=5e5dafff870579b41bb9305aa13a9d629d0ce4a8;hpb=5b2b420c48363060cda0b91137316fa4ac045673;p=simgear.git diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 5e5dafff..1c604a28 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -240,8 +240,8 @@ static void read_indices(char* buffer, vai_list& vas ) { - const int indexSize = sizeof(T) * std::bitset<32>(indexMask).count(); - const int vaSize = sizeof(T) * std::bitset<32>(vaMask).count(); + const int indexSize = sizeof(T) * std::bitset<32>((int)indexMask).count(); + const int vaSize = sizeof(T) * std::bitset<32>((int)vaMask).count(); const int count = bytes / (indexSize + vaSize); // fix endian-ness of the whole lot, if required @@ -274,6 +274,15 @@ static void read_indices(char* buffer, if (vaMask & SG_VA_FLOAT_3) vas[7].push_back(*src++); } } // of elements in the index + + // WS2.0 fix : toss zero area triangles + if ( ( count == 3 ) && (indexMask & SG_IDX_VERTICES) ) { + if ( (vertices[0] == vertices[1]) || + (vertices[1] == vertices[2]) || + (vertices[2] == vertices[0]) ) { + vertices.clear(); + } + } } template @@ -307,8 +316,8 @@ void write_indices(gzFile fp, const vai_list& vas ) { unsigned int count = vertices.size(); - const int indexSize = sizeof(T) * std::bitset<32>(indexMask).count(); - const int vaSize = sizeof(T) * std::bitset<32>(vaMask).count(); + const int indexSize = sizeof(T) * std::bitset<32>((int)indexMask).count(); + const int vaSize = sizeof(T) * std::bitset<32>((int)vaMask).count(); sgWriteUInt(fp, (indexSize + vaSize) * count); for (unsigned int i=0; i < count; ++i) { @@ -437,7 +446,7 @@ void SGBinObject::read_object( gzFile fp, throw sg_exception("Error reading object properties"); } - size_t indexCount = std::bitset<32>(idx_mask).count(); + size_t indexCount = std::bitset<32>((int)idx_mask).count(); if (indexCount == 0) { throw sg_exception("object index mask has no bits set"); } @@ -468,12 +477,15 @@ void SGBinObject::read_object( gzFile fp, read_indices(ptr, nbytes, idx_mask, vertex_attrib_mask, vs, ns, cs, tcs, vas ); } - vertices.push_back( vs ); - normals.push_back( ns ); - colors.push_back( cs ); - texCoords.push_back( tcs ); - vertexAttribs.push_back( vas ); - materials.push_back( material ); + // Fix for WS2.0 - ignore zero area triangles + if ( !vs.empty() ) { + vertices.push_back( vs ); + normals.push_back( ns ); + colors.push_back( cs ); + texCoords.push_back( tcs ); + vertexAttribs.push_back( vas ); + materials.push_back( material ); + } } // of element iteration }