diff --git a/examples/libs/geo/MapView.cpp b/examples/libs/geo/MapView.cpp index c745809a..3e7a25de 100644 --- a/examples/libs/geo/MapView.cpp +++ b/examples/libs/geo/MapView.cpp @@ -38,13 +38,14 @@ MapView::MapView(std::unique_ptr provider, std::unique_ptrbaseGeometry(); material()->transparent = true; - material()->opacity = 0.0; material()->depthWrite = false; material()->colorWrite = false; + material()->opacity = 0; scale.copy(root->baseScale()); add(*root); + root->initialize(); preSubDivide(); } diff --git a/examples/libs/geo/lod/LODRadial.hpp b/examples/libs/geo/lod/LODRadial.hpp index 5633d58c..d437a8b1 100644 --- a/examples/libs/geo/lod/LODRadial.hpp +++ b/examples/libs/geo/lod/LODRadial.hpp @@ -17,6 +17,9 @@ namespace threepp { class LODRadial: public LODControl { public: + float subdivideDistance; + float simplifyDistance; + explicit LODRadial(float subdivideDistance = 50, float simplifyDistance = 300) : subdivideDistance(subdivideDistance), simplifyDistance(simplifyDistance) {} @@ -28,7 +31,7 @@ namespace threepp { node.getWorldPosition(position); auto distance = pov.distanceTo(position); - distance /= std::pow(2, view.getProvider()->maxZoom - node.getLevel()); + distance /= std::pow(2.f, view.getProvider()->maxZoom - node.getLevel()); // if (distance < this->subdivideDistance) { node.subdivide(); @@ -39,9 +42,6 @@ namespace threepp { } protected: - float subdivideDistance; - float simplifyDistance; - Vector3 pov; Vector3 position; }; diff --git a/examples/libs/geo/lod/LODRaycast.cpp b/examples/libs/geo/lod/LODRaycast.cpp index dd79b2a0..e5a1c883 100644 --- a/examples/libs/geo/lod/LODRaycast.cpp +++ b/examples/libs/geo/lod/LODRaycast.cpp @@ -4,7 +4,6 @@ using namespace threepp; - void LODRaycast::updateLOD(MapView& view, Camera& camera, const GLRenderer& renderer, const Object3D& scene) { std::vector intersects; @@ -25,7 +24,7 @@ void LODRaycast::updateLOD(MapView& view, Camera& camera, const GLRenderer& rend auto distance = intersect.distance; if (this->powerDistance) { - distance = std::pow(distance * 2, node->getLevel()); + distance = std::pow(distance * 2.f, node->getLevel()); } if (this->scaleDistance) { diff --git a/examples/libs/geo/nodes/MapNode.cpp b/examples/libs/geo/nodes/MapNode.cpp index 58aee252..47a8cbab 100644 --- a/examples/libs/geo/nodes/MapNode.cpp +++ b/examples/libs/geo/nodes/MapNode.cpp @@ -2,8 +2,6 @@ #include "MapNode.hpp" #include "../MapView.hpp" -#include "threepp/materials/interfaces.hpp" - #include using namespace threepp; @@ -23,6 +21,8 @@ void MapNode::subdivide() { this->createChildNodes(); + layers.disable(0); + this->subdivided = true; } @@ -55,7 +55,7 @@ void MapNode::loadData() { } const auto texture = Texture::create(image); - texture->generateMipmaps = false; + texture->generateMipmaps = true; texture->format = Format::RGBA; texture->magFilter = Filter::Linear; texture->minFilter = Filter::Linear; @@ -68,7 +68,6 @@ void MapNode::loadData() { void MapNode::nodeReady() { if (this->disposed) { std::cerr << "Geo-Three: nodeReady() called for disposed node" << std::endl; - // this->dispose(); disposed = true; return; } @@ -79,13 +78,11 @@ void MapNode::nodeReady() { if (this->parentNode->nodesLoaded == MapNode::childrens) { if (this->parentNode->subdivided == true) { - this->parentNode->layers.disable(0); + this->layers.disable(0); } for (unsigned i = 0; i < this->parentNode->children.size(); i++) { this->parentNode->children[i]->visible = true; - // this->parentNode->children[i]->layers.enable(0); - // this->parentNode->layers.disable(0); } } diff --git a/examples/libs/geo/nodes/MapPlaneNode.hpp b/examples/libs/geo/nodes/MapPlaneNode.hpp index be913f9c..ed3ea493 100644 --- a/examples/libs/geo/nodes/MapPlaneNode.hpp +++ b/examples/libs/geo/nodes/MapPlaneNode.hpp @@ -3,11 +3,14 @@ #ifndef THREEPP_MAPPLANENODE_HPP #define THREEPP_MAPPLANENODE_HPP -#include "../utils/UnitUtils.hpp" #include "MapNode.hpp" #include "geo/geometries/MapNodeGeometry.hpp" +#include "geo/utils/UnitUtils.hpp" #include "threepp/materials/MeshBasicMaterial.hpp" +#include + + namespace threepp { namespace { @@ -20,11 +23,9 @@ namespace threepp { MapPlaneNode(MapNode* parent, MapView* mapView, int location = QuadTreePosition::root, int level = 0, float x = 0, float y = 0) : MapNode(parent, mapView, location, level, x, y, baseGeom, MeshBasicMaterial::create({{"wireframe", false}})) { - initialize(); - this->matrixAutoUpdate = false; this->layers.enable(0); -// this->visible = false; + this->visible = false; } void initialize() override { @@ -55,6 +56,7 @@ namespace threepp { this->add(node); node->updateMatrix(); node->updateMatrixWorld(true); + node->initialize(); node = std::make_shared(this, this->mapView, QuadTreePosition::topRight, level, x + 1, y); node->scale.set(0.5, 1.0, 0.5); @@ -62,6 +64,7 @@ namespace threepp { this->add(node); node->updateMatrix(); node->updateMatrixWorld(true); + node->initialize(); node = std::make_shared(this, this->mapView, QuadTreePosition::bottomLeft, level, x, y + 1); node->scale.set(0.5, 1.0, 0.5); @@ -69,6 +72,7 @@ namespace threepp { this->add(node); node->updateMatrix(); node->updateMatrixWorld(true); + node->initialize(); node = std::make_shared(this, this->mapView, QuadTreePosition::bottomRight, level, x + 1, y + 1); node->scale.set(0.5, 1.0, 0.5); @@ -76,6 +80,7 @@ namespace threepp { this->add(node); node->updateMatrix(); node->updateMatrixWorld(true); + node->initialize(); } }; diff --git a/examples/libs/geo/providers/OpenStreetMapsProvider.hpp b/examples/libs/geo/providers/OpenStreetMapsProvider.hpp index 1ec9bf3c..9450b540 100644 --- a/examples/libs/geo/providers/OpenStreetMapsProvider.hpp +++ b/examples/libs/geo/providers/OpenStreetMapsProvider.hpp @@ -8,9 +8,10 @@ #include "threepp/loaders/ImageLoader.hpp" +#include +#include #include #include -#include namespace threepp { @@ -27,11 +28,17 @@ namespace threepp { std::stringstream ss; ss << address << zoom << '/' << x << '/' << y << '.' << format; + const auto url = ss.str(); std::vector data; - urlFetcher.fetch(ss.str(), data); - std::cout << ss.str() << std::endl; + if (cache_.count(url)) { + data = cache_.at(url); + + } else if (urlFetcher.fetch(url, data)) { + + cache_[url] = data; + } return *loader.load(data, format == "png" ? 4 : 3, true); } @@ -40,8 +47,10 @@ namespace threepp { std::string address; std::string format = "png"; - utils::UrlFetcher urlFetcher; ImageLoader loader; + utils::UrlFetcher urlFetcher; + + std::unordered_map> cache_{}; }; }// namespace threepp diff --git a/examples/libs/utility/URLFetcher.hpp b/examples/libs/utility/URLFetcher.hpp index 85520789..1ea7106d 100644 --- a/examples/libs/utility/URLFetcher.hpp +++ b/examples/libs/utility/URLFetcher.hpp @@ -4,16 +4,21 @@ #if __has_include() #define THREEPP_WITH_CURL #include +#else +#include #endif #include #include +#include namespace threepp::utils { #ifdef THREEPP_WITH_CURL inline static size_t write_data(char* ptr, size_t size, size_t nmemb, void* userdata) { + static std::mutex m; + std::lock_guard lck(m); auto stream = (std::vector*) userdata; size_t count = size * nmemb; stream->insert(stream->end(), ptr, ptr + count); @@ -26,7 +31,7 @@ namespace threepp::utils { #ifndef THREEPP_WITH_CURL bool fetch(const std::string&, std::vector&) { - + std::cerr << "[URLFetcher] Curl not found. No fetch was made." << std::endl; return false; } #else @@ -37,19 +42,10 @@ namespace threepp::utils { bool fetch(const std::string& url, std::vector& data) { - if (cache_.count(url)) { - data = cache_[url]; - return true; - } - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); CURLcode res = curl_easy_perform(curl); - if (res == CURLE_OK) { - cache_[url] = data; - } - return res == CURLE_OK; } @@ -59,7 +55,6 @@ namespace threepp::utils { private: CURL* curl; - std::unordered_map> cache_{}; #endif }; diff --git a/examples/projects/MapView/main.cpp b/examples/projects/MapView/main.cpp index d674469d..3464b123 100644 --- a/examples/projects/MapView/main.cpp +++ b/examples/projects/MapView/main.cpp @@ -24,13 +24,17 @@ int main() { OrbitControls controls{camera, canvas}; - MapView map(std::make_unique(), std::make_unique()); + auto lodFunc = std::make_unique(); + lodFunc->subdivideDistance = 100; + auto provider = std::make_unique(); + + MapView map(std::move(provider), std::move(lodFunc)); scene.add(map); map.updateMatrixWorld(true); - const auto coords = utils::datumsToSpherical(62.50094228364612, 6.09138498277564); + const auto coords = utils::datumsToSpherical(62.467400106161094, 6.156371664207545); controls.target.set(coords.x, 0, -coords.y); - camera.position.set(coords.x, 100000, -coords.y); + camera.position.set(coords.x, 10000, -coords.y); controls.update(); canvas.onWindowResize([&](WindowSize size) {