]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
Use the original filename for the compressed image message.
[simgear.git] / simgear / io / sg_binobj.cxx
index 7a58321f14d827a72ffff0def645c84ee78861ca..f511164064fc5f0d3bafb39ce71e548baa50da3a 100644 (file)
@@ -261,13 +261,13 @@ void write_indices(gzFile fp, unsigned char indexMask,
     for (unsigned int i=0; i < count; ++i) {
         write_indice(fp, static_cast<T>(vertices[i]));
         
-        if (!normals.empty()) {
+        if (indexMask & SG_IDX_NORMALS) {
             write_indice(fp, static_cast<T>(normals[i]));
         }
-        if (!colors.empty()) {
+        if (indexMask & SG_IDX_COLORS) {
             write_indice(fp, static_cast<T>(colors[i]));
         }
-        if (!texCoords.empty()) {
+        if (indexMask & SG_IDX_TEXCOORDS) {
             write_indice(fp, static_cast<T>(texCoords[i]));
         }
     }
@@ -461,7 +461,7 @@ bool SGBinObject::read_bin( const string& file ) {
      //cout << "Total objects to read = " << nobjects << endl;
 
     if ( sgReadError() ) {
-        cout << "We detected an error while reading the file header" << endl;
+        cout << "Error while reading header of file " << file << "(.gz)" << endl;
         return false;
     }
     
@@ -612,7 +612,7 @@ bool SGBinObject::read_bin( const string& file ) {
         }
         
         if ( sgReadError() ) {
-            cout << "We detected an error while reading object:" << i << endl;
+            cout << "Error while reading object:" << i << " in file " << file << "(.gz)" << endl;
             return false;
         }
     }
@@ -621,7 +621,7 @@ bool SGBinObject::read_bin( const string& file ) {
     gzclose(fp);
 
     if ( sgReadError() ) {
-        cout << "We detected an error while reading the file." << endl;
+        cout << "Error while reading file " << file << "(.gz)" << endl;
         return false;
     }
 
@@ -667,6 +667,8 @@ void SGBinObject::write_objects(gzFile fp, int type, const group_list& verts,
     
     unsigned int start = 0, end = 1;
     string m;
+    int_list emptyList;
+    
     while (start < materials.size()) {
         m = materials[start];
     // find range of objects with identical material, write out as a single object
@@ -692,10 +694,15 @@ void SGBinObject::write_objects(gzFile fp, int type, const group_list& verts,
 //        cout << "material:" << m << ", count =" << count << endl;
     // elements
         for (unsigned int i=start; i < end; ++i) {
+            const int_list& va(verts[i]);
+            const int_list& na((idx_mask & SG_IDX_NORMALS) ? normals[i] : emptyList);
+            const int_list& ca((idx_mask & SG_IDX_COLORS) ? colors[i] : emptyList);
+            const int_list& tca((idx_mask & SG_IDX_TEXCOORDS) ? texCoords[i] : emptyList);
+            
             if (version == 7) {
-                write_indices<uint16_t>(fp, idx_mask, verts[i], normals[i], colors[i], texCoords[i]);
+                write_indices<uint16_t>(fp, idx_mask, va, na, ca, tca);
             } else {
-                write_indices<uint32_t>(fp, idx_mask, verts[i], normals[i], colors[i], texCoords[i]);
+                write_indices<uint32_t>(fp, idx_mask, va, na, ca, tca);
             }
         }
     
@@ -745,7 +752,9 @@ bool SGBinObject::write_bin_file(const SGPath& file)
     cout << "tex coords = " << texcoords.size() << endl;
 
     version = 10;
-    if (wgs84_nodes.size() < 0xffff) {
+    if ((wgs84_nodes.size() < 0xffff) &&
+        (normals.size() < 0xffff) &&
+        (texcoords.size() < 0xffff)) {
         version = 7; // use smaller indices if possible
     }
 
@@ -820,7 +829,7 @@ bool SGBinObject::write_bin_file(const SGPath& file)
     gzclose(fp);
 
     if ( sgWriteError() ) {
-        cout << "We detected an error while writing the file." << endl;
+        cout << "Error while writing file " << file.str() << endl;
         return false;
     }
 
@@ -997,9 +1006,13 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
     fclose(fp);
 
     string command = "gzip --force --best " + file.str();
-    system(command.c_str());
+    int err = system(command.c_str());
+    if (err)
+    {
+        cout << "ERROR: gzip " << file.str() << " failed!" << endl;
+    }
 
-    return true;
+    return (err == 0);
 }
 
 void SGBinObject::read_properties(gzFile fp, int nproperties)