Generation of procedural model for wipe tower reverted to old implementation, as the raycasted picking does not require it to be watertight anymore

This commit is contained in:
enricoturri1966 2023-03-08 09:21:59 +01:00
parent 6734ad6c3c
commit 54ea675473

View File

@ -511,202 +511,38 @@ int GLVolumeCollection::load_wipe_tower_preview(
// We'll now create the box with jagged edge. y-coordinates of the pre-generated model
// are shifted so that the front edge has y=0 and centerline of the back edge has y=depth:
// We split the box in three main pieces,
// the two laterals are identical and the central is the one containing the jagged geometry
// lateral parts generator
auto generate_lateral = [&](float min_x, float max_x) {
const std::vector<Vec3f> vertices = {
{ min_x, -(depth + brim_width), 0.0f },
{ max_x, -(depth + brim_width), 0.0f },
{ min_x, -(depth + brim_width), scaled_brim_height },
{ max_x, -(depth + brim_width), scaled_brim_height },
{ min_x, -depth, scaled_brim_height },
{ max_x, -depth, scaled_brim_height },
{ min_x, -depth, 1.0f },
{ max_x, -depth, 1.0f },
{ min_x, 0.0f, 1.0f },
{ max_x, 0.0f, 1.0f },
{ min_x, 0.0f, scaled_brim_height },
{ max_x, 0.0f, scaled_brim_height },
{ min_x, brim_width, scaled_brim_height },
{ max_x, brim_width, scaled_brim_height },
{ min_x, brim_width, 0.0f },
{ max_x, brim_width, 0.0f }
};
const std::vector<Vec3i> triangles = {
{ 0, 1, 3 }, { 0, 3, 2 }, { 2, 3, 5 }, { 2, 5, 4 }, { 4, 5, 7 }, { 4, 7, 6 }, { 6, 7, 9 }, { 6, 9, 8 },
{ 8, 9, 11 }, { 8, 11, 10 }, { 10, 11, 13 }, { 10, 13, 12 }, { 12, 13, 15 }, { 12, 15, 14 }, { 14, 15, 1 }, { 14, 1, 0 }
};
indexed_triangle_set its;
its.vertices.reserve(vertices.size());
for (const Vec3f& v : vertices) {
its.vertices.emplace_back(v.x(), v.y() + depth, v.z());
}
its.indices.reserve(triangles.size());
for (const Vec3i& t : triangles) {
its.indices.emplace_back(t);
}
return its;
};
// central parts generator
auto generate_central = [&]() {
const std::vector<Vec3f> vertices = {
// this part is not watertight to avoid to have different geometries for the cases
// brim_width < 10.0
// brim_width == 10.0
// brim_width > 10.0
{ 38.453f, -(depth + brim_width), 0.0f },
{ 61.547f, -(depth + brim_width), 0.0f },
{ 38.453f, -(depth + brim_width), scaled_brim_height },
{ 61.547f, -(depth + brim_width), scaled_brim_height },
{ 38.453f, -depth, scaled_brim_height },
{ 61.547f, -depth, scaled_brim_height },
{ 38.453f, -depth, 1.0f },
{ 61.547f, -depth, 1.0f },
{ 38.453f, 0.0f, 1.0f },
{ 44.2265f, 10.0f, 1.0f },
{ 50.0f, 0.0f, 1.0f },
{ 55.7735f, -10.0f, 1.0f },
{ 61.547f, 0.0f, 1.0f },
{ 38.453f, 0.0f, scaled_brim_height },
{ 44.2265f, 10.0f, scaled_brim_height },
{ 50.0f, 0.0f, scaled_brim_height },
{ 55.7735f, -10.0f, scaled_brim_height },
{ 61.547f, 0.0f, scaled_brim_height },
{ 38.453f, 0.0f, 0.0f },
{ 44.2265f, 10.0f, 0.0f },
{ 50.0f, 0.0f, 0.0f },
{ 55.7735f, -10.0f, 0.0f },
{ 61.547f, 0.0f, 0.0f },
{ 38.453f, brim_width, scaled_brim_height },
{ 61.547f, brim_width, scaled_brim_height },
{ 38.453f, brim_width, 0.0f },
{ 61.547f, brim_width, 0.0f },
};
const std::vector<Vec3i> triangles = {
{ 0, 1, 3 }, { 0, 3, 2 }, { 2, 3, 5 }, { 2, 5, 4 }, { 4, 5, 7 }, { 4, 7, 6 },
{ 6, 7, 11 }, { 6, 11, 10 }, { 6, 10, 8 }, { 8, 10, 9 }, { 11, 7, 12 }, { 14, 13, 8 },
{ 14, 8, 9 }, { 19, 18, 13 }, { 19, 13, 14 }, { 15, 14, 9 }, { 15, 9, 10 }, { 20, 19, 14 },
{ 20, 14, 15 }, { 16, 15, 10 }, { 16, 10, 11 }, { 21, 20, 15 }, { 21, 15, 16 }, { 17, 16, 11 },
{ 17, 11, 12 }, { 22, 21, 16 }, { 22, 16, 17 }, { 15, 16, 17 }, { 13, 15, 23 }, { 15, 17, 24 },
{ 15, 24, 23 }, { 26, 25, 23 }, { 26, 23, 24 }, { 0, 25, 1 }, { 1, 25, 26 }, { 20, 18, 19 }
};
indexed_triangle_set its;
its.vertices.reserve(vertices.size());
for (const Vec3f& v : vertices) {
its.vertices.emplace_back(v.x(), v.y() + depth, v.z());
}
its.indices.reserve(triangles.size());
for (const Vec3i& t : triangles) {
its.indices.emplace_back(t);
}
return its;
};
TriangleMesh tooth_mesh;
indexed_triangle_set data = generate_lateral(0.0f, 38.453f);
tooth_mesh.merge(TriangleMesh(std::move(data)));
data = generate_central();
tooth_mesh.merge(TriangleMesh(std::move(data)));
data = generate_lateral(61.547f, 100.0f);
tooth_mesh.merge(TriangleMesh(std::move(data)));
float out_points_idx[][3] = { { 0, -depth, 0 }, { 0, 0, 0 }, { 38.453f, 0, 0 }, { 61.547f, 0, 0 }, { 100.0f, 0, 0 }, { 100.0f, -depth, 0 }, { 55.7735f, -10.0f, 0 }, { 44.2265f, 10.0f, 0 },
{ 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } };
static constexpr const int out_facets_idx[][3] = {
{ 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 },
{ 8, 10, 14 }, { 3, 12, 4 }, { 3, 13, 12 }, { 6, 13, 3 }, { 6, 14, 13 }, { 7, 14, 6 }, { 7, 15, 14 }, { 2, 15, 7 }, { 2, 8, 15 }, { 1, 8, 2 }, { 1, 9, 8 },
{ 0, 9, 1 }, { 0, 10, 9 }, { 5, 10, 0 }, { 5, 11, 10 }, { 4, 11, 5 }, { 4, 12, 11 } };
indexed_triangle_set its;
for (int i = 0; i < 16; ++i)
its.vertices.emplace_back(out_points_idx[i][0] / (100.f / min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]);
its.indices.reserve(28);
for (const int* face : out_facets_idx)
its.indices.emplace_back(face);
TriangleMesh tooth_mesh(std::move(its));
// We have the mesh ready. It has one tooth and width of min_width. We will now
// append several of these together until we are close to the required width
// of the block. Than we can scale it precisely.
const size_t n = std::max(1, int(width / min_width)); // How many shall be merged?
size_t n = std::max(1, int(width / min_width)); // How many shall be merged?
for (size_t i = 0; i < n; ++i) {
mesh.merge(tooth_mesh);
tooth_mesh.translate(100.0f, 0.0f, 0.0f);
tooth_mesh.translate(min_width, 0.f, 0.f);
}
// Now we add the caps along the X axis
const float scaled_brim_width_x = brim_width * n * width / min_width;
auto generate_negx_cap = [&]() {
const std::vector<Vec3f> vertices = {
{ -scaled_brim_width_x, -(depth + brim_width), 0.0f },
{ 0.0f, -(depth + brim_width), 0.0f },
{ -scaled_brim_width_x, -(depth + brim_width), scaled_brim_height },
{ 0.0f, -(depth + brim_width), scaled_brim_height },
{ 0.0f, -depth, scaled_brim_height },
{ 0.0f, -depth, 1.0f },
{ 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, scaled_brim_height },
{ 0.0f, brim_width, scaled_brim_height },
{ -scaled_brim_width_x, brim_width, scaled_brim_height },
{ 0.0f, brim_width, 0.0f },
{ -scaled_brim_width_x, brim_width, 0.0f }
};
const std::vector<Vec3i> triangles = {
{ 0, 1, 3 }, { 0, 3, 2 }, { 2, 3, 4 }, { 2, 4, 9 }, { 9, 4, 7 }, { 9, 7, 8 }, { 9, 8, 10 }, { 9, 10, 11 },
{ 11, 10, 1 }, { 11, 1, 0 }, { 11, 0, 2 }, { 11, 2, 9 }, { 7, 4, 5 }, { 7, 5, 6 }
};
indexed_triangle_set its;
its.vertices.reserve(vertices.size());
for (const Vec3f& v : vertices) {
its.vertices.emplace_back(v.x(), v.y() + depth, v.z());
}
its.indices.reserve(triangles.size());
for (const Vec3i& t : triangles) {
its.indices.emplace_back(t);
}
return its;
};
auto generate_posx_cap = [&]() {
const float posx_cap_x = n * 100.0f;
const std::vector<Vec3f> vertices = {
{ posx_cap_x, -(depth + brim_width), 0.0f },
{ posx_cap_x + scaled_brim_width_x, -(depth + brim_width), 0.0f },
{ posx_cap_x, -(depth + brim_width), scaled_brim_height },
{ posx_cap_x + scaled_brim_width_x, -(depth + brim_width), scaled_brim_height },
{ posx_cap_x, -depth, scaled_brim_height },
{ posx_cap_x, -depth, 1.0f },
{ posx_cap_x, 0.0f, 1.0f },
{ posx_cap_x, 0.0f, scaled_brim_height },
{ posx_cap_x, brim_width, scaled_brim_height },
{ posx_cap_x + scaled_brim_width_x, brim_width, scaled_brim_height },
{ posx_cap_x, brim_width, 0.0f },
{ posx_cap_x + scaled_brim_width_x, brim_width, 0.0f }
};
const std::vector<Vec3i> triangles = {
{ 0, 1, 3 }, { 0, 3, 2 }, { 2, 3, 4 }, { 4, 3, 9 }, { 4, 9, 7 }, { 7, 9, 8 }, { 8, 9, 11 }, { 8, 11, 10 },
{ 10, 11, 1 }, { 10, 1, 0 }, { 1, 11, 9 }, { 1, 9, 3 }, { 4, 7, 6 }, { 4, 6, 5 }
};
indexed_triangle_set its;
its.vertices.reserve(vertices.size());
for (const Vec3f& v : vertices) {
its.vertices.emplace_back(v.x(), v.y() + depth, v.z());
}
its.indices.reserve(triangles.size());
for (const Vec3i& t : triangles) {
its.indices.emplace_back(t);
}
return its;
};
data = generate_negx_cap();
mesh.merge(TriangleMesh(std::move(data)));
data = generate_posx_cap();
mesh.merge(TriangleMesh(std::move(data)));
mesh.scale(Vec3f(width / (n * 100.0f), 1.0f, height)); // Scaling to proper width
}
else {
mesh = make_cube(width, depth, height - brim_height);
mesh.translate(0.0f, 0.0f, brim_height);
TriangleMesh brim_mesh = make_cube(width + 2.0f * brim_width, depth + 2.0f * brim_width, brim_height);
brim_mesh.translate(-brim_width, -brim_width, 0.0f);
mesh.merge(brim_mesh);
mesh.scale(Vec3f(width / (n * min_width), 1.f, height)); // Scaling to proper width
}
else
mesh = make_cube(width, depth, height);
// We'll make another mesh to show the brim (fixed layer height):
TriangleMesh brim_mesh = make_cube(width + 2.f * brim_width, depth + 2.f * brim_width, 0.2f);
brim_mesh.translate(-brim_width, -brim_width, 0.f);
mesh.merge(brim_mesh);
volumes.emplace_back(new GLVolume(color));
GLVolume& v = *volumes.back();