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_cloth_types.h"
39 #include "DNA_constraint_types.h"
40 #include "DNA_sdna_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_mesh_types.h"
45 #include "DNA_modifier_types.h"
46 #include "DNA_particle_types.h"
47 #include "DNA_linestyle_types.h"
48 #include "DNA_actuator_types.h"
50 #include "DNA_genfile.h"
56 #include "BLI_listbase.h"
57 #include "BLI_string.h"
59 #include "BLO_readfile.h"
64 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
68 for (con = lb->first; con; con = con->next) {
69 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
70 bTransformConstraint *data = (bTransformConstraint *)con->data;
71 const float deg_to_rad_f = DEG2RADF(1.0f);
73 if (data->from == TRANS_ROTATION) {
74 mul_v3_fl(data->from_min, deg_to_rad_f);
75 mul_v3_fl(data->from_max, deg_to_rad_f);
78 if (data->to == TRANS_ROTATION) {
79 mul_v3_fl(data->to_min, deg_to_rad_f);
80 mul_v3_fl(data->to_max, deg_to_rad_f);
86 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
90 for (con = lb->first; con; con = con->next) {
91 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
92 bTransformConstraint *data = (bTransformConstraint *)con->data;
94 if (data->from == TRANS_ROTATION) {
95 copy_v3_v3(data->from_min_rot, data->from_min);
96 copy_v3_v3(data->from_max_rot, data->from_max);
98 else if (data->from == TRANS_SCALE) {
99 copy_v3_v3(data->from_min_scale, data->from_min);
100 copy_v3_v3(data->from_max_scale, data->from_max);
103 if (data->to == TRANS_ROTATION) {
104 copy_v3_v3(data->to_min_rot, data->to_min);
105 copy_v3_v3(data->to_max_rot, data->to_max);
107 else if (data->to == TRANS_SCALE) {
108 copy_v3_v3(data->to_min_scale, data->to_min);
109 copy_v3_v3(data->to_max_scale, data->to_max);
115 static void do_version_constraints_stretch_to_limits(ListBase *lb)
119 for (con = lb->first; con; con = con->next) {
120 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
121 bStretchToConstraint *data = (bStretchToConstraint *)con->data;
122 data->bulge_min = 1.0f;
123 data->bulge_max = 1.0f;
128 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
130 if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
132 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
135 for (ob = main->object.first; ob; ob = ob->id.next) {
137 for (md = ob->modifiers.first; md; md = md->next) {
138 if (md->type == eModifierType_Bevel) {
139 BevelModifierData *bmd = (BevelModifierData *)md;
141 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
147 /* nodes don't use fixed node->id any more, clean up */
148 FOREACH_NODETREE(main, ntree, id) {
149 if (ntree->type == NTREE_COMPOSIT) {
151 for (node = ntree->nodes.first; node; node = node->next) {
152 if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
157 } FOREACH_NODETREE_END
162 for (screen = main->screen.first; screen; screen = screen->id.next) {
164 for (area = screen->areabase.first; area; area = area->next) {
165 SpaceLink *space_link;
166 for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
167 if (space_link->spacetype == SPACE_CLIP) {
168 SpaceClip *space_clip = (SpaceClip *) space_link;
169 if (space_clip->mode != SC_MODE_MASKEDIT) {
170 space_clip->mode = SC_MODE_TRACKING;
178 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
180 for (clip = main->movieclip.first; clip; clip = clip->id.next) {
181 clip->tracking.settings.default_weight = 1.0f;
186 if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
190 /* Update Transform constraint (another deg -> rad stuff). */
191 for (ob = main->object.first; ob; ob = ob->id.next) {
192 do_version_constraints_radians_degrees_270_1(&ob->constraints);
195 /* Bones constraints! */
197 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
198 do_version_constraints_radians_degrees_270_1(&pchan->constraints);
203 for (sce = main->scene.first; sce; sce = sce->id.next) {
204 if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
205 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
210 if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
213 /* Mesh smoothresh deg->rad. */
214 for (me = main->mesh.first; me; me = me->id.next) {
215 me->smoothresh = DEG2RADF(me->smoothresh);
219 if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
220 FreestyleLineStyle *linestyle;
222 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
223 linestyle->flag |= LS_NO_SORTING;
224 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
225 linestyle->integration_type = LS_INTEGRATION_MEAN;
229 if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
230 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
231 * This will always reset situation to a valid state.
235 for (sc = main->screen.first; sc; sc = sc->id.next) {
237 for (sa = sc->areabase.first; sa; sa = sa->next) {
240 for (sl = sa->spacedata.first; sl; sl = sl->next) {
242 ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
244 for (ar = lb->first; ar; ar = ar->next) {
245 BLI_listbase_clear(&ar->ui_previews);
252 if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
255 /* Update Transform constraint (again :|). */
256 for (ob = main->object.first; ob; ob = ob->id.next) {
257 do_version_constraints_radians_degrees_270_5(&ob->constraints);
260 /* Bones constraints! */
262 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
263 do_version_constraints_radians_degrees_270_5(&pchan->constraints);
269 if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
270 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
273 for (ma = main->mat.first; ma; ma = ma->id.next)
274 ma->mode2 = MA_CASTSHADOW;
277 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
280 for (sce = main->scene.first; sce; sce = sce->id.next) {
281 sce->r.bake.flag = R_BAKE_CLEAR;
282 sce->r.bake.width = 512;
283 sce->r.bake.height = 512;
284 sce->r.bake.margin = 16;
285 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
286 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
287 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
288 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
289 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
291 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
292 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
293 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
294 sce->r.bake.im_format.quality = 90;
295 sce->r.bake.im_format.compress = 15;
299 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
300 FreestyleLineStyle *linestyle;
302 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
303 linestyle->flag |= LS_TEXTURE;
304 linestyle->texstep = 1.0;
310 for (scene = main->scene.first; scene; scene = scene->id.next) {
311 int num_layers = BLI_listbase_count(&scene->r.layers);
312 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
317 if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
318 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
321 for (mat = main->mat.first; mat; mat = mat->id.next) {
322 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
323 mat->line_col[3] = mat->alpha;
327 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
329 for (scene = main->scene.first; scene; scene = scene->id.next) {
330 scene->r.preview_start_resolution = 64;
335 if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
336 /* init up & track axis property of trackto actuators */
339 for (ob = main->object.first; ob; ob = ob->id.next) {
341 for (act = ob->actuators.first; act; act = act->next) {
342 if (act->type == ACT_EDIT_OBJECT) {
343 bEditObjectActuator *eoact = act->data;
344 eoact->trackflag = ob->trackflag;
345 /* if trackflag is pointing +-Z axis then upflag should point Y axis.
346 * Rest of trackflag cases, upflag should be point z axis */
347 if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
358 if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
361 for (br = main->brush.first; br; br = br->id.next) {
362 br->fill_threshold = 0.2f;
365 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
367 for (ob = main->object.first; ob; ob = ob->id.next) {
370 for (md = ob->modifiers.first; md; md = md->next) {
371 if (md->type == eModifierType_Bevel) {
372 BevelModifierData *bmd = (BevelModifierData *)md;
380 if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
382 for (ob = main->object.first; ob; ob = ob->id.next) {
385 for (md = ob->modifiers.first; md; md = md->next) {
386 if (md->type == eModifierType_ParticleSystem) {
387 ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
388 if (pmd->psys && pmd->psys->clmd) {
389 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
396 if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
397 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
399 for (scene = main->scene.first; scene; scene = scene->id.next) {
400 scene->r.preview_start_resolution = 64;
405 if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
407 for (br = main->brush.first; br; br = br->id.next) {
408 if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
413 if (!MAIN_VERSION_ATLEAST(main, 272, 2)) {
414 if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
416 for (image = main->image.first; image != NULL; image = image->id.next) {
417 image->gen_color[3] = 1.0f;
421 if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
424 /* Update Transform constraint (again :|). */
425 for (ob = main->object.first; ob; ob = ob->id.next) {
426 do_version_constraints_stretch_to_limits(&ob->constraints);
429 /* Bones constraints! */
431 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
432 do_version_constraints_stretch_to_limits(&pchan->constraints);
439 if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
440 #define BRUSH_RAKE (1 << 7)
441 #define BRUSH_RANDOM_ROTATION (1 << 25)
445 for (br = main->brush.first; br; br = br->id.next) {
446 if (br->flag & BRUSH_RAKE) {
447 br->mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
448 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RAKE;
450 else if (br->flag & BRUSH_RANDOM_ROTATION) {
451 br->mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
452 br->mask_mtex.brush_angle_mode |= MTEX_ANGLE_RANDOM;
454 br->mtex.random_angle = 2.0f * M_PI;
455 br->mask_mtex.random_angle = 2.0f * M_PI;
459 #undef BRUSH_RANDOM_ROTATION
462 /* Customizable Safe Areas */
463 if (!MAIN_VERSION_ATLEAST(main, 273, 2)) {
464 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "DisplaySafeAreas", "safe_areas")) {
467 for (scene = main->scene.first; scene; scene = scene->id.next) {
468 copy_v2_fl2(scene->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
469 copy_v2_fl2(scene->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
470 copy_v2_fl2(scene->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
471 copy_v2_fl2(scene->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
476 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
479 for (ob = main->object.first; ob; ob = ob->id.next) {
480 for (md = ob->modifiers.first; md; md = md->next) {
481 if (md->type == eModifierType_Cloth) {
482 ClothModifierData *clmd = (ClothModifierData*) md;
483 clmd->sim_parms->bending_damping = 0.5f;
485 else if (md->type == eModifierType_ParticleSystem) {
486 ParticleSystemModifierData *pmd = (ParticleSystemModifierData*) md;
487 if (pmd->psys->clmd) {
488 pmd->psys->clmd->sim_parms->bending_damping = 0.5f;