2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation
20 * ***** END GPL LICENSE BLOCK *****
24 /** \file blender/blenloader/intern/versioning_270.c
28 #include "BLI_utildefines.h"
29 #include "BLI_compiler_attrs.h"
31 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
34 /* allow readfile to use deprecated functionality */
35 #define DNA_DEPRECATED_ALLOW
37 #include "DNA_brush_types.h"
38 #include "DNA_camera_types.h"
39 #include "DNA_cloth_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_sdna_types.h"
42 #include "DNA_sequence_types.h"
43 #include "DNA_space_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_object_types.h"
46 #include "DNA_mesh_types.h"
47 #include "DNA_modifier_types.h"
48 #include "DNA_particle_types.h"
49 #include "DNA_linestyle_types.h"
50 #include "DNA_actuator_types.h"
52 #include "DNA_genfile.h"
55 #include "BKE_modifier.h"
57 #include "BKE_sequencer.h"
58 #include "BKE_screen.h"
61 #include "BLI_listbase.h"
62 #include "BLI_string.h"
64 #include "BLO_readfile.h"
68 #include "MEM_guardedalloc.h"
70 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
74 for (con = lb->first; con; con = con->next) {
75 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
76 bTransformConstraint *data = (bTransformConstraint *)con->data;
77 const float deg_to_rad_f = DEG2RADF(1.0f);
79 if (data->from == TRANS_ROTATION) {
80 mul_v3_fl(data->from_min, deg_to_rad_f);
81 mul_v3_fl(data->from_max, deg_to_rad_f);
84 if (data->to == TRANS_ROTATION) {
85 mul_v3_fl(data->to_min, deg_to_rad_f);
86 mul_v3_fl(data->to_max, deg_to_rad_f);
92 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
96 for (con = lb->first; con; con = con->next) {
97 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
98 bTransformConstraint *data = (bTransformConstraint *)con->data;
100 if (data->from == TRANS_ROTATION) {
101 copy_v3_v3(data->from_min_rot, data->from_min);
102 copy_v3_v3(data->from_max_rot, data->from_max);
104 else if (data->from == TRANS_SCALE) {
105 copy_v3_v3(data->from_min_scale, data->from_min);
106 copy_v3_v3(data->from_max_scale, data->from_max);
109 if (data->to == TRANS_ROTATION) {
110 copy_v3_v3(data->to_min_rot, data->to_min);
111 copy_v3_v3(data->to_max_rot, data->to_max);
113 else if (data->to == TRANS_SCALE) {
114 copy_v3_v3(data->to_min_scale, data->to_min);
115 copy_v3_v3(data->to_max_scale, data->to_max);
121 static void do_version_constraints_stretch_to_limits(ListBase *lb)
125 for (con = lb->first; con; con = con->next) {
126 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
127 bStretchToConstraint *data = (bStretchToConstraint *)con->data;
128 data->bulge_min = 1.0f;
129 data->bulge_max = 1.0f;
134 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
136 if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
138 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
141 for (ob = main->object.first; ob; ob = ob->id.next) {
143 for (md = ob->modifiers.first; md; md = md->next) {
144 if (md->type == eModifierType_Bevel) {
145 BevelModifierData *bmd = (BevelModifierData *)md;
147 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
153 /* nodes don't use fixed node->id any more, clean up */
154 FOREACH_NODETREE(main, ntree, id) {
155 if (ntree->type == NTREE_COMPOSIT) {
157 for (node = ntree->nodes.first; node; node = node->next) {
158 if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
163 } FOREACH_NODETREE_END
168 for (screen = main->screen.first; screen; screen = screen->id.next) {
170 for (area = screen->areabase.first; area; area = area->next) {
171 SpaceLink *space_link;
172 for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
173 if (space_link->spacetype == SPACE_CLIP) {
174 SpaceClip *space_clip = (SpaceClip *) space_link;
175 if (space_clip->mode != SC_MODE_MASKEDIT) {
176 space_clip->mode = SC_MODE_TRACKING;
184 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
186 for (clip = main->movieclip.first; clip; clip = clip->id.next) {
187 clip->tracking.settings.default_weight = 1.0f;
192 if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
196 /* Update Transform constraint (another deg -> rad stuff). */
197 for (ob = main->object.first; ob; ob = ob->id.next) {
198 do_version_constraints_radians_degrees_270_1(&ob->constraints);
201 /* Bones constraints! */
203 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
204 do_version_constraints_radians_degrees_270_1(&pchan->constraints);
209 for (sce = main->scene.first; sce; sce = sce->id.next) {
210 if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
211 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
216 if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
219 /* Mesh smoothresh deg->rad. */
220 for (me = main->mesh.first; me; me = me->id.next) {
221 me->smoothresh = DEG2RADF(me->smoothresh);
225 if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
226 FreestyleLineStyle *linestyle;
228 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
229 linestyle->flag |= LS_NO_SORTING;
230 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
231 linestyle->integration_type = LS_INTEGRATION_MEAN;
235 if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
236 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
237 * This will always reset situation to a valid state.
241 for (sc = main->screen.first; sc; sc = sc->id.next) {
243 for (sa = sc->areabase.first; sa; sa = sa->next) {
246 for (sl = sa->spacedata.first; sl; sl = sl->next) {
248 ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
250 for (ar = lb->first; ar; ar = ar->next) {
251 BLI_listbase_clear(&ar->ui_previews);
258 if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
261 /* Update Transform constraint (again :|). */
262 for (ob = main->object.first; ob; ob = ob->id.next) {
263 do_version_constraints_radians_degrees_270_5(&ob->constraints);
266 /* Bones constraints! */
268 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
269 do_version_constraints_radians_degrees_270_5(&pchan->constraints);
275 if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
276 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
279 for (ma = main->mat.first; ma; ma = ma->id.next)
280 ma->mode2 = MA_CASTSHADOW;
283 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
286 for (sce = main->scene.first; sce; sce = sce->id.next) {
287 sce->r.bake.flag = R_BAKE_CLEAR;
288 sce->r.bake.width = 512;
289 sce->r.bake.height = 512;
290 sce->r.bake.margin = 16;
291 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
292 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
293 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
294 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
295 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
297 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
298 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
299 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
300 sce->r.bake.im_format.quality = 90;
301 sce->r.bake.im_format.compress = 15;
305 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
306 FreestyleLineStyle *linestyle;
308 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
309 linestyle->flag |= LS_TEXTURE;
310 linestyle->texstep = 1.0;
316 for (scene = main->scene.first; scene; scene = scene->id.next) {
317 int num_layers = BLI_listbase_count(&scene->r.layers);
318 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
323 if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
324 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
327 for (mat = main->mat.first; mat; mat = mat->id.next) {
328 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
329 mat->line_col[3] = mat->alpha;
333 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
335 for (scene = main->scene.first; scene; scene = scene->id.next) {
336 scene->r.preview_start_resolution = 64;
341 if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
342 /* init up & track axis property of trackto actuators */
345 for (ob = main->object.first; ob; ob = ob->id.next) {
347 for (act = ob->actuators.first; act; act = act->next) {
348 if (act->type == ACT_EDIT_OBJECT) {
349 bEditObjectActuator *eoact = act->data;
350 eoact->trackflag = ob->trackflag;
351 /* if trackflag is pointing +-Z axis then upflag should point Y axis.
352 * Rest of trackflag cases, upflag should be point z axis */
353 if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
364 if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
367 for (br = main->brush.first; br; br = br->id.next) {
368 br->fill_threshold = 0.2f;
371 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
373 for (ob = main->object.first; ob; ob = ob->id.next) {
376 for (md = ob->modifiers.first; md; md = md->next) {
377 if (md->type == eModifierType_Bevel) {
378 BevelModifierData *bmd = (BevelModifierData *)md;
386 if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
388 for (ob = main->object.first; ob; ob = ob->id.next) {
391 for (md = ob->modifiers.first; md; md = md->next) {
392 if (md->type == eModifierType_ParticleSystem) {
393 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
394 if (pmd->psys && pmd->psys->clmd) {
395 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
402 if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
403 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
405 for (scene = main->scene.first; scene; scene = scene->id.next) {
406 scene->r.preview_start_resolution = 64;
411 if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
413 for (br = main->brush.first; br; br = br->id.next) {
414 if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
419 if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
420 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
422 for (image = main->image.first; image != NULL; image = image->id.next) {
423 image->gen_color[3] = 1.0f;
427 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
430 /* Update Transform constraint (again :|). */
431 for (ob = main->object.first; ob; ob = ob->id.next) {
432 do_version_constraints_stretch_to_limits(&ob->constraints);
435 /* Bones constraints! */
437 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
438 do_version_constraints_stretch_to_limits(&pchan->constraints);
445 if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
446 #define BRUSH_RAKE (1 << 7)
447 #define BRUSH_RANDOM_ROTATION (1 << 25)
451 for (br = main->brush.first; br; br = br->id.next) {
452 if (br->flag & BRUSH_RAKE) {
453 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
454 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
456 else if (br->flag & BRUSH_RANDOM_ROTATION) {
457 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
458 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
460 br->mtex.random_angle = 2.0 * M_PI;
461 br->mask_mtex.random_angle = 2.0 * M_PI;
465 #undef BRUSH_RANDOM_ROTATION
468 /* Customizable Safe Areas */
469 if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
470 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
473 for (scene = main->scene.first; scene; scene = scene->id.next) {
474 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
475 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
476 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
477 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
482 if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
483 ParticleSettings *part;
484 for (part = main->particle.first; part; part = part->id.next) {
485 if (part->clumpcurve)
486 part->child_flag |= PART_CHILD_USE_CLUMP_CURVE;
487 if (part->roughcurve)
488 part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
492 if (!MAIN_VERSION_ATLEAST(main, 273, 6)) {
493 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
496 for (ob = main->object.first; ob; ob = ob->id.next) {
497 for (md = ob->modifiers.first; md; md = md->next) {
498 if (md->type == eModifierType_Cloth) {
499 ClothModifierData *clmd = (ClothModifierData *)md;
500 clmd->sim_parms->bending_damping = 0.5f;
502 else if (md->type == eModifierType_ParticleSystem) {
503 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
504 if (pmd->psys->clmd) {
505 pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
512 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "float", "clump_noise_size")) {
513 ParticleSettings *part;
514 for (part = main->particle.first; part; part = part->id.next) {
515 part->clump_noise_size = 1.0f;
519 if (!DNA_struct_elem_find(fd->filesdna, "ParticleSettings", "int", "kink_extra_steps")) {
520 ParticleSettings *part;
521 for (part = main->particle.first; part; part = part->id.next) {
522 part->kink_extra_steps = 4;
526 if (!DNA_struct_elem_find(fd->filesdna, "MTex", "float", "kinkampfac")) {
527 ParticleSettings *part;
528 for (part = main->particle.first; part; part = part->id.next) {
530 for (a = 0; a < MAX_MTEX; a++) {
531 MTex *mtex = part->mtex[a];
533 mtex->kinkampfac = 1.0f;
539 if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", "flag")) {
542 for (ob = main->object.first; ob; ob = ob->id.next) {
544 for (md = ob->modifiers.first; md; md = md->next) {
545 if (md->type == eModifierType_Hook) {
546 HookModifierData *hmd = (HookModifierData *)md;
547 hmd->falloff_type = eHook_Falloff_InvSquare;
553 if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
554 FOREACH_NODETREE(main, ntree, id) {
555 if (ntree->type == NTREE_COMPOSIT) {
557 for (node = ntree->nodes.first; node; node = node->next) {
558 if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
559 NodePlaneTrackDeformData *data = node->storage;
561 data->motion_blur_samples = 16;
562 data->motion_blur_shutter = 0.5f;
570 if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
572 for (ca = main->camera.first; ca; ca = ca->id.next) {
573 ca->gpu_dof.fstop = 128.0f;
574 ca->gpu_dof.focal_length = 1.0f;
575 ca->gpu_dof.focus_distance = 1.0f;
576 ca->gpu_dof.sensor = 1.0f;
581 if (!MAIN_VERSION_ATLEAST(main, 273, 7)) {
587 for (scr = main->screen.first; scr; scr = scr->id.next) {
588 /* Remove old deprecated region from filebrowsers */
589 for (sa = scr->areabase.first; sa; sa = sa->next) {
590 for (sl = sa->spacedata.first; sl; sl = sl->next) {
591 if (sl->spacetype == SPACE_FILE) {
592 for (ar = sl->regionbase.first; ar; ar = ar->next) {
593 if (ar->regiontype == RGN_TYPE_CHANNELS) {
599 /* Free old deprecated 'channel' region... */
600 BKE_area_region_free(NULL, ar);
601 BLI_freelinkN(&sl->regionbase, ar);
609 if (!MAIN_VERSION_ATLEAST(main, 273, 8)) {
611 for (ob = main->object.first; ob != NULL; ob = ob->id.next) {
613 for (md = ob->modifiers.last; md != NULL; md = md->prev) {
614 if (modifier_unique_name(&ob->modifiers, md)) {
615 printf("Warning: Object '%s' had several modifiers with the "
616 "same name, renamed one of them to '%s'.\n",
617 ob->id.name + 2, md->name);
623 if (!MAIN_VERSION_ATLEAST(main, 273, 9)) {
629 /* Make sure sequencer preview area limits zoom */
630 for (scr = main->screen.first; scr; scr = scr->id.next) {
631 for (sa = scr->areabase.first; sa; sa = sa->next) {
632 for (sl = sa->spacedata.first; sl; sl = sl->next) {
633 if (sl->spacetype == SPACE_SEQ) {
634 for (ar = sl->regionbase.first; ar; ar = ar->next) {
635 if (ar->regiontype == RGN_TYPE_PREVIEW) {
636 ar->v2d.keepzoom |= V2D_LIMITZOOM;
637 ar->v2d.minzoom = 0.001f;
638 ar->v2d.maxzoom = 1000.0f;
648 if (!MAIN_VERSION_ATLEAST(main, 274, 1)) {
649 /* particle systems need to be forced to redistribute for jitter mode fix */
652 ParticleSystem *psys;
653 for (ob = main->object.first; ob; ob = ob->id.next) {
654 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
655 psys->recalc |= PSYS_RECALC_RESET;
660 /* hysteresis setted to 10% but not actived */
661 if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) {
663 for (ob = main->object.first; ob; ob = ob->id.next) {
665 for (level = ob->lodlevels.first; level; level = level->next) {
666 level->obhysteresis = 10;
671 if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
673 for (scene = main->scene.first; scene; scene = scene->id.next) {
674 scene->gm.scehysteresis = 10;
679 if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
680 FOREACH_NODETREE(main, ntree, id) {
684 for (node = ntree->nodes.first; node; node = node->next) {
685 if (node->type == SH_NODE_MATERIAL) {
686 for (sock = node->inputs.first; sock; sock = sock->next) {
687 if (STREQ(sock->name, "Refl")) {
688 BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
692 else if (node->type == SH_NODE_MATERIAL_EXT) {
693 for (sock = node->outputs.first; sock; sock = sock->next) {
694 if (STREQ(sock->name, "Refl")) {
695 BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
697 else if (STREQ(sock->name, "Ray Mirror")) {
698 BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
703 } FOREACH_NODETREE_END
706 if (!DNA_struct_elem_find(fd->filesdna, "Sequence", "char", "storage")) {
710 #define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19)
711 #define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21)
713 for (scene = main->scene.first; scene; scene = scene->id.next) {
714 SEQ_BEGIN (scene->ed, seq) {
715 if (seq->strip && seq->strip->proxy) {
716 if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)
717 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR;
718 if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)
719 seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE;
726 #undef SEQ_USE_PROXY_CUSTOM_DIR
727 #undef SEQ_USE_PROXY_CUSTOM_FILE