diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-10 14:17:59 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-10 14:17:59 +0400 |
commit | ac9ec06ec121589fedbfeaa10137140b45bfd668 (patch) | |
tree | ab08f9528136f0b8813593b78621f869d98d655e /source/blender/blenkernel/intern | |
parent | 3c064f4553e4be988fe4fcec450b59b935fa3c80 (diff) | |
parent | 63af7068ad17f30a526ccb81fbe74253b064bc89 (diff) |
Merged changes in the trunk up to revision 54421.
Conflicts resolved:
release/datafiles/startup.blend
release/scripts/startup/bl_ui/properties_render.py
source/blender/SConscript
source/blender/blenloader/intern/readfile.c
Diffstat (limited to 'source/blender/blenkernel/intern')
44 files changed, 382 insertions, 167 deletions
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index 2079c783898..e58d484b0c0 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -230,7 +230,7 @@ int ccg_gridsize(int level) { BLI_assert(level > 0); BLI_assert(level <= 31); - + return (1 << (level - 1)) + 1; } diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 8ca6d045712..8e740075bc6 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -562,6 +562,13 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) tmp.key = NULL; } + /* Clear selection history */ + tmp.mselect = NULL; + tmp.totselect = 0; + if (me->mselect) { + MEM_freeN(me->mselect); + } + *me = tmp; } diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 5ccf9146440..509442b1d4e 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -78,11 +78,11 @@ /* ***************** Library data level operations on action ************** */ -bAction *add_empty_action(const char name[]) +bAction *add_empty_action(Main *bmain, const char name[]) { bAction *act; - act = BKE_libblock_alloc(&G.main->action, ID_AC, name); + act = BKE_libblock_alloc(&bmain->action, ID_AC, name); return act; } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index c8fd8aa93e5..bd13c406fa5 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -502,7 +502,7 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths if (srcAdt->action) { /* set up an action if necessary, and name it in a similar way so that it can be easily found again */ if (dstAdt->action == NULL) { - dstAdt->action = add_empty_action(srcAdt->action->id.name + 2); + dstAdt->action = add_empty_action(G.main, srcAdt->action->id.name + 2); } else if (dstAdt->action == srcAdt->action) { printf("Argh! Source and Destination share animation! ('%s' and '%s' both use '%s') Making new empty action\n", @@ -510,7 +510,7 @@ void BKE_animdata_separate_by_basepath(ID *srcID, ID *dstID, ListBase *basepaths /* TODO: review this... */ id_us_min(&dstAdt->action->id); - dstAdt->action = add_empty_action(dstAdt->action->id.name + 2); + dstAdt->action = add_empty_action(G.main, dstAdt->action->id.name + 2); } /* loop over base paths, trying to fix for each one... */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 3a705a07e22..480814a28c3 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -74,11 +74,11 @@ /* **************** Generic Functions, data level *************** */ -bArmature *BKE_armature_add(const char *name) +bArmature *BKE_armature_add(Main *bmain, const char *name) { bArmature *arm; - arm = BKE_libblock_alloc(&G.main->armature, ID_AR, name); + arm = BKE_libblock_alloc(&bmain->armature, ID_AR, name); arm->deformflag = ARM_DEF_VGROUP | ARM_DEF_ENVELOPE; arm->flag = ARM_COL_CUSTOM; /* custom bone-group colors */ arm->layer = 1; @@ -1655,7 +1655,8 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected else { /* always copy custom shape */ pchan->custom = pchanp->custom; - pchan->custom_tx = pchanp->custom_tx; + if (pchanp->custom_tx) + pchan->custom_tx = BKE_pose_channel_find_name(pose, pchanp->custom_tx->name); /* ID-Property Syncing */ { diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 70eaa00b82e..2ce5053bdcc 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -109,11 +109,11 @@ static void brush_defaults(Brush *brush) /* Datablock add/copy/free/make_local */ -Brush *BKE_brush_add(const char *name) +Brush *BKE_brush_add(Main *bmain, const char *name) { Brush *brush; - brush = BKE_libblock_alloc(&G.main->brush, ID_BR, name); + brush = BKE_libblock_alloc(&bmain->brush, ID_BR, name); /* enable fake user by default */ brush->id.flag |= LIB_FAKEUSER; @@ -419,7 +419,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr) idtest = (ID *)BLI_findlink(&G.main->tex, nr - 1); if (idtest == NULL) { /* new tex */ if (id) idtest = (ID *)BKE_texture_copy((Tex *)id); - else idtest = (ID *)add_texture("Tex"); + else idtest = (ID *)add_texture(G.main, "Tex"); idtest->us--; } if (idtest != id) { @@ -656,7 +656,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf * available. my ussual solution to this is to use the * ratio of change of the size to change the unprojected * radius. Not completely convinced that is correct. - * In anycase, a better solution is needed to prevent + * In any case, a better solution is needed to prevent * inconsistency. */ void BKE_brush_size_set(Scene *scene, Brush *brush, int size) diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index d1842b99831..34c2d144f4c 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -50,11 +50,11 @@ /****************************** Camera Datablock *****************************/ -void *BKE_camera_add(const char *name) +void *BKE_camera_add(Main *bmain, const char *name) { Camera *cam; - cam = BKE_libblock_alloc(&G.main->camera, ID_CA, name); + cam = BKE_libblock_alloc(&bmain->camera, ID_CA, name); cam->lens = 35.0f; cam->sensor_x = DEFAULT_SENSOR_WIDTH; diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index a6e68b9b2d5..7d6212f8760 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -167,11 +167,11 @@ void BKE_curve_free(Curve *cu) MEM_freeN(cu->tb); } -Curve *BKE_curve_add(const char *name, int type) +Curve *BKE_curve_add(Main *bmain, const char *name, int type) { Curve *cu; - cu = BKE_libblock_alloc(&G.main->curve, ID_CU, name); + cu = BKE_libblock_alloc(&bmain->curve, ID_CU, name); copy_v3_fl(cu->size, 1.0f); cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS; cu->pathlen = 100; @@ -3436,7 +3436,9 @@ int BKE_curve_center_median(Curve *cu, float cent[3]) } } - mul_v3_fl(cent, 1.0f / (float)total); + if (total) { + mul_v3_fl(cent, 1.0f / (float)total); + } return (total != 0); } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index f3548f776f5..580a69466c9 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1242,12 +1242,15 @@ void CustomData_update_typemap(CustomData *data) } } +/* currently only used in BLI_assert */ +#ifndef NDEBUG static int customdata_typemap_is_valid(const CustomData *data) { CustomData data_copy = *data; CustomData_update_typemap(&data_copy); return (memcmp(data->typemap, data_copy.typemap, sizeof(data->typemap)) == 0); } +#endif void CustomData_merge(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, int alloctype, int totelem) diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 78d7bfa5bc5..dab4235559a 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -424,7 +424,7 @@ static void dag_add_lamp_driver_relations(DagForest *dag, DagNode *node, Lamp *l dag_add_shader_nodetree_driver_relations(dag, node, la->nodetree); } -static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Object *ob, DagNode *node, int skip_forcefield) +static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Object *ob, DagNode *node, int skip_forcefield, bool no_collision) { Base *base; DagNode *node2; @@ -435,7 +435,7 @@ static void dag_add_collision_field_relation(DagForest *dag, Scene *scene, Objec if ((base->lay & ob->lay) && base->object->pd) { Object *ob1 = base->object; if ((ob1->pd->deflect || ob1->pd->forcefield) && (ob1 != ob)) { - if (skip_forcefield && ob1->pd->forcefield == skip_forcefield) + if ((skip_forcefield && ob1->pd->forcefield == skip_forcefield) || (no_collision && ob1->pd->forcefield == 0)) continue; node2 = dag_get_node(dag, ob1); dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Field Collision"); @@ -599,10 +599,13 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O modifiers_isModifierEnabled(ob, eModifierType_Cloth) || modifiers_isModifierEnabled(ob, eModifierType_DynamicPaint)) { - dag_add_collision_field_relation(dag, scene, ob, node, 0); /* TODO: use effectorweight->group */ + dag_add_collision_field_relation(dag, scene, ob, node, 0, false); /* TODO: use effectorweight->group */ } else if (modifiers_isModifierEnabled(ob, eModifierType_Smoke)) { - dag_add_collision_field_relation(dag, scene, ob, node, PFIELD_SMOKEFLOW); + dag_add_collision_field_relation(dag, scene, ob, node, PFIELD_SMOKEFLOW, false); + } + else if (ob->rigidbody_object) { + dag_add_collision_field_relation(dag, scene, ob, node, 0, true); } } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 23b0d3e6e22..6f85d4de60e 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -63,6 +63,7 @@ #include "BLO_sys_types.h" // for intptr_t support static void boundbox_displist(Object *ob); +static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase); void BKE_displist_elem_free(DispList *dl) { @@ -506,7 +507,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal) dl = dl->next; } - /* XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { */ + /* XXX (obedit && obedit->actcol) ? (obedit->actcol-1) : 0)) { */ if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES))) { if (tot) { dlnew = MEM_callocN(sizeof(DispList), "filldisplist"); @@ -758,7 +759,7 @@ static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob, int fo /* this modifiers are moving point of tessellation automatically * (some of them even can't be applied on tessellated curve), set flag - * for incformation button in modifier's header + * for information button in modifier's header */ md->mode |= eModifierMode_ApplyOnSpline; } @@ -1598,15 +1599,15 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco) if (ob->derivedFinal) { DM_set_object_boundbox(ob, ob->derivedFinal); + + /* always keep curve's BB in sync with non-deformed displist */ + if (cu->bb == NULL) + cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + + boundbox_dispbase(cu->bb, &cu->disp); } else { boundbox_displist(ob); - - /* if there is no derivedMesh, object's boundbox is unneeded */ - if (ob->bb) { - MEM_freeN(ob->bb); - ob->bb = NULL; - } } } @@ -1642,42 +1643,50 @@ float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *derivedFina return orco; } -/* this is confusing, there's also min_max_object, appplying the obmat... */ -static void boundbox_displist(Object *ob) +static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase) { - BoundBox *bb = NULL; float min[3], max[3]; DispList *dl; float *vert; int a, tot = 0; + int doit = 0; INIT_MINMAX(min, max); + for (dl = dispbase->first; dl; dl = dl->next) { + tot = (dl->type == DL_INDEX3) ? dl->nr : dl->nr * dl->parts; + vert = dl->verts; + for (a = 0; a < tot; a++, vert += 3) { + minmax_v3v3_v3(min, max, vert); + } + doit |= (tot != 0); + } + + if (!doit) { + /* there's no geometry in displist, use zero-sized boundbox */ + zero_v3(min); + zero_v3(max); + } + + BKE_boundbox_init_from_minmax(bb, min, max); +} + +/* this is confusing, there's also min_max_object, appplying the obmat... */ +static void boundbox_displist(Object *ob) +{ if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { Curve *cu = ob->data; - int doit = 0; - if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); - bb = cu->bb; + /* calculate curve's BB based on non-deformed displist */ + if (cu->bb == NULL) + cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); - for (dl = ob->disp.first; dl; dl = dl->next) { - tot = (dl->type == DL_INDEX3) ? dl->nr : dl->nr * dl->parts; - vert = dl->verts; - for (a = 0; a < tot; a++, vert += 3) { - minmax_v3v3_v3(min, max, vert); - } - doit = (tot != 0); - } + boundbox_dispbase(cu->bb, &cu->disp); - if (!doit) { - /* there's no geometry in displist, use zero-sized boundbox */ - zero_v3(min); - zero_v3(max); - } - - } + /* object's BB is calculated from final displist */ + if (ob->bb == NULL) + ob->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); - if (bb) { - BKE_boundbox_init_from_minmax(bb, min, max); + boundbox_dispbase(ob->bb, &ob->disp); } } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index d41893b4335..d652b97e2fa 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -248,6 +248,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *em) totfilltri = BLI_scanfill_calc_ex(&sf_ctx, 0, efa->no); BLI_assert(totfilltri <= efa->len - 2); + (void)totfilltri; for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) { BMLoop **l_ptr = looptris[i++]; diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 7b007af86d6..c3fc659137d 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -480,6 +480,92 @@ static FModifierTypeInfo FMI_ENVELOPE = { fcm_envelope_evaluate /* evaluate */ }; +/* exported function for finding points */ + +/* Binary search algorithm for finding where to insert Envelope Data Point. + * Returns the index to insert at (data already at that index will be offset if replace is 0) + */ +#define BINARYSEARCH_FRAMEEQ_THRESH 0.0001f + +int BKE_fcm_envelope_find_index(FCM_EnvelopeData array[], float frame, int arraylen, short *exists) +{ + int start = 0, end = arraylen; + int loopbreaker = 0, maxloop = arraylen * 2; + + /* initialize exists-flag first */ + *exists = 0; + + /* sneaky optimizations (don't go through searching process if...): + * - keyframe to be added is to be added out of current bounds + * - keyframe to be added would replace one of the existing ones on bounds + */ + if ((arraylen <= 0) || (array == NULL)) { + printf("Warning: binarysearch_fcm_envelopedata_index() encountered invalid array\n"); + return 0; + } + else { + /* check whether to add before/after/on */ + float framenum; + + /* 'First' Point (when only one point, this case is used) */ + framenum = array[0].time; + if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) { + *exists = 1; + return 0; + } + else if (frame < framenum) { + return 0; + } + + /* 'Last' Point */ + framenum = array[(arraylen - 1)].time; + if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) { + *exists = 1; + return (arraylen - 1); + } + else if (frame > framenum) { + return arraylen; + } + } + + + /* most of the time, this loop is just to find where to put it + * - 'loopbreaker' is just here to prevent infinite loops + */ + for (loopbreaker = 0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) { + /* compute and get midpoint */ + int mid = start + ((end - start) / 2); /* we calculate the midpoint this way to avoid int overflows... */ + float midfra = array[mid].time; + + /* check if exactly equal to midpoint */ + if (IS_EQT(frame, midfra, BINARYSEARCH_FRAMEEQ_THRESH)) { + *exists = 1; + return mid; + } + + /* repeat in upper/lower half */ + if (frame > midfra) { + start = mid + 1; + } + else if (frame < midfra) { + end = mid - 1; + } + } + + /* print error if loop-limit exceeded */ + if (loopbreaker == (maxloop - 1)) { + printf("Error: binarysearch_fcm_envelopedata_index() was taking too long\n"); + + // include debug info + printf("\tround = %d: start = %d, end = %d, arraylen = %d\n", loopbreaker, start, end, arraylen); + } + + /* not found, so return where to place it */ + return start; +} +#undef BINARYSEARCH_FRAMEEQ_THRESH + + /* Cycles F-Curve Modifier --------------------------- */ /* This modifier changes evaltime to something that exists within the curve's frame-range, diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index fda7dfb046e..61f468373f4 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -137,11 +137,11 @@ void BKE_group_unlink(Group *group) group->id.us = 0; } -Group *add_group(const char *name) +Group *add_group(Main *bmain, const char *name) { Group *group; - group = BKE_libblock_alloc(&G.main->group, ID_GR, name); + group = BKE_libblock_alloc(&bmain->group, ID_GR, name); group->layer = (1 << 20) - 1; return group; } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 9086ef49e4d..9fdf51ceba9 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -27,7 +27,6 @@ * \ingroup bke */ - #include <stdio.h> #include <stdlib.h> #include <stddef.h> diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 82b0d231869..018cd25187a 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -242,11 +242,11 @@ void BKE_image_free(Image *ima) } /* only image block itself */ -static Image *image_alloc(const char *name, short source, short type) +static Image *image_alloc(Main *bmain, const char *name, short source, short type) { Image *ima; - ima = BKE_libblock_alloc(&G.main->image, ID_IM, name); + ima = BKE_libblock_alloc(&bmain->image, ID_IM, name); if (ima) { ima->ok = IMA_OK; @@ -323,9 +323,9 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) } /* empty image block, of similar type and filename */ -Image *BKE_image_copy(Image *ima) +Image *BKE_image_copy(Main *bmain, Image *ima) { - Image *nima = image_alloc(ima->id.name + 2, ima->source, ima->type); + Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, ima->type); BLI_strncpy(nima->name, ima->name, sizeof(ima->name)); @@ -343,6 +343,9 @@ Image *BKE_image_copy(Image *ima) BKE_color_managed_colorspace_settings_copy(&nima->colorspace_settings, &ima->colorspace_settings); + if (ima->packedfile) + nima->packedfile = dupPackedFile(ima->packedfile); + return nima; } @@ -433,7 +436,7 @@ void BKE_image_make_local(struct Image *ima) extern_local_image(ima); } else if (is_local && is_lib) { - Image *ima_new = BKE_image_copy(ima); + Image *ima_new = BKE_image_copy(bmain, ima); ima_new->id.us = 0; @@ -568,7 +571,7 @@ static void image_init_color_management(Image *ima) } } -Image *BKE_image_load(const char *filepath) +Image *BKE_image_load(Main *bmain, const char *filepath) { Image *ima; int file, len; @@ -576,7 +579,7 @@ Image *BKE_image_load(const char *filepath) char str[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, bmain->name); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -589,7 +592,7 @@ Image *BKE_image_load(const char *filepath) while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\') len--; libname = filepath + len; - ima = image_alloc(libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima = image_alloc(bmain, libname, IMA_SRC_FILE, IMA_TYPE_IMAGE); BLI_strncpy(ima->name, filepath, sizeof(ima->name)); if (BLI_testextensie_array(filepath, imb_ext_movie)) @@ -631,7 +634,7 @@ Image *BKE_image_load_exists(const char *filepath) } } - return BKE_image_load(filepath); + return BKE_image_load(G.main, filepath); } static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, @@ -691,10 +694,10 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char } /* adds new image block, creates ImBuf and initializes color */ -Image *BKE_image_add_generated(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4]) +Image *BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4]) { /* on save, type is changed to FILE in editsima.c */ - Image *ima = image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); + Image *ima = image_alloc(bmain, name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); if (ima) { ImBuf *ibuf; @@ -720,7 +723,7 @@ Image *BKE_image_add_from_imbuf(ImBuf *ibuf) /* on save, type is changed to FILE in editsima.c */ Image *ima; - ima = image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima = image_alloc(G.main, BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); if (ima) { BLI_strncpy(ima->name, ibuf->name, FILE_MAX); @@ -2104,7 +2107,7 @@ Image *BKE_image_verify_viewer(int type, const char *name) break; if (ima == NULL) - ima = image_alloc(name, IMA_SRC_VIEWER, type); + ima = image_alloc(G.main, name, IMA_SRC_VIEWER, type); /* happens on reload, imagewindow cannot be image user when hidden*/ if (ima->id.us == 0) diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 59dd02849dd..c5364744b2d 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -1548,7 +1548,7 @@ static void ipo_to_animdata(ID *id, Ipo *ipo, char actname[], char constname[], BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name + 2); - adt->action = add_empty_action(nameBuf); + adt->action = add_empty_action(G.main, nameBuf); if (G.debug & G_DEBUG) printf("\t\tadded new action - '%s'\n", nameBuf); } @@ -2093,7 +2093,7 @@ void do_versions_ipos_to_animato(Main *main) bAction *new_act; /* add a new action for this, and convert all data into that action */ - new_act = add_empty_action(id->name + 2); + new_act = add_empty_action(main, id->name + 2); ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); new_act->idroot = ipo->blocktype; } diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 2f37db846f3..32cc5c6c22e 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -54,11 +54,11 @@ #include "BKE_main.h" #include "BKE_node.h" -Lamp *BKE_lamp_add(const char *name) +Lamp *BKE_lamp_add(Main *bmain, const char *name) { Lamp *la; - la = BKE_libblock_alloc(&G.main->lamp, ID_LA, name); + la = BKE_libblock_alloc(&bmain->lamp, ID_LA, name); la->r = la->g = la->b = la->k = 1.0f; la->haint = la->energy = 1.0f; diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index fa01e9fd933..fd57a88e279 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -180,11 +180,11 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) MEM_freeN(vertexCos); } -Lattice *BKE_lattice_add(const char *name) +Lattice *BKE_lattice_add(Main *bmain, const char *name) { Lattice *lt; - lt = BKE_libblock_alloc(&G.main->latt, ID_LT, name); + lt = BKE_libblock_alloc(&bmain->latt, ID_LT, name); lt->flag = LT_GRID; @@ -1003,3 +1003,66 @@ struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *oblatt) if (lt->editlatt) lt = lt->editlatt->latt; return lt->dvert; } + +void BKE_lattice_center_median(struct Lattice *lt, float cent[3]) +{ + int i, numVerts; + + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + zero_v3(cent); + + for (i = 0; i < numVerts; i++) + add_v3_v3(cent, lt->def[i].vec); + + mul_v3_fl(cent, 1.0f / (float)numVerts); +} + +void BKE_lattice_minmax(struct Lattice *lt, float min[3], float max[3]) +{ + int i, numVerts; + + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + for (i = 0; i < numVerts; i++) + minmax_v3v3_v3(min, max, lt->def[i].vec); +} + +void BKE_lattice_center_bounds(struct Lattice *lt, float cent[3]) +{ + float min[3], max[3]; + + INIT_MINMAX(min, max); + + BKE_lattice_minmax(lt, min, max); + mid_v3_v3v3(cent, min, max); +} + +void BKE_lattice_translate(Lattice *lt, float offset[3], int do_keys) +{ + int i, numVerts; + + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + if (lt->def) + for (i = 0; i < numVerts; i++) + add_v3_v3(lt->def[i].vec, offset); + + if (lt->editlatt) + for (i = 0; i < numVerts; i++) + add_v3_v3(lt->editlatt->latt->def[i].vec, offset); + + if (do_keys && lt->key) { + KeyBlock *kb; + + for (kb = lt->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { + add_v3_v3(fp, offset); + } + } + } +} + diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 610237abcdd..b4c1d681ddc 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -319,7 +319,7 @@ int id_copy(ID *id, ID **newid, int test) if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); return 1; case ID_IM: - if (!test) *newid = (ID *)BKE_image_copy((Image *)id); + if (!test) *newid = (ID *)BKE_image_copy(G.main, (Image *)id); return 1; case ID_LT: if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); @@ -766,13 +766,13 @@ void BKE_libblock_copy_data(ID *id, const ID *id_from, const short do_action) } /* used everywhere in blenkernel */ -void *BKE_libblock_copy(ID *id) +void *BKE_libblock_copy_ex(Main *bmain, ID *id) { ID *idn; ListBase *lb; size_t idn_len; - lb = which_libbase(G.main, GS(id->name)); + lb = which_libbase(bmain, GS(id->name)); idn = BKE_libblock_alloc(lb, GS(id->name), id->name + 2); assert(idn != NULL); @@ -793,6 +793,11 @@ void *BKE_libblock_copy(ID *id) return idn; } +void *BKE_libblock_copy(ID *id) +{ + return BKE_libblock_copy_ex(G.main, id); +} + static void BKE_library_free(Library *lib) { if (lib->packedfile) diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index bda924060d5..960432d6b3d 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -698,18 +698,18 @@ void BKE_mask_point_select_set_handle(MaskSplinePoint *point, const short do_sel } /* only mask block itself */ -static Mask *mask_alloc(const char *name) +static Mask *mask_alloc(Main *bmain, const char *name) { Mask *mask; - mask = BKE_libblock_alloc(&G.main->mask, ID_MSK, name); + mask = BKE_libblock_alloc(&bmain->mask, ID_MSK, name); mask->id.flag |= LIB_FAKEUSER; return mask; } -Mask *BKE_mask_new(const char *name) +Mask *BKE_mask_new(Main *bmain, const char *name) { Mask *mask; char mask_name[MAX_ID_NAME - 2]; @@ -719,7 +719,7 @@ Mask *BKE_mask_new(const char *name) else strcpy(mask_name, "Mask"); - mask = mask_alloc(mask_name); + mask = mask_alloc(bmain, mask_name); /* arbitrary defaults */ mask->sfra = 1; diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index 73452b216ff..e3423c93f3c 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -213,7 +213,7 @@ MaskRasterHandle *BKE_maskrasterize_handle_new(void) { MaskRasterHandle *mr_handle; - mr_handle = MEM_callocN(sizeof(MaskRasterHandle), STRINGIFY(MaskRasterHandle)); + mr_handle = MEM_callocN(sizeof(MaskRasterHandle), "MaskRasterHandle"); return mr_handle; } @@ -569,7 +569,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mas unsigned int masklay_index; mr_handle->layers_tot = BLI_countlist(&mask->masklayers); - mr_handle->layers = MEM_mallocN(sizeof(MaskRasterLayer) * mr_handle->layers_tot, STRINGIFY(MaskRasterLayer)); + mr_handle->layers = MEM_mallocN(sizeof(MaskRasterLayer) * mr_handle->layers_tot, "MaskRasterLayer"); BLI_rctf_init_minmax(&mr_handle->bounds); for (masklay = mask->masklayers.first, masklay_index = 0; masklay; masklay = masklay->next, masklay_index++) { diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index ad0a149a42c..50e00161db3 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -209,11 +209,11 @@ void init_material(Material *ma) ma->preview = NULL; } -Material *BKE_material_add(const char *name) +Material *BKE_material_add(Main *bmain, const char *name) { Material *ma; - ma = BKE_libblock_alloc(&G.main->mat, ID_MA, name); + ma = BKE_libblock_alloc(&bmain->mat, ID_MA, name); init_material(ma); @@ -1781,7 +1781,7 @@ static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag) } /* create a new material */ else { - ma = BKE_material_add(idname + 2); + ma = BKE_material_add(main, idname + 2); if (ma) { printf("TexFace Convert: Material \"%s\" created.\n", idname + 2); diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index b3f71e58e9f..d939b9cc3c0 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -196,11 +196,11 @@ void BKE_mball_free(MetaBall *mb) if (mb->disp.first) BKE_displist_free(&mb->disp); } -MetaBall *BKE_mball_add(const char *name) +MetaBall *BKE_mball_add(Main *bmain, const char *name) { MetaBall *mb; - mb = BKE_libblock_alloc(&G.main->mball, ID_MB, name); + mb = BKE_libblock_alloc(&bmain->mball, ID_MB, name); mb->size[0] = mb->size[1] = mb->size[2] = 1.0; mb->texflag = MB_AUTOSPACE; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 03df0c28944..21641e77b0b 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -445,11 +445,11 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) mesh->totface = 0; } -Mesh *BKE_mesh_add(const char *name) +Mesh *BKE_mesh_add(Main *bmain, const char *name) { Mesh *me; - me = BKE_libblock_alloc(&G.main->mesh, ID_ME, name); + me = BKE_libblock_alloc(&bmain->mesh, ID_ME, name); me->size[0] = me->size[1] = me->size[2] = 1.0; me->smoothresh = 30; @@ -466,7 +466,7 @@ Mesh *BKE_mesh_add(const char *name) return me; } -Mesh *BKE_mesh_copy(Mesh *me) +Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) { Mesh *men; MTFace *tface; @@ -474,7 +474,7 @@ Mesh *BKE_mesh_copy(Mesh *me) int a, i; const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ - men = BKE_libblock_copy(&me->id); + men = BKE_libblock_copy_ex(bmain, &me->id); men->mat = MEM_dupallocN(me->mat); for (a = 0; a < men->totcol; a++) { @@ -527,6 +527,11 @@ Mesh *BKE_mesh_copy(Mesh *me) return men; } +Mesh *BKE_mesh_copy(Mesh *me) +{ + return BKE_mesh_copy_ex(G.main, me); +} + BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob) { BMesh *bm; @@ -1489,7 +1494,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int use_orco_u if (dm == NULL) { if (BKE_mesh_nurbs_displist_to_mdata(ob, dispbase, &allvert, &totvert, &alledge, &totedge, &allloop, - &allpoly, (use_orco_uv)? &alluv: NULL, + &allpoly, (use_orco_uv) ? &alluv : NULL, &totloop, &totpoly) != 0) { /* Error initializing */ @@ -1497,7 +1502,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int use_orco_u } /* make mesh */ - me = BKE_mesh_add("Mesh"); + me = BKE_mesh_add(G.main, "Mesh"); me->totvert = totvert; me->totedge = totedge; me->totloop = totloop; @@ -1519,7 +1524,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int use_orco_u BKE_mesh_calc_edges(me, TRUE); } else { - me = BKE_mesh_add("Mesh"); + me = BKE_mesh_add(G.main, "Mesh"); DM_to_mesh(dm, me, ob); } @@ -1635,7 +1640,7 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) BLI_edgehash_free(eh, NULL); if (edges.first) { - Curve *cu = BKE_curve_add(ob->id.name + 2, OB_CURVE); + Curve *cu = BKE_curve_add(G.main, ob->id.name + 2, OB_CURVE); cu->flag |= CU_3D; while (edges.first) { @@ -2574,6 +2579,7 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, totfilltri = BLI_scanfill_calc(&sf_ctx, 0); BLI_assert(totfilltri <= mp->totloop - 2); + (void)totfilltri; for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next, mf++) { mface_to_poly_map[mface_index] = poly_index; diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 69e368f0d08..943d9e9452a 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -479,11 +479,11 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i /*********************** common functions *************************/ /* only image block itself */ -static MovieClip *movieclip_alloc(const char *name) +static MovieClip *movieclip_alloc(Main *bmain, const char *name) { MovieClip *clip; - clip = BKE_libblock_alloc(&G.main->movieclip, ID_MC, name); + clip = BKE_libblock_alloc(&bmain->movieclip, ID_MC, name); clip->aspx = clip->aspy = 1.0f; @@ -542,7 +542,7 @@ static void detect_clip_source(MovieClip *clip) * otherwise creates new. * does not load ibuf itself * pass on optional frame for #name images */ -MovieClip *BKE_movieclip_file_add(const char *name) +MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) { MovieClip *clip; int file, len; @@ -550,7 +550,7 @@ MovieClip *BKE_movieclip_file_add(const char *name) char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, name, sizeof(str)); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, bmain->name); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -559,7 +559,7 @@ MovieClip *BKE_movieclip_file_add(const char *name) close(file); /* ** first search an identical clip ** */ - for (clip = G.main->movieclip.first; clip; clip = clip->id.next) { + for (clip = bmain->movieclip.first; clip; clip = clip->id.next) { BLI_strncpy(strtest, clip->name, sizeof(clip->name)); BLI_path_abs(strtest, G.main->name); @@ -580,7 +580,7 @@ MovieClip *BKE_movieclip_file_add(const char *name) len--; libname = name + len; - clip = movieclip_alloc(libname); + clip = movieclip_alloc(bmain, libname); BLI_strncpy(clip->name, name, sizeof(clip->name)); detect_clip_source(clip); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 6f585198524..143f2186020 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1447,9 +1447,9 @@ void BKE_nla_validate_state(AnimData *adt) if (strip->extendmode != NLASTRIP_EXTEND_NOTHING) { /* 1) First strip must be set to extend hold, otherwise, stuff before acts dodgy * 2) Only overwrite extend mode if *not* changing it will most probably result in - * occlusion problems, which will occur iff - * - blendmode = REPLACE - * - all channels the same (this is fiddly to test, so is currently assumed) + * occlusion problems, which will occur if... + * - blendmode = REPLACE + * - all channels the same (this is fiddly to test, so is currently assumed) * * Should fix problems such as [#29869] */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c73bd5ef8fd..97bee320ecb 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -656,7 +656,7 @@ void nodeDetachNode(struct bNode *node) } } -bNodeTree *ntreeAddTree(const char *name, int type, int nodetype) +bNodeTree *ntreeAddTree(Main *bmain, const char *name, int type, int nodetype) { bNodeTree *ntree; bNodeType *ntype; @@ -670,7 +670,7 @@ bNodeTree *ntreeAddTree(const char *name, int type, int nodetype) BLI_strncpy(ntree->id.name + 2, name, sizeof(ntree->id.name)); } else - ntree = BKE_libblock_alloc(&G.main->nodetree, ID_NT, name); + ntree = BKE_libblock_alloc(&bmain->nodetree, ID_NT, name); ntree->type = type; ntree->nodetype = nodetype; @@ -1634,7 +1634,7 @@ void BKE_node_clipboard_add_node(bNode *node) { #ifdef USE_NODE_CB_VALIDATE /* add extra info */ - bNodeClipboardExtraInfo *node_info = MEM_mallocN(sizeof(bNodeClipboardExtraInfo), STRINGIFY(bNodeClipboardExtraInfo)); + bNodeClipboardExtraInfo *node_info = MEM_mallocN(sizeof(bNodeClipboardExtraInfo), "bNodeClipboardExtraInfo"); node_info->id = node->id; if (node->id) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a46196f38d8..498b3b226f6 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -843,16 +843,16 @@ int BKE_object_exists_check(Object *obtest) void *BKE_object_obdata_add_from_type(int type) { switch (type) { - case OB_MESH: return BKE_mesh_add("Mesh"); - case OB_CURVE: return BKE_curve_add("Curve", OB_CURVE); - case OB_SURF: return BKE_curve_add("Surf", OB_SURF); - case OB_FONT: return BKE_curve_add("Text", OB_FONT); - case OB_MBALL: return BKE_mball_add("Meta"); - case OB_CAMERA: return BKE_camera_add("Camera"); - case OB_LAMP: return BKE_lamp_add("Lamp"); - case OB_LATTICE: return BKE_lattice_add("Lattice"); - case OB_ARMATURE: return BKE_armature_add("Armature"); - case OB_SPEAKER: return BKE_speaker_add("Speaker"); + case OB_MESH: return BKE_mesh_add(G.main, "Mesh"); + case OB_CURVE: return BKE_curve_add(G.main, "Curve", OB_CURVE); + case OB_SURF: return BKE_curve_add(G.main, "Surf", OB_SURF); + case OB_FONT: return BKE_curve_add(G.main, "Text", OB_FONT); + case OB_MBALL: return BKE_mball_add(G.main, "Meta"); + case OB_CAMERA: return BKE_camera_add(G.main, "Camera"); + case OB_LAMP: return BKE_lamp_add(G.main, "Lamp"); + case OB_LATTICE: return BKE_lattice_add(G.main, "Lattice"); + case OB_ARMATURE: return BKE_armature_add(G.main, "Armature"); + case OB_SPEAKER: return BKE_speaker_add(G.main, "Speaker"); case OB_EMPTY: return NULL; default: printf("BKE_object_obdata_add_from_type: Internal error, bad type: %d\n", type); @@ -881,14 +881,14 @@ static const char *get_obdata_defname(int type) } /* more general add: creates minimum required data, but without vertices etc. */ -Object *BKE_object_add_only_object(int type, const char *name) +Object *BKE_object_add_only_object(Main *bmain, int type, const char *name) { Object *ob; if (!name) name = get_obdata_defname(type); - ob = BKE_libblock_alloc(&G.main->object, ID_OB, name); + ob = BKE_libblock_alloc(&bmain->object, ID_OB, name); /* default object vars */ ob->type = type; @@ -974,7 +974,7 @@ Object *BKE_object_add(struct Scene *scene, int type) char name[MAX_ID_NAME]; BLI_strncpy(name, get_obdata_defname(type), sizeof(name)); - ob = BKE_object_add_only_object(type, name); + ob = BKE_object_add_only_object(G.main, type, name); ob->data = BKE_object_obdata_add_from_type(type); @@ -1240,13 +1240,13 @@ void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src) copy_v3_v3(ob_tar->size, ob_src->size); } -static Object *object_copy_do(Object *ob, int copy_caches) +Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches) { Object *obn; ModifierData *md; int a; - obn = BKE_libblock_copy(&ob->id); + obn = BKE_libblock_copy_ex(bmain, &ob->id); if (ob->totcol) { obn->mat = MEM_dupallocN(ob->mat); @@ -1322,13 +1322,7 @@ static Object *object_copy_do(Object *ob, int copy_caches) /* copy objects, will re-initialize cached simulation data */ Object *BKE_object_copy(Object *ob) { - return object_copy_do(ob, FALSE); -} - -/* copy objects, will duplicate cached simulation data */ -Object *BKE_object_copy_with_caches(Object *ob) -{ - return object_copy_do(ob, TRUE); + return BKE_object_copy_ex(G.main, ob, FALSE); } static void extern_local_object(Object *ob) @@ -3205,6 +3199,9 @@ void BKE_object_relink(Object *ob) if (ob->adt) BKE_relink_animdata(ob->adt); + + if (ob->rigidbody_constraint) + BKE_rigidbody_relink_constraint(ob->rigidbody_constraint); ID_NEW(ob->parent); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index dc8aed91c00..d34d5eaa250 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -43,6 +43,7 @@ #include "BKE_brush.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_library.h" #include "BKE_paint.h" #include "BKE_subsurf.h" @@ -179,7 +180,7 @@ void BKE_paint_init(Paint *p, const char col[3]) /* If there's no brush, create one */ brush = paint_brush(p); if (brush == NULL) - brush = BKE_brush_add("Brush"); + brush = BKE_brush_add(G.main, "Brush"); paint_brush_set(p, brush); memcpy(p->paint_cursor_col, col, 3); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 71854a93f4d..c01ea4e518d 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -684,8 +684,6 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[4][4], floa ParticleRenderData *data; ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - if (G.is_rendering == FALSE) - return; if (psys->renderdata) return; @@ -2384,7 +2382,7 @@ void psys_find_parents(ParticleSimulationData *sim) int from = PART_FROM_FACE; totparent = (int)(totchild * part->parents * 0.3f); - if (G.is_rendering && part->child_nbr && part->ren_child_nbr) + if ((sim->psys->renderdata || G.is_rendering) && part->child_nbr && part->ren_child_nbr) totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; tree = BLI_kdtree_new(totparent); @@ -2461,7 +2459,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c if (totchild && part->childtype == PART_CHILD_FACES) { totparent = (int)(totchild * part->parents * 0.3f); - if (G.is_rendering && part->child_nbr && part->ren_child_nbr) + if ((psys->renderdata || G.is_rendering) && part->child_nbr && part->ren_child_nbr) totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; /* part->parents could still be 0 so we can't test with totparent */ diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 9a0b1a76988..666c85d2f6b 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -770,7 +770,7 @@ static void pbvh_bmesh_collapse_edge(PBVH *bvh, BMEdge *e, BMVert *v1, BM_edge_kill(bvh->bm, e); /* For all remaining faces of v2, create a new face that is the - same except it uses v1 instead of v2 */ + * same except it uses v1 instead of v2 */ /* Note: this could be done with BM_vert_splice(), but that * requires handling other issues like duplicate edges, so doesn't * really buy anything. */ diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index ef096adc7a7..4302032ade1 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1275,7 +1275,7 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup if (scene && (duplis-- > 0) && (ob->transflag & OB_DUPLI)) { ListBase *lb_dupli_ob; - /* don't update the dupli groups, we only wan't their pid's */ + /* don't update the dupli groups, we only want their pid's */ if ((lb_dupli_ob = object_duplilist_ex(scene, ob, FALSE, FALSE))) { DupliObject *dob; for (dob= lb_dupli_ob->first; dob; dob= dob->next) { diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 7cab0d7471f..24355149926 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -203,8 +203,6 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) /* just duplicate the whole struct first (to catch all the settings) */ rbcN = MEM_dupallocN(ob->rigidbody_constraint); - // RB_TODO be more clever about copying constrained objects - /* tag object as needing to be verified */ rbcN->flag |= RBC_FLAG_NEEDS_VALIDATE; @@ -216,6 +214,13 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) return rbcN; } +/* preserve relationships between constraints and rigid bodies after duplication */ +void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) +{ + ID_NEW(rbc->ob1); + ID_NEW(rbc->ob2); +} + /* ************************************** */ /* Setup Utilities - Validate Sim Instances */ @@ -354,7 +359,7 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild) /* if automatically determining dimensions, use the Object's boundbox * - assume that all quadrics are standing upright on local z-axis * - assume even distribution of mass around the Object's pivot - * (i.e. Object pivot is centralised in boundbox) + * (i.e. Object pivot is centralized in boundbox) */ // XXX: all dimensions are auto-determined now... later can add stored settings for this /* get object dimensions without scaling */ @@ -416,6 +421,10 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild) rbo->physics_shape = new_shape; RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo)); } + else { /* otherwise fall back to box shape */ + rbo->shape = RB_SHAPE_BOX; + BKE_rigidbody_validate_sim_shape(ob, true); + } } /* --------------------- */ @@ -853,7 +862,7 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob) if (rbw->constraints) { for (go = rbw->constraints->gobject.first; go; go = go->next) { Object *obt = go->ob; - if (obt) { + if (obt && obt->rigidbody_constraint) { rbc = obt->rigidbody_constraint; if (rbc->ob1 == ob) { rbc->ob1 = NULL; @@ -954,7 +963,7 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2])); /* make transformed objects temporarily kinmatic so that they can be moved by the user during simulation */ - if ((ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) || rbo->type == RBO_TYPE_PASSIVE) { + if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) { RB_body_set_kinematic_state(rbo->physics_object, TRUE); RB_body_set_mass(rbo->physics_object, 0.0f); } @@ -1114,6 +1123,9 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw) if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) { RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED); RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo)); + /* deactivate passive objects so they don't interfere with deactivation of active objects */ + if (rbo->type == RBO_TYPE_PASSIVE) + RB_body_deactivate(rbo->physics_object); } } } @@ -1174,8 +1186,12 @@ void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], flo copy_qt_qt(rbo->orn, ob->quat); copy_qt_qt(ob->quat, quat); } - if (rbo->physics_object) + if (rbo->physics_object) { + /* allow passive objects to return to original transform */ + if (rbo->type == RBO_TYPE_PASSIVE) + RB_body_set_kinematic_state(rbo->physics_object, TRUE); RB_body_set_loc_rot(rbo->physics_object, rbo->pos, rbo->orn); + } // RB_TODO update rigid body physics object's loc/rot for dynamic objects here as well (needs to be done outside bullet's update loop) } @@ -1280,6 +1296,7 @@ void BKE_rigidbody_free_object(Object *ob) {} void BKE_rigidbody_free_constraint(Object *ob) {} struct RigidBodyOb *BKE_rigidbody_copy_object(Object *ob) { return NULL; } struct RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) { return NULL; } +void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) {} void BKE_rigidbody_validate_sim_shape(Object *ob, short rebuild) {} void BKE_rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, short rebuild) {} void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, short rebuild) {} diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index f5d529f0f07..81084661368 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -742,7 +742,7 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) } /* used by metaballs - * doesnt return the original duplicated object, only dupli's + * doesn't return the original duplicated object, only dupli's */ int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob) { @@ -1091,7 +1091,7 @@ static void scene_depsgraph_hack(Scene *scene, Scene *scene_parent) if (ob->depsflag) { int recalc = 0; - // printf("depshack %s\n", ob->id.name+2); + // printf("depshack %s\n", ob->id.name + 2); if (ob->depsflag & OB_DEPS_EXTRA_OB_RECALC) recalc |= OB_RECALC_OB; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 95b72d0185c..01f57b95378 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -355,6 +355,20 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) return NULL; } +ARegion *BKE_area_find_region_active_win(ScrArea *sa) +{ + if (sa) { + ARegion *ar = BLI_findlink(&sa->regionbase, sa->region_active_win); + if (ar && (ar->regiontype == RGN_TYPE_WINDOW)) { + return ar; + } + + /* fallback to any */ + return BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + } + return NULL; +} + /* note, using this function is generally a last resort, you really want to be * using the context when you can - campbell * -1 for any type */ diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c index 3d8a2f7cddf..9ea405ef636 100644 --- a/source/blender/blenkernel/intern/seqmodifier.c +++ b/source/blender/blenkernel/intern/seqmodifier.c @@ -135,7 +135,7 @@ static void modifier_apply_threaded(ImBuf *ibuf, ImBuf *mask, modifier_apply_thr init_data.apply_callback = apply_callback; IMB_processor_apply_threaded(ibuf->y, sizeof(ModifierThread), &init_data, - modifier_init_handle, modifier_do_thread); + modifier_init_handle, modifier_do_thread); } /* **** Color Balance Modifier **** */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 2c1fd092fbb..f1724bdfc6b 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1434,7 +1434,7 @@ void BKE_sequencer_proxy_rebuild(SeqIndexBuildContext *context, short *stop, sho seq_proxy_build_frame(render_context, seq, cfra, 100); } - *progress = (float) cfra / (seq->enddisp - seq->endstill - seq->startdisp + seq->startstill); + *progress = (float) (cfra - seq->startdisp - seq->startstill) / (seq->enddisp - seq->endstill - seq->startdisp - seq->startstill); *do_update = TRUE; if (*stop || G.is_break) @@ -1746,7 +1746,7 @@ void BKE_sequencer_color_balance_apply(StripColorBalance *cb, ImBuf *ibuf, float init_data.mask = mask_input; IMB_processor_apply_threaded(ibuf->y, sizeof(ColorBalanceThread), &init_data, - color_balance_init_handle, color_balance_do_thread); + color_balance_init_handle, color_balance_do_thread); /* color balance either happens on float buffer or byte buffer, but never on both, * free byte buffer if there's float buffer since float buffer would be used for diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index be36e30808d..f56d03bfb57 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -213,8 +213,8 @@ static void smoke_pos_to_cell(SmokeDomainSettings *sds, float pos[3]) pos[2] *= 1.0f / sds->cell_size[2]; } -/* set domain resolution and dimensions from object derivedmesh */ -static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object *ob, DerivedMesh *dm) +/* set domain transformations and base resolution from object derivedmesh */ +static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object *ob, DerivedMesh *dm, int init_resolution) { size_t i; float min[3] = {FLT_MAX, FLT_MAX, FLT_MAX}, max[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; @@ -246,7 +246,10 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * /* calculate domain dimensions */ sub_v3_v3v3(size, max, min); - copy_v3_v3(sds->cell_size, size); + if (init_resolution) { + zero_v3_int(sds->base_res); + copy_v3_v3(sds->cell_size, size); + } mul_v3_v3(size, ob->size); copy_v3_v3(sds->global_size, size); copy_v3_v3(sds->dp0, min); @@ -254,18 +257,18 @@ static void smoke_set_domain_from_derivedmesh(SmokeDomainSettings *sds, Object * invert_m4_m4(sds->imat, ob->obmat); // prevent crash when initializing a plane as domain - if ((size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON)) + if (!init_resolution || (size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON)) return; /* define grid resolutions from longest domain side */ - if (size[0] > MAX2(size[1], size[2])) { + if (size[0] >= MAX2(size[1], size[2])) { scale = res / size[0]; sds->scale = size[0] / ob->size[0]; sds->base_res[0] = res; sds->base_res[1] = (int)(size[1] * scale + 0.5f); sds->base_res[2] = (int)(size[2] * scale + 0.5f); } - else if (size[1] > MAX2(size[0], size[2])) { + else if (size[1] >= MAX2(size[0], size[2])) { scale = res / size[1]; sds->scale = size[1] / ob->size[1]; sds->base_res[0] = (int)(size[0] * scale + 0.5f); @@ -293,7 +296,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, Scene *scene, SmokeDomainSettings *sds = smd->domain; int res[3]; /* set domain dimensions from derivedmesh */ - smoke_set_domain_from_derivedmesh(sds, ob, dm); + smoke_set_domain_from_derivedmesh(sds, ob, dm, TRUE); /* reset domain values */ zero_v3_int(sds->shift); zero_v3(sds->shift_f); @@ -1984,7 +1987,7 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh * /* update object state */ invert_m4_m4(sds->imat, ob->obmat); copy_m4_m4(sds->obmat, ob->obmat); - smoke_set_domain_from_derivedmesh(sds, ob, domain_dm); + smoke_set_domain_from_derivedmesh(sds, ob, domain_dm, (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN)); /* use global gravity if enabled */ if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index f6599cc9648..f3391803294 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -42,11 +42,11 @@ #include "BKE_main.h" #include "BKE_speaker.h" -void *BKE_speaker_add(const char *name) +void *BKE_speaker_add(Main *bmain, const char *name) { Speaker *spk; - spk = BKE_libblock_alloc(&G.main->speaker, ID_SPK, name); + spk = BKE_libblock_alloc(&bmain->speaker, ID_SPK, name); spk->attenuation = 1.0f; spk->cone_angle_inner = 360.0f; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index a0f611a5a7b..3be9097ce82 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -171,9 +171,8 @@ void BKE_text_free(Text *text) #endif } -Text *BKE_text_add(const char *name) +Text *BKE_text_add(Main *bmain, const char *name) { - Main *bmain = G.main; Text *ta; TextLine *tmp; @@ -363,9 +362,8 @@ int BKE_text_reload(Text *text) return 1; } -Text *BKE_text_load(const char *file, const char *relpath) +Text *BKE_text_load(Main *bmain, const char *file, const char *relpath) { - Main *bmain = G.main; FILE *fp; int i, llen, len; unsigned char *buffer; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 2e909f11eaa..55a0f3752a1 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -540,9 +540,8 @@ void tex_set_type(Tex *tex, int type) /* ------------------------------------------------------------------------- */ -Tex *add_texture(const char *name) +Tex *add_texture(Main *bmain, const char *name) { - Main *bmain = G.main; Tex *tex; tex = BKE_libblock_alloc(&bmain->tex, ID_TE, name); diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 3c5d94a21e4..8b81e474e76 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -169,8 +169,9 @@ void BKE_tracking_settings_init(MovieTracking *tracking) tracking->settings.default_motion_model = TRACK_MOTION_MODEL_TRANSLATION; tracking->settings.default_minimum_correlation = 0.75; - tracking->settings.default_pattern_size = 11; + tracking->settings.default_pattern_size = 15; tracking->settings.default_search_size = 61; + tracking->settings.default_algorithm_flag |= TRACK_ALGORITHM_FLAG_USE_BRUTE; tracking->settings.dist = 1; tracking->settings.object_distance = 1; tracking->settings.reconstruction_success_threshold = 1e-3; diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index ad101c41dc5..206f829eaa8 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -79,9 +79,8 @@ void BKE_world_free(World *wrld) BKE_world_free_ex(wrld, TRUE); } -World *add_world(const char *name) +World *add_world(Main *bmain, const char *name) { - Main *bmain = G.main; World *wrld; wrld = BKE_libblock_alloc(&bmain->world, ID_WO, name); |