/* -*-c++-*- */ /* osgEarth - Geospatial SDK for OpenSceneGraph * Copyright 2008-2014 Pelican Mapping * http://osgearth.org * * osgEarth is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see */ #ifndef OSGEARTH_TILE_MESHER #define OSGEARTH_TILE_MESHER 1 #include #include #include #include #define VERTEX_VISIBLE 1 // draw it #define VERTEX_BOUNDARY 2 // vertex lies on a skirt boundary #define VERTEX_HAS_ELEVATION 4 // not subject to elevation texture #define VERTEX_SKIRT 8 // it's a skirt vertex (bitmask) #define VERTEX_CONSTRAINT 16 // part of a non-morphable constraint namespace osgEarth { /** * Represents a single edit operation driven by a feature collection */ struct MeshConstraint { FeatureList features; bool hasElevation = false; // do the features contain valid elevation data in Z? bool removeInterior = false; // should we remove triangles inside polygons? bool removeExterior = false; // should we remove triangles outside polygons? bool fillElevations = false; // should we assign elevations to triangles? MeshConstraint() = default; MeshConstraint(const MeshConstraint& rhs) = default; MeshConstraint(MeshConstraint&& rhs) = default; }; //! Collection of mesh constraints using MeshConstraints = std::vector; /** * Geometry components for a tile (created by the TileMesher). */ struct OSGEARTH_EXPORT TileMesh { osg::Matrix localToWorld; osg::ref_ptr verts; osg::ref_ptr normals; osg::ref_ptr uvs; osg::ref_ptr vert_neighbors; osg::ref_ptr normal_neighbors; osg::ref_ptr indices; bool hasConstraints = false; TileMesh() { } TileMesh(const TileMesh& m); TileMesh(TileMesh&& m); TileMesh& operator = (const TileMesh&); }; /** * Creates a mesh for a TileKey, optionally including "edits" * created by constrait feature data. */ class OSGEARTH_EXPORT TileMesher { public: //! Construct a tile mesher TileMesher(); //! Configure this mesher with some terrain options void setTerrainOptions(const TerrainOptionsAPI& options); //! Create a tile mesh, optionally with a collection of edits. //! @param key TileKey for which to create the mesh //! @param constraints Constraints to apply to alter the mesh. //! If empty, the method will return a regular gridded mesh. //! @param progress Cancelation interface //! @return A tile mesh TileMesh createMesh( const TileKey& key, const MeshConstraints& constraints, Cancelable* progress) const; //! Apply edits to an existing mesh and return a new mesh. //! @param key TileKey for which to create the mesh //! @param input Existing mesh to constrain //! @param constraints Constraints to apply to alter the existing mesh //! @param progress Cancelation interface //! @return A tile mesh TileMesh createMesh( const TileKey& key, const TileMesh& input, const MeshConstraints& constraints, Cancelable* progress) const; //! Creates a primitive set that represents triangles for //! a tile mesh without any edits. osg::DrawElements* getOrCreateStandardIndices() const; protected: mutable osg::ref_ptr _standardIndices; mutable Mutex _mutex; TerrainOptionsAPI _options; TileMesh createMeshStandard( const TileKey& key, Cancelable* progress) const; TileMesh createMeshWithConstraints( const TileKey& key, const TileMesh& mesh, const MeshConstraints& edits, Cancelable* progress) const; }; } #endif // OSGEARTH_TILE_MESHER