2014-06-18 20:10:46 +00:00
|
|
|
#include "SoftwareCanvasRenderer.h"
|
|
|
|
#include "RenderConfig.h"
|
2015-09-09 22:40:47 +00:00
|
|
|
#include "Scenery.h"
|
|
|
|
#include "AtmosphereDefinition.h"
|
|
|
|
#include "CameraDefinition.h"
|
2015-10-15 15:52:03 +00:00
|
|
|
#include "TimeManager.h"
|
2015-12-17 18:29:04 +00:00
|
|
|
#include "Logs.h"
|
2015-08-12 20:11:26 +00:00
|
|
|
|
2015-09-09 22:40:47 +00:00
|
|
|
#include <cstring>
|
2015-08-12 20:11:26 +00:00
|
|
|
|
2015-09-09 22:40:47 +00:00
|
|
|
void startRender(SoftwareCanvasRenderer *renderer, const char *outputpath);
|
|
|
|
void runTestSuite();
|
2012-01-11 16:11:34 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
static void displayHelp() {
|
2012-02-26 11:28:47 +00:00
|
|
|
printf("Usage : paysages-cli [options]\n");
|
|
|
|
printf("Options :\n");
|
2015-09-09 22:40:47 +00:00
|
|
|
printf(" -h Show this help\n");
|
|
|
|
printf(" -ts Run the render test suite\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");
|
|
|
|
printf(" -ra x Render anti-aliasing (int, 1 to 4)\n");
|
2015-10-15 15:52:03 +00:00
|
|
|
printf(" -wx x Wind power in X direction (double)\n");
|
|
|
|
printf(" -wz z Wind power in Z direction (double)\n");
|
2015-09-09 22:40:47 +00:00
|
|
|
printf(" -di x Day start time (double, 0.0 to 1.0)\n");
|
|
|
|
printf(" -ds x Day step time (double)\n");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
SoftwareCanvasRenderer *renderer;
|
|
|
|
char *conf_file_path = NULL;
|
2015-09-20 22:42:58 +00:00
|
|
|
RenderConfig conf_render_params(480, 270, 1, 3);
|
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;
|
2015-10-08 21:48:19 +00:00
|
|
|
double conf_daytime_start = -1.0;
|
2012-06-17 09:40:40 +00:00
|
|
|
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;
|
2015-10-15 15:52:03 +00:00
|
|
|
double conf_wind_x = 0.0;
|
|
|
|
double conf_wind_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
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
while (argc--) {
|
|
|
|
if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) {
|
2012-01-11 16:11:34 +00:00
|
|
|
displayHelp();
|
|
|
|
return 0;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-ts") == 0 || strcmp(*argv, "--testsuite") == 0) {
|
2015-09-09 22:40:47 +00:00
|
|
|
runTestSuite();
|
|
|
|
return 0;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
|
|
|
|
if (argc--) {
|
2012-02-26 11:28:47 +00:00
|
|
|
conf_file_path = *(++argv);
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-s") == 0 || strcmp(*argv, "--start") == 0) {
|
|
|
|
if (argc--) {
|
2013-03-18 22:40:26 +00:00
|
|
|
conf_first_picture = atoi(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--count") == 0) {
|
|
|
|
if (argc--) {
|
2012-01-11 16:11:34 +00:00
|
|
|
conf_nb_pictures = atoi(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} 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
|
|
|
}
|
2015-11-09 21:30:46 +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
|
|
|
}
|
2015-11-09 21:30:46 +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));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-ra") == 0 || strcmp(*argv, "--antialias") == 0) {
|
|
|
|
if (argc--) {
|
2012-06-13 15:38:11 +00:00
|
|
|
conf_render_params.antialias = atoi(*(++argv));
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-wx") == 0 || strcmp(*argv, "--windx") == 0) {
|
|
|
|
if (argc--) {
|
2015-10-15 15:52:03 +00:00
|
|
|
conf_wind_x = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-wz") == 0 || strcmp(*argv, "--windz") == 0) {
|
|
|
|
if (argc--) {
|
2015-10-15 15:52:03 +00:00
|
|
|
conf_wind_z = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-di") == 0 || strcmp(*argv, "--daystart") == 0) {
|
|
|
|
if (argc--) {
|
2012-01-11 16:11:34 +00:00
|
|
|
conf_daytime_start = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-ds") == 0 || strcmp(*argv, "--daystep") == 0) {
|
|
|
|
if (argc--) {
|
2012-01-11 16:11:34 +00:00
|
|
|
conf_daytime_step = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-cx") == 0 || strcmp(*argv, "--camerastepx") == 0) {
|
|
|
|
if (argc--) {
|
2013-03-18 22:40:26 +00:00
|
|
|
conf_camera_step_x = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-cy") == 0 || strcmp(*argv, "--camerastepy") == 0) {
|
|
|
|
if (argc--) {
|
2013-03-18 22:40:26 +00:00
|
|
|
conf_camera_step_y = atof(*(++argv));
|
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (strcmp(*argv, "-cz") == 0 || strcmp(*argv, "--camerastepz") == 0) {
|
|
|
|
if (argc--) {
|
2013-03-18 22:40:26 +00:00
|
|
|
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");
|
2015-11-09 21:30:46 +00:00
|
|
|
Scenery *scenery = new Scenery();
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (conf_file_path) {
|
2013-12-10 21:32:58 +00:00
|
|
|
scenery->loadGlobal(conf_file_path);
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2013-12-10 21:32:58 +00:00
|
|
|
scenery->autoPreset();
|
2012-02-26 11:28:47 +00:00
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2015-12-23 23:16:50 +00:00
|
|
|
Logs::debug("CommandLine") << "Rendered scenery :" << endl
|
|
|
|
<< scenery->toString() << endl;
|
2015-12-17 18:29:04 +00:00
|
|
|
|
2015-10-15 15:52:03 +00:00
|
|
|
TimeManager time;
|
|
|
|
time.setWind(conf_wind_x, conf_wind_z);
|
2015-11-09 21:30:46 +00:00
|
|
|
if (conf_daytime_start >= 0.0) {
|
2015-10-15 15:52:03 +00:00
|
|
|
scenery->getAtmosphere()->setDayTime(conf_daytime_start);
|
|
|
|
}
|
2013-03-14 17:29:12 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
for (outputcount = 0; outputcount < conf_first_picture + conf_nb_pictures; outputcount++) {
|
|
|
|
CameraDefinition *camera = scenery->getCamera();
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
|
2013-11-14 17:47:03 +00:00
|
|
|
camera->setLocation(camera->getLocation().add(step));
|
2013-03-18 22:40:26 +00:00
|
|
|
|
2015-08-18 20:29:18 +00:00
|
|
|
renderer = new SoftwareCanvasRenderer(scenery);
|
2014-08-20 14:45:45 +00:00
|
|
|
renderer->setConfig(conf_render_params);
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (outputcount >= conf_first_picture) {
|
2015-08-12 20:11:26 +00:00
|
|
|
sprintf(outputpath, "pic%05d.png", outputcount);
|
2014-08-20 14:45:45 +00:00
|
|
|
startRender(renderer, outputpath);
|
2013-03-18 22:40:26 +00:00
|
|
|
}
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2013-11-13 22:03:02 +00:00
|
|
|
delete renderer;
|
2013-03-14 17:29:12 +00:00
|
|
|
|
2015-10-15 15:52:03 +00:00
|
|
|
time.moveForward(scenery, conf_daytime_step);
|
2012-01-11 16:11:34 +00:00
|
|
|
}
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-02-12 16:57:29 +00:00
|
|
|
printf("Cleaning up ...\n");
|
2013-12-10 21:32:58 +00:00
|
|
|
delete scenery;
|
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;
|
|
|
|
}
|