Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Mar 15, 2024
1 parent 10cc90e commit 3846864
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 153 deletions.
14 changes: 11 additions & 3 deletions examples/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,26 @@ add_library(pathfinding INTERFACE
)
target_include_directories(pathfinding INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")

add_library(geo-threepp INTERFACE
add_library(geothreepp
"${CMAKE_CURRENT_SOURCE_DIR}/geo/lod/LODControl.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/lod/LODFrustum.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/lod/LODRadial.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/lod/LODRaycast.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/geo/nodes/MapNode.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/nodes/MapNode.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/nodes/MapPlaneNode.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/geo/geometries/MapNodeGeometry.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/geo/providers/MapProvider.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/providers/OpenStreetMapsProvider.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/geo/utils/UnitUtils.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/geo/MapView.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/geo/MapView.cpp"
)

target_include_directories(geo-threepp INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(geo-threepp INTERFACE threepp::threepp CURL::libcurl)
target_include_directories(geothreepp PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(geothreepp PUBLIC threepp::threepp CURL::libcurl)

Check failure on line 54 in examples/libs/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / vcpkg-on-linux (ubuntu-22.04, 11)

Target "geothreepp" links to:

Check failure on line 54 in examples/libs/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / vcpkg-on-windows (windows-2022)

Target "geothreepp" links to:
65 changes: 65 additions & 0 deletions examples/libs/geo/MapView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

#include "MapView.hpp"

#include "lod/LODControl.hpp"
#include "lod/LODFrustum.hpp"
#include "lod/LODRaycast.hpp"

using namespace threepp;


namespace {

void subdivide(MapNode& node, float depth) {
if (depth <= 0) {
return;
}

node.subdivide();

for (unsigned i = 0; i < node.children.size(); i++) {
if (auto child = node.children[i]->as<MapNode>()) {

subdivide(*child, depth - 1);
}
}
}

}// namespace


MapView::MapView(std::unique_ptr<MapProvider> provider, std::unique_ptr<LODControl> lod): provider(std::move(provider)), lod(std::move(lod)) {

onBeforeRender = [this](void* renderer, Object3D* scene, Camera* camera, BufferGeometry*, Material*, std::optional<GeometryGroup>) {
this->lod->updateLOD(*this, *camera, *static_cast<GLRenderer*>(renderer), *scene);
};

root = std::make_unique<MapPlaneNode>(nullptr, this);

geometry_ = root->baseGeometry();
material()->transparent = false;
material()->as<MaterialWithWireframe>()->wireframe = true;
material()->opacity = 0.0;
material()->depthWrite = false;
material()->colorWrite = false;

scale.copy(root->baseScale());

add(*root);
root->initialize();

preSubDivide();
}

void MapView::preSubDivide() {

const auto minZoom = this->provider->minZoom;
if (minZoom > 0) {
subdivide(*this->root, minZoom);
}
}

MapProvider* MapView::getProvider() const {

return provider ? provider.get() : nullptr;
}
27 changes: 14 additions & 13 deletions examples/libs/geo/MapView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
#include "threepp/objects/Mesh.hpp"

#include "geo/lod/LODControl.hpp"
#include "geo/lod/LODRaycast.hpp"
#include "geo/providers/MapProvider.hpp"
#include "nodes/MapPlaneNode.hpp"
#include "providers/MapProvider.hpp"

namespace threepp {

class MapView: public Mesh {

public:
std::unique_ptr<LODControl> lod;
std::unique_ptr<MapProvider> provider;

MapView(std::unique_ptr<MapProvider> provider): provider(std::move(provider)) {

onBeforeRender = [](void*, Object3D*, Camera*, BufferGeometry*, Material*, std::optional<GeometryGroup>) {
explicit MapView(std::unique_ptr<MapProvider> provider, std::unique_ptr<LODControl> lod);

};

lod = std::make_unique<LODRaycast>();
}
void preSubDivide();

float minZoom() {
[[nodiscard]] float minZoom() const {
return this->provider->minZoom;
}

float maxZoom() {
[[nodiscard]] float maxZoom() const {
return this->provider->maxZoom;
}

MapProvider* getProvider() const;

void raycast(const Raycaster& raycaster, std::vector<Intersection>& intersects) override {}

private:

std::unique_ptr<MapPlaneNode> root;
std::unique_ptr<LODControl> lod;
std::unique_ptr<MapProvider> provider;
};


}// namespace threepp

#endif//THREEPP_MAPVIEW_HPP
9 changes: 3 additions & 6 deletions examples/libs/geo/geometries/MapNodeGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ namespace threepp {
class MapNodeGeometry: public BufferGeometry {

public:
static std::shared_ptr<MapNodeGeometry> create(int width = 1, int height = 1, int widthSegments = 1, int heightSegments = 1, bool skirt = true, int skirtDepth = 10) {

static std::shared_ptr<MapNodeGeometry> create(int width = 1, int height = 1, int widthSegments = 1, int heightSegments = 1, bool skirt = true, int skirtDepth = 10) {

return std::shared_ptr<MapNodeGeometry>(new MapNodeGeometry(width, height, widthSegments, heightSegments, skirt, skirtDepth));
}
return std::shared_ptr<MapNodeGeometry>(new MapNodeGeometry(width, height, widthSegments, heightSegments, skirt, skirtDepth));
}

private:

explicit MapNodeGeometry(int width, int height, int widthSegments, int heightSegments, bool skirt, int skirtDepth) {

std::vector<unsigned int> indices;
Expand All @@ -34,7 +32,6 @@ namespace threepp {
setAttribute("position", FloatBufferAttribute::create(vertices, 3));
setAttribute("normal", FloatBufferAttribute::create(normals, 3));
setAttribute("uv", FloatBufferAttribute::create(uvs, 2));

}

void buildPlane(std::vector<unsigned int>& indices, std::vector<float>& vertices,
Expand Down
4 changes: 2 additions & 2 deletions examples/libs/geo/lod/LODControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "threepp/cameras/Camera.hpp"
#include "threepp/renderers/GLRenderer.hpp"

#include "geo/MapView.hpp"

namespace threepp {

class MapView;

class LODControl {

public:
Expand Down
35 changes: 32 additions & 3 deletions examples/libs/geo/lod/LODFrustum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@
#include "threepp/math/Frustum.hpp"
#include "threepp/math/Matrix4.hpp"

#include "geo/lod/LODRadial.hpp"
#include "../lod/LODRadial.hpp"
#include "../MapView.hpp"

namespace threepp {

class LODFrustum: public LODRadial {

public:

bool testCenter = true;
bool pointOnly = true;

explicit LODFrustum(float subdivideDistance = 150, float simplifyDistance = 400)
: LODRadial(subdivideDistance, simplifyDistance) {}

void updateLOD(MapView& view, Camera& camera, GLRenderer& renderer, Object3D& scene) override {

projection.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
frustum.setFromProjectionMatrix(projection);
camera.getWorldPosition(pov);

view.children[0]->traverseType<MapNode>([&](MapNode& node) {
node.getWorldPosition(position);

auto distance = pov.distanceTo(position);
distance /= std::pow(2, view.getProvider()->maxZoom - node.getLevel());

const auto inFrustum = this->pointOnly ? frustum.containsPoint(position) : frustum.intersectsObject(node);

if (distance < this->subdivideDistance && inFrustum) {
node.subdivide();
} else if (distance > this->simplifyDistance && node.parentNode) {
node.parentNode->simplify();
}
});
}

private:
Matrix4 projection;
Vector3 pov;
Frustum frustum;
Vector3 position;
};

}// namespace threepp
Expand Down
31 changes: 18 additions & 13 deletions examples/libs/geo/lod/LODRadial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#include "threepp/core/Object3D.hpp"

#include "geo/lod/LODControl.hpp"
#include "geo/nodes/MapNode.hpp"
#include "../lod/LODControl.hpp"
#include "../nodes/MapNode.hpp"
#include "../MapView.hpp"

#include <cmath>

Expand All @@ -17,25 +18,29 @@ namespace threepp {
explicit LODRadial(float subdivideDistance = 50, float simplifyDistance = 300)
: subdivideDistance(subdivideDistance), simplifyDistance(simplifyDistance) {}

void updateLOD(MapView& view, Camera& camera, GLRenderer& renderer, Object3D& scene) {
void updateLOD(MapView& view, Camera& camera, GLRenderer& renderer, Object3D& scene) override {

camera.getWorldPosition(pov);

view.children[0]->traverseType<MapNode>([&](MapNode& node) {
node.getWorldPosition(position);
view.children[0]->traverse([&](Object3D& o) {

auto distance = pov.distanceTo(position);
distance /= std::pow(2, view.provider->maxZoom - node.getLevel());
//
if (distance < this->subdivideDistance) {
node.subdivide();
} else if (distance > this->simplifyDistance && node.parentNode) {
node.parentNode->simplify();
if (auto node = o.as<MapNode>()) {

node->getWorldPosition(position);

auto distance = pov.distanceTo(position);
distance /= std::pow(2, view.getProvider()->maxZoom - node->getLevel());
//
if (distance < this->subdivideDistance) {
node->subdivide();
} else if (distance > this->simplifyDistance && node->parentNode) {
node->parentNode->simplify();
}
}
});
}

private:
protected:
float subdivideDistance;
float simplifyDistance;

Expand Down
Loading

0 comments on commit 3846864

Please sign in to comment.