7 * ***** BEGIN GPL 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.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL LICENSE BLOCK *****
35 #include "MEM_guardedalloc.h"
37 #include "DNA_world_types.h"
38 #include "DNA_texture_types.h"
39 #include "DNA_scriptlink_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_camera_types.h"
45 #include "BLI_blenlib.h"
46 #include "BLI_arithb.h"
48 #include "BKE_utildefines.h"
50 #include "BKE_library.h"
51 #include "BKE_animsys.h"
52 #include "BKE_world.h"
53 #include "BKE_global.h"
55 #include "BKE_icons.h"
57 #ifndef DISABLE_PYTHON
58 #include "BPY_extern.h"
65 void free_world(World *wrld)
70 #ifndef DISABLE_PYTHON
71 BPY_free_scriptlink(&wrld->scriptlink);
73 for(a=0; a<MAX_MTEX; a++) {
75 if(mtex && mtex->tex) mtex->tex->id.us--;
76 if(mtex) MEM_freeN(mtex);
78 BKE_previewimg_free(&wrld->preview);
80 BKE_free_animdata((ID *)wrld);
82 BKE_icon_delete((struct ID*)wrld);
87 World *add_world(char *name)
91 wrld= alloc_libblock(&G.main->world, ID_WO, name);
94 wrld->skytype= WO_SKYBLEND;
95 wrld->stardist= 15.0f;
99 wrld->exposure=wrld->range= 1.0f;
103 wrld->aoenergy= 1.0f;
105 wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY;
106 wrld->ao_approx_error= 0.25f;
108 wrld->preview = NULL;
113 World *copy_world(World *wrld)
118 wrldn= copy_libblock(wrld);
120 for(a=0; a<MAX_MTEX; a++) {
122 wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
123 memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
124 id_us_plus((ID *)wrldn->mtex[a]->tex);
128 if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview);
129 #ifndef DISABLE_PYTHON
130 BPY_copy_scriptlink(&wrld->scriptlink);
133 #if 0 // XXX old animation system
134 id_us_plus((ID *)wrldn->ipo);
135 #endif // XXX old animation system
140 void make_local_world(World *wrld)
146 /* - only lib users: do nothing
147 * - only local users: set flag
151 if(wrld->id.lib==0) return;
154 wrld->id.flag= LIB_LOCAL;
155 new_id(0, (ID *)wrld, 0);
159 sce= G.main->scene.first;
161 if(sce->world==wrld) {
162 if(sce->id.lib) lib= 1;
168 if(local && lib==0) {
170 wrld->id.flag= LIB_LOCAL;
171 new_id(0, (ID *)wrld, 0);
173 else if(local && lib) {
174 wrldn= copy_world(wrld);
177 sce= G.main->scene.first;
179 if(sce->world==wrld) {