solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit 23a0f784333e50b0299ace85216a458a8c4e7fa8
parent 4e0b67f94c022c5cde8e504b241b83d3006aec49
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 22 Feb 2017 17:16:14 +0100

First implementation of the dump_obj functionality

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/solstice_c.h | 4++++
Asrc/solstice_dump_obj.c | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -86,6 +86,7 @@ set(SOLSTICE_FILES_SRC solstice.c solstice_args.c solstice_draw.c + solstice_dump_obj.c solstice_entity.c solstice_material.c solstice_node.c diff --git a/src/solstice_c.h b/src/solstice_c.h @@ -50,6 +50,10 @@ solstice_solve (struct solstice* solstice); extern LOCAL_SYM res_T +solstice_dump_obj + (struct solstice* solstice); + +extern LOCAL_SYM res_T solstice_create_sun (struct solstice* solstice); diff --git a/src/solstice_dump_obj.c b/src/solstice_dump_obj.c @@ -0,0 +1,98 @@ +/* Copyright (C) CNRS 2016-2017 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "solstice_c.h" +#include <solstice/ssol.h> + +struct dump_context { + FILE* output; + size_t ids_offset; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +dump_instantiated_shaded_shape + (struct ssol_instantiated_shaded_shape* sshape, struct dump_context* ctx) +{ + unsigned i, ntris, nverts; + ASSERT(sshape && ctx); + + SSOL(shape_get_vertices_count(sshape->shape, &nverts)); + FOR_EACH(i, 0, nverts) { + double pos[3]; + SSOL(instantiated_shaded_shape_get_vertex_attrib + (sshape, i, SSOL_POSITION, pos)); + fprintf(ctx->output, "v %g %g %g\n", SPLIT3(pos)); + } + + SSOL(shape_get_triangles_count(sshape->shape, &ntris)); + FOR_EACH(i, 0, ntris) { + unsigned ids[3]; + SSOL(shape_get_triangle_indices(sshape->shape, i, ids)); + /* Note that in the obj fileformat the first index is 1 rather than 0 */ + fprintf(ctx->output, "f %lu %lu %lu\n", + (unsigned long)(ids[0] + 1 + ctx->ids_offset), + (unsigned long)(ids[1] + 1 + ctx->ids_offset), + (unsigned long)(ids[2] + 1 + ctx->ids_offset)); + } + + ctx->ids_offset += nverts; +} + +static res_T +dump_instance(struct ssol_instance* instance, void* context) +{ + struct dump_context* ctx = context; + size_t i, n; + ASSERT(instance && ctx); + + SSOL(instance_get_shaded_shapes_count(instance, &n)); + FOR_EACH(i, 0, n) { + struct ssol_instantiated_shaded_shape sshape; + + SSOL(instance_get_shaded_shape(instance, i, &sshape)); + dump_instantiated_shaded_shape(&sshape, ctx); + } + + return RES_OK; +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ +res_T +solstice_dump_obj(struct solstice* solstice) +{ + struct dump_context ctx; + res_T res = RES_OK; + ASSERT(solstice); + + ctx.output = solstice->output; + ctx.ids_offset = 0; + + res = ssol_scene_for_each_instance(solstice->scene, dump_instance, &ctx); + if(res != RES_OK) { + fprintf(stderr, "Could not dump the solstice geometry.\n"); + goto error; + } + +exit: + return res; +error: + goto exit; +} +