creator_args.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software Foundation,
  14. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. /** \file
  17. * \ingroup creator
  18. */
  19. #ifndef WITH_PYTHON_MODULE
  20. # include <stdlib.h>
  21. # include <string.h>
  22. # include <errno.h>
  23. # include "MEM_guardedalloc.h"
  24. # include "CLG_log.h"
  25. # ifdef WIN32
  26. # include "BLI_winstuff.h"
  27. # endif
  28. # include "BLI_args.h"
  29. # include "BLI_threads.h"
  30. # include "BLI_utildefines.h"
  31. # include "BLI_listbase.h"
  32. # include "BLI_string.h"
  33. # include "BLI_string_utf8.h"
  34. # include "BLI_path_util.h"
  35. # include "BLI_fileops.h"
  36. # include "BLI_mempool.h"
  37. # include "BLI_system.h"
  38. # include "BLO_readfile.h" /* only for BLO_has_bfile_extension */
  39. # include "BKE_blender_version.h"
  40. # include "BKE_context.h"
  41. # include "BKE_global.h"
  42. # include "BKE_image.h"
  43. # include "BKE_library.h"
  44. # include "BKE_library_override.h"
  45. # include "BKE_main.h"
  46. # include "BKE_report.h"
  47. # include "BKE_scene.h"
  48. # include "BKE_sound.h"
  49. # ifdef WITH_FFMPEG
  50. # include "IMB_imbuf.h"
  51. # endif
  52. # ifdef WITH_PYTHON
  53. # include "BPY_extern.h"
  54. # endif
  55. # include "RE_engine.h"
  56. # include "RE_pipeline.h"
  57. # include "ED_datafiles.h"
  58. # include "WM_api.h"
  59. # include "GPU_draw.h"
  60. # ifdef WITH_LIBMV
  61. # include "libmv-capi.h"
  62. # endif
  63. # ifdef WITH_CYCLES_LOGGING
  64. # include "CCL_api.h"
  65. # endif
  66. # include "DEG_depsgraph.h"
  67. # include "DEG_depsgraph_build.h"
  68. # include "DEG_depsgraph_debug.h"
  69. # include "creator_intern.h" /* own include */
  70. /* -------------------------------------------------------------------- */
  71. /** \name Utility String Parsing
  72. * \{ */
  73. static bool parse_int_relative(const char *str,
  74. const char *str_end_test,
  75. int pos,
  76. int neg,
  77. int *r_value,
  78. const char **r_err_msg)
  79. {
  80. char *str_end = NULL;
  81. long value;
  82. errno = 0;
  83. switch (*str) {
  84. case '+':
  85. value = pos + strtol(str + 1, &str_end, 10);
  86. break;
  87. case '-':
  88. value = (neg - strtol(str + 1, &str_end, 10)) + 1;
  89. break;
  90. default:
  91. value = strtol(str, &str_end, 10);
  92. break;
  93. }
  94. if (*str_end != '\0' && (str_end != str_end_test)) {
  95. static const char *msg = "not a number";
  96. *r_err_msg = msg;
  97. return false;
  98. }
  99. else if ((errno == ERANGE) || ((value < INT_MIN || value > INT_MAX))) {
  100. static const char *msg = "exceeds range";
  101. *r_err_msg = msg;
  102. return false;
  103. }
  104. else {
  105. *r_value = (int)value;
  106. return true;
  107. }
  108. }
  109. static const char *parse_int_range_sep_search(const char *str, const char *str_end_test)
  110. {
  111. const char *str_end_range = NULL;
  112. if (str_end_test) {
  113. str_end_range = memchr(str, '.', (str_end_test - str) - 1);
  114. if (str_end_range && (str_end_range[1] != '.')) {
  115. str_end_range = NULL;
  116. }
  117. }
  118. else {
  119. str_end_range = strstr(str, "..");
  120. if (str_end_range && (str_end_range[2] == '\0')) {
  121. str_end_range = NULL;
  122. }
  123. }
  124. return str_end_range;
  125. }
  126. /**
  127. * Parse a number as a range, eg: `1..4`.
  128. *
  129. * The \a str_end_range argument is a result of #parse_int_range_sep_search.
  130. */
  131. static bool parse_int_range_relative(const char *str,
  132. const char *str_end_range,
  133. const char *str_end_test,
  134. int pos,
  135. int neg,
  136. int r_value_range[2],
  137. const char **r_err_msg)
  138. {
  139. if (parse_int_relative(str, str_end_range, pos, neg, &r_value_range[0], r_err_msg) &&
  140. parse_int_relative(
  141. str_end_range + 2, str_end_test, pos, neg, &r_value_range[1], r_err_msg)) {
  142. return true;
  143. }
  144. else {
  145. return false;
  146. }
  147. }
  148. static bool parse_int_relative_clamp(const char *str,
  149. const char *str_end_test,
  150. int pos,
  151. int neg,
  152. int min,
  153. int max,
  154. int *r_value,
  155. const char **r_err_msg)
  156. {
  157. if (parse_int_relative(str, str_end_test, pos, neg, r_value, r_err_msg)) {
  158. CLAMP(*r_value, min, max);
  159. return true;
  160. }
  161. else {
  162. return false;
  163. }
  164. }
  165. static bool parse_int_range_relative_clamp(const char *str,
  166. const char *str_end_range,
  167. const char *str_end_test,
  168. int pos,
  169. int neg,
  170. int min,
  171. int max,
  172. int r_value_range[2],
  173. const char **r_err_msg)
  174. {
  175. if (parse_int_range_relative(
  176. str, str_end_range, str_end_test, pos, neg, r_value_range, r_err_msg)) {
  177. CLAMP(r_value_range[0], min, max);
  178. CLAMP(r_value_range[1], min, max);
  179. return true;
  180. }
  181. else {
  182. return false;
  183. }
  184. }
  185. /**
  186. * No clamping, fails with any number outside the range.
  187. */
  188. static bool parse_int_strict_range(const char *str,
  189. const char *str_end_test,
  190. const int min,
  191. const int max,
  192. int *r_value,
  193. const char **r_err_msg)
  194. {
  195. char *str_end = NULL;
  196. long value;
  197. errno = 0;
  198. value = strtol(str, &str_end, 10);
  199. if (*str_end != '\0' && (str_end != str_end_test)) {
  200. static const char *msg = "not a number";
  201. *r_err_msg = msg;
  202. return false;
  203. }
  204. else if ((errno == ERANGE) || ((value < min || value > max))) {
  205. static const char *msg = "exceeds range";
  206. *r_err_msg = msg;
  207. return false;
  208. }
  209. else {
  210. *r_value = (int)value;
  211. return true;
  212. }
  213. }
  214. static bool parse_int(const char *str,
  215. const char *str_end_test,
  216. int *r_value,
  217. const char **r_err_msg)
  218. {
  219. return parse_int_strict_range(str, str_end_test, INT_MIN, INT_MAX, r_value, r_err_msg);
  220. }
  221. static bool parse_int_clamp(const char *str,
  222. const char *str_end_test,
  223. int min,
  224. int max,
  225. int *r_value,
  226. const char **r_err_msg)
  227. {
  228. if (parse_int(str, str_end_test, r_value, r_err_msg)) {
  229. CLAMP(*r_value, min, max);
  230. return true;
  231. }
  232. else {
  233. return false;
  234. }
  235. }
  236. # if 0
  237. /**
  238. * Version of #parse_int_relative_clamp
  239. * that parses a comma separated list of numbers.
  240. */
  241. static int *parse_int_relative_clamp_n(
  242. const char *str, int pos, int neg, int min, int max, int *r_value_len, const char **r_err_msg)
  243. {
  244. const char sep = ',';
  245. int len = 1;
  246. for (int i = 0; str[i]; i++) {
  247. if (str[i] == sep) {
  248. len++;
  249. }
  250. }
  251. int *values = MEM_mallocN(sizeof(*values) * len, __func__);
  252. int i = 0;
  253. while (true) {
  254. const char *str_end = strchr(str, sep);
  255. if ((*str == sep) || (*str == '\0')) {
  256. static const char *msg = "incorrect comma use";
  257. *r_err_msg = msg;
  258. goto fail;
  259. }
  260. else if (parse_int_relative_clamp(str, str_end, pos, neg, min, max, &values[i], r_err_msg)) {
  261. i++;
  262. }
  263. else {
  264. goto fail; /* error message already set */
  265. }
  266. if (str_end) { /* next */
  267. str = str_end + 1;
  268. }
  269. else { /* finished */
  270. break;
  271. }
  272. }
  273. *r_value_len = i;
  274. return values;
  275. fail:
  276. MEM_freeN(values);
  277. return NULL;
  278. }
  279. # endif
  280. /**
  281. * Version of #parse_int_relative_clamp & #parse_int_range_relative_clamp
  282. * that parses a comma separated list of numbers.
  283. *
  284. * \note single values are evaluated as a range with matching start/end.
  285. */
  286. static int (*parse_int_range_relative_clamp_n(const char *str,
  287. int pos,
  288. int neg,
  289. int min,
  290. int max,
  291. int *r_value_len,
  292. const char **r_err_msg))[2]
  293. {
  294. const char sep = ',';
  295. int len = 1;
  296. for (int i = 0; str[i]; i++) {
  297. if (str[i] == sep) {
  298. len++;
  299. }
  300. }
  301. int(*values)[2] = MEM_mallocN(sizeof(*values) * len, __func__);
  302. int i = 0;
  303. while (true) {
  304. const char *str_end_range;
  305. const char *str_end = strchr(str, sep);
  306. if ((*str == sep) || (*str == '\0')) {
  307. static const char *msg = "incorrect comma use";
  308. *r_err_msg = msg;
  309. goto fail;
  310. }
  311. else if ((str_end_range = parse_int_range_sep_search(str, str_end)) ?
  312. parse_int_range_relative_clamp(
  313. str, str_end_range, str_end, pos, neg, min, max, values[i], r_err_msg) :
  314. parse_int_relative_clamp(
  315. str, str_end, pos, neg, min, max, &values[i][0], r_err_msg)) {
  316. if (str_end_range == NULL) {
  317. values[i][1] = values[i][0];
  318. }
  319. i++;
  320. }
  321. else {
  322. goto fail; /* error message already set */
  323. }
  324. if (str_end) { /* next */
  325. str = str_end + 1;
  326. }
  327. else { /* finished */
  328. break;
  329. }
  330. }
  331. *r_value_len = i;
  332. return values;
  333. fail:
  334. MEM_freeN(values);
  335. return NULL;
  336. }
  337. /** \} */
  338. /* -------------------------------------------------------------------- */
  339. # ifdef WITH_PYTHON
  340. /** \name Utilities Python Context Macro (#BPY_CTX_SETUP)
  341. * \{ */
  342. struct BlendePyContextStore {
  343. wmWindowManager *wm;
  344. Scene *scene;
  345. wmWindow *win;
  346. bool has_win;
  347. };
  348. static void arg_py_context_backup(bContext *C,
  349. struct BlendePyContextStore *c_py,
  350. const char *script_id)
  351. {
  352. c_py->wm = CTX_wm_manager(C);
  353. c_py->scene = CTX_data_scene(C);
  354. c_py->has_win = !BLI_listbase_is_empty(&c_py->wm->windows);
  355. if (c_py->has_win) {
  356. c_py->win = CTX_wm_window(C);
  357. CTX_wm_window_set(C, c_py->wm->windows.first);
  358. }
  359. else {
  360. c_py->win = NULL;
  361. fprintf(stderr,
  362. "Python script \"%s\" "
  363. "running with missing context data.\n",
  364. script_id);
  365. }
  366. }
  367. static void arg_py_context_restore(bContext *C, struct BlendePyContextStore *c_py)
  368. {
  369. /* script may load a file, check old data is valid before using */
  370. if (c_py->has_win) {
  371. if ((c_py->win == NULL) || ((BLI_findindex(&G_MAIN->wm, c_py->wm) != -1) &&
  372. (BLI_findindex(&c_py->wm->windows, c_py->win) != -1))) {
  373. CTX_wm_window_set(C, c_py->win);
  374. }
  375. }
  376. if ((c_py->scene == NULL) || BLI_findindex(&G_MAIN->scenes, c_py->scene) != -1) {
  377. CTX_data_scene_set(C, c_py->scene);
  378. }
  379. }
  380. /* macro for context setup/reset */
  381. # define BPY_CTX_SETUP(_cmd) \
  382. { \
  383. struct BlendePyContextStore py_c; \
  384. arg_py_context_backup(C, &py_c, argv[1]); \
  385. { \
  386. _cmd; \
  387. } \
  388. arg_py_context_restore(C, &py_c); \
  389. } \
  390. ((void)0)
  391. # endif /* WITH_PYTHON */
  392. /** \} */
  393. /* -------------------------------------------------------------------- */
  394. /** \name Handle Argument Callbacks
  395. *
  396. * \note Doc strings here are used in differently:
  397. *
  398. * - The `--help` message.
  399. * - The man page (for Unix systems),
  400. * see: `doc/manpage/blender.1.py`
  401. * - Parsed and extracted for the manual,
  402. * which converts our ad-hoc formatting to reStructuredText.
  403. * see: https://docs.blender.org/manual/en/dev/advanced/command_line.html
  404. *
  405. * \{ */
  406. static void print_version_full(void)
  407. {
  408. printf(BLEND_VERSION_STRING_FMT);
  409. # ifdef BUILD_DATE
  410. printf("\tbuild date: %s\n", build_date);
  411. printf("\tbuild time: %s\n", build_time);
  412. printf("\tbuild commit date: %s\n", build_commit_date);
  413. printf("\tbuild commit time: %s\n", build_commit_time);
  414. printf("\tbuild hash: %s\n", build_hash);
  415. printf("\tbuild platform: %s\n", build_platform);
  416. printf("\tbuild type: %s\n", build_type);
  417. printf("\tbuild c flags: %s\n", build_cflags);
  418. printf("\tbuild c++ flags: %s\n", build_cxxflags);
  419. printf("\tbuild link flags: %s\n", build_linkflags);
  420. printf("\tbuild system: %s\n", build_system);
  421. # endif
  422. }
  423. static void print_version_short(void)
  424. {
  425. # ifdef BUILD_DATE
  426. /* NOTE: We include built time since sometimes we need to tell broken from
  427. * working built of the same hash. */
  428. printf(BLEND_VERSION_FMT " (hash %s built %s %s)\n",
  429. BLEND_VERSION_ARG,
  430. build_hash,
  431. build_date,
  432. build_time);
  433. # else
  434. printf(BLEND_VERSION_STRING_FMT);
  435. # endif
  436. }
  437. static const char arg_handle_print_version_doc[] =
  438. "\n\t"
  439. "Print Blender version and exit.";
  440. static int arg_handle_print_version(int UNUSED(argc),
  441. const char **UNUSED(argv),
  442. void *UNUSED(data))
  443. {
  444. print_version_full();
  445. exit(0);
  446. return 0;
  447. }
  448. static const char arg_handle_print_help_doc[] =
  449. "\n\t"
  450. "Print this help text and exit.";
  451. static const char arg_handle_print_help_doc_win32[] =
  452. "\n\t"
  453. "Print this help text and exit (windows only).";
  454. static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
  455. {
  456. bArgs *ba = (bArgs *)data;
  457. printf(BLEND_VERSION_STRING_FMT);
  458. printf("Usage: blender [args ...] [file] [args ...]\n\n");
  459. printf("Render Options:\n");
  460. BLI_argsPrintArgDoc(ba, "--background");
  461. BLI_argsPrintArgDoc(ba, "--render-anim");
  462. BLI_argsPrintArgDoc(ba, "--scene");
  463. BLI_argsPrintArgDoc(ba, "--render-frame");
  464. BLI_argsPrintArgDoc(ba, "--frame-start");
  465. BLI_argsPrintArgDoc(ba, "--frame-end");
  466. BLI_argsPrintArgDoc(ba, "--frame-jump");
  467. BLI_argsPrintArgDoc(ba, "--render-output");
  468. BLI_argsPrintArgDoc(ba, "--engine");
  469. BLI_argsPrintArgDoc(ba, "--threads");
  470. printf("\n");
  471. printf("Format Options:\n");
  472. BLI_argsPrintArgDoc(ba, "--render-format");
  473. BLI_argsPrintArgDoc(ba, "--use-extension");
  474. printf("\n");
  475. printf("Animation Playback Options:\n");
  476. BLI_argsPrintArgDoc(ba, "-a");
  477. printf("\n");
  478. printf("Window Options:\n");
  479. BLI_argsPrintArgDoc(ba, "--window-border");
  480. BLI_argsPrintArgDoc(ba, "--window-fullscreen");
  481. BLI_argsPrintArgDoc(ba, "--window-geometry");
  482. BLI_argsPrintArgDoc(ba, "--window-maximized");
  483. BLI_argsPrintArgDoc(ba, "--start-console");
  484. BLI_argsPrintArgDoc(ba, "--no-native-pixels");
  485. BLI_argsPrintArgDoc(ba, "--no-window-focus");
  486. printf("\n");
  487. printf("Python Options:\n");
  488. BLI_argsPrintArgDoc(ba, "--enable-autoexec");
  489. BLI_argsPrintArgDoc(ba, "--disable-autoexec");
  490. printf("\n");
  491. BLI_argsPrintArgDoc(ba, "--python");
  492. BLI_argsPrintArgDoc(ba, "--python-text");
  493. BLI_argsPrintArgDoc(ba, "--python-expr");
  494. BLI_argsPrintArgDoc(ba, "--python-console");
  495. BLI_argsPrintArgDoc(ba, "--python-exit-code");
  496. BLI_argsPrintArgDoc(ba, "--addons");
  497. printf("\n");
  498. printf("Logging Options:\n");
  499. BLI_argsPrintArgDoc(ba, "--log");
  500. BLI_argsPrintArgDoc(ba, "--log-level");
  501. BLI_argsPrintArgDoc(ba, "--log-show-basename");
  502. BLI_argsPrintArgDoc(ba, "--log-show-backtrace");
  503. BLI_argsPrintArgDoc(ba, "--log-show-timestamp");
  504. BLI_argsPrintArgDoc(ba, "--log-file");
  505. printf("\n");
  506. printf("Debug Options:\n");
  507. BLI_argsPrintArgDoc(ba, "--debug");
  508. BLI_argsPrintArgDoc(ba, "--debug-value");
  509. printf("\n");
  510. BLI_argsPrintArgDoc(ba, "--debug-events");
  511. # ifdef WITH_FFMPEG
  512. BLI_argsPrintArgDoc(ba, "--debug-ffmpeg");
  513. # endif
  514. BLI_argsPrintArgDoc(ba, "--debug-handlers");
  515. # ifdef WITH_LIBMV
  516. BLI_argsPrintArgDoc(ba, "--debug-libmv");
  517. # endif
  518. # ifdef WITH_CYCLES_LOGGING
  519. BLI_argsPrintArgDoc(ba, "--debug-cycles");
  520. # endif
  521. BLI_argsPrintArgDoc(ba, "--debug-memory");
  522. BLI_argsPrintArgDoc(ba, "--debug-jobs");
  523. BLI_argsPrintArgDoc(ba, "--debug-python");
  524. BLI_argsPrintArgDoc(ba, "--debug-depsgraph");
  525. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-eval");
  526. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-build");
  527. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-tag");
  528. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-no-threads");
  529. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-time");
  530. BLI_argsPrintArgDoc(ba, "--debug-depsgraph-pretty");
  531. BLI_argsPrintArgDoc(ba, "--debug-gpu");
  532. BLI_argsPrintArgDoc(ba, "--debug-gpumem");
  533. BLI_argsPrintArgDoc(ba, "--debug-gpu-shaders");
  534. BLI_argsPrintArgDoc(ba, "--debug-gpu-force-workarounds");
  535. BLI_argsPrintArgDoc(ba, "--debug-wm");
  536. BLI_argsPrintArgDoc(ba, "--debug-all");
  537. BLI_argsPrintArgDoc(ba, "--debug-io");
  538. printf("\n");
  539. BLI_argsPrintArgDoc(ba, "--debug-fpe");
  540. BLI_argsPrintArgDoc(ba, "--disable-crash-handler");
  541. BLI_argsPrintArgDoc(ba, "--disable-abort-handler");
  542. printf("\n");
  543. printf("Misc Options:\n");
  544. BLI_argsPrintArgDoc(ba, "--app-template");
  545. BLI_argsPrintArgDoc(ba, "--factory-startup");
  546. BLI_argsPrintArgDoc(ba, "--enable-library-override");
  547. BLI_argsPrintArgDoc(ba, "--enable-event-simulate");
  548. printf("\n");
  549. BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
  550. BLI_argsPrintArgDoc(ba, "--env-system-scripts");
  551. BLI_argsPrintArgDoc(ba, "--env-system-python");
  552. printf("\n");
  553. BLI_argsPrintArgDoc(ba, "-noaudio");
  554. BLI_argsPrintArgDoc(ba, "-setaudio");
  555. printf("\n");
  556. BLI_argsPrintArgDoc(ba, "--help");
  557. /* WIN32 only (ignored for non-win32) */
  558. BLI_argsPrintArgDoc(ba, "-R");
  559. BLI_argsPrintArgDoc(ba, "-r");
  560. BLI_argsPrintArgDoc(ba, "--version");
  561. BLI_argsPrintArgDoc(ba, "--");
  562. // printf("\n");
  563. // printf("Experimental Features:\n");
  564. /* Other options _must_ be last (anything not handled will show here) */
  565. printf("\n");
  566. printf("Other Options:\n");
  567. BLI_argsPrintOtherDoc(ba);
  568. printf("\n");
  569. printf("Argument Parsing:\n");
  570. printf("\tArguments must be separated by white space, eg:\n");
  571. printf("\t# blender -ba test.blend\n");
  572. printf("\t...will exit since '-ba' is an unknown argument.\n");
  573. printf("Argument Order:\n");
  574. printf("\tArguments are executed in the order they are given. eg:\n");
  575. printf("\t# blender --background test.blend --render-frame 1 --render-output '/tmp'\n");
  576. printf(
  577. "\t...will not render to '/tmp' because '--render-frame 1' renders before the output path "
  578. "is set.\n");
  579. printf("\t# blender --background --render-output /tmp test.blend --render-frame 1\n");
  580. printf(
  581. "\t...will not render to '/tmp' because loading the blend-file overwrites the render output "
  582. "that was set.\n");
  583. printf("\t# blender --background test.blend --render-output /tmp --render-frame 1\n");
  584. printf("\t...works as expected.\n\n");
  585. printf("Environment Variables:\n");
  586. printf(" $BLENDER_USER_CONFIG Directory for user configuration files.\n");
  587. printf(" $BLENDER_USER_SCRIPTS Directory for user scripts.\n");
  588. printf(" $BLENDER_SYSTEM_SCRIPTS Directory for system wide scripts.\n");
  589. printf(" $BLENDER_USER_DATAFILES Directory for user data files (icons, translations, ..).\n");
  590. printf(" $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n");
  591. printf(" $BLENDER_SYSTEM_PYTHON Directory for system Python libraries.\n");
  592. # ifdef WIN32
  593. printf(" $TEMP Store temporary files here.\n");
  594. # else
  595. printf(" $TMP or $TMPDIR Store temporary files here.\n");
  596. # endif
  597. # ifdef WITH_SDL
  598. printf(" $SDL_AUDIODRIVER LibSDL audio driver - alsa, esd, dma.\n");
  599. # endif
  600. printf(" $PYTHONHOME Path to the Python directory, eg. /usr/lib/python.\n\n");
  601. exit(0);
  602. return 0;
  603. }
  604. static const char arg_handle_arguments_end_doc[] =
  605. "\n\t"
  606. "End option processing, following arguments passed unchanged. Access via Python's "
  607. "'sys.argv'.";
  608. static int arg_handle_arguments_end(int UNUSED(argc),
  609. const char **UNUSED(argv),
  610. void *UNUSED(data))
  611. {
  612. return -1;
  613. }
  614. /* only to give help message */
  615. # ifndef WITH_PYTHON_SECURITY /* default */
  616. # define PY_ENABLE_AUTO ", (default)"
  617. # define PY_DISABLE_AUTO ""
  618. # else
  619. # define PY_ENABLE_AUTO ""
  620. # define PY_DISABLE_AUTO ", (compiled as non-standard default)"
  621. # endif
  622. static const char arg_handle_python_set_doc_enable[] =
  623. "\n\t"
  624. "Enable automatic Python script execution" PY_ENABLE_AUTO ".";
  625. static const char arg_handle_python_set_doc_disable[] =
  626. "\n\t"
  627. "Disable automatic Python script execution (pydrivers & startup scripts)" PY_DISABLE_AUTO ".";
  628. # undef PY_ENABLE_AUTO
  629. # undef PY_DISABLE_AUTO
  630. static int arg_handle_python_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
  631. {
  632. if ((bool)data) {
  633. G.f |= G_FLAG_SCRIPT_AUTOEXEC;
  634. }
  635. else {
  636. G.f &= ~G_FLAG_SCRIPT_AUTOEXEC;
  637. }
  638. G.f |= G_FLAG_SCRIPT_OVERRIDE_PREF;
  639. return 0;
  640. }
  641. static const char arg_handle_crash_handler_disable_doc[] =
  642. "\n\t"
  643. "Disable the crash handler.";
  644. static int arg_handle_crash_handler_disable(int UNUSED(argc),
  645. const char **UNUSED(argv),
  646. void *UNUSED(data))
  647. {
  648. app_state.signal.use_crash_handler = false;
  649. return 0;
  650. }
  651. static const char arg_handle_abort_handler_disable_doc[] =
  652. "\n\t"
  653. "Disable the abort handler.";
  654. static int arg_handle_abort_handler_disable(int UNUSED(argc),
  655. const char **UNUSED(argv),
  656. void *UNUSED(data))
  657. {
  658. app_state.signal.use_abort_handler = false;
  659. return 0;
  660. }
  661. static const char arg_handle_background_mode_set_doc[] =
  662. "\n\t"
  663. "Run in background (often used for UI-less rendering).";
  664. static int arg_handle_background_mode_set(int UNUSED(argc),
  665. const char **UNUSED(argv),
  666. void *UNUSED(data))
  667. {
  668. print_version_short();
  669. G.background = 1;
  670. return 0;
  671. }
  672. static const char arg_handle_log_level_set_doc[] =
  673. "<level>\n"
  674. "\tSet the logging verbosity level (higher for more details) defaults to 1,\n"
  675. "\tuse -1 to log all levels.";
  676. static int arg_handle_log_level_set(int argc, const char **argv, void *UNUSED(data))
  677. {
  678. const char *arg_id = "--log-level";
  679. if (argc > 1) {
  680. const char *err_msg = NULL;
  681. if (!parse_int_clamp(argv[1], NULL, -1, INT_MAX, &G.log.level, &err_msg)) {
  682. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  683. }
  684. else {
  685. if (G.log.level == -1) {
  686. G.log.level = INT_MAX;
  687. }
  688. CLG_level_set(G.log.level);
  689. }
  690. return 1;
  691. }
  692. else {
  693. printf("\nError: '%s' no args given.\n", arg_id);
  694. return 0;
  695. }
  696. }
  697. static const char arg_handle_log_show_basename_set_doc[] =
  698. "\n\t"
  699. "Only show file name in output (not the leading path).";
  700. static int arg_handle_log_show_basename_set(int UNUSED(argc),
  701. const char **UNUSED(argv),
  702. void *UNUSED(data))
  703. {
  704. CLG_output_use_basename_set(true);
  705. return 0;
  706. }
  707. static const char arg_handle_log_show_backtrace_set_doc[] =
  708. "\n\t"
  709. "Show a back trace for each log message (debug builds only).";
  710. static int arg_handle_log_show_backtrace_set(int UNUSED(argc),
  711. const char **UNUSED(argv),
  712. void *UNUSED(data))
  713. {
  714. /* Ensure types don't become incompatible. */
  715. void (*fn)(FILE * fp) = BLI_system_backtrace;
  716. CLG_backtrace_fn_set((void (*)(void *))fn);
  717. return 0;
  718. }
  719. static const char arg_handle_log_show_timestamp_set_doc[] =
  720. "\n\t"
  721. "Show a timestamp for each log message in seconds since start.";
  722. static int arg_handle_log_show_timestamp_set(int UNUSED(argc),
  723. const char **UNUSED(argv),
  724. void *UNUSED(data))
  725. {
  726. CLG_output_use_timestamp_set(true);
  727. return 0;
  728. }
  729. static const char arg_handle_log_file_set_doc[] =
  730. "<filename>\n"
  731. "\tSet a file to output the log to.";
  732. static int arg_handle_log_file_set(int argc, const char **argv, void *UNUSED(data))
  733. {
  734. const char *arg_id = "--log-file";
  735. if (argc > 1) {
  736. errno = 0;
  737. FILE *fp = BLI_fopen(argv[1], "w");
  738. if (fp == NULL) {
  739. const char *err_msg = errno ? strerror(errno) : "unknown";
  740. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  741. }
  742. else {
  743. if (UNLIKELY(G.log.file != NULL)) {
  744. fclose(G.log.file);
  745. }
  746. G.log.file = fp;
  747. CLG_output_set(G.log.file);
  748. }
  749. return 1;
  750. }
  751. else {
  752. printf("\nError: '%s' no args given.\n", arg_id);
  753. return 0;
  754. }
  755. }
  756. static const char arg_handle_log_set_doc[] =
  757. "<match>\n"
  758. "\tEnable logging categories, taking a single comma separated argument.\n"
  759. "\tMultiple categories can be matched using a '.*' suffix,\n"
  760. "\tso '--log \"wm.*\"' logs every kind of window-manager message.\n"
  761. "\tUse \"^\" prefix to ignore, so '--log \"*,^wm.operator.*\"' logs all except for "
  762. "'wm.operators.*'\n"
  763. "\tUse \"*\" to log everything.";
  764. static int arg_handle_log_set(int argc, const char **argv, void *UNUSED(data))
  765. {
  766. const char *arg_id = "--log";
  767. if (argc > 1) {
  768. const char *str_step = argv[1];
  769. while (*str_step) {
  770. const char *str_step_end = strchr(str_step, ',');
  771. int str_step_len = str_step_end ? (str_step_end - str_step) : strlen(str_step);
  772. if (str_step[0] == '^') {
  773. CLG_type_filter_exclude(str_step + 1, str_step_len - 1);
  774. }
  775. else {
  776. CLG_type_filter_include(str_step, str_step_len);
  777. }
  778. if (str_step_end) {
  779. /* typically only be one, but don't fail on multiple.*/
  780. while (*str_step_end == ',') {
  781. str_step_end++;
  782. }
  783. str_step = str_step_end;
  784. }
  785. else {
  786. break;
  787. }
  788. }
  789. return 1;
  790. }
  791. else {
  792. printf("\nError: '%s' no args given.\n", arg_id);
  793. return 0;
  794. }
  795. }
  796. static const char arg_handle_debug_mode_set_doc[] =
  797. "\n"
  798. "\tTurn debugging on.\n"
  799. "\n"
  800. "\t* Enables memory error detection\n"
  801. "\t* Disables mouse grab (to interact with a debugger in some cases)\n"
  802. "\t* Keeps Python's 'sys.stdin' rather than setting it to None";
  803. static int arg_handle_debug_mode_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
  804. {
  805. G.debug |= G_DEBUG; /* std output printf's */
  806. printf(BLEND_VERSION_STRING_FMT);
  807. MEM_set_memory_debug();
  808. # ifndef NDEBUG
  809. BLI_mempool_set_memory_debug();
  810. # endif
  811. # ifdef WITH_BUILDINFO
  812. printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
  813. # endif
  814. BLI_argsPrint(data);
  815. return 0;
  816. }
  817. # ifdef WITH_FFMPEG
  818. static const char arg_handle_debug_mode_generic_set_doc_ffmpeg[] =
  819. "\n\t"
  820. "Enable debug messages from FFmpeg library.";
  821. # endif
  822. # ifdef WITH_FREESTYLE
  823. static const char arg_handle_debug_mode_generic_set_doc_freestyle[] =
  824. "\n\t"
  825. "Enable debug messages for Freestyle.";
  826. # endif
  827. static const char arg_handle_debug_mode_generic_set_doc_python[] =
  828. "\n\t"
  829. "Enable debug messages for Python.";
  830. static const char arg_handle_debug_mode_generic_set_doc_events[] =
  831. "\n\t"
  832. "Enable debug messages for the event system.";
  833. static const char arg_handle_debug_mode_generic_set_doc_handlers[] =
  834. "\n\t"
  835. "Enable debug messages for event handling.";
  836. static const char arg_handle_debug_mode_generic_set_doc_wm[] =
  837. "\n\t"
  838. "Enable debug messages for the window manager, shows all operators in search, shows "
  839. "keymap errors.";
  840. static const char arg_handle_debug_mode_generic_set_doc_jobs[] =
  841. "\n\t"
  842. "Enable time profiling for background jobs.";
  843. static const char arg_handle_debug_mode_generic_set_doc_gpu[] =
  844. "\n\t"
  845. "Enable gpu debug context and information for OpenGL 4.3+.";
  846. static const char arg_handle_debug_mode_generic_set_doc_depsgraph[] =
  847. "\n\t"
  848. "Enable all debug messages from dependency graph.";
  849. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_build[] =
  850. "\n\t"
  851. "Enable debug messages from dependency graph related on graph construction.";
  852. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_tag[] =
  853. "\n\t"
  854. "Enable debug messages from dependency graph related on tagging.";
  855. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_time[] =
  856. "\n\t"
  857. "Enable debug messages from dependency graph related on timing.";
  858. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_eval[] =
  859. "\n\t"
  860. "Enable debug messages from dependency graph related on evaluation.";
  861. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_no_threads[] =
  862. "\n\t"
  863. "Switch dependency graph to a single threaded evaluation.";
  864. static const char arg_handle_debug_mode_generic_set_doc_depsgraph_pretty[] =
  865. "\n\t"
  866. "Enable colors for dependency graph debug messages.";
  867. static const char arg_handle_debug_mode_generic_set_doc_gpumem[] =
  868. "\n\t"
  869. "Enable GPU memory stats in status bar.";
  870. static int arg_handle_debug_mode_generic_set(int UNUSED(argc),
  871. const char **UNUSED(argv),
  872. void *data)
  873. {
  874. G.debug |= POINTER_AS_INT(data);
  875. return 0;
  876. }
  877. static const char arg_handle_debug_mode_io_doc[] =
  878. "\n\t"
  879. "Enable debug messages for I/O (collada, ...).";
  880. static int arg_handle_debug_mode_io(int UNUSED(argc),
  881. const char **UNUSED(argv),
  882. void *UNUSED(data))
  883. {
  884. G.debug |= G_DEBUG_IO;
  885. return 0;
  886. }
  887. static const char arg_handle_debug_mode_all_doc[] =
  888. "\n\t"
  889. "Enable all debug messages.";
  890. static int arg_handle_debug_mode_all(int UNUSED(argc),
  891. const char **UNUSED(argv),
  892. void *UNUSED(data))
  893. {
  894. G.debug |= G_DEBUG_ALL;
  895. # ifdef WITH_LIBMV
  896. libmv_startDebugLogging();
  897. # endif
  898. # ifdef WITH_CYCLES_LOGGING
  899. CCL_start_debug_logging();
  900. # endif
  901. return 0;
  902. }
  903. # ifdef WITH_LIBMV
  904. static const char arg_handle_debug_mode_libmv_doc[] =
  905. "\n\t"
  906. "Enable debug messages from libmv library.";
  907. static int arg_handle_debug_mode_libmv(int UNUSED(argc),
  908. const char **UNUSED(argv),
  909. void *UNUSED(data))
  910. {
  911. libmv_startDebugLogging();
  912. return 0;
  913. }
  914. # endif
  915. # ifdef WITH_CYCLES_LOGGING
  916. static const char arg_handle_debug_mode_cycles_doc[] =
  917. "\n\t"
  918. "Enable debug messages from Cycles.";
  919. static int arg_handle_debug_mode_cycles(int UNUSED(argc),
  920. const char **UNUSED(argv),
  921. void *UNUSED(data))
  922. {
  923. CCL_start_debug_logging();
  924. return 0;
  925. }
  926. # endif
  927. static const char arg_handle_debug_mode_memory_set_doc[] =
  928. "\n\t"
  929. "Enable fully guarded memory allocation and debugging.";
  930. static int arg_handle_debug_mode_memory_set(int UNUSED(argc),
  931. const char **UNUSED(argv),
  932. void *UNUSED(data))
  933. {
  934. MEM_set_memory_debug();
  935. return 0;
  936. }
  937. static const char arg_handle_debug_value_set_doc[] =
  938. "<value>\n"
  939. "\tSet debug value of <value> on startup.";
  940. static int arg_handle_debug_value_set(int argc, const char **argv, void *UNUSED(data))
  941. {
  942. const char *arg_id = "--debug-value";
  943. if (argc > 1) {
  944. const char *err_msg = NULL;
  945. int value;
  946. if (!parse_int(argv[1], NULL, &value, &err_msg)) {
  947. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  948. return 1;
  949. }
  950. G.debug_value = value;
  951. return 1;
  952. }
  953. else {
  954. printf("\nError: you must specify debug value to set.\n");
  955. return 0;
  956. }
  957. }
  958. static const char arg_handle_debug_fpe_set_doc[] =
  959. "\n\t"
  960. "Enable floating point exceptions.";
  961. static int arg_handle_debug_fpe_set(int UNUSED(argc),
  962. const char **UNUSED(argv),
  963. void *UNUSED(data))
  964. {
  965. main_signal_setup_fpe();
  966. return 0;
  967. }
  968. static const char arg_handle_app_template_doc[] =
  969. "<template>\n"
  970. "\tSet the application template (matching the directory name), use 'default' for none.";
  971. static int arg_handle_app_template(int argc, const char **argv, void *UNUSED(data))
  972. {
  973. if (argc > 1) {
  974. const char *app_template = STREQ(argv[1], "default") ? "" : argv[1];
  975. WM_init_state_app_template_set(app_template);
  976. return 1;
  977. }
  978. else {
  979. printf("\nError: App template must follow '--app-template'.\n");
  980. return 0;
  981. }
  982. }
  983. static const char arg_handle_factory_startup_set_doc[] =
  984. "\n\t"
  985. "Skip reading the " STRINGIFY(BLENDER_STARTUP_FILE) " in the users home directory.";
  986. static int arg_handle_factory_startup_set(int UNUSED(argc),
  987. const char **UNUSED(argv),
  988. void *UNUSED(data))
  989. {
  990. G.factory_startup = 1;
  991. G.f |= G_FLAG_USERPREF_NO_SAVE_ON_EXIT;
  992. return 0;
  993. }
  994. static const char arg_handle_enable_override_library_doc[] =
  995. "\n\t"
  996. "Enable Library Override features in the UI.";
  997. static int arg_handle_enable_override_library(int UNUSED(argc),
  998. const char **UNUSED(argv),
  999. void *UNUSED(data))
  1000. {
  1001. BKE_override_library_enable(true);
  1002. return 0;
  1003. }
  1004. static const char arg_handle_enable_event_simulate_doc[] =
  1005. "\n\t"
  1006. "Enable event simulation testing feature 'bpy.types.Window.event_simulate'.";
  1007. static int arg_handle_enable_event_simulate(int UNUSED(argc),
  1008. const char **UNUSED(argv),
  1009. void *UNUSED(data))
  1010. {
  1011. G.f |= G_FLAG_EVENT_SIMULATE;
  1012. return 0;
  1013. }
  1014. static const char arg_handle_env_system_set_doc_datafiles[] =
  1015. "\n\t"
  1016. "Set the " STRINGIFY_ARG(BLENDER_SYSTEM_DATAFILES) " environment variable.";
  1017. static const char arg_handle_env_system_set_doc_scripts[] =
  1018. "\n\t"
  1019. "Set the " STRINGIFY_ARG(BLENDER_SYSTEM_SCRIPTS) " environment variable.";
  1020. static const char arg_handle_env_system_set_doc_python[] =
  1021. "\n\t"
  1022. "Set the " STRINGIFY_ARG(BLENDER_SYSTEM_PYTHON) " environment variable.";
  1023. static int arg_handle_env_system_set(int argc, const char **argv, void *UNUSED(data))
  1024. {
  1025. /* "--env-system-scripts" --> "BLENDER_SYSTEM_SCRIPTS" */
  1026. char env[64] = "BLENDER";
  1027. char *ch_dst = env + 7; /* skip BLENDER */
  1028. const char *ch_src = argv[0] + 5; /* skip --env */
  1029. if (argc < 2) {
  1030. printf("%s requires one argument\n", argv[0]);
  1031. exit(1);
  1032. }
  1033. for (; *ch_src; ch_src++, ch_dst++) {
  1034. *ch_dst = (*ch_src == '-') ? '_' : (*ch_src) - 32; /* toupper() */
  1035. }
  1036. *ch_dst = '\0';
  1037. BLI_setenv(env, argv[1]);
  1038. return 1;
  1039. }
  1040. static const char arg_handle_playback_mode_doc[] =
  1041. "<options> <file(s)>\n"
  1042. "\tInstead of showing Blender's user interface, this runs Blender as an animation player,\n"
  1043. "\tto view movies and image sequences rendered in Blender (ignored if '-b' is set).\n"
  1044. "\n"
  1045. "\tPlayback Arguments:\n"
  1046. "\n"
  1047. "\t-p <sx> <sy>\n"
  1048. "\t\tOpen with lower left corner at <sx>, <sy>.\n"
  1049. "\t-m\n"
  1050. "\t\tRead from disk (Do not buffer).\n"
  1051. "\t-f <fps> <fps-base>\n"
  1052. "\t\tSpecify FPS to start with.\n"
  1053. "\t-j <frame>\n"
  1054. "\t\tSet frame step to <frame>.\n"
  1055. "\t-s <frame>\n"
  1056. "\t\tPlay from <frame>.\n"
  1057. "\t-e <frame>\n"
  1058. "\t\tPlay until <frame>.";
  1059. static int arg_handle_playback_mode(int argc, const char **argv, void *UNUSED(data))
  1060. {
  1061. /* not if -b was given first */
  1062. if (G.background == 0) {
  1063. # ifdef WITH_FFMPEG
  1064. /* Setup FFmpeg with current debug flags. */
  1065. IMB_ffmpeg_init();
  1066. # endif
  1067. WM_main_playanim(argc, argv); /* not the same argc and argv as before */
  1068. exit(0); /* 2.4x didn't do this */
  1069. }
  1070. return -2;
  1071. }
  1072. static const char arg_handle_window_geometry_doc[] =
  1073. "<sx> <sy> <w> <h>\n"
  1074. "\tOpen with lower left corner at <sx>, <sy> and width and height as <w>, <h>.";
  1075. static int arg_handle_window_geometry(int argc, const char **argv, void *UNUSED(data))
  1076. {
  1077. const char *arg_id = "-p / --window-geometry";
  1078. int params[4], i;
  1079. if (argc < 5) {
  1080. fprintf(stderr, "Error: requires four arguments '%s'\n", arg_id);
  1081. exit(1);
  1082. }
  1083. for (i = 0; i < 4; i++) {
  1084. const char *err_msg = NULL;
  1085. if (!parse_int(argv[i + 1], NULL, &params[i], &err_msg)) {
  1086. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1087. exit(1);
  1088. }
  1089. }
  1090. WM_init_state_size_set(UNPACK4(params));
  1091. return 4;
  1092. }
  1093. static const char arg_handle_native_pixels_set_doc[] =
  1094. "\n\t"
  1095. "Do not use native pixel size, for high resolution displays (MacBook 'Retina').";
  1096. static int arg_handle_native_pixels_set(int UNUSED(argc),
  1097. const char **UNUSED(argv),
  1098. void *UNUSED(data))
  1099. {
  1100. WM_init_native_pixels(false);
  1101. return 0;
  1102. }
  1103. static const char arg_handle_with_borders_doc[] =
  1104. "\n\t"
  1105. "Force opening with borders.";
  1106. static int arg_handle_with_borders(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
  1107. {
  1108. WM_init_state_normal_set();
  1109. return 0;
  1110. }
  1111. static const char arg_handle_without_borders_doc[] =
  1112. "\n\t"
  1113. "Force opening in fullscreen mode.";
  1114. static int arg_handle_without_borders(int UNUSED(argc),
  1115. const char **UNUSED(argv),
  1116. void *UNUSED(data))
  1117. {
  1118. WM_init_state_fullscreen_set();
  1119. return 0;
  1120. }
  1121. static const char arg_handle_window_maximized_doc[] =
  1122. "\n\t"
  1123. "Force opening maximized.";
  1124. static int arg_handle_window_maximized(int UNUSED(argc),
  1125. const char **UNUSED(argv),
  1126. void *UNUSED(data))
  1127. {
  1128. WM_init_state_maximized_set();
  1129. return 0;
  1130. }
  1131. static const char arg_handle_no_window_focus_doc[] =
  1132. "\n\t"
  1133. "Open behind other windows and without taking focus.";
  1134. static int arg_handle_no_window_focus(int UNUSED(argc),
  1135. const char **UNUSED(argv),
  1136. void *UNUSED(data))
  1137. {
  1138. WM_init_window_focus_set(false);
  1139. return 0;
  1140. }
  1141. static const char arg_handle_start_with_console_doc[] =
  1142. "\n\t"
  1143. "Start with the console window open (ignored if '-b' is set), (Windows only).";
  1144. static int arg_handle_start_with_console(int UNUSED(argc),
  1145. const char **UNUSED(argv),
  1146. void *UNUSED(data))
  1147. {
  1148. WM_init_state_start_with_console_set(true);
  1149. return 0;
  1150. }
  1151. static const char arg_handle_register_extension_doc[] =
  1152. "\n\t"
  1153. "Register blend-file extension, then exit (Windows only).";
  1154. static const char arg_handle_register_extension_doc_silent[] =
  1155. "\n\t"
  1156. "Silently register blend-file extension, then exit (Windows only).";
  1157. static int arg_handle_register_extension(int UNUSED(argc), const char **UNUSED(argv), void *data)
  1158. {
  1159. # ifdef WIN32
  1160. if (data) {
  1161. G.background = 1;
  1162. }
  1163. RegisterBlendExtension();
  1164. # else
  1165. (void)data; /* unused */
  1166. # endif
  1167. return 0;
  1168. }
  1169. static const char arg_handle_audio_disable_doc[] =
  1170. "\n\t"
  1171. "Force sound system to None.";
  1172. static int arg_handle_audio_disable(int UNUSED(argc),
  1173. const char **UNUSED(argv),
  1174. void *UNUSED(data))
  1175. {
  1176. BKE_sound_force_device("Null");
  1177. return 0;
  1178. }
  1179. static const char arg_handle_audio_set_doc[] =
  1180. "\n\t"
  1181. "Force sound system to a specific device."
  1182. "\n\t"
  1183. "'NULL' 'SDL' 'OPENAL' 'JACK'.";
  1184. static int arg_handle_audio_set(int argc, const char **argv, void *UNUSED(data))
  1185. {
  1186. if (argc < 1) {
  1187. fprintf(stderr, "-setaudio require one argument\n");
  1188. exit(1);
  1189. }
  1190. BKE_sound_force_device(argv[1]);
  1191. return 1;
  1192. }
  1193. static const char arg_handle_output_set_doc[] =
  1194. "<path>\n"
  1195. "\tSet the render path and file name.\n"
  1196. "\tUse '//' at the start of the path to render relative to the blend-file.\n"
  1197. "\n"
  1198. "\tThe '#' characters are replaced by the frame number, and used to define zero padding.\n"
  1199. "\n"
  1200. "\t* 'animation_##_test.png' becomes 'animation_01_test.png'\n"
  1201. "\t* 'test-######.png' becomes 'test-000001.png'\n"
  1202. "\n"
  1203. "\tWhen the filename does not contain '#', The suffix '####' is added to the filename.\n"
  1204. "\n"
  1205. "\tThe frame number will be added at the end of the filename, eg:\n"
  1206. "\t# blender -b animation.blend -o //render_ -F PNG -x 1 -a\n"
  1207. "\t'//render_' becomes '//render_####', writing frames as '//render_0001.png'";
  1208. static int arg_handle_output_set(int argc, const char **argv, void *data)
  1209. {
  1210. bContext *C = data;
  1211. if (argc > 1) {
  1212. Scene *scene = CTX_data_scene(C);
  1213. if (scene) {
  1214. BLI_strncpy(scene->r.pic, argv[1], sizeof(scene->r.pic));
  1215. }
  1216. else {
  1217. printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n");
  1218. }
  1219. return 1;
  1220. }
  1221. else {
  1222. printf("\nError: you must specify a path after '-o / --render-output'.\n");
  1223. return 0;
  1224. }
  1225. }
  1226. static const char arg_handle_engine_set_doc[] =
  1227. "<engine>\n"
  1228. "\tSpecify the render engine.\n"
  1229. "\tUse '-E' help to list available engines.";
  1230. static int arg_handle_engine_set(int argc, const char **argv, void *data)
  1231. {
  1232. bContext *C = data;
  1233. if (argc >= 2) {
  1234. if (STREQ(argv[1], "help")) {
  1235. RenderEngineType *type = NULL;
  1236. printf("Blender Engine Listing:\n");
  1237. for (type = R_engines.first; type; type = type->next) {
  1238. printf("\t%s\n", type->idname);
  1239. }
  1240. exit(0);
  1241. }
  1242. else {
  1243. Scene *scene = CTX_data_scene(C);
  1244. if (scene) {
  1245. if (BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
  1246. BLI_strncpy_utf8(scene->r.engine, argv[1], sizeof(scene->r.engine));
  1247. }
  1248. else {
  1249. printf("\nError: engine not found '%s'\n", argv[1]);
  1250. exit(1);
  1251. }
  1252. }
  1253. else {
  1254. printf(
  1255. "\nError: no blend loaded. "
  1256. "order the arguments so '-E / --engine' is after a blend is loaded.\n");
  1257. }
  1258. }
  1259. return 1;
  1260. }
  1261. else {
  1262. printf("\nEngine not specified, give 'help' for a list of available engines.\n");
  1263. return 0;
  1264. }
  1265. }
  1266. static const char arg_handle_image_type_set_doc[] =
  1267. "<format>\n"
  1268. "\tSet the render format.\n"
  1269. "\tValid options are:\n"
  1270. "\t'TGA' 'RAWTGA' 'JPEG' 'IRIS' 'IRIZ' 'AVIRAW' 'AVIJPEG' 'PNG' 'BMP'\n"
  1271. "\n"
  1272. "\tFormats that can be compiled into Blender, not available on all systems:\n"
  1273. "\t'HDR' 'TIFF' 'OPEN_EXR' 'OPEN_EXR_MULTILAYER' 'MPEG' 'CINEON' 'DPX' 'DDS' 'JP2'";
  1274. static int arg_handle_image_type_set(int argc, const char **argv, void *data)
  1275. {
  1276. bContext *C = data;
  1277. if (argc > 1) {
  1278. const char *imtype = argv[1];
  1279. Scene *scene = CTX_data_scene(C);
  1280. if (scene) {
  1281. const char imtype_new = BKE_imtype_from_arg(imtype);
  1282. if (imtype_new == R_IMF_IMTYPE_INVALID) {
  1283. printf(
  1284. "\nError: Format from '-F / --render-format' not known or not compiled in this "
  1285. "release.\n");
  1286. }
  1287. else {
  1288. scene->r.im_format.imtype = imtype_new;
  1289. }
  1290. }
  1291. else {
  1292. printf(
  1293. "\nError: no blend loaded. "
  1294. "order the arguments so '-F / --render-format' is after the blend is loaded.\n");
  1295. }
  1296. return 1;
  1297. }
  1298. else {
  1299. printf("\nError: you must specify a format after '-F / --render-foramt'.\n");
  1300. return 0;
  1301. }
  1302. }
  1303. static const char arg_handle_threads_set_doc[] =
  1304. "<threads>\n"
  1305. "\tUse amount of <threads> for rendering and other operations\n"
  1306. "\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count.";
  1307. static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data))
  1308. {
  1309. const char *arg_id = "-t / --threads";
  1310. const int min = 0, max = BLENDER_MAX_THREADS;
  1311. if (argc > 1) {
  1312. const char *err_msg = NULL;
  1313. int threads;
  1314. if (!parse_int_strict_range(argv[1], NULL, min, max, &threads, &err_msg)) {
  1315. printf("\nError: %s '%s %s', expected number in [%d..%d].\n",
  1316. err_msg,
  1317. arg_id,
  1318. argv[1],
  1319. min,
  1320. max);
  1321. return 1;
  1322. }
  1323. BLI_system_num_threads_override_set(threads);
  1324. return 1;
  1325. }
  1326. else {
  1327. printf("\nError: you must specify a number of threads in [%d..%d] '%s'.\n", min, max, arg_id);
  1328. return 0;
  1329. }
  1330. }
  1331. static const char arg_handle_verbosity_set_doc[] =
  1332. "<verbose>\n"
  1333. "\tSet logging verbosity level for debug messages which supports it.";
  1334. static int arg_handle_verbosity_set(int argc, const char **argv, void *UNUSED(data))
  1335. {
  1336. const char *arg_id = "--verbose";
  1337. if (argc > 1) {
  1338. const char *err_msg = NULL;
  1339. int level;
  1340. if (!parse_int(argv[1], NULL, &level, &err_msg)) {
  1341. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1342. }
  1343. # ifdef WITH_LIBMV
  1344. libmv_setLoggingVerbosity(level);
  1345. # elif defined(WITH_CYCLES_LOGGING)
  1346. CCL_logging_verbosity_set(level);
  1347. # else
  1348. (void)level;
  1349. # endif
  1350. return 1;
  1351. }
  1352. else {
  1353. printf("\nError: you must specify a verbosity level.\n");
  1354. return 0;
  1355. }
  1356. }
  1357. static const char arg_handle_extension_set_doc[] =
  1358. "<bool>\n"
  1359. "\tSet option to add the file extension to the end of the file.";
  1360. static int arg_handle_extension_set(int argc, const char **argv, void *data)
  1361. {
  1362. bContext *C = data;
  1363. if (argc > 1) {
  1364. Scene *scene = CTX_data_scene(C);
  1365. if (scene) {
  1366. if (argv[1][0] == '0') {
  1367. scene->r.scemode &= ~R_EXTENSION;
  1368. }
  1369. else if (argv[1][0] == '1') {
  1370. scene->r.scemode |= R_EXTENSION;
  1371. }
  1372. else {
  1373. printf("\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n");
  1374. }
  1375. }
  1376. else {
  1377. printf(
  1378. "\nError: no blend loaded. "
  1379. "order the arguments so '-o ' is after '-x '.\n");
  1380. }
  1381. return 1;
  1382. }
  1383. else {
  1384. printf("\nError: you must specify a path after '- '.\n");
  1385. return 0;
  1386. }
  1387. }
  1388. static const char arg_handle_render_frame_doc[] =
  1389. "<frame>\n"
  1390. "\tRender frame <frame> and save it.\n"
  1391. "\n"
  1392. "\t* +<frame> start frame relative, -<frame> end frame relative.\n"
  1393. "\t* A comma separated list of frames can also be used (no spaces).\n"
  1394. "\t* A range of frames can be expressed using '..' separator between the first and last "
  1395. "frames (inclusive).\n";
  1396. static int arg_handle_render_frame(int argc, const char **argv, void *data)
  1397. {
  1398. const char *arg_id = "-f / --render-frame";
  1399. bContext *C = data;
  1400. Scene *scene = CTX_data_scene(C);
  1401. if (scene) {
  1402. Main *bmain = CTX_data_main(C);
  1403. if (argc > 1) {
  1404. const char *err_msg = NULL;
  1405. Render *re;
  1406. ReportList reports;
  1407. int(*frame_range_arr)[2], frames_range_len;
  1408. if ((frame_range_arr = parse_int_range_relative_clamp_n(argv[1],
  1409. scene->r.sfra,
  1410. scene->r.efra,
  1411. MINAFRAME,
  1412. MAXFRAME,
  1413. &frames_range_len,
  1414. &err_msg)) == NULL) {
  1415. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1416. return 1;
  1417. }
  1418. re = RE_NewSceneRender(scene);
  1419. BLI_threaded_malloc_begin();
  1420. BKE_reports_init(&reports, RPT_STORE);
  1421. RE_SetReports(re, &reports);
  1422. for (int i = 0; i < frames_range_len; i++) {
  1423. /* We could pass in frame ranges,
  1424. * but prefer having exact behavior as passing in multiple frames */
  1425. if ((frame_range_arr[i][0] <= frame_range_arr[i][1]) == 0) {
  1426. printf("\nWarning: negative range ignored '%s %s'.\n", arg_id, argv[1]);
  1427. }
  1428. for (int frame = frame_range_arr[i][0]; frame <= frame_range_arr[i][1]; frame++) {
  1429. RE_RenderAnim(re, bmain, scene, NULL, NULL, frame, frame, scene->r.frame_step);
  1430. }
  1431. }
  1432. RE_SetReports(re, NULL);
  1433. BKE_reports_clear(&reports);
  1434. BLI_threaded_malloc_end();
  1435. MEM_freeN(frame_range_arr);
  1436. return 1;
  1437. }
  1438. else {
  1439. printf("\nError: frame number must follow '%s'.\n", arg_id);
  1440. return 0;
  1441. }
  1442. }
  1443. else {
  1444. printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
  1445. return 0;
  1446. }
  1447. }
  1448. static const char arg_handle_render_animation_doc[] =
  1449. "\n\t"
  1450. "Render frames from start to end (inclusive).";
  1451. static int arg_handle_render_animation(int UNUSED(argc), const char **UNUSED(argv), void *data)
  1452. {
  1453. bContext *C = data;
  1454. Scene *scene = CTX_data_scene(C);
  1455. if (scene) {
  1456. Main *bmain = CTX_data_main(C);
  1457. Render *re = RE_NewSceneRender(scene);
  1458. ReportList reports;
  1459. BLI_threaded_malloc_begin();
  1460. BKE_reports_init(&reports, RPT_STORE);
  1461. RE_SetReports(re, &reports);
  1462. RE_RenderAnim(re, bmain, scene, NULL, NULL, scene->r.sfra, scene->r.efra, scene->r.frame_step);
  1463. RE_SetReports(re, NULL);
  1464. BKE_reports_clear(&reports);
  1465. BLI_threaded_malloc_end();
  1466. }
  1467. else {
  1468. printf("\nError: no blend loaded. cannot use '-a'.\n");
  1469. }
  1470. return 0;
  1471. }
  1472. static const char arg_handle_scene_set_doc[] =
  1473. "<name>\n"
  1474. "\tSet the active scene <name> for rendering.";
  1475. static int arg_handle_scene_set(int argc, const char **argv, void *data)
  1476. {
  1477. if (argc > 1) {
  1478. bContext *C = data;
  1479. Scene *scene = BKE_scene_set_name(CTX_data_main(C), argv[1]);
  1480. if (scene) {
  1481. CTX_data_scene_set(C, scene);
  1482. /* Set the scene of the first window, see: T55991,
  1483. * otherwise scrips that run later won't get this scene back from the context. */
  1484. wmWindow *win = CTX_wm_window(C);
  1485. if (win == NULL) {
  1486. win = CTX_wm_manager(C)->windows.first;
  1487. }
  1488. if (win != NULL) {
  1489. WM_window_set_active_scene(CTX_data_main(C), C, win, scene);
  1490. }
  1491. }
  1492. return 1;
  1493. }
  1494. else {
  1495. printf("\nError: Scene name must follow '-S / --scene'.\n");
  1496. return 0;
  1497. }
  1498. }
  1499. static const char arg_handle_frame_start_set_doc[] =
  1500. "<frame>\n"
  1501. "\tSet start to frame <frame>, supports +/- for relative frames too.";
  1502. static int arg_handle_frame_start_set(int argc, const char **argv, void *data)
  1503. {
  1504. const char *arg_id = "-s / --frame-start";
  1505. bContext *C = data;
  1506. Scene *scene = CTX_data_scene(C);
  1507. if (scene) {
  1508. if (argc > 1) {
  1509. const char *err_msg = NULL;
  1510. if (!parse_int_relative_clamp(argv[1],
  1511. NULL,
  1512. scene->r.sfra,
  1513. scene->r.sfra - 1,
  1514. MINAFRAME,
  1515. MAXFRAME,
  1516. &scene->r.sfra,
  1517. &err_msg)) {
  1518. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1519. }
  1520. return 1;
  1521. }
  1522. else {
  1523. printf("\nError: frame number must follow '%s'.\n", arg_id);
  1524. return 0;
  1525. }
  1526. }
  1527. else {
  1528. printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
  1529. return 0;
  1530. }
  1531. }
  1532. static const char arg_handle_frame_end_set_doc[] =
  1533. "<frame>\n"
  1534. "\tSet end to frame <frame>, supports +/- for relative frames too.";
  1535. static int arg_handle_frame_end_set(int argc, const char **argv, void *data)
  1536. {
  1537. const char *arg_id = "-e / --frame-end";
  1538. bContext *C = data;
  1539. Scene *scene = CTX_data_scene(C);
  1540. if (scene) {
  1541. if (argc > 1) {
  1542. const char *err_msg = NULL;
  1543. if (!parse_int_relative_clamp(argv[1],
  1544. NULL,
  1545. scene->r.efra,
  1546. scene->r.efra - 1,
  1547. MINAFRAME,
  1548. MAXFRAME,
  1549. &scene->r.efra,
  1550. &err_msg)) {
  1551. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1552. }
  1553. return 1;
  1554. }
  1555. else {
  1556. printf("\nError: frame number must follow '%s'.\n", arg_id);
  1557. return 0;
  1558. }
  1559. }
  1560. else {
  1561. printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
  1562. return 0;
  1563. }
  1564. }
  1565. static const char arg_handle_frame_skip_set_doc[] =
  1566. "<frames>\n"
  1567. "\tSet number of frames to step forward after each rendered frame.";
  1568. static int arg_handle_frame_skip_set(int argc, const char **argv, void *data)
  1569. {
  1570. const char *arg_id = "-j / --frame-jump";
  1571. bContext *C = data;
  1572. Scene *scene = CTX_data_scene(C);
  1573. if (scene) {
  1574. if (argc > 1) {
  1575. const char *err_msg = NULL;
  1576. if (!parse_int_clamp(argv[1], NULL, 1, MAXFRAME, &scene->r.frame_step, &err_msg)) {
  1577. printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
  1578. }
  1579. return 1;
  1580. }
  1581. else {
  1582. printf("\nError: number of frames to step must follow '%s'.\n", arg_id);
  1583. return 0;
  1584. }
  1585. }
  1586. else {
  1587. printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
  1588. return 0;
  1589. }
  1590. }
  1591. static const char arg_handle_python_file_run_doc[] =
  1592. "<filename>\n"
  1593. "\tRun the given Python script file.";
  1594. static int arg_handle_python_file_run(int argc, const char **argv, void *data)
  1595. {
  1596. # ifdef WITH_PYTHON
  1597. bContext *C = data;
  1598. /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
  1599. if (argc > 1) {
  1600. /* Make the path absolute because its needed for relative linked blends to be found */
  1601. char filename[FILE_MAX];
  1602. BLI_strncpy(filename, argv[1], sizeof(filename));
  1603. BLI_path_cwd(filename, sizeof(filename));
  1604. bool ok;
  1605. BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL));
  1606. if (!ok && app_state.exit_code_on_error.python) {
  1607. printf("\nError: script failed, file: '%s', exiting.\n", argv[1]);
  1608. BPY_python_end();
  1609. exit(app_state.exit_code_on_error.python);
  1610. }
  1611. return 1;
  1612. }
  1613. else {
  1614. printf("\nError: you must specify a filepath after '%s'.\n", argv[0]);
  1615. return 0;
  1616. }
  1617. # else
  1618. UNUSED_VARS(argc, argv, data);
  1619. printf("This Blender was built without Python support\n");
  1620. return 0;
  1621. # endif /* WITH_PYTHON */
  1622. }
  1623. static const char arg_handle_python_text_run_doc[] =
  1624. "<name>\n"
  1625. "\tRun the given Python script text block.";
  1626. static int arg_handle_python_text_run(int argc, const char **argv, void *data)
  1627. {
  1628. # ifdef WITH_PYTHON
  1629. bContext *C = data;
  1630. /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
  1631. if (argc > 1) {
  1632. Main *bmain = CTX_data_main(C);
  1633. /* Make the path absolute because its needed for relative linked blends to be found */
  1634. struct Text *text = (struct Text *)BKE_libblock_find_name(bmain, ID_TXT, argv[1]);
  1635. bool ok;
  1636. if (text) {
  1637. BPY_CTX_SETUP(ok = BPY_execute_text(C, text, NULL, false));
  1638. }
  1639. else {
  1640. printf("\nError: text block not found %s.\n", argv[1]);
  1641. ok = false;
  1642. }
  1643. if (!ok && app_state.exit_code_on_error.python) {
  1644. printf("\nError: script failed, text: '%s', exiting.\n", argv[1]);
  1645. BPY_python_end();
  1646. exit(app_state.exit_code_on_error.python);
  1647. }
  1648. return 1;
  1649. }
  1650. else {
  1651. printf("\nError: you must specify a text block after '%s'.\n", argv[0]);
  1652. return 0;
  1653. }
  1654. # else
  1655. UNUSED_VARS(argc, argv, data);
  1656. printf("This Blender was built without Python support\n");
  1657. return 0;
  1658. # endif /* WITH_PYTHON */
  1659. }
  1660. static const char arg_handle_python_expr_run_doc[] =
  1661. "<expression>\n"
  1662. "\tRun the given expression as a Python script.";
  1663. static int arg_handle_python_expr_run(int argc, const char **argv, void *data)
  1664. {
  1665. # ifdef WITH_PYTHON
  1666. bContext *C = data;
  1667. /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
  1668. if (argc > 1) {
  1669. bool ok;
  1670. BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, NULL, argv[1], false));
  1671. if (!ok && app_state.exit_code_on_error.python) {
  1672. printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]);
  1673. BPY_python_end();
  1674. exit(app_state.exit_code_on_error.python);
  1675. }
  1676. return 1;
  1677. }
  1678. else {
  1679. printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]);
  1680. return 0;
  1681. }
  1682. # else
  1683. UNUSED_VARS(argc, argv, data);
  1684. printf("This Blender was built without Python support\n");
  1685. return 0;
  1686. # endif /* WITH_PYTHON */
  1687. }
  1688. static const char arg_handle_python_console_run_doc[] =
  1689. "\n\t"
  1690. "Run Blender with an interactive console.";
  1691. static int arg_handle_python_console_run(int UNUSED(argc), const char **argv, void *data)
  1692. {
  1693. # ifdef WITH_PYTHON
  1694. bContext *C = data;
  1695. BPY_CTX_SETUP(BPY_execute_string(C, (const char *[]){"code", NULL}, "code.interact()"));
  1696. return 0;
  1697. # else
  1698. UNUSED_VARS(argv, data);
  1699. printf("This Blender was built without python support\n");
  1700. return 0;
  1701. # endif /* WITH_PYTHON */
  1702. }
  1703. static const char arg_handle_python_exit_code_set_doc[] =
  1704. "<code>\n"
  1705. "\tSet the exit-code in [0..255] to exit if a Python exception is raised\n"
  1706. "\t(only for scripts executed from the command line), zero disables.";
  1707. static int arg_handle_python_exit_code_set(int argc, const char **argv, void *UNUSED(data))
  1708. {
  1709. const char *arg_id = "--python-exit-code";
  1710. if (argc > 1) {
  1711. const char *err_msg = NULL;
  1712. const int min = 0, max = 255;
  1713. int exit_code;
  1714. if (!parse_int_strict_range(argv[1], NULL, min, max, &exit_code, &err_msg)) {
  1715. printf("\nError: %s '%s %s', expected number in [%d..%d].\n",
  1716. err_msg,
  1717. arg_id,
  1718. argv[1],
  1719. min,
  1720. max);
  1721. return 1;
  1722. }
  1723. app_state.exit_code_on_error.python = (unsigned char)exit_code;
  1724. return 1;
  1725. }
  1726. else {
  1727. printf("\nError: you must specify an exit code number '%s'.\n", arg_id);
  1728. return 0;
  1729. }
  1730. }
  1731. static const char arg_handle_addons_set_doc[] =
  1732. "<addon(s)>\n"
  1733. "\tComma separated list of add-ons (no spaces).";
  1734. static int arg_handle_addons_set(int argc, const char **argv, void *data)
  1735. {
  1736. /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
  1737. if (argc > 1) {
  1738. # ifdef WITH_PYTHON
  1739. const char script_str[] =
  1740. "from addon_utils import check, enable\n"
  1741. "for m in '%s'.split(','):\n"
  1742. " if check(m)[1] is False:\n"
  1743. " enable(m, persistent=True)";
  1744. const int slen = strlen(argv[1]) + (sizeof(script_str) - 2);
  1745. char *str = malloc(slen);
  1746. bContext *C = data;
  1747. BLI_snprintf(str, slen, script_str, argv[1]);
  1748. BLI_assert(strlen(str) + 1 == slen);
  1749. BPY_CTX_SETUP(BPY_execute_string_ex(C, NULL, str, false));
  1750. free(str);
  1751. # else
  1752. UNUSED_VARS(argv, data);
  1753. # endif /* WITH_PYTHON */
  1754. return 1;
  1755. }
  1756. else {
  1757. printf("\nError: you must specify a comma separated list after '--addons'.\n");
  1758. return 0;
  1759. }
  1760. }
  1761. static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
  1762. {
  1763. bContext *C = data;
  1764. ReportList reports;
  1765. bool success;
  1766. /* Make the path absolute because its needed for relative linked blends to be found */
  1767. char filename[FILE_MAX];
  1768. /* note, we could skip these, but so far we always tried to load these files */
  1769. if (argv[0][0] == '-') {
  1770. fprintf(stderr, "unknown argument, loading as file: %s\n", argv[0]);
  1771. }
  1772. BLI_strncpy(filename, argv[0], sizeof(filename));
  1773. BLI_path_cwd(filename, sizeof(filename));
  1774. /* load the file */
  1775. BKE_reports_init(&reports, RPT_PRINT);
  1776. WM_file_autoexec_init(filename);
  1777. success = WM_file_read(C, filename, &reports);
  1778. BKE_reports_clear(&reports);
  1779. if (success) {
  1780. if (G.background) {
  1781. /* ensuer we use 'C->data.scene' for background render */
  1782. CTX_wm_window_set(C, NULL);
  1783. }
  1784. }
  1785. else {
  1786. /* failed to load file, stop processing arguments if running in background mode */
  1787. if (G.background) {
  1788. /* Set is_break if running in the background mode so
  1789. * blender will return non-zero exit code which then
  1790. * could be used in automated script to control how
  1791. * good or bad things are.
  1792. */
  1793. G.is_break = true;
  1794. return -1;
  1795. }
  1796. if (BLO_has_bfile_extension(filename)) {
  1797. /* Just pretend a file was loaded, so the user can press Save and it'll
  1798. * save at the filename from the CLI. */
  1799. BLI_strncpy(G_MAIN->name, filename, FILE_MAX);
  1800. G.relbase_valid = true;
  1801. G.save_over = true;
  1802. printf("... opened default scene instead; saving will write to: %s\n", filename);
  1803. }
  1804. else {
  1805. printf(
  1806. "Error: argument has no '.blend' file extension, not using as new file, exiting! %s\n",
  1807. filename);
  1808. G.is_break = true;
  1809. WM_exit(C);
  1810. }
  1811. }
  1812. G.file_loaded = 1;
  1813. return 0;
  1814. }
  1815. void main_args_setup(bContext *C, bArgs *ba)
  1816. {
  1817. # define CB(a) a##_doc, a
  1818. # define CB_EX(a, b) a##_doc_##b, a
  1819. // BLI_argsAdd(ba, pass, short_arg, long_arg, doc, cb, C);
  1820. /* end argument processing after -- */
  1821. BLI_argsAdd(ba, -1, "--", NULL, CB(arg_handle_arguments_end), NULL);
  1822. /* first pass: background mode, disable python and commands that exit after usage */
  1823. BLI_argsAdd(ba, 1, "-h", "--help", CB(arg_handle_print_help), ba);
  1824. /* Windows only */
  1825. BLI_argsAdd(ba, 1, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba);
  1826. BLI_argsAdd(ba, 1, "-v", "--version", CB(arg_handle_print_version), NULL);
  1827. BLI_argsAdd(
  1828. ba, 1, "-y", "--enable-autoexec", CB_EX(arg_handle_python_set, enable), (void *)true);
  1829. BLI_argsAdd(
  1830. ba, 1, "-Y", "--disable-autoexec", CB_EX(arg_handle_python_set, disable), (void *)false);
  1831. BLI_argsAdd(ba, 1, NULL, "--disable-crash-handler", CB(arg_handle_crash_handler_disable), NULL);
  1832. BLI_argsAdd(ba, 1, NULL, "--disable-abort-handler", CB(arg_handle_abort_handler_disable), NULL);
  1833. BLI_argsAdd(ba, 1, "-b", "--background", CB(arg_handle_background_mode_set), NULL);
  1834. BLI_argsAdd(ba, 1, "-a", NULL, CB(arg_handle_playback_mode), NULL);
  1835. BLI_argsAdd(ba, 1, NULL, "--log", CB(arg_handle_log_set), ba);
  1836. BLI_argsAdd(ba, 1, NULL, "--log-level", CB(arg_handle_log_level_set), ba);
  1837. BLI_argsAdd(ba, 1, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba);
  1838. BLI_argsAdd(ba, 1, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba);
  1839. BLI_argsAdd(ba, 1, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba);
  1840. BLI_argsAdd(ba, 1, NULL, "--log-file", CB(arg_handle_log_file_set), ba);
  1841. BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);
  1842. # ifdef WITH_FFMPEG
  1843. BLI_argsAdd(ba,
  1844. 1,
  1845. NULL,
  1846. "--debug-ffmpeg",
  1847. CB_EX(arg_handle_debug_mode_generic_set, ffmpeg),
  1848. (void *)G_DEBUG_FFMPEG);
  1849. # endif
  1850. # ifdef WITH_FREESTYLE
  1851. BLI_argsAdd(ba,
  1852. 1,
  1853. NULL,
  1854. "--debug-freestyle",
  1855. CB_EX(arg_handle_debug_mode_generic_set, freestyle),
  1856. (void *)G_DEBUG_FREESTYLE);
  1857. # endif
  1858. BLI_argsAdd(ba,
  1859. 1,
  1860. NULL,
  1861. "--debug-python",
  1862. CB_EX(arg_handle_debug_mode_generic_set, python),
  1863. (void *)G_DEBUG_PYTHON);
  1864. BLI_argsAdd(ba,
  1865. 1,
  1866. NULL,
  1867. "--debug-events",
  1868. CB_EX(arg_handle_debug_mode_generic_set, events),
  1869. (void *)G_DEBUG_EVENTS);
  1870. BLI_argsAdd(ba,
  1871. 1,
  1872. NULL,
  1873. "--debug-handlers",
  1874. CB_EX(arg_handle_debug_mode_generic_set, handlers),
  1875. (void *)G_DEBUG_HANDLERS);
  1876. BLI_argsAdd(
  1877. ba, 1, NULL, "--debug-wm", CB_EX(arg_handle_debug_mode_generic_set, wm), (void *)G_DEBUG_WM);
  1878. BLI_argsAdd(ba, 1, NULL, "--debug-all", CB(arg_handle_debug_mode_all), NULL);
  1879. BLI_argsAdd(ba, 1, NULL, "--debug-io", CB(arg_handle_debug_mode_io), NULL);
  1880. BLI_argsAdd(ba, 1, NULL, "--debug-fpe", CB(arg_handle_debug_fpe_set), NULL);
  1881. # ifdef WITH_LIBMV
  1882. BLI_argsAdd(ba, 1, NULL, "--debug-libmv", CB(arg_handle_debug_mode_libmv), NULL);
  1883. # endif
  1884. # ifdef WITH_CYCLES_LOGGING
  1885. BLI_argsAdd(ba, 1, NULL, "--debug-cycles", CB(arg_handle_debug_mode_cycles), NULL);
  1886. # endif
  1887. BLI_argsAdd(ba, 1, NULL, "--debug-memory", CB(arg_handle_debug_mode_memory_set), NULL);
  1888. BLI_argsAdd(ba, 1, NULL, "--debug-value", CB(arg_handle_debug_value_set), NULL);
  1889. BLI_argsAdd(ba,
  1890. 1,
  1891. NULL,
  1892. "--debug-jobs",
  1893. CB_EX(arg_handle_debug_mode_generic_set, jobs),
  1894. (void *)G_DEBUG_JOBS);
  1895. BLI_argsAdd(ba,
  1896. 1,
  1897. NULL,
  1898. "--debug-gpu",
  1899. CB_EX(arg_handle_debug_mode_generic_set, gpu),
  1900. (void *)G_DEBUG_GPU);
  1901. BLI_argsAdd(ba,
  1902. 1,
  1903. NULL,
  1904. "--debug-depsgraph",
  1905. CB_EX(arg_handle_debug_mode_generic_set, depsgraph),
  1906. (void *)G_DEBUG_DEPSGRAPH);
  1907. BLI_argsAdd(ba,
  1908. 1,
  1909. NULL,
  1910. "--debug-depsgraph-build",
  1911. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_build),
  1912. (void *)G_DEBUG_DEPSGRAPH_BUILD);
  1913. BLI_argsAdd(ba,
  1914. 1,
  1915. NULL,
  1916. "--debug-depsgraph-eval",
  1917. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_eval),
  1918. (void *)G_DEBUG_DEPSGRAPH_EVAL);
  1919. BLI_argsAdd(ba,
  1920. 1,
  1921. NULL,
  1922. "--debug-depsgraph-tag",
  1923. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_tag),
  1924. (void *)G_DEBUG_DEPSGRAPH_TAG);
  1925. BLI_argsAdd(ba,
  1926. 1,
  1927. NULL,
  1928. "--debug-depsgraph-time",
  1929. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_time),
  1930. (void *)G_DEBUG_DEPSGRAPH_TIME);
  1931. BLI_argsAdd(ba,
  1932. 1,
  1933. NULL,
  1934. "--debug-depsgraph-no-threads",
  1935. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_no_threads),
  1936. (void *)G_DEBUG_DEPSGRAPH_NO_THREADS);
  1937. BLI_argsAdd(ba,
  1938. 1,
  1939. NULL,
  1940. "--debug-depsgraph-pretty",
  1941. CB_EX(arg_handle_debug_mode_generic_set, depsgraph_pretty),
  1942. (void *)G_DEBUG_DEPSGRAPH_PRETTY);
  1943. BLI_argsAdd(ba,
  1944. 1,
  1945. NULL,
  1946. "--debug-gpumem",
  1947. CB_EX(arg_handle_debug_mode_generic_set, gpumem),
  1948. (void *)G_DEBUG_GPU_MEM);
  1949. BLI_argsAdd(ba,
  1950. 1,
  1951. NULL,
  1952. "--debug-gpu-shaders",
  1953. CB_EX(arg_handle_debug_mode_generic_set, gpumem),
  1954. (void *)G_DEBUG_GPU_SHADERS);
  1955. BLI_argsAdd(ba,
  1956. 1,
  1957. NULL,
  1958. "--debug-gpu-force-workarounds",
  1959. CB_EX(arg_handle_debug_mode_generic_set, gpumem),
  1960. (void *)G_DEBUG_GPU_FORCE_WORKAROUNDS);
  1961. BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
  1962. BLI_argsAdd(ba, 1, NULL, "--app-template", CB(arg_handle_app_template), NULL);
  1963. BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
  1964. BLI_argsAdd(
  1965. ba, 1, NULL, "--enable-library-override", CB(arg_handle_enable_override_library), NULL);
  1966. BLI_argsAdd(ba, 1, NULL, "--enable-event-simulate", CB(arg_handle_enable_event_simulate), NULL);
  1967. /* TODO, add user env vars? */
  1968. BLI_argsAdd(
  1969. ba, 1, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
  1970. BLI_argsAdd(
  1971. ba, 1, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
  1972. BLI_argsAdd(ba, 1, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
  1973. /* second pass: custom window stuff */
  1974. BLI_argsAdd(ba, 2, "-p", "--window-geometry", CB(arg_handle_window_geometry), NULL);
  1975. BLI_argsAdd(ba, 2, "-w", "--window-border", CB(arg_handle_with_borders), NULL);
  1976. BLI_argsAdd(ba, 2, "-W", "--window-fullscreen", CB(arg_handle_without_borders), NULL);
  1977. BLI_argsAdd(ba, 2, "-M", "--window-maximized", CB(arg_handle_window_maximized), NULL);
  1978. BLI_argsAdd(ba, 2, NULL, "--no-window-focus", CB(arg_handle_no_window_focus), NULL);
  1979. BLI_argsAdd(ba, 2, "-con", "--start-console", CB(arg_handle_start_with_console), NULL);
  1980. BLI_argsAdd(ba, 2, "-R", NULL, CB(arg_handle_register_extension), NULL);
  1981. BLI_argsAdd(ba, 2, "-r", NULL, CB_EX(arg_handle_register_extension, silent), ba);
  1982. BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba);
  1983. /* third pass: disabling things and forcing settings */
  1984. BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL);
  1985. BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL);
  1986. /* fourth pass: processing arguments */
  1987. BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C);
  1988. BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C);
  1989. BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);
  1990. BLI_argsAdd(ba, 4, "-s", "--frame-start", CB(arg_handle_frame_start_set), C);
  1991. BLI_argsAdd(ba, 4, "-e", "--frame-end", CB(arg_handle_frame_end_set), C);
  1992. BLI_argsAdd(ba, 4, "-j", "--frame-jump", CB(arg_handle_frame_skip_set), C);
  1993. BLI_argsAdd(ba, 4, "-P", "--python", CB(arg_handle_python_file_run), C);
  1994. BLI_argsAdd(ba, 4, NULL, "--python-text", CB(arg_handle_python_text_run), C);
  1995. BLI_argsAdd(ba, 4, NULL, "--python-expr", CB(arg_handle_python_expr_run), C);
  1996. BLI_argsAdd(ba, 4, NULL, "--python-console", CB(arg_handle_python_console_run), C);
  1997. BLI_argsAdd(ba, 4, NULL, "--python-exit-code", CB(arg_handle_python_exit_code_set), NULL);
  1998. BLI_argsAdd(ba, 4, NULL, "--addons", CB(arg_handle_addons_set), C);
  1999. BLI_argsAdd(ba, 4, "-o", "--render-output", CB(arg_handle_output_set), C);
  2000. BLI_argsAdd(ba, 4, "-E", "--engine", CB(arg_handle_engine_set), C);
  2001. BLI_argsAdd(ba, 4, "-F", "--render-format", CB(arg_handle_image_type_set), C);
  2002. BLI_argsAdd(ba, 1, "-t", "--threads", CB(arg_handle_threads_set), NULL);
  2003. BLI_argsAdd(ba, 4, "-x", "--use-extension", CB(arg_handle_extension_set), C);
  2004. # undef CB
  2005. # undef CB_EX
  2006. }
  2007. /**
  2008. * Needs to be added separately.
  2009. */
  2010. void main_args_setup_post(bContext *C, bArgs *ba)
  2011. {
  2012. BLI_argsParse(ba, 4, arg_handle_load_file, C);
  2013. }
  2014. /** \} */
  2015. #endif /* WITH_PYTHON_MODULE */