-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathKmlLoader.cpp
109 lines (95 loc) · 3.27 KB
/
KmlLoader.cpp
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
#include <omega.h>
#include <cyclops/cyclops.h>
// OSG
#include <osg/Group>
#include <osg/Vec3>
#include <osg/Uniform>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgEarth/MapNode>
using namespace omega;
using namespace cyclops;
using namespace osgEarth;
///////////////////////////////////////////////////////////////////////////////
class KmlLoader: public ModelLoader
{
public:
KmlLoader() : ModelLoader("kml") {}
virtual bool load(ModelAsset* model);
virtual bool loadInMap(ModelAsset* model, ModelAsset* mapAsset);
virtual bool supportsExtension(const String& ext);
};
///////////////////////////////////////////////////////////////////////////////
// Python wrapper code.
BOOST_PYTHON_MODULE(KmlLoader)
{
PYAPI_REF_CLASS_WITH_CTOR(KmlLoader, ModelLoader);
}
///////////////////////////////////////////////////////////////////////////////
bool KmlLoader::supportsExtension(const String& ext)
{
if(StringUtils::endsWith(ext, "kml") ||
StringUtils::endsWith(ext, "kmz")) return true;
return false;
}
///////////////////////////////////////////////////////////////////////////////
bool KmlLoader::load(cyclops::ModelAsset* model)
{
return false;
}
///////////////////////////////////////////////////////////////////////////////
bool KmlLoader::loadInMap(ModelAsset* asset, ModelAsset* mapAsset)
{
String orfp = StringUtils::replaceAll(asset->name, "*", "%1%");
String filePath = asset->info->path;
for(int iterator = 0; iterator < asset->numNodes; iterator++)
{
// If present in the string, this line will substitute %1% with the iterator number.
if(asset->numNodes != 1)
{
filePath = ostr(orfp, %iterator);
}
String assetPath;
if(DataManager::findFile(filePath, assetPath))
{
ofmsg("Loading model......%1%", %filePath);
osgDB::Options* options = new osgDB::Options;
options->setOptionString("noTesselateLargePolygons noTriStripPolygons noRotation");
if(mapAsset)
{
if(StringUtils::endsWith(filePath, ".kml") || StringUtils::endsWith(filePath, ".kmz"))
{
omsg("Adding mapNode option");
MapNode *mapNode = MapNode::findMapNode(mapAsset->nodes[0]);
if(mapNode)
options->setPluginData("osgEarth::MapNode", mapNode);
}
}
if(asset->info->buildKdTree)
{
osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
}
else
{
osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::DO_NOT_BUILD_KDTREES);
}
osg::Node* node = osgDB::readNodeFile(assetPath, options);
if(node != NULL)
{
node = processDefaultOptions(node, asset);
asset->nodes.push_back(node);
}
else
{
//ofwarn("loading failed: %1%", %assetPath);
return false;
}
}
else
{
ofwarn("could not find file: %1%", %filePath);
return false;
}
}
return true;
}