> I think the solution to this whole issue is to bring fgfs-construct .btg
> generation closer to how the genapt works - keeping the material
> information around with each poly through the clipping process.  


Hi Peter,
I thought that was already the case? I was fooling around the other day, 
modifying the BTG loader to use a material definition for each feature 
(fan/strip/triangle), thus loading a different texture from the <texture-set> 
instead of only one per tile. Really the only modification I made was to store 
the geometry along with the material while loading, instead of loading a 
material and then storing all features with that material in the same bin. 
That seemed to bring the performance down to a crawl (to be expected since 
otherwise this code would probably have been there from day 1). If it's any 
use, I'll attach here a diff of my experiments.

Cheers,
Adrian


diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx
index d080ff3..ba56c0e 100644
--- a/simgear/scene/tgdb/obj.cxx
+++ b/simgear/scene/tgdb/obj.cxx
@@ -68,7 +68,7 @@
 
 using namespace simgear;
 
-typedef std::map<std::string,SGTexturedTriangleBin> SGMaterialTriangleMap;
+typedef std::multimap<std::string,SGTexturedTriangleBin> SGMaterialTriangleMap;
 typedef std::list<SGLightBin> SGLightListBin;
 typedef std::list<SGDirectionalLightBin> SGDirectionalLightListBin;
 
@@ -190,7 +190,7 @@ struct SGTileGeometryBin {
   }
 
   static void
-  addTriangleGeometry(SGTexturedTriangleBin& triangles,
+  addTriangleGeometry(SGMaterialTriangleMap& triangleMap, std::string& material_name,
                       const std::vector<SGVec3d>& vertices,
                       const std::vector<SGVec3f>& normals,
                       const std::vector<SGVec2f>& texCoords,
@@ -203,11 +203,11 @@ struct SGTileGeometryBin {
       // If the normal indices do not match, they should be inmplicitly
       // the same than the vertex indices. So just call ourselves again
       // with the matching index vector.
-      addTriangleGeometry(triangles, vertices, normals, texCoords,
+      addTriangleGeometry(triangleMap, material_name, vertices, normals, texCoords,
                           tris_v, tris_v, tris_tc, tcScale);
       return;
     }
-
+    SGTexturedTriangleBin triangles;
     for (unsigned i = 2; i < tris_v.size(); i += 3) {
       SGVertNormTex v0;
       v0.vertex = toVec3f(vertices[tris_v[i-2]]);
@@ -223,10 +223,11 @@ struct SGTileGeometryBin {
       v2.texCoord = getTexCoord(texCoords, tris_tc, tcScale, i);
       triangles.insert(v0, v1, v2);
     }
+    triangleMap.insert(std::pair<std::string, SGTexturedTriangleBin> (material_name, triangles));
   }
 
   static void
-  addStripGeometry(SGTexturedTriangleBin& triangles,
+  addStripGeometry(SGMaterialTriangleMap& triangleMap, std::string& material_name,
                    const std::vector<SGVec3d>& vertices,
                    const std::vector<SGVec3f>& normals,
                    const std::vector<SGVec2f>& texCoords,
@@ -239,11 +240,11 @@ struct SGTileGeometryBin {
       // If the normal indices do not match, they should be inmplicitly
       // the same than the vertex indices. So just call ourselves again
       // with the matching index vector.
-      addStripGeometry(triangles, vertices, normals, texCoords,
+      addStripGeometry(triangleMap, material_name, vertices, normals, texCoords,
                        strips_v, strips_v, strips_tc, tcScale);
       return;
     }
-
+    SGTexturedTriangleBin triangles;
     for (unsigned i = 2; i < strips_v.size(); ++i) {
       SGVertNormTex v0;
       v0.vertex = toVec3f(vertices[strips_v[i-2]]);
@@ -262,10 +263,11 @@ struct SGTileGeometryBin {
       else
         triangles.insert(v0, v1, v2);
     }
+    triangleMap.insert(std::pair<std::string, SGTexturedTriangleBin> (material_name, triangles));
   }
   
   static void
-  addFanGeometry(SGTexturedTriangleBin& triangles,
+  addFanGeometry(SGMaterialTriangleMap& triangleMap, std::string& material_name,
                  const std::vector<SGVec3d>& vertices,
                  const std::vector<SGVec3f>& normals,
                  const std::vector<SGVec2f>& texCoords,
@@ -278,11 +280,11 @@ struct SGTileGeometryBin {
       // If the normal indices do not match, they should be implicitly
       // the same than the vertex indices. So just call ourselves again
       // with the matching index vector.
-      addFanGeometry(triangles, vertices, normals, texCoords,
+      addFanGeometry(triangleMap, material_name, vertices, normals, texCoords,
                      fans_v, fans_v, fans_tc, tcScale);
       return;
     }
-
+    SGTexturedTriangleBin triangles;
     SGVertNormTex v0;
     v0.vertex = toVec3f(vertices[fans_v[0]]);
     v0.normal = normals[fans_n[0]];
@@ -299,6 +301,7 @@ struct SGTileGeometryBin {
       triangles.insert(v0, v1, v2);
       v1 = v2;
     }
+    triangleMap.insert(std::pair<std::string, SGTexturedTriangleBin> (material_name, triangles));
   }
 
   SGVec2f getTexCoordScale(const std::string& name, SGMaterialLib* matlib)
@@ -325,7 +328,7 @@ struct SGTileGeometryBin {
     for (unsigned grp = 0; grp < obj.get_tris_v().size(); ++grp) {
       std::string materialName = obj.get_tri_materials()[grp];
       SGVec2f tcScale = getTexCoordScale(materialName, matlib);
-      addTriangleGeometry(materialTriangleMap[materialName],
+      addTriangleGeometry(materialTriangleMap, materialName,
                           obj.get_wgs84_nodes(), obj.get_normals(),
                           obj.get_texcoords(), obj.get_tris_v()[grp],
                           obj.get_tris_n()[grp], obj.get_tris_tc()[grp],
@@ -341,7 +344,7 @@ struct SGTileGeometryBin {
     for (unsigned grp = 0; grp < obj.get_strips_v().size(); ++grp) {
       std::string materialName = obj.get_strip_materials()[grp];
       SGVec2f tcScale = getTexCoordScale(materialName, matlib);
-      addStripGeometry(materialTriangleMap[materialName],
+      addStripGeometry(materialTriangleMap, materialName,
                        obj.get_wgs84_nodes(), obj.get_normals(),
                        obj.get_texcoords(), obj.get_strips_v()[grp],
                        obj.get_strips_n()[grp], obj.get_strips_tc()[grp],
@@ -357,7 +360,7 @@ struct SGTileGeometryBin {
     for (unsigned grp = 0; grp < obj.get_fans_v().size(); ++grp) {
       std::string materialName = obj.get_fan_materials()[grp];
       SGVec2f tcScale = getTexCoordScale(materialName, matlib);
-      addFanGeometry(materialTriangleMap[materialName],
+      addFanGeometry(materialTriangleMap, materialName,
                      obj.get_wgs84_nodes(), obj.get_normals(),
                      obj.get_texcoords(), obj.get_fans_v()[grp],
                      obj.get_fans_n()[grp], obj.get_fans_tc()[grp],
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to