How to load models from file on demand, without specifying them all in .earth file?

classic Classic list List threaded Threaded
2 messages Options
10110111 10110111
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to load models from file on demand, without specifying them all in .earth file?

I have the following .earth file:
<map name="OpenStreetMap" type="geocentric" version="2">
 
    <elevation name="strm" driver="gdal">
	    <url>../../share/ControlIndicator/world.tif</url>
	    <min_valid_value>0</min_valid_value>
	    <max_valid_value>0</max_valid_value>
	    <nodata_policy>msl</nodata_policy>
    </elevation>

    <options>
        <lighting>false</lighting>
        <terrain>
            <min_tile_range_factor>8</min_tile_range_factor>
	    <color>#9f9f9fff</color>
        </terrain>
    </options>

    <model name="Moscow water" driver="feature_geom">
        <features name="Moscow water" driver="ogr">
            <url>/tmp/Москва/water.shp</url>
            <convert type="polygon"/>
        </features>
        <styles>
            <style type="text/css">
                waters {
                    fill: #0077ff;
                    altitude-clamping:  terrain;
                    altitude-technique: drape;
                }
            </style>
        </styles>
    </model>
</map>

It loads by osgDB::readNodeFile() without problems, I can get a MapNode from there and use it to show the Earth and Moscow water at the correct coordinates. But here the model path and style is "hard-coded" inside the .earth file. I'd rather load ".shp" files with corresponding styles on demand.
I've tried to look what osgEarth does to load the file (step-by-step tracing in a debugger), but got lost due to the amount of templated functions, functors and virtual calls. I guess this complexity is due to the generality of osgDB::readNodeFile().

I suspect that to do this manually, I don't have to learn all the things deep inside osgDB::readNodeFile(), and there's something more special, easier to use.

So, how do I load the file and attach it to my map node? I've tried following instructions in the FAQ entry "How do I place a 3D model on the map?", but I just didn't get the model visible. And another concern with the instructions is that the code there calls model->setPosition(...), which in my case of ".shp" file seems extraneous, since it already specifies the coordinates.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to load models from file on demand, without specifying them all in .earth file?

10110111,

Use osgDB::readNodeFile to load your model.

Use an osgEarth::GeoTransform to position it on the earth (as in the FAQ entry). Make sure you are using the correct SRS.

To read position data from a shapefile, you can use the OGRFeatureSource class. See the "osgearth_featureinfo.cpp" example.

Glenn Waldron / Pelican Mapping
Loading...