Skip to content

Commit

Permalink
ubuntu build
Browse files Browse the repository at this point in the history
  • Loading branch information
fanvanzh committed May 22, 2024
1 parent 6b13137 commit d3962d6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 65 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@ 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-
- 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
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
// -------------
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/earcut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <algorithm>
#include <cassert>
#include <limits>
#include <cmath>
#include <memory>
#include <vector>
Expand Down
12 changes: 2 additions & 10 deletions src/shp23dtile.cpp
Original file line number Diff line number Diff line change
@@ -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 <gdal/ogrsf_frmts.h>

#include <osg/Material>
#include <osg/PagedLOD>
#include <osgDB/ReadFile>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<Polygon_Mesh>& meshes);
std::string make_b3dm(std::vector<Polygon_Mesh>& meshes, bool);
Expand All @@ -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;
Expand Down Expand Up @@ -545,9 +540,6 @@ shp23dtile(const char* filename, int layer_id,
//
GDALClose(poDS);
return true;
#else
return false;
#endif
}

template<class T>
Expand Down
58 changes: 18 additions & 40 deletions src/tileset.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#ifdef _WIN32
#include <gdal/ogr_spatialref.h>
#include <gdal/ogrsf_frmts.h>
#endif

#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#include <gdal/ogrsf_frmts.h>
#include <gdal/ogr_spatialref.h>

#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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -88,8 +72,8 @@ extern "C"
}
}


std::vector<double> transfrom_xyz(double radian_x, double radian_y, double height_min){
std::vector<double>
transfrom_xyz(double radian_x, double radian_y, double height_min){
double ellipsod_a = 40680631590769;
double ellipsod_b = 40680631590769;
double ellipsod_c = 40408299984661.4;
Expand Down Expand Up @@ -149,19 +133,17 @@ std::vector<double> 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<double> 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<double> matrix;
if (trans) {
matrix = transfrom_xyz(trans->radian_x,trans->radian_y,trans->min_height);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d3962d6

Please sign in to comment.