Skip to content

Commit

Permalink
Procedural: separate modelassetmanager from biomemanager, add empty i…
Browse files Browse the repository at this point in the history
…nstancinglayer
  • Loading branch information
gwaldron committed Feb 21, 2025
1 parent 4a5f87e commit 7933a81
Show file tree
Hide file tree
Showing 15 changed files with 4,166 additions and 1,360 deletions.
16 changes: 10 additions & 6 deletions src/osgEarth/PowerlineLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ namespace
}
};

bool eq2d(const osg::Vec3d& lhs, const osg::Vec3d& rhs, double EPS = 1e-3)
bool eq2d(const osg::Vec3d& lhs, const osg::Vec3d& rhs, double EPS) // = 1e-3)
{
return
equivalent(lhs.x(), rhs.x(), EPS) &&
Expand Down Expand Up @@ -456,29 +456,31 @@ namespace

auto* geom = feature->getGeometry();

double eps = feature->getSRS()->isGeographic() ? 1e-9 : 1e-3;

for (auto& other : lines)
{
if (other.valid() && other != feature)
{
auto* other_geom = other->getGeometry();

if (eq2d(geom->back(), other_geom->front()))
if (eq2d(geom->back(), other_geom->front(), eps))
{
geom->resize(geom->size() - 1);
geom->insert(geom->end(), other_geom->begin(), other_geom->end());
changes++;
other = nullptr;
}

else if (eq2d(geom->back(), other_geom->back()))
else if (eq2d(geom->back(), other_geom->back(), eps))
{
geom->resize(geom->size() - 1);
geom->insert(geom->end(), other_geom->rbegin(), other_geom->rend());
changes++;
other = nullptr;
}

else if (eq2d(other_geom->back(), geom->front()))
else if (eq2d(other_geom->back(), geom->front(), eps))
{
other_geom->resize(other_geom->size() - 1);
other_geom->insert(other_geom->end(), geom->begin(), geom->end());
Expand All @@ -487,7 +489,7 @@ namespace
break;
}

else if (eq2d(other_geom->back(), geom->back()))
else if (eq2d(other_geom->back(), geom->back(), eps))
{
other_geom->resize(other_geom->size() - 1);
other_geom->insert(other_geom->end(), geom->rbegin(), geom->rend());
Expand All @@ -514,6 +516,8 @@ namespace
{
auto* output = new LineString();

double eps = feature->getSRS()->isGeographic() ? 1e-6 : 1e-1;

GeometryIterator iter(feature->getGeometry(), false);
iter.forEach([&](Geometry* geom)
{
Expand All @@ -522,7 +526,7 @@ namespace
osg::Vec3d point = (*geom)[i];

// skip duplicates.
if (i == 0 || !eq2d(point, (*geom)[i - 1], 0.1)) // local data (mercator)
if (i == 0 || !eq2d(point, (*geom)[i - 1], eps)) //0.1)) // local data (mercator)
{
auto ptItr = pointMap.find(point);
if (ptItr != pointMap.end())
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthImGui/PickerGUI
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace osgEarth
void highlight_fragment(inout vec4 color)
{
if ( selected == 1 )
color.rgb = mix(color.rgb, clamp(vec3(0.5,2.0,2.0)*(1.0-color.rgb), 0.0, 1.0), 0.5);
color.rgb = vec3(0,1,1);
}
)";

Expand Down
4 changes: 3 additions & 1 deletion src/osgEarthImGui/VegetationLayerGUI
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ namespace osgEarth
{
auto biocat = _biolayer->getBiomeCatalog();
auto& bioman = _biolayer->getBiomeManager();
auto& assetman = bioman.getAssetManager();

auto assets = assetman.getResidentAssetsIfNotLocked();

auto assets = bioman.getResidentAssetsIfNotLocked();
for (auto& asset : assets)
{
drawModelAsset(asset);
Expand Down
185 changes: 2 additions & 183 deletions src/osgEarthProcedural/Biome
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_PROCEDURAL_BIOME
#define OSGEARTH_PROCEDURAL_BIOME 1
#pragma once

#include <osgEarthProcedural/Export>
#include <osgEarthProcedural/ModelAssetManager>
#include <osgEarth/Config>
#include <osgEarth/URI>
#include <osgEarth/Units>
Expand Down Expand Up @@ -50,159 +50,6 @@ namespace osgEarth
toString(const std::vector<std::string>& traits);
};

/**
* Individual artwork asset that lives in the AssetCatalog.
* This structure defines the asset only; it does not contain
* the actual loaded asset data like the 3D model or billboard
* images.
*/
class OSGEARTHPROCEDURAL_EXPORT ModelAsset
{
public:
//! Readable name of the asset
OE_PROPERTY(std::string, name, {});

//! URI from which to load the asset 3D model
OE_OPTION(URI, modelURI);

//! URI from which to load a side texture for an impostor
OE_OPTION(URI, sideBillboardURI);

//! URI from which to load a top texture for an impostor
OE_OPTION(URI, topBillboardURI);

//! When only billboards are available, width of each billboard (meters)
OE_OPTION(float, width);

//! When only billboards are availalbe, height of each billboard (meters)
OE_OPTION(float, height);

//! Static scale to apply to 3D model (no impact on width/height options)
OE_OPTION(float, scale);

//! Variation range (+/-) added to the scale when creating an
//! instance of this asset.
//! For example:
//! - Value of 0.0 means the scale will always be 1.0
//! - Value of 0.5 means the scale can be [0.5 ... 1.5].
//! - Value of 1.0 means the scale can be [0.0 ... 2.0].
OE_OPTION(float, sizeVariation);

//! Stiffness, or how much it will move in the wind. [0..1]
//! - 0 = no stiffness, free to move;
//! - 1 = completely stiff, wind has no effect.
//! Default is 0.5
OE_OPTION(float, stiffness);

//! Minimum lushness of this asset [0..1] - the asset becomes a
//! candidate for placement if the lifemap's lush value is
//! greater than or equal to this value. Default is zero (0).
OE_OPTION(float, minLush);

//! Maximum lushness of this asset [0..1] - the asset becomes a
//! candidate for placement if the lifemap's lush value is
//! less than or equal to this value. Default is one (1).
OE_OPTION(float, maxLush);

//! Height at which to position the top billboard when
//! rendering as an impostor (meters). By default it
//! is placed 1/3 up the height of the model.
OE_OPTION(float, topBillboardHeight);

//! User-defined traits string (comma-delimited)
OE_PROPERTY(std::vector<std::string>, traits, {});

//! If true, this asset will ONLY be used in a biome that
//! explicity inherits this asset's traits from land cover
//! data. Default = false.
OE_OPTION(bool, traitsRequired);

//! Asset group to which this model belongs.
OE_PROPERTY(std::string, group, {});

public:
//! Construct an empty model asset definition
ModelAsset() { }

//! Deserialize the asset def from a Config
ModelAsset(const Config& conf);

//! Serialize to a config
Config getConfig() const;

//! Get Config from which this asset was originally loaded,
//! which will give the caller access to user-defined values
//! if they exist.
const Config& getSourceConfig() const {
return _sourceConfig;
}

private:
Config _sourceConfig;
};

/**
* Definition of a ground material artwork asset.
* This structure contains the definition only and does not hold
* any actual loaded data.
*/
class OSGEARTHPROCEDURAL_EXPORT MaterialAsset
{
public:
OE_OPTION(std::string, name);
OE_OPTION(URI, uri);
OE_OPTION(Distance, size);

public:
MaterialAsset() { }
MaterialAsset(const Config& conf);
Config getConfig() const;
};

/**
* Container for all artwork asset definitions.
*/
class OSGEARTHPROCEDURAL_EXPORT AssetCatalog
{
public:
//! Construct an empty asset catalog
AssetCatalog() { }

//! Deserialize an asset catalog
AssetCatalog(const Config& conf);

//! Model asset associated with given name
//! @param name Name of model asset to return
//! @return ModelAsset or nullptr if no match
const ModelAsset* getModel(const std::string& name) const;

//! Material asset with the given name
//! @param name Name of material asset to return
//! @return MaterialAsset or nullptr if no match
const MaterialAsset* getMaterial(const std::string& name) const;

//! Dimensions of the lifemap texture matrix (x,y)
unsigned getLifeMapMatrixWidth() const;

//! Collection of ground textures in the lifemap matrix
const std::vector<MaterialAsset>& getMaterials() const {
return _materials;
}

//! Is the catalog empty?
bool empty() const;

public:
//! serialize into a Config
Config getConfig() const;

protected:
// use std::map for consistent iteration
std::map<std::string, ModelAsset> _models;
unsigned _lifemapMatrixWidth;
std::vector<MaterialAsset> _materials;
};

/**
* Collection of artwork assets.
* A biome may have a "parent" biome. This means that if the Biome
Expand All @@ -224,32 +71,6 @@ namespace osgEarth
//! Optional identifier of this biome's parent
OE_OPTION(std::string, parentId);

// points to an asset, adding in some custom parameters.
struct OSGEARTHPROCEDURAL_EXPORT ModelAssetRef
{
ModelAssetRef();

using Ptr = std::shared_ptr<ModelAssetRef>;

// points to the base asset in the catalog
using ModelAssetPointer = const ModelAsset * ;

//! Reference to the asset being used
OE_PROPERTY(ModelAssetPointer, asset, {});

//! Selection weight compared to other assets (default = 1.0)
OE_PROPERTY(float, weight, 1.0f);

//! Coverage percentage when this asset it selected (default = 1.0)
OE_PROPERTY(float, coverage, 1.0f);

bool operator < (const ModelAssetRef& rhs) const {
return (std::uintptr_t)asset() < (std::uintptr_t)rhs.asset();
}
};

using ModelAssetRefs = std::vector<ModelAssetRef::Ptr>;

// A collection of asset pointers for each existing AssetGroup
ModelAssetRefs _assetsToUse;

Expand Down Expand Up @@ -315,5 +136,3 @@ namespace osgEarth
};

} } // namespace osgEarth::Procedural

#endif
Loading

0 comments on commit 7933a81

Please sign in to comment.