]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
Introduce SGBinaryFile
[simgear.git] / simgear / io / sg_binobj.cxx
index 5e5dafff870579b41bb9305aa13a9d629d0ce4a8..1c604a28b39fb7e2555324050b3197c026071cae 100644 (file)
@@ -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 <class T>
@@ -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<uint16_t>(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
 }