Advice needed for loading custom buildings

classic Classic list List threaded Threaded
18 messages Options
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Advice needed for loading custom buildings

This post was updated on .
I need some advice for how to get started loading custom 3D building models into osgEarth 3.1.  Let's say the buildings are in UTM coordinates.

Can I create a .earth file with the building model file paths (say, "B001.obj", "B002.obj", ..., etc.) just listed in it?  Or do I need to load a .shp file with a point for each building and the model pathname as an attribute?  Or will I need to create a new Layer type to do this?
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

I would go the shapefile route but you would also need each model localized to 0,0.  I typically use a corner of the building as the origin point and the matching vertex in the shapefile.

Yes, then you can have an attribute named model_name and then your style attribute could be:   model: [model_name];


You can also do it manually if you look in simple_model.earth in the tests folder:

<Map name="Demo: simple model layer">

    <Model name="Cow in the Hudson">
<url>C:\Users\plevy\Documents\ptt\ptt.FLT.100.scale</url>
        <location lat="40.717" long="-74.018" alt="1200"/>
    </Model>
   
    <xi:include href="readymap_imagery.xml"/>
    <xi:include href="readymap_elevation.xml"/>
   
</Map>


--
Paul Levy : Pelican Mapping 


On Fri, Jan 29, 2021 at 2:51 PM notsofast [via osgEarth] <[hidden email]> wrote:
I need some advice for how to get started loading custom 3D building models into osgEarth.  Let's say the buildings are in UTM coordinates.

Can I create a .earth file with the building model file paths (say, "B001.obj", "B002.obj", ..., etc.) just listed in it?  Or do I need to load a .shp file with a point for each building and the model pathname as an attribute?  Or will I need to create a new Layer type to do this?


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Advice-needed-for-loading-custom-buildings-tp7593651.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by notsofast
The simplest thing would be to use a Model annotation inside a Annotations layer like this:

    <Annotations name="Buildings">   
        <Model name="B001">
            <position lat="43" long="-100"/>
            <style> model: "B001.obj"; </style>        </Model> 
        ....      
    </Annotations>

If you have more than a few though, the shapefile/attribute approach (as in "feature_models.earth") is probably more manageable and will perform better in the long run.
Glenn Waldron / Pelican Mapping
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by plevy
@plevy, I could put the models in local coordinates, so the shapefile approach would work.  Also, thanks for pointing me to the simple_model.earth example.
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by gwaldron
@gwaldron, Thanks for the tips.

In @plevy's example, the <Model> element was not enclosed in an <Annotations>.  Does putting the models inside an <Annotations> element make it more efficient, or just provide some control over all the building models as single layer?

Also, is there a Layers Reference Guide planned for osgEarth 3, or is there another way that beginners like me can know all the valid ways the layer types can be combined, and what all the options do?
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by plevy
Can you point me to an example of the specific syntax for placing the models using a point shapefile?  This is one of many variations I have tried, but no buildings are showing up:

<map name="Denver">

    <OGRFeatures name="points">
        <url>c:/models/denver/model_pts_utm.shp</url>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>model: [model_name];</style>        </styles>
    </FeatureModel>

    <viewpoints>
        <viewpoint name="Denver" lat="39.7419" long="-104.9908" pitch="-21" range="1000"/>
    </viewpoints>

</map>
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

I found 'em!  The buildings are far below ground and too far north.  Not sure why.

I am applying a rotation to the buildings to convert Z-up to Y-up by appending ".(-90,0,0).rot" to the end of the filename.

When I place the buildings individually, using the approach suggested by @gwaldron, the buildings appear in their correct locations:

    <Annotations name="Buildings">
        <Model><style>model: "c:/denver/DV171767.obj.(-90,0,0).rot"; </style> <position lat="39.740320979" long="-104.991165337" alt="1595.130" /></Model>
        <Model><style>model: "c:/denver/DV171760.obj.(-90,0,0).rot"; </style> <position lat="39.742935827" long="-104.992144699" alt="1593.374" /></Model>
      ....
    </Annotations>


When I try to place the buildings using the point shapefile (which contains points with height values) they get rotated to below-ground positions:

    <OGRFeatures name="points">
        <url>c:/denver/model_points_wgs84.shp</url>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>model: [model_path];</style>
        </styles>
    </FeatureModel>

This seems like incorrect (or at least puzzling) behavior.  Is there a way to compensate for it?
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

I understand more about what is going on now.  My OBJ building models are Z-up oriented, but the OBJ loader assumes they are Y-up and rotates them.  So I was rotating them back, but when loading using a Shapefile for positioning, that rotation must not be done in the right place in the transformation order.

What I would really like to do is pass the "-O noRotation" option to the OBJ loader (which is what I would do when using osgviewer).  Is there a way to do that from the osgEarth command line or from the .earth file?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

notsofast, put this in your layer:

<osg_options>-O noRotation</osg_options>

That's the intent anyway; I'm not sure anyone has tested it in a long while.

Hope this helps.
Glenn Waldron / Pelican Mapping
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

@gwaldron, thanks for the suggestion.  However, it did not seem to work.  I tried putting osg_options in a bunch of places (see below), but am not seeing any effect.

<map name="PLW Denver" osg_options="-O noRotation">

    <osg_options>-O noRotation</osg_options>

    <OGRFeatures name="points" osg_options="-O noRotation">
        <url>c:/denver/model_utm13n.shp</url>
        <osg_options>-O noRotation</osg_options>
    </OGRFeatures>

    <FeatureModel name="points" features="points" osg_options="-O noRotation">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
                lighting: false
                noRotation: true;
                rotation: false;
            </style>
        </styles>
        <lighting>false</lighting>
        <osg_options>-O noRotation</osg_options>
    </FeatureModel>

     <TMSElevation name="ReadyMap 90m Elevation">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
        <vdatum>egm96</vdatum>
    </TMSElevation>

    <XYZImage name="OSM Imagery">
        <url>http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <profile>spherical-mercator</profile>
        <cache_policy usage="none"/>
        <attribution>&#169;OpenStreetMap contributors</attribution>
    </XYZImage>

    <options lighting="false" osg_options="-O noRotation">
        <terrain min_tile_range_factor="14" lighting="true"/>
        <osg_options>-O noRotation</osg_options>
    </options>

    <viewpoints>
        <viewpoint name="Denver Low" lat="39.7419" long="-104.9908" pitch="-21" alt="1800" range="0"/>
        <viewpoint name="Denver High" lat="39.7419" long="-104.9908" pitch="-90" range="4000" />
    </viewpoints>
</map>
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

My mistake. You don't need the "-O" since that is just the osgviewer command line indicator.
Try <osg_options>noRotation</osg_options>. And you only need it on the layer that will be using it, not everywhere.
Glenn Waldron / Pelican Mapping
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

Thanks!  Rats!  I thought that would do it, but no.  I'm still getting this:


The building tops are all facing South.

This is my current .earth file:
<map name="PLW Denver">

    <OGRFeatures name="points">
        <url>c:/denver/model_utm13n.shp</url>
        <osg_options>noRotation</osg_options>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
            </style>
        </styles>
        <osg_options>noRotation</osg_options>
    </FeatureModel>

    <TMSElevation name="ReadyMap 90m Elevation">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
        <vdatum>egm96</vdatum>
    </TMSElevation>

    <XYZImage name="OSM Imagery">
        <url>http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <profile>spherical-mercator</profile>
        <cache_policy usage="none"/>
        <attribution>&#169;OpenStreetMap contributors</attribution>
    </XYZImage>

    <options lighting="false">
        <terrain min_tile_range_factor="14" lighting="true"/>
    </options>

    <viewpoints>
        <viewpoint name="Denver Low" lat="39.7419" long="-104.9908" pitch="-21" alt="1800" range="0"/>
        <viewpoint name="Denver High" lat="39.7419" long="-104.9908" pitch="-90" range="4000" />
    </viewpoints>
</map>

Is it time for me to get out the debugger?
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

You can also try the rot pseudroloader on each model.  Something like this:
building-model:     "PowertransmisionTower.obj.0,0,45.rot";


--
Paul Levy : Pelican Mapping 

On Wed, Feb 3, 2021 at 10:44 AM notsofast [via osgEarth] <[hidden email]> wrote:
Thanks!  Rats!  I thought that would do it, but no.  I'm still getting this:


The building tops are all facing South.

This is my current .earth file:
<map name="PLW Denver">

    <OGRFeatures name="points">
        <url>c:/denver/model_utm13n.shp</url>
        <osg_options>noRotation</osg_options>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
            </style>
        </styles>
        <osg_options>noRotation</osg_options>
    </FeatureModel>

    <TMSElevation name="ReadyMap 90m Elevation">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
        <vdatum>egm96</vdatum>
    </TMSElevation>

    <XYZImage name="OSM Imagery">
        <url>http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <profile>spherical-mercator</profile>
        <cache_policy usage="none"/>
        <attribution>&#169;OpenStreetMap contributors</attribution>
    </XYZImage>

    <options lighting="false">
        <terrain min_tile_range_factor="14" lighting="true"/>
    </options>

    <viewpoints>
        <viewpoint name="Denver Low" lat="39.7419" long="-104.9908" pitch="-21" alt="1800" range="0"/>
        <viewpoint name="Denver High" lat="39.7419" long="-104.9908" pitch="-90" range="4000" />
    </viewpoints>
</map>

Is it time for me to get out the debugger?



If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Advice-needed-for-loading-custom-buildings-tp7593651p7593665.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by notsofast
Or osgconvert your obj files to osgb with the rotation
--
Paul Levy : Pelican Mapping 


On Wed, Feb 3, 2021 at 10:54 AM Paul Levy <[hidden email]> wrote:
You can also try the rot pseudroloader on each model.  Something like this:
building-model:     "PowertransmisionTower.obj.0,0,45.rot";


--
Paul Levy : Pelican Mapping 

On Wed, Feb 3, 2021 at 10:44 AM notsofast [via osgEarth] <[hidden email]> wrote:
Thanks!  Rats!  I thought that would do it, but no.  I'm still getting this:


The building tops are all facing South.

This is my current .earth file:
<map name="PLW Denver">

    <OGRFeatures name="points">
        <url>c:/denver/model_utm13n.shp</url>
        <osg_options>noRotation</osg_options>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
            </style>
        </styles>
        <osg_options>noRotation</osg_options>
    </FeatureModel>

    <TMSElevation name="ReadyMap 90m Elevation">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
        <vdatum>egm96</vdatum>
    </TMSElevation>

    <XYZImage name="OSM Imagery">
        <url>http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <profile>spherical-mercator</profile>
        <cache_policy usage="none"/>
        <attribution>&#169;OpenStreetMap contributors</attribution>
    </XYZImage>

    <options lighting="false">
        <terrain min_tile_range_factor="14" lighting="true"/>
    </options>

    <viewpoints>
        <viewpoint name="Denver Low" lat="39.7419" long="-104.9908" pitch="-21" alt="1800" range="0"/>
        <viewpoint name="Denver High" lat="39.7419" long="-104.9908" pitch="-90" range="4000" />
    </viewpoints>
</map>

Is it time for me to get out the debugger?



If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Advice-needed-for-loading-custom-buildings-tp7593651p7593665.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

In reply to this post by plevy
Thanks, I tried that.  While the rot pseudoloader works for models included directly in the .earth file, it did not work correctly when the models were loaded using a shapefile for the locations.  Apparently it was rotating them around a different origin (probably the x, y of the building origin, but with z=0).  So the 3D building models would end up underground and to the North.  I discovered this by turning on wireframe mode.
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

I cloned the repository and built osgEarth, and it works with this code in the .earth file:

    <OGRFeatures name="points">
        <url>c:/denver/model_utm13n.shp</url>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
            </style>
        </styles>
        <osg_options>noRotation</osg_options>
    </FeatureModel>

The buildings' Z-up orientation is preserved:


However, it did not work for the "vcpkg install osgearth:x64-windows" installation.  The working cloned-from-github version says it's osgEarth 3.1.0 build 101.  The non-working vcpkg version says it's osgEarth 3.1.0 build 100 (according to osgearth_version.exe).

Does it make sense that something changed between build 100 and build 101 to make the <osg_options>noRotation</osg_options> start working?
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

Are you using the same version of osg for both? 

--



On Tue, Feb 16, 2021 at 11:44 AM notsofast [via osgEarth] <[hidden email]> wrote:
I cloned the repository and built osgEarth, and it works with this code in the .earth file:

    <OGRFeatures name="points">
        <url>c:/denver/model_utm13n.shp</url>
    </OGRFeatures>

    <FeatureModel name="points" features="points">
        <styles>
            <style>
                model: [path_obj];
                render-lighting: false;
            </style>
        </styles>
        <osg_options>noRotation</osg_options>
    </FeatureModel>

The buildings' Z-up orientation is preserved:


However, it did not work for the "vcpkg install osgearth:x64-windows" installation.  The working cloned-from-github version says it's osgEarth 3.1.0 build 101.  The non-working vcpkg version says it's osgEarth 3.1.0 build 100 (according to osgearth_version.exe).

Does it make sense that something changed between build 100 and build 101 to make the <osg_options>noRotation</osg_options> start working?


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Advice-needed-for-loading-custom-buildings-tp7593651p7593684.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
notsofast notsofast
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed for loading custom buildings

plevy wrote
Are you using the same version of osg for both?
I tried it both ways:  using everything from the vcpkg build, and using osg from the vcpkg build plus osgEarth built from the repo.  The combination that works is:

- osg from the vcpkg build
- osgEarth from the 3.1 branch of the repo, which reports as build 101