|
Blender V2.27
|
00001 /* 00002 * $Id: creator.c 34545 2011-01-28 15:24:02Z jhk $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00030 #if defined(__linux__) && defined(__GNUC__) 00031 #define _GNU_SOURCE 00032 #include <fenv.h> 00033 #endif 00034 00035 #define OSX_SSE_FPE (defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))) 00036 00037 #if OSX_SSE_FPE 00038 #include <xmmintrin.h> 00039 #endif 00040 00041 #include <stdlib.h> 00042 #include <string.h> 00043 00044 /* for setuid / getuid */ 00045 #ifdef __sgi 00046 #include <sys/types.h> 00047 #include <unistd.h> 00048 #endif 00049 00050 /* This little block needed for linking to Blender... */ 00051 00052 #include "MEM_guardedalloc.h" 00053 00054 #ifdef WIN32 00055 #include "BLI_winstuff.h" 00056 #endif 00057 00058 #include "BLI_args.h" 00059 #include "BLI_threads.h" 00060 #include "BLI_scanfill.h" // for BLI_setErrorCallBack, TODO, move elsewhere 00061 #include "BLI_utildefines.h" 00062 00063 #include "DNA_ID.h" 00064 #include "DNA_scene_types.h" 00065 00066 #include "BLI_blenlib.h" 00067 00068 #include "BKE_utildefines.h" 00069 #include "BKE_blender.h" 00070 #include "BKE_context.h" 00071 #include "BKE_depsgraph.h" // for DAG_on_load_update 00072 #include "BKE_font.h" 00073 #include "BKE_global.h" 00074 #include "BKE_main.h" 00075 #include "BKE_material.h" 00076 #include "BKE_packedFile.h" 00077 #include "BKE_scene.h" 00078 #include "BKE_node.h" 00079 #include "BKE_report.h" 00080 #include "BKE_sound.h" 00081 00082 #include "IMB_imbuf.h" // for IMB_init 00083 00084 #ifdef WITH_PYTHON 00085 #include "BPY_extern.h" 00086 #endif 00087 00088 #include "RE_pipeline.h" 00089 00090 //XXX #include "playanim_ext.h" 00091 #include "ED_datafiles.h" 00092 00093 #include "WM_api.h" 00094 00095 #include "RNA_define.h" 00096 00097 #include "GPU_draw.h" 00098 #include "GPU_extensions.h" 00099 00100 /* for passing information between creator and gameengine */ 00101 #ifdef WITH_GAMEENGINE 00102 #include "GEN_messaging.h" 00103 #include "SYS_System.h" 00104 #else /* dummy */ 00105 #define SYS_SystemHandle int 00106 #endif 00107 00108 #include <signal.h> 00109 00110 #ifdef __FreeBSD__ 00111 # include <sys/types.h> 00112 # include <floatingpoint.h> 00113 # include <sys/rtprio.h> 00114 #endif 00115 00116 #ifdef WITH_BINRELOC 00117 #include "binreloc.h" 00118 #endif 00119 00120 // from buildinfo.c 00121 #ifdef BUILD_DATE 00122 extern char build_date[]; 00123 extern char build_time[]; 00124 extern char build_rev[]; 00125 extern char build_platform[]; 00126 extern char build_type[]; 00127 extern char build_cflags[]; 00128 extern char build_cxxflags[]; 00129 extern char build_linkflags[]; 00130 extern char build_system[]; 00131 #endif 00132 00133 /* Local Function prototypes */ 00134 static int print_help(int argc, char **argv, void *data); 00135 static int print_version(int argc, char **argv, void *data); 00136 00137 /* for the callbacks: */ 00138 00139 extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */ 00140 00141 char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */ 00142 char btempdir[FILE_MAXDIR+FILE_MAXFILE]; 00143 00144 #define BLEND_VERSION_STRING_FMT "Blender %d.%02d (sub %d) Build\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION 00145 00146 /* Initialise callbacks for the modules that need them */ 00147 static void setCallbacks(void); 00148 00149 /* set breakpoints here when running in debug mode, useful to catch floating point errors */ 00150 #if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE 00151 static void fpe_handler(int UNUSED(sig)) 00152 { 00153 // printf("SIGFPE trapped\n"); 00154 } 00155 #endif 00156 00157 /* handling ctrl-c event in console */ 00158 static void blender_esc(int sig) 00159 { 00160 static int count = 0; 00161 00162 G.afbreek = 1; /* forces render loop to read queue, not sure if its needed */ 00163 00164 if (sig == 2) { 00165 if (count) { 00166 printf("\nBlender killed\n"); 00167 exit(2); 00168 } 00169 printf("\nSent an internal break event. Press ^C again to kill Blender\n"); 00170 count++; 00171 } 00172 } 00173 00174 /* buildinfo can have quotes */ 00175 #ifdef BUILD_DATE 00176 static void strip_quotes(char *str) 00177 { 00178 if(str[0] == '"') { 00179 int len= strlen(str) - 1; 00180 memmove(str, str+1, len); 00181 if(str[len-1] == '"') { 00182 str[len-1]= '\0'; 00183 } 00184 } 00185 } 00186 #endif 00187 00188 static int print_version(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00189 { 00190 printf (BLEND_VERSION_STRING_FMT); 00191 #ifdef BUILD_DATE 00192 printf ("\tbuild date: %s\n", build_date); 00193 printf ("\tbuild time: %s\n", build_time); 00194 printf ("\tbuild revision: %s\n", build_rev); 00195 printf ("\tbuild platform: %s\n", build_platform); 00196 printf ("\tbuild type: %s\n", build_type); 00197 printf ("\tbuild c flags: %s\n", build_cflags); 00198 printf ("\tbuild c++ flags: %s\n", build_cxxflags); 00199 printf ("\tbuild link flags: %s\n", build_linkflags); 00200 printf ("\tbuild system: %s\n", build_system); 00201 #endif 00202 exit(0); 00203 00204 return 0; 00205 } 00206 00207 static int print_help(int UNUSED(argc), char **UNUSED(argv), void *data) 00208 { 00209 bArgs *ba = (bArgs*)data; 00210 00211 printf (BLEND_VERSION_STRING_FMT); 00212 printf ("Usage: blender [args ...] [file] [args ...]\n\n"); 00213 00214 printf ("Render Options:\n"); 00215 BLI_argsPrintArgDoc(ba, "--background"); 00216 BLI_argsPrintArgDoc(ba, "--render-anim"); 00217 BLI_argsPrintArgDoc(ba, "--scene"); 00218 BLI_argsPrintArgDoc(ba, "--render-frame"); 00219 BLI_argsPrintArgDoc(ba, "--frame-start"); 00220 BLI_argsPrintArgDoc(ba, "--frame-end"); 00221 BLI_argsPrintArgDoc(ba, "--frame-jump"); 00222 BLI_argsPrintArgDoc(ba, "--render-output"); 00223 BLI_argsPrintArgDoc(ba, "--engine"); 00224 00225 printf("\n"); 00226 printf ("Format Options:\n"); 00227 BLI_argsPrintArgDoc(ba, "--render-format"); 00228 BLI_argsPrintArgDoc(ba, "--use-extension"); 00229 BLI_argsPrintArgDoc(ba, "--threads"); 00230 00231 printf("\n"); 00232 printf ("Animation Playback Options:\n"); 00233 BLI_argsPrintArgDoc(ba, "-a"); 00234 00235 printf("\n"); 00236 printf ("Window Options:\n"); 00237 BLI_argsPrintArgDoc(ba, "--window-border"); 00238 BLI_argsPrintArgDoc(ba, "--window-borderless"); 00239 BLI_argsPrintArgDoc(ba, "--window-geometry"); 00240 00241 printf("\n"); 00242 printf ("Game Engine Specific Options:\n"); 00243 BLI_argsPrintArgDoc(ba, "-g"); 00244 00245 printf("\n"); 00246 printf ("Misc Options:\n"); 00247 BLI_argsPrintArgDoc(ba, "--debug"); 00248 BLI_argsPrintArgDoc(ba, "--debug-fpe"); 00249 printf("\n"); 00250 BLI_argsPrintArgDoc(ba, "--factory-startup"); 00251 printf("\n"); 00252 BLI_argsPrintArgDoc(ba, "--env-system-config"); 00253 BLI_argsPrintArgDoc(ba, "--env-system-datafiles"); 00254 BLI_argsPrintArgDoc(ba, "--env-system-scripts"); 00255 BLI_argsPrintArgDoc(ba, "--env-system-plugins"); 00256 BLI_argsPrintArgDoc(ba, "--env-system-python"); 00257 printf("\n"); 00258 BLI_argsPrintArgDoc(ba, "-nojoystick"); 00259 BLI_argsPrintArgDoc(ba, "-noglsl"); 00260 BLI_argsPrintArgDoc(ba, "-noaudio"); 00261 BLI_argsPrintArgDoc(ba, "-setaudio"); 00262 00263 printf("\n"); 00264 00265 BLI_argsPrintArgDoc(ba, "--help"); 00266 00267 printf("\n"); 00268 00269 BLI_argsPrintArgDoc(ba, "--enable-autoexec"); 00270 BLI_argsPrintArgDoc(ba, "--disable-autoexec"); 00271 00272 printf("\n"); 00273 00274 BLI_argsPrintArgDoc(ba, "--python"); 00275 BLI_argsPrintArgDoc(ba, "--python-console"); 00276 BLI_argsPrintArgDoc(ba, "--addons"); 00277 00278 #ifdef WIN32 00279 BLI_argsPrintArgDoc(ba, "-R"); 00280 #endif 00281 BLI_argsPrintArgDoc(ba, "--version"); 00282 00283 BLI_argsPrintArgDoc(ba, "--"); 00284 00285 printf ("Other Options:\n"); 00286 BLI_argsPrintOtherDoc(ba); 00287 00288 printf ("Argument Parsing:\n"); 00289 printf ("\targuments must be separated by white space. eg\n"); 00290 printf ("\t\t\"blender -ba test.blend\"\n"); 00291 printf ("\t...will ignore the 'a'\n"); 00292 printf ("\t\t\"blender -b test.blend -f8\"\n"); 00293 printf ("\t...will ignore 8 because there is no space between the -f and the frame value\n\n"); 00294 00295 printf ("Argument Order:\n"); 00296 printf ("Arguments are executed in the order they are given. eg\n"); 00297 printf ("\t\t\"blender --background test.blend --render-frame 1 --render-output /tmp\"\n"); 00298 printf ("\t...will not render to /tmp because '--render-frame 1' renders before the output path is set\n"); 00299 printf ("\t\t\"blender --background --render-output /tmp test.blend --render-frame 1\"\n"); 00300 printf ("\t...will not render to /tmp because loading the blend file overwrites the render output that was set\n"); 00301 printf ("\t\t\"blender --background test.blend --render-output /tmp --render-frame 1\" works as expected.\n\n"); 00302 00303 printf ("\nEnvironment Variables:\n"); 00304 printf (" $BLENDER_USER_CONFIG Directory for user configuration files.\n"); 00305 printf (" $BLENDER_SYSTEM_CONFIG Directory for system wide configuration files.\n"); 00306 printf (" $BLENDER_USER_SCRIPTS Directory for user scripts.\n"); 00307 printf (" $BLENDER_SYSTEM_SCRIPTS Directory for system wide scripts.\n"); 00308 printf (" $BLENDER_USER_DATAFILES Directory for user data files (icons, translations, ..).\n"); 00309 printf (" $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n"); 00310 printf (" $BLENDER_SYSTEM_PYTHON Directory for system python libraries.\n"); 00311 #ifdef WIN32 00312 printf (" $TEMP Store temporary files here.\n"); 00313 #else 00314 printf (" $TMP or $TMPDIR Store temporary files here.\n"); 00315 #endif 00316 #ifndef DISABLE_SDL 00317 printf (" $SDL_AUDIODRIVER LibSDL audio driver - alsa, esd, dma.\n"); 00318 #endif 00319 printf (" $PYTHONHOME Path to the python directory, eg. /usr/lib/python.\n\n"); 00320 00321 exit(0); 00322 00323 return 0; 00324 } 00325 00326 00327 double PIL_check_seconds_timer(void); 00328 00329 /* XXX This was here to fix a crash when running python scripts 00330 * with -P that used the screen. 00331 * 00332 * static void main_init_screen( void ) 00333 { 00334 setscreen(G.curscreen); 00335 00336 if(G.main->scene.first==0) { 00337 set_scene( add_scene("1") ); 00338 } 00339 }*/ 00340 00341 static int end_arguments(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00342 { 00343 return -1; 00344 } 00345 00346 static int enable_python(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00347 { 00348 G.f |= G_SCRIPT_AUTOEXEC; 00349 return 0; 00350 } 00351 00352 static int disable_python(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00353 { 00354 G.f &= ~G_SCRIPT_AUTOEXEC; 00355 return 0; 00356 } 00357 00358 static int background_mode(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00359 { 00360 G.background = 1; 00361 return 0; 00362 } 00363 00364 static int debug_mode(int UNUSED(argc), char **UNUSED(argv), void *data) 00365 { 00366 G.f |= G_DEBUG; /* std output printf's */ 00367 printf(BLEND_VERSION_STRING_FMT); 00368 MEM_set_memory_debug(); 00369 00370 #ifdef NAN_BUILDINFO 00371 printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type); 00372 #endif // NAN_BUILDINFO 00373 00374 BLI_argsPrint(data); 00375 return 0; 00376 } 00377 00378 static int set_fpe(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00379 { 00380 #if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE 00381 /* zealous but makes float issues a heck of a lot easier to find! 00382 * set breakpoints on fpe_handler */ 00383 signal(SIGFPE, fpe_handler); 00384 00385 # if defined(__linux__) && defined(__GNUC__) 00386 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW ); 00387 # endif /* defined(__linux__) && defined(__GNUC__) */ 00388 # if OSX_SSE_FPE 00389 /* OSX uses SSE for floating point by default, so here 00390 * use SSE instructions to throw floating point exceptions */ 00391 _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK &~ 00392 (_MM_MASK_OVERFLOW|_MM_MASK_INVALID|_MM_MASK_DIV_ZERO)); 00393 # endif /* OSX_SSE_FPE */ 00394 # if defined(_WIN32) && defined(_MSC_VER) 00395 _controlfp_s(NULL, 0, _MCW_EM); /* enables all fp exceptions */ 00396 _controlfp_s(NULL, _EM_DENORMAL | _EM_UNDERFLOW | _EM_INEXACT, _MCW_EM); /* hide the ones we don't care about */ 00397 # endif /* _WIN32 && _MSC_VER */ 00398 #endif 00399 00400 return 0; 00401 } 00402 00403 static int set_factory_startup(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00404 { 00405 G.factory_startup= 1; 00406 return 0; 00407 } 00408 00409 static int set_env(int argc, char **argv, void *UNUSED(data)) 00410 { 00411 /* "--env-system-scripts" --> "BLENDER_SYSTEM_SCRIPTS" */ 00412 00413 char env[64]= "BLENDER"; 00414 char *ch_dst= env + 7; /* skip BLENDER */ 00415 char *ch_src= argv[0] + 5; /* skip --env */ 00416 00417 if (argc < 2) { 00418 printf("%s requires one argument\n", argv[0]); 00419 exit(1); 00420 } 00421 00422 for(; *ch_src; ch_src++, ch_dst++) { 00423 *ch_dst= (*ch_src == '-') ? '_' : (*ch_src)-32; /* toupper() */ 00424 } 00425 00426 *ch_dst= '\0'; 00427 BLI_setenv(env, argv[1]); 00428 return 1; 00429 } 00430 00431 static int playback_mode(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00432 { 00433 /* not if -b was given first */ 00434 if (G.background == 0) { 00435 00436 // XXX playanim(argc, argv); /* not the same argc and argv as before */ 00437 exit(0); 00438 } 00439 00440 return -2; 00441 } 00442 00443 static int prefsize(int argc, char **argv, void *UNUSED(data)) 00444 { 00445 int stax, stay, sizx, sizy; 00446 00447 if (argc < 5) { 00448 printf ("-p requires four arguments\n"); 00449 exit(1); 00450 } 00451 00452 stax= atoi(argv[1]); 00453 stay= atoi(argv[2]); 00454 sizx= atoi(argv[3]); 00455 sizy= atoi(argv[4]); 00456 00457 WM_setprefsize(stax, stay, sizx, sizy); 00458 00459 return 4; 00460 } 00461 00462 static int with_borders(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00463 { 00464 WM_setinitialstate_normal(); 00465 return 0; 00466 } 00467 00468 static int without_borders(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00469 { 00470 WM_setinitialstate_fullscreen(); 00471 return 0; 00472 } 00473 00474 static int register_extension(int UNUSED(argc), char **UNUSED(argv), void *data) 00475 { 00476 #ifdef WIN32 00477 char *path = BLI_argsArgv(data)[0]; 00478 RegisterBlendExtension(path); 00479 #else 00480 (void)data; /* unused */ 00481 #endif 00482 00483 return 0; 00484 } 00485 00486 static int no_joystick(int UNUSED(argc), char **UNUSED(argv), void *data) 00487 { 00488 #ifndef WITH_GAMEENGINE 00489 (void)data; 00490 #else 00491 SYS_SystemHandle *syshandle = data; 00492 00497 SYS_WriteCommandLineInt(*syshandle, "nojoystick",1); 00498 if (G.f & G_DEBUG) printf("disabling nojoystick\n"); 00499 #endif 00500 00501 return 0; 00502 } 00503 00504 static int no_glsl(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00505 { 00506 GPU_extensions_disable(); 00507 return 0; 00508 } 00509 00510 static int no_audio(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) 00511 { 00512 sound_force_device(0); 00513 return 0; 00514 } 00515 00516 static int set_audio(int argc, char **argv, void *UNUSED(data)) 00517 { 00518 if (argc < 1) { 00519 printf("-setaudio require one argument\n"); 00520 exit(1); 00521 } 00522 00523 sound_force_device(sound_define_from_str(argv[1])); 00524 return 1; 00525 } 00526 00527 static int set_output(int argc, char **argv, void *data) 00528 { 00529 bContext *C = data; 00530 if (argc >= 1){ 00531 if (CTX_data_scene(C)) { 00532 Scene *scene= CTX_data_scene(C); 00533 BLI_strncpy(scene->r.pic, argv[1], FILE_MAXDIR); 00534 } else { 00535 printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n"); 00536 } 00537 return 1; 00538 } else { 00539 printf("\nError: you must specify a path after '-o / --render-output'.\n"); 00540 return 0; 00541 } 00542 } 00543 00544 static int set_engine(int argc, char **argv, void *data) 00545 { 00546 bContext *C = data; 00547 if (argc >= 1) 00548 { 00549 if (!strcmp(argv[1],"help")) 00550 { 00551 RenderEngineType *type = NULL; 00552 00553 for( type = R_engines.first; type; type = type->next ) 00554 { 00555 printf("\t%s\n", type->idname); 00556 } 00557 exit(0); 00558 } 00559 else 00560 { 00561 if (CTX_data_scene(C)==NULL) 00562 { 00563 printf("\nError: no blend loaded. order the arguments so '-E / --engine ' is after a blend is loaded.\n"); 00564 } 00565 else 00566 { 00567 Scene *scene= CTX_data_scene(C); 00568 RenderData *rd = &scene->r; 00569 RenderEngineType *type = NULL; 00570 00571 for( type = R_engines.first; type; type = type->next ) 00572 { 00573 if (!strcmp(argv[1],type->idname)) 00574 { 00575 BLI_strncpy(rd->engine, type->idname, sizeof(rd->engine)); 00576 } 00577 } 00578 } 00579 } 00580 00581 return 1; 00582 } 00583 else 00584 { 00585 printf("\nEngine not specified.\n"); 00586 return 0; 00587 } 00588 } 00589 00590 static int set_image_type(int argc, char **argv, void *data) 00591 { 00592 bContext *C = data; 00593 if (argc >= 1){ 00594 char *imtype = argv[1]; 00595 if (CTX_data_scene(C)==NULL) { 00596 printf("\nError: no blend loaded. order the arguments so '-F / --render-format' is after the blend is loaded.\n"); 00597 } else { 00598 Scene *scene= CTX_data_scene(C); 00599 if (!strcmp(imtype,"TGA")) scene->r.imtype = R_TARGA; 00600 else if (!strcmp(imtype,"IRIS")) scene->r.imtype = R_IRIS; 00601 #ifdef WITH_DDS 00602 else if (!strcmp(imtype,"DDS")) scene->r.imtype = R_DDS; 00603 #endif 00604 else if (!strcmp(imtype,"JPEG")) scene->r.imtype = R_JPEG90; 00605 else if (!strcmp(imtype,"IRIZ")) scene->r.imtype = R_IRIZ; 00606 else if (!strcmp(imtype,"RAWTGA")) scene->r.imtype = R_RAWTGA; 00607 else if (!strcmp(imtype,"AVIRAW")) scene->r.imtype = R_AVIRAW; 00608 else if (!strcmp(imtype,"AVIJPEG")) scene->r.imtype = R_AVIJPEG; 00609 else if (!strcmp(imtype,"PNG")) scene->r.imtype = R_PNG; 00610 else if (!strcmp(imtype,"AVICODEC")) scene->r.imtype = R_AVICODEC; 00611 else if (!strcmp(imtype,"QUICKTIME")) scene->r.imtype = R_QUICKTIME; 00612 else if (!strcmp(imtype,"BMP")) scene->r.imtype = R_BMP; 00613 #ifdef WITH_HDR 00614 else if (!strcmp(imtype,"HDR")) scene->r.imtype = R_RADHDR; 00615 #endif 00616 #ifdef WITH_TIFF 00617 else if (!strcmp(imtype,"TIFF")) scene->r.imtype = R_TIFF; 00618 #endif 00619 #ifdef WITH_OPENEXR 00620 else if (!strcmp(imtype,"EXR")) scene->r.imtype = R_OPENEXR; 00621 else if (!strcmp(imtype,"MULTILAYER")) scene->r.imtype = R_MULTILAYER; 00622 #endif 00623 else if (!strcmp(imtype,"MPEG")) scene->r.imtype = R_FFMPEG; 00624 else if (!strcmp(imtype,"FRAMESERVER")) scene->r.imtype = R_FRAMESERVER; 00625 #ifdef WITH_CINEON 00626 else if (!strcmp(imtype,"CINEON")) scene->r.imtype = R_CINEON; 00627 else if (!strcmp(imtype,"DPX")) scene->r.imtype = R_DPX; 00628 #endif 00629 #if WITH_OPENJPEG 00630 else if (!strcmp(imtype,"JP2")) scene->r.imtype = R_JP2; 00631 #endif 00632 else printf("\nError: Format from '-F / --render-format' not known or not compiled in this release.\n"); 00633 } 00634 return 1; 00635 } else { 00636 printf("\nError: you must specify a format after '-F / --render-foramt'.\n"); 00637 return 0; 00638 } 00639 } 00640 00641 static int set_threads(int argc, char **argv, void *UNUSED(data)) 00642 { 00643 if (argc >= 1) { 00644 if(G.background) { 00645 RE_set_max_threads(atoi(argv[1])); 00646 } else { 00647 printf("Warning: threads can only be set in background mode\n"); 00648 } 00649 return 1; 00650 } else { 00651 printf("\nError: you must specify a number of threads between 0 and 8 '-t / --threads'.\n"); 00652 return 0; 00653 } 00654 } 00655 00656 static int set_extension(int argc, char **argv, void *data) 00657 { 00658 bContext *C = data; 00659 if (argc >= 1) { 00660 if (CTX_data_scene(C)) { 00661 Scene *scene= CTX_data_scene(C); 00662 if (argv[1][0] == '0') { 00663 scene->r.scemode &= ~R_EXTENSION; 00664 } else if (argv[1][0] == '1') { 00665 scene->r.scemode |= R_EXTENSION; 00666 } else { 00667 printf("\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n"); 00668 } 00669 } else { 00670 printf("\nError: no blend loaded. order the arguments so '-o ' is after '-x '.\n"); 00671 } 00672 return 1; 00673 } else { 00674 printf("\nError: you must specify a path after '- '.\n"); 00675 return 0; 00676 } 00677 } 00678 00679 static int set_ge_parameters(int argc, char **argv, void *data) 00680 { 00681 int a = 0; 00682 #ifdef WITH_GAMEENGINE 00683 SYS_SystemHandle syshandle = *(SYS_SystemHandle*)data; 00684 #else 00685 (void)data; 00686 #endif 00687 00697 if(argc >= 1) 00698 { 00699 char* paramname = argv[a]; 00700 /* check for single value versus assignment */ 00701 if (a+1 < argc && (*(argv[a+1]) == '=')) 00702 { 00703 a++; 00704 if (a+1 < argc) 00705 { 00706 a++; 00707 /* assignment */ 00708 #ifdef WITH_GAMEENGINE 00709 SYS_WriteCommandLineString(syshandle,paramname,argv[a]); 00710 #endif 00711 } else 00712 { 00713 printf("error: argument assignment (%s) without value.\n",paramname); 00714 return 0; 00715 } 00716 /* name arg eaten */ 00717 00718 } else { 00719 #ifdef WITH_GAMEENGINE 00720 SYS_WriteCommandLineInt(syshandle,argv[a],1); 00721 #endif 00722 /* doMipMap */ 00723 if (!strcmp(argv[a],"nomipmap")) 00724 { 00725 GPU_set_mipmap(0); //doMipMap = 0; 00726 } 00727 /* linearMipMap */ 00728 if (!strcmp(argv[a],"linearmipmap")) 00729 { 00730 GPU_set_linear_mipmap(1); //linearMipMap = 1; 00731 } 00732 00733 00734 } /* if (*(argv[a+1]) == '=') */ 00735 } 00736 00737 return a; 00738 } 00739 00740 static int render_frame(int argc, char **argv, void *data) 00741 { 00742 bContext *C = data; 00743 if (CTX_data_scene(C)) { 00744 Main *bmain= CTX_data_main(C); 00745 Scene *scene= CTX_data_scene(C); 00746 00747 if (argc > 1) { 00748 Render *re = RE_NewRender(scene->id.name); 00749 int frame; 00750 ReportList reports; 00751 00752 switch(*argv[1]) { 00753 case '+': 00754 frame= scene->r.sfra + atoi(argv[1]+1); 00755 break; 00756 case '-': 00757 frame= (scene->r.efra - atoi(argv[1]+1)) + 1; 00758 break; 00759 default: 00760 frame= atoi(argv[1]); 00761 break; 00762 } 00763 00764 BKE_reports_init(&reports, RPT_PRINT); 00765 00766 frame = MIN2(MAXFRAME, MAX2(MINAFRAME, frame)); 00767 00768 RE_BlenderAnim(re, bmain, scene, scene->lay, frame, frame, scene->r.frame_step, &reports); 00769 return 1; 00770 } else { 00771 printf("\nError: frame number must follow '-f / --render-frame'.\n"); 00772 return 0; 00773 } 00774 } else { 00775 printf("\nError: no blend loaded. cannot use '-f / --render-frame'.\n"); 00776 return 0; 00777 } 00778 } 00779 00780 static int render_animation(int UNUSED(argc), char **UNUSED(argv), void *data) 00781 { 00782 bContext *C = data; 00783 if (CTX_data_scene(C)) { 00784 Main *bmain= CTX_data_main(C); 00785 Scene *scene= CTX_data_scene(C); 00786 Render *re= RE_NewRender(scene->id.name); 00787 ReportList reports; 00788 BKE_reports_init(&reports, RPT_PRINT); 00789 RE_BlenderAnim(re, bmain, scene, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step, &reports); 00790 } else { 00791 printf("\nError: no blend loaded. cannot use '-a'.\n"); 00792 } 00793 return 0; 00794 } 00795 00796 static int set_scene(int argc, char **argv, void *data) 00797 { 00798 if(argc > 1) { 00799 bContext *C= data; 00800 Scene *sce= set_scene_name(CTX_data_main(C), argv[1]); 00801 if(sce) { 00802 CTX_data_scene_set(C, sce); 00803 } 00804 return 1; 00805 } else { 00806 printf("\nError: Scene name must follow '-S / --scene'.\n"); 00807 return 0; 00808 } 00809 } 00810 00811 static int set_start_frame(int argc, char **argv, void *data) 00812 { 00813 bContext *C = data; 00814 if (CTX_data_scene(C)) { 00815 Scene *scene= CTX_data_scene(C); 00816 if (argc > 1) { 00817 int frame = atoi(argv[1]); 00818 (scene->r.sfra) = CLAMPIS(frame, MINFRAME, MAXFRAME); 00819 return 1; 00820 } else { 00821 printf("\nError: frame number must follow '-s / --frame-start'.\n"); 00822 return 0; 00823 } 00824 } else { 00825 printf("\nError: no blend loaded. cannot use '-s / --frame-start'.\n"); 00826 return 0; 00827 } 00828 } 00829 00830 static int set_end_frame(int argc, char **argv, void *data) 00831 { 00832 bContext *C = data; 00833 if (CTX_data_scene(C)) { 00834 Scene *scene= CTX_data_scene(C); 00835 if (argc > 1) { 00836 int frame = atoi(argv[1]); 00837 (scene->r.efra) = CLAMPIS(frame, MINFRAME, MAXFRAME); 00838 return 1; 00839 } else { 00840 printf("\nError: frame number must follow '-e / --frame-end'.\n"); 00841 return 0; 00842 } 00843 } else { 00844 printf("\nError: no blend loaded. cannot use '-e / --frame-end'.\n"); 00845 return 0; 00846 } 00847 } 00848 00849 static int set_skip_frame(int argc, char **argv, void *data) 00850 { 00851 bContext *C = data; 00852 if (CTX_data_scene(C)) { 00853 Scene *scene= CTX_data_scene(C); 00854 if (argc > 1) { 00855 int frame = atoi(argv[1]); 00856 (scene->r.frame_step) = CLAMPIS(frame, 1, MAXFRAME); 00857 return 1; 00858 } else { 00859 printf("\nError: number of frames to step must follow '-j / --frame-jump'.\n"); 00860 return 0; 00861 } 00862 } else { 00863 printf("\nError: no blend loaded. cannot use '-j / --frame-jump'.\n"); 00864 return 0; 00865 } 00866 } 00867 00868 /* macro for ugly context setup/reset */ 00869 #ifdef WITH_PYTHON 00870 #define BPY_CTX_SETUP(_cmd) \ 00871 { \ 00872 wmWindowManager *wm= CTX_wm_manager(C); \ 00873 wmWindow *prevwin= CTX_wm_window(C); \ 00874 Scene *prevscene= CTX_data_scene(C); \ 00875 if(wm->windows.first) { \ 00876 CTX_wm_window_set(C, wm->windows.first); \ 00877 _cmd; \ 00878 CTX_wm_window_set(C, prevwin); \ 00879 } \ 00880 else { \ 00881 fprintf(stderr, "Python script \"%s\" running with missing context data.\n", argv[1]); \ 00882 _cmd; \ 00883 } \ 00884 CTX_data_scene_set(C, prevscene); \ 00885 } \ 00886 00887 #endif /* WITH_PYTHON */ 00888 00889 static int run_python(int argc, char **argv, void *data) 00890 { 00891 #ifdef WITH_PYTHON 00892 bContext *C = data; 00893 00894 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ 00895 if (argc > 1) { 00896 /* Make the path absolute because its needed for relative linked blends to be found */ 00897 char filename[FILE_MAXDIR + FILE_MAXFILE]; 00898 BLI_strncpy(filename, argv[1], sizeof(filename)); 00899 BLI_path_cwd(filename); 00900 00901 BPY_CTX_SETUP(BPY_filepath_exec(C, filename, NULL)) 00902 00903 return 1; 00904 } else { 00905 printf("\nError: you must specify a Python script after '-P / --python'.\n"); 00906 return 0; 00907 } 00908 #else 00909 (void)argc; (void)argv; (void)data; /* unused */ 00910 printf("This blender was built without python support\n"); 00911 return 0; 00912 #endif /* WITH_PYTHON */ 00913 } 00914 00915 static int run_python_console(int UNUSED(argc), char **argv, void *data) 00916 { 00917 #ifdef WITH_PYTHON 00918 bContext *C = data; 00919 00920 BPY_CTX_SETUP(BPY_string_exec(C, "__import__('code').interact()")) 00921 00922 return 0; 00923 #else 00924 (void)argv; (void)data; /* unused */ 00925 printf("This blender was built without python support\n"); 00926 return 0; 00927 #endif /* WITH_PYTHON */ 00928 } 00929 00930 static int set_addons(int argc, char **argv, void *data) 00931 { 00932 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ 00933 if (argc > 1) { 00934 #ifdef WITH_PYTHON 00935 char *str= malloc(strlen(argv[1]) + 100); 00936 bContext *C= data; 00937 sprintf(str, "[__import__('bpy').utils.addon_enable(i) for i in '%s'.split(',')]", argv[1]); 00938 BPY_CTX_SETUP(BPY_string_exec(C, str)); 00939 free(str); 00940 #else 00941 (void)argv; (void)data; /* unused */ 00942 #endif /* WITH_PYTHON */ 00943 return 1; 00944 } 00945 else { 00946 printf("\nError: you must specify a comma separated list after '--addons'.\n"); 00947 return 0; 00948 } 00949 } 00950 00951 00952 static int load_file(int UNUSED(argc), char **argv, void *data) 00953 { 00954 bContext *C = data; 00955 00956 /* Make the path absolute because its needed for relative linked blends to be found */ 00957 char filename[FILE_MAXDIR + FILE_MAXFILE]; 00958 BLI_strncpy(filename, argv[0], sizeof(filename)); 00959 BLI_path_cwd(filename); 00960 00961 if (G.background) { 00962 int retval = BKE_read_file(C, filename, NULL); 00963 00964 /*we successfully loaded a blend file, get sure that 00965 pointcache works */ 00966 if (retval != BKE_READ_FILE_FAIL) { 00967 wmWindowManager *wm= CTX_wm_manager(C); 00968 00969 /* special case, 2.4x files */ 00970 if(wm==NULL && CTX_data_main(C)->wm.first==NULL) { 00971 extern void wm_add_default(bContext *C); 00972 00973 /* wm_add_default() needs the screen to be set. */ 00974 CTX_wm_screen_set(C, CTX_data_main(C)->screen.first); 00975 wm_add_default(C); 00976 } 00977 00978 CTX_wm_manager_set(C, NULL); /* remove wm to force check */ 00979 WM_check(C); 00980 G.relbase_valid = 1; 00981 if (CTX_wm_manager(C) == NULL) CTX_wm_manager_set(C, wm); /* reset wm */ 00982 00983 DAG_on_load_update(CTX_data_main(C), TRUE); 00984 } 00985 00986 /* WM_read_file() runs normally but since we're in background mode do here */ 00987 #ifdef WITH_PYTHON 00988 /* run any texts that were loaded in and flagged as modules */ 00989 BPY_driver_reset(); 00990 BPY_modules_load_user(C); 00991 #endif 00992 00993 /* happens for the UI on file reading too (huh? (ton))*/ 00994 // XXX BKE_reset_undo(); 00995 // BKE_write_undo("original"); /* save current state */ 00996 } else { 00997 /* we are not running in background mode here, but start blender in UI mode with 00998 a file - this should do everything a 'load file' does */ 00999 ReportList reports; 01000 BKE_reports_init(&reports, RPT_PRINT); 01001 WM_read_file(C, filename, &reports); 01002 BKE_reports_clear(&reports); 01003 } 01004 01005 G.file_loaded = 1; 01006 01007 return 0; 01008 } 01009 01010 void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) 01011 { 01012 static char output_doc[] = "<path>" 01013 "\n\tSet the render path and file name." 01014 "\n\tUse // at the start of the path to" 01015 "\n\t\trender relative to the blend file." 01016 "\n\tThe # characters are replaced by the frame number, and used to define zero padding." 01017 "\n\t\tani_##_test.png becomes ani_01_test.png" 01018 "\n\t\ttest-######.png becomes test-000001.png" 01019 "\n\t\tWhen the filename does not contain #, The suffix #### is added to the filename" 01020 "\n\tThe frame number will be added at the end of the filename." 01021 "\n\t\teg: blender -b foobar.blend -o //render_ -F PNG -x 1 -a" 01022 "\n\t\t//render_ becomes //render_####, writing frames as //render_0001.png//"; 01023 01024 static char format_doc[] = "<format>" 01025 "\n\tSet the render format, Valid options are..." 01026 "\n\t\tTGA IRIS JPEG MOVIE IRIZ RAWTGA" 01027 "\n\t\tAVIRAW AVIJPEG PNG BMP FRAMESERVER" 01028 "\n\t(formats that can be compiled into blender, not available on all systems)" 01029 "\n\t\tHDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS"; 01030 01031 static char playback_doc[] = "<options> <file(s)>" 01032 "\n\tPlayback <file(s)>, only operates this way when not running in background." 01033 "\n\t\t-p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>" 01034 "\n\t\t-m\t\tRead from disk (Don't buffer)" 01035 "\n\t\t-f <fps> <fps-base>\t\tSpecify FPS to start with" 01036 "\n\t\t-j <frame>\tSet frame step to <frame>"; 01037 01038 static char game_doc[] = "Game Engine specific options" 01039 "\n\t-g fixedtime\t\tRun on 50 hertz without dropping frames" 01040 "\n\t-g vertexarrays\t\tUse Vertex Arrays for rendering (usually faster)" 01041 "\n\t-g nomipmap\t\tNo Texture Mipmapping" 01042 "\n\t-g linearmipmap\t\tLinear Texture Mipmapping instead of Nearest (default)"; 01043 01044 static char debug_doc[] = "\n\tTurn debugging on\n" 01045 "\n\t* Prints every operator call and their arguments" 01046 "\n\t* Disables mouse grab (to interact with a debugger in some cases)" 01047 "\n\t* Keeps python sys.stdin rather then setting it to None"; 01048 01049 //BLI_argsAdd(ba, pass, short_arg, long_arg, doc, cb, C); 01050 01051 /* end argument processing after -- */ 01052 BLI_argsAdd(ba, -1, "--", NULL, "\n\tEnds option processing, following arguments passed unchanged. Access via python's sys.argv", end_arguments, NULL); 01053 01054 /* first pass: background mode, disable python and commands that exit after usage */ 01055 BLI_argsAdd(ba, 1, "-h", "--help", "\n\tPrint this help text and exit", print_help, ba); 01056 /* Windows only */ 01057 BLI_argsAdd(ba, 1, "/?", NULL, "\n\tPrint this help text and exit (windows only)", print_help, ba); 01058 01059 BLI_argsAdd(ba, 1, "-v", "--version", "\n\tPrint Blender version and exit", print_version, NULL); 01060 01061 BLI_argsAdd(ba, 1, "-y", "--enable-autoexec", "\n\tEnable automatic python script execution (default)", enable_python, NULL); 01062 BLI_argsAdd(ba, 1, "-Y", "--disable-autoexec", "\n\tDisable automatic python script execution (pydrivers, pyconstraints, pynodes)", disable_python, NULL); 01063 01064 BLI_argsAdd(ba, 1, "-b", "--background", "<file>\n\tLoad <file> in background (often used for UI-less rendering)", background_mode, NULL); 01065 01066 BLI_argsAdd(ba, 1, "-a", NULL, playback_doc, playback_mode, NULL); 01067 01068 BLI_argsAdd(ba, 1, "-d", "--debug", debug_doc, debug_mode, ba); 01069 BLI_argsAdd(ba, 1, NULL, "--debug-fpe", "\n\tEnable floating point exceptions", set_fpe, NULL); 01070 01071 BLI_argsAdd(ba, 1, NULL, "--factory-startup", "\n\tSkip reading the "STRINGIFY(BLENDER_STARTUP_FILE)" in the users home directory", set_factory_startup, NULL); 01072 01073 /* TODO, add user env vars? */ 01074 BLI_argsAdd(ba, 1, NULL, "--env-system-config", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_CONFIG)" environment variable", set_env, NULL); 01075 BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_DATAFILES)" environment variable", set_env, NULL); 01076 BLI_argsAdd(ba, 1, NULL, "--env-system-scripts", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_SCRIPTS)" environment variable", set_env, NULL); 01077 BLI_argsAdd(ba, 1, NULL, "--env-system-plugins", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PLUGINS)" environment variable", set_env, NULL); 01078 BLI_argsAdd(ba, 1, NULL, "--env-system-python", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PYTHON)" environment variable", set_env, NULL); 01079 01080 /* second pass: custom window stuff */ 01081 BLI_argsAdd(ba, 2, "-p", "--window-geometry", "<sx> <sy> <w> <h>\n\tOpen with lower left corner at <sx>, <sy> and width and height as <w>, <h>", prefsize, NULL); 01082 BLI_argsAdd(ba, 2, "-w", "--window-border", "\n\tForce opening with borders (default)", with_borders, NULL); 01083 BLI_argsAdd(ba, 2, "-W", "--window-borderless", "\n\tForce opening without borders", without_borders, NULL); 01084 BLI_argsAdd(ba, 2, "-R", NULL, "\n\tRegister .blend extension (windows only)", register_extension, ba); 01085 01086 /* third pass: disabling things and forcing settings */ 01087 BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, "\n\tDisable joystick support", no_joystick, syshandle); 01088 BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, "\n\tDisable GLSL shading", no_glsl, NULL); 01089 BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, "\n\tForce sound system to None", no_audio, NULL); 01090 BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, "\n\tForce sound system to a specific device\n\tNULL SDL OPENAL JACK", set_audio, NULL); 01091 01092 /* fourth pass: processing arguments */ 01093 BLI_argsAdd(ba, 4, "-g", NULL, game_doc, set_ge_parameters, syshandle); 01094 BLI_argsAdd(ba, 4, "-f", "--render-frame", "<frame>\n\tRender frame <frame> and save it.\n\t+<frame> start frame relative, -<frame> end frame relative.", render_frame, C); 01095 BLI_argsAdd(ba, 4, "-a", "--render-anim", "\n\tRender frames from start to end (inclusive)", render_animation, C); 01096 BLI_argsAdd(ba, 4, "-S", "--scene", "<name>\n\tSet the active scene <name> for rendering", set_scene, C); 01097 BLI_argsAdd(ba, 4, "-s", "--frame-start", "<frame>\n\tSet start to frame <frame> (use before the -a argument)", set_start_frame, C); 01098 BLI_argsAdd(ba, 4, "-e", "--frame-end", "<frame>\n\tSet end to frame <frame> (use before the -a argument)", set_end_frame, C); 01099 BLI_argsAdd(ba, 4, "-j", "--frame-jump", "<frames>\n\tSet number of frames to step forward after each rendered frame", set_skip_frame, C); 01100 BLI_argsAdd(ba, 4, "-P", "--python", "<filename>\n\tRun the given Python script (filename or Blender Text)", run_python, C); 01101 BLI_argsAdd(ba, 4, NULL, "--python-console", "\n\tRun blender with an interactive console", run_python_console, C); 01102 BLI_argsAdd(ba, 4, NULL, "--addons", "\n\tComma separated list of addons (no spaces)", set_addons, C); 01103 01104 BLI_argsAdd(ba, 4, "-o", "--render-output", output_doc, set_output, C); 01105 BLI_argsAdd(ba, 4, "-E", "--engine", "<engine>\n\tSpecify the render engine\n\tuse -E help to list available engines", set_engine, C); 01106 01107 BLI_argsAdd(ba, 4, "-F", "--render-format", format_doc, set_image_type, C); 01108 BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL); 01109 BLI_argsAdd(ba, 4, "-x", "--use-extension", "<bool>\n\tSet option to add the file extension to the end of the file", set_extension, C); 01110 01111 } 01112 01113 int main(int argc, char **argv) 01114 { 01115 SYS_SystemHandle syshandle; 01116 bContext *C= CTX_create(); 01117 bArgs *ba; 01118 01119 #ifdef WITH_BINRELOC 01120 br_init( NULL ); 01121 #endif 01122 01123 setCallbacks(); 01124 #ifdef __APPLE__ 01125 /* patch to ignore argument finder gives us (pid?) */ 01126 if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) { 01127 extern int GHOST_HACK_getFirstFile(char buf[]); 01128 static char firstfilebuf[512]; 01129 01130 argc= 1; 01131 01132 if (GHOST_HACK_getFirstFile(firstfilebuf)) { 01133 argc= 2; 01134 argv[1]= firstfilebuf; 01135 } 01136 } 01137 01138 #endif 01139 01140 #ifdef __FreeBSD__ 01141 fpsetmask(0); 01142 #endif 01143 01144 // copy path to executable in bprogname. playanim and creting runtimes 01145 // need this. 01146 01147 BLI_where_am_i(bprogname, argv[0]); 01148 01149 #ifdef BUILD_DATE 01150 strip_quotes(build_date); 01151 strip_quotes(build_time); 01152 strip_quotes(build_rev); 01153 strip_quotes(build_platform); 01154 strip_quotes(build_type); 01155 strip_quotes(build_cflags); 01156 strip_quotes(build_cxxflags); 01157 strip_quotes(build_linkflags); 01158 strip_quotes(build_system); 01159 #endif 01160 01161 BLI_threadapi_init(); 01162 01163 RNA_init(); 01164 RE_engines_init(); 01165 01166 /* Hack - force inclusion of the plugin api functions, 01167 * see blenpluginapi:pluginapi.c 01168 */ 01169 pluginapi_force_ref(); 01170 01171 init_nodesystem(); 01172 01173 initglobals(); /* blender.c */ 01174 01175 IMB_init(); 01176 01177 #ifdef WITH_GAMEENGINE 01178 syshandle = SYS_GetSystem(); 01179 GEN_init_messaging_system(); 01180 #else 01181 syshandle= 0; 01182 #endif 01183 01184 /* first test for background */ 01185 ba = BLI_argsInit(argc, argv); /* skip binary path */ 01186 setupArguments(C, ba, &syshandle); 01187 01188 BLI_argsParse(ba, 1, NULL, NULL); 01189 01190 #ifdef __sgi 01191 setuid(getuid()); /* end superuser */ 01192 #endif 01193 01194 01195 /* for all platforms, even windos has it! */ 01196 if(G.background) signal(SIGINT, blender_esc); /* ctrl c out bg render */ 01197 01198 /* background render uses this font too */ 01199 BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size); 01200 01201 /* Initialiaze ffmpeg if built in, also needed for bg mode if videos are 01202 rendered via ffmpeg */ 01203 sound_init_once(); 01204 01205 init_def_material(); 01206 01207 if(G.background==0) { 01208 BLI_argsParse(ba, 2, NULL, NULL); 01209 BLI_argsParse(ba, 3, NULL, NULL); 01210 01211 WM_init(C, argc, argv); 01212 01213 /* this is properly initialized with user defs, but this is default */ 01214 BLI_where_is_temp( btempdir, 1 ); /* call after loading the startup.blend so we can read U.tempdir */ 01215 01216 #ifndef DISABLE_SDL 01217 BLI_setenv("SDL_VIDEODRIVER", "dummy"); 01218 #endif 01219 } 01220 else { 01221 BLI_argsParse(ba, 3, NULL, NULL); 01222 01223 WM_init(C, argc, argv); 01224 01225 BLI_where_is_temp( btempdir, 0 ); /* call after loading the startup.blend so we can read U.tempdir */ 01226 } 01227 #ifdef WITH_PYTHON 01228 01237 // TODO - U.pythondir 01238 #else 01239 printf("\n* WARNING * - Blender compiled without Python!\nthis is not intended for typical usage\n\n"); 01240 #endif 01241 01242 CTX_py_init_set(C, 1); 01243 WM_keymap_init(C); 01244 01245 /* OK we are ready for it */ 01246 BLI_argsParse(ba, 4, load_file, C); 01247 01248 BLI_argsFree(ba); 01249 01250 if(G.background) { 01251 /* actually incorrect, but works for now (ton) */ 01252 WM_exit(C); 01253 } 01254 01255 else { 01256 if((G.fileflags & G_FILE_AUTOPLAY) && (G.f & G_SCRIPT_AUTOEXEC)) 01257 { 01258 if(WM_init_game(C)) 01259 return 0; 01260 } 01261 else if(!G.file_loaded) 01262 WM_init_splash(C); 01263 } 01264 01265 WM_main(C); 01266 01267 01268 /*XXX if (scr_init==0) { 01269 main_init_screen(); 01270 } 01271 01272 screenmain();*/ /* main display loop */ 01273 01274 return 0; 01275 } /* end of int main(argc,argv) */ 01276 01277 static void error_cb(char *err) 01278 { 01279 01280 printf("%s\n", err); /* XXX do this in WM too */ 01281 } 01282 01283 static void mem_error_cb(const char *errorStr) 01284 { 01285 fputs(errorStr, stderr); 01286 fflush(stderr); 01287 } 01288 01289 static void setCallbacks(void) 01290 { 01291 /* Error output from the alloc routines: */ 01292 MEM_set_error_callback(mem_error_cb); 01293 01294 01295 /* BLI_blenlib: */ 01296 01297 BLI_setErrorCallBack(error_cb); /* */ 01298 // XXX BLI_setInterruptCallBack(blender_test_break); 01299 01300 }
1.7.3