commit 2886ddccd7a53c5803b2f87908428361cf69ecc6
parent 74efa7138a6313b80a3771a4dbc5103f037aa7c8
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Mon, 18 Jul 2022 17:54:05 +0200
Add extrude function to create 3D geometry from surface primitive
Diffstat:
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/src/scad.h b/src/scad.h
@@ -278,6 +278,15 @@ scad_geometry_rotate
const double dir[3],
const double angle);
+ /* Extrude the geometry `geom' using a translation along (`dx', `dy',
+ * `dz').*/
+SCAD_API res_T
+scad_geometry_extrude
+ (const struct scad_geometry* geom,
+ const char* name, /* Can be NULL */
+ const double dxdydz[3],
+ struct scad_geometry** out_geometry);
+
/* Export the geometry `geom' to an STL file.
* If `prefix' is provided it is used to name the file (just adding .stl),
* otherwise the geometry name is used instead (and it is an error if neither
diff --git a/src/scad_geometry.c b/src/scad_geometry.c
@@ -766,6 +766,69 @@ error:
}
res_T
+scad_geometry_extrude
+ (const struct scad_geometry* geom,
+ const char* name,
+ const double dxdydz[3],
+ struct scad_geometry** out_geometry)
+{
+ int* tagout = NULL;
+ size_t tagoutn;
+ int* data;
+ size_t i, j, sz;
+ int* extrude_data = NULL;
+ size_t extrude_sz = 0;
+ int ierr = 0;
+ struct scad_geometry* extrude_geom = NULL;
+ res_T res = RES_OK;
+
+ if(!geom || !dxdydz){
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if(geom->scene->device->need_synchro) {
+ ERR(scad_device_synchronize(geom->scene->device));
+ }
+
+ sz = geom->gmsh_dimTags_n;
+ data = geom->gmsh_dimTags;
+ gmshModelOccExtrude(data, sz, SPLIT3(dxdydz), &tagout, &tagoutn,
+ NULL, 0, NULL, 0, 0 , &ierr);
+ geom->scene->device->need_synchro = 1;
+ ERR(gmsh_err_to_res_T(ierr));
+
+ ERR(scad_geometry_create(geom->scene, name, &extrude_geom));
+ /* keep only 3D entities */
+ /* TODO : NOT SURE OF THE CONCEPT */
+ for (i=0; i<tagoutn/2; ++i) {
+ if (tagout[2*i] == 3) extrude_sz += 2;
+ }
+ extrude_data = malloc(extrude_sz * sizeof(int));
+ j = 0;
+ for (i=0; i<tagoutn/2; ++i) {
+ if (tagout[2*i] == 3) {
+ extrude_data[2*j] = 3;
+ extrude_data[2*j+1] = tagout[2*i+1];
+ ++j;
+ }
+ }
+ extrude_geom->gmsh_dimTags_n = extrude_sz;
+ extrude_geom->gmsh_dimTags = extrude_data;
+
+exit:
+ if(out_geometry) *out_geometry = extrude_geom;
+ if (tagout) free(tagout);
+ return res;
+error:
+ if(extrude_geom) {
+ SCAD(geometry_release(extrude_geom));
+ extrude_geom = NULL;
+ }
+ goto exit;
+}
+
+res_T
scad_geometry_translate
(struct scad_geometry* geom,
const double dxdydz[3])