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

[WIP] Tangram 3D Hack #1875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions bench/src/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

using namespace Tangram;

std::vector<glm::vec2> line = {
{0.0, 0.0},
{1.0, 0.0},
{1.0, 1.0},
{0.0, 1.0},
std::vector<glm::vec3> line = {
{0.0, 0.0, 0.0},
{1.0, 0.0, 0.0},
{1.0, 1.0, 0.0},
{0.0, 1.0, 0.0},
};

struct PosNormEnormColVertex {
glm::vec2 pos;
glm::vec3 pos;
glm::vec2 texcoord;
glm::vec2 enorm;
GLfloat ewidth;
Expand All @@ -30,7 +30,7 @@ static void BM_Tangram_BuildButtMiterLine(benchmark::State& state) {
while(state.KeepRunning()) {
std::vector<PosNormEnormColVertex> vertices;
PolyLineBuilder builder {
[&](const glm::vec2& coord, const glm::vec2& normal, const glm::vec2& uv) {
[&](const glm::vec3& coord, const glm::vec2& normal, const glm::vec2& uv) {
vertices.push_back({ coord, uv, normal, 0.5f, 0xffffff, 0.f });
},
CapTypes::butt,
Expand All @@ -46,7 +46,7 @@ static void BM_Tangram_BuildRoundRoundLine(benchmark::State& state) {
while(state.KeepRunning()) {
std::vector<PosNormEnormColVertex> vertices;
PolyLineBuilder builder {
[&](const glm::vec2& coord, const glm::vec2& normal, const glm::vec2& uv) {
[&](const glm::vec3& coord, const glm::vec2& normal, const glm::vec2& uv) {
vertices.push_back({ coord, uv, normal, 0.5f, 0xffffff, 0.f });
},
CapTypes::round,
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/clientGeoJsonSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ struct add_geometry {

// Transform a geojsonvt::TilePoint into the corresponding Tangram::Point
Point transformPoint(geometry::point<int16_t> pt) {
return { pt.x / extent, 1. - pt.y / extent };
return { pt.x / extent, 1. - pt.y / extent, 0 };
}

Feature& feature;
Expand Down
1 change: 1 addition & 0 deletions core/src/data/formats/geoJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ std::shared_ptr<TileData> GeoJson::parseTile(const TileTask& _task, const MapPro
return Point {
(tmp.x - tileOrigin.x) * tileInverseScale,
(tmp.y - tileOrigin.y) * tileInverseScale,
0
};
};

Expand Down
1 change: 1 addition & 0 deletions core/src/data/formats/topoJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ std::shared_ptr<TileData> TopoJson::parseTile(const TileTask& _task, const MapPr
return Point {
(tmp.x - tileOrigin.x) * tileInverseScale,
(tmp.y - tileOrigin.y) * tileInverseScale,
0
};
};

Expand Down
10 changes: 5 additions & 5 deletions core/src/data/rasterSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ std::shared_ptr<TileData> RasterSource::parse(const TileTask& _task, const MapPr
Feature rasterFeature;
rasterFeature.geometryType = GeometryType::polygons;
rasterFeature.polygons = { { {
{0.0f, 0.0f},
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 1.0f},
{0.0f, 0.0f}
{0.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 0.0f},
{1.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f}
} } };
rasterFeature.props = Properties();

Expand Down
13 changes: 8 additions & 5 deletions core/src/data/tileData.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Tile Coordinates:

A point in the geometry of a tile is represented with 32-bit floating point
x and y coordinates. Coordinates represent normalized displacement from
x, y, and z coordinates. Coordinates represent normalized displacement from
the origin (i.e. lower-left corner) of a tile.

(0.0, 1.0) ---------- (1.0, 1.0)
Expand All @@ -25,6 +25,8 @@ Tile Coordinates:
servers may choose not to clip certain geometries to tile boundaries, but these
points are clipped in the client-side geometry processing.

Z coordinates are expected to be normalized to the same scale as x, y coordinates.

Data heirarchy:

TileData is a heirarchical container of structs modeled after the geoJSON spec:
Expand All @@ -48,7 +50,8 @@ Data heirarchy:

A <Line> is a collection of <Point>s.

A <Point> is 2 32-bit floating point coordinates representing x and y.
A <Point> is 3 32-bit floating point coordinates representing x, y, and z
(in that order).

*/
namespace Tangram {
Expand All @@ -60,11 +63,11 @@ enum GeometryType {
polygons
};

using Point = glm::vec2;
typedef glm::vec3 Point;

using Line = std::vector<Point>;
typedef std::vector<Point> Line;

using Polygon = std::vector<Line>;
typedef std::vector<Line> Polygon;

struct Feature {
Feature() {}
Expand Down
4 changes: 2 additions & 2 deletions core/src/marker/markerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bool MarkerManager::setPolyline(MarkerID markerID, LngLat* coordinates, int coun
for (int i = 0; i < count; ++i) {
auto degrees = glm::dvec2(coordinates[i].longitude, coordinates[i].latitude);
auto meters = m_mapProjection->LonLatToMeters(degrees);
line.emplace_back((meters.x - origin.x) * scale, (meters.y - origin.y) * scale);
line.emplace_back((meters.x - origin.x) * scale, (meters.y - origin.y) * scale, 0.f);
}

// Update the feature data for the marker.
Expand Down Expand Up @@ -273,7 +273,7 @@ bool MarkerManager::setPolygon(MarkerID markerID, LngLat* coordinates, int* coun
for (int j = 0; j < count; ++j) {
auto degrees = glm::dvec2(ring[j].longitude, ring[j].latitude);
auto meters = m_mapProjection->LonLatToMeters(degrees);
line.emplace_back((meters.x - origin.x) * scale, (meters.y - origin.y) * scale);
line.emplace_back((meters.x - origin.x) * scale, (meters.y - origin.y) * scale, 0.f);
}
ring += count;
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/scene/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Scene::Scene(std::shared_ptr<const Platform> _platform, const Url& _url)
: id(s_serial++),
m_url(_url),
m_fontContext(std::make_shared<FontContext>(_platform)),
m_featureSelection(std::make_unique<FeatureSelection>()) {
m_featureSelection(std::make_unique<FeatureSelection>()),
m_platform(_platform) {

// For now we only have one projection..
// TODO how to share projection with view?
Expand All @@ -37,7 +38,8 @@ Scene::Scene(std::shared_ptr<const Platform> _platform, const Url& _url)
Scene::Scene(std::shared_ptr<const Platform> _platform, const std::string& _yaml, const Url& _url)
: id(s_serial++),
m_fontContext(std::make_shared<FontContext>(_platform)),
m_featureSelection(std::make_unique<FeatureSelection>()) {
m_featureSelection(std::make_unique<FeatureSelection>()),
m_platform(_platform) {

m_url = _url;
m_yaml = _yaml;
Expand Down
4 changes: 4 additions & 0 deletions core/src/scene/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class Scene {

std::vector<SceneError> errors;

std::shared_ptr<const Platform> platform() const { return m_platform; }

private:

// The URL from which this scene was loaded
Expand Down Expand Up @@ -203,6 +205,8 @@ class Scene {

float m_time = 0.0;

std::shared_ptr<const Platform> m_platform;

};

}
6 changes: 3 additions & 3 deletions core/src/style/pointStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void PointStyleBuilder::labelPointsPlacing(const Line& _line, const glm::vec4& _
}
break;
case LabelProperty::Placement::spaced: {
LineSampler<std::vector<glm::vec3>> sampler;
LineSampler<std::vector<Point>> sampler;

sampler.set(_line);

Expand All @@ -477,7 +477,7 @@ void PointStyleBuilder::labelPointsPlacing(const Line& _line, const glm::vec4& _
params.labelOptions.angle = RAD_TO_DEG * atan2(r.x, r.y);
}

addLabel({p.x, p.y}, _uvsQuad, _texture, params, _rule);
addLabel({p.x, p.y, 0.f}, _uvsQuad, _texture, params, _rule);

} while (sampler.advance(spacing, p, r));
}
Expand Down Expand Up @@ -555,7 +555,7 @@ bool PointStyleBuilder::addPolygon(const Polygon& _polygon, const Properties& _p
}
} else {
if (!_polygon.empty()) {
glm::vec2 c;
glm::vec3 c;
c = centroid(_polygon.front().begin(), _polygon.front().end());
addLabel(c, uvsQuad, texture, p, _rule);
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/style/polylineStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ void PolylineStyleBuilder<V>::buildLine(const Line& _line, const typename Parame
MeshData<V>& _mesh, GLuint selection) {

float zoom = m_overzoom2;
m_builder.addVertex = [&](const glm::vec2& coord, const glm::vec2& normal, const glm::vec2& uv) {
m_builder.addVertex = [&](const glm::vec3& coord, const glm::vec2& normal, const glm::vec2& uv) {
auto h = _att.height;
h.x += coord.z * position_scale;
_mesh.vertices.push_back({{ coord.x,coord.y }, normal, { uv.x, uv.y * zoom },
_att.width, _att.height, _att.color, selection});
_att.width, h, _att.color, selection});
};

Builders::buildPolyLine(_line, m_builder);
Expand Down
2 changes: 1 addition & 1 deletion core/src/style/textStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ bool TextStyleBuilder::addFeature(const Feature& _feat, const DrawRule& _rule) {
const auto& polygons = _feat.polygons;
for (const auto& polygon : polygons) {
if (!polygon.empty()) {
glm::vec2 c;
glm::vec3 c;
c = centroid(polygon.front().begin(), polygon.front().end());
addLabel(Label::Type::point, {{ c }}, params, attrib, _rule);
}
Expand Down
Loading