]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/test_binobj.cxx
SGPath: fix creating paths with permission checker.
[simgear.git] / simgear / io / test_binobj.cxx
index 2ca1edf149bdd02e474fb1e210b94ed8e2d22194..f51a9a19980fd58e14da691fd93b3e35c4e6caae 100644 (file)
@@ -103,6 +103,15 @@ int_list make_tri(int maxIndex)
     return r;
 }
 
+tci_list make_tri_tcs(int maxIndex)
+{
+    tci_list tci;
+    tci[0].push_back(random() % maxIndex);
+    tci[0].push_back(random() % maxIndex);
+    tci[0].push_back(random() % maxIndex);
+    return tci;
+}
+
 void compareTris(const SGBinObject& a, const SGBinObject& b)
 {
     unsigned int count = a.get_tri_materials().size();
@@ -113,32 +122,31 @@ void compareTris(const SGBinObject& a, const SGBinObject& b)
 
         COMPARE(a.get_tri_materials()[i], b.get_tri_materials()[i]);
         
-        const int_list& tA(a.get_tris_tc()[i]);
-        const int_list& tB(b.get_tris_tc()[i]);
+        const int_list& tA(a.get_tris_tcs()[i][0]);
+        const int_list& tB(b.get_tris_tcs()[i][0]);
         VERIFY(tA == tB);
     }
 }
 
 void generate_tris(SGBinObject& b, int count)
 {
-    group_list v, n, tc;
+    group_list v, n;
+    group_tci_list tc;
     string_list materials;
 
     int maxVertices = b.get_wgs84_nodes().size();
     int maxNormals = b.get_normals().size();
     int maxTCs = b.get_texcoords().size();
     
+    SGBinObjectTriangle sgboTri;
     for (int t=0; t<count; ++t) {
-        v.push_back(make_tri(maxVertices));
-        n.push_back(make_tri(maxNormals));
-        tc.push_back(make_tri(maxTCs));
-        materials.push_back("material1");
+        sgboTri.material = "material1";    
+        sgboTri.v_list = make_tri(maxVertices);
+        sgboTri.n_list = make_tri(maxNormals);
+        sgboTri.tc_list[0] = make_tri(maxTCs);
+
+        b.add_triangle( sgboTri );
     }
-    
-    b.set_tris_v(v);
-    b.set_tris_n(n);
-    b.set_tris_tc(tc);
-    b.set_tri_materials(materials);
 }
  
 void test_basic()
@@ -250,12 +258,88 @@ void test_big()
    compareTris(basic, rd);
 }
 
+void test_some_objects()
+{
+    SGBinObject basic;
+    SGPath path(simgear::Dir::current().file("some_objects.btg.gz"));
+    
+    SGVec3d center(1, 2, 3);
+    basic.set_gbs_center(center);
+    basic.set_gbs_radius(12345);
+    
+    std::vector<SGVec3d> points;
+    generate_points(10000, points);
+    std::vector<SGVec3f> normals;
+    generate_normals(1024, normals);
+    std::vector<SGVec2f> texCoords;
+    generate_tcs(20000, texCoords);
+    
+    basic.set_wgs84_nodes(points);
+    basic.set_normals(normals);
+    basic.set_texcoords(texCoords);
+    
+    generate_tris(basic, 30000); // a number smaller than 2^15!
+    
+    bool ok = basic.write_bin_file(path);
+    VERIFY( ok );
+    
+    SGBinObject rd;
+    ok = rd.read_bin(path.str()) ;
+    VERIFY( ok);
+    COMPARE(rd.get_version(), 7); // since we have less than 2^15 tris
+    COMPARE(rd.get_wgs84_nodes().size(), points.size());
+    COMPARE(rd.get_texcoords().size(), texCoords.size());
+   
+    comparePoints(rd, points);
+    compareTexCoords(rd, texCoords);
+    compareTris(basic, rd);
+}
+
+void test_many_objects()
+{
+    SGBinObject basic;
+    SGPath path(simgear::Dir::current().file("many_objects.btg.gz"));
+    
+    SGVec3d center(1, 2, 3);
+    basic.set_gbs_center(center);
+    basic.set_gbs_radius(12345);
+    
+    std::vector<SGVec3d> points;
+    generate_points(10000, points);
+    std::vector<SGVec3f> normals;
+    generate_normals(1024, normals);
+    std::vector<SGVec2f> texCoords;
+    generate_tcs(20000, texCoords);
+    
+    basic.set_wgs84_nodes(points);
+    basic.set_normals(normals);
+    basic.set_texcoords(texCoords);
+    
+    generate_tris(basic, 200000);
+    
+    bool ok = basic.write_bin_file(path);
+    VERIFY( ok );
+    
+    SGBinObject rd;
+    ok = rd.read_bin(path.str()) ;
+    VERIFY( ok);
+    COMPARE(rd.get_version(), 10); // should be version 10 since indices are > 2^16
+    COMPARE(rd.get_wgs84_nodes().size(), points.size());
+    COMPARE(rd.get_texcoords().size(), texCoords.size());
+   
+    comparePoints(rd, points);
+    compareTexCoords(rd, texCoords);
+    compareTris(basic, rd);
+}
+
 int main(int argc, char* argv[])
 {
     test_empty();
     test_basic();
     test_many_tcs();
     test_big();
+    test_some_objects();
+    test_many_objects();
     
     return 0;
 }