Displaying a 3D cube

classic Classic list List threaded Threaded
13 messages Options
smani smani
Reply | Threaded
Open this post in threaded view
|

Displaying a 3D cube

Hi,
I'm trying to create a osgFeature with a simple 3D cube geometry (coordinates in EPSG:2056) as follows:

      osgEarth::Features::MultiGeometry* multiGeometry = new osgEarth::Features::MultiGeometry();
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2682878, 1247710, 0);
        poly->push_back(2682878, 1248710, 0);
        poly->push_back(2682878, 1248710, 1000);
        poly->push_back(2682878, 1247710, 1000);
        poly->push_back(2682878, 1247710, 0);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2682878, 1247710, 0);
        poly->push_back(2682878, 1247710, 1000);
        poly->push_back(2683878, 1247710, 1000);
        poly->push_back(2683878, 1247710, 0);
        poly->push_back(2682878, 1247710, 0);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2683878, 1248710, 0);
        poly->push_back(2683878, 1248710, 1000);
        poly->push_back(2682878, 1248710, 1000);
        poly->push_back(2682878, 1248710, 0);
        poly->push_back(2683878, 1248710, 0);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2683878, 1247710, 0);
        poly->push_back(2683878, 1247710, 1000);
        poly->push_back(2683878, 1248710, 1000);
        poly->push_back(2683878, 1248710, 0);
        poly->push_back(2683878, 1247710, 0);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2682878, 1247710, 1000);
        poly->push_back(2682878, 1248710, 1000);
        poly->push_back(2683878, 1248710, 1000);
        poly->push_back(2683878, 1247710, 1000);
        poly->push_back(2682878, 1247710, 1000);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }
      {
        osgEarth::Features::Polygon* poly = new osgEarth::Features::Polygon();
        poly->push_back(2682878, 1247710, 0);
        poly->push_back(2682878, 1248710, 0);
        poly->push_back(2683878, 1248710, 0);
        poly->push_back(2683878, 1247710, 0);
        poly->push_back(2682878, 1247710, 0);
        poly->rewind( osgEarth::Symbology::Ring::ORIENTATION_CCW );
        multiGeometry->getComponents().push_back( poly );
      }

But I cannot seem to get anything except some occasional garbled random patches displayed. This without any terrain clamping enabled.

Any ideas?

Thanks
Sandro

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Sandro,
This code just makes the geometry -- can you show the rest of the code please that creates the FeatureNode?
Glenn Waldron / Pelican Mapping
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Glenn,
Thanks for your reply, sure: the short bit is just

[...]
osgEarth::Features::Feature* retFeat = new osgEarth::Features::Feature( multiGeometry, 0, osgEarth::Style(), featureId );

The full story is [1], [2]: its a feature source for displaying QGIS features in osgEarth, the features are created in QgsGlobeFeatureSource::getFeature resp. QgsGlobeFeatureUtils::featureFromQgsFeature. Since QGIS also supports features with 3D coordinates, I'm trying to get these to display as full 3D objects in osgEarth as well (instead of merely extruded 2D geometries). As a first experiment, I just changed QgsGlobeFeatureUtils::geometryFromQgsGeometry to always return the geometry I posted in the initial post.

Thanks
Sandro

[1] https://github.com/sourcepole/kadas-albireo/blob/master/src/plugins/globe/featuresource/qgsglobefeaturesource.cpp
[2] https://github.com/sourcepole/kadas-albireo/blob/master/src/plugins/globe/featuresource/qgsglobefeatureutils.h
remoe remoe
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Sandro

Do you have a screenshot sample of "garbled random patches" ?

Cheers,
Remo Eichenberger, Switzerland, @crocomer
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Remo

Sure: https://smani.fedorapeople.org/tmp/artefacts.png

Looks like the cube is reduced to a flat quad on earths surface, and the result is z-fighting with the earth surface.

Thanks
Sandro
remoe remoe
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Sandro

Are you sure you have no special shader activated on your feature? We had also such artifacts with activated gpu-clamping enabled. Do you have tried your code on plain osgearth_viewer sample?

Cheers,
Remo Eichenberger, Switzerland, @crocomer
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Remo

Hmm indeed, starting from scratch with a minimal example I get the cube to display. I'm gradually expanding the code to what I have in the QGIS Globe plugin to see what causes the issues.

Cheers
Sandro
remoe remoe
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi Sandro

Interesting! Please keep us updated ;)

Thanks

Remo Eichenberger, Switzerland, @crocomer
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

In reply to this post by smani
Sandro,

Make sure when you create your Feature that you include the SRS (instead of 0L):

const SpatialReference* srs = SpatialReference::get("EPSG:2056");
...
Feature* f = new Feature(geometry, srs, ...);

Glenn Waldron / Pelican Mapping
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Hi all
So in short, as soon as I add an altitude symbol, regardless of configuration of that symbol, the geometry is rendered as garbled patches. Actually does an altitude symbol even make sense for such a geometry? I was hoping to have an option to offset the Z coordinates by the terrain height, but perhaps I just need to require that the models have the correct, absolute Z coordinates, and omit the altitude symbol altogether?

Thanks
Sandro
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

Oh and I'm also trying to figure out why lighting does not work. For 2D geometries with extrusion symbol, this works fine

osgEarth::RenderSymbol* renderSymbol = style.getOrCreateSymbol<osgEarth::RenderSymbol>();
renderSymbol->lighting() = layerConfig->lightingEnabled;
renderSymbol->backfaceCulling() = false;
style.addSymbol( renderSymbol );

but it appears to have no effect with the 3D geometry.

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

In reply to this post by smani
How did you configure your altitude symbol?
Glenn Waldron / Pelican Mapping
smani smani
Reply | Threaded
Open this post in threaded view
|

Re: Displaying a 3D cube

I was testing with

  osgEarth::AltitudeSymbol* altitudeSymbol = style.getOrCreateSymbol<osgEarth::AltitudeSymbol>();
  altitudeSymbol->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_RELATIVE_TO_TERRAIN;
  altitudeSymbol->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_MAP;
  altitudeSymbol->binding() = osgEarth::Symbology::AltitudeSymbol::BINDING_VERTEX;
  style.addSymbol( altitudeSymbol );

Thanks
Sandro