Using AutoTransform with GeoTransform. PagedLOD questions.

classic Classic list List threaded Threaded
3 messages Options
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Using AutoTransform with GeoTransform. PagedLOD questions.

This post was updated on .
Hi,
I have a task to draw a lot of moving and static 3D models scattered across the earth's surface. Models should be autoscaled and should use LOD (I guess it is possible?).

Problems arose when I was trying to integrate LOD technique.

Previously I used osg::Node* 3D model loaded from file and then I set autoScale with ModelSymbol:
this->styleEarth.getOrCreate<osgEarth::Annotation::ModelSymbol>()->setModel(this->model3D.get());
this->styleEarth.getOrCreate<osgEarth::Annotation::ModelSymbol>()->autoScale() = true;
this->styleEarth.getOrCreate<osgEarth::Annotation::ModelSymbol>()->minAutoScale() = 3.0;

this->modelOnEarth = new osgEarth::Annotation::ModelNode(mapNode, this->styleEarth);
And that approach worked fine.

Then I tried to add osg::PagedLOD with several 3D models instead of single osg::Node* 3D model. After these changes - I can't see any 3D models on Earth and no errors in console.


So I decided to use osgEarth::GeoTransform and osg::AutoTransform:
this->modelScaled = new osg::AutoTransform;
this->modelScaled->addChild(this->pagedLOD.get());
this->modelScaled->setMinimumScale(1);
this->modelScaled->setMaximumScale(500);
this->modelScaled->setAutoScaleToScreen(true);

this->modelOnEarth = new osgEarth::GeoTransform();
this->modelOnEarth->setTerrain(mapNode->getTerrain());
this->modelOnEarth->addChild(this->modelScaled.get());

// To enable textures on 3D model
osgEarth::Registry::shaderGenerator().run(modelOnEarth);


This looks almost fine, but if I set object position with Altitude=0 and move camera close to object - object's 3D model is very big. It doesn't return to scale=1.0. And PagedLOD is also not working.

I guess some wrong calculations of AutoTransform are made, so that it thinks that camera is too distant from Node.
Any ideas how to fix this or should I use another approach?
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Using AutoTransform with GeoTransform

I've disabled all built-in autoScales and wrote something close to autoscaling.
I use camera (manipulator) altitude and then set all models scale:
double _scale = _scene->getCurrentCameraManipulatorHeight() / 1000.0;
double scale = _scale;
if (_scale < 10.0) scale = 10.0;
if (_scale < 1.0) scale = 1.0;

modelScaled->setScale(scale); // modelScaled is an osg::AutoTransform

Also for PagedLOD I've created Low-poly and Mid-poly "models" - red box and blue box, respectively (see video below).
pagedLOD->setFileName(0, fileLowPoly.toStdString());
pagedLOD->setRange(0, 1000.0f, FLT_MAX);
pagedLOD->setFileName(1, fileMidPoly.toStdString());
pagedLOD->setRange(1, 500.0f, 1000.0f);
pagedLOD->setFileName(2, fileHighPoly.toStdString());
pagedLOD->setRange(2, 0.0f, 500.0f);

And now I  observe strange behaviour of PagedLOD.
In case EarthManipulator is watching straight to earth (90 degrees), PagedLOD is loading Mid-poly model no matter how far the camera is.
If I tilt Manipulator a bit, this spot of blue mid-poly models moves towards projected position of Manipulator to earth's surface.



Is it correct behaviour?

P.S. Also in this video you can see switching from high-poly to mid-poly while zooming. I guess that's problem with my implementation of autoScale.
Best regards,
Nikita Petrov
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Using AutoTransform with GeoTransform

Nikita,
You don't show your entire PagedLOD setup but I will speculate.

One guess: PagedLOD is based on distance from the camera to the bounding sphere of the object. Since an AutoTransform'd object scales based on distance, its bounding sphere will scale as well, causing the effective range calculation to be the same regardless of the camera distance.

Another possibility is that you are using PIXEL_SIZE_ON_SCREEN mode which, as above, will cause the ranges to be expressed in pixels instead of meters.

Just guessing! -gw
Glenn Waldron / Pelican Mapping