commit 217bd74802d801bd4551002968181e617008ad81
parent 3a5ba799710c3b7da936dcf2f20d74759bdafa6f
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Thu, 26 Jan 2023 11:26:07 +0100
Improvement of the ground in order to obtain separately the top, the bottom and the lateral sides
Diffstat:
3 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/src/cg_city.c b/src/cg_city.c
@@ -210,7 +210,7 @@ city_ground_build(struct city* city)
ERR(building->functors->build_footprint(building, city->allocator,
city->logger, footprint));
}
- ERR(ground_build_cad(city, &ground));
+ ERR(ground_build_cad(city->allocator, city, &ground));
ERR(scad_scene_mesh());
ERR(ground_export_stl(&ground, city->binary_export));
diff --git a/src/cg_ground.c b/src/cg_ground.c
@@ -26,13 +26,18 @@
res_T
ground_build_cad
- (struct city* city,
+ (struct mem_allocator* allocator,
+ struct city* city,
struct ground* ground)
{
res_T res = RES_OK;
double origin[3];
double extent[3];
struct scad_geometry* bound = NULL;
+ struct scad_geometry** list = NULL;
+ struct scad_geometry* surface = NULL;
+ size_t i, count = 0;
+
if (!city || !ground) {
res = RES_BAD_ARG;
@@ -55,10 +60,54 @@ ground_build_cad
ERR(scad_add_box(NULL, origin, extent, &ground->box));
ERR(scad_geometry_boundary(NULL, &ground->box, 1, &bound));
- ERR(scad_cut_geometries(NULL, &bound, 1,
- ground->footprints, ground->footprints_count, &ground->boundary));
+ ERR(scad_geometry_explode(bound, NULL, &list, &count));
+
+ ground->boundary = MEM_CALLOC(allocator, 6, sizeof(struct scad_geometry*));
+
+ for (i = 0; i < count; i++){
+ double center[3];
+ size_t center_n;
+ double N[3];
+
+ ERR(scad_geometry_get_count(list[i], ¢er_n));
+ ASSERT(center_n == 1);
+ ERR(scad_geometry_get_centerofmass(list[i], center));
+
+ ERR(scad_geometry_normal(list[i], center, N, NULL, &surface));
+
+ if (N[0] == 0 && N[1] == 0 && N[2] == -1) {
+ ERR(scad_geometry_copy(surface, "B_ground_bottom", &ground->boundary[0]));
+ }
+
+ if (N[0] == 0 && N[1] == 0 && N[2] == 1) {
+ ERR(scad_cut_geometries("B_ground_top", &surface, 1,
+ ground->footprints, ground->footprints_count, &ground->boundary[1]));
+ }
+
+ if (N[0] == -1 && N[1] == 0 && N[2] == 0) {
+ ERR(scad_geometry_copy(surface, "B_ground_lateral_0", &ground->boundary[2]));
+ }
+
+ if (N[0] == 1 && N[1] == 0 && N[2] == 0) {
+ ERR(scad_geometry_copy(surface, "B_ground_lateral_1", &ground->boundary[3]));
+ }
+
+ if (N[0] == 0 && N[1] == -1 && N[2] == 0) {
+ ERR(scad_geometry_copy(surface, "B_ground_lateral_2", &ground->boundary[4]));
+ }
+
+ if (N[0] == 0 && N[1] == 1 && N[2] == 0) {
+ ERR(scad_geometry_copy(surface, "B_ground_lateral_3", &ground->boundary[5]));
+ }
+ }
+
exit:
+ for (i = 0; i < count; i++) {
+ scad_geometry_delete(list[i]);
+ }
+ if (surface) scad_geometry_delete(surface);
+ MEM_RM(allocator, list);
if (bound) SCAD(geometry_delete(bound));
return res;
error:
@@ -69,9 +118,12 @@ res_T
ground_export_stl(const struct ground* ground, const int binary)
{
res_T res = RES_OK;
+ size_t i = 0;
- ERR(scad_stl_export(ground->boundary, "B_ground", 0, binary));
- ERR(scad_stl_export_split(ground->boundary, "B_ground", binary));
+ for(i = 0; i < 6; i++) {
+ ERR(scad_stl_export(ground->boundary[i], NULL, 0, binary));
+ }
+ /*ERR(scad_stl_export_split(ground->boundary, "B_ground", binary));*/
exit:
return res;
@@ -112,7 +164,11 @@ ground_clear
{
size_t i;
SCAD(geometry_delete(ground->box));
- SCAD(geometry_delete(ground->boundary));
+ for(i = 0; i < 6; i++) {
+ SCAD(geometry_delete(ground->boundary[i]));
+ }
+ MEM_RM(allocator, ground->boundary);
+
for(i = 0; i < ground->footprints_count; i++) {
SCAD(geometry_delete(ground->footprints[i]));
}
diff --git a/src/cg_ground.h b/src/cg_ground.h
@@ -30,7 +30,7 @@ struct logger;
struct ground {
/* cad representation */
struct scad_geometry* box;
- struct scad_geometry* boundary;
+ struct scad_geometry** boundary;
struct scad_geometry** footprints; /* list of building footprint */
size_t footprints_count; /* number of footprint */
};
@@ -40,7 +40,8 @@ static const struct ground GROUND_NULL = GROUND_NULL__;
res_T
ground_build_cad
- (struct city* city,
+ (struct mem_allocator* allocator,
+ struct city* city,
struct ground* ground);
res_T