This file is indexed.

/usr/include/simgear/scene/tgdb/SGTileGeometryBin.hxx is in libsimgear-dev 3.4.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#ifdef HAVE_CONFIG_H
#  include <simgear_config.h>
#endif

#include "obj.hxx"

#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/material/mat.hxx>

#include "SGTexturedTriangleBin.hxx"

using namespace simgear;

typedef std::map<std::string,SGTexturedTriangleBin> SGMaterialTriangleMap;

// Class handling the initial BTG loading : should probably be in its own file
// it is very closely coupled with SGTexturedTriangleBin.hxx
// it was used to load fans, strips, and triangles.
// WS2.0 no longer uses fans or strips, but people still use ws1.0, so we need 
// to keep this functionality.
class SGTileGeometryBin : public osg::Referenced {
public:
  SGMaterialTriangleMap materialTriangleMap;

  SGTileGeometryBin() {}

  static SGVec2f
  getTexCoord(const std::vector<SGVec2f>& texCoords, const int_list& tc,
              const SGVec2f& tcScale, unsigned i)
  {
    if (tc.empty())
      return tcScale;
    else if (tc.size() == 1)
      return mult(texCoords[tc[0]], tcScale);
    else
      return mult(texCoords[tc[i]], tcScale);
  }

  SGVec2f getTexCoordScale(const std::string& name, SGMaterialCache* matcache)
  {
    if (!matcache)
      return SGVec2f(1, 1);
    SGMaterial* material = matcache->find(name);
    if (!material)
      return SGVec2f(1, 1);

    return material->get_tex_coord_scale();
  }
  
  static void
  addTriangleGeometry(SGTexturedTriangleBin& triangles,
                      const SGBinObject& obj, unsigned grp,
                      const SGVec2f& tc0Scale, 
                      const SGVec2f& tc1Scale)
  {
    const std::vector<SGVec3d>& vertices(obj.get_wgs84_nodes());
    const std::vector<SGVec3f>& normals(obj.get_normals());
    const std::vector<SGVec2f>& texCoords(obj.get_texcoords());
    const int_list& tris_v(obj.get_tris_v()[grp]);
    const int_list& tris_n(obj.get_tris_n()[grp]);
    const tci_list& tris_tc(obj.get_tris_tcs()[grp]);
    bool  num_norms_is_num_verts = true;  
    
    if (tris_v.size() != tris_n.size()) {
        // If the normal indices do not match, they should be inmplicitly
        // the same than the vertex indices. 
        num_norms_is_num_verts = false;
    }

    if ( !tris_tc[1].empty() ) {
        triangles.hasSecondaryTexCoord(true);
    }
    
    for (unsigned i = 2; i < tris_v.size(); i += 3) {
        SGVertNormTex v0;
        v0.SetVertex( toVec3f(vertices[tris_v[i-2]]) );
        v0.SetNormal( num_norms_is_num_verts ? normals[tris_n[i-2]] : 
                                               normals[tris_v[i-2]] );
        v0.SetTexCoord( 0, getTexCoord(texCoords, tris_tc[0], tc0Scale, i-2) );
        if (!tris_tc[1].empty()) {
            v0.SetTexCoord( 1, getTexCoord(texCoords, tris_tc[1], tc1Scale, i-2) );
        }
        SGVertNormTex v1;
        v1.SetVertex( toVec3f(vertices[tris_v[i-1]]) );
        v1.SetNormal( num_norms_is_num_verts ? normals[tris_n[i-1]] : 
                                               normals[tris_v[i-1]] );
        v1.SetTexCoord( 0, getTexCoord(texCoords, tris_tc[0], tc0Scale, i-1) );
        if (!tris_tc[1].empty()) {
            v1.SetTexCoord( 1, getTexCoord(texCoords, tris_tc[1], tc1Scale, i-1) );
        }
        SGVertNormTex v2;
        v2.SetVertex( toVec3f(vertices[tris_v[i]]) );
        v2.SetNormal( num_norms_is_num_verts ? normals[tris_n[i]] : 
                                               normals[tris_v[i]] );
        v2.SetTexCoord( 0, getTexCoord(texCoords, tris_tc[0], tc0Scale, i) );
        if (!tris_tc[1].empty()) {
            v2.SetTexCoord( 1, getTexCoord(texCoords, tris_tc[1], tc1Scale, i) );
        }
        
        triangles.insert(v0, v1, v2);
    }
  }

  static void
  addStripGeometry(SGTexturedTriangleBin& triangles,
                   const SGBinObject& obj, unsigned grp,
                   const SGVec2f& tc0Scale, 
                   const SGVec2f& tc1Scale)
  {
      const std::vector<SGVec3d>& vertices(obj.get_wgs84_nodes());
      const std::vector<SGVec3f>& normals(obj.get_normals());
      const std::vector<SGVec2f>& texCoords(obj.get_texcoords());
      const int_list& strips_v(obj.get_strips_v()[grp]);
      const int_list& strips_n(obj.get_strips_n()[grp]);
      const tci_list& strips_tc(obj.get_strips_tcs()[grp]);
      bool  num_norms_is_num_verts = true;  
      
      if (strips_v.size() != strips_n.size()) {
          // If the normal indices do not match, they should be inmplicitly
          // the same than the vertex indices. 
          num_norms_is_num_verts = false;
      }
      
      if ( !strips_tc[1].empty() ) {
          triangles.hasSecondaryTexCoord(true);
      }
      
    for (unsigned i = 2; i < strips_v.size(); ++i) {
      SGVertNormTex v0;
      v0.SetVertex( toVec3f(vertices[strips_v[i-2]]) );
      v0.SetNormal( num_norms_is_num_verts ? normals[strips_n[i-2]] : 
                                             normals[strips_v[i-2]] );
      v0.SetTexCoord( 0, getTexCoord(texCoords, strips_tc[0], tc0Scale, i-2) );
      if (!strips_tc[1].empty()) {
          v0.SetTexCoord( 1, getTexCoord(texCoords, strips_tc[1], tc1Scale, i-2) );
      }
      SGVertNormTex v1;
      v1.SetVertex( toVec3f(vertices[strips_v[i-1]]) );
      v1.SetNormal( num_norms_is_num_verts ? normals[strips_n[i-1]] : 
                                             normals[strips_v[i-1]] );
      v1.SetTexCoord( 0, getTexCoord(texCoords, strips_tc[1], tc0Scale, i-1) );
      if (!strips_tc[1].empty()) {
          v1.SetTexCoord( 1, getTexCoord(texCoords, strips_tc[1], tc1Scale, i-1) );
      }
      SGVertNormTex v2;
      v2.SetVertex( toVec3f(vertices[strips_v[i]]) );
      v2.SetNormal( num_norms_is_num_verts ? normals[strips_n[i]] : 
                                             normals[strips_v[i]] );
      v2.SetTexCoord( 0, getTexCoord(texCoords, strips_tc[0], tc0Scale, i) );
      if (!strips_tc[1].empty()) {
          v2.SetTexCoord( 1, getTexCoord(texCoords, strips_tc[1], tc1Scale, i) );
      }
      if (i%2)
        triangles.insert(v1, v0, v2);
      else
        triangles.insert(v0, v1, v2);
    }
  }

  static void
  addFanGeometry(SGTexturedTriangleBin& triangles,
                 const SGBinObject& obj, unsigned grp,
                 const SGVec2f& tc0Scale, 
                 const SGVec2f& tc1Scale)
  {
      const std::vector<SGVec3d>& vertices(obj.get_wgs84_nodes());
      const std::vector<SGVec3f>& normals(obj.get_normals());
      const std::vector<SGVec2f>& texCoords(obj.get_texcoords());
      const int_list& fans_v(obj.get_fans_v()[grp]);
      const int_list& fans_n(obj.get_fans_n()[grp]);
      const tci_list& fans_tc(obj.get_fans_tcs()[grp]);
      bool  num_norms_is_num_verts = true;  
      
      if (fans_v.size() != fans_n.size()) {
          // If the normal indices do not match, they should be inmplicitly
          // the same than the vertex indices. 
          num_norms_is_num_verts = false;
      }
      
      if ( !fans_tc[1].empty() ) {
          triangles.hasSecondaryTexCoord(true);
      }
      
    SGVertNormTex v0;
    v0.SetVertex( toVec3f(vertices[fans_v[0]]) );
    v0.SetNormal( num_norms_is_num_verts ? normals[fans_n[0]] : 
                                           normals[fans_v[0]] );
    v0.SetTexCoord( 0, getTexCoord(texCoords, fans_tc[0], tc0Scale, 0) );
    if (!fans_tc[1].empty()) {
        v0.SetTexCoord( 1, getTexCoord(texCoords, fans_tc[1], tc1Scale, 0) );
    }
    SGVertNormTex v1;
    v1.SetVertex( toVec3f(vertices[fans_v[1]]) );
    v1.SetNormal( num_norms_is_num_verts ? normals[fans_n[1]] : 
                                           normals[fans_v[1]] );
    v1.SetTexCoord( 0, getTexCoord(texCoords, fans_tc[0], tc0Scale, 1) );
    if (!fans_tc[1].empty()) {
        v1.SetTexCoord( 1, getTexCoord(texCoords, fans_tc[1], tc1Scale, 1) );
    }
    for (unsigned i = 2; i < fans_v.size(); ++i) {
      SGVertNormTex v2;
      v2.SetVertex( toVec3f(vertices[fans_v[i]]) );
      v2.SetNormal( num_norms_is_num_verts ? normals[fans_n[i]] : 
                                             normals[fans_v[i]] );
      v2.SetTexCoord( 0, getTexCoord(texCoords, fans_tc[0], tc0Scale, i) );
      if (!fans_tc[1].empty()) {
          v2.SetTexCoord( 1, getTexCoord(texCoords, fans_tc[1], tc1Scale, i) );
      }
      triangles.insert(v0, v1, v2);
      v1 = v2;
    }
  }

  bool
  insertSurfaceGeometry(const SGBinObject& obj, SGMaterialCache* matcache)
  {
    if (obj.get_tris_n().size() < obj.get_tris_v().size() ||
        obj.get_tris_tcs().size() < obj.get_tris_v().size()) {
      SG_LOG(SG_TERRAIN, SG_ALERT,
             "Group list sizes for triangles do not match!");
      return false;
    }

    for (unsigned grp = 0; grp < obj.get_tris_v().size(); ++grp) {
      std::string materialName = obj.get_tri_materials()[grp];
      SGVec2f tc0Scale = getTexCoordScale(materialName, matcache);
      SGVec2f tc1Scale(1.0, 1.0);
      addTriangleGeometry(materialTriangleMap[materialName],
                          obj, grp, tc0Scale, tc1Scale );
    }

    if (obj.get_strips_n().size() < obj.get_strips_v().size() ||
        obj.get_strips_tcs().size() < obj.get_strips_v().size()) {
      SG_LOG(SG_TERRAIN, SG_ALERT,
             "Group list sizes for strips do not match!");
      return false;
    }
    for (unsigned grp = 0; grp < obj.get_strips_v().size(); ++grp) {
      std::string materialName = obj.get_strip_materials()[grp];
      SGVec2f tc0Scale = getTexCoordScale(materialName, matcache);
      SGVec2f tc1Scale(1.0, 1.0);
      addStripGeometry(materialTriangleMap[materialName],
                          obj, grp, tc0Scale, tc1Scale);
    }

    if (obj.get_fans_n().size() < obj.get_fans_v().size() ||
        obj.get_fans_tcs().size() < obj.get_fans_v().size()) {
      SG_LOG(SG_TERRAIN, SG_ALERT,
             "Group list sizes for fans do not match!");
      return false;
    }
    for (unsigned grp = 0; grp < obj.get_fans_v().size(); ++grp) {
      std::string materialName = obj.get_fan_materials()[grp];
      SGVec2f tc0Scale = getTexCoordScale(materialName, matcache);
      SGVec2f tc1Scale(1.0, 1.0);
      addFanGeometry(materialTriangleMap[materialName],
                       obj, grp, tc0Scale, tc1Scale );
    }
    return true;
  }

  osg::Node* getSurfaceGeometry(SGMaterialCache* matcache, bool useVBOs) const
  {
    if (materialTriangleMap.empty())
      return 0;

    EffectGeode* eg = NULL;
    osg::Group* group = (materialTriangleMap.size() > 1 ? new osg::Group : NULL);
    if (group) {
        group->setName("surfaceGeometryGroup");
    }
    
    //osg::Geode* geode = new osg::Geode;
    SGMaterialTriangleMap::const_iterator i;
    for (i = materialTriangleMap.begin(); i != materialTriangleMap.end(); ++i) {
      osg::Geometry* geometry = i->second.buildGeometry(useVBOs);
      SGMaterial *mat = NULL;
      if (matcache) {
        mat = matcache->find(i->first);
      }
      eg = new EffectGeode;
      eg->setName("EffectGeode");
      if (mat) {
        eg->setMaterial(mat);
        eg->setEffect(mat->get_one_effect(i->second.getTextureIndex()));
      } else {
        eg->setMaterial(NULL);
      }
      eg->addDrawable(geometry);
      eg->runGenerators(geometry);  // Generate extra data needed by effect
      if (group) {
        group->addChild(eg);
      }
    }
    
    if (group) {
        return group;
    } else {
        return eg;
    }
  }
};