OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

adding object models in osgEarth best practices


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Tue Apr 30, 2019 6:12 pm    Post subject:
adding object models in osgEarth best practices
Reply with quote

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
Back to top
View user's profile Send private message
ceranco (Eran Cohen)
Newbie


Joined: 15 Dec 2017
Posts: 19

PostPosted: Thu May 02, 2019 3:03 pm    Post subject:
Reply with quote

Hi David,

If you're adding a model from code, you can simple load it normally using osgDB::readNodeFile and place it under an osgEarth::GeoTransform to transform to the correct location:

Code:

auto model = osgDB::readNodeFile("path-to-model");

auto geoTransform = new osgEarth::GeoTransform;
geoTransform->addChild(model);

...



GeoTransform can place the model using a GeoPoint and orients correctly so that the Z-axis down is toward the earth.

To scale and rotate the model, simply put it under an additional transform:
Code:

auto model = osgDB::readNodeFile("path-to-model");

auto transform = new osg::MatrixTransform;
transform->setMatrix(osg::Matrix::scale(10, 10, 10));
transform->addChild(model);

auto geoTransform = new osgEarth::GeoTransform;
geoTransform->addChild(transform);

...


Cheers,
Eran
Back to top
View user's profile Send private message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Thu May 02, 2019 3:07 pm    Post subject:
Reply with quote

Hi Eran,

Great, thanks so much. I'll give that a shot!

Cheers,
David
Back to top
View user's profile Send private message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Thu May 02, 2019 4:12 pm    Post subject:
Reply with quote

Hi Eran,

Ok, dumb follow up - I'm trying to add the geoTransform to my mapnode, and nothing is showing up. Is there something else I should be doing to add this transformed model to my map node?

(Sorry, total newb with osg/osgearth, here)

Thanks again,
David
Back to top
View user's profile Send private message
ceranco (Eran Cohen)
Newbie


Joined: 15 Dec 2017
Posts: 19

PostPosted: Thu May 02, 2019 6:14 pm    Post subject:
Reply with quote

Hi David,

It would help if you post the code that doesn't work for you so that we can see whats wrong with it.

Have you set its location using a GeoPoint?

Code:


auto model = osgDB::readNodeFile("path-to-model");

auto geoTransform = new osgEarth::GeoTransform;
geoTransform->addChild(model);

// This sets the location to New ork at an altitude of 1000 meters
auto srs = osgEarth::SpatialReference::get("wgs84);
GeoPoint newYork(srs, -73.935242, 40.730610, 1000);
geoTransform->setLocation(newYork);


...


If this isn't the problem then reply with a snippet of the code that isn't working.

Cheers,
Eran
Back to top
View user's profile Send private message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Thu May 02, 2019 6:27 pm    Post subject:
Reply with quote

Hi Eran,

Yes, sure... this is what I'm doing:

First to load my map:
Code:

_map = new osgEarth::Map();

osgEarth::Drivers::GDALOptions basemap;
basemap.url() = "I:/Dev/QtOsgTest1/data/world.tif";
_map->addLayer(new ImageLayer(ImageLayerOptions("basemap", basemap)));

_mapNode = new osgEarth::MapNode(_map);



Then later to load the model:
Code:


auto model = osgDB::readNodeFile("I:/Dev/QtOsgTest1/data/cow.osg");
if (!model) {
qDebug() << "Oh shit, model didn't load!";
}

auto transform = new osg::MatrixTransform;
transform->setMatrix(osg::Matrix::scale(100, 100, 100));
if (!transform->addChild(model)) {
qDebug() << "Failed adding model to matrix transform";
}

auto geoTransform = new osgEarth::GeoTransform;
geoTransform->setTerrain(_mapNode->getTerrain());
if (!geoTransform->setPosition(osgEarth::GeoPoint(_mapNode->getMapSRS()->getGeographicSRS(), -100, 52, 1000))) {
qDebug() << "Setting position failed";
}

if (!geoTransform->addChild(transform)) {
qDebug() << "Adding matrix transform to geotransform failed";
}

_mapNode->addChild(geoTransform);


I don't see the model show up, but I also don't see any of my error statements, either.

Thanks again,
david
Back to top
View user's profile Send private message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Thu May 02, 2019 6:37 pm    Post subject:
Reply with quote

Hi Eran,

So, it looks like if I zoom in *a lot* I do see my cow... I was playing around with it again and tried getting in real close, and setting the scale much larger again, and it's showing up. I guess it's a very small model, and I wasn't really looking close enough for it, either.

Thank you again for your help!

Cheers,
David
Back to top
View user's profile Send private message
ceranco (Eran Cohen)
Newbie


Joined: 15 Dec 2017
Posts: 19

PostPosted: Thu May 02, 2019 6:47 pm    Post subject:
Reply with quote

Good to hear!
As an aside, if you find yourself dealing with clipping issues when zooming in closely to models, take a look at osgEarth::Util::LogarithmicDepthBuffer.

Cheers,
Eran
Back to top
View user's profile Send private message
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Thu May 02, 2019 7:47 pm    Post subject:
Reply with quote

Hi Eran,

Ok, thanks! I'll look into that.

Last question (I think) for now... I'm trying to set my cow's orientation. From what you have suggested previously, would I add another MatrixTransform node with the rotations set into it?

Or should I add a PositionAttitudeTransform instead? If so, are there some helper classes that I can use that will create the Quat properly based on my heading, pitch and roll? I've been looking through the headers and cannot seem to find something that will help.

Thank you again!

Cheers,
David
Back to top
View user's profile Send private message
Trajce Nikolov NICK
Guest





PostPosted: Fri May 03, 2019 6:36 am    Post subject:
adding object models in osgEarth best practices
Reply with quote

Hi David,


to set up a Quat with your hpr you can do something like this:
osg::Quat q;
q.makeRotate(h,osg::Vec3(0,0,1),p,osg::Vec3(1,0,0),r,osg::Vec3(0,1,0));


of course you can tune the order


Cheers,
Nick



On Thu, May 2, 2019 at 11:02 PM David Bobavid < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi Eran,

Ok, thanks! I'll look into that.

Last question (I think) for now... I'm trying to set my cow's orientation. From what you have suggested previously, would I add another MatrixTransform node with the rotations set into it?

Or should I add a PositionAttitudeTransform instead? If so, are there some helper classes that I can use that will create the Quat properly based on my heading, pitch and roll? I've been looking through the headers and cannot seem to find something that will help.

Thank you again!

Cheers,
David

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





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Db80
Newbie


Joined: 30 Apr 2019
Posts: 9

PostPosted: Fri May 03, 2019 12:46 pm    Post subject:
Reply with quote

Hi Nick,

Thanks - I'll give it a try!

Cheers,
David
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts questions about developing drivers fo... speterson@idealaero.com General 4 Fri Aug 30, 2019 8:24 pm View latest post
No new posts osgQt & osgEarth not working with... Db80 General 1 Thu May 16, 2019 2:15 pm View latest post
No new posts Best Practices and Switches d_a_heitbrink General 3 Tue Apr 30, 2019 4:39 pm View latest post
No new posts Make an object linked to camera moove... GiacomoB General 0 Wed Mar 20, 2019 9:45 am View latest post
No new posts Air-Traffic Surveillance Display usin... eskay187 Announcement [ANN] 2 Wed Feb 13, 2019 7:07 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP