LEFT | RIGHT |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 26 matching lines...) Expand all Loading... |
37 #ifndef WIN32· | 37 #ifndef WIN32· |
38 #include <unistd.h> | 38 #include <unistd.h> |
39 #else | 39 #else |
40 #include <io.h> | 40 #include <io.h> |
41 #endif | 41 #endif |
42 | 42 |
43 #include "MEM_guardedalloc.h" | 43 #include "MEM_guardedalloc.h" |
44 | 44 |
45 #include "DNA_anim_types.h" | 45 #include "DNA_anim_types.h" |
46 #include "DNA_group_types.h" | 46 #include "DNA_group_types.h" |
47 #include "DNA_linestyle_types.h" | |
48 #include "DNA_node_types.h" | 47 #include "DNA_node_types.h" |
49 #include "DNA_object_types.h" | 48 #include "DNA_object_types.h" |
50 #include "DNA_rigidbody_types.h" | |
51 #include "DNA_scene_types.h" | 49 #include "DNA_scene_types.h" |
52 #include "DNA_screen_types.h" | 50 #include "DNA_screen_types.h" |
53 #include "DNA_sequence_types.h" | 51 #include "DNA_sequence_types.h" |
54 | 52 |
55 #include "BLI_math.h" | 53 #include "BLI_math.h" |
56 #include "BLI_blenlib.h" | 54 #include "BLI_blenlib.h" |
57 #include "BLI_utildefines.h" | 55 #include "BLI_utildefines.h" |
58 #include "BLI_callbacks.h" | 56 #include "BLI_callbacks.h" |
59 #include "BLI_string.h" | |
60 #include "BLI_threads.h" | |
61 | |
62 #include "BLF_translation.h" | |
63 | 57 |
64 #include "BKE_anim.h" | 58 #include "BKE_anim.h" |
65 #include "BKE_animsys.h" | 59 #include "BKE_animsys.h" |
66 #include "BKE_action.h" | |
67 #include "BKE_colortools.h" | |
68 #include "BKE_depsgraph.h" | 60 #include "BKE_depsgraph.h" |
69 #include "BKE_fcurve.h" | |
70 #include "BKE_freestyle.h" | |
71 #include "BKE_global.h" | 61 #include "BKE_global.h" |
72 #include "BKE_group.h" | 62 #include "BKE_group.h" |
73 #include "BKE_idprop.h" | 63 #include "BKE_idprop.h" |
74 #include "BKE_image.h" | |
75 #include "BKE_library.h" | 64 #include "BKE_library.h" |
76 #include "BKE_main.h" | 65 #include "BKE_main.h" |
77 #include "BKE_mask.h" | |
78 #include "BKE_node.h" | 66 #include "BKE_node.h" |
79 #include "BKE_object.h" | 67 #include "BKE_object.h" |
80 #include "BKE_paint.h" | 68 #include "BKE_paint.h" |
81 #include "BKE_pointcache.h" | 69 #include "BKE_pointcache.h" |
82 #include "BKE_rigidbody.h" | |
83 #include "BKE_scene.h" | 70 #include "BKE_scene.h" |
84 #include "BKE_sequencer.h" | 71 #include "BKE_sequencer.h" |
| 72 #include "BKE_world.h" |
| 73 |
85 #include "BKE_sound.h" | 74 #include "BKE_sound.h" |
86 #include "BKE_world.h" | |
87 | 75 |
88 #include "RE_engine.h" | 76 #include "RE_engine.h" |
89 | |
90 #include "IMB_colormanagement.h" | |
91 | 77 |
92 //XXX #include "BIF_previewrender.h" | 78 //XXX #include "BIF_previewrender.h" |
93 //XXX #include "BIF_editseq.h" | 79 //XXX #include "BIF_editseq.h" |
94 | 80 |
95 #ifdef WIN32 | 81 #ifdef WIN32 |
96 #else | 82 #else |
97 #include <sys/time.h> | 83 #include <sys/time.h> |
98 #endif | 84 #endif |
99 | 85 |
100 void free_avicodecdata(AviCodecData *acd) | 86 void free_avicodecdata(AviCodecData *acd) |
(...skipping 16 matching lines...) Expand all Loading... |
117 { | 103 { |
118 if (qcd) { | 104 if (qcd) { |
119 if (qcd->cdParms) { | 105 if (qcd->cdParms) { |
120 MEM_freeN(qcd->cdParms); | 106 MEM_freeN(qcd->cdParms); |
121 qcd->cdParms = NULL; | 107 qcd->cdParms = NULL; |
122 qcd->cdSize = 0; | 108 qcd->cdSize = 0; |
123 } | 109 } |
124 } | 110 } |
125 } | 111 } |
126 | 112 |
127 static void remove_sequencer_fcurves(Scene *sce) | |
128 { | |
129 AnimData *adt = BKE_animdata_from_id(&sce->id); | |
130 | |
131 if (adt && adt->action) { | |
132 FCurve *fcu, *nextfcu; | |
133 ················ | |
134 for (fcu = adt->action->curves.first; fcu; fcu = nextfcu) { | |
135 nextfcu = fcu->next; | |
136 ························ | |
137 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_
all")) { | |
138 action_groups_remove_channel(adt->action, fcu); | |
139 free_fcurve(fcu); | |
140 } | |
141 } | |
142 } | |
143 } | |
144 | |
145 Scene *BKE_scene_copy(Scene *sce, int type) | 113 Scene *BKE_scene_copy(Scene *sce, int type) |
146 { | 114 { |
147 Scene *scen; | 115 Scene *scen; |
148 SceneRenderLayer *srl, *new_srl; | |
149 ToolSettings *ts; | 116 ToolSettings *ts; |
150 Base *base, *obase; | 117 Base *base, *obase; |
151 ········ | 118 ········ |
152 if (type == SCE_COPY_EMPTY) { | 119 if (type == SCE_COPY_EMPTY) { |
153 ListBase lb; | 120 ListBase lb; |
154 » » /* XXX. main should become an arg */ | 121 » » scen = BKE_scene_add(sce->id.name + 2); |
155 » » scen = BKE_scene_add(G.main, sce->id.name + 2); | |
156 ················ | 122 ················ |
157 lb = scen->r.layers; | 123 lb = scen->r.layers; |
158 scen->r = sce->r; | 124 scen->r = sce->r; |
159 scen->r.layers = lb; | 125 scen->r.layers = lb; |
160 scen->r.actlay = 0; | |
161 scen->unit = sce->unit; | 126 scen->unit = sce->unit; |
162 scen->physics_settings = sce->physics_settings; | 127 scen->physics_settings = sce->physics_settings; |
163 scen->gm = sce->gm; | 128 scen->gm = sce->gm; |
164 scen->audio = sce->audio; | 129 scen->audio = sce->audio; |
165 | 130 |
166 MEM_freeN(scen->toolsettings); | 131 MEM_freeN(scen->toolsettings); |
167 } | 132 } |
168 else { | 133 else { |
169 scen = BKE_libblock_copy(&sce->id); | 134 scen = BKE_libblock_copy(&sce->id); |
170 BLI_duplicatelist(&(scen->base), &(sce->base)); | 135 BLI_duplicatelist(&(scen->base), &(sce->base)); |
171 ················ | 136 ················ |
172 clear_id_newpoins(); | 137 clear_id_newpoins(); |
173 ················ | 138 ················ |
174 id_us_plus((ID *)scen->world); | 139 id_us_plus((ID *)scen->world); |
175 id_us_plus((ID *)scen->set); | 140 id_us_plus((ID *)scen->set); |
176 id_us_plus((ID *)scen->gm.dome.warptext); | 141 id_us_plus((ID *)scen->gm.dome.warptext); |
177 | 142 |
178 scen->ed = NULL; | 143 scen->ed = NULL; |
179 scen->theDag = NULL; | 144 scen->theDag = NULL; |
180 scen->obedit = NULL; | 145 scen->obedit = NULL; |
181 scen->stats = NULL; | 146 scen->stats = NULL; |
182 scen->fps_info = NULL; | 147 scen->fps_info = NULL; |
183 | 148 |
184 if (sce->rigidbody_world) | |
185 scen->rigidbody_world = BKE_rigidbody_world_copy(sce->ri
gidbody_world); | |
186 | |
187 BLI_duplicatelist(&(scen->markers), &(sce->markers)); | 149 BLI_duplicatelist(&(scen->markers), &(sce->markers)); |
188 BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_sp
aces)); | 150 BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_sp
aces)); |
189 BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers)); | 151 BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers)); |
190 BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); | 152 BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets)); |
191 | 153 |
192 if (sce->nodetree) { | 154 if (sce->nodetree) { |
193 » » » /* ID's are managed on both copy and switch */ | 155 » » » scen->nodetree = ntreeCopyTree(sce->nodetree); /* copies
actions */ |
194 » » » scen->nodetree = ntreeCopyTree(sce->nodetree); | |
195 ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); | 156 ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); |
196 } | 157 } |
197 | 158 |
198 obase = sce->base.first; | 159 obase = sce->base.first; |
199 base = scen->base.first; | 160 base = scen->base.first; |
200 while (base) { | 161 while (base) { |
201 id_us_plus(&base->object->id); | 162 id_us_plus(&base->object->id); |
202 if (obase == sce->basact) scen->basact = base; | 163 if (obase == sce->basact) scen->basact = base; |
203 ········ | 164 ········ |
204 obase = obase->next; | 165 obase = obase->next; |
205 base = base->next; | 166 base = base->next; |
206 } | |
207 | |
208 /* copy color management settings */ | |
209 BKE_color_managed_display_settings_copy(&scen->display_settings,
&sce->display_settings); | |
210 BKE_color_managed_view_settings_copy(&scen->view_settings, &sce-
>view_settings); | |
211 BKE_color_managed_view_settings_copy(&scen->r.im_format.view_set
tings, &sce->r.im_format.view_settings); | |
212 | |
213 BLI_strncpy(scen->sequencer_colorspace_settings.name, sce->seque
ncer_colorspace_settings.name, | |
214 sizeof(scen->sequencer_colorspace_settings.name)); | |
215 | |
216 /* remove animation used by sequencer */ | |
217 if (type != SCE_COPY_FULL) | |
218 remove_sequencer_fcurves(scen); | |
219 | |
220 /* copy Freestyle settings */ | |
221 new_srl = scen->r.layers.first; | |
222 for (srl = sce->r.layers.first; srl; srl = srl->next) { | |
223 BKE_freestyle_config_copy(&new_srl->freestyleConfig, &sr
l->freestyleConfig); | |
224 new_srl = new_srl->next; | |
225 } | 167 } |
226 } | 168 } |
227 | 169 |
228 /* tool settings */ | 170 /* tool settings */ |
229 scen->toolsettings = MEM_dupallocN(sce->toolsettings); | 171 scen->toolsettings = MEM_dupallocN(sce->toolsettings); |
230 | 172 |
231 ts = scen->toolsettings; | 173 ts = scen->toolsettings; |
232 if (ts) { | 174 if (ts) { |
233 if (ts->vpaint) { | 175 if (ts->vpaint) { |
234 ts->vpaint = MEM_dupallocN(ts->vpaint); | 176 ts->vpaint = MEM_dupallocN(ts->vpaint); |
235 ts->vpaint->paintcursor = NULL; | 177 ts->vpaint->paintcursor = NULL; |
236 ts->vpaint->vpaint_prev = NULL; | 178 ts->vpaint->vpaint_prev = NULL; |
237 ts->vpaint->wpaint_prev = NULL; | 179 ts->vpaint->wpaint_prev = NULL; |
238 » » » BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint); | 180 » » » copy_paint(&ts->vpaint->paint, &ts->vpaint->paint); |
239 } | 181 } |
240 if (ts->wpaint) { | 182 if (ts->wpaint) { |
241 ts->wpaint = MEM_dupallocN(ts->wpaint); | 183 ts->wpaint = MEM_dupallocN(ts->wpaint); |
242 ts->wpaint->paintcursor = NULL; | 184 ts->wpaint->paintcursor = NULL; |
243 ts->wpaint->vpaint_prev = NULL; | 185 ts->wpaint->vpaint_prev = NULL; |
244 ts->wpaint->wpaint_prev = NULL; | 186 ts->wpaint->wpaint_prev = NULL; |
245 » » » BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint); | 187 » » » copy_paint(&ts->wpaint->paint, &ts->wpaint->paint); |
246 } | 188 } |
247 if (ts->sculpt) { | 189 if (ts->sculpt) { |
248 ts->sculpt = MEM_dupallocN(ts->sculpt); | 190 ts->sculpt = MEM_dupallocN(ts->sculpt); |
249 » » » BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint); | 191 » » » copy_paint(&ts->sculpt->paint, &ts->sculpt->paint); |
250 » » } | 192 » » } |
251 | 193 |
252 » » BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint); | 194 » » copy_paint(&ts->imapaint.paint, &ts->imapaint.paint); |
253 ts->imapaint.paintcursor = NULL; | 195 ts->imapaint.paintcursor = NULL; |
254 ts->particle.paintcursor = NULL; | 196 ts->particle.paintcursor = NULL; |
255 } | 197 } |
256 ········ | 198 ········ |
257 /* make a private copy of the avicodecdata */ | 199 /* make a private copy of the avicodecdata */ |
258 if (sce->r.avicodecdata) { | 200 if (sce->r.avicodecdata) { |
259 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata); | 201 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata); |
260 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecd
ata->lpFormat); | 202 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecd
ata->lpFormat); |
261 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecda
ta->lpParms); | 203 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecda
ta->lpParms); |
262 } | 204 } |
(...skipping 23 matching lines...) Expand all Loading... |
286 if (type == SCE_COPY_FULL) { | 228 if (type == SCE_COPY_FULL) { |
287 BKE_copy_animdata_id_action((ID *)scen); | 229 BKE_copy_animdata_id_action((ID *)scen); |
288 if (scen->world) { | 230 if (scen->world) { |
289 id_us_plus((ID *)scen->world); | 231 id_us_plus((ID *)scen->world); |
290 scen->world = BKE_world_copy(scen->world); | 232 scen->world = BKE_world_copy(scen->world); |
291 BKE_copy_animdata_id_action((ID *)scen->world); | 233 BKE_copy_animdata_id_action((ID *)scen->world); |
292 } | 234 } |
293 | 235 |
294 if (sce->ed) { | 236 if (sce->ed) { |
295 scen->ed = MEM_callocN(sizeof(Editing), "addseq"); | 237 scen->ed = MEM_callocN(sizeof(Editing), "addseq"); |
| 238 scen->ed->seqbasep = &scen->ed->seqbase; |
| 239 seqbase_dupli_recursive(sce, scen, &scen->ed->seqbase, &
sce->ed->seqbase, SEQ_DUPE_ALL); |
| 240 } |
| 241 } |
| 242 |
| 243 return scen; |
| 244 } |
| 245 |
| 246 /* do not free scene itself */ |
| 247 void BKE_scene_free(Scene *sce) |
| 248 { |
| 249 Base *base; |
| 250 |
| 251 base = sce->base.first; |
| 252 while (base) { |
| 253 base->object->id.us--; |
| 254 base = base->next; |
| 255 } |
| 256 /* do not free objects! */ |
| 257 ········ |
| 258 if (sce->gpd) { |
| 259 #if 0 // removed since this can be invalid memory when freeing everything |
| 260 // since the grease pencil data is freed before the scene. |
| 261 // since grease pencil data is not (yet?), shared between object
s |
| 262 // its probably safe not to do this, some save and reload will f
ree this. |
| 263 sce->gpd->id.us--; |
| 264 #endif |
| 265 sce->gpd = NULL; |
| 266 } |
| 267 |
| 268 BLI_freelistN(&sce->base); |
| 269 BKE_sequencer_editing_free(sce); |
| 270 |
| 271 BKE_free_animdata((ID *)sce); |
| 272 BKE_keyingsets_free(&sce->keyingsets); |
| 273 ········ |
| 274 if (sce->r.avicodecdata) { |
| 275 free_avicodecdata(sce->r.avicodecdata); |
| 276 MEM_freeN(sce->r.avicodecdata); |
| 277 sce->r.avicodecdata = NULL; |
| 278 } |
| 279 if (sce->r.qtcodecdata) { |
| 280 free_qtcodecdata(sce->r.qtcodecdata); |
| 281 MEM_freeN(sce->r.qtcodecdata); |
| 282 sce->r.qtcodecdata = NULL; |
| 283 } |
| 284 if (sce->r.ffcodecdata.properties) { |
| 285 IDP_FreeProperty(sce->r.ffcodecdata.properties); |
| 286 MEM_freeN(sce->r.ffcodecdata.properties); |
| 287 sce->r.ffcodecdata.properties = NULL; |
| 288 } |
| 289 ········ |
| 290 BLI_freelistN(&sce->markers); |
| 291 BLI_freelistN(&sce->transform_spaces); |
| 292 BLI_freelistN(&sce->r.layers); |
| 293 ········ |
| 294 if (sce->toolsettings) { |
| 295 if (sce->toolsettings->vpaint) { |
| 296 free_paint(&sce->toolsettings->vpaint->paint); |
| 297 MEM_freeN(sce->toolsettings->vpaint); |
| 298 } |
296 free_paint(&sce->toolsettings->sculpt->paint); | 299 free_paint(&sce->toolsettings->sculpt->paint); |
297 MEM_freeN(sce->toolsettings->sculpt); | 300 MEM_freeN(sce->toolsettings->sculpt); |
298 } | 301 } |
299 free_paint(&sce->toolsettings->imapaint.paint); | 302 free_paint(&sce->toolsettings->imapaint.paint); |
300 | 303 |
301 MEM_freeN(sce->toolsettings); | 304 MEM_freeN(sce->toolsettings); |
LEFT | RIGHT |