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 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/blenloader/intern/versioning_legacy.c
38 # include <unistd.h> // for read close
40 # include <io.h> // for open close read
41 # include "winsock2.h"
42 # include "BLI_winstuff.h"
45 /* allow readfile to use deprecated functionality */
46 #define DNA_DEPRECATED_ALLOW
48 #include "DNA_armature_types.h"
49 #include "DNA_actuator_types.h"
50 #include "DNA_camera_types.h"
51 #include "DNA_constraint_types.h"
52 #include "DNA_effect_types.h"
53 #include "DNA_group_types.h"
54 #include "DNA_key_types.h"
55 #include "DNA_lattice_types.h"
56 #include "DNA_lamp_types.h"
57 #include "DNA_material_types.h"
58 #include "DNA_mesh_types.h"
59 #include "DNA_meshdata_types.h"
60 #include "DNA_nla_types.h"
61 #include "DNA_node_types.h"
62 #include "DNA_object_fluidsim.h" // NT
63 #include "DNA_object_types.h"
64 #include "DNA_property_types.h"
65 #include "DNA_view3d_types.h"
66 #include "DNA_screen_types.h"
67 #include "DNA_sensor_types.h"
68 #include "DNA_sdna_types.h"
69 #include "DNA_sequence_types.h"
70 #include "DNA_sound_types.h"
71 #include "DNA_space_types.h"
72 #include "DNA_vfont_types.h"
73 #include "DNA_world_types.h"
75 #include "MEM_guardedalloc.h"
77 #include "BLI_utildefines.h"
78 #include "BLI_blenlib.h"
80 #include "BLI_edgehash.h"
82 #include "BKE_armature.h"
83 #include "BKE_colortools.h"
84 #include "BKE_constraint.h"
85 #include "BKE_deform.h"
86 #include "BKE_fcurve.h"
87 #include "BKE_global.h" // for G
88 #include "BKE_image.h"
89 #include "BKE_lattice.h"
90 #include "BKE_main.h" // for Main
91 #include "BKE_mesh.h" // for ME_ defines (patching)
92 #include "BKE_modifier.h"
93 #include "BKE_particle.h"
94 #include "BKE_pointcache.h"
95 #include "BKE_property.h" // for get_ob_property
96 #include "BKE_scene.h"
97 #include "BKE_sequencer.h"
98 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
100 #include "IMB_imbuf.h" // for proxy / timecode versioning stuff
102 #include "NOD_socket.h"
104 #include "BLO_readfile.h"
105 #include "BLO_undofile.h"
107 #include "RE_engine.h"
109 #include "readfile.h"
111 #include "PIL_time.h"
115 static void vcol_to_fcol(Mesh *me)
118 unsigned int *mcol, *mcoln, *mcolmain;
121 if (me->totface == 0 || me->mcol == NULL)
124 mcoln = mcolmain = MEM_mallocN(4*sizeof(int)*me->totface, "mcoln");
125 mcol = (unsigned int *)me->mcol;
127 for (a = me->totface; a > 0; a--, mface++) {
128 mcoln[0] = mcol[mface->v1];
129 mcoln[1] = mcol[mface->v2];
130 mcoln[2] = mcol[mface->v3];
131 mcoln[3] = mcol[mface->v4];
136 me->mcol = (MCol *)mcolmain;
139 static int map_223_keybd_code_to_224_keybd_code(int code)
143 return 311; /* F12KEY */
145 return 161; /* PADSLASHKEY */
147 return 150; /* PAD0 */
149 return 151; /* PAD1 */
151 return 152; /* PAD2 */
153 return 153; /* PAD3 */
155 return 154; /* PAD4 */
157 return 155; /* PAD5 */
159 return 156; /* PAD6 */
161 return 157; /* PAD7 */
163 return 158; /* PAD8 */
165 return 159; /* PAD9 */
171 static void do_version_bone_head_tail_237(Bone *bone)
177 copy_v3_v3(bone->arm_head, bone->arm_mat[3]);
179 /* tail is in current local coord system */
180 copy_v3_v3(vec, bone->arm_mat[1]);
181 mul_v3_fl(vec, bone->length);
182 add_v3_v3v3(bone->arm_tail, bone->arm_head, vec);
184 for (child = bone->childbase.first; child; child = child->next)
185 do_version_bone_head_tail_237(child);
188 static void bone_version_238(ListBase *lb)
192 for (bone = lb->first; bone; bone = bone->next) {
193 if (bone->rad_tail == 0.0f && bone->rad_head == 0.0f) {
194 bone->rad_head = 0.25f*bone->length;
195 bone->rad_tail = 0.1f*bone->length;
197 bone->dist-= bone->rad_head;
198 if (bone->dist<=0.0f)
201 bone_version_238(&bone->childbase);
205 static void bone_version_239(ListBase *lb)
209 for (bone = lb->first; bone; bone = bone->next) {
210 if (bone->layer == 0)
212 bone_version_239(&bone->childbase);
216 static void ntree_version_241(bNodeTree *ntree)
220 if (ntree->type == NTREE_COMPOSIT) {
221 for (node = ntree->nodes.first; node; node = node->next) {
222 if (node->type == CMP_NODE_BLUR) {
223 if (node->storage == NULL) {
224 NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur patch");
225 nbd->sizex = node->custom1;
226 nbd->sizey = node->custom2;
227 nbd->filtertype = R_FILTER_QUAD;
231 else if (node->type == CMP_NODE_VECBLUR) {
232 if (node->storage == NULL) {
233 NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur patch");
234 nbd->samples = node->custom1;
235 nbd->maxspeed = node->custom2;
244 static void ntree_version_242(bNodeTree *ntree)
248 if (ntree->type == NTREE_COMPOSIT) {
249 for (node = ntree->nodes.first; node; node = node->next) {
250 if (node->type == CMP_NODE_HUE_SAT) {
252 NodeHueSat *nhs = node->storage;
253 if (nhs->val == 0.0f)
259 else if (ntree->type == NTREE_SHADER) {
260 for (node = ntree->nodes.first; node; node = node->next)
261 if (node->type == SH_NODE_GEOMETRY && node->storage == NULL)
262 node->storage = MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
267 static void ntree_version_245(FileData *fd, Library *lib, bNodeTree *ntree)
275 if (ntree->type == NTREE_COMPOSIT) {
276 for (node = ntree->nodes.first; node; node = node->next) {
277 if (node->type == CMP_NODE_ALPHAOVER) {
278 if (!node->storage) {
279 ntf = MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
286 /* fix for temporary flag changes during 245 cycle */
287 nodeid = blo_do_versions_newlibadr(fd, lib, node->id);
288 if (node->storage && nodeid && GS(nodeid->name) == ID_IM) {
289 image = (Image*)nodeid;
290 iuser = node->storage;
291 if (iuser->flag & IMA_OLD_PREMUL) {
292 iuser->flag &= ~IMA_OLD_PREMUL;
293 iuser->flag |= IMA_DO_PREMUL;
295 if (iuser->flag & IMA_DO_PREMUL) {
296 image->flag &= ~IMA_OLD_PREMUL;
297 image->flag |= IMA_DO_PREMUL;
304 static void idproperties_fix_groups_lengths_recurse(IDProperty *prop)
309 for (loop = prop->data.group.first, i = 0; loop; loop = loop->next, i++) {
310 if (loop->type == IDP_GROUP)
311 idproperties_fix_groups_lengths_recurse(loop);
314 if (prop->len != i) {
315 printf("Found and fixed bad id property group length.\n");
320 static void idproperties_fix_group_lengths(ListBase idlist)
324 for (id = idlist.first; id; id = id->next) {
325 if (id->properties) {
326 idproperties_fix_groups_lengths_recurse(id->properties);
331 static void alphasort_version_246(FileData *fd, Library *lib, Mesh *me)
338 /* verify we have a tface layer */
339 for (b = 0; b < me->fdata.totlayer; b++)
340 if (me->fdata.layers[b].type == CD_MTFACE)
343 if (b == me->fdata.totlayer)
346 /* if we do, set alpha sort if the game engine did it before */
347 for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
348 if (mf->mat_nr < me->totcol) {
349 ma = blo_do_versions_newlibadr(fd, lib, me->mat[mf->mat_nr]);
352 /* we can't read from this if it comes from a library,
353 * because direct_link might not have happened on it,
354 * so ma->mtex is not pointing to valid memory yet */
355 if (ma && ma->id.lib)
358 for (b = 0; ma && b < MAX_MTEX; b++)
359 if (ma->mtex && ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA)
367 for (b = 0; b < me->fdata.totlayer; b++) {
368 if (me->fdata.layers[b].type == CD_MTFACE) {
369 tf = ((MTFace*)me->fdata.layers[b].data) + a;
371 tf->mode &= ~TF_ALPHASORT;
372 if (ma && (ma->mode & MA_ZTRANSP))
373 if (ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP)))
374 tf->mode |= TF_ALPHASORT;
380 static void customdata_version_242(Mesh *me)
382 CustomDataLayer *layer;
386 int a, mtfacen, mcoln;
388 if (!me->vdata.totlayer) {
389 CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, me->mvert, me->totvert);
392 CustomData_add_layer(&me->vdata, CD_MSTICKY, CD_ASSIGN, me->msticky, me->totvert);
394 CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_ASSIGN, me->dvert, me->totvert);
397 if (!me->edata.totlayer)
398 CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->medge, me->totedge);
400 if (!me->fdata.totlayer) {
401 CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->mface, me->totface);
407 me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface);
408 me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_CALLOC, NULL, me->totface);
414 for (a = 0; a < me->totface; a++, mtf++, tf++, mcol += 4) {
415 memcpy(mcol, tf->col, sizeof(tf->col));
416 memcpy(mtf->uv, tf->uv, sizeof(tf->uv));
418 mtf->flag = tf->flag;
419 mtf->unwrap = tf->unwrap;
420 mtf->mode = tf->mode;
421 mtf->tile = tf->tile;
422 mtf->tpage = tf->tpage;
423 mtf->transp = tf->transp;
426 MEM_freeN(me->tface);
430 me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, CD_ASSIGN, me->mcol, me->totface);
435 MEM_freeN(me->tface);
439 for (a = 0, mtfacen = 0, mcoln = 0; a < me->fdata.totlayer; a++) {
440 layer = &me->fdata.layers[a];
442 if (layer->type == CD_MTFACE) {
443 if (layer->name[0] == 0) {
444 if (mtfacen == 0) strcpy(layer->name, "UVMap");
445 else BLI_snprintf(layer->name, sizeof(layer->name), "UVMap.%.3d", mtfacen);
449 else if (layer->type == CD_MCOL) {
450 if (layer->name[0] == 0) {
452 strcpy(layer->name, "Col");
454 BLI_snprintf(layer->name, sizeof(layer->name), "Col.%.3d", mcoln);
460 mesh_update_customdata_pointers(me, TRUE);
463 /*only copy render texface layer from active*/
464 static void customdata_version_243(Mesh *me)
466 CustomDataLayer *layer;
469 for (a = 0; a < me->fdata.totlayer; a++) {
470 layer = &me->fdata.layers[a];
471 layer->active_rnd = layer->active;
475 /* struct NodeImageAnim moved to ImageUser, and we make it default available */
476 static void do_version_ntree_242_2(bNodeTree *ntree)
480 if (ntree->type == NTREE_COMPOSIT) {
481 for (node = ntree->nodes.first; node; node = node->next) {
482 if (ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
483 /* only image had storage */
485 NodeImageAnim *nia = node->storage;
486 ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "ima user node");
488 iuser->frames = nia->frames;
489 iuser->sfra = nia->sfra;
490 iuser->offset = nia->nr-1;
491 iuser->cycl = nia->cyclic;
495 node->storage = iuser;
499 ImageUser *iuser = node->storage = MEM_callocN(sizeof(ImageUser), "node image user");
509 static void do_version_free_effect_245(Effect *eff)
513 if (eff->type == EFF_PARTICLE) {
514 paf = (PartEff *)eff;
516 MEM_freeN(paf->keys);
521 static void do_version_free_effects_245(ListBase *lb)
527 BLI_remlink(lb, eff);
528 do_version_free_effect_245(eff);
533 PartEff *blo_do_version_give_parteff_245(Object *ob)
537 paf = ob->effect.first;
539 if (paf->type == EFF_PARTICLE)
546 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already */
547 void blo_do_version_old_trackto_to_constraints(Object *ob)
549 /* create new trackto constraint from the relationship */
551 bConstraint *con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO);
552 bTrackToConstraint *data = con->data;
554 /* copy tracking settings from the object */
555 data->tar = ob->track;
556 data->reserved1 = ob->trackflag;
557 data->reserved2 = ob->upflag;
560 /* clear old track setting */
564 void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
566 /* WATCH IT!!!: pointers from libdata have not been converted */
568 if (main->versionfile == 100) {
569 /* tex->extend and tex->imageflag have changed: */
570 Tex *tex = main->tex.first;
572 if (tex->id.flag & LIB_NEED_LINK) {
574 if (tex->extend == 0) {
575 if (tex->xrepeat || tex->yrepeat) {
576 tex->extend = TEX_REPEAT;
579 tex->extend = TEX_EXTEND;
580 tex->xrepeat = tex->yrepeat = 1;
589 if (main->versionfile <= 101) {
591 Scene *sce = main->scene.first;
593 sce->r.framapto = 100;
595 sce->r.framelen = 1.0;
600 if (main->versionfile <= 102) {
601 /* init halo's at 1.0 */
602 Material *ma = main->mat.first;
609 if (main->versionfile <= 103) {
610 /* new variable in object: colbits */
611 Object *ob = main->object.first;
616 for (a = 0; a < ob->totcol; a++) {
618 ob->colbits |= (1<<a);
625 if (main->versionfile <= 104) {
627 Object *ob = main->object.first;
629 if (ob->transflag & 1) {
631 //ob->ipoflag |= OB_OFFS_OB;
637 if (main->versionfile <= 105) {
638 Object *ob = main->object.first;
648 if (main->versionfile <= 106) {
650 Mesh *me = main->mesh.first;
659 if (main->versionfile <= 107) {
661 Scene *sce = main->scene.first;
663 sce->r.mode |= R_GAMMA;
666 ob = main->object.first;
668 //ob->ipoflag |= OB_OFFS_PARENT;
676 if (main->versionfile <= 109) {
677 /* new variable: gridlines */
678 bScreen *sc = main->screen.first;
680 ScrArea *sa = sc->areabase.first;
682 SpaceLink *sl = sa->spacedata.first;
684 if (sl->spacetype == SPACE_VIEW3D) {
685 View3D *v3d = (View3D*) sl;
687 if (v3d->gridlines == 0)
698 if (main->versionfile <= 113) {
699 Material *ma = main->mat.first;
701 if (ma->flaresize == 0.0f)
702 ma->flaresize = 1.0f;
704 ma->flareboost = 1.0f;
709 if (main->versionfile <= 134) {
710 Tex *tex = main->tex.first;
712 if ((tex->rfac == 0.0f) &&
713 (tex->gfac == 0.0f) &&
719 tex->filtersize = 1.0f;
725 if (main->versionfile <= 140) {
726 /* r-g-b-fac in texture */
727 Tex *tex = main->tex.first;
729 if ((tex->rfac == 0.0f) &&
730 (tex->gfac == 0.0f) &&
736 tex->filtersize = 1.0f;
742 if (main->versionfile <= 153) {
743 Scene *sce = main->scene.first;
745 if (sce->r.blurfac == 0.0f)
746 sce->r.blurfac = 1.0f;
751 if (main->versionfile <= 163) {
752 Scene *sce = main->scene.first;
754 if (sce->r.frs_sec == 0)
760 if (main->versionfile <= 164) {
761 Mesh *me = main->mesh.first;
768 if (main->versionfile <= 165) {
769 Mesh *me = main->mesh.first;
779 cp = (char *)&tface->col[0];
780 if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
781 if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
782 if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
783 cp = (char *)&tface->col[1];
784 if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
785 if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
786 if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
787 cp = (char *)&tface->col[2];
788 if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
789 if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
790 if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
791 cp = (char *)&tface->col[3];
792 if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
793 if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
794 if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
803 if (main->versionfile <= 169) {
804 Mesh *me = main->mesh.first;
812 if (main->versionfile <= 169) {
813 bScreen *sc = main->screen.first;
815 ScrArea *sa = sc->areabase.first;
817 SpaceLink *sl = sa->spacedata.first;
819 if (sl->spacetype == SPACE_IPO) {
820 SpaceIpo *sipo = (SpaceIpo*) sl;
821 sipo->v2d.max[0] = 15000.0;
831 if (main->versionfile <= 170) {
832 Object *ob = main->object.first;
835 paf = blo_do_version_give_parteff_245(ob);
837 if (paf->staticstep == 0) {
845 if (main->versionfile <= 171) {
846 bScreen *sc = main->screen.first;
848 ScrArea *sa = sc->areabase.first;
850 SpaceLink *sl = sa->spacedata.first;
852 if (sl->spacetype == SPACE_TEXT) {
853 SpaceText *st = (SpaceText*) sl;
864 if (main->versionfile <= 173) {
866 Mesh *me = main->mesh.first;
869 TFace *tface = me->tface;
870 for (a = 0; a < me->totface; a++, tface++) {
871 for (b = 0; b < 4; b++) {
872 tface->uv[b][0] /= 32767.0f;
873 tface->uv[b][1] /= 32767.0f;
881 if (main->versionfile <= 191) {
882 Object *ob = main->object.first;
883 Material *ma = main->mat.first;
885 /* let faces have default add factor of 0.0 */
887 if (!(ma->mode & MA_HALO))
895 /*ob->quat[1] = 1.0f;*/ /* quats arnt used yet */
900 if (main->versionfile <= 193) {
901 Object *ob = main->object.first;
909 if (main->versionfile <= 196) {
910 Mesh *me = main->mesh.first;
914 TFace *tface = me->tface;
915 for (a = 0; a < me->totface; a++, tface++) {
916 for (b = 0; b < 4; b++) {
917 tface->mode |= TF_DYNAMIC;
918 tface->mode &= ~TF_INVISIBLE;
926 if (main->versionfile <= 200) {
927 Object *ob = main->object.first;
929 ob->scaflag = ob->gameflag & (OB_DO_FH|OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
931 ob->gameflag &= ~(OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
936 if (main->versionfile <= 201) {
937 /* add-object + end-object are joined to edit-object actuator */
938 Object *ob = main->object.first;
942 bEditObjectActuator *eoa;
943 bAddObjectActuator *aoa;
945 act = ob->actuators.first;
947 if (act->type == ACT_IPO) {
949 prop = get_ob_property(ob, ia->name);
951 ia->type = ACT_IPO_FROM_PROP;
954 else if (act->type == ACT_ADD_OBJECT) {
956 eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
957 eoa->type = ACT_EDOB_ADD_OBJECT;
959 eoa->time = aoa->time;
962 act->type = act->otype = ACT_EDIT_OBJECT;
964 else if (act->type == ACT_END_OBJECT) {
965 eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
966 eoa->type = ACT_EDOB_END_OBJECT;
968 act->type = act->otype = ACT_EDIT_OBJECT;
976 if (main->versionfile <= 202) {
977 /* add-object and end-object are joined to edit-object
979 Object *ob = main->object.first;
983 act = ob->actuators.first;
985 if (act->type == ACT_OBJECT) {
987 oa->flag &= ~(ACT_TORQUE_LOCAL|ACT_DROT_LOCAL); /* this actuator didn't do local/glob rot before */
995 if (main->versionfile <= 204) {
996 /* patches for new physics */
997 Object *ob = main->object.first;
1003 /* please check this for demo20 files like
1004 * original Egypt levels etc. converted
1005 * rotation factor of 50 is not workable */
1006 act = ob->actuators.first;
1008 if (act->type == ACT_OBJECT) {
1011 oa->forceloc[0] *= 25.0f;
1012 oa->forceloc[1] *= 25.0f;
1013 oa->forceloc[2] *= 25.0f;
1015 oa->forcerot[0] *= 10.0f;
1016 oa->forcerot[1] *= 10.0f;
1017 oa->forcerot[2] *= 10.0f;
1024 sound = main->sound.first;
1026 if (sound->volume < 0.01f) {
1027 sound->volume = 1.0f;
1029 sound = sound->id.next;
1033 if (main->versionfile <= 205) {
1034 /* patches for new physics */
1035 Object *ob = main->object.first;
1038 bEditObjectActuator *oa;
1040 bCollisionSensor *cs;
1042 /* Set anisotropic friction off for old objects,
1044 ob->gameflag &= ~OB_ANISOTROPIC_FRICTION;
1045 ob->anisotropicFriction[0] = 1.0;
1046 ob->anisotropicFriction[1] = 1.0;
1047 ob->anisotropicFriction[2] = 1.0;
1049 act = ob->actuators.first;
1051 if (act->type == ACT_EDIT_OBJECT) {
1052 /* Zero initial velocity for newly
1055 oa->linVelocity[0] = 0.0;
1056 oa->linVelocity[1] = 0.0;
1057 oa->linVelocity[2] = 0.0;
1063 sens = ob->sensors.first;
1065 /* Extra fields for radar sensors. */
1066 if (sens->type == SENS_RADAR) {
1067 bRadarSensor *s = sens->data;
1071 /* Pulsing: defaults for new sensors. */
1072 if (sens->type != SENS_ALWAYS) {
1083 /* Collision and ray: default = trigger
1084 * on property. The material field can
1086 if (sens->type == SENS_COLLISION) {
1087 cs = (bCollisionSensor*) sens->data;
1090 if (sens->type == SENS_RAY) {
1091 rs = (bRaySensor*) sens->data;
1098 /* have to check the exact multiplier */
1101 if (main->versionfile <= 211) {
1102 /* Render setting: per scene, the applicable gamma value
1103 * can be set. Default is 1.0, which means no
1106 bObjectActuator *oa;
1109 /* added alpha in obcolor */
1110 ob = main->object.first;
1116 /* added alpha in obcolor */
1117 ob = main->object.first;
1119 act = ob->actuators.first;
1121 if (act->type == ACT_OBJECT) {
1122 /* multiply velocity with 50 in old files */
1124 if (fabsf(oa->linearvelocity[0]) >= 0.01f)
1125 oa->linearvelocity[0] *= 50.0f;
1126 if (fabsf(oa->linearvelocity[1]) >= 0.01f)
1127 oa->linearvelocity[1] *= 50.0f;
1128 if (fabsf(oa->linearvelocity[2]) >= 0.01f)
1129 oa->linearvelocity[2] *= 50.0f;
1130 if (fabsf(oa->angularvelocity[0]) >= 0.01f)
1131 oa->angularvelocity[0] *= 50.0f;
1132 if (fabsf(oa->angularvelocity[1]) >= 0.01f)
1133 oa->angularvelocity[1] *= 50.0f;
1134 if (fabsf(oa->angularvelocity[2]) >= 0.01f)
1135 oa->angularvelocity[2] *= 50.0f;
1143 if (main->versionfile <= 212) {
1149 sound = main->sound.first;
1151 sound->max_gain = 1.0;
1152 sound->min_gain = 0.0;
1153 sound->distance = 1.0;
1155 if (sound->attenuation > 0.0f)
1156 sound->flags |= SOUND_FLAGS_3D;
1158 sound->flags &= ~SOUND_FLAGS_3D;
1160 sound = sound->id.next;
1163 ob = main->object.first;
1166 prop = ob->prop.first;
1168 if (prop->type == GPROP_TIME) {
1169 // convert old GPROP_TIME values from int to float
1170 *((float *)&prop->data) = (float) prop->data;
1178 /* me->subdiv changed to reflect the actual reparametization
1179 * better, and smeshes were removed - if it was a smesh make
1180 * it a subsurf, and reset the subdiv level because subsurf
1181 * takes a lot more work to calculate.
1183 for (me = main->mesh.first; me; me = me->id.next) {
1184 if (me->flag & ME_SMESH) {
1185 me->flag &= ~ME_SMESH;
1186 me->flag |= ME_SUBSURF;
1199 if (main->versionfile <= 220) {
1203 ob = main->object.first;
1205 /* adapt form factor in order to get the 'old' physics
1210 /* in future, distinguish between different
1211 * object bounding shapes
1213 ob->formfactor = 0.4f;
1214 /* patch form factor, note that inertia equiv radius
1215 * of a rotation symmetrical obj
1217 if (ob->inertia != 1.0f) {
1218 ob->formfactor /= ob->inertia * ob->inertia;
1223 /* Began using alpha component of vertex colors, but
1224 * old file vertex colors are undefined, reset them
1225 * to be fully opaque. -zr
1227 for (me = main->mesh.first; me; me = me->id.next) {
1231 for (i = 0; i < me->totface * 4; i++) {
1232 MCol *mcol = &me->mcol[i];
1239 for (i = 0; i < me->totface; i++) {
1240 TFace *tf = &((TFace*) me->tface)[i];
1242 for (j = 0; j < 4; j++) {
1243 char *col = (char*) &tf->col[j];
1252 if (main->versionfile <= 221) {
1253 Scene *sce = main->scene.first;
1255 /* new variables for std-alone player and runtime */
1259 sce->r.freqplay = 60;
1266 if (main->versionfile <= 222) {
1267 Scene *sce = main->scene.first;
1269 /* new variables for std-alone player and runtime */
1277 if (main->versionfile <= 223) {
1282 for (vf = main->vfont.first; vf; vf = vf->id.next) {
1283 if (strcmp(vf->name + strlen(vf->name)-6, ".Bfont") == 0) {
1284 strcpy(vf->name, FO_BUILTIN_NAME);
1288 /* Old textures animate at 25 FPS */
1289 for (ima = main->image.first; ima; ima = ima->id.next) {
1290 ima->animspeed = 25;
1293 /* Zr remapped some keyboard codes to be linear (stupid zr) */
1294 for (ob = main->object.first; ob; ob = ob->id.next) {
1297 for (sens = ob->sensors.first; sens; sens = sens->next) {
1298 if (sens->type == SENS_KEYBOARD) {
1299 bKeyboardSensor *ks = sens->data;
1301 ks->key = map_223_keybd_code_to_224_keybd_code(ks->key);
1302 ks->qual = map_223_keybd_code_to_224_keybd_code(ks->qual);
1303 ks->qual2 = map_223_keybd_code_to_224_keybd_code(ks->qual2);
1309 if (main->versionfile <= 224) {
1315 for (sound = main->sound.first; sound; sound = sound->id.next) {
1316 if (sound->packedfile) {
1317 if (sound->newpackedfile == NULL) {
1318 sound->newpackedfile = sound->packedfile;
1320 sound->packedfile = NULL;
1323 /* Make sure that old subsurf meshes don't have zero subdivision level for rendering */
1324 for (me = main->mesh.first; me; me = me->id.next) {
1325 if ((me->flag & ME_SUBSURF) && (me->subdivr == 0))
1326 me->subdivr = me->subdiv;
1329 for (sce = main->scene.first; sce; sce = sce->id.next) {
1330 sce->r.stereomode = 1; // no stereo
1333 /* some oldfile patch, moved from set_func_space */
1334 for (sc = main->screen.first; sc; sc = sc->id.next) {
1337 for (sa = sc->areabase.first; sa; sa = sa->next) {
1340 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1341 if (sl->spacetype == SPACE_IPO) {
1342 SpaceSeq *sseq = (SpaceSeq*) sl;
1343 sseq->v2d.keeptot = 0;
1350 if (main->versionfile <= 225) {
1352 /* Use Sumo for old games */
1353 for (wo = main->world.first; wo; wo = wo->id.next) {
1354 wo->physicsEngine = 2;
1358 if (main->versionfile <= 227) {
1364 /* As of now, this insures that the transition from the old Track system
1365 * to the new full constraint Track is painless for everyone. - theeth
1367 ob = main->object.first;
1371 list = &ob->constraints;
1373 /* check for already existing TrackTo constraint
1374 * set their track and up flag correctly
1378 bConstraint *curcon;
1379 for (curcon = list->first; curcon; curcon = curcon->next) {
1380 if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
1381 bTrackToConstraint *data = curcon->data;
1382 data->reserved1 = ob->trackflag;
1383 data->reserved2 = ob->upflag;
1388 if (ob->type == OB_ARMATURE) {
1390 bConstraint *curcon;
1391 bPoseChannel *pchan;
1392 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1393 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
1394 if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
1395 bTrackToConstraint *data = curcon->data;
1396 data->reserved1 = ob->trackflag;
1397 data->reserved2 = ob->upflag;
1404 /* Change Ob->Track in real TrackTo constraint */
1405 blo_do_version_old_trackto_to_constraints(ob);
1410 for (sce = main->scene.first; sce; sce = sce->id.next) {
1411 sce->audio.mixrate = 44100;
1412 sce->audio.flag |= AUDIO_SCRUB;
1413 sce->r.mode |= R_ENVMAP;
1416 /* init new shader vars */
1417 for (ma = main->mat.first; ma; ma = ma->id.next) {
1419 ma->roughness = 0.5f;
1420 ma->param[0] = 0.5f;
1421 ma->param[1] = 0.1f;
1422 ma->param[2] = 0.1f;
1423 ma->param[3] = 0.05f;
1426 /* patch for old wrong max view2d settings, allows zooming out more */
1427 for (sc = main->screen.first; sc; sc = sc->id.next) {
1430 for (sa = sc->areabase.first; sa; sa = sa->next) {
1433 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1434 if (sl->spacetype == SPACE_ACTION) {
1435 SpaceAction *sac = (SpaceAction *) sl;
1436 sac->v2d.max[0] = 32000;
1438 else if (sl->spacetype == SPACE_NLA) {
1439 SpaceNla *sla = (SpaceNla *) sl;
1440 sla->v2d.max[0] = 32000;
1447 if (main->versionfile <= 228) {
1452 /* As of now, this insures that the transition from the old Track system
1453 * to the new full constraint Track is painless for everyone.
1455 ob = main->object.first;
1459 list = &ob->constraints;
1461 /* check for already existing TrackTo constraint
1462 * set their track and up flag correctly */
1465 bConstraint *curcon;
1466 for (curcon = list->first; curcon; curcon = curcon->next) {
1467 if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
1468 bTrackToConstraint *data = curcon->data;
1469 data->reserved1 = ob->trackflag;
1470 data->reserved2 = ob->upflag;
1475 if (ob->type == OB_ARMATURE) {
1477 bConstraint *curcon;
1478 bPoseChannel *pchan;
1479 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1480 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
1481 if (curcon->type == CONSTRAINT_TYPE_TRACKTO) {
1482 bTrackToConstraint *data = curcon->data;
1483 data->reserved1 = ob->trackflag;
1484 data->reserved2 = ob->upflag;
1494 for (sce = main->scene.first; sce; sce = sce->id.next) {
1495 sce->r.mode |= R_ENVMAP;
1498 /* convert old mainb values for new button panels */
1499 for (sc = main->screen.first; sc; sc = sc->id.next) {
1502 for (sa = sc->areabase.first; sa; sa = sa->next) {
1505 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1506 if (sl->spacetype == SPACE_BUTS) {
1507 SpaceButs *sbuts = (SpaceButs *) sl;
1509 sbuts->v2d.maxzoom = 1.2f;
1510 sbuts->align = 1; /* horizontal default */
1512 if (sbuts->mainb == BUTS_LAMP) {
1513 sbuts->mainb = CONTEXT_SHADING;
1514 //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_LAMP;
1516 else if (sbuts->mainb == BUTS_MAT) {
1517 sbuts->mainb = CONTEXT_SHADING;
1518 //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_MAT;
1520 else if (sbuts->mainb == BUTS_TEX) {
1521 sbuts->mainb = CONTEXT_SHADING;
1522 //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_TEX;
1524 else if (sbuts->mainb == BUTS_ANIM) {
1525 sbuts->mainb = CONTEXT_OBJECT;
1527 else if (sbuts->mainb == BUTS_WORLD) {
1528 sbuts->mainb = CONTEXT_SCENE;
1529 //sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_WORLD;
1531 else if (sbuts->mainb == BUTS_RENDER) {
1532 sbuts->mainb = CONTEXT_SCENE;
1533 //sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_RENDER;
1535 else if (sbuts->mainb == BUTS_GAME) {
1536 sbuts->mainb = CONTEXT_LOGIC;
1538 else if (sbuts->mainb == BUTS_FPAINT) {
1539 sbuts->mainb = CONTEXT_EDITING;
1541 else if (sbuts->mainb == BUTS_RADIO) {
1542 sbuts->mainb = CONTEXT_SHADING;
1543 //sbuts->tab[CONTEXT_SHADING] = TAB_SHADING_RAD;
1545 else if (sbuts->mainb == BUTS_CONSTRAINT) {
1546 sbuts->mainb = CONTEXT_OBJECT;
1548 else if (sbuts->mainb == BUTS_SCRIPT) {
1549 sbuts->mainb = CONTEXT_OBJECT;
1551 else if (sbuts->mainb == BUTS_EDIT) {
1552 sbuts->mainb = CONTEXT_EDITING;
1554 else sbuts->mainb = CONTEXT_SCENE;
1561 /* ton: made this 230 instead of 229,
1562 * to be sure (tuho files) and this is a reliable check anyway
1563 * nevertheless, we might need to think over a fitness (initialize)
1564 * check apart from the do_versions()
1567 if (main->versionfile <= 230) {
1570 /* new variable blockscale, for panels in any area */
1571 for (sc = main->screen.first; sc; sc = sc->id.next) {
1574 for (sa = sc->areabase.first; sa; sa = sa->next) {
1577 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1578 if (sl->blockscale == 0.0f)
1579 sl->blockscale = 0.7f;
1580 /* added: 5x better zoom in for action */
1581 if (sl->spacetype == SPACE_ACTION) {
1582 SpaceAction *sac = (SpaceAction *)sl;
1583 sac->v2d.maxzoom = 50;
1590 if (main->versionfile <= 231) {
1591 /* new bit flags for showing/hiding grid floor and axes */
1592 bScreen *sc = main->screen.first;
1595 ScrArea *sa = sc->areabase.first;
1597 SpaceLink *sl = sa->spacedata.first;
1599 if (sl->spacetype == SPACE_VIEW3D) {
1600 View3D *v3d = (View3D*) sl;
1602 if (v3d->gridflag == 0) {
1603 v3d->gridflag |= V3D_SHOW_X;
1604 v3d->gridflag |= V3D_SHOW_Y;
1605 v3d->gridflag |= V3D_SHOW_FLOOR;
1606 v3d->gridflag &= ~V3D_SHOW_Z;
1617 if (main->versionfile <= 231) {
1618 Material *ma = main->mat.first;
1619 bScreen *sc = main->screen.first;
1624 /* introduction of raytrace */
1626 if (ma->fresnel_tra_i == 0.0f)
1627 ma->fresnel_tra_i = 1.25f;
1628 if (ma->fresnel_mir_i == 0.0f)
1629 ma->fresnel_mir_i = 1.25f;
1633 ma->ray_depth_tra = 2;
1634 ma->fresnel_tra = 0.0;
1635 ma->fresnel_mir = 0.0;
1639 sce = main->scene.first;
1641 if (sce->r.gauss == 0.0f)
1642 sce->r.gauss = 1.0f;
1645 la = main->lamp.first;
1647 if (la->k == 0.0f) la->k = 1.0;
1648 if (la->ray_samp == 0)
1650 if (la->ray_sampy == 0)
1652 if (la->ray_sampz == 0)
1654 if (la->area_size == 0.0f)
1655 la->area_size = 1.0f;
1656 if (la->area_sizey == 0.0f)
1657 la->area_sizey = 1.0f;
1658 if (la->area_sizez == 0.0f)
1659 la->area_sizez = 1.0f;
1662 wrld = main->world.first;
1664 if (wrld->range == 0.0f) {
1665 wrld->range = 1.0f / wrld->exposure;
1667 wrld = wrld->id.next;
1670 /* new bit flags for showing/hiding grid floor and axes */
1673 ScrArea *sa = sc->areabase.first;
1675 SpaceLink *sl = sa->spacedata.first;
1677 if (sl->spacetype == SPACE_VIEW3D) {
1678 View3D *v3d = (View3D*) sl;
1680 if (v3d->gridflag == 0) {
1681 v3d->gridflag |= V3D_SHOW_X;
1682 v3d->gridflag |= V3D_SHOW_Y;
1683 v3d->gridflag |= V3D_SHOW_FLOOR;
1684 v3d->gridflag &= ~V3D_SHOW_Z;
1695 if (main->versionfile <= 232) {
1696 Tex *tex = main->tex.first;
1697 World *wrld = main->world.first;
1702 if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
1703 tex->flag |= TEX_CHECKER_ODD;
1705 /* copied from kernel texture.c */
1706 if (tex->ns_outscale == 0.0f) {
1709 tex->mg_lacunarity = 2.0f;
1710 tex->mg_octaves = 2.0f;
1711 tex->mg_offset = 1.0f;
1712 tex->mg_gain = 1.0f;
1713 tex->ns_outscale = 1.0f;
1715 tex->dist_amount = 1.0f;
1718 tex->vn_mexp = 2.5f;
1724 if (wrld->aodist == 0.0f) {
1725 wrld->aodist = 10.0f;
1726 wrld->aobias = 0.05f;
1728 if (wrld->aosamp == 0)
1730 if (wrld->aoenergy == 0.0f)
1731 wrld->aoenergy = 1.0f;
1732 wrld = wrld->id.next;
1735 /* new variable blockscale, for panels in any area, do again because new
1736 * areas didnt initialize it to 0.7 yet
1738 for (sc = main->screen.first; sc; sc = sc->id.next) {
1740 for (sa = sc->areabase.first; sa; sa = sa->next) {
1742 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1743 if (sl->blockscale == 0.0f)
1744 sl->blockscale = 0.7f;
1746 /* added: 5x better zoom in for nla */
1747 if (sl->spacetype == SPACE_NLA) {
1748 SpaceNla *snla = (SpaceNla *) sl;
1749 snla->v2d.maxzoom = 50;
1754 sce = main->scene.first;
1756 if (sce->r.ocres == 0)
1763 if (main->versionfile <= 233) {
1765 Material *ma = main->mat.first;
1766 /* Object *ob = main->object.first; */
1769 if (ma->rampfac_col == 0.0f)
1770 ma->rampfac_col = 1.0;
1771 if (ma->rampfac_spec == 0.0f)
1772 ma->rampfac_spec = 1.0;
1773 if (ma->pr_lamp == 0)
1778 /* this should have been done loooong before! */
1779 #if 0 /* deprecated in 2.5+ */
1781 if (ob->ipowin == 0)
1786 for (sc = main->screen.first; sc; sc = sc->id.next) {
1788 for (sa = sc->areabase.first; sa; sa = sa->next) {
1790 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1791 if (sl->spacetype == SPACE_VIEW3D) {
1792 View3D *v3d = (View3D *) sl;
1793 v3d->flag |= V3D_SELECT_OUTLINE;
1800 if (main->versionfile <= 234) {
1804 /* force sumo engine to be active */
1805 for (wo = main->world.first; wo; wo = wo->id.next) {
1806 if (wo->physicsEngine == 0)
1807 wo->physicsEngine = 2;
1810 for (sc = main->screen.first; sc; sc = sc->id.next) {
1812 for (sa = sc->areabase.first; sa; sa = sa->next) {
1814 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1815 if (sl->spacetype == SPACE_VIEW3D) {
1816 View3D *v3d = (View3D *) sl;
1817 v3d->flag |= V3D_ZBUF_SELECT;
1819 else if (sl->spacetype == SPACE_TEXT) {
1820 SpaceText *st = (SpaceText *)sl;
1821 if (st->tabnumber == 0)
1829 if (main->versionfile <= 235) {
1830 Tex *tex = main->tex.first;
1831 Scene *sce = main->scene.first;
1836 if (tex->nabla == 0.0f)
1837 tex->nabla = 0.025f;
1843 SEQ_BEGIN (sce->ed, seq)
1845 if (seq->type == SEQ_TYPE_IMAGE || seq->type == SEQ_TYPE_MOVIE)
1846 seq->flag |= SEQ_MAKE_PREMUL;
1855 if (main->versionfile <= 236) {
1857 Camera *cam = main->camera.first;
1862 if (cam->ortho_scale == 0.0f) {
1863 cam->ortho_scale = 256.0f / cam->lens;
1864 if (cam->type == CAM_ORTHO)
1865 printf("NOTE: ortho render has changed, tweak new Camera 'scale' value.\n");
1869 /* set manipulator type */
1870 /* force oops draw if depgraph was set*/
1871 /* set time line var */
1872 for (sc = main->screen.first; sc; sc = sc->id.next) {
1874 for (sa = sc->areabase.first; sa; sa = sa->next) {
1876 for (sl = sa->spacedata.first; sl; sl = sl->next) {
1877 if (sl->spacetype == SPACE_VIEW3D) {
1878 View3D *v3d = (View3D *) sl;
1879 if (v3d->twtype == 0)
1880 v3d->twtype = V3D_MANIP_TRANSLATE;
1885 /* init new shader vars */
1886 for (ma = main->mat.first; ma; ma = ma->id.next) {
1887 if (ma->darkness == 0.0f) {
1889 ma->darkness = 1.0f;
1893 /* softbody init new vars */
1894 for (ob = main->object.first; ob; ob = ob->id.next) {
1896 if (ob->soft->defgoal == 0.0f)
1897 ob->soft->defgoal = 0.7f;
1898 if (ob->soft->physics_speed == 0.0f)
1899 ob->soft->physics_speed = 1.0f;
1901 if (ob->soft->interval == 0) {
1902 ob->soft->interval = 2;
1904 ob->soft->efra = 100;
1907 if (ob->soft && ob->soft->vertgroup == 0) {
1908 bDeformGroup *locGroup = defgroup_find_name(ob, "SOFTGOAL");
1910 /* retrieve index for that group */
1911 ob->soft->vertgroup = 1 + BLI_findindex(&ob->defbase, locGroup);
1917 if (main->versionfile <= 237) {
1923 /* armature recode checks */
1924 for (arm = main->armature.first; arm; arm = arm->id.next) {
1925 BKE_armature_where_is(arm);
1927 for (bone = arm->bonebase.first; bone; bone = bone->next)
1928 do_version_bone_head_tail_237(bone);
1930 for (ob = main->object.first; ob; ob = ob->id.next) {
1932 Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
1933 if (parent && parent->type == OB_LATTICE)
1934 ob->partype = PARSKEL;
1937 /* btw. armature_rebuild_pose is further only called on leave editmode */
1938 if (ob->type == OB_ARMATURE) {
1940 ob->pose->flag |= POSE_RECALC;
1942 /* cannot call stuff now (pointers!), done in setup_app_data */
1943 ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
1945 /* new generic xray option */
1946 arm = blo_do_versions_newlibadr(fd, lib, ob->data);
1947 if (arm->flag & ARM_DRAWXRAY) {
1948 ob->dtx |= OB_DRAWXRAY;
1951 else if (ob->type == OB_MESH) {
1952 Mesh *me = blo_do_versions_newlibadr(fd, lib, ob->data);
1954 if ((me->flag&ME_SUBSURF)) {
1955 SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
1957 smd->levels = MAX2(1, me->subdiv);
1958 smd->renderLevels = MAX2(1, me->subdivr);
1959 smd->subdivType = me->subsurftype;
1961 smd->modifier.mode = 0;
1962 if (me->subdiv != 0)
1963 smd->modifier.mode |= 1;
1964 if (me->subdivr != 0)
1965 smd->modifier.mode |= 2;
1966 if (me->flag & ME_OPT_EDGES)
1967 smd->flags |= eSubsurfModifierFlag_ControlEdges;
1969 BLI_addtail(&ob->modifiers, smd);
1971 modifier_unique_name(&ob->modifiers, (ModifierData*)smd);
1975 /* follow path constraint needs to set the 'path' option in curves... */
1976 for (con = ob->constraints.first; con; con = con->next) {
1977 if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
1978 bFollowPathConstraint *data = con->data;
1979 Object *obc = blo_do_versions_newlibadr(fd, lib, data->tar);
1981 if (obc && obc->type == OB_CURVE) {
1982 Curve *cu = blo_do_versions_newlibadr(fd, lib, obc->data);
1984 cu->flag |= CU_PATH;
1991 if (main->versionfile <= 238) {
1997 Scene *sce = main->scene.first;
2000 if (sce->toolsettings == NULL) {
2001 sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
2002 sce->toolsettings->cornertype =0;
2003 sce->toolsettings->degr = 90;
2004 sce->toolsettings->step = 9;
2005 sce->toolsettings->turn = 1;
2006 sce->toolsettings->extr_offs = 1;
2007 sce->toolsettings->doublimit = 0.001f;
2008 sce->toolsettings->segments = 32;
2009 sce->toolsettings->rings = 32;
2010 sce->toolsettings->vertices = 32;
2015 for (lt = main->latt.first; lt; lt = lt->id.next) {
2016 if (lt->fu == 0.0f && lt->fv == 0.0f && lt->fw == 0.0f) {
2017 calc_lat_fudu(lt->flag, lt->pntsu, <->fu, <->du);
2018 calc_lat_fudu(lt->flag, lt->pntsv, <->fv, <->dv);
2019 calc_lat_fudu(lt->flag, lt->pntsw, <->fw, <->dw);
2023 for (ob = main->object.first; ob; ob = ob->id.next) {
2027 for (md = ob->modifiers.first; md; md = md->next) {
2028 if (md->type == eModifierType_Subsurf) {
2029 SubsurfModifierData *smd = (SubsurfModifierData*) md;
2031 smd->flags &= ~(eSubsurfModifierFlag_Incremental|eSubsurfModifierFlag_DebugIncr);
2035 if ((ob->softflag & OB_SB_ENABLE) && !modifiers_findByType(ob, eModifierType_Softbody)) {
2036 if (ob->softflag & OB_SB_POSTDEF) {
2037 md = ob->modifiers.first;
2039 while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) {
2043 BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(eModifierType_Softbody));
2046 BLI_addhead(&ob->modifiers, modifier_new(eModifierType_Softbody));
2049 ob->softflag &= ~OB_SB_ENABLE;
2053 bPoseChannel *pchan;
2055 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2056 /* note, pchan->bone is also lib-link stuff */
2057 if (pchan->limitmin[0] == 0.0f && pchan->limitmax[0] == 0.0f) {
2058 pchan->limitmin[0] = pchan->limitmin[1] = pchan->limitmin[2] = -180.0f;
2059 pchan->limitmax[0] = pchan->limitmax[1] = pchan->limitmax[2] = 180.0f;
2061 for (con = pchan->constraints.first; con; con = con->next) {
2062 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2063 bKinematicConstraint *data = (bKinematicConstraint*)con->data;
2064 data->weight = 1.0f;
2065 data->orientweight = 1.0f;
2066 data->flag &= ~CONSTRAINT_IK_ROT;
2068 /* enforce conversion from old IK_TOPARENT to rootbone index */
2069 data->rootbone = -1;
2071 /* update_pose_etc handles rootbone == -1 */
2072 ob->pose->flag |= POSE_RECALC;
2079 paf = blo_do_version_give_parteff_245(ob);
2083 if (paf->speedtex == 0)
2090 for (arm = main->armature.first; arm; arm = arm->id.next) {
2091 bone_version_238(&arm->bonebase);
2092 arm->deformflag |= ARM_DEF_VGROUP;
2095 for (me = main->mesh.first; me; me = me->id.next) {
2097 BKE_mesh_make_edges(me, 1); /* 1 = use mface->edcode */
2100 BKE_mesh_strip_loose_faces(me);
2104 for (key = main->key.first; key; key = key->id.next) {
2108 for (kb = key->block.first; kb; kb = kb->next) {
2109 if (kb == key->refkey) {
2110 if (kb->name[0] == 0)
2111 strcpy(kb->name, "Basis");
2114 if (kb->name[0] == 0) {
2115 BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
2123 if (main->versionfile <= 239) {
2126 Scene *sce = main->scene.first;
2127 Camera *cam = main->camera.first;
2128 Material *ma = main->mat.first;
2129 int set_passepartout = 0;
2131 /* deformflag is local in modifier now */
2132 for (ob = main->object.first; ob; ob = ob->id.next) {
2135 for (md = ob->modifiers.first; md; md = md->next) {
2136 if (md->type == eModifierType_Armature) {
2137 ArmatureModifierData *amd = (ArmatureModifierData*) md;
2138 if (amd->object && amd->deformflag == 0) {
2139 Object *oba = blo_do_versions_newlibadr(fd, lib, amd->object);
2140 arm = blo_do_versions_newlibadr(fd, lib, oba->data);
2141 amd->deformflag = arm->deformflag;
2147 /* updating stepsize for ghost drawing */
2148 for (arm = main->armature.first; arm; arm = arm->id.next) {
2149 if (arm->ghostsize == 0)
2151 bone_version_239(&arm->bonebase);
2152 if (arm->layer == 0)
2156 for (; sce; sce = sce->id.next) {
2157 /* make 'innervert' the default subdivide type, for backwards compat */
2158 sce->toolsettings->cornertype = 1;
2160 if (sce->r.scemode & R_PASSEPARTOUT) {
2161 set_passepartout = 1;
2162 sce->r.scemode &= ~R_PASSEPARTOUT;
2164 /* gauss is filter variable now */
2165 if (sce->r.mode & R_GAUSS) {
2166 sce->r.filtertype = R_FILTER_GAUSS;
2167 sce->r.mode &= ~R_GAUSS;
2171 for (; cam; cam = cam->id.next) {
2172 if (set_passepartout)
2173 cam->flag |= CAM_SHOWPASSEPARTOUT;
2175 /* make sure old cameras have title safe on */
2176 if (!(cam->flag & CAM_SHOWTITLESAFE))
2177 cam->flag |= CAM_SHOWTITLESAFE;
2179 /* set an appropriate camera passepartout alpha */
2180 if (!(cam->passepartalpha))
2181 cam->passepartalpha = 0.2f;
2184 for (; ma; ma = ma->id.next) {
2185 if (ma->strand_sta == 0.0f) {
2186 ma->strand_sta = ma->strand_end = 1.0f;
2187 ma->mode |= MA_TANGENT_STR;
2189 if (ma->mode & MA_TRACEBLE)
2190 ma->mode |= MA_SHADBUF;
2194 if (main->versionfile <= 241) {
2204 for (wo = main->world.first; wo; wo = wo->id.next) {
2205 /* Migrate to Bullet for games, except for the NaN versions */
2206 /* People can still explicitly choose for Sumo (after 2.42 is out) */
2207 if (main->versionfile > 225)
2208 wo->physicsEngine = WOPHY_BULLET;
2209 if (WO_AODIST == wo->aomode)
2210 wo->aocolor = WO_AOPLAIN;
2213 /* updating layers still */
2214 for (arm = main->armature.first; arm; arm = arm->id.next) {
2215 bone_version_239(&arm->bonebase);
2216 if (arm->layer == 0)
2219 for (sce = main->scene.first; sce; sce = sce->id.next) {
2220 if (sce->audio.mixrate == 0)
2221 sce->audio.mixrate = 44100;
2223 if (sce->r.xparts <2 )
2225 if (sce->r.yparts < 2)
2228 /* adds default layer */
2229 if (sce->r.layers.first == NULL)
2230 BKE_scene_add_render_layer(sce, NULL);
2232 SceneRenderLayer *srl;
2233 /* new layer flag for sky, was default for solid */
2234 for (srl = sce->r.layers.first; srl; srl = srl->next) {
2235 if (srl->layflag & SCE_LAY_SOLID)
2236 srl->layflag |= SCE_LAY_SKY;
2237 srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
2241 /* node version changes */
2243 ntree_version_241(sce->nodetree);
2245 /* uv calculation options moved to toolsettings */
2246 if (sce->toolsettings->uvcalc_radius == 0.0f) {
2247 sce->toolsettings->uvcalc_radius = 1.0f;
2248 sce->toolsettings->uvcalc_cubesize = 1.0f;
2249 sce->toolsettings->uvcalc_mapdir = 1;
2250 sce->toolsettings->uvcalc_mapalign = 1;
2251 sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
2252 sce->toolsettings->unwrapper = 1;
2255 if (sce->r.mode & R_PANORAMA) {
2256 /* all these checks to ensure saved files with svn version keep working... */
2257 if (sce->r.xsch < sce->r.ysch) {
2258 Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
2259 if (obc && obc->type == OB_CAMERA) {
2260 Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data);
2261 if (cam->lens >= 10.0f) {
2262 sce->r.xsch *= sce->r.xparts;
2263 cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch;
2270 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2271 ntree_version_241(ntree);
2273 for (la = main->lamp.first; la; la = la->id.next)
2274 if (la->buffers == 0)
2277 for (tex = main->tex.first; tex; tex = tex->id.next) {
2278 if (tex->env && tex->env->viewscale == 0.0f)
2279 tex->env->viewscale = 1.0f;
2280 //tex->imaflag |= TEX_GAUSS_MIP;
2283 /* for empty drawsize and drawtype */
2284 for (ob = main->object.first; ob; ob = ob->id.next) {
2285 if (ob->empty_drawsize == 0.0f) {
2286 ob->empty_drawtype = OB_ARROWS;
2287 ob->empty_drawsize = 1.0;
2291 for (ma = main->mat.first; ma; ma = ma->id.next) {
2292 /* stucci returns intensity from now on */
2294 for (a = 0; a < MAX_MTEX; a++) {
2295 if (ma->mtex[a] && ma->mtex[a]->tex) {
2296 tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
2297 if (tex && tex->type == TEX_STUCCI)
2298 ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF);
2301 /* transmissivity defaults */
2302 if (ma->tx_falloff == 0.0f)
2303 ma->tx_falloff = 1.0f;
2306 /* during 2.41 images with this name were used for viewer node output, lets fix that */
2307 if (main->versionfile == 241) {
2309 for (ima = main->image.first; ima; ima = ima->id.next)
2310 if (strcmp(ima->name, "Compositor") == 0) {
2311 strcpy(ima->id.name+2, "Viewer Node");
2312 strcpy(ima->name, "Viewer Node");
2317 if (main->versionfile <= 242) {
2331 for (sc = main->screen.first; sc; sc = sc->id.next) {
2333 sa = sc->areabase.first;
2337 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2338 if (sl->spacetype == SPACE_VIEW3D) {
2339 View3D *v3d = (View3D*) sl;
2340 if (v3d->gridsubdiv == 0)
2341 v3d->gridsubdiv = 10;
2348 for (sce = main->scene.first; sce; sce = sce->id.next) {
2349 if (sce->toolsettings->select_thresh == 0.0f)
2350 sce->toolsettings->select_thresh = 0.01f;
2351 if (sce->toolsettings->clean_thresh == 0.0f)
2352 sce->toolsettings->clean_thresh = 0.1f;
2354 if (sce->r.threads == 0) {
2355 if (sce->r.mode & R_THREADS)
2361 ntree_version_242(sce->nodetree);
2364 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2365 ntree_version_242(ntree);
2367 /* add default radius values to old curve points */
2368 for (cu = main->curve.first; cu; cu = cu->id.next) {
2369 for (nu = cu->nurb.first; nu; nu = nu->next) {
2372 for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++) {
2378 for (bp = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
2387 for (ob = main->object.first; ob; ob = ob->id.next) {
2390 list = &ob->constraints;
2392 /* check for already existing MinMax (floor) constraint
2393 * and update the sticky flagging */
2396 bConstraint *curcon;
2397 for (curcon = list->first; curcon; curcon = curcon->next) {
2398 switch (curcon->type) {
2399 case CONSTRAINT_TYPE_MINMAX:
2401 bMinMaxConstraint *data = curcon->data;
2402 if (data->sticky == 1)
2403 data->flag |= MINMAX_STICKY;
2405 data->flag &= ~MINMAX_STICKY;
2408 case CONSTRAINT_TYPE_ROTLIKE:
2410 bRotateLikeConstraint *data = curcon->data;
2412 /* version patch from buttons_object.c */
2413 if (data->flag == 0)
2414 data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
2421 if (ob->type == OB_ARMATURE) {
2423 bConstraint *curcon;
2424 bPoseChannel *pchan;
2425 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2426 for (curcon = pchan->constraints.first; curcon; curcon = curcon->next) {
2427 switch (curcon->type) {
2428 case CONSTRAINT_TYPE_MINMAX:
2430 bMinMaxConstraint *data = curcon->data;
2431 if (data->sticky == 1)
2432 data->flag |= MINMAX_STICKY;
2434 data->flag &= ~MINMAX_STICKY;
2437 case CONSTRAINT_TYPE_KINEMATIC:
2439 bKinematicConstraint *data = curcon->data;
2440 if (!(data->flag & CONSTRAINT_IK_POS)) {
2441 data->flag |= CONSTRAINT_IK_POS;
2442 data->flag |= CONSTRAINT_IK_STRETCH;
2446 case CONSTRAINT_TYPE_ROTLIKE:
2448 bRotateLikeConstraint *data = curcon->data;
2450 /* version patch from buttons_object.c */
2451 if (data->flag == 0)
2452 data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
2461 /* copy old object level track settings to curve modifers */
2462 for (md = ob->modifiers.first; md; md = md->next) {
2463 if (md->type == eModifierType_Curve) {
2464 CurveModifierData *cmd = (CurveModifierData*) md;
2466 if (cmd->defaxis == 0)
2467 cmd->defaxis = ob->trackflag+1;
2473 for (ma = main->mat.first; ma; ma = ma->id.next) {
2474 if (ma->shad_alpha == 0.0f)
2475 ma->shad_alpha = 1.0f;
2477 ntree_version_242(ma->nodetree);
2480 for (me = main->mesh.first; me; me = me->id.next)
2481 customdata_version_242(me);
2483 for (group = main->group.first; group; group = group->id.next)
2484 if (group->layer == 0)
2485 group->layer = (1<<20)-1;
2487 /* now, subversion control! */
2488 if (main->subversionfile < 3) {
2492 /* Image refactor initialize */
2493 for (ima = main->image.first; ima; ima = ima->id.next) {
2494 ima->source = IMA_SRC_FILE;
2495 ima->type = IMA_TYPE_IMAGE;
2497 ima->gen_x = 256; ima->gen_y = 256;
2500 if (0 == strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name) - 2)) {
2501 ima->source = IMA_SRC_VIEWER;
2502 ima->type = IMA_TYPE_COMPOSITE;
2504 if (0 == strncmp(ima->id.name+2, "Render Result", sizeof(ima->id.name) - 2)) {
2505 ima->source = IMA_SRC_VIEWER;
2506 ima->type = IMA_TYPE_R_RESULT;
2510 for (tex = main->tex.first; tex; tex = tex->id.next) {
2511 if (tex->type == TEX_IMAGE && tex->ima) {
2512 ima = blo_do_versions_newlibadr(fd, lib, tex->ima);
2513 if (tex->imaflag & TEX_ANIM5_)
2514 ima->source = IMA_SRC_MOVIE;
2515 if (tex->imaflag & TEX_FIELDS_)
2516 ima->flag |= IMA_FIELDS;
2517 if (tex->imaflag & TEX_STD_FIELD_)
2518 ima->flag |= IMA_STD_FIELD;
2520 tex->iuser.frames = tex->frames;
2521 tex->iuser.fie_ima = (char)tex->fie_ima;
2522 tex->iuser.offset = tex->offset;
2523 tex->iuser.sfra = tex->sfra;
2524 tex->iuser.cycl = (tex->imaflag & TEX_ANIMCYCLIC_)!=0;
2526 for (sce = main->scene.first; sce; sce = sce->id.next) {
2528 do_version_ntree_242_2(sce->nodetree);
2530 for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
2531 do_version_ntree_242_2(ntree);
2532 for (ma = main->mat.first; ma; ma = ma->id.next)
2534 do_version_ntree_242_2(ma->nodetree);
2536 for (sc = main->screen.first; sc; sc = sc->id.next) {
2538 for (sa = sc->areabase.first; sa; sa = sa->next) {
2540 for (sl = sa->spacedata.first; sl; sl = sl->next) {
2541 if (sl->spacetype == SPACE_IMAGE)
2542 ((SpaceImage *)sl)->iuser.fie_ima = 2;
2543 else if (sl->spacetype == SPACE_VIEW3D) {
2544 View3D *v3d = (View3D *)sl;
2546 for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
2547 bgpic->iuser.fie_ima = 2;
2554 if (main->subversionfile < 4) {
2555 for (sce = main->scene.first; sce; sce = sce->id.next) {
2556 sce->r.bake_mode = 1; /* prevent to include render stuff here */
2557 sce->r.bake_filter = 2;
2558 sce->r.bake_osa = 5;
2559 sce->r.bake_flag = R_BAKE_CLEAR;
2563 if (main->subversionfile < 5) {
2564 for (sce = main->scene.first; sce; sce = sce->id.next) {
2565 /* improved triangle to quad conversion settings */
2566 if (sce->toolsettings->jointrilimit == 0.0f)
2567 sce->toolsettings->jointrilimit = 0.8f;
2572 if (main->versionfile <= 243) {
2573 Object *ob = main->object.first;
2576 for (ma = main->mat.first; ma; ma = ma->id.next) {
2577 if (ma->sss_scale == 0.0f) {
2578 ma->sss_radius[0] = 1.0f;
2579 ma->sss_radius[1] = 1.0f;