2012-01-10 20:51:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-01-11 16:11:34 +00:00
|
|
|
#include <string.h>
|
2013-03-14 17:29:12 +00:00
|
|
|
#include <math.h>
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/auto.h"
|
2012-01-29 21:45:58 +00:00
|
|
|
#include "../lib_paysages/main.h"
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "../lib_paysages/render.h"
|
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-06-13 15:38:11 +00:00
|
|
|
void startRender(Renderer* renderer, char* outputpath, RenderParams params)
|
2012-01-11 16:11:34 +00:00
|
|
|
{
|
|
|
|
printf("\rRendering %s ... \n", outputpath);
|
2012-06-13 15:38:11 +00:00
|
|
|
rendererStart(renderer, params);
|
2012-01-11 16:11:34 +00:00
|
|
|
printf("\rSaving %s ... \n", outputpath);
|
|
|
|
remove(outputpath);
|
2012-01-29 21:45:58 +00:00
|
|
|
renderSaveToFile(renderer->render_area, outputpath);
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void displayHelp()
|
|
|
|
{
|
2012-02-26 11:28:47 +00:00
|
|
|
printf("Usage : paysages-cli [options]\n");
|
|
|
|
printf("Options :\n");
|
|
|
|
printf(" -h Show this help\n");
|
|
|
|
printf(" -f x Saved file to load (str)\n");
|
|
|
|
printf(" -n Number of pictures in the sequence\n");
|
|
|
|
printf(" -rw x Render width (int)\n");
|
|
|
|
printf(" -rh x Render height (int)\n");
|
|
|
|
printf(" -rq x Render quality (int, 1 to 10)\n");
|
2012-06-13 15:38:11 +00:00
|
|
|
printf(" -ra x Render anti-aliasing (int, 1 to 4)\n");
|
2012-06-17 09:40:40 +00:00
|
|
|
printf(" -di x Day start time (double, 0.0 to 1.0)\n");
|
|
|
|
printf(" -ds x Day step time (double)\n");
|
2013-03-18 22:40:26 +00:00
|
|
|
printf(" -cx x Camera X step (double)\n");
|
|
|
|
printf(" -cy y Camera Y step (double)\n");
|
|
|
|
printf(" -cz z Camera Z step (double)\n");
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void _previewUpdate(double progress)
|
2012-01-11 16:11:34 +00:00
|
|
|
{
|
|
|
|
printf("\rProgress : %0.1f%% ", progress * 100.0);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2012-01-10 20:51:27 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* renderer;
|
2012-02-26 11:28:47 +00:00
|
|
|
char* conf_file_path = NULL;
|
2012-06-13 15:38:11 +00:00
|
|
|
RenderParams conf_render_params = {800, 600, 1, 5};
|
2013-03-18 22:40:26 +00:00
|
|
|
int conf_first_picture = 0;
|
2012-01-11 16:11:34 +00:00
|
|
|
int conf_nb_pictures = 1;
|
2012-06-17 09:40:40 +00:00
|
|
|
double conf_daytime_start = 0.4;
|
|
|
|
double conf_daytime_step = 0.0;
|
2013-03-18 22:40:26 +00:00
|
|
|
double conf_camera_step_x = 0.0;
|
|
|
|
double conf_camera_step_y = 0.0;
|
|
|
|
double conf_camera_step_z = 0.0;
|
2012-01-11 16:11:34 +00:00
|
|
|
int outputcount;
|
|
|
|
char outputpath[500];
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
while (argc--)
|
|
|
|
{
|
|
|
|
if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0)
|
|
|
|
{
|
|
|
|
displayHelp();
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-26 11:28:47 +00:00
|
|
|
else if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_file_path = *(++argv);
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 22:40:26 +00:00
|
|
|
else if (strcmp(*argv, "-s") == 0 || strcmp(*argv, "--start") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_first_picture = atoi(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 16:11:34 +00:00
|
|
|
else if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--count") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_nb_pictures = atoi(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-rw") == 0 || strcmp(*argv, "--width") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
2012-06-13 15:38:11 +00:00
|
|
|
conf_render_params.width = atoi(*(++argv));
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-rh") == 0 || strcmp(*argv, "--height") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
2012-06-13 15:38:11 +00:00
|
|
|
conf_render_params.height = atoi(*(++argv));
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-rq") == 0 || strcmp(*argv, "--quality") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
2012-06-13 15:38:11 +00:00
|
|
|
conf_render_params.quality = atoi(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-ra") == 0 || strcmp(*argv, "--antialias") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_render_params.antialias = atoi(*(++argv));
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-di") == 0 || strcmp(*argv, "--daystart") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_daytime_start = atof(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-ds") == 0 || strcmp(*argv, "--daystep") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_daytime_step = atof(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 22:40:26 +00:00
|
|
|
else if (strcmp(*argv, "-cx") == 0 || strcmp(*argv, "--camerastepx") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_camera_step_x = atof(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-cy") == 0 || strcmp(*argv, "--camerastepy") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_camera_step_y = atof(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(*argv, "-cz") == 0 || strcmp(*argv, "--camerastepz") == 0)
|
|
|
|
{
|
|
|
|
if (argc--)
|
|
|
|
{
|
|
|
|
conf_camera_step_z = atof(*(++argv));
|
|
|
|
}
|
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
argv++;
|
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
printf("Initializing ...\n");
|
2012-01-10 20:51:27 +00:00
|
|
|
paysagesInit();
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-02-26 11:28:47 +00:00
|
|
|
if (conf_file_path)
|
|
|
|
{
|
|
|
|
paysagesLoad(conf_file_path);
|
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2013-03-18 22:40:26 +00:00
|
|
|
for (outputcount = 0; outputcount < conf_first_picture + conf_nb_pictures; outputcount++)
|
2012-01-11 16:11:34 +00:00
|
|
|
{
|
2013-03-14 17:29:12 +00:00
|
|
|
AtmosphereDefinition* atmo;
|
|
|
|
atmo = AtmosphereDefinitionClass.create();
|
|
|
|
sceneryGetAtmosphere(atmo);
|
|
|
|
atmo->hour = (int)floor(conf_daytime_start * 24.0);
|
|
|
|
atmo->minute = (int)floor(fmod(conf_daytime_start, 1.0 / 24.0) * 24.0 * 60.0);
|
|
|
|
AtmosphereDefinitionClass.validate(atmo);
|
|
|
|
scenerySetAtmosphere(atmo);
|
|
|
|
AtmosphereDefinitionClass.destroy(atmo);
|
|
|
|
|
2013-03-18 22:40:26 +00:00
|
|
|
CameraDefinition camera;
|
|
|
|
camera = cameraCreateDefinition();
|
|
|
|
sceneryGetCamera(&camera);
|
|
|
|
camera.location.x += conf_camera_step_x;
|
|
|
|
camera.location.y += conf_camera_step_y;
|
|
|
|
camera.location.z += conf_camera_step_z;
|
|
|
|
scenerySetCamera(&camera);
|
|
|
|
cameraDeleteDefinition(&camera);
|
|
|
|
|
2013-03-14 17:29:12 +00:00
|
|
|
renderer = sceneryCreateStandardRenderer();
|
|
|
|
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2013-03-18 22:40:26 +00:00
|
|
|
if (outputcount >= conf_first_picture)
|
|
|
|
{
|
|
|
|
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
|
|
|
startRender(renderer, outputpath, conf_render_params);
|
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2013-03-14 17:29:12 +00:00
|
|
|
rendererDelete(renderer);
|
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
conf_daytime_start += conf_daytime_step;
|
|
|
|
}
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-02-12 16:57:29 +00:00
|
|
|
printf("Cleaning up ...\n");
|
|
|
|
paysagesQuit();
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-11 16:11:34 +00:00
|
|
|
printf("\rDone. \n");
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-10 20:51:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|