solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit bd368905dbc32a16cc87b5a7ea97b6827aad882d
parent eed4cbe9fe79f7947d3b993b7e2e2fad93f69830
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 20 Feb 2017 15:02:43 +0100

Add accessors to the geometry data of a ssol_shape

Diffstat:
Msrc/ssol.h | 23+++++++++++++++++++++++
Msrc/ssol_object.c | 12+++++-------
Msrc/ssol_shape.c | 52+++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/src/ssol.h b/src/ssol.h @@ -483,6 +483,29 @@ SSOL_API res_T ssol_shape_ref_put (struct ssol_shape* shape); +SSOL_API res_T +ssol_shape_get_vertices_count + (const struct ssol_shape* shape, + unsigned* nverts); + +SSOL_API res_T +ssol_shape_get_vertex_attrib + (const struct ssol_shape* shape, + const unsigned ivert, + const enum ssol_attrib_usage usage, + double value[]); + +SSOL_API res_T +ssol_shape_get_triangles_count + (const struct ssol_shape* shape, + unsigned* ntris); + +SSOL_API res_T +ssol_shape_get_triangle_indices + (const struct ssol_shape* shape, + const unsigned itri, + unsigned ids[3]); + /* Define a punched surface in local space, i.e. no translation & no orientation */ SSOL_API res_T ssol_punched_surface_setup diff --git a/src/ssol_object.c b/src/ssol_object.c @@ -111,7 +111,7 @@ ssol_object_add_shaded_shape struct ssol_material* front, struct ssol_material* back) { - enum { + enum { ATTACH_S3D_RT, ATTACH_S3D_SAMP, REGISTER_RT, REGISTER_SAMP, REGISTER_SHAPE }; struct shaded_shape* shaded_shape; @@ -209,7 +209,7 @@ ssol_object_clear(struct ssol_object* obj) darray_shaded_shape_clear(&obj->shaded_shapes); htable_shaded_shape_clear(&obj->shaded_shapes_rt); htable_shaded_shape_clear(&obj->shaded_shapes_samp); - + obj->scn_rt_area = 0; S3D(scene_clear(obj->scn_rt)); @@ -219,12 +219,11 @@ ssol_object_clear(struct ssol_object* obj) } res_T -ssol_object_get_area -(const struct ssol_object* object, - double* area) +ssol_object_get_area(const struct ssol_object* object, double* area) { if (!object || !area) return RES_BAD_ARG;; /* the area of the 3D surface */ *area = object->scn_rt_area; return RES_OK; -} -\ No newline at end of file +} + diff --git a/src/ssol_shape.c b/src/ssol_shape.c @@ -426,7 +426,7 @@ mesh_compute_area unsigned itri; double area = 0; (void)nverts; - + FOR_EACH(itri, 0, ntris) { float v0[3], v1[3], v2[3]; double E0[3], E1[3], N[3]; @@ -961,6 +961,56 @@ ssol_shape_ref_put(struct ssol_shape* shape) } res_T +ssol_shape_get_vertices_count + (const struct ssol_shape* shape, unsigned* nverts) +{ + if(!shape || !nverts) return RES_BAD_ARG; + return s3d_mesh_get_vertices_count(shape->shape_rt, nverts); +} + +res_T +ssol_shape_get_vertex_attrib + (const struct ssol_shape* shape, + const unsigned ivert, + const enum ssol_attrib_usage usage, + double value[]) +{ + struct s3d_attrib s3d_attr; + enum s3d_attrib_usage s3d_usage; + res_T res = RES_OK; + + if(!shape || (unsigned)usage >= SSOL_ATTRIBS_COUNT__) return RES_BAD_ARG; + s3d_usage = ssol_to_s3d_attrib_usage(usage); + + res = s3d_mesh_get_vertex_attrib(shape->shape_rt, ivert, s3d_usage, &s3d_attr); + if(res != RES_OK) return res; + + switch(s3d_attr.type) { + case S3D_FLOAT3: value[2] = (double)s3d_attr.value[2]; + case S3D_FLOAT2: value[1] = (double)s3d_attr.value[1]; + case S3D_FLOAT: value[0] = (double)s3d_attr.value[0]; + break; + default: FATAL("Unexpected vertex attrib type\n"); break; + } + return RES_OK; +} + +res_T +ssol_shape_get_triangles_count(const struct ssol_shape* shape, unsigned* ntris) +{ + if(!shape || !ntris) return RES_BAD_ARG; + return s3d_mesh_get_triangles_count(shape->shape_rt, ntris); +} + +res_T +ssol_shape_get_triangle_indices + (const struct ssol_shape* shape, const unsigned itri, unsigned ids[3]) +{ + if(!shape || !ids) return RES_BAD_ARG; + return s3d_mesh_get_triangle_indices(shape->shape_rt, itri, ids); +} + +res_T ssol_punched_surface_setup (struct ssol_shape* shape, const struct ssol_punched_surface* psurf)