Used new tri strip function to generate road mesh
This commit is contained in:
parent
e20bb714b0
commit
d467bbb1da
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Upgraded to Unreal Engine 4.24
|
||||
* Fixed autonomous agents' incorrect detection of red traffic lights affecting them
|
||||
* Added walkable pedestrian crossings to OpenDRIVE standalone mode
|
||||
* Added walkable pedestrian crosswalks in OpenDRIVE standalone mode
|
||||
* Improved manual_control by adding realistic throttle and brake
|
||||
* Added new Behavior agent
|
||||
|
||||
|
|
|
@ -306,10 +306,6 @@ namespace geom {
|
|||
return *this;
|
||||
}
|
||||
|
||||
// Mesh operator+(Mesh &lhs, const Mesh &rhs) {
|
||||
// return lhs += rhs;
|
||||
// }
|
||||
|
||||
Mesh operator+(const Mesh &lhs, const Mesh &rhs) {
|
||||
Mesh m = lhs;
|
||||
return m += rhs;
|
||||
|
|
|
@ -134,7 +134,6 @@ namespace geom {
|
|||
|
||||
/// Merges two meshes into a single mesh
|
||||
Mesh &operator+=(const Mesh &rhs);
|
||||
Mesh &operator+(const Mesh &rhs);
|
||||
|
||||
friend Mesh operator+(const Mesh &lhs, const Mesh &rhs);
|
||||
|
||||
|
@ -153,18 +152,6 @@ namespace geom {
|
|||
std::vector<uv_type> _uvs;
|
||||
|
||||
std::vector<material_type> _materials;
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
// Location(const FVector &vector) // from centimeters to meters.
|
||||
// : Location(1e-2f * vector.X, 1e-2f * vector.Y, 1e-2f * vector.Z) {}
|
||||
|
||||
// operator FVector() const {
|
||||
// return FVector{1e2f * x, 1e2f * y, 1e2f * z}; // from meters to centimeters.
|
||||
// }
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
};
|
||||
|
||||
} // namespace geom
|
||||
|
|
|
@ -941,34 +941,6 @@ namespace road {
|
|||
return _data.GetJunction(id);
|
||||
}
|
||||
|
||||
static void ExtrudeMeshEdge(
|
||||
geom::Mesh &mesh,
|
||||
geom::Vector3D new_vertex1,
|
||||
geom::Vector3D new_vertex2,
|
||||
size_t connection_index_1,
|
||||
size_t connection_index_2) {
|
||||
// Add the vertices
|
||||
mesh.AddVertex(new_vertex1);
|
||||
mesh.AddVertex(new_vertex2);
|
||||
|
||||
// Find the indexes
|
||||
const size_t last_index = mesh.GetLastVertexIndex();
|
||||
const size_t bottom_left_index = connection_index_1; // local quad index: 1
|
||||
const size_t bottom_right_index = connection_index_2; // local quad index: 2
|
||||
const size_t top_left_index = last_index - 1; // local quad index: 3
|
||||
const size_t top_right_index = last_index; // local quad index: 4
|
||||
|
||||
// Vertex order is counter clockwise:
|
||||
// First triangle: 1 -> 2 -> 4
|
||||
mesh.AddIndex(bottom_left_index); // local quad index: 1
|
||||
mesh.AddIndex(bottom_right_index); // local quad index: 2
|
||||
mesh.AddIndex(top_right_index); // local quad index: 4
|
||||
// Second triangle: 1 -> 4 -> 3
|
||||
mesh.AddIndex(bottom_left_index); // local quad index: 1
|
||||
mesh.AddIndex(top_right_index); // local quad index: 4
|
||||
mesh.AddIndex(top_left_index); // local quad index: 3
|
||||
}
|
||||
|
||||
/// Computes the location of the edges of the current lane at the current waypoint
|
||||
static std::pair<geom::Vector3D, geom::Vector3D> GetWaypointCornerPositions(
|
||||
const Map &map, const Waypoint &waypoint, const Lane &lane) {
|
||||
|
@ -1016,42 +988,29 @@ namespace road {
|
|||
lane.GetId(),
|
||||
lane_section.GetDistance() + EPSILON };
|
||||
|
||||
if (lane.GetType() == Lane::LaneType::Sidewalk) {
|
||||
out_mesh.AddMaterial("sidewalk");
|
||||
} else {
|
||||
out_mesh.AddMaterial("road");
|
||||
}
|
||||
// Iterate over the lane distance and store the vertices based on it's width
|
||||
std::vector<geom::Vector3D> vertices;
|
||||
do {
|
||||
// Get the location of the edges of the current lane at the current waypoint
|
||||
const auto edges = GetWaypointCornerPositions(*this, current_wp, lane);
|
||||
vertices.push_back(edges.first);
|
||||
vertices.push_back(edges.second);
|
||||
|
||||
std::pair<geom::Vector3D, geom::Vector3D> edges;
|
||||
if (!IsLaneStraight(lane)) {
|
||||
do {
|
||||
// Get the location of the edges of the current lane at the current waypoint
|
||||
edges = GetWaypointCornerPositions(*this, current_wp, lane);
|
||||
if (out_mesh.GetVerticesNum() < 2) {
|
||||
// Add 2 first vertices only
|
||||
out_mesh.AddVertex(edges.first);
|
||||
out_mesh.AddVertex(edges.second);
|
||||
} else {
|
||||
// Extrude adding vertices and joining the using indices
|
||||
const size_t last_index = out_mesh.GetLastVertexIndex();
|
||||
ExtrudeMeshEdge(
|
||||
out_mesh, edges.first, edges.second, last_index - 1, last_index);
|
||||
}
|
||||
// Update the current waypoint's "s"
|
||||
current_wp.s += distance;
|
||||
} while(current_wp.s < end_distance);
|
||||
|
||||
// Update the current waypoint's "s"
|
||||
current_wp.s += distance;
|
||||
|
||||
} while(current_wp.s < end_distance);
|
||||
}
|
||||
// This ensures the mesh is constant and have no gaps between
|
||||
// segments and roads
|
||||
// This ensures the mesh is constant and have no gaps between roads
|
||||
if (end_distance - (current_wp.s - distance) > EPSILON) {
|
||||
current_wp.s = end_distance;
|
||||
edges = GetWaypointCornerPositions(*this, current_wp, lane);
|
||||
const size_t last_index = out_mesh.GetLastVertexIndex();
|
||||
ExtrudeMeshEdge(
|
||||
out_mesh, edges.first, edges.second, last_index - 1, last_index);
|
||||
const auto edges = GetWaypointCornerPositions(*this, current_wp, lane);
|
||||
vertices.push_back(edges.first);
|
||||
vertices.push_back(edges.second);
|
||||
}
|
||||
// Add the adient material, create the strip and close the material
|
||||
out_mesh.AddMaterial(
|
||||
lane.GetType() == Lane::LaneType::Sidewalk ? "sidewalk" : "road");
|
||||
out_mesh.AddTriangleStrip(vertices);
|
||||
out_mesh.EndMaterial();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,15 +20,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
// TODO delete this
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
namespace carla {
|
||||
namespace road {
|
||||
|
||||
|
@ -43,17 +34,6 @@ namespace road {
|
|||
|
||||
Map(MapData m) : _data(std::move(m)) {
|
||||
CreateRtree();
|
||||
// todo: delete -----------
|
||||
// | | | |
|
||||
// v v v v
|
||||
|
||||
std::ofstream out_road("road.obj");
|
||||
out_road << GenerateMesh(2).GenerateOBJForRecast();
|
||||
out_road.close();
|
||||
|
||||
std::ofstream out_cross("cross.obj");
|
||||
out_cross << GetAllCrosswalkMesh().GenerateOBJForRecast();
|
||||
out_cross.close();
|
||||
}
|
||||
|
||||
/// ========================================================================
|
||||
|
|
Loading…
Reference in New Issue