diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 437b727..1d7c298 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Cache dependencies uses: actions/cache@v2 # 使用actions/cache with: - path: ~/vcpkg # 设置缓存目录路径 + path: ./vcpkg # 设置缓存目录路径 key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/build.rs') }} # 设置缓存的key restore-keys: | # 设置恢复缓存的key列表 ${{ runner.os }}-vcpkg- @@ -22,21 +22,22 @@ jobs: - name: Install dependencies on Ubuntu if: runner.os == 'Linux' run: | - sudo apt-get install -y libxi-dev libgl1-mesa-dev libglu1-mesa-dev mesa-common-dev libxrandr-dev libxxf86vm-dev - git clone /~https://github.com/Microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.sh - ./vcpkg/vcpkg integrate install - ./vcpkg/vcpkg install osg - ./vcpkg/vcpkg install gdal + sudo apt-get update + sudo apt-get install -y g++ libgdal-dev libopenscenegraph-dev - name: Install dependencies on Windows if: runner.os == 'Windows' run: | - git clone /~https://github.com/Microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.bat - ./vcpkg/vcpkg integrate install - ./vcpkg/vcpkg install osg - ./vcpkg/vcpkg install gdal + if (-Not (Test-Path "./vcpkg")) { + git clone /~https://github.com/Microsoft/vcpkg.git + ./vcpkg/bootstrap-vcpkg.bat + ./vcpkg/vcpkg integrate install + ./vcpkg/vcpkg install osg + ./vcpkg/vcpkg install gdal + } + else { + Write-Host "vcpkg directory exists. Skipping installation." + } - name: Build run: cargo build --verbose --release diff --git a/README.md b/README.md index d2cfb72..7b3ace2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,21 @@ You may intereted in: - [Docker Image](https://hub.docker.com/r/winner1/3dtiles) +# Build +## Ubuntu +``` +sudo apt-get update +sudo apt-get install -y g++ libgdal-dev libopenscenegraph-dev cargo +cargo build --release +``` +## Centos +``` + +``` +## Windows +``` + +``` # Usage ## ① Command Line diff --git a/build.rs b/build.rs index a71d84b..e9d3463 100644 --- a/build.rs +++ b/build.rs @@ -18,7 +18,7 @@ fn build_win_msvc() { .file("./src/osgb23dtile.cpp") .file("./src/dxt_img.cpp") .file("./src/GeoTransform.cpp") - .compile("_3dtile"); + .compile("3dtile"); // ------------- println!("cargo:rustc-link-search=native=./lib"); // ------------- @@ -53,14 +53,17 @@ fn build_linux_unkonw() { .file("./src/shp23dtile.cpp") .file("./src/osgb23dtile.cpp") .file("./src/dxt_img.cpp") - .compile("_3dtile"); + .file("./src/GeoTransform.cpp") + .compile("3dtile"); // ------------- - println!("cargo:rustc-link-search=native=./lib"); + println!("cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu"); // ------------- println!("cargo:rustc-link-lib=OpenThreads"); println!("cargo:rustc-link-lib=osg"); println!("cargo:rustc-link-lib=osgDB"); println!("cargo:rustc-link-lib=osgUtil"); + // gdal library + println!("cargo:rustc-link-lib=gdal"); } fn main() { diff --git a/src/earcut.hpp b/src/earcut.hpp index a916c1d..8e8907d 100644 --- a/src/earcut.hpp +++ b/src/earcut.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/src/shp23dtile.cpp b/src/shp23dtile.cpp index 275d3da..407f20d 100644 --- a/src/shp23dtile.cpp +++ b/src/shp23dtile.cpp @@ -1,12 +1,10 @@ -#ifdef _WIN32 -#include "gdal/ogrsf_frmts.h" -#endif - #include "tiny_gltf.h" #include "earcut.hpp" #include "json.hpp" #include "extern.h" +#include + #include #include #include @@ -248,7 +246,6 @@ void calc_normal(int baseCnt, int ptNum, Polygon_Mesh &mesh) } } -#ifdef _WIN32 Polygon_Mesh convert_polygon(OGRPolygon* polyon, double center_x, double center_y, double height) { @@ -372,7 +369,6 @@ convert_polygon(OGRPolygon* polyon, double center_x, double center_y, double hei } return mesh; } -#endif std::string make_polymesh(std::vector& meshes); std::string make_b3dm(std::vector& meshes, bool); @@ -381,7 +377,6 @@ extern "C" bool shp23dtile(const char* filename, int layer_id, const char* dest, const char* height) { -#ifdef _WIN32 if (!filename || layer_id < 0 || layer_id > 10000 || !dest) { LOG_E("make shp23dtile [%s] failed", filename); return false; @@ -545,9 +540,6 @@ shp23dtile(const char* filename, int layer_id, // GDALClose(poDS); return true; -#else - return false; -#endif } template diff --git a/src/tileset.cpp b/src/tileset.cpp index b08cc35..58dc218 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -1,22 +1,20 @@ -#ifdef _WIN32 -#include -#include -#endif - #include #include #include #include #include +#include +#include + #include "extern.h" #include "GeoTransform.h" /////////////////////// static const double pi = std::acos(-1); -#ifdef _WIN32 -extern "C" bool epsg_convert(int insrs, double* val, char* path) { +extern "C" bool +epsg_convert(int insrs, double* val, char* path) { CPLSetConfigOption("GDAL_DATA", path); OGRSpatialReference inRs,outRs; inRs.importFromEPSG(insrs); @@ -34,7 +32,8 @@ extern "C" bool epsg_convert(int insrs, double* val, char* path) { return false; } -extern "C" bool wkt_convert(char* wkt, double* val, char* path) { +extern "C" bool +wkt_convert(char* wkt, double* val, char* path) { CPLSetConfigOption("GDAL_DATA", path); OGRSpatialReference inRs,outRs; inRs.importFromWkt(&wkt); @@ -51,21 +50,6 @@ extern "C" bool wkt_convert(char* wkt, double* val, char* path) { return false; } -#else -extern "C" bool -epsg_convert(int insrs, double* val, char* path) -{ - return false; -} - -extern "C" bool -wkt_convert(char* wkt, double* val, char* path) -{ - return false; -} - -#endif - extern "C" { double degree2rad(double val) { @@ -88,8 +72,8 @@ extern "C" } } - -std::vector transfrom_xyz(double radian_x, double radian_y, double height_min){ +std::vector +transfrom_xyz(double radian_x, double radian_y, double height_min){ double ellipsod_a = 40680631590769; double ellipsod_b = 40680631590769; double ellipsod_c = 40408299984661.4; @@ -149,19 +133,17 @@ std::vector transfrom_xyz(double radian_x, double radian_y, double heigh return matrix; } -extern "C" void transform_c(double center_x, double center_y, double height_min, double* ptr) { +extern "C" void +transform_c(double center_x, double center_y, double height_min, double* ptr) { double radian_x = degree2rad( center_x ); double radian_y = degree2rad( center_y ); std::vector v = transfrom_xyz(radian_x, radian_y, height_min); std::memcpy(ptr, v.data(), v.size() * 8); } -bool write_tileset_box( - Transform* trans, Box& box, - double geometricError, - const char* b3dm_file, - const char* json_file) { - +bool +write_tileset_box(Transform* trans, Box& box, double geometricError, + const char* b3dm_file, const char* json_file) { std::vector matrix; if (trans) { matrix = transfrom_xyz(trans->radian_x,trans->radian_y,trans->min_height); @@ -257,14 +239,10 @@ bool write_tileset_region( } /***/ -bool write_tileset( - double radian_x, double radian_y, - double tile_w, double tile_h, - double height_min, double height_max, - double geometricError, - const char* filename, const char* full_path) -{ - +bool +write_tileset(double radian_x, double radian_y, + double tile_w, double tile_h, double height_min, double height_max, + double geometricError, const char* filename, const char* full_path) { double ellipsod_a = 40680631590769; double ellipsod_b = 40680631590769; double ellipsod_c = 40408299984661.4;