Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cesium 3dTtiles generation #225

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ nbactions.xml
nbbuild.xml
nb-configuration.xml

# Vscode
.vscode/

# Miscellaneous
*~
*.swp
*.tileset.json
.DS_Store
33 changes: 33 additions & 0 deletions build-adds/tiles-to-glb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Usage ./tiles-to-glb.sh /path/to/tiles

BASE_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
BIN="java -jar $BASE_DIR/target/osm2world-0.4.0-SNAPSHOT.jar"

TILES_ROOT=${1%/}

echo "Convert tiles from $TILES_ROOT"
echo $BASE_DIR

mkdir -p "$TILES_ROOT/tiles"

for tile_p in $(find $TILES_ROOT -iname '*.osm'); do
#cut prefix
tile_sfx=${tile_p#"$TILES_ROOT/"}
#cut suffix
tile=${tile_sfx%".osm"}

z=${tile%%/*}
xy=${tile#*/}
x=${xy%%/*}
y=${xy#*/}

if [ -f "$TILES_ROOT/$z/$x/$y.osm" ]; then
echo $tile $z $x $y

cmd="$BIN --input $TILES_ROOT/$z/$x/$y.osm --tile $z/$x/$y --output $TILES_ROOT/tiles/${z}_${x}_${y}.glb"
$cmd > /dev/null 2>&1
fi

done
826 changes: 826 additions & 0 deletions src/main/java/org/cesiumjs/LICENSE.md

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions src/main/java/org/cesiumjs/WGS84Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.cesiumjs;

import org.osm2world.core.map_data.creation.LatLon;
import org.osm2world.core.math.VectorXYZ;

/**
* This code is adoptation of Cesiumjs code.
* See LICENSE.md
* */
public class WGS84Util {

private static final double WGS84_A = 6378137.0;
private static final double WGS84_B = 6356752.3142451793;

private static final VectorXYZ oneOverRadiiSquared = new VectorXYZ(
1.0 / (WGS84_A * WGS84_A),
1.0 / (WGS84_A * WGS84_A),
1.0 / (WGS84_B * WGS84_B));

private static final VectorXYZ wgs84RadiiSquared =
new VectorXYZ(WGS84_A * WGS84_A, WGS84_A * WGS84_A, WGS84_B * WGS84_B);

public static VectorXYZ cartesianFromLatLon(LatLon origin, double height) {
double latitude = Math.toRadians(origin.lat);
double longitude = Math.toRadians(origin.lon);
VectorXYZ radiiSquared = wgs84RadiiSquared;

double cosLatitude = Math.cos(latitude);
VectorXYZ scratchN = new VectorXYZ(
cosLatitude * Math.cos(longitude),
cosLatitude * Math.sin(longitude),
Math.sin(latitude));

scratchN = scratchN.normalize();

VectorXYZ scratchK = mulByComponents(radiiSquared, scratchN);
double gamma = Math.sqrt(scratchN.dot(scratchK));
scratchK = scratchK.mult(1.0 / gamma);
scratchN = scratchN.mult(height);

return scratchK.add(scratchN);
}

public static double[] eastNorthUpToFixedFrame(VectorXYZ cartesian) {

VectorXYZ normal = geodeticSurfaceNormal(cartesian);
VectorXYZ tangent = new VectorXYZ(-cartesian.y, cartesian.x, 0.0).normalize();
VectorXYZ bitangent = normal.cross(tangent);

// Matrix 4x4 by columns
return new double[] {
tangent.x,
tangent.y,
tangent.z,
0.0,
bitangent.x,
bitangent.y,
bitangent.z,
0.0,
normal.x,
normal.y,
normal.z,
0.0,
cartesian.x,
cartesian.y,
cartesian.z,
1.0
};
}

public static VectorXYZ geodeticSurfaceNormal(VectorXYZ cartesian) {
VectorXYZ mulByComponents = mulByComponents(cartesian, oneOverRadiiSquared);
return mulByComponents.normalize();
}

public static VectorXYZ mulByComponents(VectorXYZ a, VectorXYZ b) {
return new VectorXYZ(a.x * b.x, a.y * b.y, a.z * b.z);
}

}
27 changes: 19 additions & 8 deletions src/main/java/org/osm2world/console/Output.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.osm2world.console;

import static java.time.Instant.now;
import static java.util.Collections.singletonList;
import static java.util.Map.entry;
import static java.util.stream.Collectors.toList;
import static java.time.Instant.*;
import static java.util.Collections.*;
import static java.util.Map.*;
import static java.util.stream.Collectors.*;
import static org.osm2world.core.ConversionFacade.Phase.*;
import static org.osm2world.core.math.AxisAlignedRectangleXZ.bbox;
import static org.osm2world.core.math.AxisAlignedRectangleXZ.*;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -32,10 +32,21 @@
import org.osm2world.core.map_data.creation.LatLonBounds;
import org.osm2world.core.map_data.creation.MapProjection;
import org.osm2world.core.map_data.data.MapMetadata;
import org.osm2world.core.map_elevation.creation.*;
import org.osm2world.core.map_elevation.creation.BridgeTunnelEleCalculator;
import org.osm2world.core.map_elevation.creation.ConstraintEleCalculator;
import org.osm2world.core.map_elevation.creation.EleTagEleCalculator;
import org.osm2world.core.map_elevation.creation.LeastSquaresInterpolator;
import org.osm2world.core.map_elevation.creation.NaturalNeighborInterpolator;
import org.osm2world.core.map_elevation.creation.NoOpEleCalculator;
import org.osm2world.core.map_elevation.creation.SimpleEleConstraintEnforcer;
import org.osm2world.core.map_elevation.creation.ZeroInterpolator;
import org.osm2world.core.math.AxisAlignedRectangleXZ;
import org.osm2world.core.math.VectorXYZ;
import org.osm2world.core.osm.creation.*;
import org.osm2world.core.osm.creation.GeodeskReader;
import org.osm2world.core.osm.creation.MbtilesReader;
import org.osm2world.core.osm.creation.OSMDataReader;
import org.osm2world.core.osm.creation.OSMFileReader;
import org.osm2world.core.osm.creation.OverpassReader;
import org.osm2world.core.target.TargetUtil;
import org.osm2world.core.target.TargetUtil.Compression;
import org.osm2world.core.target.common.rendering.Camera;
Expand Down Expand Up @@ -230,7 +241,7 @@ public static void output(Configuration config,
? GltfTarget.GltfFlavor.GLB : GltfTarget.GltfFlavor.GLTF;
Compression compression = EnumSet.of(OutputMode.GLTF_GZ, OutputMode.GLB_GZ).contains(outputMode)
? Compression.GZ : Compression.NONE;
GltfTarget gltfTarget = new GltfTarget(outputFile, gltfFlavor, compression, bounds);
GltfTarget gltfTarget = new GltfTarget(outputFile, gltfFlavor, compression, results.getMapProjection(), bounds);
gltfTarget.setConfiguration(config);
boolean underground = config.getBoolean("renderUnderground", true);
TargetUtil.renderWorldObjects(gltfTarget, results.getMapData(), underground);
Expand Down
Loading