[osg-users] adding object models in osgEarth best practices

David Bobavid david.bobavid at gmail.com
Tue Apr 30 11:12:47 PDT 2019


Hi,

I'm new to OSG and OSGEarth, and I did some googling, but still have some trouble finding out the proper way to do this.

So I have an osgEarth program, and I want to add some entity models, such as planes, moving around my globe. While I'm good with loading a .earth file for the terrain, or adding the textures/elevation data through code, I'm having some trouble adding models.

>From the examples (such as the osgearth_annotation), it seems like models are added by way of Styles:

Code:

Style style;
style.getOrCreate<ModelSymbol>()->autoScale() = true;
style.getOrCreate<ModelSymbol>()->url()->setLiteral("../data/red_flag.osg.50.scale");
ModelNode* modelNode = new ModelNode(mapNode, style); 
modelNode->setPosition(GeoPoint(geoSRS, -100, 52));
annoGroup->addChild(modelNode);




Which seems to work all right. I have tried adding another model, such as the cow.osg that comes with the osg data, and it doesn't look so good. For starters, it's very small, even with the scaling. I tried setting a new scale, but it didn't seem to help:

Code:

Style style;
style.getOrCreate<ModelSymbol>()->autoScale() = true;
style.getOrCreate<ModelSymbol>()->url()->setLiteral("../data/cow.osg");
style.getOrCreate<ModelSymbol>()->scale() = 4000;
ModelNode* modelNode = new ModelNode(mapNode, style); 
modelNode->setPosition(GeoPoint(geoSRS, -100, 52));
annoGroup->addChild(modelNode);




The cow seems to the same size (tiny!) and even when I zooom in, it's still super small. Also, I tried setting the heading:

Code:

Style style;
style.getOrCreate<ModelSymbol>()->autoScale() = true;
style.getOrCreate<ModelSymbol>()->url()->setLiteral("../data/red_flag.osg.50.scale");
style.getOrCreate<ModelSymbol>()->heading() = 180;
ModelNode* modelNode = new ModelNode(mapNode, style); 
modelNode->setPosition(GeoPoint(geoSRS, -100, 52));
annoGroup->addChild(modelNode);




And in this case, it seems like the model is 180degrees from where it was facing, not 180 from North.

So - what is the best way to go about adding a model and orienting it properly? Is this styles approach the correct way? I have seen some reference in another post about an osgEarthUtil::ObjectPlacer, but that class doesn't seem to exist any more.


Thank you!

Cheers,
David

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75923#75923







More information about the osg-users mailing list