Blender V5.3
versioning_legacy.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <climits>
11
12#ifndef WIN32
13# include <unistd.h> /* for read close */
14#else
15# include "BLI_winstuff.hh"
16# include "winsock2.h"
17# include <io.h> /* for open close read */
18#endif
19
20/* allow readfile to use deprecated functionality */
21#define DNA_DEPRECATED_ALLOW
22
23#include "DNA_armature_types.h"
24#include "DNA_camera_types.h"
27#include "DNA_curve_types.h"
28#include "DNA_effect_types.h"
29#include "DNA_key_types.h"
30#include "DNA_lattice_types.h"
31#include "DNA_listBase.h"
32#include "DNA_material_types.h"
33#include "DNA_mesh_types.h"
34#include "DNA_meshdata_types.h"
35#include "DNA_nla_types.h"
36#include "DNA_node_types.h"
39#include "DNA_object_types.h"
40#include "DNA_screen_types.h"
41#include "DNA_sequence_types.h"
42#include "DNA_sound_types.h"
43#include "DNA_space_types.h"
44#include "DNA_vfont_types.h"
45#include "DNA_view3d_types.h"
46#include "DNA_world_types.h"
47
48#include "MEM_guardedalloc.h"
49
50#include "BLI_listbase.hh"
51#include "BLI_math_matrix_c.hh"
52#include "BLI_math_vector_c.hh"
53#include "BLI_string.hh"
54#include "BLI_string_utf8.hh"
55#include "BLI_time.hh"
56#include "BLI_utildefines.hh"
57
58#include "BKE_action.hh"
59#include "BKE_armature.hh"
60#include "BKE_constraint.h"
61#include "BKE_customdata.hh"
62#include "BKE_deform.hh"
63#include "BKE_lattice.hh"
64#include "BKE_main.hh" /* for Main */
65#include "BKE_mesh.hh" /* for ME_ defines (patching) */
67#include "BKE_modifier.hh"
68#include "BKE_node.hh"
70#include "BKE_object.hh"
71#include "BKE_particle.h"
72#include "BKE_pointcache.h"
73
74#include "SEQ_iterator.hh"
75#include "SEQ_sequencer.hh"
76
77#include "BLO_readfile.hh"
78
79#include "readfile.hh"
80
81#include <cerrno>
82
83namespace blender {
84
85/* Make preferences read-only, use `versioning_userdef.cc`. */
86#define U (*((const UserDef *)&U))
87
88static void vcol_to_fcol(Mesh *mesh)
89{
90 MFace *mface;
91 uint *mcol, *mcoln, *mcolmain;
92 int a;
93
94 if (mesh->totface_legacy == 0 || mesh->mcol == nullptr) {
95 return;
96 }
97
98 mcoln = mcolmain = MEM_new_array_uninitialized<uint>(4 * mesh->totface_legacy, "mcoln");
99 mcol = reinterpret_cast<uint *>(mesh->mcol);
100 mface = mesh->mface;
101 for (a = mesh->totface_legacy; a > 0; a--, mface++) {
102 mcoln[0] = mcol[mface->v1];
103 mcoln[1] = mcol[mface->v2];
104 mcoln[2] = mcol[mface->v3];
105 mcoln[3] = mcol[mface->v4];
106 mcoln += 4;
107 }
108
109 MEM_delete(mesh->mcol);
110 mesh->mcol = reinterpret_cast<MCol *>(mcolmain);
111}
112
114{
115 float vec[3];
116
117 /* head */
118 copy_v3_v3(bone->arm_head, bone->arm_mat[3]);
119
120 /* tail is in current local coord system */
121 copy_v3_v3(vec, bone->arm_mat[1]);
122 mul_v3_fl(vec, bone->length);
123 add_v3_v3v3(bone->arm_tail, bone->arm_head, vec);
124
125 for (Bone &child : bone->childbase) {
127 }
128}
129
130static void bone_version_238(ListBaseT<Bone> *lb)
131{
132 for (Bone &bone : *lb) {
133 if (bone.rad_tail == 0.0f && bone.rad_head == 0.0f) {
134 bone.rad_head = 0.25f * bone.length;
135 bone.rad_tail = 0.1f * bone.length;
136
137 bone.dist -= bone.rad_head;
138 bone.dist = std::max(bone.dist, 0.0f);
139 }
140 bone_version_238(&bone.childbase);
141 }
142}
143
144static void bone_version_239(ListBaseT<Bone> *lb)
145{
146 for (Bone &bone : *lb) {
147 if (bone.layer == 0) {
148 bone.layer = 1;
149 }
150 bone_version_239(&bone.childbase);
151 }
152}
153
154static void ntree_version_241(bNodeTree *ntree)
155{
156 if (ntree->type == NTREE_COMPOSIT) {
157 for (bNode &node : ntree->nodes) {
158 if (node.type_legacy == CMP_NODE_BLUR) {
159 if (node.storage == nullptr) {
160 NodeBlurData *nbd = MEM_new<NodeBlurData>("node blur patch");
161 nbd->sizex = node.custom1;
162 nbd->sizey = node.custom2;
164 node.storage = nbd;
165 }
166 }
167 else if (node.type_legacy == CMP_NODE_VECBLUR) {
168 if (node.storage == nullptr) {
169 NodeBlurData *nbd = MEM_new<NodeBlurData>("node blur patch");
170 nbd->samples = node.custom1;
171 nbd->maxspeed = node.custom2;
172 nbd->fac = 1.0f;
173 node.storage = nbd;
174 }
175 }
176 }
177 }
178}
179
180static void ntree_version_242(bNodeTree *ntree)
181{
182 if (ntree->type == NTREE_COMPOSIT) {
183 for (bNode &node : ntree->nodes) {
184 if (node.type_legacy == CMP_NODE_HUE_SAT) {
185 if (node.storage) {
186 NodeHueSat *nhs = static_cast<NodeHueSat *>(node.storage);
187 if (nhs->val == 0.0f) {
188 nhs->val = 1.0f;
189 }
190 }
191 }
192 }
193 }
194}
195
196static void ntree_version_245(FileData *fd, Library * /*lib*/, bNodeTree *ntree)
197{
198 NodeTwoFloats *ntf;
199 ID *nodeid;
200 Image *image;
201 ImageUser *iuser;
202
203 if (ntree->type == NTREE_COMPOSIT) {
204 for (bNode &node : ntree->nodes) {
205 if (node.type_legacy == CMP_NODE_ALPHAOVER) {
206 if (!node.storage) {
207 ntf = MEM_new<NodeTwoFloats>("NodeTwoFloats");
208 node.storage = ntf;
209 if (node.custom1) {
210 ntf->x = 1.0f;
211 }
212 }
213 }
214
215 /* fix for temporary flag changes during 245 cycle */
216 nodeid = static_cast<ID *>(
217 blo_do_versions_newlibadr(fd, &ntree->id, ID_IS_LINKED(ntree), node.id));
218 if (node.storage && nodeid && GS(nodeid->name) == ID_IM) {
219 image = id_cast<Image *>(nodeid);
220 iuser = static_cast<ImageUser *>(node.storage);
221 if (iuser->flag & eImageUser_Flag(IMA_OLD_PREMUL)) {
223 }
224 if (iuser->flag & eImageUser_Flag(IMA_DO_PREMUL)) {
225 image->flag &= ~IMA_OLD_PREMUL;
226 image->alpha_mode = IMA_ALPHA_STRAIGHT;
227 }
228 }
229 }
230 }
231}
232
234{
235 IDProperty *loop;
236 int i;
237
238 for (loop = prop->data.group.first(), i = 0; loop; loop = loop->next, i++) {
239 if (loop->type == IDP_GROUP) {
241 }
242 }
243
244 if (prop->len != i) {
245 printf("Found and fixed bad id property group length.\n");
246 prop->len = i;
247 }
248}
249
250template<typename T> static void idproperties_fix_group_lengths(const ListBaseT<T> &idlist)
251{
252 for (ID &id : idlist.template cast<ID>()) {
253 if (id.properties) {
255 }
256 }
257}
258
260{
262 MTFace *mtf;
263 MCol *mcol;
264 TFace *tf;
265 int a, mtfacen, mcoln;
266
267 if (!mesh->vert_data.totlayer) {
269 &mesh->vert_data, CD_MVERT, mesh->mvert, mesh->verts_num, nullptr);
270
271 if (mesh->dvert) {
273 &mesh->vert_data, CD_MDEFORMVERT, mesh->dvert, mesh->verts_num, nullptr);
274 }
275 }
276
277 if (!mesh->edge_data.totlayer) {
279 &mesh->edge_data, CD_MEDGE, mesh->medge, mesh->edges_num, nullptr);
280 }
281
282 if (!mesh->fdata_legacy.totlayer) {
284 &mesh->fdata_legacy, CD_MFACE, mesh->mface, mesh->totface_legacy, nullptr);
285
286 if (mesh->tface) {
287 if (mesh->mcol) {
288 MEM_delete(mesh->mcol);
289 }
290
291 mesh->mcol = static_cast<MCol *>(CustomData_add_layer(
292 &mesh->fdata_legacy, CD_MCOL, CD_SET_DEFAULT, mesh->totface_legacy));
293 mesh->mtface = static_cast<MTFace *>(CustomData_add_layer(
294 &mesh->fdata_legacy, CD_MTFACE, CD_SET_DEFAULT, mesh->totface_legacy));
295
296 mtf = mesh->mtface;
297 mcol = mesh->mcol;
298 tf = mesh->tface;
299
300 for (a = 0; a < mesh->totface_legacy; a++, mtf++, tf++, mcol += 4) {
301 memcpy(mcol, tf->col, sizeof(tf->col));
302 memcpy(mtf->uv, tf->uv, sizeof(tf->uv));
303 }
304
305 MEM_delete(mesh->tface);
306 mesh->tface = nullptr;
307 }
308 else if (mesh->mcol) {
310 &mesh->fdata_legacy, CD_MCOL, mesh->mcol, mesh->totface_legacy, nullptr);
311 }
312 }
313
314 if (mesh->tface) {
315 MEM_delete(mesh->tface);
316 mesh->tface = nullptr;
317 }
318
319 for (a = 0, mtfacen = 0, mcoln = 0; a < mesh->fdata_legacy.totlayer; a++) {
320 layer = &mesh->fdata_legacy.layers[a];
321
322 if (layer->type == CD_MTFACE) {
323 if (layer->name[0] == 0) {
324 if (mtfacen == 0) {
325 STRNCPY_UTF8(layer->name, "UVMap");
326 }
327 else {
328 SNPRINTF_UTF8(layer->name, "UVMap.%.3d", mtfacen);
329 }
330 }
331 mtfacen++;
332 }
333 else if (layer->type == CD_MCOL) {
334 if (layer->name[0] == 0) {
335 if (mcoln == 0) {
336 STRNCPY_UTF8(layer->name, "Col");
337 }
338 else {
339 SNPRINTF_UTF8(layer->name, "Col.%.3d", mcoln);
340 }
341 }
342 mcoln++;
343 }
344 }
345}
346
347/* Only copy render texface layer from active. */
349{
351 int a;
352
353 for (a = 0; a < mesh->fdata_legacy.totlayer; a++) {
354 layer = &mesh->fdata_legacy.layers[a];
355 layer->active_rnd = layer->active;
356 }
357}
358
359/* struct NodeImageAnim moved to ImageUser, and we make it default available */
361{
362 if (ntree->type == NTREE_COMPOSIT) {
363 for (bNode &node : ntree->nodes) {
364 if (ELEM(node.type_legacy, CMP_NODE_IMAGE, CMP_NODE_VIEWER)) {
365 /* only image had storage */
366 if (node.storage) {
367 NodeImageAnim *nia = static_cast<NodeImageAnim *>(node.storage);
368 ImageUser *iuser = MEM_new<ImageUser>("ima user node");
369
370 iuser->frames = nia->frames;
371 iuser->sfra = nia->sfra;
372 iuser->offset = nia->nr - 1;
373 iuser->cycl = nia->cyclic;
374
375 node.storage = iuser;
376 MEM_delete(nia);
377 }
378 else {
379 ImageUser *iuser = MEM_new<ImageUser>("node image user");
380 iuser->sfra = 1;
381 node.storage = iuser;
382 }
383 }
384 }
385 }
386}
387
389{
390 PartEff *paf;
391
392 if (eff->type == EFF_PARTICLE) {
393 paf = reinterpret_cast<PartEff *>(eff);
394 if (paf->keys) {
395 MEM_delete(paf->keys);
396 }
397 }
398 MEM_delete(eff);
399}
400
401static void do_version_free_effects_245(ListBaseT<Effect> *lb)
402{
403 while (Effect *eff = static_cast<Effect *>(BLI_pophead(lb))) {
405 }
406}
407
408static void do_version_constraints_245(ListBaseT<bConstraint> *lb)
409{
410 for (bConstraint &con : *lb) {
411 if (con.type == CONSTRAINT_TYPE_LOCLIKE) {
412 bLocateLikeConstraint *data = static_cast<bLocateLikeConstraint *>(con.data);
413
414 /* new headtail functionality makes Bone-Tip function obsolete */
415 if (data->flag & LOCLIKE_TIP) {
416 con.headtail = 1.0f;
417 }
418 }
419 }
420}
421
423{
424 /* create new trackto constraint from the relationship */
425 if (ob->track) {
427 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(con->data);
428
429 /* copy tracking settings from the object */
430 data->tar = ob->track;
431 data->reserved1 = eTrackToAxis_Modes(ob->trackflag);
432 data->reserved2 = eUpAxis_Modes(ob->upflag);
433 }
434
435 /* clear old track setting */
436 ob->track = nullptr;
437}
438
439static bool strip_set_alpha_mode_cb(Strip *strip, void * /*user_data*/)
440{
442 strip->alpha_mode = SEQ_ALPHA_STRAIGHT;
443 }
444 return true;
445}
446
447static bool strip_set_blend_mode_cb(Strip *strip, void * /*user_data*/)
448{
449 if (strip->blend_mode == STRIP_BLEND_REPLACE) {
450 strip->blend_opacity = 100.0f;
451 }
452 return true;
453}
454
455/* NOLINTNEXTLINE: readability-function-size */
457{
458 /* WATCH IT!!!: pointers from libdata have not been converted */
459
460 if (bmain->versionfile == 100) {
461 /* tex->extend and tex->imageflag have changed: */
462 Tex *tex = bmain->textures.first();
463 while (tex) {
465 if (tex->extend == 0) {
466 if (tex->xrepeat || tex->yrepeat) {
467 tex->extend = TEX_REPEAT;
468 }
469 else {
470 tex->extend = TEX_EXTEND;
471 tex->xrepeat = tex->yrepeat = 1;
472 }
473 }
474 }
475 tex = static_cast<Tex *>(tex->id.next);
476 }
477 }
478
479 if (bmain->versionfile <= 101) {
480 /* frame mapping */
481 Scene *sce = bmain->scenes.first();
482 while (sce) {
483 sce->r.framapto = 100;
484 sce->r.images = 100;
485 sce->r.framelen = 1.0;
486 sce = static_cast<Scene *>(sce->id.next);
487 }
488 }
489
490 if (bmain->versionfile <= 103) {
491 /* new variable in object: colbits */
492 Object *ob = bmain->objects.first();
493 int a;
494 while (ob) {
495 ob->colbits = 0;
496 if (ob->totcol) {
497 for (a = 0; a < ob->totcol; a++) {
498 if (ob->mat[a]) {
499 ob->colbits |= (1 << a);
500 }
501 }
502 }
503 ob = static_cast<Object *>(ob->id.next);
504 }
505 }
506
507 if (bmain->versionfile <= 104) {
508 /* timeoffs moved */
509 Object *ob = bmain->objects.first();
510 while (ob) {
511 if (ob->transflag & 1) {
513 }
514 ob = static_cast<Object *>(ob->id.next);
515 }
516 }
517
518 if (bmain->versionfile <= 106) {
519 /* mcol changed */
520 Mesh *mesh = bmain->meshes.first();
521 while (mesh) {
522 if (mesh->mcol) {
524 }
525 mesh = static_cast<Mesh *>(mesh->id.next);
526 }
527 }
528
529 if (bmain->versionfile <= 107) {
530 Object *ob;
531 ob = bmain->objects.first();
532 while (ob) {
533 if (ob->dt == 0) {
534 ob->dt = OB_SOLID;
535 }
536 ob = static_cast<Object *>(ob->id.next);
537 }
538 }
539
540 if (bmain->versionfile <= 109) {
541 /* New variable: `gridlines`. */
542 bScreen *screen = bmain->screens.first();
543 while (screen) {
544 ScrArea *area = screen->areabase.first();
545 while (area) {
546 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
547 while (sl) {
548 if (sl->spacetype == SPACE_VIEW3D) {
549 View3D *v3d = reinterpret_cast<View3D *>(sl);
550
551 if (v3d->gridlines == 0) {
552 v3d->gridlines = 20;
553 }
554 }
555 sl = sl->next;
556 }
557 area = area->next;
558 }
559 screen = static_cast<bScreen *>(screen->id.next);
560 }
561 }
562
563 if (bmain->versionfile <= 134) {
564 Tex *tex = bmain->textures.first();
565 while (tex) {
566 if ((tex->rfac == 0.0f) && (tex->gfac == 0.0f) && (tex->bfac == 0.0f)) {
567 tex->rfac = 1.0f;
568 tex->gfac = 1.0f;
569 tex->bfac = 1.0f;
570 tex->filtersize = 1.0f;
571 }
572 tex = static_cast<Tex *>(tex->id.next);
573 }
574 }
575
576 if (bmain->versionfile <= 140) {
577 /* r-g-b-fac in texture */
578 Tex *tex = bmain->textures.first();
579 while (tex) {
580 if ((tex->rfac == 0.0f) && (tex->gfac == 0.0f) && (tex->bfac == 0.0f)) {
581 tex->rfac = 1.0f;
582 tex->gfac = 1.0f;
583 tex->bfac = 1.0f;
584 tex->filtersize = 1.0f;
585 }
586 tex = static_cast<Tex *>(tex->id.next);
587 }
588 }
589
590 if (bmain->versionfile <= 153) {
591 Scene *sce = bmain->scenes.first();
592 while (sce) {
593 if (sce->r.motion_blur_shutter == 0.0f) {
594 sce->r.motion_blur_shutter = 1.0f;
595 }
596 sce = static_cast<Scene *>(sce->id.next);
597 }
598 }
599
600 if (bmain->versionfile <= 163) {
601 Scene *sce = bmain->scenes.first();
602 while (sce) {
603 if (sce->r.frs_sec == 0) {
604 sce->r.frs_sec = 25;
605 }
606 sce = static_cast<Scene *>(sce->id.next);
607 }
608 }
609
610 if (bmain->versionfile <= 164) {
611 Mesh *mesh = bmain->meshes.first();
612 while (mesh) {
613 mesh->smoothresh_legacy = 30;
614 mesh = static_cast<Mesh *>(mesh->id.next);
615 }
616 }
617
618 if (bmain->versionfile <= 165) {
619 Mesh *mesh = bmain->meshes.first();
620 TFace *tface;
621 int nr;
622 char *cp;
623
624 while (mesh) {
625 if (mesh->tface) {
626 nr = mesh->totface_legacy;
627 tface = mesh->tface;
628 while (nr--) {
629 int j;
630 for (j = 0; j < 4; j++) {
631 int k;
632 cp = (reinterpret_cast<char *>(&tface->col[j])) + 1;
633 for (k = 0; k < 3; k++) {
634 cp[k] = (cp[k] > 126) ? 255 : cp[k] * 2;
635 }
636 }
637
638 tface++;
639 }
640 }
641 mesh = static_cast<Mesh *>(mesh->id.next);
642 }
643 }
644
645 if (bmain->versionfile <= 169) {
646 Mesh *mesh = bmain->meshes.first();
647 while (mesh) {
648 if (mesh->subdiv == 0) {
649 mesh->subdiv = 1;
650 }
651 mesh = static_cast<Mesh *>(mesh->id.next);
652 }
653 }
654
655 if (bmain->versionfile <= 169) {
656 bScreen *screen = bmain->screens.first();
657 while (screen) {
658 ScrArea *area = screen->areabase.first();
659 while (area) {
660 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
661 while (sl) {
662 if (sl->spacetype == SPACE_GRAPH) {
663 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(sl);
664 sipo->v2d.max[0] = 15000.0;
665 }
666 sl = sl->next;
667 }
668 area = area->next;
669 }
670 screen = static_cast<bScreen *>(screen->id.next);
671 }
672 }
673
674 if (bmain->versionfile <= 170) {
675 Object *ob = bmain->objects.first();
676 PartEff *paf;
677 while (ob) {
679 if (paf) {
680 if (paf->staticstep == 0) {
681 paf->staticstep = 5;
682 }
683 }
684 ob = static_cast<Object *>(ob->id.next);
685 }
686 }
687
688 if (bmain->versionfile <= 171) {
689 bScreen *screen = bmain->screens.first();
690 while (screen) {
691 ScrArea *area = screen->areabase.first();
692 while (area) {
693 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
694 while (sl) {
695 if (sl->spacetype == SPACE_TEXT) {
696 SpaceText *st = reinterpret_cast<SpaceText *>(sl);
697 st->line_height = 12;
698 }
699 sl = sl->next;
700 }
701 area = area->next;
702 }
703 screen = static_cast<bScreen *>(screen->id.next);
704 }
705 }
706
707 if (bmain->versionfile <= 173) {
708 int a, b;
709 Mesh *mesh = bmain->meshes.first();
710 while (mesh) {
711 if (mesh->tface) {
712 TFace *tface = mesh->tface;
713 for (a = 0; a < mesh->totface_legacy; a++, tface++) {
714 for (b = 0; b < 4; b++) {
715 tface->uv[b][0] /= 32767.0f;
716 tface->uv[b][1] /= 32767.0f;
717 }
718 }
719 }
720 mesh = static_cast<Mesh *>(mesh->id.next);
721 }
722 }
723
724 if (bmain->versionfile <= 204) {
725 bSound *sound;
726
727 sound = bmain->sounds.first();
728 while (sound) {
729 if (sound->volume < 0.01f) {
730 sound->volume = 1.0f;
731 }
732 sound = static_cast<bSound *>(sound->id.next);
733 }
734 }
735
736 if (bmain->versionfile <= 212) {
737 bSound *sound;
738 Mesh *mesh;
739
740 sound = bmain->sounds.first();
741 while (sound) {
742 sound->max_gain = 1.0;
743 sound->min_gain = 0.0;
744 sound->distance = 1.0;
745
746 if (sound->attenuation > 0.0f) {
747 sound->flags |= SOUND_FLAGS_3D;
748 }
749 else {
750 sound->flags &= ~SOUND_FLAGS_3D;
751 }
752
753 sound = static_cast<bSound *>(sound->id.next);
754 }
755
756 /* `mesh->subdiv` changed to reflect the actual reparametrization
757 * better, and S-meshes were removed - if it was a S-mesh make
758 * it a subsurf, and reset the subdivision level because subsurf
759 * takes a lot more work to calculate. */
760 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
761 constexpr eMesh_Flag ME_SMESH = eMesh_Flag(1 << 6);
762 constexpr eMesh_Flag ME_SUBSURF = eMesh_Flag(1 << 7);
763 if (mesh->flag & ME_SMESH) {
764 mesh->flag &= ~ME_SMESH;
765 mesh->flag |= ME_SUBSURF;
766
767 mesh->subdiv = 1;
768 }
769 else {
770 if (mesh->subdiv < 2) {
771 mesh->subdiv = 1;
772 }
773 else {
774 mesh->subdiv--;
775 }
776 }
777 }
778 }
779
780 if (bmain->versionfile <= 220) {
781 Mesh *mesh;
782
783 /* Began using alpha component of vertex colors, but
784 * old file vertex colors are undefined, reset them
785 * to be fully opaque. -zr
786 */
787 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
788 if (mesh->mcol) {
789 int i;
790
791 for (i = 0; i < mesh->totface_legacy * 4; i++) {
792 MCol *mcol = &mesh->mcol[i];
793 mcol->a = 255;
794 }
795 }
796 if (mesh->tface) {
797 int i, j;
798
799 for (i = 0; i < mesh->totface_legacy; i++) {
800 TFace *tf = &(static_cast<TFace *>(mesh->tface))[i];
801
802 for (j = 0; j < 4; j++) {
803 char *col = reinterpret_cast<char *>(&tf->col[j]);
804
805 col[0] = 255;
806 }
807 }
808 }
809 }
810 }
811
812 if (bmain->versionfile <= 223) {
813 VFont *vf;
814 for (vf = bmain->fonts.first(); vf; vf = static_cast<VFont *>(vf->id.next)) {
815 if (BLI_str_endswith(vf->filepath, ".Bfont")) {
817 }
818 }
819 }
820
821 if (bmain->versionfile <= 224) {
822 bSound *sound;
823 Mesh *mesh;
824 bScreen *screen;
825
826 for (sound = bmain->sounds.first(); sound; sound = static_cast<bSound *>(sound->id.next)) {
827 if (sound->packedfile) {
828 if (sound->newpackedfile == nullptr) {
829 sound->newpackedfile = sound->packedfile;
830 }
831 sound->packedfile = nullptr;
832 }
833 }
834 /* Make sure that old subsurf meshes don't have zero subdivision level for rendering */
835 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
836 constexpr eMesh_Flag ME_SUBSURF = eMesh_Flag(1 << 7);
837 if ((mesh->flag & ME_SUBSURF) && (mesh->subdivr == 0)) {
838 mesh->subdivr = mesh->subdiv;
839 }
840 }
841
842 /* some oldfile patch, moved from set_func_space */
843 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
844 {
845 for (ScrArea &area : screen->areabase) {
846 for (SpaceLink &sl : area.spacedata) {
847 if (sl.spacetype == SPACE_GRAPH) {
848 SpaceSeq *sseq = reinterpret_cast<SpaceSeq *>(&sl);
849 sseq->v2d.keeptot = {};
850 }
851 }
852 }
853 }
854 }
855
856 if (bmain->versionfile <= 227) {
857 Scene *sce;
858 bScreen *screen;
859 Object *ob;
860
861 /* NOTE(@theeth): As of now, this insures that the transition from the old Track system
862 * to the new full constraint Track is painless for everyone. */
863 ob = bmain->objects.first();
864
865 while (ob) {
866 ListBaseT<bConstraint> &list = ob->constraints;
867
868 /* check for already existing TrackTo constraint
869 * set their track and up flag correctly
870 */
871
872 for (bConstraint &curcon : list) {
873 if (curcon.type == CONSTRAINT_TYPE_TRACKTO) {
874 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(curcon.data);
875 data->reserved1 = eTrackToAxis_Modes(ob->trackflag);
876 data->reserved2 = eUpAxis_Modes(ob->upflag);
877 }
878 }
879
880 if (ob->type == OB_ARMATURE) {
881 if (ob->pose) {
882 for (bPoseChannel &pchan : ob->pose->chanbase) {
883 for (bConstraint &curcon : pchan.constraints) {
884 if (curcon.type == CONSTRAINT_TYPE_TRACKTO) {
885 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(curcon.data);
886 data->reserved1 = eTrackToAxis_Modes(ob->trackflag);
887 data->reserved2 = eUpAxis_Modes(ob->upflag);
888 }
889 }
890 }
891 }
892 }
893
894 /* Change Ob->Track in real TrackTo constraint */
896
897 ob = static_cast<Object *>(ob->id.next);
898 }
899
900 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
901 sce->audio.mixrate = 48000;
902 sce->audio.flag |= AUDIO_SCRUB;
903 }
904
905 /* patch for old wrong max view2d settings, allows zooming out more */
906 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
907 {
908 for (ScrArea &area : screen->areabase) {
909 for (SpaceLink &sl : area.spacedata) {
910 if (sl.spacetype == SPACE_ACTION) {
911 SpaceAction *sac = reinterpret_cast<SpaceAction *>(&sl);
912 sac->v2d.max[0] = 32000;
913 }
914 else if (sl.spacetype == SPACE_NLA) {
915 SpaceNla *sla = reinterpret_cast<SpaceNla *>(&sl);
916 sla->v2d.max[0] = 32000;
917 }
918 }
919 }
920 }
921 }
922
923 if (bmain->versionfile <= 228) {
924 bScreen *screen;
925 Object *ob;
926
927 /* As of now, this insures that the transition from the old Track system
928 * to the new full constraint Track is painless for everyone.
929 */
930 ob = bmain->objects.first();
931
932 while (ob) {
933 ListBaseT<bConstraint> &list = ob->constraints;
934
935 /* check for already existing TrackTo constraint
936 * set their track and up flag correctly */
937
938 for (bConstraint &curcon : list) {
939 if (curcon.type == CONSTRAINT_TYPE_TRACKTO) {
940 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(curcon.data);
941 data->reserved1 = eTrackToAxis_Modes(ob->trackflag);
942 data->reserved2 = eUpAxis_Modes(ob->upflag);
943 }
944 }
945
946 if (ob->type == OB_ARMATURE) {
947 if (ob->pose) {
948 for (bPoseChannel &pchan : ob->pose->chanbase) {
949 for (bConstraint &curcon : pchan.constraints) {
950 if (curcon.type == CONSTRAINT_TYPE_TRACKTO) {
951 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(curcon.data);
952 data->reserved1 = eTrackToAxis_Modes(ob->trackflag);
953 data->reserved2 = eUpAxis_Modes(ob->upflag);
954 }
955 }
956 }
957 }
958 }
959
960 ob = static_cast<Object *>(ob->id.next);
961 }
962
963 /* convert old mainb values for new button panels */
964 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
965 {
966 for (ScrArea &area : screen->areabase) {
967 for (SpaceLink &sl : area.spacedata) {
968 if (sl.spacetype == SPACE_PROPERTIES) {
969 SpaceProperties *sbuts = reinterpret_cast<SpaceProperties *>(&sl);
970
971 sbuts->v2d.maxzoom = 1.2f;
972
973 if (sbuts->mainb == eSpaceButtons_Context(BUTS_LAMP)) {
974 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SHADING);
975 // sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_LAMP;
976 }
977 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_MAT)) {
978 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SHADING);
979 // sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_MAT;
980 }
981 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_TEX)) {
982 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SHADING);
983 // sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_TEX;
984 }
985 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_ANIM)) {
986 sbuts->mainb = eSpaceButtons_Context(CONTEXT_OBJECT);
987 }
988 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_WORLD)) {
989 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SCENE);
990 // sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_WORLD;
991 }
992 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_RENDER)) {
993 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SCENE);
994 // sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_RENDER;
995 }
996 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_FPAINT)) {
997 sbuts->mainb = eSpaceButtons_Context(CONTEXT_EDITING);
998 }
999 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_RADIO)) {
1000 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SHADING);
1001 // sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_RAD;
1002 }
1003 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_CONSTRAINT)) {
1004 sbuts->mainb = eSpaceButtons_Context(CONTEXT_OBJECT);
1005 }
1006 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_SCRIPT)) {
1007 sbuts->mainb = eSpaceButtons_Context(CONTEXT_OBJECT);
1008 }
1009 else if (sbuts->mainb == eSpaceButtons_Context(BUTS_EDIT)) {
1010 sbuts->mainb = eSpaceButtons_Context(CONTEXT_EDITING);
1011 }
1012 else {
1013 sbuts->mainb = eSpaceButtons_Context(CONTEXT_SCENE);
1014 }
1015 }
1016 }
1017 }
1018 }
1019 }
1020
1021 /* NOTE(@ton): made this 230 instead of 229,
1022 * to be sure (files from the `tuhopuu` branch) and this is a reliable check anyway
1023 * nevertheless, we might need to think over a fitness (initialize)
1024 * check apart from the do_versions(). */
1025
1026 if (bmain->versionfile <= 230) {
1027 bScreen *screen;
1028
1029 /* New variable block-scale, for panels in any area. */
1030 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
1031 {
1032 for (ScrArea &area : screen->areabase) {
1033 for (SpaceLink &sl : area.spacedata) {
1034 /* added: 5x better zoom in for action */
1035 if (sl.spacetype == SPACE_ACTION) {
1036 SpaceAction *sac = reinterpret_cast<SpaceAction *>(&sl);
1037 sac->v2d.maxzoom = 50;
1038 }
1039 }
1040 }
1041 }
1042 }
1043
1044 if (bmain->versionfile <= 231) {
1045 bScreen *screen = bmain->screens.first();
1046
1047 /* new bit flags for showing/hiding grid floor and axes */
1048
1049 while (screen) {
1050 ScrArea *area = screen->areabase.first();
1051 while (area) {
1052 SpaceLink *sl = area->spacedata.first_as<SpaceLink>();
1053 while (sl) {
1054 if (sl->spacetype == SPACE_VIEW3D) {
1055 View3D *v3d = reinterpret_cast<View3D *>(sl);
1056
1057 if (v3d->gridflag == 0) {
1058 v3d->gridflag |= V3D_SHOW_X;
1059 v3d->gridflag |= V3D_SHOW_Y;
1060 v3d->gridflag |= V3D_SHOW_FLOOR;
1061 v3d->gridflag &= ~V3D_SHOW_Z;
1062 }
1063 }
1064 sl = sl->next;
1065 }
1066 area = area->next;
1067 }
1068 screen = static_cast<bScreen *>(screen->id.next);
1069 }
1070 }
1071
1072 if (bmain->versionfile <= 232) {
1073 Tex *tex = bmain->textures.first();
1074 World *wrld = bmain->worlds.first();
1075 bScreen *screen;
1076
1077 while (tex) {
1078 if ((tex->flag & (TEX_CHECKER_ODD + TEX_CHECKER_EVEN)) == 0) {
1079 tex->flag |= TEX_CHECKER_ODD;
1080 }
1081 /* Copied from kernel `texture.cc`. */
1082 if (tex->ns_outscale == 0.0f) {
1083 /* musgrave */
1084 tex->mg_H = 1.0f;
1085 tex->mg_lacunarity = 2.0f;
1086 tex->mg_octaves = 2.0f;
1087 tex->mg_offset = 1.0f;
1088 tex->mg_gain = 1.0f;
1089 tex->ns_outscale = 1.0f;
1090 /* distnoise */
1091 tex->dist_amount = 1.0f;
1092 /* voronoi */
1093 tex->vn_w1 = 1.0f;
1094 tex->vn_mexp = 2.5f;
1095 }
1096 tex = static_cast<Tex *>(tex->id.next);
1097 }
1098
1099 while (wrld) {
1100 if (wrld->aodist == 0.0f) {
1101 wrld->aodist = 10.0f;
1102 }
1103 if (wrld->aoenergy == 0.0f) {
1104 wrld->aoenergy = 1.0f;
1105 }
1106 wrld = static_cast<World *>(wrld->id.next);
1107 }
1108
1109 /* New variable block-scale, for panels in any area, do again because new
1110 * areas didn't initialize it to 0.7 yet. */
1111 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
1112 {
1113 for (ScrArea &area : screen->areabase) {
1114 for (SpaceLink &sl : area.spacedata) {
1115 /* added: 5x better zoom in for nla */
1116 if (sl.spacetype == SPACE_NLA) {
1117 SpaceNla *snla = reinterpret_cast<SpaceNla *>(&sl);
1118 snla->v2d.maxzoom = 50;
1119 }
1120 }
1121 }
1122 }
1123 }
1124
1125 if (bmain->versionfile <= 233) {
1126 bScreen *screen;
1127
1128 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
1129 {
1130 for (ScrArea &area : screen->areabase) {
1131 for (SpaceLink &sl : area.spacedata) {
1132 if (sl.spacetype == SPACE_VIEW3D) {
1133 View3D *v3d = reinterpret_cast<View3D *>(&sl);
1134 v3d->flag |= V3D_SELECT_OUTLINE;
1135 }
1136 }
1137 }
1138 }
1139 }
1140
1141 if (bmain->versionfile <= 234) {
1142 bScreen *screen;
1143
1144 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
1145 {
1146 for (ScrArea &area : screen->areabase) {
1147 for (SpaceLink &sl : area.spacedata) {
1148 if (sl.spacetype == SPACE_TEXT) {
1149 SpaceText *st = reinterpret_cast<SpaceText *>(&sl);
1150 if (st->tabnumber == 0) {
1151 st->tabnumber = 2;
1152 }
1153 }
1154 }
1155 }
1156 }
1157 }
1158
1159 if (bmain->versionfile <= 235) {
1160 Tex *tex = bmain->textures.first();
1161 Scene *sce = bmain->scenes.first();
1162 Editing *ed;
1163
1164 while (tex) {
1165 if (tex->nabla == 0.0f) {
1166 tex->nabla = 0.025f;
1167 }
1168 tex = static_cast<Tex *>(tex->id.next);
1169 }
1170 while (sce) {
1171 ed = sce->ed;
1172 if (ed) {
1174 }
1175
1176 sce = static_cast<Scene *>(sce->id.next);
1177 }
1178 }
1179
1180 if (bmain->versionfile <= 236) {
1181 Object *ob;
1182 Camera *cam = bmain->cameras.first();
1183
1184 while (cam) {
1185 if (cam->ortho_scale == 0.0f) {
1186 cam->ortho_scale = 256.0f / cam->lens;
1187 if (cam->type == CAM_ORTHO) {
1188 printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
1189 }
1190 }
1191 cam = static_cast<Camera *>(cam->id.next);
1192 }
1193 /* Force oops draw if depsgraph was set. */
1194 /* Set time line var. */
1195
1196 /* softbody init new vars */
1197 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1198 if (ob->soft) {
1199 if (ob->soft->defgoal == 0.0f) {
1200 ob->soft->defgoal = 0.7f;
1201 }
1202 if (ob->soft->physics_speed == 0.0f) {
1203 ob->soft->physics_speed = 1.0f;
1204 }
1205 }
1206 if (ob->soft && ob->soft->vertgroup == 0) {
1207 bDeformGroup *locGroup = BKE_object_defgroup_find_name(ob, "SOFTGOAL");
1208 if (locGroup) {
1209 /* retrieve index for that group */
1210 ob->soft->vertgroup = 1 + BLI_findindex(&ob->defbase, locGroup);
1211 }
1212 }
1213 }
1214 }
1215
1216 if (bmain->versionfile <= 237) {
1217 bArmature *arm;
1218 Object *ob;
1219
1220 /* armature recode checks */
1221 for (arm = bmain->armatures.first(); arm; arm = static_cast<bArmature *>(arm->id.next)) {
1223
1224 for (Bone &bone : arm->bonebase) {
1226 }
1227 }
1228 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1229 if (ob->parent) {
1230 Object *parent = static_cast<Object *>(
1231 blo_do_versions_newlibadr(fd, &ob->id, ID_IS_LINKED(ob), ob->parent));
1232 if (parent && parent->type == OB_LATTICE) {
1233 ob->partype = PARSKEL;
1234 }
1235 }
1236
1237 /* NOTE: #BKE_pose_rebuild is further only called on leave edit-mode. */
1238 if (ob->type == OB_ARMATURE) {
1239 if (ob->pose) {
1240 BKE_pose_tag_recalc(bmain, ob->pose);
1241 }
1242
1243 /* Cannot call stuff now (pointers!), done in #setup_app_data. */
1244 ob->id.recalc |= ID_RECALC_ALL;
1245
1246 /* New generic X-ray option. */
1247 arm = static_cast<bArmature *>(
1248 blo_do_versions_newlibadr(fd, &ob->id, ID_IS_LINKED(ob), ob->data));
1249 enum { ARM_DRAWXRAY = (1 << 1) };
1250 if (arm->flag & eArmature_Flag(ARM_DRAWXRAY)) {
1251 ob->dtx |= OB_DRAW_IN_FRONT;
1252 }
1253 }
1254 else if (ob->type == OB_MESH) {
1255 Mesh *mesh = static_cast<Mesh *>(
1256 blo_do_versions_newlibadr(fd, &ob->id, ID_IS_LINKED(ob), ob->data));
1257
1258 constexpr eMesh_Flag ME_SUBSURF = eMesh_Flag(1 << 7);
1259 constexpr eMesh_Flag ME_OPT_EDGES = eMesh_Flag(1 << 8);
1260
1261 if (mesh->flag & ME_SUBSURF) {
1262 SubsurfModifierData *smd = reinterpret_cast<SubsurfModifierData *>(
1264
1265 smd->levels = std::max<short>(1, mesh->subdiv);
1266 smd->renderLevels = std::max<short>(1, mesh->subdivr);
1267 smd->subdivType = mesh->subsurftype;
1268
1269 smd->modifier.mode = ModifierMode{};
1270 if (mesh->subdiv != 0) {
1271 smd->modifier.mode |= ModifierMode(1);
1272 }
1273 if (mesh->subdivr != 0) {
1274 smd->modifier.mode |= ModifierMode(2);
1275 }
1276
1277 if (mesh->flag & ME_OPT_EDGES) {
1279 }
1280
1281 BLI_addtail(&ob->modifiers, smd);
1282
1283 BKE_modifier_unique_name(&ob->modifiers, reinterpret_cast<ModifierData *>(smd));
1284 }
1285 }
1286
1287 /* follow path constraint needs to set the 'path' option in curves... */
1288 for (bConstraint &con : ob->constraints) {
1289 if (con.type == CONSTRAINT_TYPE_FOLLOWPATH) {
1291 Object *obc = static_cast<Object *>(
1292 blo_do_versions_newlibadr(fd, &ob->id, ID_IS_LINKED(ob), data->tar));
1293
1294 if (obc && obc->type == OB_CURVES_LEGACY) {
1295 Curve *cu = static_cast<Curve *>(
1296 blo_do_versions_newlibadr(fd, &obc->id, ID_IS_LINKED(obc), obc->data));
1297 if (cu) {
1298 cu->flag |= CU_PATH;
1299 }
1300 }
1301 }
1302 }
1303 }
1304 }
1305
1306 if (bmain->versionfile <= 238) {
1307 Lattice *lt;
1308 Object *ob;
1309 bArmature *arm;
1310 Mesh *mesh;
1311 Key *key;
1312 Scene *sce = bmain->scenes.first();
1313
1314 while (sce) {
1315 if (sce->toolsettings == nullptr) {
1316 sce->toolsettings = MEM_new<ToolSettings>("Tool Settings Struct");
1317 sce->toolsettings->doublimit = 0.001f;
1318 }
1319 sce = static_cast<Scene *>(sce->id.next);
1320 }
1321
1322 for (lt = bmain->lattices.first(); lt; lt = static_cast<Lattice *>(lt->id.next)) {
1323 if (lt->fu == 0.0f && lt->fv == 0.0f && lt->fw == 0.0f) {
1324 calc_lat_fudu(lt->flag, lt->pntsu, &lt->fu, &lt->du);
1325 calc_lat_fudu(lt->flag, lt->pntsv, &lt->fv, &lt->dv);
1326 calc_lat_fudu(lt->flag, lt->pntsw, &lt->fw, &lt->dw);
1327 }
1328 }
1329
1330 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1331 PartEff *paf;
1332
1333 for (ModifierData &md : ob->modifiers) {
1334 if (md.type == eModifierType_Subsurf) {
1335 SubsurfModifierData *smd = reinterpret_cast<SubsurfModifierData *>(&md);
1336
1338 }
1339 }
1340
1342 {
1343 if (ob->softflag & OB_SB_POSTDEF) {
1344 ModifierData *md = ob->modifiers.first();
1345
1347 md = md->next;
1348 }
1349
1351 }
1352 else {
1354 }
1355
1356 ob->softflag &= ~OB_SB_ENABLE;
1357 }
1358
1359 if (ob->pose) {
1360 for (bPoseChannel &pchan : ob->pose->chanbase) {
1361 if (pchan.limitmin[0] == 0.0f && pchan.limitmax[0] == 0.0f) {
1362 pchan.limitmin[0] = pchan.limitmin[1] = pchan.limitmin[2] = -180.0f;
1363 pchan.limitmax[0] = pchan.limitmax[1] = pchan.limitmax[2] = 180.0f;
1364
1365 for (bConstraint &con : pchan.constraints) {
1366 if (con.type == CONSTRAINT_TYPE_KINEMATIC) {
1367 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con.data);
1368 data->weight = 1.0f;
1369 data->orientweight = 1.0f;
1370 data->flag &= ~CONSTRAINT_IK_ROT;
1371
1372 /* enforce conversion from old IK_TOPARENT to rootbone index */
1373 data->rootbone = -1;
1374
1375 /* update_pose_etc handles rootbone == -1 */
1376 BKE_pose_tag_recalc(bmain, ob->pose);
1377 }
1378 }
1379 }
1380 }
1381 }
1382
1384 if (paf) {
1385 if (paf->disp == 0) {
1386 paf->disp = 100;
1387 }
1388 if (paf->speedtex == 0) {
1389 paf->speedtex = 8;
1390 }
1391 if (paf->omat == 0) {
1392 paf->omat = 1;
1393 }
1394 }
1395 }
1396
1397 for (arm = bmain->armatures.first(); arm; arm = static_cast<bArmature *>(arm->id.next)) {
1399 arm->deformflag |= ARM_DEF_VGROUP;
1400 }
1401
1402 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
1403 if (!mesh->medge) {
1405 }
1406 else {
1408 }
1409 }
1410
1411 for (key = bmain->shapekeys.first(); key; key = static_cast<Key *>(key->id.next)) {
1412 int index = 1;
1413
1414 for (KeyBlock &kb : key->block) {
1415 if (&kb == key->refkey) {
1416 if (kb.name[0] == 0) {
1417 STRNCPY_UTF8(kb.name, "Basis");
1418 }
1419 }
1420 else {
1421 if (kb.name[0] == 0) {
1422 SNPRINTF_UTF8(kb.name, "Key %d", index);
1423 }
1424 index++;
1425 }
1426 }
1427 }
1428 }
1429
1430 if (bmain->versionfile <= 239) {
1431 bArmature *arm;
1432 Object *ob;
1433 Scene *sce = bmain->scenes.first();
1434 Camera *cam = bmain->cameras.first();
1435 int set_passepartout = 0;
1436
1437 /* deformflag is local in modifier now */
1438 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1439 for (ModifierData &md : ob->modifiers) {
1440 if (md.type == eModifierType_Armature) {
1441 ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(&md);
1442 if (amd->object && amd->deformflag == 0) {
1443 Object *oba = static_cast<Object *>(
1444 blo_do_versions_newlibadr(fd, &ob->id, ID_IS_LINKED(ob), amd->object));
1445 arm = static_cast<bArmature *>(
1446 blo_do_versions_newlibadr(fd, &oba->id, ID_IS_LINKED(oba), oba->data));
1447 amd->deformflag = arm->deformflag;
1448 }
1449 }
1450 }
1451 }
1452
1453 for (arm = bmain->armatures.first(); arm; arm = static_cast<bArmature *>(arm->id.next)) {
1455 if (arm->layer == 0) {
1456 arm->layer = 1;
1457 }
1458 }
1459
1460 for (; sce; sce = static_cast<Scene *>(sce->id.next)) {
1461 if (sce->r.scemode & R_PASSEPARTOUT) {
1462 set_passepartout = 1;
1463 sce->r.scemode &= ~R_PASSEPARTOUT;
1464 }
1465 }
1466
1467 for (; cam; cam = static_cast<Camera *>(cam->id.next)) {
1468 if (set_passepartout) {
1469 cam->flag |= CAM_SHOWPASSEPARTOUT;
1470 }
1471
1472 /* make sure old cameras have title safe on */
1473 if (!(cam->flag & CAM_SHOW_SAFE_MARGINS)) {
1474 cam->flag |= CAM_SHOW_SAFE_MARGINS;
1475 }
1476
1477 /* set an appropriate camera passepartout alpha */
1478 if (!(cam->passepartalpha)) {
1479 cam->passepartalpha = 0.2f;
1480 }
1481 }
1482 }
1483
1484 if (bmain->versionfile <= 241) {
1485 Object *ob;
1486 Scene *sce;
1487 bArmature *arm;
1488 bNodeTree *ntree;
1489
1490 /* updating layers still */
1491 for (arm = bmain->armatures.first(); arm; arm = static_cast<bArmature *>(arm->id.next)) {
1493 if (arm->layer == 0) {
1494 arm->layer = 1;
1495 }
1496 }
1497 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
1498 if (sce->audio.mixrate == 0) {
1499 sce->audio.mixrate = 48000;
1500 }
1501
1502 /* We don't add default layer since blender2.8 because the layers
1503 * are now in Scene->view_layers and a default layer is created in
1504 * the doversion later on. */
1505
1506 /* new layer flag for sky, was default for solid */
1507 for (SceneRenderLayer &srl : sce->r.layers) {
1508 if (srl.layflag & SCE_LAY_SOLID) {
1509 srl.layflag |= SCE_LAY_SKY;
1510 }
1512 }
1513
1514 /* node version changes */
1515 if (sce->nodetree) {
1517 }
1518
1519 /* uv calculation options moved to toolsettings */
1523 }
1524 }
1525
1526 for (ntree = bmain->nodetrees.first(); ntree; ntree = static_cast<bNodeTree *>(ntree->id.next))
1527 {
1528 ntree_version_241(ntree);
1529 }
1530
1531 /* for empty drawsize and drawtype */
1532 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1533 if (ob->empty_drawsize == 0.0f) {
1535 ob->empty_drawsize = 1.0;
1536 }
1537 }
1538
1539 /* during 2.41 images with this name were used for viewer node output, lets fix that */
1540 if (bmain->versionfile == 241) {
1541 Image *ima;
1542 for (ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
1543 if (STREQ(ima->filepath, "Compositor")) {
1544 BLI_strncpy_utf8(ima->id.name + 2, "Viewer Node", sizeof(ima->id.name) - 2);
1545 STRNCPY(ima->filepath, "Viewer Node");
1546 }
1547 }
1548 }
1549 }
1550
1551 if (bmain->versionfile <= 242) {
1552 Scene *sce;
1553 bScreen *screen;
1554 Object *ob;
1555 Curve *cu;
1556 Material *ma;
1557 Mesh *mesh;
1558 Collection *collection;
1559 BezTriple *bezt;
1560 BPoint *bp;
1561 bNodeTree *ntree;
1562 int a;
1563
1564 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
1565 {
1566 ScrArea *area;
1567 area = screen->areabase.first();
1568 while (area) {
1569 for (SpaceLink &sl : area->spacedata) {
1570 if (sl.spacetype == SPACE_VIEW3D) {
1571 View3D *v3d = reinterpret_cast<View3D *>(&sl);
1572 if (v3d->gridsubdiv == 0) {
1573 v3d->gridsubdiv = 10;
1574 }
1575 }
1576 }
1577 area = area->next;
1578 }
1579 }
1580
1581 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
1582 enum {
1583 R_THREADS = (1 << 19),
1584 };
1585 if (sce->toolsettings->select_thresh == 0.0f) {
1586 sce->toolsettings->select_thresh = 0.01f;
1587 }
1588 if (sce->r.threads == 0) {
1589 if (sce->r.mode & R_THREADS) {
1590 sce->r.threads = 2;
1591 }
1592 else {
1593 sce->r.threads = 1;
1594 }
1595 }
1596 if (sce->nodetree) {
1598 }
1599 }
1600
1601 for (ntree = bmain->nodetrees.first(); ntree; ntree = static_cast<bNodeTree *>(ntree->id.next))
1602 {
1603 ntree_version_242(ntree);
1604 }
1605
1606 /* add default radius values to old curve points */
1607 for (cu = bmain->curves.first(); cu; cu = static_cast<Curve *>(cu->id.next)) {
1608 for (Nurb &nu : cu->nurb) {
1609 if (nu.bezt) {
1610 for (bezt = nu.bezt, a = 0; a < nu.pntsu; a++, bezt++) {
1611 if (!bezt->radius) {
1612 bezt->radius = 1.0;
1613 }
1614 }
1615 }
1616 else if (nu.bp) {
1617 for (bp = nu.bp, a = 0; a < nu.pntsu * nu.pntsv; a++, bp++) {
1618 if (!bp->radius) {
1619 bp->radius = 1.0;
1620 }
1621 }
1622 }
1623 }
1624 }
1625
1626 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1627 ListBaseT<bConstraint> &list = ob->constraints;
1628
1629 /* check for already existing MinMax (floor) constraint
1630 * and update the sticky flagging */
1631
1632 for (bConstraint &curcon : list) {
1633 switch (curcon.type) {
1635 bRotateLikeConstraint *data = static_cast<bRotateLikeConstraint *>(curcon.data);
1636
1637 /* version patch from buttons_object.c */
1638 if (data->flag == 0) {
1639 data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z;
1640 }
1641
1642 break;
1643 }
1644 default:
1645 break;
1646 }
1647 }
1648
1649 if (ob->type == OB_ARMATURE) {
1650 if (ob->pose) {
1651 for (bPoseChannel &pchan : ob->pose->chanbase) {
1652 for (bConstraint &curcon : pchan.constraints) {
1653 switch (curcon.type) {
1655 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(curcon.data);
1656 if (!(data->flag & CONSTRAINT_IK_POS)) {
1657 data->flag |= CONSTRAINT_IK_POS;
1658 data->flag |= CONSTRAINT_IK_STRETCH;
1659 }
1660 break;
1661 }
1663 bRotateLikeConstraint *data = static_cast<bRotateLikeConstraint *>(curcon.data);
1664
1665 /* version patch from buttons_object.c */
1666 if (data->flag == 0) {
1667 data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z;
1668 }
1669 break;
1670 }
1671 default:
1672 break;
1673 }
1674 }
1675 }
1676 }
1677 }
1678
1679 /* copy old object level track settings to curve modifiers */
1680 for (ModifierData &md : ob->modifiers) {
1681 if (md.type == eModifierType_Curve) {
1682 CurveModifierData *cmd = reinterpret_cast<CurveModifierData *>(&md);
1683
1684 if (cmd->defaxis == 0) {
1686 }
1687 }
1688 }
1689 }
1690
1691 for (ma = bmain->materials.first(); ma; ma = static_cast<Material *>(ma->id.next)) {
1692 if (ma->nodetree) {
1693 ntree_version_242(ma->nodetree);
1694 }
1695 }
1696
1697 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
1699 }
1700
1701 for (collection = bmain->collections.first(); collection;
1702 collection = static_cast<Collection *>(collection->id.next))
1703 {
1704 if (collection->layer == 0) {
1705 collection->layer = (1 << 20) - 1;
1706 }
1707 }
1708
1709 /* now, subversion control! */
1710 if (bmain->subversionfile < 3) {
1711 Image *ima;
1712 Tex *tex;
1713
1714 /* Image refactor initialize */
1715 for (ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
1716 ima->source = IMA_SRC_FILE;
1717 ima->type = IMA_TYPE_IMAGE;
1718
1719 ima->gen_x = 256;
1720 ima->gen_y = 256;
1721 ima->gen_type = eImageGenType(1);
1722
1723 if (STREQLEN(ima->id.name + 2, "Viewer Node", sizeof(ima->id.name) - 2)) {
1724 ima->source = IMA_SRC_VIEWER;
1725 ima->type = IMA_TYPE_COMPOSITE;
1726 }
1727 if (STREQLEN(ima->id.name + 2, "Render Result", sizeof(ima->id.name) - 2)) {
1728 ima->source = IMA_SRC_VIEWER;
1729 ima->type = IMA_TYPE_R_RESULT;
1730 }
1731 }
1732 for (tex = bmain->textures.first(); tex; tex = static_cast<Tex *>(tex->id.next)) {
1733 enum {
1734 TEX_ANIMCYCLIC = (1 << 6),
1735 TEX_ANIM5 = (1 << 7),
1736 };
1737
1738 if (tex->type == TEX_IMAGE && tex->ima) {
1739 ima = static_cast<Image *>(
1740 blo_do_versions_newlibadr(fd, &tex->id, ID_IS_LINKED(tex), tex->ima));
1741 if (tex->imaflag & eTex_ImaFlag(TEX_ANIM5)) {
1742 ima->source = IMA_SRC_MOVIE;
1743 }
1744 }
1745 tex->iuser.frames = tex->frames;
1746 tex->iuser.offset = tex->offset;
1747 tex->iuser.sfra = tex->sfra;
1748 tex->iuser.cycl = (tex->imaflag & eTex_ImaFlag(TEX_ANIMCYCLIC)) != 0;
1749 }
1750 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
1751 if (sce->nodetree) {
1753 }
1754 }
1755 for (ntree = bmain->nodetrees.first(); ntree;
1756 ntree = static_cast<bNodeTree *>(ntree->id.next))
1757 {
1759 }
1760 for (ma = bmain->materials.first(); ma; ma = static_cast<Material *>(ma->id.next)) {
1761 if (ma->nodetree) {
1762 do_version_ntree_242_2(ma->nodetree);
1763 }
1764 }
1765 }
1766 }
1767
1768 if (bmain->versionfile <= 243) {
1769 Object *ob = bmain->objects.first();
1770
1771 for (; ob; ob = static_cast<Object *>(ob->id.next)) {
1772 for (bDeformGroup &curdef : ob->defbase) {
1773 /* replace an empty-string name with unique name */
1774 if (curdef.name[0] == '\0') {
1776 }
1777 }
1778
1779 if (bmain->versionfile < 243 || bmain->subversionfile < 1) {
1780 /* translate old mirror modifier axis values to new flags */
1781 for (ModifierData &md : ob->modifiers) {
1782 if (md.type == eModifierType_Mirror) {
1783 MirrorModifierData *mmd = reinterpret_cast<MirrorModifierData *>(&md);
1784
1785 switch (mmd->axis) {
1786 case 0:
1787 mmd->flag |= MOD_MIR_AXIS_X;
1788 break;
1789 case 1:
1790 mmd->flag |= MOD_MIR_AXIS_Y;
1791 break;
1792 case 2:
1793 mmd->flag |= MOD_MIR_AXIS_Z;
1794 break;
1795 }
1796
1797 mmd->axis = 0;
1798 }
1799 }
1800 }
1801 }
1802
1803 /* render layer added, this is not the active layer */
1804 if (bmain->versionfile <= 243 || bmain->subversionfile < 2) {
1805 Mesh *mesh;
1806 for (mesh = bmain->meshes.first(); mesh; mesh = static_cast<Mesh *>(mesh->id.next)) {
1808 }
1809 }
1810 }
1811
1812 if (bmain->versionfile <= 244) {
1813 bScreen *screen;
1814
1815 if (bmain->versionfile != 244 || bmain->subversionfile < 2) {
1816 /* correct older action editors - incorrect scrolling */
1817 for (screen = bmain->screens.first(); screen;
1818 screen = static_cast<bScreen *>(screen->id.next))
1819 {
1820 ScrArea *area;
1821 area = screen->areabase.first();
1822 while (area) {
1823 for (SpaceLink &sl : area->spacedata) {
1824 if (sl.spacetype == SPACE_ACTION) {
1825 SpaceAction *saction = reinterpret_cast<SpaceAction *>(&sl);
1826
1827 saction->v2d.tot.ymin = -1000.0;
1828 saction->v2d.tot.ymax = 0.0;
1829
1830 saction->v2d.cur.ymin = -75.0;
1831 saction->v2d.cur.ymax = 5.0;
1832 }
1833 }
1834 area = area->next;
1835 }
1836 }
1837 }
1838 }
1839
1840 if (bmain->versionfile <= 245) {
1841 Scene *sce;
1842 Object *ob;
1843 Image *ima;
1844 Material *ma;
1845 ParticleSettings *part;
1846 bNodeTree *ntree;
1847 Tex *tex;
1848
1849 /* unless the file was created 2.44.3 but not 2.45, update the constraints */
1850 if (!(bmain->versionfile == 244 && bmain->subversionfile == 3) &&
1851 ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile == 0)))
1852 {
1853 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1854 ListBaseT<bConstraint> &list = ob->constraints;
1855
1856 /* fix up constraints due to constraint recode changes (originally at 2.44.3) */
1857 for (bConstraint &curcon : list) {
1858 /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */
1859 if (curcon.flag & 0x20) {
1860 curcon.ownspace = CONSTRAINT_SPACE_LOCAL;
1861 curcon.tarspace = CONSTRAINT_SPACE_LOCAL;
1862 }
1863
1864 switch (curcon.type) {
1866 bLocLimitConstraint *data = static_cast<bLocLimitConstraint *>(curcon.data);
1867
1868 /* old limit without parent option for objects */
1869 if (int(data->flag2)) {
1870 curcon.ownspace = CONSTRAINT_SPACE_LOCAL;
1871 }
1872 break;
1873 }
1874 default:
1875 break;
1876 }
1877 }
1878
1879 /* correctly initialize constinv matrix */
1880 unit_m4(ob->constinv);
1881
1882 if (ob->type == OB_ARMATURE) {
1883 if (ob->pose) {
1884 for (bPoseChannel &pchan : ob->pose->chanbase) {
1885 /* make sure constraints are all up to date */
1886 for (bConstraint &curcon : pchan.constraints) {
1887 /* old CONSTRAINT_LOCAL check -> convert to CONSTRAINT_SPACE_LOCAL */
1888 if (curcon.flag & 0x20) {
1891 }
1892
1893 switch (curcon.type) {
1895 bActionConstraint *data = static_cast<bActionConstraint *>(curcon.data);
1896
1897 /* 'data->local' used to mean that target was in local-space */
1898 if (data->local) {
1900 }
1901 break;
1902 }
1903 default:
1904 break;
1905 }
1906 }
1907
1908 /* correctly initialize constinv matrix */
1909 unit_m4(pchan.constinv);
1910 }
1911 }
1912 }
1913 }
1914 }
1915
1916 /* fix all versions before 2.45 */
1917 if (bmain->versionfile != 245) {
1918
1919 /* Repair preview from 242 - 244. */
1920 for (ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
1921 ima->preview = nullptr;
1922 }
1923 }
1924
1925 /* add point caches */
1926 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
1927 if (ob->soft && !ob->soft->pointcache) {
1929 }
1930
1931 for (ParticleSystem &psys : ob->particlesystem) {
1932 if (psys.pointcache) {
1933 if (psys.pointcache->flag & PTCACHE_BAKED &&
1934 (psys.pointcache->flag & PTCACHE_DISK_CACHE) == 0)
1935 {
1936 printf("Old memory cache isn't supported for particles, so re-bake the simulation!\n");
1938 }
1939 }
1940 else {
1941 psys.pointcache = BKE_ptcache_add(&psys.ptcaches);
1942 }
1943 }
1944
1945 for (ModifierData &md : ob->modifiers) {
1946 if (md.type == eModifierType_Cloth) {
1947 ClothModifierData *clmd = reinterpret_cast<ClothModifierData *>(&md);
1948 if (!clmd->point_cache) {
1949 clmd->point_cache = BKE_ptcache_add(&clmd->ptcaches);
1950 clmd->point_cache->step = 1;
1951 }
1952 }
1953 }
1954 }
1955
1956 for (ma = bmain->materials.first(); ma; ma = static_cast<Material *>(ma->id.next)) {
1957 if (ma->gloss_mir == 0.0f) {
1958 ma->gloss_mir = 1.0f;
1959 }
1960 }
1961
1962 for (part = bmain->particles.first(); part;
1963 part = static_cast<ParticleSettings *>(part->id.next))
1964 {
1965 if (part->child_render_percent == 0) {
1966 part->child_render_percent = part->child_percent;
1967 }
1968 }
1969
1970 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
1971 if (sce->nodetree) {
1972 ntree_version_245(fd, lib, sce->nodetree);
1973 }
1974
1975 if (sce->r.simplify_subsurf == 0) {
1976 sce->r.simplify_subsurf = 6;
1977 sce->r.simplify_particles = 1.0f;
1978 }
1979 }
1980
1981 for (ntree = bmain->nodetrees.first(); ntree; ntree = static_cast<bNodeTree *>(ntree->id.next))
1982 {
1983 ntree_version_245(fd, lib, ntree);
1984 }
1985
1986 /* fix for temporary flag changes during 245 cycle */
1987 for (ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
1988 if (ima->flag & IMA_OLD_PREMUL) {
1989 ima->flag &= ~IMA_OLD_PREMUL;
1990 ima->alpha_mode = IMA_ALPHA_STRAIGHT;
1991 }
1992 }
1993
1994 for (tex = bmain->textures.first(); tex; tex = static_cast<Tex *>(tex->id.next)) {
1995 if (int(tex->iuser.flag) & int(IMA_OLD_PREMUL)) {
1997 }
1998
1999 ima = static_cast<Image *>(
2000 blo_do_versions_newlibadr(fd, &tex->id, ID_IS_LINKED(tex), tex->ima));
2001 if (ima && (int(tex->iuser.flag) & int(IMA_DO_PREMUL))) {
2002 ima->flag &= ~IMA_OLD_PREMUL;
2003 ima->alpha_mode = IMA_ALPHA_STRAIGHT;
2004 }
2005 }
2006 }
2007
2008 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 2)) {
2009 Image *ima;
2010
2011 /* initialize 1:1 Aspect */
2012 for (ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
2013 ima->aspx = ima->aspy = 1.0f;
2014 }
2015 }
2016
2017 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 4)) {
2018 bArmature *arm;
2019 Object *ob;
2020
2021 for (arm = bmain->armatures.first(); arm; arm = static_cast<bArmature *>(arm->id.next)) {
2022 arm->deformflag |= ARM_DEF_B_BONE_REST;
2023 }
2024
2025 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2026 for (ModifierData &md : ob->modifiers) {
2027 if (md.type == eModifierType_Armature) {
2028 (reinterpret_cast<ArmatureModifierData *>(&md))->deformflag |= ARM_DEF_B_BONE_REST;
2029 }
2030 }
2031 }
2032 }
2033
2034 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 5)) {
2035 /* foreground color needs to be something other than black */
2036 Scene *sce;
2037 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
2038 sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
2039 sce->r.fg_stamp[3] = 1.0f; /* don't use text alpha yet */
2040 sce->r.bg_stamp[3] = 0.25f; /* make sure the background has full alpha */
2041 }
2042 }
2043
2044 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 6)) {
2045 Scene *sce;
2046 /* fix frs_sec_base */
2047 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
2048 if (sce->r.frs_sec_base == 0) {
2049 sce->r.frs_sec_base = 1;
2050 }
2051 }
2052 }
2053
2054 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 7)) {
2055 Object *ob;
2056
2057 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2058 if (ob->pose) {
2059 for (bPoseChannel &pchan : ob->pose->chanbase) {
2061 }
2062 }
2064
2065 if (ob->soft && ob->soft->keys) {
2066 SoftBody *sb = ob->soft;
2067 int k;
2068
2069 for (k = 0; k < sb->totkey; k++) {
2070 if (sb->keys[k]) {
2071 MEM_delete(sb->keys[k]);
2072 }
2073 }
2074
2075 MEM_delete(sb->keys);
2076
2077 sb->keys = nullptr;
2078 sb->totkey = 0;
2079 }
2080 }
2081 }
2082
2083 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 8)) {
2084 Scene *sce;
2085 Object *ob;
2086
2087 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2088 if (ob->soft && ob->soft->keys) {
2089 SoftBody *sb = ob->soft;
2090 int k;
2091
2092 for (k = 0; k < sb->totkey; k++) {
2093 if (sb->keys[k]) {
2094 MEM_delete(sb->keys[k]);
2095 }
2096 }
2097
2098 MEM_delete(sb->keys);
2099
2100 sb->keys = nullptr;
2101 sb->totkey = 0;
2102 }
2103
2104 /* convert old particles to new system */
2106 if (paf) {
2107 ParticleSystem *psys;
2108 ModifierData *md;
2110 ParticleSettings *part;
2111
2112 /* create new particle system */
2113 psys = MEM_new<ParticleSystem>("particle_system");
2114 psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
2115
2116 /* Bad, but better not try to change this prehistorical code nowadays. */
2117 bmain->is_locked_for_linking = false;
2118 part = psys->part = BKE_particlesettings_add(bmain, "ParticleSettings");
2119 bmain->is_locked_for_linking = true;
2120
2121 /* needed for proper libdata lookup */
2122 blo_do_versions_oldnewmap_insert(fd->libmap, psys->part, psys->part, 0);
2123 part->id.lib = ob->id.lib;
2124
2125 part->id.us--;
2128
2129 psys->totpart = 0;
2130 psys->flag = PSYS_CURRENT;
2131
2132 BLI_addtail(&ob->particlesystem, psys);
2133
2135 SNPRINTF_UTF8(md->name, "ParticleSystem %i", ob->particlesystem.count());
2136 psmd = reinterpret_cast<ParticleSystemModifierData *>(md);
2137 psmd->psys = psys;
2138 BLI_addtail(&ob->modifiers, md);
2139
2140 /* convert settings from old particle system */
2141 /* general settings */
2142 part->totpart = std::min(paf->totpart, 100000);
2143 part->sta = paf->sta;
2144 part->end = paf->end;
2145 part->lifetime = paf->lifetime;
2146 part->randlife = paf->randlife;
2147 psys->seed = paf->seed;
2148 part->disp = paf->disp;
2149 part->omat = paf->mat[0];
2150 part->hair_step = paf->totkey;
2151
2152 part->force_group = paf->group;
2153
2154 /* old system didn't interpolate between keypoints at render time */
2155 part->draw_step = part->ren_step = 0;
2156
2157 /* physics */
2158 part->normfac = paf->normfac * 25.0f;
2159 part->obfac = paf->obfac;
2160 part->randfac = paf->randfac * 25.0f;
2161 part->dampfac = paf->damp;
2162 copy_v3_v3(part->acc, paf->force);
2163
2164 /* flags */
2165 if (paf->stype & PAF_VECT) {
2166 if (paf->flag & PAF_STATIC) {
2167 /* new hair lifetime is always 100.0f */
2168 float fac = paf->lifetime / 100.0f;
2169
2170 part->draw_as = PART_DRAW_PATH;
2171 part->type = PART_HAIR;
2172 psys->recalc |= ID_RECALC_PSYS_REDO;
2173
2174 part->normfac *= fac;
2175 part->randfac *= fac;
2176 }
2177 else {
2178 part->draw_as = PART_DRAW_LINE;
2179 part->draw |= PART_DRAW_VEL_LENGTH;
2180 part->draw_line[1] = 0.04f;
2181 }
2182 }
2183
2184 part->rotmode = PART_ROT_VEL;
2185
2186 part->flag |= (paf->flag & PAF_BSPLINE) ? PART_HAIR_BSPLINE : eParticleFlag{};
2187 part->flag |= (paf->flag & PAF_TRAND) ? PART_TRAND : eParticleFlag{};
2188 part->flag |= (paf->flag & PAF_EDISTR) ? PART_EDISTR : eParticleFlag{};
2189 part->flag |= (paf->flag & PAF_UNBORN) ? PART_UNBORN : eParticleFlag{};
2190 part->flag |= (paf->flag & PAF_DIED) ? PART_DIED : eParticleFlag{};
2191 part->from = eParticleFrom(part->from | ((paf->flag & PAF_FACE) ? PART_FROM_FACE : 0));
2192 part->draw |= eParticleDrawFlag((paf->flag & PAF_SHOWE) ? PART_DRAW_EMITTER :
2194
2195 psys->vgroup[PSYS_VG_DENSITY] = paf->vertgroup;
2196 psys->vgroup[PSYS_VG_VEL] = paf->vertgroup_v;
2197 psys->vgroup[PSYS_VG_LENGTH] = paf->vertgroup_v;
2198
2199 /* Dupli-objects. */
2200 if (ob->transflag & OB_DUPLIVERTS) {
2201 Object *dup = bmain->objects.first();
2202
2203 for (; dup; dup = static_cast<Object *>(dup->id.next)) {
2204 if (ob == blo_do_versions_newlibadr(fd, &dup->id, ID_IS_LINKED(dup), dup->parent)) {
2205 part->instance_object = dup;
2206 ob->transflag |= OB_DUPLIPARTS;
2208
2209 part->draw_as = PART_DRAW_OB;
2210
2211 /* needed for proper libdata lookup */
2212 blo_do_versions_oldnewmap_insert(fd->libmap, dup, dup, 0);
2213 }
2214 }
2215 }
2216
2217 {
2218 FluidsimModifierData *fluidmd = reinterpret_cast<FluidsimModifierData *>(
2220 if (fluidmd && fluidmd->fss && fluidmd->fss->type == OB_FLUIDSIM_PARTICLE) {
2221 part->type = PART_FLUID;
2222 }
2223 }
2224
2226
2227 printf("Old particle system converted to new system.\n");
2228 }
2229 }
2230
2231 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
2233 int a;
2234
2235 if (pset->brush[0].size == 0) {
2237 pset->emitterdist = 0.25f;
2238 pset->totrekey = 5;
2239 pset->totaddkey = 5;
2240
2241 for (a = 0; a < ARRAY_SIZE(pset->brush); a++) {
2242 pset->brush[a].strength = 50;
2243 pset->brush[a].size = 50;
2244 pset->brush[a].step = 10;
2245 }
2246
2247 pset->brush[PE_BRUSH_CUT].strength = 100;
2248 }
2249 }
2250 }
2251
2252 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 10)) {
2253 Object *ob;
2254
2255 /* dupliface scale */
2256 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2257 ob->instance_faces_scale = 1.0f;
2258 }
2259 }
2260
2261 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 14)) {
2262 Scene *sce;
2263
2264 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
2265 if (sce->ed) {
2267 }
2268 }
2269 }
2270
2271 /* fix broken group lengths in id properties */
2272 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 245, 15)) {
2297 }
2298
2299 /* convert fluids to modifier */
2300 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 246, 1)) {
2301 Object *ob;
2302
2303 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2304 if (ob->fluidsimSettings) {
2305 FluidsimModifierData *fluidmd = reinterpret_cast<FluidsimModifierData *>(
2307 BLI_addhead(&ob->modifiers, reinterpret_cast<ModifierData *>(fluidmd));
2308
2309 MEM_delete(fluidmd->fss);
2310 fluidmd->fss = MEM_dupalloc(ob->fluidsimSettings);
2311 MEM_delete(ob->fluidsimSettings);
2312
2313 fluidmd->fss->lastgoodframe = INT_MAX;
2314 fluidmd->fss->flag = eFluidsim_Flag{};
2315 fluidmd->fss->meshVelocities = nullptr;
2316 }
2317 }
2318 }
2319
2320 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 246, 1)) {
2321 Object *ob;
2322 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2323 if (ob->pd && (ob->pd->forcefield == PFIELD_WIND)) {
2324 ob->pd->f_noise = 0.0f;
2325 }
2326 }
2327 }
2328
2329 /* set the curve radius interpolation to 2.47 default - easy */
2330 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 247, 6)) {
2331 Curve *cu;
2332
2333 for (cu = bmain->curves.first(); cu; cu = static_cast<Curve *>(cu->id.next)) {
2334 for (Nurb &nu : cu->nurb) {
2335 nu.radius_interp = 3;
2336
2337 /* resolu and resolv are now used differently for surfaces
2338 * rather than using the resolution to define the entire number of divisions,
2339 * use it for the number of divisions per segment
2340 */
2341 if (nu.pntsv > 1) {
2342 nu.resolu = std::max(1, int((float(nu.resolu) / float(nu.pntsu)) + 0.5f));
2343 nu.resolv = std::max(1, int((float(nu.resolv) / float(nu.pntsv)) + 0.5f));
2344 }
2345 }
2346 }
2347 }
2348
2349 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 248, 2)) {
2350 Scene *sce;
2351
2352 /* NOTE: these will need to be added for painting. */
2353 for (sce = bmain->scenes.first(); sce; sce = static_cast<Scene *>(sce->id.next)) {
2356 }
2357 }
2358
2359 if (!MAIN_VERSION_FILE_ATLEAST(bmain, 248, 3)) {
2360 bScreen *screen;
2361
2362 /* adjust default settings for Animation Editors */
2363 for (screen = bmain->screens.first(); screen; screen = static_cast<bScreen *>(screen->id.next))
2364 {
2365 for (ScrArea &area : screen->areabase) {
2366 for (SpaceLink &sl : area.spacedata) {
2367 switch (sl.spacetype) {
2368 case SPACE_ACTION: {
2369 SpaceAction *sact = reinterpret_cast<SpaceAction *>(&sl);
2370
2371 sact->mode = SACTCONT_DOPESHEET;
2372 sact->autosnap = SACTSNAP_FRAME;
2373 break;
2374 }
2375 case SPACE_GRAPH: {
2376 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(&sl);
2377 sipo->autosnap = SACTSNAP_FRAME;
2378 break;
2379 }
2380 case SPACE_NLA: {
2381 SpaceNla *snla = reinterpret_cast<SpaceNla *>(&sl);
2382 snla->autosnap = SACTSNAP_FRAME;
2383 break;
2384 }
2385 }
2386 }
2387 }
2388 }
2389 }
2390
2391 /* correct introduce of seed for wind force */
2392 if (bmain->versionfile < 249 && bmain->subversionfile < 1) {
2393 Object *ob;
2394 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2395 if (ob->pd) {
2396 ob->pd->seed = (uint(ceil(BLI_time_now_seconds())) + 1) % 128;
2397 }
2398 }
2399 }
2400
2401 if (bmain->versionfile < 249 && bmain->subversionfile < 2) {
2402 Scene *sce = bmain->scenes.first();
2403 Editing *ed;
2404
2405 while (sce) {
2406 ed = sce->ed;
2407 if (ed) {
2408 for (Strip &strip : *seq::active_seqbase_get(ed)) {
2409 if (strip.data && strip.data->proxy) {
2410 strip.data->proxy->quality = 90;
2411 }
2412 }
2413 }
2414
2415 sce = static_cast<Scene *>(sce->id.next);
2416 }
2417 }
2418}
2419
2420} // namespace blender
Blender kernel action and pose functionality.
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define MAIN_VERSION_FILE_ATLEAST(main, ver, subver)
Definition BKE_main.hh:949
#define CMP_NODE_VECBLUR
#define CMP_NODE_VIEWER
#define CMP_NODE_HUE_SAT
#define CMP_NODE_ALPHAOVER
#define CMP_NODE_IMAGE
#define CMP_NODE_BLUR
General operations, lookup, etc. for blender objects.
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
Platform independent time functions.
Compatibility-like things for windows.
external readfile function prototypes.
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
Object groups, one object can be in many groups at once.
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
#define FO_BUILTIN_NAME
Read Blender memory allocation and freeing.
#define STREQLEN(a, b, n)
#define ELEM(...)
#define STREQ(a, b)
#define INT_MAX
#define layer
#define ceil
ccl_device_inline int4 cast(const float4 a)
Definition math_float4.h:32
ccl_device_inline int4 srl(const int4 a, const int i)
Definition math_int4.h:205
ListBaseT< Strip > * active_seqbase_get(const Editing *ed)
Definition sequencer.cc:463
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:60
BMesh Iterators.
ID_Readfile_Data::Tags & BLO_readfile_id_runtime_tags_for_write(ID &id)
Definition readfile.cc:2307
static void do_version_free_effects_245(ListBaseT< Effect > *lb)
static void vcol_to_fcol(Mesh *mesh)
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
Definition deform.cc:758
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static void idproperties_fix_groups_lengths_recurse(IDProperty *prop)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
static void ntree_version_242(bNodeTree *ntree)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
bDeformGroup * BKE_object_defgroup_find_name(const Object *ob, StringRef name)
Definition deform.cc:530
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
void * blo_do_versions_newlibadr(FileData *fd, ID *self_id, const bool is_linked_only, const void *adr)
Definition readfile.cc:1534
PartEff * BKE_object_do_version_give_parteff_245(Object *ob)
Definition object.cc:1162
@ eModifierType_ParticleSystem
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static void bone_version_238(ListBaseT< Bone > *lb)
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, eBConstraint_Types type)
void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du)
Definition lattice.cc:261
struct ParticleSettings * BKE_particlesettings_add(struct Main *bmain, const char *name)
Definition particle.cc:4135
static void bone_version_239(ListBaseT< Bone > *lb)
MINLINE void mul_v3_fl(float r[3], float f)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
static void do_version_free_effect_245(Effect *eff)
@ CMP_NODE_BLUR_TYPE_QUAD
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
const void * CustomData_add_layer_with_data(CustomData *data, eCustomDataType type, void *layer_data, int totelem, const ImplicitSharingInfo *sharing_info)
@ UVCALC_UNWRAP_METHOD_ANGLE
@ UVCALC_UNWRAP_METHOD_CONFORMAL
@ eSubsurfModifierFlag_DebugIncr
@ eSubsurfModifierFlag_Incremental
@ eSubsurfModifierFlag_ControlEdges
void blo_do_versions_oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, const int nr)
Definition readfile.cc:314
BMesh const char void * data
ModifierData * BKE_modifier_new(int type)
static void idproperties_fix_group_lengths(const ListBaseT< T > &idlist)
static void customdata_version_242(Mesh *mesh)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static void customdata_version_243(Mesh *mesh)
void BKE_mesh_calc_edges_legacy(Mesh *mesh)
void unit_m4(float m[4][4])
void BKE_armature_where_is(bArmature *arm)
void blo_do_version_old_trackto_to_constraints(Object *ob)
static void ntree_version_245(FileData *fd, Library *, bNodeTree *ntree)
static void ntree_version_241(bNodeTree *ntree)
enum DNA_DEPRECATED SACTSNAP_FRAME
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:378
@ CAM_SHOW_SAFE_MARGINS
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
void BKE_mesh_strip_loose_faces(Mesh *mesh)
static void do_version_constraints_245(ListBaseT< bConstraint > *lb)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static void do_version_bone_head_tail_237(Bone *bone)
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_PSYS_REDO
Definition DNA_ID.h:1081
ID_Type GS(const char *name)
Definition DNA_ID.h:410
struct PointCache * BKE_ptcache_add(ListBaseT< PointCache > *ptcaches)
double BLI_time_now_seconds()
Definition time.cc:30
static bool strip_set_blend_mode_cb(Strip *strip, void *)
static void do_version_ntree_242_2(bNodeTree *ntree)
static bool strip_set_alpha_mode_cb(Strip *strip, void *)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
ID_Readfile_Data::Tags BLO_readfile_id_runtime_tags(const ID &id)
Definition readfile.cc:2297
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
ListBaseT< Bone > childbase
struct PointCache * point_cache
struct ListBaseT< PointCache > ptcaches
DNA_DEPRECATED unsigned int layer
CurveModifierDefaultAxis defaxis
ListBaseT< Nurb > nurb
ListBaseT< Strip > seqbase
eEffect_Type type
OldNewMap * libmap
Definition readfile.hh:164
struct FluidsimSettings * fss
struct FluidVertexVelocity * meshVelocities
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
eIDPropertyType type
Definition DNA_ID.h:145
struct IDProperty * next
Definition DNA_ID.h:144
IDPropertyData data
Definition DNA_ID.h:157
char name[258]
Definition DNA_ID.h:433
struct Library * lib
Definition DNA_ID.h:421
void * next
Definition DNA_ID.h:418
unsigned int recalc
Definition DNA_ID.h:446
eImageUser_Flag flag
KeyBlock * refkey
ListBaseT< KeyBlock > block
ListBaseT< Key > shapekeys
Definition BKE_main.hh:398
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< bArmature > armatures
Definition BKE_main.hh:407
ListBaseT< Lattice > lattices
Definition BKE_main.hh:395
ListBaseT< bNodeTree > nodetrees
Definition BKE_main.hh:409
ListBaseT< VFont > fonts
Definition BKE_main.hh:401
ListBaseT< Camera > cameras
Definition BKE_main.hh:397
ListBaseT< MetaBall > metaballs
Definition BKE_main.hh:391
ListBaseT< Text > texts
Definition BKE_main.hh:402
bool is_locked_for_linking
Definition BKE_main.hh:313
ListBaseT< Library > libraries
Definition BKE_main.hh:387
ListBaseT< Light > lights
Definition BKE_main.hh:396
ListBaseT< World > worlds
Definition BKE_main.hh:399
short versionfile
Definition BKE_main.hh:269
ListBaseT< Brush > brushes
Definition BKE_main.hh:410
ListBaseT< Material > materials
Definition BKE_main.hh:392
ListBaseT< Object > objects
Definition BKE_main.hh:388
short subversionfile
Definition BKE_main.hh:270
ListBaseT< Curve > curves
Definition BKE_main.hh:390
ListBaseT< Mesh > meshes
Definition BKE_main.hh:389
ListBaseT< bSound > sounds
Definition BKE_main.hh:405
ListBaseT< ParticleSettings > particles
Definition BKE_main.hh:411
ListBaseT< Image > images
Definition BKE_main.hh:394
ListBaseT< bAction > actions
Definition BKE_main.hh:408
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< Tex > textures
Definition BKE_main.hh:393
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
struct ModifierData * next
DNA_DEPRECATED short samples
DNA_DEPRECATED short filtertype
DNA_DEPRECATED short maxspeed
DNA_DEPRECATED short sizex
DNA_DEPRECATED float fac
DNA_DEPRECATED short sizey
DNA_DEPRECATED float val
DNA_DEPRECATED int sfra
DNA_DEPRECATED int nr
DNA_DEPRECATED int frames
DNA_DEPRECATED char cyclic
DNA_DEPRECATED float x
BezTriple * bezt
struct PartDeflect * pd
struct Object * parent
ListBaseT< ModifierData > modifiers
eObject_DrawExtraFlag dtx
ListBaseT< struct ParticleSystem > particlesystem
struct Object * track
DNA_DEPRECATED short colbits
eObject_Partype partype
ListBaseT< Effect > effect
ListBaseT< bConstraint > constraints
ListBaseT< bDeformGroup > defbase
eObject_Axis upflag
eObject_Axis trackflag
eObject_EmptyDrawType empty_drawtype
eObject_TransFlag transflag
struct bPose * pose
struct Material ** mat
struct SoftBody * soft
struct Collection * group
ePartEff_SType stype
DNA_DEPRECATED struct Collection * force_group
eParticleRotationMode rotmode
ListBaseT< PointCache > ptcaches
eParticleSystem_Flag flag
struct PointCache * pointcache
ListBaseT< SceneRenderLayer > layers
struct Editing * ed
DNA_DEPRECATED struct bNodeTree * nodetree
struct RenderData r
struct AudioData audio
struct ToolSettings * toolsettings
struct ScrArea * next
ListBaseT< SpaceLink > spacedata
DNA_DEPRECATED struct PointCache * pointcache
ListBaseT< PointCache > ptcaches
DNA_DEPRECATED View2D v2d
DNA_DEPRECATED char autosnap
eAnimEdit_Context mode
DNA_DEPRECATED short autosnap
DNA_DEPRECATED View2D v2d
DNA_DEPRECATED View2D v2d
DNA_DEPRECATED short autosnap
DNA_DEPRECATED View2D v2d
eSpaceButtons_Context mainb
DNA_DEPRECATED View2D v2d
DNA_DEPRECATED int sfra
struct ImageUser iuser
struct Image * ima
eTex_ImaFlag imaflag
eTex_Extend extend
DNA_DEPRECATED int frames
DNA_DEPRECATED int offset
struct ParticleEditSettings particle
struct ImagePaintSettings imapaint
eTool_UvCalcFlag uvcalc_flag
eTool_Unwrapper unwrapper
char filepath[1024]
eView2D_KeepTot keeptot
eView3D_GridFlag gridflag
DNA_DEPRECATED unsigned int layer
eArmature_DeformFlag deformflag
ListBaseT< Bone > bonebase
eBConstraint_SpaceTypes ownspace
eBConstraint_SpaceTypes tarspace
eNodeTree_Type type
ListBaseT< bNode > nodes
ListBaseT< struct bConstraint > constraints
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct ScrArea > areabase
eSound_Flag flags
struct PackedFile * newpackedfile
struct PackedFile * packedfile