7 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version. The Blender
13 * Foundation also sells licenses for use in proprietary software under
14 * the Blender License. See http://www.blender.org/BL/ for information
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
27 * All rights reserved.
29 * The Original Code is: all of this file.
31 * Contributor(s): none yet.
33 * ***** END GPL/BL DUAL LICENSE BLOCK *****
45 #include "BLI_winstuff.h"
48 #include "MEM_guardedalloc.h"
50 #include "nla.h" /* for __NLA : IMPORTANT Do not delete me yet! */
51 #ifdef __NLA /* for __NLA : IMPORTANT Do not delete me yet! */
52 #include "DNA_armature_types.h" /* for __NLA : IMPORTANT Do not delete me yet! */
53 #include "BKE_armature.h" /* for __NLA : IMPORTANT Do not delete me yet! */
54 #include "BKE_action.h" /* for __NLA : IMPORTANT Do not delete me yet! */
55 #endif /* for __NLA : IMPORTANT Do not delete me yet! */
57 #include "DNA_constraint_types.h"
58 #include "DNA_scene_types.h"
59 #include "DNA_object_types.h"
60 #include "DNA_scriptlink_types.h"
61 #include "DNA_meta_types.h"
62 #include "DNA_ika_types.h"
63 #include "DNA_lamp_types.h"
64 #include "DNA_material_types.h"
65 #include "DNA_mesh_types.h"
66 #include "DNA_group_types.h"
67 #include "DNA_curve_types.h"
68 #include "DNA_userdef_types.h"
70 #include "BLI_blenlib.h"
72 #include "BKE_bad_level_calls.h"
73 #include "BKE_utildefines.h"
75 #include "BKE_global.h"
79 #include "BKE_library.h"
81 #include "BPY_extern.h"
82 #include "BKE_scene.h"
83 #include "BKE_world.h"
88 void free_avicodecdata(AviCodecData *acd)
92 MEM_freeN(acd->lpFormat);
97 MEM_freeN(acd->lpParms);
104 /* do not free scene itself */
105 void free_scene(Scene *sce)
109 base= sce->base.first;
111 base->object->id.us--;
114 /* do not free objects! */
116 BLI_freelistN(&sce->base);
117 free_editing(sce->ed);
118 if(sce->radio) MEM_freeN(sce->radio);
119 if(sce->fcam) MEM_freeN(sce->fcam);
122 BPY_free_scriptlink(&sce->scriptlink);
123 if (sce->r.avicodecdata) {
124 free_avicodecdata(sce->r.avicodecdata);
125 MEM_freeN(sce->r.avicodecdata);
126 sce->r.avicodecdata = NULL;
130 Scene *add_scene(char *name)
134 sce= alloc_libblock(&G.main->scene, ID_SCE, name);
137 sce->r.mode= R_GAMMA;
150 sce->r.framapto= 100;
152 sce->r.framelen= 1.0;
160 if (sce->r.avicodecdata) {
161 printf("this is not good\n");
163 // sce->r.imtype= R_TARGA;
165 sce->r.stereomode = 1; // no stereo
167 strcpy(sce->r.backbuf, "//backbuf");
168 strcpy(sce->r.pic, U.renderdir);
169 strcpy(sce->r.ftype, "//ftype");
171 BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
177 int object_in_scene(Object *ob, Scene *sce)
181 base= sce->base.first;
183 if(base->object == ob) return 1;
189 void sort_baselist(Scene *sce)
191 /* in order of parent and track */
192 ListBase tempbase, noparentbase, notyetbase;
193 Base *base, *test=NULL;
195 int doit, domore= 0, lastdomore=1;
198 /* keep same order when nothing has changed! */
200 while(domore!=lastdomore) {
204 tempbase.first= tempbase.last= 0;
205 noparentbase.first= noparentbase.last= 0;
206 notyetbase.first= notyetbase.last= 0;
208 while( (base= sce->base.first) ) {
209 BLI_remlink(&sce->base, base);
212 if(base->object->type==OB_IKA) {
213 Ika *ika= base->object->data;
217 if(par || base->object->parent || base->object->track) {
220 if(base->object->parent) doit++;
221 if(base->object->track) doit++;
223 /* Count constraints */
226 for (con = base->object->constraints.first; con; con=con->next){
228 case CONSTRAINT_TYPE_KINEMATIC:
230 bKinematicConstraint *data=con->data;
231 if (data->tar) doit++;
234 case CONSTRAINT_TYPE_TRACKTO:
236 bTrackToConstraint *data=con->data;
237 if (data->tar) doit++;
240 case CONSTRAINT_TYPE_NULL:
242 case CONSTRAINT_TYPE_ROTLIKE:
244 bRotateLikeConstraint *data=con->data;
245 if (data->tar) doit++;
249 case CONSTRAINT_TYPE_LOCLIKE:
251 bLocateLikeConstraint *data=con->data;
252 if (data->tar) doit++;
255 case CONSTRAINT_TYPE_ACTION:
257 bActionConstraint *data=con->data;
258 if (data->tar) doit++;
269 test= tempbase.first;
272 if(test->object==base->object->parent) doit--;
273 if(test->object==base->object->track) doit--;
274 if(test->object==par) doit--;
276 /* Decrement constraints */
279 for (con = base->object->constraints.first; con; con=con->next){
281 case CONSTRAINT_TYPE_KINEMATIC:
283 bKinematicConstraint *data=con->data;
284 if (test->object == data->tar && test->object!=base->object) doit--;
287 case CONSTRAINT_TYPE_TRACKTO:
289 bTrackToConstraint *data=con->data;
290 if (test->object == data->tar && test->object!=base->object) doit--;
293 case CONSTRAINT_TYPE_NULL:
295 case CONSTRAINT_TYPE_ROTLIKE:
297 bRotateLikeConstraint *data=con->data;
298 if (test->object == data->tar && test->object!=base->object) doit--;
302 case CONSTRAINT_TYPE_LOCLIKE:
304 bLocateLikeConstraint *data=con->data;
305 if (test->object == data->tar && test->object!=base->object) doit--;
308 case CONSTRAINT_TYPE_ACTION:
310 bActionConstraint *data=con->data;
311 if (test->object == data->tar && test->object!=base->object) doit--;
324 if(test) BLI_insertlink(&tempbase, test, base);
326 BLI_addhead(&tempbase, base);
331 else BLI_addtail(&noparentbase, base);
334 sce->base= noparentbase;
335 addlisttolist(&sce->base, &tempbase);
336 addlisttolist(&sce->base, ¬yetbase);
342 void set_scene_bg(Scene *sce)
352 /* deselect objects (for dataselect) */
353 ob= G.main->object.first;
355 ob->flag &= ~(SELECT|OB_FROMGROUP);
359 /* group flags again */
360 group= G.main->group.first;
362 go= group->gobject.first;
364 if(go->ob) go->ob->flag |= OB_FROMGROUP;
367 group= group->id.next;
373 /* copy layers and flags from bases to objects */
374 base= G.scene->base.first;
377 base->object->lay= base->lay;
379 base->flag &= ~OB_FROMGROUP;
380 flag= base->object->flag & OB_FROMGROUP;
383 base->object->ctime= -1234567.0; /* force ipo to be calculated later */
387 do_all_ipos(); /* layers/materials */
389 BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
399 void set_scene_name(char *name)
403 for (sce= G.main->scene.first; sce; sce= sce->id.next) {
404 if (BLI_streq(name, sce->id.name+2)) {
410 error("Can't find scene: %s", name);
414 * doesnt return the original duplicated object, only dupli's
416 int next_object(int val, Base **base, Object **ob)
418 extern ListBase duplilist;
419 static Object *dupob;
430 /* run_again is set when a duplilist has been ended */
438 *base= G.scene->base.first;
440 *ob= (*base)->object;
444 /* exception: empty scene */
445 if(G.scene->set && G.scene->set->base.first) {
446 *base= G.scene->set->base.first;
447 *ob= (*base)->object;
453 if(*base && fase!=F_DUPLI) {
454 *base= (*base)->next;
455 if(*base) *ob= (*base)->object;
458 /* scene is finished, now do the set */
459 if(G.scene->set && G.scene->set->base.first) {
460 *base= G.scene->set->base.first;
461 *ob= (*base)->object;
469 if(*base == 0) fase= F_START;
472 if( (*base)->object->transflag & OB_DUPLI) {
474 make_duplilist(G.scene, (*base)->object);
475 dupob= duplilist.first;
485 dupob= dupob->id.next;
487 else if(fase==F_DUPLI) {
500 Object *scene_find_camera(Scene *sc)
504 for (base= sc->base.first; base; base= base->next)
505 if (base->object->type==OB_CAMERA)
512 Base *scene_add_base(Scene *sce, Object *ob)
514 Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
515 BLI_addhead(&sce->base, b);
524 void scene_deselect_all(Scene *sce)
528 for (b= sce->base.first; b; b= b->next) {
530 b->object->flag= b->flag;
534 void scene_select_base(Scene *sce, Base *selbase)
536 scene_deselect_all(sce);
538 selbase->flag |= SELECT;
539 selbase->object->flag= selbase->flag;
541 sce->basact= selbase;