6 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version. The Blender
12 * Foundation also sells licenses for use in proprietary software under
13 * the Blender License. See http://www.blender.org/BL/ for information
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26 * All rights reserved.
28 * The Original Code is: all of this file.
30 * Contributor(s): none yet.
32 * ***** END GPL/BL DUAL LICENSE BLOCK *****
44 #include "BLI_winstuff.h"
47 #include "MEM_guardedalloc.h"
49 #include "nla.h" /* for __NLA : IMPORTANT Do not delete me yet! */
50 #ifdef __NLA /* for __NLA : IMPORTANT Do not delete me yet! */
51 #include "DNA_armature_types.h" /* for __NLA : IMPORTANT Do not delete me yet! */
52 #include "BKE_armature.h" /* for __NLA : IMPORTANT Do not delete me yet! */
53 #include "BKE_action.h" /* for __NLA : IMPORTANT Do not delete me yet! */
54 #endif /* for __NLA : IMPORTANT Do not delete me yet! */
56 #include "DNA_constraint_types.h"
57 #include "DNA_scene_types.h"
58 #include "DNA_object_types.h"
59 #include "DNA_scriptlink_types.h"
60 #include "DNA_meta_types.h"
61 #include "DNA_ika_types.h"
62 #include "DNA_lamp_types.h"
63 #include "DNA_material_types.h"
64 #include "DNA_mesh_types.h"
65 #include "DNA_group_types.h"
66 #include "DNA_curve_types.h"
67 #include "DNA_userdef_types.h"
69 #include "BLI_blenlib.h"
71 #include "BKE_bad_level_calls.h"
72 #include "BKE_utildefines.h"
74 #include "BKE_global.h"
78 #include "BKE_library.h"
80 #include "BPY_extern.h"
81 #include "BKE_scene.h"
82 #include "BKE_world.h"
87 void free_avicodecdata(AviCodecData *acd)
91 MEM_freeN(acd->lpFormat);
96 MEM_freeN(acd->lpParms);
103 void free_qtcodecdata(QuicktimeCodecData *qcd)
107 MEM_freeN(qcd->cdParms);
114 /* do not free scene itself */
115 void free_scene(Scene *sce)
119 base= sce->base.first;
121 base->object->id.us--;
124 /* do not free objects! */
126 BLI_freelistN(&sce->base);
127 free_editing(sce->ed);
128 if(sce->radio) MEM_freeN(sce->radio);
129 if(sce->fcam) MEM_freeN(sce->fcam);
132 BPY_free_scriptlink(&sce->scriptlink);
133 if (sce->r.avicodecdata) {
134 free_avicodecdata(sce->r.avicodecdata);
135 MEM_freeN(sce->r.avicodecdata);
136 sce->r.avicodecdata = NULL;
138 if (sce->r.qtcodecdata) {
139 free_qtcodecdata(sce->r.qtcodecdata);
140 MEM_freeN(sce->r.qtcodecdata);
141 sce->r.qtcodecdata = NULL;
145 Scene *add_scene(char *name)
149 sce= alloc_libblock(&G.main->scene, ID_SCE, name);
152 sce->r.mode= R_GAMMA;
165 sce->r.framapto= 100;
167 sce->r.framelen= 1.0;
175 if (sce->r.avicodecdata) {
176 printf("this is not good\n");
178 // sce->r.imtype= R_TARGA;
180 sce->r.stereomode = 1; // no stereo
182 strcpy(sce->r.backbuf, "//backbuf");
183 strcpy(sce->r.pic, U.renderdir);
184 strcpy(sce->r.ftype, "//ftype");
186 BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
192 int object_in_scene(Object *ob, Scene *sce)
196 base= sce->base.first;
198 if(base->object == ob) return 1;
204 void sort_baselist(Scene *sce)
206 /* in order of parent and track */
207 ListBase tempbase, noparentbase, notyetbase;
208 Base *base, *test=NULL;
210 int doit, domore= 0, lastdomore=1;
213 /* keep same order when nothing has changed! */
215 while(domore!=lastdomore) {
219 tempbase.first= tempbase.last= 0;
220 noparentbase.first= noparentbase.last= 0;
221 notyetbase.first= notyetbase.last= 0;
223 while( (base= sce->base.first) ) {
224 BLI_remlink(&sce->base, base);
227 if(base->object->type==OB_IKA) {
228 Ika *ika= base->object->data;
232 if(par || base->object->parent || base->object->track) {
235 if(base->object->parent) doit++;
236 if(base->object->track) doit++;
238 /* Count constraints */
241 for (con = base->object->constraints.first; con; con=con->next){
243 case CONSTRAINT_TYPE_KINEMATIC:
245 bKinematicConstraint *data=con->data;
246 if (data->tar) doit++;
249 case CONSTRAINT_TYPE_TRACKTO:
251 bTrackToConstraint *data=con->data;
252 if (data->tar) doit++;
255 case CONSTRAINT_TYPE_NULL:
257 case CONSTRAINT_TYPE_ROTLIKE:
259 bRotateLikeConstraint *data=con->data;
260 if (data->tar) doit++;
264 case CONSTRAINT_TYPE_LOCLIKE:
266 bLocateLikeConstraint *data=con->data;
267 if (data->tar) doit++;
270 case CONSTRAINT_TYPE_ACTION:
272 bActionConstraint *data=con->data;
273 if (data->tar) doit++;
284 test= tempbase.first;
287 if(test->object==base->object->parent) doit--;
288 if(test->object==base->object->track) doit--;
289 if(test->object==par) doit--;
291 /* Decrement constraints */
294 for (con = base->object->constraints.first; con; con=con->next){
296 case CONSTRAINT_TYPE_KINEMATIC:
298 bKinematicConstraint *data=con->data;
299 if (test->object == data->tar && test->object!=base->object) doit--;
302 case CONSTRAINT_TYPE_TRACKTO:
304 bTrackToConstraint *data=con->data;
305 if (test->object == data->tar && test->object!=base->object) doit--;
308 case CONSTRAINT_TYPE_NULL:
310 case CONSTRAINT_TYPE_ROTLIKE:
312 bRotateLikeConstraint *data=con->data;
313 if (test->object == data->tar && test->object!=base->object) doit--;
317 case CONSTRAINT_TYPE_LOCLIKE:
319 bLocateLikeConstraint *data=con->data;
320 if (test->object == data->tar && test->object!=base->object) doit--;
323 case CONSTRAINT_TYPE_ACTION:
325 bActionConstraint *data=con->data;
326 if (test->object == data->tar && test->object!=base->object) doit--;
339 if(test) BLI_insertlink(&tempbase, test, base);
341 BLI_addhead(&tempbase, base);
346 else BLI_addtail(&noparentbase, base);
349 sce->base= noparentbase;
350 addlisttolist(&sce->base, &tempbase);
351 addlisttolist(&sce->base, ¬yetbase);
357 void set_scene_bg(Scene *sce)
367 /* deselect objects (for dataselect) */
368 ob= G.main->object.first;
370 ob->flag &= ~(SELECT|OB_FROMGROUP);
374 /* group flags again */
375 group= G.main->group.first;
377 go= group->gobject.first;
379 if(go->ob) go->ob->flag |= OB_FROMGROUP;
382 group= group->id.next;
388 /* copy layers and flags from bases to objects */
389 base= G.scene->base.first;
392 base->object->lay= base->lay;
394 base->flag &= ~OB_FROMGROUP;
395 flag= base->object->flag & OB_FROMGROUP;
398 base->object->ctime= -1234567.0; /* force ipo to be calculated later */
402 do_all_ipos(); /* layers/materials */
404 BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
414 void set_scene_name(char *name)
418 for (sce= G.main->scene.first; sce; sce= sce->id.next) {
419 if (BLI_streq(name, sce->id.name+2)) {
425 error("Can't find scene: %s", name);
429 * doesnt return the original duplicated object, only dupli's
431 int next_object(int val, Base **base, Object **ob)
433 extern ListBase duplilist;
434 static Object *dupob;
445 /* run_again is set when a duplilist has been ended */
453 *base= G.scene->base.first;
455 *ob= (*base)->object;
459 /* exception: empty scene */
460 if(G.scene->set && G.scene->set->base.first) {
461 *base= G.scene->set->base.first;
462 *ob= (*base)->object;
468 if(*base && fase!=F_DUPLI) {
469 *base= (*base)->next;
470 if(*base) *ob= (*base)->object;
473 /* scene is finished, now do the set */
474 if(G.scene->set && G.scene->set->base.first) {
475 *base= G.scene->set->base.first;
476 *ob= (*base)->object;
484 if(*base == 0) fase= F_START;
487 if( (*base)->object->transflag & OB_DUPLI) {
489 make_duplilist(G.scene, (*base)->object);
490 dupob= duplilist.first;
500 dupob= dupob->id.next;
502 else if(fase==F_DUPLI) {
515 Object *scene_find_camera(Scene *sc)
519 for (base= sc->base.first; base; base= base->next)
520 if (base->object->type==OB_CAMERA)
527 Base *scene_add_base(Scene *sce, Object *ob)
529 Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
530 BLI_addhead(&sce->base, b);
539 void scene_deselect_all(Scene *sce)
543 for (b= sce->base.first; b; b= b->next) {
545 b->object->flag= b->flag;
549 void scene_select_base(Scene *sce, Base *selbase)
551 scene_deselect_all(sce);
553 selbase->flag |= SELECT;
554 selbase->object->flag= selbase->flag;
556 sce->basact= selbase;