From 33accdb725bb7e5bb133b17faa2cc6191eca73ef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 5 Nov 2011 11:04:28 +0000 Subject: use (const char*) rather than (char*) where possible. also removed some unused function definitons. --- source/blender/blenkernel/intern/anim_sys.c | 10 +++++----- source/blender/blenkernel/intern/blender.c | 2 +- source/blender/blenkernel/intern/customdata_file.c | 10 +++++----- source/blender/blenkernel/intern/fcurve.c | 4 ++-- source/blender/blenkernel/intern/lattice.c | 6 ++++-- source/blender/blenkernel/intern/pointcache.c | 6 +++--- source/blender/blenkernel/intern/property.c | 6 +++--- source/blender/blenkernel/intern/sequencer.c | 6 +++--- source/blender/blenkernel/intern/text.c | 2 +- source/blender/blenkernel/intern/unit.c | 16 +++++++--------- source/blender/blenkernel/intern/writeffmpeg.c | 2 +- 11 files changed, 35 insertions(+), 35 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 6d94b42a7ac..63ab74fc105 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -545,7 +545,7 @@ void BKE_animdata_separate_by_basepath (ID *srcID, ID *dstID, ListBase *basepath /* Path Validation -------------------------------------------- */ /* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */ -static short check_rna_path_is_valid (ID *owner_id, char *path) +static short check_rna_path_is_valid (ID *owner_id, const char *path) { PointerRNA id_ptr, ptr; PropertyRNA *prop=NULL; @@ -560,7 +560,7 @@ static short check_rna_path_is_valid (ID *owner_id, char *path) /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate * NOTE: we assume that oldName and newName have [" "] padding around them */ -static char *rna_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, char *oldpath, int verify_paths) +static char *rna_path_rename_fix (ID *owner_id, const char *prefix, const char *oldName, const char *newName, char *oldpath, int verify_paths) { char *prefixPtr= strstr(oldpath, prefix); char *oldNamePtr= strstr(oldpath, oldName); @@ -631,7 +631,7 @@ static void fcurves_path_rename_fix (ID *owner_id, const char *prefix, char *old } /* Check RNA-Paths for a list of Drivers */ -static void drivers_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, char *oldKey, char *newKey, ListBase *curves, int verify_paths) +static void drivers_path_rename_fix (ID *owner_id, const char *prefix, const char *oldName, const char *newName, const char *oldKey, const char *newKey, ListBase *curves, int verify_paths) { FCurve *fcu; @@ -691,7 +691,7 @@ static void nlastrips_path_rename_fix (ID *owner_id, const char *prefix, char *o * NOTE: it is assumed that the structure we're replacing is <["><"]> * i.e. pose.bones["Bone"] */ -void BKE_animdata_fix_paths_rename (ID *owner_id, AnimData *adt, const char *prefix, char *oldName, char *newName, int oldSubscript, int newSubscript, int verify_paths) +void BKE_animdata_fix_paths_rename (ID *owner_id, AnimData *adt, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, int verify_paths) { NlaTrack *nlt; char *oldN, *newN; @@ -808,7 +808,7 @@ void BKE_animdata_main_cb (Main *mainptr, ID_AnimData_Edit_Callback func, void * * i.e. pose.bones["Bone"] */ /* TODO: use BKE_animdata_main_cb for looping over all data */ -void BKE_all_animdata_fix_paths_rename (char *prefix, char *oldName, char *newName) +void BKE_all_animdata_fix_paths_rename (const char *prefix, const char *oldName, const char *newName) { Main *mainptr= G.main; ID *id; diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index d68b0b361d1..0e8d598da3d 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -663,7 +663,7 @@ int BKE_undo_valid(const char *name) /* get name of undo item, return null if no item with this index */ /* if active pointer, set it to 1 if true */ -char *BKE_undo_get_name(int nr, int *active) +const char *BKE_undo_get_name(int nr, int *active) { UndoElem *uel= BLI_findlink(&undobase, nr); diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c index d65f08ed7a3..75898018a2b 100644 --- a/source/blender/blenkernel/intern/customdata_file.c +++ b/source/blender/blenkernel/intern/customdata_file.c @@ -273,7 +273,7 @@ static int cdf_write_header(CDataFile *cdf) return 1; } -int cdf_read_open(CDataFile *cdf, char *filename) +int cdf_read_open(CDataFile *cdf, const char *filename) { FILE *f; @@ -341,7 +341,7 @@ void cdf_read_close(CDataFile *cdf) } } -int cdf_write_open(CDataFile *cdf, char *filename) +int cdf_write_open(CDataFile *cdf, const char *filename) { CDataFileHeader *header; CDataFileImageHeader *image; @@ -405,14 +405,14 @@ void cdf_write_close(CDataFile *cdf) } } -void cdf_remove(char *filename) +void cdf_remove(const char *filename) { BLI_delete(filename, 0, 0); } /********************************** Layers ***********************************/ -CDataFileLayer *cdf_layer_find(CDataFile *cdf, int type, char *name) +CDataFileLayer *cdf_layer_find(CDataFile *cdf, int type, const char *name) { CDataFileLayer *layer; int a; @@ -427,7 +427,7 @@ CDataFileLayer *cdf_layer_find(CDataFile *cdf, int type, char *name) return NULL; } -CDataFileLayer *cdf_layer_add(CDataFile *cdf, int type, char *name, size_t datasize) +CDataFileLayer *cdf_layer_add(CDataFile *cdf, int type, const char *name, size_t datasize) { CDataFileLayer *newlayer, *layer; diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 474b3a5ce63..5ab997d2c54 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -184,7 +184,7 @@ FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *pro char *path; if(driven) - *driven = 0; + *driven = FALSE; /* only use the current action ??? */ if (ELEM(NULL, adt, adt->action)) @@ -205,7 +205,7 @@ FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *pro if ((fcu == NULL) && (adt->drivers.first)) { fcu= list_find_fcurve(&adt->drivers, path, index); if(fcu && driven) - *driven = 1; + *driven = TRUE; fcu = NULL; } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 47878242604..cef23ac3824 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -658,7 +658,9 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C return 0; } -void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3], int numVerts, char *vgroup, short defaxis) +void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, + DerivedMesh *dm, float (*vertexCos)[3], + int numVerts, const char *vgroup, short defaxis) { Curve *cu; int a, flag; @@ -817,7 +819,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, float *orco } void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, - float (*vertexCos)[3], int numVerts, char *vgroup) + float (*vertexCos)[3], int numVerts, const char *vgroup) { int a; int use_vgroups; diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index fa9d94eb24d..ae12ad8e66f 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2875,7 +2875,7 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid) BKE_ptcache_update_info(pid); } -void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to) +void BKE_ptcache_disk_cache_rename(PTCacheID *pid, const char *name_src, const char *name_dst) { char old_name[80]; int len; /* store the length of the string */ @@ -2892,7 +2892,7 @@ void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to) BLI_strncpy(old_name, pid->cache->name, sizeof(old_name)); /* get "from" filename */ - BLI_strncpy(pid->cache->name, from, sizeof(pid->cache->name)); + BLI_strncpy(pid->cache->name, name_src, sizeof(pid->cache->name)); len = ptcache_filename(pid, old_filename, 0, 0, 0); /* no path */ @@ -2906,7 +2906,7 @@ void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to) BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index); /* put new name into cache */ - BLI_strncpy(pid->cache->name, to, sizeof(pid->cache->name)); + BLI_strncpy(pid->cache->name, name_dst, sizeof(pid->cache->name)); while ((de = readdir(dir)) != NULL) { if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c index f9d470e48d8..d6c4b5f3a2e 100644 --- a/source/blender/blenkernel/intern/property.c +++ b/source/blender/blenkernel/intern/property.c @@ -200,7 +200,7 @@ void set_ob_property(Object *ob, bProperty *propc) /* negative: prop is smaller * positive: prop is larger */ -int compare_property(bProperty *prop, char *str) +int compare_property(bProperty *prop, const char *str) { // extern int Gdfra; /* sector.c */ float fvalue, ftest; @@ -237,7 +237,7 @@ int compare_property(bProperty *prop, char *str) return 0; } -void set_property(bProperty *prop, char *str) +void set_property(bProperty *prop, const char *str) { // extern int Gdfra; /* sector.c */ @@ -261,7 +261,7 @@ void set_property(bProperty *prop, char *str) } -void add_property(bProperty *prop, char *str) +void add_property(bProperty *prop, const char *str) { // extern int Gdfra; /* sector.c */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 6b319e6b5e1..9bde9374ab7 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3404,7 +3404,7 @@ void seq_offset_animdata(Scene *scene, Sequence *seq, int ofs) } } -void seq_dupe_animdata(Scene *scene, char *name_from, char *name_to) +void seq_dupe_animdata(Scene *scene, const char *name_src, const char *name_dst) { char str_from[32]; FCurve *fcu; @@ -3415,7 +3415,7 @@ void seq_dupe_animdata(Scene *scene, char *name_from, char *name_to) if(scene->adt==NULL || scene->adt->action==NULL) return; - sprintf(str_from, "[\"%s\"]", name_from); + sprintf(str_from, "[\"%s\"]", name_src); fcu_last= scene->adt->action->curves.last; @@ -3427,7 +3427,7 @@ void seq_dupe_animdata(Scene *scene, char *name_from, char *name_to) } /* notice validate is 0, keep this because the seq may not be added to the scene yet */ - BKE_animdata_fix_paths_rename(&scene->id, scene->adt, "sequence_editor.sequences_all", name_from, name_to, 0, 0, 0); + BKE_animdata_fix_paths_rename(&scene->id, scene->adt, "sequence_editor.sequences_all", name_src, name_dst, 0, 0, 0); /* add the original fcurves back */ BLI_movelisttolist(&scene->adt->action->curves, &lb); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 69af2570d0c..955127a8000 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1234,7 +1234,7 @@ char *txt_to_buf (Text *text) return buf; } -int txt_find_string(Text *text, char *findstr, int wrap, int match_case) +int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) { TextLine *tl, *startl; char *s= NULL; diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 01b090f2967..616c27f6b0b 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -426,9 +426,9 @@ void bUnit_AsString(char *str, int len_max, double value, int prec, int system, } -static char *unit_find_str(char *str, const char *substr) +static const char *unit_find_str(const char *str, const char *substr) { - char *str_found; + const char *str_found; if(substr && substr[0] != '\0') { str_found= strstr(str, substr); @@ -485,7 +485,7 @@ static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pr { char *str_found; - if((len_max>0) && (str_found= unit_find_str(str, replace_str))) { /* XXX - investigate, does not respect len_max properly */ + if((len_max>0) && (str_found= (char *)unit_find_str(str, replace_str))) { /* XXX - investigate, does not respect len_max properly */ int len, len_num, len_name, len_move, found_ofs; found_ofs = (int)(str_found-str); @@ -537,7 +537,7 @@ static int unit_replace(char *str, int len_max, char *str_tmp, double scale_pref return ofs; } -static int unit_find(char *str, bUnitDef *unit) +static int unit_find(const char *str, bUnitDef *unit) { if (unit_find_str(str, unit->name_short)) return 1; if (unit_find_str(str, unit->name_plural)) return 1; @@ -562,7 +562,7 @@ static int unit_find(char *str, bUnitDef *unit) * * return true of a change was made. */ -int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pref, int system, int type) +int bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type) { bUnitCollection *usys = unit_get_system(system, type); @@ -676,7 +676,7 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre } /* 45µm --> 45um */ -void bUnit_ToUnitAltName(char *str, int len_max, char *orig_str, int system, int type) +void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type) { bUnitCollection *usys = unit_get_system(system, type); @@ -687,9 +687,7 @@ void bUnit_ToUnitAltName(char *str, int len_max, char *orig_str, int system, int for(unit= usys->units; unit->name; unit++) { if(len_max > 0 && (unit->name_alt || unit == unit_def)) { - char *found= NULL; - - found= unit_find_str(orig_str, unit->name_short); + const char *found= unit_find_str(orig_str, unit->name_short); if(found) { int offset= (int)(found - orig_str); int len_name= 0; diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index da1412dac0d..2646f5164b2 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1046,7 +1046,7 @@ void ffmpeg_property_del(RenderData *rd, void *type, void *prop_) } } -IDProperty *ffmpeg_property_add(RenderData *rd, char * type, int opt_index, int parent_index) +IDProperty *ffmpeg_property_add(RenderData *rd, const char *type, int opt_index, int parent_index) { AVCodecContext c; const AVOption * o; -- cgit v1.2.3 From 98841291173614410fca3b9db1cd0ee320d9eb84 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 5 Nov 2011 13:00:39 +0000 Subject: Code refactoring: split camera functions from object.c into new camera.c. --- source/blender/blenkernel/intern/camera.c | 394 +++++++++++++++++++++++++++++ source/blender/blenkernel/intern/library.c | 1 + source/blender/blenkernel/intern/object.c | 352 +------------------------- 3 files changed, 396 insertions(+), 351 deletions(-) create mode 100644 source/blender/blenkernel/intern/camera.c (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c new file mode 100644 index 00000000000..74cc5a76a75 --- /dev/null +++ b/source/blender/blenkernel/intern/camera.c @@ -0,0 +1,394 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/camera.c + * \ingroup bke + */ + +#include "DNA_camera_types.h" +#include "DNA_lamp_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "BKE_animsys.h" +#include "BKE_camera.h" +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_main.h" + +void *add_camera(const char *name) +{ + Camera *cam; + + cam= alloc_libblock(&G.main->camera, ID_CA, name); + + cam->lens= 35.0f; + cam->sensor_x= 32.0f; + cam->sensor_y= 18.0f; + cam->clipsta= 0.1f; + cam->clipend= 100.0f; + cam->drawsize= 0.5f; + cam->ortho_scale= 6.0; + cam->flag |= CAM_SHOWPASSEPARTOUT; + cam->passepartalpha = 0.5f; + + return cam; +} + +Camera *copy_camera(Camera *cam) +{ + Camera *camn; + + camn= copy_libblock(cam); + + return camn; +} + +void make_local_camera(Camera *cam) +{ + Main *bmain= G.main; + Object *ob; + int is_local= FALSE, is_lib= FALSE; + + /* - only lib users: do nothing + * - only local users: set flag + * - mixed: make copy + */ + + if(cam->id.lib==NULL) return; + if(cam->id.us==1) { + id_clear_lib_data(bmain, &cam->id); + return; + } + + for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { + if(ob->data==cam) { + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; + } + } + + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &cam->id); + } + else if(is_local && is_lib) { + Camera *camn= copy_camera(cam); + + camn->id.us= 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &camn->id); + + for(ob= bmain->object.first; ob; ob= ob->id.next) { + if(ob->data == cam) { + if(ob->id.lib==NULL) { + ob->data= camn; + camn->id.us++; + cam->id.us--; + } + } + } + } +} + +/* get the camera's dof value, takes the dof object into account */ +float dof_camera(Object *ob) +{ + Camera *cam = (Camera *)ob->data; + if (ob->type != OB_CAMERA) + return 0.0f; + if (cam->dof_ob) { + /* too simple, better to return the distance on the view axis only + * return len_v3v3(ob->obmat[3], cam->dof_ob->obmat[3]); */ + float mat[4][4], imat[4][4], obmat[4][4]; + + copy_m4_m4(obmat, ob->obmat); + normalize_m4(obmat); + invert_m4_m4(imat, obmat); + mul_m4_m4m4(mat, cam->dof_ob->obmat, imat); + return (float)fabs(mat[3][2]); + } + return cam->YF_dofdist; +} + +void free_camera(Camera *ca) +{ + BKE_free_animdata((ID *)ca); +} + +void object_camera_mode(RenderData *rd, Object *camera) +{ + rd->mode &= ~(R_ORTHO|R_PANORAMA); + if(camera && camera->type==OB_CAMERA) { + Camera *cam= camera->data; + if(cam->type == CAM_ORTHO) rd->mode |= R_ORTHO; + if(cam->flag & CAM_PANORAMA) rd->mode |= R_PANORAMA; + } +} + +void object_camera_intrinsics(Object *camera, Camera **cam_r, short *is_ortho, float *shiftx, float *shifty, + float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit) +{ + Camera *cam= NULL; + + (*shiftx)= 0.0f; + (*shifty)= 0.0f; + + (*sensor_x)= DEFAULT_SENSOR_WIDTH; + (*sensor_y)= DEFAULT_SENSOR_HEIGHT; + (*sensor_fit)= CAMERA_SENSOR_FIT_AUTO; + + if(camera->type==OB_CAMERA) { + cam= camera->data; + + if(cam->type == CAM_ORTHO) { + *is_ortho= TRUE; + } + + /* solve this too... all time depending stuff is in convertblender.c? + * Need to update the camera early because it's used for projection matrices + * and other stuff BEFORE the animation update loop is done + * */ +#if 0 // XXX old animation system + if(cam->ipo) { + calc_ipo(cam->ipo, frame_to_float(re->scene, re->r.cfra)); + execute_ipo(&cam->id, cam->ipo); + } +#endif // XXX old animation system + (*shiftx)=cam->shiftx; + (*shifty)=cam->shifty; + (*lens)= cam->lens; + (*sensor_x)= cam->sensor_x; + (*sensor_y)= cam->sensor_y; + (*clipsta)= cam->clipsta; + (*clipend)= cam->clipend; + (*sensor_fit)= cam->sensor_fit; + } + else if(camera->type==OB_LAMP) { + Lamp *la= camera->data; + float fac= cosf((float)M_PI*la->spotsize/360.0f); + float phi= acos(fac); + + (*lens)= 16.0f*fac/sinf(phi); + if((*lens)==0.0f) + (*lens)= 35.0f; + (*clipsta)= la->clipsta; + (*clipend)= la->clipend; + } + else { /* envmap exception... */; + if((*lens)==0.0f) /* is this needed anymore? */ + (*lens)= 16.0f; + + if((*clipsta)==0.0f || (*clipend)==0.0f) { + (*clipsta)= 0.1f; + (*clipend)= 1000.0f; + } + } + + (*cam_r)= cam; +} + +/* 'lens' may be set for envmap only */ +void object_camera_matrix( + RenderData *rd, Object *camera, int winx, int winy, short field_second, + float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, + float *sensor_x, float *sensor_y, short *sensor_fit, float *ycor, + float *viewdx, float *viewdy) +{ + Camera *cam=NULL; + float pixsize; + float shiftx=0.0, shifty=0.0, winside, viewfac; + short is_ortho= FALSE; + + /* question mark */ + (*ycor)= rd->yasp / rd->xasp; + if(rd->mode & R_FIELDS) + (*ycor) *= 2.0f; + + object_camera_intrinsics(camera, &cam, &is_ortho, &shiftx, &shifty, clipsta, clipend, lens, sensor_x, sensor_y, sensor_fit); + + /* ortho only with camera available */ + if(cam && is_ortho) { + if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { + if(rd->xasp*winx >= rd->yasp*winy) viewfac= winx; + else viewfac= (*ycor) * winy; + } + else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { + viewfac= winx; + } + else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ + viewfac= (*ycor) * winy; + } + + /* ortho_scale == 1.0 means exact 1 to 1 mapping */ + pixsize= cam->ortho_scale/viewfac; + } + else { + if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { + if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx) / (*sensor_x); + else viewfac= (*ycor) * ((*lens) * winy) / (*sensor_x); + } + else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { + viewfac= ((*lens) * winx) / (*sensor_x); + } + else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ + viewfac= ((*lens) * winy) / (*sensor_y); + } + + pixsize= (*clipsta) / viewfac; + } + + /* viewplane fully centered, zbuffer fills in jittered between -.5 and +.5 */ + winside= MAX2(winx, winy); + + if(cam) { + if(cam->sensor_fit==CAMERA_SENSOR_FIT_HOR) + winside= winx; + else if(cam->sensor_fit==CAMERA_SENSOR_FIT_VERT) + winside= winy; + } + + viewplane->xmin= -0.5f*(float)winx + shiftx*winside; + viewplane->ymin= -0.5f*(*ycor)*(float)winy + shifty*winside; + viewplane->xmax= 0.5f*(float)winx + shiftx*winside; + viewplane->ymax= 0.5f*(*ycor)*(float)winy + shifty*winside; + + if(field_second) { + if(rd->mode & R_ODDFIELD) { + viewplane->ymin-= 0.5f * (*ycor); + viewplane->ymax-= 0.5f * (*ycor); + } + else { + viewplane->ymin+= 0.5f * (*ycor); + viewplane->ymax+= 0.5f * (*ycor); + } + } + /* the window matrix is used for clipping, and not changed during OSA steps */ + /* using an offset of +0.5 here would give clip errors on edges */ + viewplane->xmin *= pixsize; + viewplane->xmax *= pixsize; + viewplane->ymin *= pixsize; + viewplane->ymax *= pixsize; + + (*viewdx)= pixsize; + (*viewdy)= (*ycor) * pixsize; + + if(is_ortho) + orthographic_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend); + else + perspective_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend); + +} + +void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const short do_clip, const float scale[3], + float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3]) +{ + float facx, facy; + float depth; + + /* aspect correcton */ + if (scene) { + float aspx= (float) scene->r.xsch*scene->r.xasp; + float aspy= (float) scene->r.ysch*scene->r.yasp; + + if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { + if(aspx < aspy) { + r_asp[0]= aspx / aspy; + r_asp[1]= 1.0; + } + else { + r_asp[0]= 1.0; + r_asp[1]= aspy / aspx; + } + } + else if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { + r_asp[0]= aspx / aspy; + r_asp[1]= 1.0; + } + else { + r_asp[0]= 1.0; + r_asp[1]= aspy / aspx; + } + } + else { + r_asp[0]= 1.0f; + r_asp[1]= 1.0f; + } + + if(camera->type==CAM_ORTHO) { + facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; + facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; + r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0]; + r_shift[1]= camera->shifty * camera->ortho_scale * scale[1]; + depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2]; + + *r_drawsize= 0.5f * camera->ortho_scale; + } + else { + /* that way it's always visible - clipsta+0.1 */ + float fac; + float half_sensor= 0.5f*((camera->sensor_fit==CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); + + *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); + + if(do_clip) { + /* fixed depth, variable size (avoids exceeding clipping range) */ + depth = -(camera->clipsta + 0.1f); + fac = depth / (camera->lens/(-half_sensor) * scale[2]); + } + else { + /* fixed size, variable depth (stays a reasonable size in the 3D view) */ + depth= *r_drawsize * camera->lens/(-half_sensor) * scale[2]; + fac= *r_drawsize; + } + + facx= fac * r_asp[0] * scale[0]; + facy= fac * r_asp[1] * scale[1]; + r_shift[0]= camera->shiftx*fac*2 * scale[0]; + r_shift[1]= camera->shifty*fac*2 * scale[1]; + } + + r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth; + r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth; + r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth; + r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth; +} + +void camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) +{ + float dummy_asp[2]; + float dummy_shift[2]; + float dummy_drawsize; + const float dummy_scale[3]= {1.0f, 1.0f, 1.0f}; + + camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale, + dummy_asp, dummy_shift, &dummy_drawsize, r_vec); +} + diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 35b50730a31..36e2428ce24 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -77,6 +77,7 @@ #include "BLI_bpath.h" #include "BKE_animsys.h" +#include "BKE_camera.h" #include "BKE_context.h" #include "BKE_library.h" #include "BKE_main.h" diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index b09d1ea98aa..1ba06c02976 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -98,6 +98,7 @@ #include "BKE_speaker.h" #include "BKE_softbody.h" #include "BKE_material.h" +#include "BKE_camera.h" #include "LBM_fluidsim.h" @@ -715,103 +716,6 @@ int exist_object(Object *obtest) return 0; } -void *add_camera(const char *name) -{ - Camera *cam; - - cam= alloc_libblock(&G.main->camera, ID_CA, name); - - cam->lens= 35.0f; - cam->sensor_x= 32.0f; - cam->sensor_y= 18.0f; - cam->clipsta= 0.1f; - cam->clipend= 100.0f; - cam->drawsize= 0.5f; - cam->ortho_scale= 6.0; - cam->flag |= CAM_SHOWPASSEPARTOUT; - cam->passepartalpha = 0.5f; - - return cam; -} - -Camera *copy_camera(Camera *cam) -{ - Camera *camn; - - camn= copy_libblock(cam); - - return camn; -} - - - -void make_local_camera(Camera *cam) -{ - Main *bmain= G.main; - Object *ob; - int is_local= FALSE, is_lib= FALSE; - - /* - only lib users: do nothing - * - only local users: set flag - * - mixed: make copy - */ - - if(cam->id.lib==NULL) return; - if(cam->id.us==1) { - id_clear_lib_data(bmain, &cam->id); - return; - } - - for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) { - if(ob->data==cam) { - if(ob->id.lib) is_lib= TRUE; - else is_local= TRUE; - } - } - - if(is_local && is_lib == FALSE) { - id_clear_lib_data(bmain, &cam->id); - } - else if(is_local && is_lib) { - Camera *camn= copy_camera(cam); - - camn->id.us= 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, &camn->id); - - for(ob= bmain->object.first; ob; ob= ob->id.next) { - if(ob->data == cam) { - if(ob->id.lib==NULL) { - ob->data= camn; - camn->id.us++; - cam->id.us--; - } - } - } - } -} - -/* get the camera's dof value, takes the dof object into account */ -float dof_camera(Object *ob) -{ - Camera *cam = (Camera *)ob->data; - if (ob->type != OB_CAMERA) - return 0.0f; - if (cam->dof_ob) { - /* too simple, better to return the distance on the view axis only - * return len_v3v3(ob->obmat[3], cam->dof_ob->obmat[3]); */ - float mat[4][4], imat[4][4], obmat[4][4]; - - copy_m4_m4(obmat, ob->obmat); - normalize_m4(obmat); - invert_m4_m4(imat, obmat); - mul_m4_m4m4(mat, cam->dof_ob->obmat, imat); - return (float)fabs(mat[3][2]); - } - return cam->YF_dofdist; -} - void *add_lamp(const char *name) { Lamp *la; @@ -966,11 +870,6 @@ void make_local_lamp(Lamp *la) } } -void free_camera(Camera *ca) -{ - BKE_free_animdata((ID *)ca); -} - void free_lamp(Lamp *la) { MTex *mtex; @@ -2942,255 +2841,6 @@ int object_insert_ptcache(Object *ob) return i; } -void object_camera_mode(RenderData *rd, Object *camera) -{ - rd->mode &= ~(R_ORTHO|R_PANORAMA); - if(camera && camera->type==OB_CAMERA) { - Camera *cam= camera->data; - if(cam->type == CAM_ORTHO) rd->mode |= R_ORTHO; - if(cam->flag & CAM_PANORAMA) rd->mode |= R_PANORAMA; - } -} - -void object_camera_intrinsics(Object *camera, Camera **cam_r, short *is_ortho, float *shiftx, float *shifty, - float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit) -{ - Camera *cam= NULL; - - (*shiftx)= 0.0f; - (*shifty)= 0.0f; - - (*sensor_x)= DEFAULT_SENSOR_WIDTH; - (*sensor_y)= DEFAULT_SENSOR_HEIGHT; - (*sensor_fit)= CAMERA_SENSOR_FIT_AUTO; - - if(camera->type==OB_CAMERA) { - cam= camera->data; - - if(cam->type == CAM_ORTHO) { - *is_ortho= TRUE; - } - - /* solve this too... all time depending stuff is in convertblender.c? - * Need to update the camera early because it's used for projection matrices - * and other stuff BEFORE the animation update loop is done - * */ -#if 0 // XXX old animation system - if(cam->ipo) { - calc_ipo(cam->ipo, frame_to_float(re->scene, re->r.cfra)); - execute_ipo(&cam->id, cam->ipo); - } -#endif // XXX old animation system - (*shiftx)=cam->shiftx; - (*shifty)=cam->shifty; - (*lens)= cam->lens; - (*sensor_x)= cam->sensor_x; - (*sensor_y)= cam->sensor_y; - (*clipsta)= cam->clipsta; - (*clipend)= cam->clipend; - (*sensor_fit)= cam->sensor_fit; - } - else if(camera->type==OB_LAMP) { - Lamp *la= camera->data; - float fac= cosf((float)M_PI*la->spotsize/360.0f); - float phi= acos(fac); - - (*lens)= 16.0f*fac/sinf(phi); - if((*lens)==0.0f) - (*lens)= 35.0f; - (*clipsta)= la->clipsta; - (*clipend)= la->clipend; - } - else { /* envmap exception... */; - if((*lens)==0.0f) /* is this needed anymore? */ - (*lens)= 16.0f; - - if((*clipsta)==0.0f || (*clipend)==0.0f) { - (*clipsta)= 0.1f; - (*clipend)= 1000.0f; - } - } - - (*cam_r)= cam; -} - -/* 'lens' may be set for envmap only */ -void object_camera_matrix( - RenderData *rd, Object *camera, int winx, int winy, short field_second, - float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, - float *sensor_x, float *sensor_y, short *sensor_fit, float *ycor, - float *viewdx, float *viewdy) -{ - Camera *cam=NULL; - float pixsize; - float shiftx=0.0, shifty=0.0, winside, viewfac; - short is_ortho= FALSE; - - /* question mark */ - (*ycor)= rd->yasp / rd->xasp; - if(rd->mode & R_FIELDS) - (*ycor) *= 2.0f; - - object_camera_intrinsics(camera, &cam, &is_ortho, &shiftx, &shifty, clipsta, clipend, lens, sensor_x, sensor_y, sensor_fit); - - /* ortho only with camera available */ - if(cam && is_ortho) { - if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { - if(rd->xasp*winx >= rd->yasp*winy) viewfac= winx; - else viewfac= (*ycor) * winy; - } - else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { - viewfac= winx; - } - else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ - viewfac= (*ycor) * winy; - } - - /* ortho_scale == 1.0 means exact 1 to 1 mapping */ - pixsize= cam->ortho_scale/viewfac; - } - else { - if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { - if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx) / (*sensor_x); - else viewfac= (*ycor) * ((*lens) * winy) / (*sensor_x); - } - else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { - viewfac= ((*lens) * winx) / (*sensor_x); - } - else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ - viewfac= ((*lens) * winy) / (*sensor_y); - } - - pixsize= (*clipsta) / viewfac; - } - - /* viewplane fully centered, zbuffer fills in jittered between -.5 and +.5 */ - winside= MAX2(winx, winy); - - if(cam) { - if(cam->sensor_fit==CAMERA_SENSOR_FIT_HOR) - winside= winx; - else if(cam->sensor_fit==CAMERA_SENSOR_FIT_VERT) - winside= winy; - } - - viewplane->xmin= -0.5f*(float)winx + shiftx*winside; - viewplane->ymin= -0.5f*(*ycor)*(float)winy + shifty*winside; - viewplane->xmax= 0.5f*(float)winx + shiftx*winside; - viewplane->ymax= 0.5f*(*ycor)*(float)winy + shifty*winside; - - if(field_second) { - if(rd->mode & R_ODDFIELD) { - viewplane->ymin-= 0.5f * (*ycor); - viewplane->ymax-= 0.5f * (*ycor); - } - else { - viewplane->ymin+= 0.5f * (*ycor); - viewplane->ymax+= 0.5f * (*ycor); - } - } - /* the window matrix is used for clipping, and not changed during OSA steps */ - /* using an offset of +0.5 here would give clip errors on edges */ - viewplane->xmin *= pixsize; - viewplane->xmax *= pixsize; - viewplane->ymin *= pixsize; - viewplane->ymax *= pixsize; - - (*viewdx)= pixsize; - (*viewdy)= (*ycor) * pixsize; - - if(is_ortho) - orthographic_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend); - else - perspective_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend); - -} - -void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const short do_clip, const float scale[3], - float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3]) -{ - float facx, facy; - float depth; - - /* aspect correcton */ - if (scene) { - float aspx= (float) scene->r.xsch*scene->r.xasp; - float aspy= (float) scene->r.ysch*scene->r.yasp; - - if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { - if(aspx < aspy) { - r_asp[0]= aspx / aspy; - r_asp[1]= 1.0; - } - else { - r_asp[0]= 1.0; - r_asp[1]= aspy / aspx; - } - } - else if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { - r_asp[0]= aspx / aspy; - r_asp[1]= 1.0; - } - else { - r_asp[0]= 1.0; - r_asp[1]= aspy / aspx; - } - } - else { - r_asp[0]= 1.0f; - r_asp[1]= 1.0f; - } - - if(camera->type==CAM_ORTHO) { - facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; - facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0]; - r_shift[1]= camera->shifty * camera->ortho_scale * scale[1]; - depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2]; - - *r_drawsize= 0.5f * camera->ortho_scale; - } - else { - /* that way it's always visible - clipsta+0.1 */ - float fac; - float half_sensor= 0.5f*((camera->sensor_fit==CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); - - *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); - - if(do_clip) { - /* fixed depth, variable size (avoids exceeding clipping range) */ - depth = -(camera->clipsta + 0.1f); - fac = depth / (camera->lens/(-half_sensor) * scale[2]); - } - else { - /* fixed size, variable depth (stays a reasonable size in the 3D view) */ - depth= *r_drawsize * camera->lens/(-half_sensor) * scale[2]; - fac= *r_drawsize; - } - - facx= fac * r_asp[0] * scale[0]; - facy= fac * r_asp[1] * scale[1]; - r_shift[0]= camera->shiftx*fac*2 * scale[0]; - r_shift[1]= camera->shifty*fac*2 * scale[1]; - } - - r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth; - r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth; - r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth; - r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth; -} - -void camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) -{ - float dummy_asp[2]; - float dummy_shift[2]; - float dummy_drawsize; - const float dummy_scale[3]= {1.0f, 1.0f, 1.0f}; - - camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale, - dummy_asp, dummy_shift, &dummy_drawsize, r_vec); -} - #if 0 static int pc_findindex(ListBase *listbase, int index) { -- cgit v1.2.3 From 647447db58ed7d3abd0ddeb627110069042e28fe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 5 Nov 2011 13:11:49 +0000 Subject: Code refactoring: split lamp functions from object.c into new lamp.c. --- source/blender/blenkernel/intern/camera.c | 2 + source/blender/blenkernel/intern/lamp.c | 233 +++++++++++++++++++++++++++++ source/blender/blenkernel/intern/library.c | 1 + source/blender/blenkernel/intern/object.c | 182 +--------------------- 4 files changed, 237 insertions(+), 181 deletions(-) create mode 100644 source/blender/blenkernel/intern/lamp.c (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 74cc5a76a75..eeec82c3beb 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -29,6 +29,8 @@ * \ingroup bke */ +#include + #include "DNA_camera_types.h" #include "DNA_lamp_types.h" #include "DNA_object_types.h" diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c new file mode 100644 index 00000000000..974aa660e9f --- /dev/null +++ b/source/blender/blenkernel/intern/lamp.c @@ -0,0 +1,233 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/lamp.c + * \ingroup bke + */ + +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_object_types.h" +#include "DNA_texture_types.h" + +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "BKE_animsys.h" +#include "BKE_colortools.h" +#include "BKE_icons.h" +#include "BKE_global.h" +#include "BKE_lamp.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_node.h" + +void *add_lamp(const char *name) +{ + Lamp *la; + + la= alloc_libblock(&G.main->lamp, ID_LA, name); + + la->r= la->g= la->b= la->k= 1.0f; + la->haint= la->energy= 1.0f; + la->dist= 25.0f; + la->spotsize= 45.0f; + la->spotblend= 0.15f; + la->att2= 1.0f; + la->mode= LA_SHAD_BUF; + la->bufsize= 512; + la->clipsta= 0.5f; + la->clipend= 40.0f; + la->shadspotsize= 45.0f; + la->samp= 3; + la->bias= 1.0f; + la->soft= 3.0f; + la->compressthresh= 0.05f; + la->ray_samp= la->ray_sampy= la->ray_sampz= 1; + la->area_size=la->area_sizey=la->area_sizez= 1.0f; + la->buffers= 1; + la->buftype= LA_SHADBUF_HALFWAY; + la->ray_samp_method = LA_SAMP_HALTON; + la->adapt_thresh = 0.001f; + la->preview=NULL; + la->falloff_type = LA_FALLOFF_INVSQUARE; + la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); + la->sun_effect_type = 0; + la->horizon_brightness = 1.0; + la->spread = 1.0; + la->sun_brightness = 1.0; + la->sun_size = 1.0; + la->backscattered_light = 1.0f; + la->atm_turbidity = 2.0f; + la->atm_inscattering_factor = 1.0f; + la->atm_extinction_factor = 1.0f; + la->atm_distance_factor = 1.0f; + la->sun_intensity = 1.0f; + la->skyblendtype= MA_RAMP_ADD; + la->skyblendfac= 1.0f; + la->sky_colorspace= BLI_XYZ_CIE; + la->sky_exposure= 1.0f; + + curvemapping_initialize(la->curfalloff); + return la; +} + +Lamp *copy_lamp(Lamp *la) +{ + Lamp *lan; + int a; + + lan= copy_libblock(la); + + for(a=0; amtex[a]) { + lan->mtex[a]= MEM_mallocN(sizeof(MTex), "copylamptex"); + memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); + id_us_plus((ID *)lan->mtex[a]->tex); + } + } + + lan->curfalloff = curvemapping_copy(la->curfalloff); + + if(la->nodetree) + lan->nodetree= ntreeCopyTree(la->nodetree); + + if(la->preview) + lan->preview = BKE_previewimg_copy(la->preview); + + return lan; +} + +Lamp *localize_lamp(Lamp *la) +{ + Lamp *lan; + int a; + + lan= copy_libblock(la); + BLI_remlink(&G.main->lamp, lan); + + for(a=0; amtex[a]) { + lan->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_lamp"); + memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); + /* free lamp decrements */ + id_us_plus((ID *)lan->mtex[a]->tex); + } + } + + lan->curfalloff = curvemapping_copy(la->curfalloff); + + if(la->nodetree) + lan->nodetree= ntreeLocalize(la->nodetree); + + lan->preview= NULL; + + return lan; +} + +void make_local_lamp(Lamp *la) +{ + Main *bmain= G.main; + Object *ob; + int is_local= FALSE, is_lib= FALSE; + + /* - only lib users: do nothing + * - only local users: set flag + * - mixed: make copy + */ + + if(la->id.lib==NULL) return; + if(la->id.us==1) { + id_clear_lib_data(bmain, &la->id); + return; + } + + ob= bmain->object.first; + while(ob) { + if(ob->data==la) { + if(ob->id.lib) is_lib= TRUE; + else is_local= TRUE; + } + ob= ob->id.next; + } + + if(is_local && is_lib == FALSE) { + id_clear_lib_data(bmain, &la->id); + } + else if(is_local && is_lib) { + Lamp *lan= copy_lamp(la); + lan->id.us= 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, &lan->id); + + ob= bmain->object.first; + while(ob) { + if(ob->data==la) { + + if(ob->id.lib==NULL) { + ob->data= lan; + lan->id.us++; + la->id.us--; + } + } + ob= ob->id.next; + } + } +} + +void free_lamp(Lamp *la) +{ + MTex *mtex; + int a; + + for(a=0; amtex[a]; + if(mtex && mtex->tex) mtex->tex->id.us--; + if(mtex) MEM_freeN(mtex); + } + + BKE_free_animdata((ID *)la); + + curvemapping_free(la->curfalloff); + + /* is no lib link block, but lamp extension */ + if(la->nodetree) { + ntreeFreeTree(la->nodetree); + MEM_freeN(la->nodetree); + } + + BKE_previewimg_free(&la->preview); + BKE_icon_delete(&la->id); + la->id.icon_id = 0; +} + diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 36e2428ce24..0b01c3d6dd1 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -79,6 +79,7 @@ #include "BKE_animsys.h" #include "BKE_camera.h" #include "BKE_context.h" +#include "BKE_lamp.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 1ba06c02976..a78b010392e 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -42,7 +42,6 @@ #include "DNA_constraint_types.h" #include "DNA_group_types.h" #include "DNA_key_types.h" -#include "DNA_lamp_types.h" #include "DNA_lattice_types.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" @@ -81,6 +80,7 @@ #include "BKE_group.h" #include "BKE_icons.h" #include "BKE_key.h" +#include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" #include "BKE_mesh.h" @@ -716,186 +716,6 @@ int exist_object(Object *obtest) return 0; } -void *add_lamp(const char *name) -{ - Lamp *la; - - la= alloc_libblock(&G.main->lamp, ID_LA, name); - - la->r= la->g= la->b= la->k= 1.0f; - la->haint= la->energy= 1.0f; - la->dist= 25.0f; - la->spotsize= 45.0f; - la->spotblend= 0.15f; - la->att2= 1.0f; - la->mode= LA_SHAD_BUF; - la->bufsize= 512; - la->clipsta= 0.5f; - la->clipend= 40.0f; - la->shadspotsize= 45.0f; - la->samp= 3; - la->bias= 1.0f; - la->soft= 3.0f; - la->compressthresh= 0.05f; - la->ray_samp= la->ray_sampy= la->ray_sampz= 1; - la->area_size=la->area_sizey=la->area_sizez= 1.0f; - la->buffers= 1; - la->buftype= LA_SHADBUF_HALFWAY; - la->ray_samp_method = LA_SAMP_HALTON; - la->adapt_thresh = 0.001f; - la->preview=NULL; - la->falloff_type = LA_FALLOFF_INVSQUARE; - la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); - la->sun_effect_type = 0; - la->horizon_brightness = 1.0; - la->spread = 1.0; - la->sun_brightness = 1.0; - la->sun_size = 1.0; - la->backscattered_light = 1.0f; - la->atm_turbidity = 2.0f; - la->atm_inscattering_factor = 1.0f; - la->atm_extinction_factor = 1.0f; - la->atm_distance_factor = 1.0f; - la->sun_intensity = 1.0f; - la->skyblendtype= MA_RAMP_ADD; - la->skyblendfac= 1.0f; - la->sky_colorspace= BLI_XYZ_CIE; - la->sky_exposure= 1.0f; - - curvemapping_initialize(la->curfalloff); - return la; -} - -Lamp *copy_lamp(Lamp *la) -{ - Lamp *lan; - int a; - - lan= copy_libblock(la); - - for(a=0; amtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "copylamptex"); - memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); - id_us_plus((ID *)lan->mtex[a]->tex); - } - } - - lan->curfalloff = curvemapping_copy(la->curfalloff); - - if(la->nodetree) - lan->nodetree= ntreeCopyTree(la->nodetree); - - if(la->preview) - lan->preview = BKE_previewimg_copy(la->preview); - - return lan; -} - -Lamp *localize_lamp(Lamp *la) -{ - Lamp *lan; - int a; - - lan= copy_libblock(la); - BLI_remlink(&G.main->lamp, lan); - - for(a=0; amtex[a]) { - lan->mtex[a]= MEM_mallocN(sizeof(MTex), "localize_lamp"); - memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex)); - /* free lamp decrements */ - id_us_plus((ID *)lan->mtex[a]->tex); - } - } - - lan->curfalloff = curvemapping_copy(la->curfalloff); - - if(la->nodetree) - lan->nodetree= ntreeLocalize(la->nodetree); - - lan->preview= NULL; - - return lan; -} - -void make_local_lamp(Lamp *la) -{ - Main *bmain= G.main; - Object *ob; - int is_local= FALSE, is_lib= FALSE; - - /* - only lib users: do nothing - * - only local users: set flag - * - mixed: make copy - */ - - if(la->id.lib==NULL) return; - if(la->id.us==1) { - id_clear_lib_data(bmain, &la->id); - return; - } - - ob= bmain->object.first; - while(ob) { - if(ob->data==la) { - if(ob->id.lib) is_lib= TRUE; - else is_local= TRUE; - } - ob= ob->id.next; - } - - if(is_local && is_lib == FALSE) { - id_clear_lib_data(bmain, &la->id); - } - else if(is_local && is_lib) { - Lamp *lan= copy_lamp(la); - lan->id.us= 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, &lan->id); - - ob= bmain->object.first; - while(ob) { - if(ob->data==la) { - - if(ob->id.lib==NULL) { - ob->data= lan; - lan->id.us++; - la->id.us--; - } - } - ob= ob->id.next; - } - } -} - -void free_lamp(Lamp *la) -{ - MTex *mtex; - int a; - - for(a=0; amtex[a]; - if(mtex && mtex->tex) mtex->tex->id.us--; - if(mtex) MEM_freeN(mtex); - } - - BKE_free_animdata((ID *)la); - - curvemapping_free(la->curfalloff); - - /* is no lib link block, but lamp extension */ - if(la->nodetree) { - ntreeFreeTree(la->nodetree); - MEM_freeN(la->nodetree); - } - - BKE_previewimg_free(&la->preview); - BKE_icon_delete(&la->id); - la->id.icon_id = 0; -} - /* *************************************************** */ static void *add_obdata_from_type(int type) -- cgit v1.2.3 From 2a7ade9de24860bbd13e4be8480e9285d1f3fe4c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 5 Nov 2011 14:26:18 +0000 Subject: remove po/ since the workflow for translations uses branches which isnt that useful to have within blenders source dir. For now treat translations as binary files - just access from 'release/datafiles/locale' --- source/blender/blenkernel/intern/scene.c | 2 ++ source/blender/blenkernel/intern/sequencer.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a9de75dc7d0..f1e094c3909 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -806,6 +806,8 @@ int scene_camera_switch_update(Scene *scene) scene->camera= camera; return 1; } +#else + (void)scene; #endif return 0; } diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 9bde9374ab7..3e9b570d104 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1980,6 +1980,8 @@ static ImBuf * seq_render_scene_strip_impl( /* stooping to new low's in hackyness :( */ oldmarkers= scene->markers; scene->markers.first= scene->markers.last= NULL; +#else + (void)oldmarkers; #endif if(sequencer_view3d_cb && BLI_thread_is_main() && doseq_gl && (scene == context.scene || have_seq==0) && camera) { -- cgit v1.2.3 From 440c1c2c1745b6d4acd13f405643100cb913fb3b Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 6 Nov 2011 05:46:45 +0000 Subject: As discussed on the mailing list, removing the non-functional, incompatible, and unmaintainable Time Offset cruft. - Slow Parenting lives another day (just), although it now carries appropriate cautionary disclaimers. It's only really for the Game Engine nowadays, as that's the only place where it can possibly work with any reliability. - "Animation Hacks" panel is now "Relations Extras". I could've merged the two panels, though I figured these options weren't that frequently used to justify taking up screen-space by default along with the panel --- source/blender/blenkernel/intern/group.c | 8 ++--- source/blender/blenkernel/intern/object.c | 46 ++++++--------------------- source/blender/blenkernel/intern/pointcache.c | 2 +- 3 files changed, 15 insertions(+), 41 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index cd025ecb559..76c3e6e5502 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -276,8 +276,9 @@ void group_tag_recalc(Group *group) int group_is_animated(Object *parent, Group *group) { GroupObject *go; - - if(give_timeoffset(parent) != 0.0f || parent->nlastrips.first) + + // XXX: old animsys depreceated... + if(parent->nlastrips.first) return 1; for(go= group->gobject.first; go; go= go->next) @@ -343,12 +344,11 @@ void group_handle_recalc_and_update(Scene *scene, Object *UNUSED(parent), Group * but when its enabled at some point it will need to be changed so as not to update so much - campbell */ /* if animated group... */ - if(give_timeoffset(parent) != 0.0f || parent->nlastrips.first) { + if(parent->nlastrips.first) { int cfrao; /* switch to local time */ cfrao= scene->r.cfra; - scene->r.cfra -= (int)floor(give_timeoffset(parent) + 0.5f); /* we need a DAG per group... */ for(go= group->gobject.first; go; go= go->next) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a78b010392e..5782ae5f2d7 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1431,15 +1431,7 @@ float bsystem_time(struct Scene *scene, Object *UNUSED(ob), float cfra, float of /* global time */ if (scene) - cfra*= scene->r.framelen; - -#if 0 // XXX old animation system - if (ob) { - /* ofset frames */ - if ((ob->ipoflag & OB_OFFS_PARENT) && (ob->partype & PARSLOW)==0) - cfra-= give_timeoffset(ob); - } -#endif // XXX old animation system + cfra *= scene->r.framelen; cfra-= ofs; @@ -1592,12 +1584,6 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) makeDispListCurveTypes(scene, par, 0); if(cu->path==NULL) return; - /* exception, timeoffset is regarded as distance offset */ - if(cu->flag & CU_OFFS_PATHDIST) { - timeoffs = give_timeoffset(ob); - SWAP(float, sf_orig, ob->sf); - } - /* catch exceptions: feature for nla stride editing */ if(ob->ipoflag & OB_DISABLE_PATH) { ctime= 0.0f; @@ -1618,7 +1604,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) CLAMP(ctime, 0.0f, 1.0f); } else { - ctime= scene->r.cfra - give_timeoffset(ob); + ctime= scene->r.cfra; if (IS_EQF(cu->pathlen, 0.0f) == 0) ctime /= cu->pathlen; @@ -1862,9 +1848,6 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) if(ob->parent) { Object *par= ob->parent; - // XXX depreceated - animsys - if(ob->ipoflag & OB_OFFS_PARENT) ctime-= give_timeoffset(ob); - /* hurms, code below conflicts with depgraph... (ton) */ /* and even worse, it gives bad effects for NLA stride too (try ctime != par->ctime, with MBlur) */ if(no_parent_ipo==0 && stime != par->ctime) { @@ -1873,17 +1856,20 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) if(par->proxy_from); // was a copied matrix, no where_is! bad... else where_is_object_time(scene, par, ctime); - + solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); - + *par= tmp; } else solve_parenting(scene, ob, par, ob->obmat, slowmat, 0); + /* "slow parent" is definitely not threadsafe, and may also give bad results jumping around + * An old-fashioned hack which probably doesn't really cut it anymore + */ if(ob->partype & PARSLOW) { // include framerate - fac1= ( 1.0f / (1.0f + (float)fabs(give_timeoffset(ob))) ); + fac1= ( 1.0f / (1.0f + (float)fabs(ob->sf)) ); if(fac1 >= 1.0f) return; fac2= 1.0f-fac1; @@ -2006,7 +1992,6 @@ void where_is_object_simul(Scene *scene, Object *ob) for a lamp that is the child of another object */ { Object *par; - //Ipo *ipo; float *fp1, *fp2; float slowmat[4][4]; float fac1, fac2; @@ -2017,10 +2002,9 @@ for a lamp that is the child of another object */ par= ob->parent; solve_parenting(scene, ob, par, ob->obmat, slowmat, 1); - + if(ob->partype & PARSLOW) { - - fac1= (float)(1.0/(1.0+ fabs(give_timeoffset(ob)))); + fac1= (float)(1.0/(1.0+ fabs(ob->sf))); fac2= 1.0f-fac1; fp1= ob->obmat[0]; fp2= slowmat[0]; @@ -2028,7 +2012,6 @@ for a lamp that is the child of another object */ fp1[0]= fac1*fp1[0] + fac2*fp2[0]; } } - } else { object_to_mat4(ob, ob->obmat); @@ -2554,15 +2537,6 @@ void object_sculpt_modifiers_changed(Object *ob) } } -float give_timeoffset(Object *ob) -{ - if ((ob->ipoflag & OB_OFFS_PARENTADD) && ob->parent) { - return ob->sf + give_timeoffset(ob->parent); - } else { - return ob->sf; - } -} - int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, float **rot) { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index ae12ad8e66f..b327afa7df7 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2163,7 +2163,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra * system timing. */ #if 0 if ((ob->partype & PARSLOW)==0) { - offset= give_timeoffset(ob); + offset= ob->sf; *startframe += (int)(offset+0.5f); *endframe += (int)(offset+0.5f); -- cgit v1.2.3 From 723484ec066d3e2d2b0943dc9dca156d63c07c39 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 6 Nov 2011 06:08:18 +0000 Subject: Removed old "bsystem_time()" function, which by now is just a duplicate of BKE_curframe() which just takes two extra args. For the few calls in the physics engine where CFRA+1 instead of CFRA was being used, I've added a new BKE_nextframe() call, which will calculate for CFRA+1 instead of CFRA in much the same way that bsystem_time() would end up doing things (which means including subframe steps). --- source/blender/blenkernel/intern/anim.c | 2 +- source/blender/blenkernel/intern/armature.c | 3 ++- source/blender/blenkernel/intern/key.c | 15 ++++++++------- source/blender/blenkernel/intern/object.c | 20 -------------------- source/blender/blenkernel/intern/particle.c | 5 +++-- source/blender/blenkernel/intern/pointcache.c | 4 ++-- source/blender/blenkernel/intern/scene.c | 19 ++++++++++++++----- 7 files changed, 30 insertions(+), 38 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index f939c168f51..c1f294fb102 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1230,7 +1230,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if(G.rendering == 0) no_draw_flag |= PARS_NO_DISP; - ctime = bsystem_time(scene, par, (float)scene->r.cfra, 0.0); + ctime = BKE_curframe(scene); /* NOTE: in old animsys, used parent object's timeoffset... */ totpart = psys->totpart; totchild = psys->totchild; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index e9a19b50a81..f19ed859064 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -68,6 +68,7 @@ #include "BKE_lattice.h" #include "BKE_main.h" #include "BKE_object.h" +#include "BKE_scene.h" #include "BIK_api.h" #include "BKE_sketch.h" @@ -2406,7 +2407,7 @@ void where_is_pose (Scene *scene, Object *ob) if((ob->pose==NULL) || (ob->pose->flag & POSE_RECALC)) armature_rebuild_pose(ob, arm); - ctime= bsystem_time(scene, ob, (float)scene->r.cfra, 0.0); /* not accurate... */ + ctime= BKE_curframe(scene); /* not accurate... */ /* In editmode or restposition we read the data from the bones */ if(arm->edbo || (arm->flag & ARM_RESTPOS)) { diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 6d095117136..c389800b0d1 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -59,6 +59,7 @@ #include "BKE_main.h" #include "BKE_object.h" #include "BKE_deform.h" +#include "BKE_scene.h" #include "RNA_access.h" @@ -1072,7 +1073,7 @@ static void do_mesh_key(Scene *scene, Object *ob, Key *key, char *out, const int for(a=0; aipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; @@ -1106,7 +1107,7 @@ static void do_mesh_key(Scene *scene, Object *ob, Key *key, char *out, const int } } else { - ctime= bsystem_time(scene, ob, (float)scene->r.cfra, 0.0f); // xxx old cruft + ctime= BKE_curframe(scene); #if 0 // XXX old animation system if(calc_ipo_spec(key->ipo, KEY_SPEED, &ctime)==0) { @@ -1204,7 +1205,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in while (a < estep) { if (remain <= 0) { cfra+= delta; - ctime= bsystem_time(scene, NULL, cfra, 0.0f); // XXX old cruft + ctime= BKE_curframe(scene); ctime /= 100.0f; CLAMP(ctime, 0.0f, 1.0f); // XXX for compat, we use this, but this clamping was confusing @@ -1231,7 +1232,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in } else { - ctime= bsystem_time(scene, NULL, (float)scene->r.cfra, 0.0); + ctime= BKE_curframe(scene); if(key->type==KEY_RELATIVE) { do_rel_cu_key(cu, cu->key, actkb, ctime, out, tot); @@ -1267,7 +1268,7 @@ static void do_latt_key(Scene *scene, Object *ob, Key *key, char *out, const int for(a=0; aipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; @@ -1298,7 +1299,7 @@ static void do_latt_key(Scene *scene, Object *ob, Key *key, char *out, const int } } else { - ctime= bsystem_time(scene, NULL, (float)scene->r.cfra, 0.0); + ctime= BKE_curframe(scene); #if 0 // XXX old animation system if(calc_ipo_spec(key->ipo, KEY_SPEED, &ctime)==0) { @@ -1462,7 +1463,7 @@ KeyBlock *add_keyblock(Key *key, const char *name) kb->pos= curpos + 0.1f; else { #if 0 // XXX old animation system - curpos= bsystem_time(scene, 0, (float)CFRA, 0.0); + curpos= BKE_curframe(scene); if(calc_ipo_spec(key->ipo, KEY_SPEED, &curpos)==0) { curpos /= 100.0; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 5782ae5f2d7..a493120e320 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1419,25 +1419,6 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) /* *************** CALC ****************** */ -/* there is also a timing calculation in drawobject() */ - - -// XXX THIS CRUFT NEEDS SERIOUS RECODING ASAP! -/* ob can be NULL */ -float bsystem_time(struct Scene *scene, Object *UNUSED(ob), float cfra, float ofs) -{ - /* returns float ( see BKE_curframe in scene.c) */ - cfra += scene->r.subframe; - - /* global time */ - if (scene) - cfra *= scene->r.framelen; - - cfra-= ofs; - - return cfra; -} - void object_scale_to_mat3(Object *ob, float mat[][3]) { float vec[3]; @@ -1445,7 +1426,6 @@ void object_scale_to_mat3(Object *ob, float mat[][3]) size_to_mat3( mat,vec); } - void object_rot_to_mat3(Object *ob, float mat[][3]) { float rmat[3][3], dmat[3][3]; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 7678da1c7c4..f8d281c2951 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -77,6 +77,7 @@ #include "BKE_mesh.h" #include "BKE_cdderivedmesh.h" #include "BKE_pointcache.h" +#include "BKE_scene.h" #include "RE_render_ext.h" @@ -3426,7 +3427,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n psys->totpart=0; psys->flag = PSYS_ENABLED|PSYS_CURRENT; - psys->cfra=bsystem_time(scene,ob,scene->r.cfra+1,0.0); + psys->cfra = BKE_nextframe(scene); DAG_scene_sort(G.main, scene); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); @@ -4189,7 +4190,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta float timestep = psys_get_timestep(sim); /* negative time means "use current time" */ - cfra = state->time > 0 ? state->time : bsystem_time(sim->scene, 0, (float)sim->scene->r.cfra, 0.0); + cfra = state->time > 0 ? state->time : BKE_curframe(sim->scene); if(p>=totpart){ if(!psys->totchild) diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b327afa7df7..7a8162391d5 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2147,8 +2147,8 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra cache= pid->cache; if(timescale) { - time= bsystem_time(scene, ob, cfra, 0.0f); - nexttime= bsystem_time(scene, ob, cfra+1.0f, 0.0f); + time= BKE_curframe(scene); + nexttime= BKE_nextframe(scene); *timescale= MAX2(nexttime - time, 0.0f); } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index f1e094c3909..2f24b7e735d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -910,14 +910,23 @@ int scene_check_setscene(Main *bmain, Scene *sce) } /* This function is needed to cope with fractional frames - including two Blender rendering features -* mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. */ - -/* see also bsystem_time in object.c */ + * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. + */ float BKE_curframe(Scene *scene) { float ctime = scene->r.cfra; - ctime+= scene->r.subframe; - ctime*= scene->r.framelen; + ctime += scene->r.subframe; + ctime *= scene->r.framelen; + + return ctime; +} + +/* Similar to BKE_curframe(), but is used by physics sims to get "next time", which is defined as cfra+1 */ +float BKE_nextframe(Scene *scene) +{ + float ctime = (float)(scene->r.cfra + 1); + ctime += scene->r.subframe; + ctime *= scene->r.framelen; return ctime; } -- cgit v1.2.3 From e03fdd81122edba048882f07bfef09a1764e1682 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 6 Nov 2011 12:12:14 +0000 Subject: Second attempt at getting rid of bsystem_time() Hopefully this fixes Collada. Can't really compile that to check here... --- source/blender/blenkernel/intern/particle.c | 2 +- source/blender/blenkernel/intern/pointcache.c | 4 ++-- source/blender/blenkernel/intern/scene.c | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index f8d281c2951..76d08f6fff2 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3427,7 +3427,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n psys->totpart=0; psys->flag = PSYS_ENABLED|PSYS_CURRENT; - psys->cfra = BKE_nextframe(scene); + psys->cfra = BKE_frame_to_ctime(scene, CFRA + 1); DAG_scene_sort(G.main, scene); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 7a8162391d5..ba5b98ee3cd 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2148,8 +2148,8 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra if(timescale) { time= BKE_curframe(scene); - nexttime= BKE_nextframe(scene); - + nexttime= BKE_frame_to_ctime(scene, CFRA+1); + *timescale= MAX2(nexttime - time, 0.0f); } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 2f24b7e735d..66d29b02263 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -914,20 +914,16 @@ int scene_check_setscene(Main *bmain, Scene *sce) */ float BKE_curframe(Scene *scene) { - float ctime = scene->r.cfra; - ctime += scene->r.subframe; - ctime *= scene->r.framelen; - - return ctime; + return BKE_frame_to_ctime(scene, scene->r.cfra); } -/* Similar to BKE_curframe(), but is used by physics sims to get "next time", which is defined as cfra+1 */ -float BKE_nextframe(Scene *scene) +/* This function is used to obtain arbitrary fractional frames */ +float BKE_frame_to_ctime(Scene *scene, const float frame) { - float ctime = (float)(scene->r.cfra + 1); + float ctime = frame; ctime += scene->r.subframe; ctime *= scene->r.framelen; - + return ctime; } -- cgit v1.2.3 From b82dee0cb42e1796b3d1f9d6e9c2d4bd5b94b0de Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 Nov 2011 14:00:55 +0000 Subject: replace macros with bli math functions for particles code --- source/blender/blenkernel/intern/particle.c | 197 +++++++++++---------- source/blender/blenkernel/intern/particle_system.c | 18 +- 2 files changed, 108 insertions(+), 107 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 76d08f6fff2..3b6fc09ad4f 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -619,13 +619,13 @@ static float psys_render_viewport_falloff(double rate, float dist, float width) return pow(rate, dist/width); } -static float psys_render_projected_area(ParticleSystem *psys, float *center, float area, double vprate, float *viewport) +static float psys_render_projected_area(ParticleSystem *psys, const float center[3], float area, double vprate, float *viewport) { ParticleRenderData *data= psys->renderdata; float co[4], view[3], ortho1[3], ortho2[3], w, dx, dy, radius; /* transform to view space */ - VECCOPY(co, center); + copy_v3_v3(co, center); co[3]= 1.0f; mul_m4_v4(data->viewmat, co); @@ -829,17 +829,17 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) b= (origindex)? origindex[a]: a; if(b != -1) { - VECCOPY(co1, mvert[mf->v1].co); - VECCOPY(co2, mvert[mf->v2].co); - VECCOPY(co3, mvert[mf->v3].co); + copy_v3_v3(co1, mvert[mf->v1].co); + copy_v3_v3(co2, mvert[mf->v2].co); + copy_v3_v3(co3, mvert[mf->v3].co); - VECADD(facecenter[b], facecenter[b], co1); - VECADD(facecenter[b], facecenter[b], co2); - VECADD(facecenter[b], facecenter[b], co3); + add_v3_v3(facecenter[b], co1); + add_v3_v3(facecenter[b], co2); + add_v3_v3(facecenter[b], co3); if(mf->v4) { - VECCOPY(co4, mvert[mf->v4].co); - VECADD(facecenter[b], facecenter[b], co4); + copy_v3_v3(co4, mvert[mf->v4].co); + add_v3_v3(facecenter[b], co4); facearea[b] += area_quad_v3(co1, co2, co3, co4); facetotvert[b] += 4; } @@ -998,7 +998,7 @@ int psys_render_simplify_params(ParticleSystem *psys, ChildParticle *cpa, float /************************************************/ /* Interpolation */ /************************************************/ -static float interpolate_particle_value(float v1, float v2, float v3, float v4, float *w, int four) +static float interpolate_particle_value(float v1, float v2, float v3, float v4, const float w[4], int four) { float value; @@ -1029,12 +1029,12 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic if(dt>0.999f){ key_curve_position_weights(dt-0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); - VECSUB(result->vel, result->co, temp); + sub_v3_v3v3(result->vel, result->co, temp); } else{ key_curve_position_weights(dt+0.001f, t, type); interp_v3_v3v3v3v3(temp, keys[0].co, keys[1].co, keys[2].co, keys[3].co, t); - VECSUB(result->vel, temp, result->co); + sub_v3_v3v3(result->vel, temp, result->co); } } } @@ -1180,21 +1180,21 @@ static void init_particle_interpolation(Object *ob, ParticleSystem *psys, Partic } static void edit_to_particle(ParticleKey *key, PTCacheEditKey *ekey) { - VECCOPY(key->co, ekey->co); + copy_v3_v3(key->co, ekey->co); if(ekey->vel) { - VECCOPY(key->vel, ekey->vel); + copy_v3_v3(key->vel, ekey->vel); } key->time = *(ekey->time); } static void hair_to_particle(ParticleKey *key, HairKey *hkey) { - VECCOPY(key->co, hkey->co); + copy_v3_v3(key->co, hkey->co); key->time = hkey->time; } static void mvert_to_particle(ParticleKey *key, MVert *mvert, HairKey *hkey) { - VECCOPY(key->co, mvert->co); + copy_v3_v3(key->co, mvert->co); key->time = hkey->time; } @@ -1473,13 +1473,13 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or } } else { - VECCOPY(orco, vec); + copy_v3_v3(orco, vec); if(ornor && nor) - VECCOPY(ornor, nor); + copy_v3_v3(ornor, nor); } } } -void psys_interpolate_uvs(MTFace *tface, int quad, float *w, float *uvco) +void psys_interpolate_uvs(const MTFace *tface, int quad, const float w[4], float uvco[2]) { float v10= tface->uv[0][0]; float v11= tface->uv[0][1]; @@ -1502,7 +1502,7 @@ void psys_interpolate_uvs(MTFace *tface, int quad, float *w, float *uvco) } } -void psys_interpolate_mcol(MCol *mcol, int quad, float *w, MCol *mc) +void psys_interpolate_mcol(const MCol *mcol, int quad, const float w[4], MCol *mc) { char *cp, *cp1, *cp2, *cp3, *cp4; @@ -1527,7 +1527,7 @@ void psys_interpolate_mcol(MCol *mcol, int quad, float *w, MCol *mc) } } -static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int index, float *fw, float *values) +static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int index, const float fw[4], const float *values) { if(values==0 || index==-1) return 0.0; @@ -1543,18 +1543,18 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int } } - return 0.0; + return 0.0f; } /* conversion of pa->fw to origspace layer coordinates */ -static void psys_w_to_origspace(float *w, float *uv) +static void psys_w_to_origspace(const float w[4], float uv[2]) { uv[0]= w[1] + w[2]; uv[1]= w[2] + w[3]; } /* conversion of pa->fw to weights in face from origspace */ -static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, float *w, float *neww) +static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, const float w[4], float neww[4]) { float v[4][3], co[3]; @@ -1567,17 +1567,17 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, float *w, float if(quad) { v[3][0]= osface->uv[3][0]; v[3][1]= osface->uv[3][1]; v[3][2]= 0.0f; - interp_weights_poly_v3( neww,v, 4, co); + interp_weights_poly_v3(neww, v, 4, co); } else { - interp_weights_poly_v3( neww,v, 3, co); + interp_weights_poly_v3(neww, v, 3, co); neww[3]= 0.0f; } } /* find the derived mesh face for a particle, set the mf passed. this is slow * and can be optimized but only for many lookups. returns the face index. */ -int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, float *fw, struct LinkNode *node) +int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const float fw[4], struct LinkNode *node) { Mesh *me= (Mesh*)ob->data; MFace *mface; @@ -1644,7 +1644,7 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, float * return DMCACHE_NOTFOUND; } -static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache, float *fw, float UNUSED(foffset), int *mapindex, float *mapfw) +static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache, const float fw[4], float UNUSED(foffset), int *mapindex, float mapfw[4]) { if(index < 0) return 0; @@ -1704,7 +1704,7 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_ } /* interprets particle data to get a point on a mesh in object space */ -void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache, float *fw, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor) +void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache, const float fw[4], float foffset, float vec[3], float nor[3], float utan[3], float vtan[3], float orco[3], float ornor[3]) { float tmpnor[3], mapfw[4]; float (*orcodata)[3]; @@ -1732,7 +1732,7 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache } if(orco) - VECCOPY(orco, orcodata[mapindex]) + copy_v3_v3(orco, orcodata[mapindex]); if(ornor) { dm->getVertNo(dm,mapindex,nor); @@ -1759,11 +1759,11 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache if(from==PART_FROM_VOLUME) { psys_interpolate_face(mvert,mface,mtface,orcodata,mapfw,vec,tmpnor,utan,vtan,orco,ornor); if(nor) - VECCOPY(nor,tmpnor); + copy_v3_v3(nor,tmpnor); normalize_v3(tmpnor); mul_v3_fl(tmpnor,-foffset); - VECADD(vec,vec,tmpnor); + add_v3_v3(vec, tmpnor); } else psys_interpolate_face(mvert,mface,mtface,orcodata,mapfw,vec,nor,utan,vtan,orco,ornor); @@ -1805,22 +1805,22 @@ static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index), float * /* TODO */ float zerovec[3]={0.0f,0.0f,0.0f}; if(vec){ - VECCOPY(vec,zerovec); + copy_v3_v3(vec,zerovec); } if(nor){ - VECCOPY(nor,zerovec); + copy_v3_v3(nor,zerovec); } if(utan){ - VECCOPY(utan,zerovec); + copy_v3_v3(utan,zerovec); } if(vtan){ - VECCOPY(vtan,zerovec); + copy_v3_v3(vtan,zerovec); } if(orco){ - VECCOPY(orco,zerovec); + copy_v3_v3(orco,zerovec); } if(ornor){ - VECCOPY(ornor,zerovec); + copy_v3_v3(ornor,zerovec); } } /************************************************/ @@ -1990,7 +1990,7 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float } else if(inp_z > 0.0f){ mul_v3_v3fl(state_co, z_vec, (float)sin((float)M_PI/3.f)); - VECADDFAC(state_co,state_co,y_vec,-0.5f); + madd_v3_v3fl(state_co, y_vec, -0.5f); mul_v3_fl(y_vec, -amplitude * (float)cos(t + (float)M_PI/3.f)); mul_v3_fl(z_vec, amplitude/2.f * (float)cos(2.f*t + (float)M_PI/6.f)); @@ -2088,7 +2088,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) data = eff->guide_data + p; - VECSUB(efd.vec_to_point, state.co, eff->guide_loc); + sub_v3_v3v3(efd.vec_to_point, state.co, eff->guide_loc); copy_v3_v3(efd.nor, eff->guide_dir); efd.distance = len_v3(efd.vec_to_point); @@ -2142,7 +2142,7 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) normalize_v3(guidedir); - VECCOPY(vec_to_point, data->vec_to_point); + copy_v3_v3(vec_to_point, data->vec_to_point); if(guidetime != 0.0f) { /* curve direction */ @@ -2167,16 +2167,16 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) } } par.co[0] = par.co[1] = par.co[2] = 0.0f; - VECCOPY(key.co, vec_to_point); + copy_v3_v3(key.co, vec_to_point); do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0); do_clump(&key, &par, guidetime, pd->clump_fac, pd->clump_pow, 1.0f); - VECCOPY(vec_to_point, key.co); + copy_v3_v3(vec_to_point, key.co); - VECADD(vec_to_point, vec_to_point, guidevec); + add_v3_v3(vec_to_point, guidevec); - //VECSUB(pa_loc,pa_loc,pa_zero); - VECADDFAC(effect, effect, vec_to_point, data->strength); - VECADDFAC(veffect, veffect, guidedir, data->strength); + //sub_v3_v3v3(pa_loc,pa_loc,pa_zero); + madd_v3_v3fl(effect, vec_to_point, data->strength); + madd_v3_v3fl(veffect, guidedir, data->strength); totstrength += data->strength; if(pd->flag & PFIELD_GUIDE_PATH_WEIGHT) @@ -2187,12 +2187,12 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) if(totstrength > 1.0f) mul_v3_fl(effect, 1.0f / totstrength); CLAMP(totstrength, 0.0f, 1.0f); - //VECADD(effect,effect,pa_zero); + //add_v3_v3(effect,pa_zero); interp_v3_v3v3(state->co, state->co, effect, totstrength); normalize_v3(veffect); mul_v3_fl(veffect, len_v3(state->vel)); - VECCOPY(state->vel, veffect); + copy_v3_v3(state->vel, veffect); return 1; } return 0; @@ -2205,15 +2205,15 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size if(thres != 0.0f) if((float)fabs((float)(-1.5f+loc[0]+loc[1]+loc[2]))<1.5f*thres) return; - VECCOPY(rco,loc); + copy_v3_v3(rco,loc); mul_v3_fl(rco,t); rough[0]=-1.0f+2.0f*BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2,0,2); rough[1]=-1.0f+2.0f*BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2,0,2); rough[2]=-1.0f+2.0f*BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2,0,2); - VECADDFAC(state->co,state->co,mat[0],fac*rough[0]); - VECADDFAC(state->co,state->co,mat[1],fac*rough[1]); - VECADDFAC(state->co,state->co,mat[2],fac*rough[2]); + madd_v3_v3fl(state->co, mat[0], fac * rough[0]); + madd_v3_v3fl(state->co, mat[1], fac * rough[1]); + madd_v3_v3fl(state->co, mat[2], fac * rough[2]); } static void do_rough_end(float *loc, float mat[4][4], float t, float fac, float shape, ParticleKey *state) { @@ -2226,8 +2226,8 @@ static void do_rough_end(float *loc, float mat[4][4], float t, float fac, float rough[1]=-1.0f+2.0f*rough[1]; mul_v2_fl(rough,roughfac); - VECADDFAC(state->co,state->co,mat[0],rough[0]); - VECADDFAC(state->co,state->co,mat[1],rough[1]); + madd_v3_v3fl(state->co, mat[0], rough[0]); + madd_v3_v3fl(state->co, mat[1], rough[1]); } static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheKey *ca, int k, int steps, float *UNUSED(rootco), float effector, float UNUSED(dfra), float UNUSED(cfra), float *length, float *vec) { @@ -2239,9 +2239,9 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK if(sim->psys->flag & PSYS_HAIR_DYNAMICS) return; - VECCOPY(eff_key.co,(ca-1)->co); - VECCOPY(eff_key.vel,(ca-1)->vel); - QUATCOPY(eff_key.rot,(ca-1)->rot); + copy_v3_v3(eff_key.co,(ca-1)->co); + copy_v3_v3(eff_key.vel,(ca-1)->vel); + copy_qt_qt(eff_key.rot,(ca-1)->rot); pd_point_from_particle(sim, sim->psys->particles+i, &eff_key, &epoint); pdDoEffectors(sim->psys->effectors, sim->colliders, sim->psys->part->effector_weights, &epoint, force, NULL); @@ -2264,7 +2264,7 @@ static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *st { if(*cur_length + length > max_length){ mul_v3_fl(dvec, (max_length - *cur_length) / length); - VECADD(state->co, (state - 1)->co, dvec); + add_v3_v3v3(state->co, (state - 1)->co, dvec); keys->steps = k; /* something over the maximum step value */ return k=100000; @@ -2364,8 +2364,9 @@ static void get_strand_normal(Material *ma, float *surfnor, float surfdist, floa interp_v3_v3v3(vnor, nstrand, surfnor, blend); normalize_v3(vnor); } - else - VECCOPY(vnor, nor) + else { + copy_v3_v3(vnor, nor); + } if(ma->strand_surfnor > 0.0f) { if(ma->strand_surfnor > surfdist) { @@ -2375,7 +2376,7 @@ static void get_strand_normal(Material *ma, float *surfnor, float surfdist, floa } } - VECCOPY(nor, vnor); + copy_v3_v3(nor, vnor); } static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float cfra, int editupdate) @@ -2716,7 +2717,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle } if(ctx->ma && (part->draw_col == PART_DRAW_COL_MAT)) { - VECCOPY(child->col, &ctx->ma->r) + copy_v3_v3(child->col, &ctx->ma->r); get_strand_normal(ctx->ma, ornor, cur_length, child->vel); } } @@ -2899,7 +2900,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) psys->lattice = psys_get_lattice(sim); ma= give_current_material(sim->ob, psys->part->omat); if(ma && (psys->part->draw_col == PART_DRAW_COL_MAT)) - VECCOPY(col, &ma->r) + copy_v3_v3(col, &ma->r); if((psys->flag & PSYS_GLOBAL_HAIR)==0) { if((psys->part->flag & PART_CHILD_EFFECT)==0) @@ -2933,9 +2934,9 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* hairmat is needed for for non-hair particle too so we get proper rotations */ psys_mat_hair_to_global(sim->ob, psmd->dm, psys->part->from, pa, hairmat); - VECCOPY(rotmat[0], hairmat[2]); - VECCOPY(rotmat[1], hairmat[1]); - VECCOPY(rotmat[2], hairmat[0]); + copy_v3_v3(rotmat[0], hairmat[2]); + copy_v3_v3(rotmat[1], hairmat[1]); + copy_v3_v3(rotmat[2], hairmat[0]); if(part->draw & PART_ABS_PATH_TIME) { birthtime = MAX2(pind.birthtime, part->path_start); @@ -3189,7 +3190,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf else { if((ekey + (pind.ekey[0] - point->keys))->flag & PEK_SELECT){ if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){ - VECCOPY(ca->col, sel_col); + copy_v3_v3(ca->col, sel_col); } else{ keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); @@ -3202,7 +3203,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime); } else{ - VECCOPY(ca->col, nosel_col); + copy_v3_v3(ca->col, nosel_col); } } } @@ -3253,9 +3254,9 @@ void copy_particle_key(ParticleKey *to, ParticleKey *from, int time){ } } void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, float *time){ - if(loc) VECCOPY(loc,key->co); - if(vel) VECCOPY(vel,key->vel); - if(rot) QUATCOPY(rot,key->rot); + if(loc) copy_v3_v3(loc,key->co); + if(vel) copy_v3_v3(vel,key->vel); + if(rot) copy_qt_qt(rot,key->rot); if(time) *time=key->time; } /*-------changing particle keys from space to another-------*/ @@ -3263,13 +3264,13 @@ void psys_get_from_key(ParticleKey *key, float *loc, float *vel, float *rot, flo static void key_from_object(Object *ob, ParticleKey *key){ float q[4]; - VECADD(key->vel,key->vel,key->co); + add_v3_v3(key->vel, key->co); mul_m4_v3(ob->obmat,key->co); mul_m4_v3(ob->obmat,key->vel); mat4_to_quat(q,ob->obmat); - VECSUB(key->vel,key->vel,key->co); + sub_v3_v3v3(key->vel,key->vel,key->co); mul_qt_qtqt(key->rot,q,key->rot); } #endif @@ -3330,9 +3331,9 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m osface=dm->getFaceData(dm,i,CD_ORIGSPACE); if(orco && (orcodata=dm->getVertDataArray(dm, CD_ORCO))) { - VECCOPY(v[0], orcodata[mface->v1]); - VECCOPY(v[1], orcodata[mface->v2]); - VECCOPY(v[2], orcodata[mface->v3]); + copy_v3_v3(v[0], orcodata[mface->v1]); + copy_v3_v3(v[1], orcodata[mface->v2]); + copy_v3_v3(v[2], orcodata[mface->v3]); /* ugly hack to use non-transformed orcos, since only those * give symmetric results for mirroring in particle mode */ @@ -3354,7 +3355,7 @@ void psys_mat_hair_to_object(Object *UNUSED(ob), DerivedMesh *dm, short from, Pa psys_face_mat(0, dm, pa, hairmat, 0); psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, 0, 0); - VECCOPY(hairmat[3],vec); + copy_v3_v3(hairmat[3],vec); } void psys_mat_hair_to_orco(Object *ob, DerivedMesh *dm, short from, ParticleData *pa, float hairmat[][4]) @@ -3367,7 +3368,7 @@ void psys_mat_hair_to_orco(Object *ob, DerivedMesh *dm, short from, ParticleData /* see psys_face_mat for why this function is called */ if(DM_get_vert_data_layer(dm, CD_ORIGINDEX)) transform_mesh_orco_verts(ob->data, &orco, 1, 1); - VECCOPY(hairmat[3],orco); + copy_v3_v3(hairmat[3],orco); } void psys_vec_rot_to_face(DerivedMesh *dm, ParticleData *pa, float *vec) @@ -3658,7 +3659,7 @@ void make_local_particlesettings(ParticleSettings *part) /* Textures */ /************************************************/ -static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, float *fuv, char *name, float *texco) +static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, const float fuv[4], char *name, float *texco) { MFace *mf; MTFace *tf; @@ -3702,7 +3703,7 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, fl #define CLAMP_PARTICLE_TEXTURE_POS(type, pvalue) if(event & type) { if(pvalue < 0.f) pvalue = 1.f+pvalue; CLAMP(pvalue, 0.0f, 1.0f); } #define CLAMP_PARTICLE_TEXTURE_POSNEG(type, pvalue) if(event & type) { CLAMP(pvalue, -1.0f, 1.0f); } -static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par, int child_index, int face_index, float *fw, float *orco, ParticleTexture *ptex, int event, float cfra) +static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par, int child_index, int face_index, const float fw[4], float *orco, ParticleTexture *ptex, int event, float cfra) { MTex *mtex, **mtexp = part->mtex; int m; @@ -4071,7 +4072,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * psys_particle_on_emitter(psmd,cpa_from,cpa_num,DMCACHE_ISCHILD,cpa->fuv,foffset,co,0,0,0,orco,0); /* we need to save the actual root position of the child for positioning it accurately to the surface of the emitter */ - //VECCOPY(cpa_1st,co); + //copy_v3_v3(cpa_1st,co); //mul_m4_v3(ob->obmat,cpa_1st); @@ -4142,7 +4143,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * w++; } /* apply offset for correct positioning */ - //VECADD(state->co,state->co,cpa_1st); + //add_v3_v3(state->co, cpa_1st); } else{ /* offset the child from the parent position */ @@ -4165,13 +4166,13 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * if(t>=0.001f){ tstate.time=t-0.001f; psys_get_particle_on_path(sim,p,&tstate,0); - VECSUB(state->vel,state->co,tstate.co); + sub_v3_v3v3(state->vel,state->co,tstate.co); normalize_v3(state->vel); } else{ tstate.time=t+0.001f; psys_get_particle_on_path(sim,p,&tstate,0); - VECSUB(state->vel,tstate.co,state->co); + sub_v3_v3v3(state->vel,tstate.co,state->co); normalize_v3(state->vel); } @@ -4422,9 +4423,9 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa cross_v3_v3v3(nor, vec, side); unit_m4(mat); - VECCOPY(mat[0], vec); - VECCOPY(mat[1], side); - VECCOPY(mat[2], nor); + copy_v3_v3(mat[0], vec); + copy_v3_v3(mat[1], side); + copy_v3_v3(mat[2], nor); } else { quat_to_mat4(mat, pa->state.rot); @@ -4470,12 +4471,12 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] normalize_v3_v3(temp, bb->vel); - VECSUB(zvec, bb->ob->obmat[3], bb->vec); + sub_v3_v3v3(zvec, bb->ob->obmat[3], bb->vec); if(bb->lock) { float fac = -dot_v3v3(zvec, temp); - VECADDFAC(zvec, zvec, temp, fac); + madd_v3_v3fl(zvec, temp, fac); } normalize_v3(zvec); @@ -4485,7 +4486,7 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] cross_v3_v3v3(yvec,zvec,xvec); } else { - VECSUB(zvec, bb->ob->obmat[3], bb->vec); + sub_v3_v3v3(zvec, bb->ob->obmat[3], bb->vec); if(bb->lock) zvec[bb->align] = 0.0f; normalize_v3(zvec); @@ -4499,22 +4500,22 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] cross_v3_v3v3(yvec,zvec,xvec); } - VECCOPY(tvec, xvec); - VECCOPY(tvec2, yvec); + copy_v3_v3(tvec, xvec); + copy_v3_v3(tvec2, yvec); mul_v3_fl(xvec, cos(bb->tilt * (float)M_PI)); mul_v3_fl(tvec2, sin(bb->tilt * (float)M_PI)); - VECADD(xvec, xvec, tvec2); + add_v3_v3(xvec, tvec2); mul_v3_fl(yvec, cos(bb->tilt * (float)M_PI)); mul_v3_fl(tvec, -sin(bb->tilt * (float)M_PI)); - VECADD(yvec, yvec, tvec); + add_v3_v3(yvec, tvec); mul_v3_fl(xvec, bb->size[0]); mul_v3_fl(yvec, bb->size[1]); - VECADDFAC(center, bb->vec, xvec, bb->offset[0]); - VECADDFAC(center, center, yvec, bb->offset[1]); + madd_v3_v3v3fl(center, bb->vec, xvec, bb->offset[0]); + madd_v3_v3fl(center, yvec, bb->offset[1]); } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index ec058b23050..f92fb4444cc 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -454,7 +454,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) max[2]=MAX2(max[2],mv->co[2]); } - VECSUB(delta,max,min); + sub_v3_v3v3(delta, max, min); /* determine major axis */ axis = (delta[0]>=delta[1]) ? 0 : ((delta[1]>=delta[2]) ? 1 : 2); @@ -1588,15 +1588,15 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P if(part->tanfac!=0.0f){ //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f; float phase=0.0f; - mul_v3_fl(vtan,-(float)cos((float)M_PI*(part->tanphase+phase))); - fac=-(float)sin((float)M_PI*(part->tanphase+phase)); - VECADDFAC(vtan,vtan,utan,fac); + mul_v3_fl(vtan,-cosf((float)M_PI*(part->tanphase+phase))); + fac= -sinf((float)M_PI*(part->tanphase+phase)); + madd_v3_v3fl(vtan, utan, fac); mul_mat3_m4_v3(ob->obmat,vtan); - VECCOPY(utan,nor); + copy_v3_v3(utan, nor); mul_v3_fl(utan,dot_v3v3(vtan,nor)); - VECSUB(vtan,vtan,utan); + sub_v3_v3(vtan, utan); normalize_v3(vtan); } @@ -2606,7 +2606,7 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa if(do_guides(sim->psys->effectors, &tkey, p, time)) { VECCOPY(pa->state.co,tkey.co); /* guides don't produce valid velocity */ - VECSUB(pa->state.vel,tkey.co,pa->prev_state.co); + sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co); mul_v3_fl(pa->state.vel,1.0f/dtime); pa->state.time=tkey.time; } @@ -3471,7 +3471,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) /* create fake root before actual root to resist bending */ if(k==0) { float temp[3]; - VECSUB(temp, key->co, (key+1)->co); + sub_v3_v3v3(temp, key->co, (key+1)->co); VECCOPY(mvert->co, key->co); VECADD(mvert->co, mvert->co, temp); mul_m4_v3(hairmat, mvert->co); @@ -3589,7 +3589,7 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra)){ mul_m4_v3(ob->imat, key->co); if(pa->totkey) { - VECSUB(key->co, key->co, root->co); + sub_v3_v3(key->co, root->co); psys_vec_rot_to_face(sim->psmd->dm, pa, key->co); } -- cgit v1.2.3 From ec3b0c6a968210512e0c36e1e62eefcbe0cf1ea0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 Nov 2011 15:17:43 +0000 Subject: misc macro --> bli math lib functions --- source/blender/blenkernel/intern/bvhutils.c | 81 +++++++++++++-------------- source/blender/blenkernel/intern/colortools.c | 4 +- source/blender/blenkernel/intern/displist.c | 12 ++-- source/blender/blenkernel/intern/object.c | 2 +- source/blender/blenkernel/intern/shrinkwrap.c | 2 +- 5 files changed, 50 insertions(+), 51 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index ee160a13fa2..93abad8858f 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -48,27 +48,27 @@ /* Math stuff for ray casting on mesh faces and for nearest surface */ -static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), const float *v0, const float *v1, const float *v2) +static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), const float v0[3], const float v1[3], const float v2[3]) { float dist; - if(isect_ray_tri_v3((float*)ray->origin, (float*)ray->direction, (float*)v0, (float*)v1, (float*)v2, &dist, NULL)) + if(isect_ray_tri_v3(ray->origin, ray->direction, v0, v1, v2, &dist, NULL)) return dist; return FLT_MAX; } -static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, const float m_dist, const float *v0, const float *v1, const float *v2) +static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, const float m_dist, const float v0[3], const float v1[3], const float v2[3]) { float idist; float p1[3]; float plane_normal[3], hit_point[3]; - normal_tri_v3( plane_normal,(float*)v0, (float*)v1, (float*)v2); + normal_tri_v3(plane_normal, v0, v1, v2); - VECADDFAC( p1, ray->origin, ray->direction, m_dist); - if(isect_sweeping_sphere_tri_v3((float*)ray->origin, p1, radius, (float*)v0, (float*)v1, (float*)v2, &idist, hit_point)) + madd_v3_v3v3fl(p1, ray->origin, ray->direction, m_dist); + if(isect_sweeping_sphere_tri_v3(ray->origin, p1, radius, v0, v1, v2, &idist, hit_point)) { return idist * m_dist; } @@ -81,7 +81,7 @@ static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, con * Function adapted from David Eberly's distance tools (LGPL) * http://www.geometrictools.com/LibFoundation/Distance/Distance.html */ -static float nearest_point_in_tri_surface(const float *v0,const float *v1,const float *v2,const float *p, int *v, int *e, float *nearest ) +static float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const float v2[3], const float p[3], int *v, int *e, float nearest[3]) { float diff[3]; float e0[3]; @@ -98,16 +98,16 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const float sqrDist; int lv = -1, le = -1; - VECSUB(diff, v0, p); - VECSUB(e0, v1, v0); - VECSUB(e1, v2, v0); + sub_v3_v3v3(diff, v0, p); + sub_v3_v3v3(e0, v1, v0); + sub_v3_v3v3(e1, v2, v0); - A00 = INPR ( e0, e0 ); - A01 = INPR( e0, e1 ); - A11 = INPR ( e1, e1 ); - B0 = INPR( diff, e0 ); - B1 = INPR( diff, e1 ); - C = INPR( diff, diff ); + A00 = dot_v3v3(e0, e0); + A01 = dot_v3v3(e0, e1 ); + A11 = dot_v3v3(e1, e1 ); + B0 = dot_v3v3(diff, e0 ); + B1 = dot_v3v3(diff, e1 ); + C = dot_v3v3(diff, diff ); Det = fabs( A00 * A11 - A01 * A01 ); S = A01 * B1 - A11 * B0; T = A01 * B0 - A00 * B1; @@ -123,7 +123,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const T = 0.0f; if ( -B0 >= A00 ) { - S = (float)1.0; + S = 1.0f; sqrDist = A00 + 2.0f * B0 + C; lv = 1; } @@ -379,15 +379,15 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const { float w[3], x[3], y[3], z[3]; - VECCOPY(w, v0); - VECCOPY(x, e0); + copy_v3_v3(w, v0); + copy_v3_v3(x, e0); mul_v3_fl(x, S); - VECCOPY(y, e1); + copy_v3_v3(y, e1); mul_v3_fl(y, T); VECADD(z, w, x); VECADD(z, z, y); - //VECSUB(d, p, z); - VECCOPY(nearest, z); + //sub_v3_v3v3(d, p, z); + copy_v3_v3(nearest, z); // d = p - ( v0 + S * e0 + T * e1 ); } *v = lv; @@ -403,7 +403,7 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const // Callback to bvh tree nearest point. The tree must bust have been built using bvhtree_from_mesh_faces. // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. -static void mesh_faces_nearest_point(void *userdata, int index, const float *co, BVHTreeNearest *nearest) +static void mesh_faces_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; MVert *vert = data->vert; @@ -426,7 +426,7 @@ static void mesh_faces_nearest_point(void *userdata, int index, const float *co, { nearest->index = index; nearest->dist = dist; - VECCOPY(nearest->co, nearest_tmp); + copy_v3_v3(nearest->co, nearest_tmp); normal_tri_v3( nearest->no,t0, t1, t2); } @@ -464,7 +464,7 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r { hit->index = index; hit->dist = dist; - VECADDFAC(hit->co, ray->origin, ray->direction, dist); + madd_v3_v3v3fl(hit->co, ray->origin, ray->direction, dist); normal_tri_v3( hit->no,t0, t1, t2); } @@ -478,7 +478,7 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r // Callback to bvh tree nearest point. The tree must bust have been built using bvhtree_from_mesh_edges. // userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. -static void mesh_edges_nearest_point(void *userdata, int index, const float *co, BVHTreeNearest *nearest) +static void mesh_edges_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) { const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata; MVert *vert = data->vert; @@ -488,16 +488,15 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float *co, float *t0, *t1; t0 = vert[ edge->v1 ].co; t1 = vert[ edge->v2 ].co; - - // NOTE: casts to "float*" here are due to co being "const float*" - closest_to_line_segment_v3(nearest_tmp, (float*)co, t0, t1); - dist = len_squared_v3v3(nearest_tmp, (float*)co); + + closest_to_line_segment_v3(nearest_tmp, co, t0, t1); + dist = len_squared_v3v3(nearest_tmp, co); if(dist < nearest->dist) { nearest->index = index; nearest->dist = dist; - VECCOPY(nearest->co, nearest_tmp); + copy_v3_v3(nearest->co, nearest_tmp); sub_v3_v3v3(nearest->no, t0, t1); normalize_v3(nearest->no); } @@ -590,11 +589,11 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float for(i = 0; i < numFaces; i++, efa= efa->next) { if(!(efa->f & 1) && efa->h==0 && !((efa->v1->f&1)+(efa->v2->f&1)+(efa->v3->f&1)+(efa->v4?efa->v4->f&1:0))) { float co[4][3]; - VECCOPY(co[0], vert[ face[i].v1 ].co); - VECCOPY(co[1], vert[ face[i].v2 ].co); - VECCOPY(co[2], vert[ face[i].v3 ].co); + copy_v3_v3(co[0], vert[ face[i].v1 ].co); + copy_v3_v3(co[1], vert[ face[i].v2 ].co); + copy_v3_v3(co[2], vert[ face[i].v3 ].co); if(face[i].v4) - VECCOPY(co[3], vert[ face[i].v4 ].co); + copy_v3_v3(co[3], vert[ face[i].v4 ].co); BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3); } @@ -603,11 +602,11 @@ BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float else { for(i = 0; i < numFaces; i++) { float co[4][3]; - VECCOPY(co[0], vert[ face[i].v1 ].co); - VECCOPY(co[1], vert[ face[i].v2 ].co); - VECCOPY(co[2], vert[ face[i].v3 ].co); + copy_v3_v3(co[0], vert[ face[i].v1 ].co); + copy_v3_v3(co[1], vert[ face[i].v2 ].co); + copy_v3_v3(co[2], vert[ face[i].v3 ].co); if(face[i].v4) - VECCOPY(co[3], vert[ face[i].v4 ].co); + copy_v3_v3(co[3], vert[ face[i].v4 ].co); BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3); } @@ -669,8 +668,8 @@ BVHTree* bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *mesh, float for(i = 0; i < numEdges; i++) { float co[4][3]; - VECCOPY(co[0], vert[ edge[i].v1 ].co); - VECCOPY(co[1], vert[ edge[i].v2 ].co); + copy_v3_v3(co[0], vert[ edge[i].v1 ].co); + copy_v3_v3(co[1], vert[ edge[i].v2 ].co); BLI_bvhtree_insert(tree, i, co[0], 2); } diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 98a434a7d8b..2f568aa01eb 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -501,7 +501,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) hlen= len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */ /* clip handle point */ - VECCOPY(vec, bezt[1].vec[0]); + copy_v3_v3(vec, bezt[1].vec[0]); if(vec[0] < bezt[0].vec[1][0]) vec[0]= bezt[0].vec[1][0]; @@ -518,7 +518,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) hlen= len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */ /* clip handle point */ - VECCOPY(vec, bezt[a-1].vec[2]); + copy_v3_v3(vec, bezt[a-1].vec[2]); if(vec[0] > bezt[a].vec[1][0]) vec[0]= bezt[a].vec[1][0]; diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 6ae556874bb..a5be056bc16 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -346,7 +346,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i if(a==0 && dl->type== DL_POLY) bezt= nu->bezt; if(prevbezt->h2==HD_VECT && bezt->h1==HD_VECT) { - VECCOPY(data, prevbezt->vec[1]); + copy_v3_v3(data, prevbezt->vec[1]); data+= 3; } else { @@ -363,7 +363,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i } if(a==0 && dl->type==DL_SEGM) { - VECCOPY(data, bezt->vec[1]); + copy_v3_v3(data, bezt->vec[1]); } prevbezt= bezt; @@ -404,7 +404,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, i a= len; bp= nu->bp; while(a--) { - VECCOPY(data, bp->vec); + copy_v3_v3(data, bp->vec); bp++; data+= 3; } @@ -486,7 +486,7 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal) totvert= 0; eve= fillvertbase.first; while(eve) { - VECCOPY(f1, eve->co); + copy_v3_v3(f1, eve->co); f1+= 3; /* index number */ @@ -559,7 +559,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) a= dl->parts; while(a--) { - VECCOPY(fp1, fp); + copy_v3_v3(fp1, fp); fp1+= 3; fp+= dpoly; } @@ -579,7 +579,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase) a= dl->parts; while(a--) { - VECCOPY(fp1, fp); + copy_v3_v3(fp1, fp); fp1+= 3; fp+= dpoly; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a493120e320..ae4e6ea81b8 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2120,7 +2120,7 @@ void object_set_dimensions(Object *ob, const float *value) } } -void minmax_object(Object *ob, float *min, float *max) +void minmax_object(Object *ob, float min[3], float max[3]) { BoundBox bb; float vec[3]; diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index e47dcd68ce1..3d788b40a17 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -469,7 +469,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) if(calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) { //Make the vertex stay on the front side of the face - VECADDFAC(tmp_co, nearest.co, nearest.no, calc->keepDist); + madd_v3_v3v3fl(tmp_co, nearest.co, nearest.no, calc->keepDist); } else { -- cgit v1.2.3 From d8717d2628b3b57f2c5a60a417806d903a531179 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 Nov 2011 15:39:20 +0000 Subject: more macro --> bli math lib replacements. --- source/blender/blenkernel/intern/DerivedMesh.c | 21 +++-- source/blender/blenkernel/intern/boids.c | 126 ++++++++++++------------- source/blender/blenkernel/intern/cloth.c | 2 +- source/blender/blenkernel/intern/effect.c | 24 ++--- source/blender/blenkernel/intern/fluidsim.c | 2 +- source/blender/blenkernel/intern/smoke.c | 83 ++++++++-------- source/blender/blenkernel/intern/softbody.c | 2 +- 7 files changed, 130 insertions(+), 130 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 0c99735f73e..aaed0381b2e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -292,7 +292,7 @@ void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb) mvert=dm->getVertDataArray(dm, CD_MVERT); for(a=0; atotelem; a++, fp+=3, mvert++) { - VECCOPY(fp, mvert->co); + copy_v3_v3(fp, mvert->co); } } @@ -604,12 +604,12 @@ static void emDM_drawUVEdges(DerivedMesh *dm) static void emDM__calcFaceCent(EditFace *efa, float cent[3], float (*vertexCos)[3]) { if (vertexCos) { - VECCOPY(cent, vertexCos[(int) efa->v1->tmp.l]); + copy_v3_v3(cent, vertexCos[(int) efa->v1->tmp.l]); add_v3_v3(cent, vertexCos[(int) efa->v2->tmp.l]); add_v3_v3(cent, vertexCos[(int) efa->v3->tmp.l]); if (efa->v4) add_v3_v3(cent, vertexCos[(int) efa->v4->tmp.l]); } else { - VECCOPY(cent, efa->v1->co); + copy_v3_v3(cent, efa->v1->co); add_v3_v3(cent, efa->v2->co); add_v3_v3(cent, efa->v3->co); if (efa->v4) add_v3_v3(cent, efa->v4->co); @@ -1184,7 +1184,7 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *vert_r) for(i = 0; i < index; ++i) ev = ev->next; - VECCOPY(vert_r->co, ev->co); + copy_v3_v3(vert_r->co, ev->co); normal_float_to_short_v3(vert_r->no, ev->no); @@ -1539,8 +1539,9 @@ static float *get_editmesh_orco_verts(EditMesh *em) orco = MEM_mallocN(sizeof(float)*3*totvert, "EditMesh Orco"); - for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3) - VECCOPY(orco+a, eve->co); + for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3) { + copy_v3_v3(orco+a, eve->co); + } return orco; } @@ -2146,7 +2147,7 @@ float (*editmesh_get_vertex_cos(EditMesh *em, int *numVerts_r))[3] cos = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos"); for (i=0,eve=em->verts.first; inext) { - VECCOPY(cos[i], eve->co); + copy_v3_v3(cos[i], eve->co); } return cos; @@ -2654,7 +2655,7 @@ static void GetPosition(const SMikkTSpaceContext * pContext, float fPos[], const //assert(vert_index>=0 && vert_index<4); SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; const float *co= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co; - VECCOPY(fPos, co); + copy_v3_v3(fPos, co); } static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[], const int face_num, const int vert_index) @@ -2680,7 +2681,7 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH); if(!smoothnormal) { // flat if(pMesh->precomputedFaceNormals) { - VECCOPY(fNorm, &pMesh->precomputedFaceNormals[3*face_num]); + copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3*face_num]); } else { MFace *mf= &pMesh->mface[face_num]; @@ -2707,7 +2708,7 @@ static void SetTSpace(const SMikkTSpaceContext * pContext, const float fvTangent //assert(vert_index>=0 && vert_index<4); SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData; float * pRes = pMesh->tangent[4*face_num+iVert]; - VECCOPY(pRes, fvTangent); + copy_v3_v3(pRes, fvTangent); pRes[3]=fSign; } diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index 3ae81c70d4f..c9868bd900f 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -162,7 +162,7 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, negate_v3_v3(efd.vec_to_point, bpa->gravity); } - VECCOPY(bbd->wanted_co, efd.vec_to_point); + copy_v3_v3(bbd->wanted_co, efd.vec_to_point); mul_v3_fl(bbd->wanted_co, mul); bbd->wanted_speed = val->max_speed * priority; @@ -204,7 +204,7 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * BVHTreeRayHit hit; float radius = val->personal_space * pa->size, ray_dir[3]; - VECCOPY(col.co1, pa->prev_state.co); + copy_v3_v3(col.co1, pa->prev_state.co); add_v3_v3v3(col.co2, pa->prev_state.co, pa->prev_state.vel); sub_v3_v3v3(ray_dir, col.co2, col.co1); mul_v3_fl(ray_dir, acbr->look_ahead); @@ -254,10 +254,10 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * { neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, acbr->look_ahead * len_v3(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); if(neighbors > 1) for(n=1; nprev_state.co); - VECCOPY(vel1, pa->prev_state.vel); - VECCOPY(co2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.co); - VECCOPY(vel2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.vel); + copy_v3_v3(co1, pa->prev_state.co); + copy_v3_v3(vel1, pa->prev_state.vel); + copy_v3_v3(co2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.co); + copy_v3_v3(vel2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.vel); sub_v3_v3v3(loc, co1, co2); @@ -270,8 +270,8 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * t = -dot_v3v3(loc, vec)/inp; /* cpa is not too far in the future so investigate further */ if(t > 0.0f && t < t_min) { - VECADDFAC(co1, co1, vel1, t); - VECADDFAC(co2, co2, vel2, t); + madd_v3_v3fl(co1, vel1, t); + madd_v3_v3fl(co2, vel2, t); sub_v3_v3v3(vec, co2, co1); @@ -300,10 +300,10 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * if(epsys) { neighbors = BLI_kdtree_range_search(epsys->tree, acbr->look_ahead * len_v3(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); if(neighbors > 0) for(n=0; nprev_state.co); - VECCOPY(vel1, pa->prev_state.vel); - VECCOPY(co2, (epsys->particles + ptn[n].index)->prev_state.co); - VECCOPY(vel2, (epsys->particles + ptn[n].index)->prev_state.vel); + copy_v3_v3(co1, pa->prev_state.co); + copy_v3_v3(vel1, pa->prev_state.vel); + copy_v3_v3(co2, (epsys->particles + ptn[n].index)->prev_state.co); + copy_v3_v3(vel2, (epsys->particles + ptn[n].index)->prev_state.vel); sub_v3_v3v3(loc, co1, co2); @@ -316,8 +316,8 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * t = -dot_v3v3(loc, vec)/inp; /* cpa is not too far in the future so investigate further */ if(t > 0.0f && t < t_min) { - VECADDFAC(co1, co1, vel1, t); - VECADDFAC(co2, co2, vel2, t); + madd_v3_v3fl(co1, vel1, t); + madd_v3_v3fl(co2, vel2, t); sub_v3_v3v3(vec, co2, co1); @@ -439,7 +439,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va len = len_v3(loc); /* too close to leader */ if(len < 2.0f * val->personal_space * pa->size) { - VECCOPY(bbd->wanted_co, loc); + copy_v3_v3(bbd->wanted_co, loc); bbd->wanted_speed = val->max_speed; return 1; } @@ -449,7 +449,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* possible blocking of leader in near future */ if(t > 0.0f && t < 3.0f) { - VECCOPY(vec2, vec); + copy_v3_v3(vec2, vec); mul_v3_fl(vec2, t); sub_v3_v3v3(vec2, loc, vec2); @@ -457,7 +457,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va len = len_v3(vec2); if(len < 2.0f * val->personal_space * pa->size) { - VECCOPY(bbd->wanted_co, vec2); + copy_v3_v3(bbd->wanted_co, vec2); bbd->wanted_speed = val->max_speed * (3.0f - t)/3.0f; return 1; } @@ -466,17 +466,17 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* not blocking so try to follow leader */ if(p && flbr->options & BRULE_LEADER_IN_LINE) { - VECCOPY(vec, bbd->sim->psys->particles[p-1].prev_state.vel); - VECCOPY(loc, bbd->sim->psys->particles[p-1].prev_state.co); + copy_v3_v3(vec, bbd->sim->psys->particles[p-1].prev_state.vel); + copy_v3_v3(loc, bbd->sim->psys->particles[p-1].prev_state.co); } else { - VECCOPY(loc, flbr->oloc); + copy_v3_v3(loc, flbr->oloc); sub_v3_v3v3(vec, flbr->loc, flbr->oloc); mul_v3_fl(vec, 1.0f/bbd->timestep); } /* fac is seconds behind leader */ - VECADDFAC(loc, loc, vec, -flbr->distance); + madd_v3_v3fl(loc, vec, -flbr->distance); sub_v3_v3v3(bbd->wanted_co, loc, pa->prev_state.co); bbd->wanted_speed = len_v3(bbd->wanted_co); @@ -488,7 +488,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* first check we're not blocking any leaders */ for(i = 0; i< bbd->sim->psys->totpart; i+=n){ - VECCOPY(vec, bbd->sim->psys->particles[i].prev_state.vel); + copy_v3_v3(vec, bbd->sim->psys->particles[i].prev_state.vel); sub_v3_v3v3(loc, pa->prev_state.co, bbd->sim->psys->particles[i].prev_state.co); @@ -499,7 +499,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va len = len_v3(loc); /* too close to leader */ if(len < 2.0f * val->personal_space * pa->size) { - VECCOPY(bbd->wanted_co, loc); + copy_v3_v3(bbd->wanted_co, loc); bbd->wanted_speed = val->max_speed; return 1; } @@ -509,7 +509,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* possible blocking of leader in near future */ if(t > 0.0f && t < t_min) { - VECCOPY(vec2, vec); + copy_v3_v3(vec2, vec); mul_v3_fl(vec2, t); sub_v3_v3v3(vec2, loc, vec2); @@ -518,7 +518,7 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va if(len < 2.0f * val->personal_space * pa->size) { t_min = t; - VECCOPY(bbd->wanted_co, loc); + copy_v3_v3(bbd->wanted_co, loc); bbd->wanted_speed = val->max_speed * (3.0f - t)/3.0f; ret = 1; } @@ -530,16 +530,16 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* not blocking so try to follow leader */ if(flbr->options & BRULE_LEADER_IN_LINE) { - VECCOPY(vec, bbd->sim->psys->particles[p-1].prev_state.vel); - VECCOPY(loc, bbd->sim->psys->particles[p-1].prev_state.co); + copy_v3_v3(vec, bbd->sim->psys->particles[p-1].prev_state.vel); + copy_v3_v3(loc, bbd->sim->psys->particles[p-1].prev_state.co); } else { - VECCOPY(vec, bbd->sim->psys->particles[p - p%n].prev_state.vel); - VECCOPY(loc, bbd->sim->psys->particles[p - p%n].prev_state.co); + copy_v3_v3(vec, bbd->sim->psys->particles[p - p%n].prev_state.vel); + copy_v3_v3(loc, bbd->sim->psys->particles[p - p%n].prev_state.co); } /* fac is seconds behind leader */ - VECADDFAC(loc, loc, vec, -flbr->distance); + madd_v3_v3fl(loc, vec, -flbr->distance); sub_v3_v3v3(bbd->wanted_co, loc, pa->prev_state.co); bbd->wanted_speed = len_v3(bbd->wanted_co); @@ -563,11 +563,11 @@ static int rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *va normalize_v3(bpa->wander); - VECCOPY(vec, bpa->wander); + copy_v3_v3(vec, bpa->wander); mul_qt_v3(pa->prev_state.rot, vec); - VECCOPY(bbd->wanted_co, pa->prev_state.ave); + copy_v3_v3(bbd->wanted_co, pa->prev_state.ave); mul_v3_fl(bbd->wanted_co, 1.1f); @@ -581,7 +581,7 @@ static int rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *va } } else { - VECCOPY(bbd->wanted_co, pa->prev_state.ave); + copy_v3_v3(bbd->wanted_co, pa->prev_state.ave); /* may happen at birth */ if(dot_v2v2(bbd->wanted_co,bbd->wanted_co)==0.0f) { @@ -643,7 +643,7 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti health += bpa->data.health; if(n==0 && pt->mode==PTARGET_MODE_ENEMY && ptn[n].dist < closest_dist) { - VECCOPY(closest_enemy, ptn[n].co); + copy_v3_v3(closest_enemy, ptn[n].co); closest_dist = ptn[n].dist; enemy_pa = epars + ptn[n].index; } @@ -741,7 +741,7 @@ static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData * } } -static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *ground_co, float *ground_nor) +static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float ground_co[3], float ground_nor[3]) { BoidParticle *bpa = pa->boid; @@ -820,7 +820,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro } /* default to z=0 */ - VECCOPY(ground_co, pa->state.co); + copy_v3_v3(ground_co, pa->state.co); ground_co[2] = 0; ground_nor[0] = ground_nor[1] = 0.0f; ground_nor[2] = 1.0f; @@ -853,8 +853,8 @@ void boids_precalc_rules(ParticleSettings *part, float cfra) if(flbr->ob && flbr->cfra != cfra) { /* save object locations for velocity calculations */ - VECCOPY(flbr->oloc, flbr->loc); - VECCOPY(flbr->loc, flbr->ob->obmat[3]); + copy_v3_v3(flbr->oloc, flbr->loc); + copy_v3_v3(flbr->loc, flbr->ob->obmat[3]); flbr->cfra = cfra; } } @@ -868,7 +868,7 @@ static void boid_climb(BoidSettings *boids, ParticleData *pa, float *surface_co, copy_v3_v3(nor, surface_nor); /* gather apparent gravity */ - VECADDFAC(bpa->gravity, bpa->gravity, surface_nor, -1.0f); + madd_v3_v3fl(bpa->gravity, surface_nor, -1.0f); normalize_v3(bpa->gravity); /* raise boid it's size from surface */ @@ -997,7 +997,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) wanted_speed /= (float)n; } - VECCOPY(bbd->wanted_co, wanted_co); + copy_v3_v3(bbd->wanted_co, wanted_co); bbd->wanted_speed = wanted_speed; break; } @@ -1012,10 +1012,10 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) if(boids->options & BOID_ALLOW_FLIGHT && bbd->wanted_co[2] > 0.0f) { float cvel[3], dir[3]; - VECCOPY(dir, pa->prev_state.ave); + copy_v3_v3(dir, pa->prev_state.ave); normalize_v2(dir); - VECCOPY(cvel, bbd->wanted_co); + copy_v3_v3(cvel, bbd->wanted_co); normalize_v2(cvel); if(dot_v2v2(cvel, dir) > 0.95f / mul) @@ -1031,10 +1031,10 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) float z_v, ground_v, cur_v; float len; - VECCOPY(dir, pa->prev_state.ave); + copy_v3_v3(dir, pa->prev_state.ave); normalize_v2(dir); - VECCOPY(cvel, bbd->wanted_co); + copy_v3_v3(cvel, bbd->wanted_co); normalize_v2(cvel); len = len_v2(pa->prev_state.vel); @@ -1054,7 +1054,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) len = MIN2(len, val.jump_speed); - VECCOPY(jump_v, dir); + copy_v3_v3(jump_v, dir); jump_v[2] = z_v; mul_v3_fl(jump_v, ground_v); @@ -1071,7 +1071,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) } if(jump) { - VECCOPY(pa->prev_state.vel, jump_v); + copy_v3_v3(pa->prev_state.vel, jump_v); bpa->data.mode = eBoidMode_Falling; } } @@ -1143,12 +1143,12 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) } } - VECCOPY(old_dir, pa->prev_state.ave); + copy_v3_v3(old_dir, pa->prev_state.ave); new_speed = normalize_v3_v3(wanted_dir, bbd->wanted_co); /* first check if we have valid direction we want to go towards */ if(new_speed == 0.0f) { - VECCOPY(new_dir, old_dir); + copy_v3_v3(new_dir, old_dir); } else { float old_dir2[2], wanted_dir2[2], nor[3], angle; @@ -1172,13 +1172,13 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) cross_v3_v3v3(nor, old_dir, wanted_dir); axis_angle_to_quat( q,nor, angle); - VECCOPY(new_dir, old_dir); + copy_v3_v3(new_dir, old_dir); mul_qt_v3(q, new_dir); normalize_v3(new_dir); /* save direction in case resulting velocity too small */ axis_angle_to_quat( q,nor, angle*dtime); - VECCOPY(pa->state.ave, old_dir); + copy_v3_v3(pa->state.ave, old_dir); mul_qt_v3(q, pa->state.ave); normalize_v3(pa->state.ave); } @@ -1192,7 +1192,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) new_speed = MIN2(bbd->wanted_speed, old_speed + val.max_acc); /* combine direction and speed */ - VECCOPY(new_vel, new_dir); + copy_v3_v3(new_vel, new_dir); mul_v3_fl(new_vel, new_speed); /* maintain minimum flying velocity if not landing */ @@ -1236,7 +1236,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) add_v3_v3(acc, force); /* store smoothed acceleration for nice banking etc. */ - VECADDFAC(bpa->data.acc, bpa->data.acc, acc, dtime); + madd_v3_v3fl(bpa->data.acc, acc, dtime); mul_v3_fl(bpa->data.acc, 1.0f / (1.0f + dtime)); /* integrate new location & velocity */ @@ -1245,15 +1245,15 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* can get better control allthough it's a bit unphysical */ mul_v3_fl(acc, 1.0f/pa_mass); - VECCOPY(dvec, acc); + copy_v3_v3(dvec, acc); mul_v3_fl(dvec, dtime*dtime*0.5f); - VECCOPY(bvec, pa->prev_state.vel); + copy_v3_v3(bvec, pa->prev_state.vel); mul_v3_fl(bvec, dtime); add_v3_v3(dvec, bvec); add_v3_v3(pa->state.co, dvec); - VECADDFAC(pa->state.vel, pa->state.vel, acc, dtime); + madd_v3_v3fl(pa->state.vel, acc, dtime); //if(bpa->data.mode != eBoidMode_InAir) bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor); @@ -1274,11 +1274,11 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) sub_v3_v3v3(dvec, bpa->data.acc, dvec); } else { - VECCOPY(dvec, bpa->data.acc); + copy_v3_v3(dvec, bpa->data.acc); } /* gather apparent gravity */ - VECADDFAC(bpa->gravity, grav, dvec, -boids->banking); + madd_v3_v3v3fl(bpa->gravity, grav, dvec, -boids->banking); normalize_v3(bpa->gravity); /* stick boid on goal when close enough */ @@ -1313,7 +1313,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* gather apparent gravity */ - VECADDFAC(bpa->gravity, bpa->gravity, grav, dtime); + madd_v3_v3fl(bpa->gravity, grav, dtime); normalize_v3(bpa->gravity); if(boids->options & BOID_ALLOW_LAND) { @@ -1345,7 +1345,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) //copy_v3_v3(nor, ground_nor); ///* gather apparent gravity to r_ve */ - //VECADDFAC(pa->r_ve, pa->r_ve, ground_nor, -1.0); + //madd_v3_v3fl(pa->r_ve, ground_nor, -1.0); //normalize_v3(pa->r_ve); ///* raise boid it's size from surface */ @@ -1385,12 +1385,12 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) sub_v3_v3v3(dvec, bpa->data.acc, dvec); /* gather apparent gravity */ - VECADDFAC(bpa->gravity, grav, dvec, -boids->banking); + madd_v3_v3v3fl(bpa->gravity, grav, dvec, -boids->banking); normalize_v3(bpa->gravity); } else { /* gather negative surface normal */ - VECADDFAC(bpa->gravity, bpa->gravity, ground_nor, -1.0f); + madd_v3_v3fl(bpa->gravity, ground_nor, -1.0f); normalize_v3(bpa->gravity); } break; @@ -1411,7 +1411,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* calculate rotation matrix based on forward & down vectors */ if(bpa->data.mode == eBoidMode_InAir) { - VECCOPY(mat[0], pa->state.ave); + copy_v3_v3(mat[0], pa->state.ave); project_v3_v3v3(dvec, bpa->gravity, pa->state.ave); sub_v3_v3v3(mat[2], bpa->gravity, dvec); @@ -1422,7 +1422,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) sub_v3_v3v3(mat[0], pa->state.ave, dvec); normalize_v3(mat[0]); - VECCOPY(mat[2], bpa->gravity); + copy_v3_v3(mat[2], bpa->gravity); } negate_v3(mat[2]); cross_v3_v3v3(mat[1], mat[2], mat[0]); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 444d17ad004..f917a0fe68c 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -190,7 +190,7 @@ static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float eps // fill tree for(i = 0; i < cloth->numverts; i++, verts++) { - VECCOPY(&co[0*3], verts->xold); + copy_v3_v3(&co[0*3], verts->xold); BLI_bvhtree_insert(bvhtree, i, co, 1); } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index bb14a1ddeaf..7b58c0bc00b 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -555,7 +555,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU if(falloff == 0.0f) break; - VECADDFAC(temp, efd->vec_to_point, efd->nor, -fac); + madd_v3_v3v3fl(temp, efd->vec_to_point, efd->nor, -fac); r_fac= len_v3(temp); falloff*= falloff_func_rad(eff->pd, r_fac); break; @@ -573,7 +573,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU return falloff; } -int closest_point_on_surface(SurfaceModifierData *surmd, float *co, float *surface_co, float *surface_nor, float *surface_vel) +int closest_point_on_surface(SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3]) { BVHTreeNearest nearest; @@ -797,7 +797,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP if(eff->pd->flag & PFIELD_TEX_2D) { float fac=-dot_v3v3(tex_co, efd->nor); - VECADDFAC(tex_co, tex_co, efd->nor, fac); + madd_v3_v3fl(tex_co, efd->nor, fac); } if(eff->pd->flag & PFIELD_TEX_OBJECT) { @@ -848,7 +848,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP if(eff->pd->flag & PFIELD_TEX_2D){ float fac = -dot_v3v3(force, efd->nor); - VECADDFAC(force, force, efd->nor, fac); + madd_v3_v3fl(force, efd->nor, fac); } add_v3_v3(total_force, force); @@ -897,7 +897,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected cross_v3_v3v3(force, efd->nor2, temp); mul_v3_fl(force, strength * efd->falloff); - VECADDFAC(temp, temp, point->vel, -point->vel_to_sec); + madd_v3_v3fl(temp, point->vel, -point->vel_to_sec); add_v3_v3(force, temp); } break; @@ -940,7 +940,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected copy_v3_v3(temp, point->loc); } else { - VECADD(temp, efd->vec_to_point2, efd->nor2); + add_v3_v3v3(temp, efd->vec_to_point2, efd->nor2); } force[0] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[0], temp[1], temp[2], 2,0,2); force[1] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[1], temp[2], temp[0], 2,0,2); @@ -959,10 +959,10 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected } if(pd->flag & PFIELD_DO_LOCATION) { - VECADDFAC(total_force, total_force, force, 1.0f/point->vel_to_sec); + madd_v3_v3fl(total_force, force, 1.0f/point->vel_to_sec); if(ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG)==0 && pd->f_flow != 0.0f) { - VECADDFAC(total_force, total_force, point->vel, -pd->f_flow * efd->falloff); + madd_v3_v3fl(total_force, point->vel, -pd->f_flow * efd->falloff); } } @@ -972,7 +972,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected mul_qt_v3(point->rot, xvec); cross_v3_v3v3(dave, xvec, force); if(pd->f_flow != 0.0f) { - VECADDFAC(dave, dave, point->ave, -pd->f_flow * efd->falloff); + madd_v3_v3fl(dave, point->ave, -pd->f_flow * efd->falloff); } add_v3_v3(point->ave, dave); } @@ -1038,14 +1038,14 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we // for softbody backward compatibility if(point->flag & PE_WIND_AS_SPEED && impulse){ - VECSUB(temp2, force, temp1); - VECSUB(impulse, impulse, temp2); + sub_v3_v3v3(temp2, force, temp1); + sub_v3_v3v3(impulse, impulse, temp2); } } } else if(eff->flag & PE_VELOCITY_TO_IMPULSE && impulse) { /* special case for harmonic effector */ - VECADD(impulse, impulse, efd.vel); + add_v3_v3v3(impulse, impulse, efd.vel); } } } diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index bf432785064..cdb2b194b43 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -92,7 +92,7 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob, *numVertices = totvert; verts = MEM_callocN( totvert*3*sizeof(float), "elbeemmesh_vertices"); for(i=0; iobmat, &verts[i*3]); } } *vertices = verts; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 7174126a00c..60941ef78a3 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -172,7 +172,7 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, { float tmp[3]; - VECCOPY(tmp, verts[i].co); + copy_v3_v3(tmp, verts[i].co); mul_m4_v3(ob->obmat, tmp); // min BB @@ -186,11 +186,11 @@ static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, max[2] = MAX2(max[2], tmp[2]); } - VECCOPY(smd->domain->p0, min); - VECCOPY(smd->domain->p1, max); + copy_v3_v3(smd->domain->p0, min); + copy_v3_v3(smd->domain->p1, max); // calc other res with max_res provided - VECSUB(size, max, min); + sub_v3_v3v3(size, max, min); // printf("size: %f, %f, %f\n", size[0], size[1], size[2]); @@ -354,9 +354,9 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) for(i = 0; i < dm->getNumVerts(dm); i++) { float tmpvec[3]; - VECCOPY(tmpvec, mvert[i].co); + copy_v3_v3(tmpvec, mvert[i].co); mul_m4_v3(ob->obmat, tmpvec); - VECCOPY(&scs->points[i * 3], tmpvec); + copy_v3_v3(&scs->points[i * 3], tmpvec); } for(i = 0, facecounter = 0; i < dm->getNumFaces(dm); i++) @@ -372,18 +372,18 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) if(again == 1 && mface[i].v4) { - VECSUB(side1, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); - VECSUB(side2, mvert[ mface[i].v4 ].co, mvert[ mface[i].v1 ].co); + sub_v3_v3v3(side1, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); + sub_v3_v3v3(side2, mvert[ mface[i].v4 ].co, mvert[ mface[i].v1 ].co); } else { - VECSUB(side1, mvert[ mface[i].v2 ].co, mvert[ mface[i].v1 ].co); - VECSUB(side2, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); + sub_v3_v3v3(side1, mvert[ mface[i].v2 ].co, mvert[ mface[i].v1 ].co); + sub_v3_v3v3(side2, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); } cross_v3_v3v3(trinormorg, side1, side2); normalize_v3(trinormorg); - VECCOPY(trinorm, trinormorg); + copy_v3_v3(trinorm, trinormorg); mul_v3_fl(trinorm, 0.25 * cell_len); for(j = 0; j <= divs1; j++) @@ -401,43 +401,42 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) continue; } - VECCOPY(p1, mvert[ mface[i].v1 ].co); + copy_v3_v3(p1, mvert[ mface[i].v1 ].co); if(again == 1 && mface[i].v4) { - VECCOPY(p2, mvert[ mface[i].v3 ].co); - VECCOPY(p3, mvert[ mface[i].v4 ].co); + copy_v3_v3(p2, mvert[ mface[i].v3 ].co); + copy_v3_v3(p3, mvert[ mface[i].v4 ].co); } else { - VECCOPY(p2, mvert[ mface[i].v2 ].co); - VECCOPY(p3, mvert[ mface[i].v3 ].co); + copy_v3_v3(p2, mvert[ mface[i].v2 ].co); + copy_v3_v3(p3, mvert[ mface[i].v3 ].co); } mul_v3_fl(p1, (1.0-uf-vf)); mul_v3_fl(p2, uf); mul_v3_fl(p3, vf); - VECADD(p, p1, p2); - VECADD(p, p, p3); + add_v3_v3v3(p, p1, p2); + add_v3_v3(p, p3); if(newdivs > divs) printf("mem problem\n"); // mMovPoints.push_back(p + trinorm); - VECCOPY(tmpvec, p); - VECADD(tmpvec, tmpvec, trinorm); + add_v3_v3v3(tmpvec, p, trinorm); mul_m4_v3(ob->obmat, tmpvec); - VECCOPY(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); + copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; if(newdivs > divs) printf("mem problem\n"); // mMovPoints.push_back(p - trinorm); - VECCOPY(tmpvec, p); - VECSUB(tmpvec, tmpvec, trinorm); + copy_v3_v3(tmpvec, p); + sub_v3_v3(tmpvec, trinorm); mul_m4_v3(ob->obmat, tmpvec); - VECCOPY(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); + copy_v3_v3(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; } } @@ -488,23 +487,23 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa float side3[3]; int divs1=0, divs2=0, divs3=0; - VECCOPY(p0, verts[faces[i].v1].co); + copy_v3_v3(p0, verts[faces[i].v1].co); mul_m4_v3(ob->obmat, p0); - VECCOPY(p1, verts[faces[i].v2].co); + copy_v3_v3(p1, verts[faces[i].v2].co); mul_m4_v3(ob->obmat, p1); - VECCOPY(p2, verts[faces[i].v3].co); + copy_v3_v3(p2, verts[faces[i].v3].co); mul_m4_v3(ob->obmat, p2); - VECSUB(side1, p1, p0); - VECSUB(side2, p2, p0); - VECSUB(side3, p1, p2); + sub_v3_v3v3(side1, p1, p0); + sub_v3_v3v3(side2, p2, p0); + sub_v3_v3v3(side3, p1, p2); - if(INPR(side1, side1) > fsTri*fsTri) + if(dot_v3v3(side1, side1) > fsTri*fsTri) { float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } - if(INPR(side2, side2) > fsTri*fsTri) + if(dot_v3v3(side2, side2) > fsTri*fsTri) { float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); @@ -527,23 +526,23 @@ static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFa facecounter++; - VECCOPY(p0, verts[faces[i].v3].co); + copy_v3_v3(p0, verts[faces[i].v3].co); mul_m4_v3(ob->obmat, p0); - VECCOPY(p1, verts[faces[i].v4].co); + copy_v3_v3(p1, verts[faces[i].v4].co); mul_m4_v3(ob->obmat, p1); - VECCOPY(p2, verts[faces[i].v1].co); + copy_v3_v3(p2, verts[faces[i].v1].co); mul_m4_v3(ob->obmat, p2); - VECSUB(side1, p1, p0); - VECSUB(side2, p2, p0); - VECSUB(side3, p1, p2); + sub_v3_v3v3(side1, p1, p0); + sub_v3_v3v3(side2, p2, p0); + sub_v3_v3v3(side3, p1, p2); - if(INPR(side1, side1) > fsTri*fsTri) + if(dot_v3v3(side1, side1) > fsTri*fsTri) { float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } - if(INPR(side2, side2) > fsTri*fsTri) + if(dot_v3v3(side2, side2) > fsTri*fsTri) { float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); @@ -1050,7 +1049,7 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) if(psys_get_particle_state(&sim, p, &state, 0) == 0) continue; - // VECCOPY(pos, pa->state.co); + // copy_v3_v3(pos, pa->state.co); // mul_m4_v3(ob->imat, pos); // 1. get corresponding cell get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, state.co, cell, 0); @@ -1589,7 +1588,7 @@ static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int { float tmp[3]; - VECSUB(tmp, pos, p0); + sub_v3_v3v3(tmp, pos, p0); mul_v3_fl(tmp, 1.0 / dx); if(correct) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 28925a7b170..accf3e442e8 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2697,7 +2697,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa /* gravitation */ - VECADDFAC(bp->force, bp->force, gravity, _final_mass(ob,bp)); /* individual mass of node here */ + madd_v3_v3fl(bp->force, gravity, _final_mass(ob,bp)); /* individual mass of node here */ /* particle field & vortex */ -- cgit v1.2.3 From 85540d5aa7abb487e546b5483fffeef2e6075af5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 Nov 2011 16:38:21 +0000 Subject: more macro --> BLI math lib, mainly replace VECCOPY in render and blenkernel. --- source/blender/blenkernel/intern/bvhutils.c | 4 +- source/blender/blenkernel/intern/cloth.c | 62 +++-- source/blender/blenkernel/intern/particle.c | 4 +- source/blender/blenkernel/intern/particle_system.c | 42 ++-- source/blender/blenkernel/intern/softbody.c | 270 ++++++++++----------- source/blender/blenkernel/intern/subsurf_ccg.c | 2 +- source/blender/blenkernel/intern/texture.c | 2 +- 7 files changed, 190 insertions(+), 196 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 93abad8858f..1a27a640797 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -384,8 +384,8 @@ static float nearest_point_in_tri_surface(const float v0[3], const float v1[3], mul_v3_fl(x, S); copy_v3_v3(y, e1); mul_v3_fl(y, T); - VECADD(z, w, x); - VECADD(z, z, y); + add_v3_v3v3(z, w, x); + add_v3_v3v3(z, z, y); //sub_v3_v3v3(d, p, z); copy_v3_v3(nearest, z); // d = p - ( v0 + S * e0 + T * e1 ); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index f917a0fe68c..ae6a6ec012a 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -231,12 +231,12 @@ static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float epsilon // fill tree for(i = 0; i < cloth->numfaces; i++, mfaces++) { - VECCOPY(&co[0*3], verts[mfaces->v1].xold); - VECCOPY(&co[1*3], verts[mfaces->v2].xold); - VECCOPY(&co[2*3], verts[mfaces->v3].xold); + copy_v3_v3(&co[0*3], verts[mfaces->v1].xold); + copy_v3_v3(&co[1*3], verts[mfaces->v2].xold); + copy_v3_v3(&co[2*3], verts[mfaces->v3].xold); if(mfaces->v4) - VECCOPY(&co[3*3], verts[mfaces->v4].xold); + copy_v3_v3(&co[3*3], verts[mfaces->v4].xold); BLI_bvhtree_insert(bvhtree, i, co, (mfaces->v4 ? 4 : 3)); } @@ -267,23 +267,23 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving) { for(i = 0; i < cloth->numfaces; i++, mfaces++) { - VECCOPY(&co[0*3], verts[mfaces->v1].txold); - VECCOPY(&co[1*3], verts[mfaces->v2].txold); - VECCOPY(&co[2*3], verts[mfaces->v3].txold); + copy_v3_v3(&co[0*3], verts[mfaces->v1].txold); + copy_v3_v3(&co[1*3], verts[mfaces->v2].txold); + copy_v3_v3(&co[2*3], verts[mfaces->v3].txold); if(mfaces->v4) - VECCOPY(&co[3*3], verts[mfaces->v4].txold); + copy_v3_v3(&co[3*3], verts[mfaces->v4].txold); // copy new locations into array if(moving) { // update moving positions - VECCOPY(&co_moving[0*3], verts[mfaces->v1].tx); - VECCOPY(&co_moving[1*3], verts[mfaces->v2].tx); - VECCOPY(&co_moving[2*3], verts[mfaces->v3].tx); + copy_v3_v3(&co_moving[0*3], verts[mfaces->v1].tx); + copy_v3_v3(&co_moving[1*3], verts[mfaces->v2].tx); + copy_v3_v3(&co_moving[2*3], verts[mfaces->v3].tx); if(mfaces->v4) - VECCOPY(&co_moving[3*3], verts[mfaces->v4].tx); + copy_v3_v3(&co_moving[3*3], verts[mfaces->v4].tx); ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, (mfaces->v4 ? 4 : 3)); } @@ -321,13 +321,13 @@ void bvhselftree_update_from_cloth(ClothModifierData *clmd, int moving) { for(i = 0; i < cloth->numverts; i++, verts++) { - VECCOPY(&co[0*3], verts->txold); + copy_v3_v3(&co[0*3], verts->txold); // copy new locations into array if(moving) { // update moving positions - VECCOPY(&co_moving[0*3], verts->tx); + copy_v3_v3(&co_moving[0*3], verts->tx); ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, 1); } @@ -399,11 +399,11 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul /* force any pinned verts to their constrained location. */ for(i = 0; i < clmd->clothObject->numverts; i++, verts++) { /* save the previous position. */ - VECCOPY(verts->xold, verts->xconst); - VECCOPY(verts->txold, verts->x); + copy_v3_v3(verts->xold, verts->xconst); + copy_v3_v3(verts->txold, verts->x); /* Get the current position. */ - VECCOPY(verts->xconst, mvert[i].co); + copy_v3_v3(verts->xconst, mvert[i].co); mul_m4_v3(ob->obmat, verts->xconst); } @@ -712,7 +712,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh * for (i = 0; i < numverts; i++) { - VECCOPY (mvert[i].co, cloth->verts[i].x); + copy_v3_v3 (mvert[i].co, cloth->verts[i].x); mul_m4_v3(ob->imat, mvert[i].co); /* cloth is in global coords */ } } @@ -880,14 +880,14 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d verts->goal= 0.0f; verts->flags = 0; - VECCOPY ( verts->xold, verts->x ); - VECCOPY ( verts->xconst, verts->x ); - VECCOPY ( verts->txold, verts->x ); - VECCOPY ( verts->tx, verts->x ); + copy_v3_v3 ( verts->xold, verts->x ); + copy_v3_v3 ( verts->xconst, verts->x ); + copy_v3_v3 ( verts->txold, verts->x ); + copy_v3_v3 ( verts->tx, verts->x ); mul_v3_fl( verts->v, 0.0f ); verts->impulse_count = 0; - VECCOPY ( verts->impulse, tnull ); + copy_v3_v3 ( verts->impulse, tnull ); } // apply / set vertex groups @@ -1053,7 +1053,6 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) LinkNode **edgelist = NULL; EdgeHash *edgehash = NULL; LinkNode *search = NULL, *search2 = NULL; - float temp[3]; // error handling if ( numedges==0 ) @@ -1086,8 +1085,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) { spring->ij = MIN2(medge[i].v1, medge[i].v2); spring->kl = MAX2(medge[i].v2, medge[i].v1); - VECSUB ( temp, cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest ); - spring->restlen = sqrt ( INPR ( temp, temp ) ); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); clmd->sim_parms->avg_spring_len += spring->restlen; cloth->verts[spring->ij].avg_spring_len += spring->restlen; cloth->verts[spring->kl].avg_spring_len += spring->restlen; @@ -1132,8 +1130,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->ij = MIN2(mface[i].v1, mface[i].v3); spring->kl = MAX2(mface[i].v3, mface[i].v1); - VECSUB ( temp, cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest ); - spring->restlen = sqrt ( INPR ( temp, temp ) ); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); spring->type = CLOTH_SPRING_TYPE_SHEAR; spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0; @@ -1155,8 +1152,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->ij = MIN2(mface[i].v2, mface[i].v4); spring->kl = MAX2(mface[i].v4, mface[i].v2); - VECSUB ( temp, cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest ); - spring->restlen = sqrt ( INPR ( temp, temp ) ); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); spring->type = CLOTH_SPRING_TYPE_SHEAR; spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0; @@ -1197,8 +1193,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->ij = MIN2(tspring2->ij, index2); spring->kl = MAX2(tspring2->ij, index2); - VECSUB ( temp, cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest ); - spring->restlen = sqrt ( INPR ( temp, temp ) ); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); spring->type = CLOTH_SPRING_TYPE_BENDING; spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0; BLI_edgehash_insert ( edgehash, spring->ij, spring->kl, NULL ); @@ -1237,8 +1232,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->ij = tspring2->ij; spring->kl = tspring->kl; - VECSUB ( temp, cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest ); - spring->restlen = sqrt ( INPR ( temp, temp ) ); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); spring->type = CLOTH_SPRING_TYPE_BENDING; spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0; bend_springs++; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 3b6fc09ad4f..56e4c91ba5e 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -1663,7 +1663,7 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_ return 0; *mapindex = index; - QUATCOPY(mapfw, fw); + copy_v4_v4(mapfw, fw); } } else { /* for other meshes that have been modified, we try to map the particle @@ -2835,7 +2835,7 @@ static void cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache * angle, since floating point accuracy makes it give * different results across platforms */ if(cosangle > 0.999999f) { - QUATCOPY(key1->rot, key2->rot); + copy_v4_v4(key1->rot, key2->rot); } else { angle= saacos(cosangle); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index f92fb4444cc..3e88fb7d65e 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -815,7 +815,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch normalize_v3(nor); mul_v3_fl(nor,-100.0); - VECADD(co2,co1,nor); + add_v3_v3v3(co2,co1,nor); min_d=2.0; intersect=0; @@ -1099,11 +1099,11 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D for(p=0; pdata, &co, 1, 1); } else - VECCOPY(co,mv[p].co) + copy_v3_v3(co,mv[p].co); BLI_kdtree_insert(tree,p,co,NULL); } @@ -1141,14 +1141,14 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D MFace *mf=dm->getFaceData(dm,i,CD_MFACE); if(orcodata) { - VECCOPY(co1, orcodata[mf->v1]); - VECCOPY(co2, orcodata[mf->v2]); - VECCOPY(co3, orcodata[mf->v3]); + copy_v3_v3(co1, orcodata[mf->v1]); + copy_v3_v3(co2, orcodata[mf->v2]); + copy_v3_v3(co3, orcodata[mf->v3]); transform_mesh_orco_verts((Mesh*)ob->data, &co1, 1, 1); transform_mesh_orco_verts((Mesh*)ob->data, &co2, 1, 1); transform_mesh_orco_verts((Mesh*)ob->data, &co3, 1, 1); if(mf->v4) { - VECCOPY(co4, orcodata[mf->v4]); + copy_v3_v3(co4, orcodata[mf->v4]); transform_mesh_orco_verts((Mesh*)ob->data, &co4, 1, 1); } } @@ -1156,12 +1156,12 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D v1= (MVert*)dm->getVertData(dm,mf->v1,CD_MVERT); v2= (MVert*)dm->getVertData(dm,mf->v2,CD_MVERT); v3= (MVert*)dm->getVertData(dm,mf->v3,CD_MVERT); - VECCOPY(co1, v1->co); - VECCOPY(co2, v2->co); - VECCOPY(co3, v3->co); + copy_v3_v3(co1, v1->co); + copy_v3_v3(co2, v2->co); + copy_v3_v3(co3, v3->co); if(mf->v4) { v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT); - VECCOPY(co4, v4->co); + copy_v3_v3(co4, v4->co); } } @@ -1648,7 +1648,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P normalize_v3(state->ave); } else { - VECCOPY(state->ave, nor); + copy_v3_v3(state->ave, nor); } /* calculate rotation matrix */ @@ -2423,7 +2423,7 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa pfr.element_size = MAXFLOAT; } sphdata->element_size = pfr.element_size; - VECCOPY(sphdata->flow, pfr.flow); + copy_v3_v3(sphdata->flow, pfr.flow); pressure = stiffness * (pfr.density - rest_density); near_pressure = stiffness_near_fac * pfr.near_density; @@ -2520,7 +2520,7 @@ static void sph_integrate(ParticleSimulationData *sim, ParticleData *pa, float d integrate_particle(part, pa, dtime, effector_acceleration, sph_force_cb, &sphdata); *element_size = sphdata.element_size; - VECCOPY(flow, sphdata.flow); + copy_v3_v3(flow, sphdata.flow); } /************************************************/ @@ -2592,19 +2592,19 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa if(part->dampfac != 0.f) mul_v3_fl(pa->state.vel, 1.f - part->dampfac * efdata.ptex.damp * 25.f * dtime); - //VECCOPY(pa->state.ave, states->ave); + //copy_v3_v3(pa->state.ave, states->ave); /* finally we do guides */ time=(cfra-pa->time)/pa->lifetime; CLAMP(time, 0.0f, 1.0f); - VECCOPY(tkey.co,pa->state.co); - VECCOPY(tkey.vel,pa->state.vel); + copy_v3_v3(tkey.co,pa->state.co); + copy_v3_v3(tkey.vel,pa->state.vel); tkey.time=pa->state.time; if(part->type != PART_HAIR) { if(do_guides(sim->psys->effectors, &tkey, p, time)) { - VECCOPY(pa->state.co,tkey.co); + copy_v3_v3(pa->state.co,tkey.co); /* guides don't produce valid velocity */ sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co); mul_v3_fl(pa->state.vel,1.0f/dtime); @@ -3472,8 +3472,8 @@ static void do_hair_dynamics(ParticleSimulationData *sim) if(k==0) { float temp[3]; sub_v3_v3v3(temp, key->co, (key+1)->co); - VECCOPY(mvert->co, key->co); - VECADD(mvert->co, mvert->co, temp); + copy_v3_v3(mvert->co, key->co); + add_v3_v3v3(mvert->co, mvert->co, temp); mul_m4_v3(hairmat, mvert->co); mvert++; @@ -3492,7 +3492,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) } } - VECCOPY(mvert->co, key->co); + copy_v3_v3(mvert->co, key->co); mul_m4_v3(hairmat, mvert->co); mvert++; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index accf3e442e8..5b02731050e 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -321,7 +321,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) /* determine the ortho BB */ for(i=0; i < pccd_M->totvert; i++){ /* evaluate limits */ - VECCOPY(v,pccd_M->mvert[i].co); + copy_v3_v3(v,pccd_M->mvert[i].co); pccd_M->bbmin[0] = MIN2(pccd_M->bbmin[0],v[0]-hull); pccd_M->bbmin[1] = MIN2(pccd_M->bbmin[1],v[1]-hull); pccd_M->bbmin[2] = MIN2(pccd_M->bbmin[2],v[2]-hull); @@ -345,7 +345,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->minx=mima->miny=mima->minz=1e30f; mima->maxx=mima->maxy=mima->maxz=-1e30f; - VECCOPY(v,pccd_M->mvert[mface->v1].co); + copy_v3_v3(v,pccd_M->mvert[mface->v1].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -353,7 +353,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mvert[mface->v2].co); + copy_v3_v3(v,pccd_M->mvert[mface->v2].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -361,7 +361,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mvert[mface->v3].co); + copy_v3_v3(v,pccd_M->mvert[mface->v3].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -370,7 +370,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) mima->maxz = MAX2(mima->maxz,v[2]+hull); if(mface->v4){ - VECCOPY(v,pccd_M->mvert[mface->v4].co); + copy_v3_v3(v,pccd_M->mvert[mface->v4].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -419,7 +419,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) /* determine the ortho BB */ for(i=0; i < pccd_M->totvert; i++){ /* evaluate limits */ - VECCOPY(v,pccd_M->mvert[i].co); + copy_v3_v3(v,pccd_M->mvert[i].co); pccd_M->bbmin[0] = MIN2(pccd_M->bbmin[0],v[0]-hull); pccd_M->bbmin[1] = MIN2(pccd_M->bbmin[1],v[1]-hull); pccd_M->bbmin[2] = MIN2(pccd_M->bbmin[2],v[2]-hull); @@ -429,7 +429,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) pccd_M->bbmax[2] = MAX2(pccd_M->bbmax[2],v[2]+hull); /* evaluate limits */ - VECCOPY(v,pccd_M->mprevvert[i].co); + copy_v3_v3(v,pccd_M->mprevvert[i].co); pccd_M->bbmin[0] = MIN2(pccd_M->bbmin[0],v[0]-hull); pccd_M->bbmin[1] = MIN2(pccd_M->bbmin[1],v[1]-hull); pccd_M->bbmin[2] = MIN2(pccd_M->bbmin[2],v[2]-hull); @@ -449,7 +449,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->minx=mima->miny=mima->minz=1e30f; mima->maxx=mima->maxy=mima->maxz=-1e30f; - VECCOPY(v,pccd_M->mvert[mface->v1].co); + copy_v3_v3(v,pccd_M->mvert[mface->v1].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -457,7 +457,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mvert[mface->v2].co); + copy_v3_v3(v,pccd_M->mvert[mface->v2].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -465,7 +465,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mvert[mface->v3].co); + copy_v3_v3(v,pccd_M->mvert[mface->v3].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -474,7 +474,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxz = MAX2(mima->maxz,v[2]+hull); if(mface->v4){ - VECCOPY(v,pccd_M->mvert[mface->v4].co); + copy_v3_v3(v,pccd_M->mvert[mface->v4].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -484,7 +484,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) } - VECCOPY(v,pccd_M->mprevvert[mface->v1].co); + copy_v3_v3(v,pccd_M->mprevvert[mface->v1].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -492,7 +492,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mprevvert[mface->v2].co); + copy_v3_v3(v,pccd_M->mprevvert[mface->v2].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -500,7 +500,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxy = MAX2(mima->maxy,v[1]+hull); mima->maxz = MAX2(mima->maxz,v[2]+hull); - VECCOPY(v,pccd_M->mprevvert[mface->v3].co); + copy_v3_v3(v,pccd_M->mprevvert[mface->v3].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -509,7 +509,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M) mima->maxz = MAX2(mima->maxz,v[2]+hull); if(mface->v4){ - VECCOPY(v,pccd_M->mprevvert[mface->v4].co); + copy_v3_v3(v,pccd_M->mprevvert[mface->v4].co); mima->minx = MIN2(mima->minx,v[0]-hull); mima->miny = MIN2(mima->miny,v[1]-hull); mima->minz = MIN2(mima->minz,v[2]-hull); @@ -1024,8 +1024,8 @@ static int sb_detect_aabb_collisionCached( float UNUSED(force[3]), unsigned int #endif if ((sb == NULL) || (sb->scratch ==NULL)) return 0; - VECCOPY(aabbmin,sb->scratch->aabbmin); - VECCOPY(aabbmax,sb->scratch->aabbmax); + copy_v3_v3(aabbmin,sb->scratch->aabbmin); + copy_v3_v3(aabbmax,sb->scratch->aabbmax); hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); @@ -1099,8 +1099,8 @@ static int sb_detect_face_pointCached(float face_v1[3],float face_v2[3],float fa aabbmax[2] = MAX3(face_v1[2],face_v2[2],face_v3[2]); /* calculate face normal once again SIGH */ - VECSUB(edge1, face_v1, face_v2); - VECSUB(edge2, face_v3, face_v2); + sub_v3_v3v3(edge1, face_v1, face_v2); + sub_v3_v3v3(edge2, face_v3, face_v2); cross_v3_v3v3(d_nvect, edge2, edge1); normalize_v3(d_nvect); @@ -1143,13 +1143,13 @@ static int sb_detect_face_pointCached(float face_v1[3],float face_v2[3],float fa /* use mesh*/ if (mvert) { while(a){ - VECCOPY(nv1,mvert[a-1].co); + copy_v3_v3(nv1,mvert[a-1].co); if(mprevvert){ mul_v3_fl(nv1,time); Vec3PlusStVec(nv1,(1.0f-time),mprevvert[a-1].co); } /* origin to face_v2*/ - VECSUB(nv1, nv1, face_v2); + sub_v3_v3(nv1, face_v2); facedist = dot_v3v3(nv1,d_nvect); if (ABS(facedist)v1].co); - VECCOPY(nv2,mvert[mface->v2].co); - VECCOPY(nv3,mvert[mface->v3].co); + copy_v3_v3(nv1,mvert[mface->v1].co); + copy_v3_v3(nv2,mvert[mface->v2].co); + copy_v3_v3(nv3,mvert[mface->v3].co); if (mface->v4){ - VECCOPY(nv4,mvert[mface->v4].co); + copy_v3_v3(nv4,mvert[mface->v4].co); } if (mprevvert){ mul_v3_fl(nv1,time); @@ -1277,8 +1277,8 @@ static int sb_detect_face_collisionCached(float face_v1[3],float face_v2[3],floa } /* switch origin to be nv2*/ - VECSUB(edge1, nv1, nv2); - VECSUB(edge2, nv3, nv2); + sub_v3_v3v3(edge1, nv1, nv2); + sub_v3_v3v3(edge2, nv3, nv2); cross_v3_v3v3(d_nvect, edge2, edge1); normalize_v3(d_nvect); if ( @@ -1291,8 +1291,8 @@ static int sb_detect_face_collisionCached(float face_v1[3],float face_v2[3],floa } if (mface->v4){ /* quad */ /* switch origin to be nv4 */ - VECSUB(edge1, nv3, nv4); - VECSUB(edge2, nv1, nv4); + sub_v3_v3v3(edge1, nv3, nv4); + sub_v3_v3v3(edge2, nv1, nv4); cross_v3_v3v3(d_nvect, edge2, edge1); normalize_v3(d_nvect); if ( @@ -1481,11 +1481,11 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa if (mvert){ - VECCOPY(nv1,mvert[mface->v1].co); - VECCOPY(nv2,mvert[mface->v2].co); - VECCOPY(nv3,mvert[mface->v3].co); + copy_v3_v3(nv1,mvert[mface->v1].co); + copy_v3_v3(nv2,mvert[mface->v2].co); + copy_v3_v3(nv3,mvert[mface->v3].co); if (mface->v4){ - VECCOPY(nv4,mvert[mface->v4].co); + copy_v3_v3(nv4,mvert[mface->v4].co); } if (mprevvert){ mul_v3_fl(nv1,time); @@ -1505,16 +1505,16 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa } /* switch origin to be nv2*/ - VECSUB(edge1, nv1, nv2); - VECSUB(edge2, nv3, nv2); + sub_v3_v3v3(edge1, nv1, nv2); + sub_v3_v3v3(edge2, nv3, nv2); cross_v3_v3v3(d_nvect, edge2, edge1); normalize_v3(d_nvect); if ( isect_line_tri_v3(edge_v1, edge_v2, nv1, nv2, nv3, &t, NULL)){ float v1[3],v2[3]; float intrusiondepth,i1,i2; - VECSUB(v1, edge_v1, nv2); - VECSUB(v2, edge_v2, nv2); + sub_v3_v3v3(v1, edge_v1, nv2); + sub_v3_v3v3(v2, edge_v2, nv2); i1 = dot_v3v3(v1,d_nvect); i2 = dot_v3v3(v2,d_nvect); intrusiondepth = -MIN2(i1,i2)/el; @@ -1524,16 +1524,16 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa } if (mface->v4){ /* quad */ /* switch origin to be nv4 */ - VECSUB(edge1, nv3, nv4); - VECSUB(edge2, nv1, nv4); + sub_v3_v3v3(edge1, nv3, nv4); + sub_v3_v3v3(edge2, nv1, nv4); cross_v3_v3v3(d_nvect, edge2, edge1); normalize_v3(d_nvect); if (isect_line_tri_v3( edge_v1, edge_v2,nv1, nv3, nv4, &t, NULL)){ float v1[3],v2[3]; float intrusiondepth,i1,i2; - VECSUB(v1, edge_v1, nv4); - VECSUB(v2, edge_v2, nv4); + sub_v3_v3v3(v1, edge_v1, nv4); + sub_v3_v3v3(v2, edge_v2, nv4); i1 = dot_v3v3(v1,d_nvect); i2 = dot_v3v3(v2,d_nvect); intrusiondepth = -MIN2(i1,i2)/el; @@ -1602,16 +1602,16 @@ static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, } /* media in rest */ else{ - VECADD(vel, sb->bpoint[bs->v1].vec , sb->bpoint[bs->v2].vec); + add_v3_v3v3(vel, sb->bpoint[bs->v1].vec , sb->bpoint[bs->v2].vec); } f = normalize_v3(vel); f = -0.0001f*f*f*sb->aeroedge; /* (todo) add a nice angle dependant function done for now BUT */ /* still there could be some nice drag/lift function, but who needs it */ - VECSUB(sp, sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos); + sub_v3_v3v3(sp, sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos); project_v3_v3v3(pr,vel,sp); - VECSUB(vel,vel,pr); + sub_v3_v3(vel, pr); normalize_v3(vel); if (ob->softflag & OB_SB_AERO_ANGLE){ normalize_v3(sp); @@ -1725,9 +1725,9 @@ static int choose_winner(float*w, float* pos,float*a,float*b,float*c,float*ca,fl winner =3; } switch (winner){ - case 1: VECCOPY(w,ca); break; - case 2: VECCOPY(w,cb); break; - case 3: VECCOPY(w,cc); + case 1: copy_v3_v3(w,ca); break; + case 2: copy_v3_v3(w,cb); break; + case 3: copy_v3_v3(w,cc); } return(winner); } @@ -1824,11 +1824,11 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], if (mvert){ - VECCOPY(nv1,mvert[mface->v1].co); - VECCOPY(nv2,mvert[mface->v2].co); - VECCOPY(nv3,mvert[mface->v3].co); + copy_v3_v3(nv1,mvert[mface->v1].co); + copy_v3_v3(nv2,mvert[mface->v2].co); + copy_v3_v3(nv3,mvert[mface->v3].co); if (mface->v4){ - VECCOPY(nv4,mvert[mface->v4].co); + copy_v3_v3(nv4,mvert[mface->v4].co); } if (mprevvert){ @@ -1838,11 +1838,11 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], since the AABB reduced propabitlty to get here drasticallly it might be a nice tradeof CPU <--> memory */ - VECSUB(vv1,nv1,mprevvert[mface->v1].co); - VECSUB(vv2,nv2,mprevvert[mface->v2].co); - VECSUB(vv3,nv3,mprevvert[mface->v3].co); + sub_v3_v3v3(vv1,nv1,mprevvert[mface->v1].co); + sub_v3_v3v3(vv2,nv2,mprevvert[mface->v2].co); + sub_v3_v3v3(vv3,nv3,mprevvert[mface->v3].co); if (mface->v4){ - VECSUB(vv4,nv4,mprevvert[mface->v4].co); + sub_v3_v3v3(vv4,nv4,mprevvert[mface->v4].co); } mul_v3_fl(nv1,time); @@ -1862,9 +1862,9 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } /* switch origin to be nv2*/ - VECSUB(edge1, nv1, nv2); - VECSUB(edge2, nv3, nv2); - VECSUB(dv1,opco,nv2); /* abuse dv1 to have vertex in question at *origin* of triangle */ + sub_v3_v3v3(edge1, nv1, nv2); + sub_v3_v3v3(edge2, nv3, nv2); + sub_v3_v3v3(dv1,opco,nv2); /* abuse dv1 to have vertex in question at *origin* of triangle */ cross_v3_v3v3(d_nvect, edge2, edge1); /* n_mag = */ /* UNUSED */ normalize_v3(d_nvect); @@ -1890,7 +1890,7 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } if ((mprevvert) && (*damp > 0.0f)){ choose_winner(ve,opco,nv1,nv2,nv3,vv1,vv2,vv3); - VECADD(avel,avel,ve); + add_v3_v3(avel, ve); cavel ++; } *intrusion += facedist; @@ -1899,9 +1899,9 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } if (mface->v4){ /* quad */ /* switch origin to be nv4 */ - VECSUB(edge1, nv3, nv4); - VECSUB(edge2, nv1, nv4); - VECSUB(dv1,opco,nv4); /* abuse dv1 to have vertex in question at *origin* of triangle */ + sub_v3_v3v3(edge1, nv3, nv4); + sub_v3_v3v3(edge2, nv1, nv4); + sub_v3_v3v3(dv1,opco,nv4); /* abuse dv1 to have vertex in question at *origin* of triangle */ cross_v3_v3v3(d_nvect, edge2, edge1); /* n_mag = */ /* UNUSED */ normalize_v3(d_nvect); @@ -1926,7 +1926,7 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], if ((mprevvert) && (*damp > 0.0f)){ choose_winner(ve,opco,nv1,nv3,nv4,vv1,vv3,vv4); - VECADD(avel,avel,ve); + add_v3_v3(avel, ve); cavel ++; } *intrusion += facedist; @@ -1939,46 +1939,46 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], float dist; closest_to_line_segment_v3(ve, opco, nv1, nv2); - VECSUB(ve,opco,ve); + sub_v3_v3v3(ve,opco,ve); dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ - VECCOPY(coledge,ve); + copy_v3_v3(coledge,ve); mindistedge = dist, deflected=1; } closest_to_line_segment_v3(ve, opco, nv2, nv3); - VECSUB(ve,opco,ve); + sub_v3_v3v3(ve,opco,ve); dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ - VECCOPY(coledge,ve); + copy_v3_v3(coledge,ve); mindistedge = dist, deflected=1; } closest_to_line_segment_v3(ve, opco, nv3, nv1); - VECSUB(ve,opco,ve); + sub_v3_v3v3(ve,opco,ve); dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ - VECCOPY(coledge,ve); + copy_v3_v3(coledge,ve); mindistedge = dist, deflected=1; } if (mface->v4){ /* quad */ closest_to_line_segment_v3(ve, opco, nv3, nv4); - VECSUB(ve,opco,ve); + sub_v3_v3v3(ve,opco,ve); dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ - VECCOPY(coledge,ve); + copy_v3_v3(coledge,ve); mindistedge = dist, deflected=1; } closest_to_line_segment_v3(ve, opco, nv1, nv4); - VECSUB(ve,opco,ve); + sub_v3_v3v3(ve,opco,ve); dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ - VECCOPY(coledge,ve); + copy_v3_v3(coledge,ve); mindistedge = dist, deflected=1; } @@ -2007,15 +2007,15 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } if (deflected == 2){ // face inner detected - VECADD(force,force,innerforceaccu); + add_v3_v3(force, innerforceaccu); } if (deflected == 3){ // face outer detected - VECADD(force,force,outerforceaccu); + add_v3_v3(force, outerforceaccu); } BLI_ghashIterator_free(ihash); if (cavel) mul_v3_fl(avel,1.0f/(float)cavel); - VECCOPY(vel,avel); + copy_v3_v3(vel,avel); if (ci) *intrusion /= ci; if (deflected){ normalize_v3_v3(facenormal, force); @@ -2029,7 +2029,7 @@ static int sb_deflect_face(Object *ob,float *actpos,float *facenormal,float *for { float s_actpos[3]; int deflected; - VECCOPY(s_actpos,actpos); + copy_v3_v3(s_actpos,actpos); deflected= sb_detect_vertex_collisionCached(s_actpos, facenormal, cf, force , ob->lay, ob,time,vel,intrusion); //deflected= sb_detect_vertex_collisionCachedEx(s_actpos, facenormal, cf, force , ob->lay, ob,time,vel,intrusion); return(deflected); @@ -2286,7 +2286,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* gravitation */ if (sb && scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY){ float gravity[3]; - VECCOPY(gravity, scene->physics_settings.gravity); + copy_v3_v3(gravity, scene->physics_settings.gravity); mul_v3_fl(gravity, sb_grav_force_scale(ob)*_final_mass(ob,bp)*sb->effector_weights->global_gravity); /* individual mass of node here */ add_v3_v3(bp->force, gravity); } @@ -2303,7 +2303,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* apply forcefield*/ mul_v3_fl(force,fieldfactor* eval_sb_fric_force_scale); - VECADD(bp->force, bp->force, force); + add_v3_v3(bp->force, force); /* BP friction in moving media */ kd= sb->mediafrict* eval_sb_fric_force_scale; @@ -2337,7 +2337,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo bp->choke = sb->choke*0.01f; } - VECSUB(cfforce,bp->vec,vel); + sub_v3_v3v3(cfforce,bp->vec,vel); Vec3PlusStVec(bp->force,-cf*50.0f,cfforce); Vec3PlusStVec(bp->force,kd,defforce); @@ -2524,7 +2524,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY){ - VECCOPY(gravity, scene->physics_settings.gravity); + copy_v3_v3(gravity, scene->physics_settings.gravity); mul_v3_fl(gravity, sb_grav_force_scale(ob)*sb->effector_weights->global_gravity); } @@ -2711,7 +2711,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa /* apply forcefield*/ mul_v3_fl(force,fieldfactor* eval_sb_fric_force_scale); - VECADD(bp->force, bp->force, force); + add_v3_v3(bp->force, force); /* BP friction in moving media */ kd= sb->mediafrict* eval_sb_fric_force_scale; @@ -2764,7 +2764,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa } else{ - VECSUB(cfforce,bp->vec,vel); + sub_v3_v3v3(cfforce,bp->vec,vel); Vec3PlusStVec(bp->force,-cf*50.0f,cfforce); } @@ -2774,7 +2774,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa bp->choke = sb->choke*0.01f; } else{ - VECSUB(cfforce,bp->vec,vel); + sub_v3_v3v3(cfforce,bp->vec,vel); Vec3PlusStVec(bp->force,-cf*50.0f,cfforce); } Vec3PlusStVec(bp->force,kd,defforce); @@ -2876,7 +2876,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa else{ printf("Matrix inversion failed \n"); for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(bp->impdv,bp->force); + copy_v3_v3(bp->impdv,bp->force); } } @@ -2923,7 +2923,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * if(_final_goal(ob,bp) < SOFTGOALSNAP){ /* this makes t~ = t */ - if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec); + if(mid_flags & MID_PRESERVE) copy_v3_v3(dx,bp->vec); /* so here is (v)' = a(cceleration) = sum(F_springs)/m + gravitation + some friction forces + more forces*/ /* the ( ... )' operator denotes derivate respective time */ @@ -2931,11 +2931,11 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * /* v(t + dt) = v(t) + a(t) * dt */ mul_v3_fl(bp->force,timeovermass);/* individual mass of node here */ /* some nasty if's to have heun in here too */ - VECCOPY(dv,bp->force); + copy_v3_v3(dv,bp->force); if (mode == 1){ - VECCOPY(bp->prevvec, bp->vec); - VECCOPY(bp->prevdv, dv); + copy_v3_v3(bp->prevvec, bp->vec); + copy_v3_v3(bp->prevdv, dv); } if (mode ==2){ @@ -2948,10 +2948,10 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * maxerrvel = MAX2(maxerrvel,ABS(dv[1] - bp->prevdv[1])); maxerrvel = MAX2(maxerrvel,ABS(dv[2] - bp->prevdv[2])); } - else {VECADD(bp->vec, bp->vec, bp->force);} + else { add_v3_v3(bp->vec, bp->force); } /* this makes t~ = t+dt */ - if(!(mid_flags & MID_PRESERVE)) VECCOPY(dx,bp->vec); + if(!(mid_flags & MID_PRESERVE)) copy_v3_v3(dx,bp->vec); /* so here is (x)'= v(elocity) */ /* the euler step for location then becomes */ @@ -2970,8 +2970,8 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * */ /* again some nasty if's to have heun in here too */ if (mode ==1){ - VECCOPY(bp->prevpos,bp->pos); - VECCOPY(bp->prevdx ,dx); + copy_v3_v3(bp->prevpos,bp->pos); + copy_v3_v3(bp->prevdx ,dx); } if (mode ==2){ @@ -2994,7 +2994,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * } } - else { VECADD(bp->pos, bp->pos, dx);} + else { add_v3_v3(bp->pos, dx);} }/*snap*/ /* so while we are looping BPs anyway do statistics on the fly */ aabbmin[0] = MIN2(aabbmin[0],bp->pos[0]); @@ -3008,8 +3008,8 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * if (sb->totpoint) mul_v3_fl(cm,1.0f/sb->totpoint); if (sb->scratch){ - VECCOPY(sb->scratch->aabbmin,aabbmin); - VECCOPY(sb->scratch->aabbmax,aabbmax); + copy_v3_v3(sb->scratch->aabbmin,aabbmin); + copy_v3_v3(sb->scratch->aabbmax,aabbmax); } if (err){ /* so step size will be controlled by biggest difference in slope */ @@ -3032,8 +3032,8 @@ static void softbody_restore_prev_step(Object *ob) int a; for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(bp->vec, bp->prevvec); - VECCOPY(bp->pos, bp->prevpos); + copy_v3_v3(bp->vec, bp->prevvec); + copy_v3_v3(bp->pos, bp->prevpos); } } @@ -3045,8 +3045,8 @@ static void softbody_store_step(Object *ob) int a; for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(bp->prevvec,bp->vec); - VECCOPY(bp->prevpos,bp->pos); + copy_v3_v3(bp->prevvec,bp->vec); + copy_v3_v3(bp->prevpos,bp->pos); } } @@ -3061,10 +3061,10 @@ static void softbody_store_state(Object *ob,float *ppos,float *pvel) for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(pv, bp->vec); + copy_v3_v3(pv, bp->vec); pv+=3; - VECCOPY(pp, bp->pos); + copy_v3_v3(pp, bp->pos); pp+=3; } } @@ -3079,10 +3079,10 @@ static void softbody_retrieve_state(Object *ob,float *ppos,float *pvel) for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(bp->vec,pv); + copy_v3_v3(bp->vec,pv); pv+=3; - VECCOPY(bp->pos,pp); + copy_v3_v3(bp->pos,pp); pp+=3; } } @@ -3098,14 +3098,14 @@ static void softbody_swap_state(Object *ob,float *ppos,float *pvel) for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { - VECCOPY(temp, bp->vec); - VECCOPY(bp->vec,pv); - VECCOPY(pv,temp); + copy_v3_v3(temp, bp->vec); + copy_v3_v3(bp->vec,pv); + copy_v3_v3(pv,temp); pv+=3; - VECCOPY(temp, bp->pos); - VECCOPY(bp->pos,pp); - VECCOPY(pp,temp); + copy_v3_v3(temp, bp->pos); + copy_v3_v3(bp->pos,pp); + copy_v3_v3(pp,temp); pp+=3; } } @@ -3126,8 +3126,8 @@ static void softbody_apply_goalsnap(Object *ob) for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { if (_final_goal(ob,bp) >= SOFTGOALSNAP){ - VECCOPY(bp->prevpos,bp->pos); - VECCOPY(bp->pos,bp->origT); + copy_v3_v3(bp->prevpos,bp->pos); + copy_v3_v3(bp->pos,bp->origT); } } } @@ -3238,7 +3238,7 @@ static void springs_from_mesh(Object *ob) if(me->totvert) { bp= ob->soft->bpoint; for(a=0; atotvert; a++, bp++) { - VECCOPY(bp->origS, me->mvert[a].co); + copy_v3_v3(bp->origS, me->mvert[a].co); mul_m4_v3(ob->obmat, bp->origS); } @@ -3399,12 +3399,12 @@ static void reference_to_scratch(Object *ob) bp= ob->soft->bpoint; rp= sb->scratch->Ref.ivert; for(a=0; atotpoint; a++, rp++, bp++) { - VECCOPY(rp->pos,bp->pos); - VECADD(accu_pos,accu_pos,bp->pos); + copy_v3_v3(rp->pos,bp->pos); + add_v3_v3(accu_pos, bp->pos); accu_mass += _final_mass(ob,bp); } mul_v3_fl(accu_pos,1.0f/accu_mass); - VECCOPY(sb->scratch->Ref.com,accu_pos); + copy_v3_v3(sb->scratch->Ref.com,accu_pos); /* printf("reference_to_scratch \n"); */ } @@ -3415,9 +3415,9 @@ when object is rescaled static float globallen(float *v1,float *v2,Object *ob) { float p1[3],p2[3]; - VECCOPY(p1,v1); + copy_v3_v3(p1,v1); mul_m4_v3(ob->obmat, p1); - VECCOPY(p2,v2); + copy_v3_v3(p2,v2); mul_m4_v3(ob->obmat, p2); return len_v3v3(p1,p2); } @@ -3656,7 +3656,7 @@ static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts, invert_m4_m4(ob->imat, ob->obmat); for(a=0; apos); + copy_v3_v3(vertexCos[a], bp->pos); if(local==0) mul_m4_v3(ob->imat, vertexCos[a]); /* softbody is in global coords, baked optionally not */ } @@ -3784,14 +3784,14 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo for(a=0,bp=sb->bpoint; aorigS, bp->origE); + copy_v3_v3(bp->origS, bp->origE); /* copy the position of the goals at desired end time */ - VECCOPY(bp->origE, vertexCos[a]); + copy_v3_v3(bp->origE, vertexCos[a]); /* vertexCos came from local world, go global */ mul_m4_v3(ob->obmat, bp->origE); /* just to be save give bp->origT a defined value will be calulated in interpolate_exciter()*/ - VECCOPY(bp->origT, bp->origE); + copy_v3_v3(bp->origT, bp->origE); } } @@ -3828,14 +3828,14 @@ void SB_estimate_transform(Object *ob,float lloc[3],float lrot[3][3],float lscal rpos= MEM_callocN( (sb->totpoint)*3*sizeof(float), "SB_RPOS"); /* might filter vertex selection with a vertex group */ for(a=0, bp=sb->bpoint, rp=sb->scratch->Ref.ivert; atotpoint; a++, bp++, rp++) { - VECCOPY(rpos[a],rp->pos); - VECCOPY(opos[a],bp->pos); + copy_v3_v3(rpos[a],rp->pos); + copy_v3_v3(opos[a],bp->pos); } vcloud_estimate_transform(sb->totpoint, opos, NULL, rpos, NULL, com, rcom,lrot,lscale); - //VECSUB(com,com,rcom); - if (lloc) VECCOPY(lloc,com); - VECCOPY(sb->lcom,com); + //sub_v3_v3(com,rcom); + if (lloc) copy_v3_v3(lloc,com); + copy_v3_v3(sb->lcom,com); if (lscale) copy_m3_m3(sb->lscale,lscale); if (lrot) copy_m3_m3(sb->lrot,lrot); @@ -3850,11 +3850,11 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int int a; for(a=0,bp=sb->bpoint; apos, vertexCos[a]); + copy_v3_v3(bp->pos, vertexCos[a]); mul_m4_v3(ob->obmat, bp->pos); /* yep, sofbody is global coords*/ - VECCOPY(bp->origS, bp->pos); - VECCOPY(bp->origE, bp->pos); - VECCOPY(bp->origT, bp->pos); + copy_v3_v3(bp->origS, bp->pos); + copy_v3_v3(bp->origE, bp->pos); + copy_v3_v3(bp->origT, bp->pos); bp->vec[0]= bp->vec[1]= bp->vec[2]= 0.0f; /* the bp->prev*'s are for rolling back from a canceled try to propagate in time @@ -3869,10 +3869,10 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int 4.b yup we're done */ - VECCOPY(bp->prevpos, bp->pos); - VECCOPY(bp->prevvec, bp->vec); - VECCOPY(bp->prevdx, bp->vec); - VECCOPY(bp->prevdv, bp->vec); + copy_v3_v3(bp->prevpos, bp->pos); + copy_v3_v3(bp->prevvec, bp->vec); + copy_v3_v3(bp->prevdx, bp->vec); + copy_v3_v3(bp->prevdv, bp->vec); } /* make a nice clean scratch struc */ diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 986e0e2b552..9848b27d32e 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -668,7 +668,7 @@ static void ccgDM_getFinalVertCo(DerivedMesh *dm, int vertNum, float co_r[3]) MVert mvert; ccgDM_getFinalVert(dm, vertNum, &mvert); - VECCOPY(co_r, mvert.co); + copy_v3_v3(co_r, mvert.co); } static void ccgDM_getFinalVertNo(DerivedMesh *dm, int vertNum, float no_r[3]) diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index d3bd7d7b766..3aa289d0ef8 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -227,7 +227,7 @@ void init_mapping(TexMapping *texmap) mul_m3_m3m3(mat, rmat, smat); copy_m4_m3(texmap->mat, mat); - VECCOPY(texmap->mat[3], texmap->loc); + copy_v3_v3(texmap->mat[3], texmap->loc); } -- cgit v1.2.3 From 96d73bfdcfd74bfccd58bf02ae25b64577fce904 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2011 01:38:32 +0000 Subject: replace VECCOPY with copy_v3_v3, same for 2d copy, also added vec copy functions for int & char. --- source/blender/blenkernel/intern/cdderivedmesh.c | 58 ++++++++++++------------ source/blender/blenkernel/intern/pointcache.c | 20 ++++---- source/blender/blenkernel/intern/shrinkwrap.c | 32 ++++++------- 3 files changed, 54 insertions(+), 56 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 25f9f17f201..d2c86a14572 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -152,7 +152,7 @@ static void cdDM_getVertCo(DerivedMesh *dm, int index, float co_r[3]) { CDDerivedMesh *cddm = (CDDerivedMesh*) dm; - VECCOPY(co_r, cddm->mvert[index].co); + copy_v3_v3(co_r, cddm->mvert[index].co); } static void cdDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3]) @@ -161,7 +161,7 @@ static void cdDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3]) int i; for(i = 0; i < dm->numVertData; i++, mv++) - VECCOPY(cos_r[i], mv->co); + copy_v3_v3(cos_r[i], mv->co); } static void cdDM_getVertNo(DerivedMesh *dm, int index, float no_r[3]) @@ -1246,39 +1246,39 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo if( numdata != 0 ) { offset = 0; if(attribs.totorco) { - VECCOPY((float *)&varray[elementsize*curface*3],(float *)attribs.orco.array[mface->v1]); - VECCOPY((float *)&varray[elementsize*curface*3+elementsize],(float *)attribs.orco.array[mface->v2]); - VECCOPY((float *)&varray[elementsize*curface*3+elementsize*2],(float *)attribs.orco.array[mface->v3]); + copy_v3_v3((float *)&varray[elementsize*curface*3],(float *)attribs.orco.array[mface->v1]); + copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize],(float *)attribs.orco.array[mface->v2]); + copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2],(float *)attribs.orco.array[mface->v3]); offset += sizeof(float)*3; } for(b = 0; b < attribs.tottface; b++) { MTFace *tf = &attribs.tface[b].array[a]; - VECCOPY2D((float *)&varray[elementsize*curface*3+offset],tf->uv[0]); - VECCOPY2D((float *)&varray[elementsize*curface*3+offset+elementsize],tf->uv[1]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset],tf->uv[0]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize],tf->uv[1]); - VECCOPY2D((float *)&varray[elementsize*curface*3+offset+elementsize*2],tf->uv[2]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2],tf->uv[2]); offset += sizeof(float)*2; } for(b = 0; b < attribs.totmcol; b++) { MCol *cp = &attribs.mcol[b].array[a*4 + 0]; GLubyte col[4]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col); cp = &attribs.mcol[b].array[a*4 + 1]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset+elementsize], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col); cp = &attribs.mcol[b].array[a*4 + 2]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset+elementsize*2], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col); offset += sizeof(unsigned char)*4; } if(attribs.tottang) { float *tang = attribs.tang.array[a*4 + 0]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang); tang = attribs.tang.array[a*4 + 1]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang); tang = attribs.tang.array[a*4 + 2]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); offset += sizeof(float)*4; } (void)offset; @@ -1288,38 +1288,38 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo if( numdata != 0 ) { offset = 0; if(attribs.totorco) { - VECCOPY((float *)&varray[elementsize*curface*3],(float *)attribs.orco.array[mface->v3]); - VECCOPY((float *)&varray[elementsize*curface*3+elementsize],(float *)attribs.orco.array[mface->v4]); - VECCOPY((float *)&varray[elementsize*curface*3+elementsize*2],(float *)attribs.orco.array[mface->v1]); + copy_v3_v3((float *)&varray[elementsize*curface*3],(float *)attribs.orco.array[mface->v3]); + copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize],(float *)attribs.orco.array[mface->v4]); + copy_v3_v3((float *)&varray[elementsize*curface*3+elementsize*2],(float *)attribs.orco.array[mface->v1]); offset += sizeof(float)*3; } for(b = 0; b < attribs.tottface; b++) { MTFace *tf = &attribs.tface[b].array[a]; - VECCOPY2D((float *)&varray[elementsize*curface*3+offset],tf->uv[2]); - VECCOPY2D((float *)&varray[elementsize*curface*3+offset+elementsize],tf->uv[3]); - VECCOPY2D((float *)&varray[elementsize*curface*3+offset+elementsize*2],tf->uv[0]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset],tf->uv[2]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize],tf->uv[3]); + copy_v2_v2((float *)&varray[elementsize*curface*3+offset+elementsize*2],tf->uv[0]); offset += sizeof(float)*2; } for(b = 0; b < attribs.totmcol; b++) { MCol *cp = &attribs.mcol[b].array[a*4 + 2]; GLubyte col[4]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset], (char *)col); cp = &attribs.mcol[b].array[a*4 + 3]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset+elementsize], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize], (char *)col); cp = &attribs.mcol[b].array[a*4 + 0]; col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; - QUATCOPY((unsigned char *)&varray[elementsize*curface*3+offset+elementsize*2], col); + copy_v4_v4_char((char *)&varray[elementsize*curface*3+offset+elementsize*2], (char *)col); offset += sizeof(unsigned char)*4; } if(attribs.tottang) { float *tang = attribs.tang.array[a*4 + 2]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset], tang); tang = attribs.tang.array[a*4 + 3]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize], tang); tang = attribs.tang.array[a*4 + 0]; - QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); + copy_v4_v4((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); offset += sizeof(float)*4; } (void)offset; @@ -1439,7 +1439,7 @@ static void cdDM_foreachMappedFaceCenter( else orig = i; - VECCOPY(cent, mv[mf->v1].co); + copy_v3_v3(cent, mv[mf->v1].co); add_v3_v3(cent, mv[mf->v2].co); add_v3_v3(cent, mv[mf->v3].co); @@ -1625,7 +1625,7 @@ DerivedMesh *CDDM_from_editmesh(EditMesh *em, Mesh *UNUSED(me)) i++, eve = eve->next, index++) { MVert *mv = &mvert[i]; - VECCOPY(mv->co, eve->co); + copy_v3_v3(mv->co, eve->co); normal_float_to_short_v3(mv->no, eve->no); mv->bweight = (unsigned char) (eve->bweight * 255.0f); @@ -1793,7 +1793,7 @@ void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) cddm->mvert = vert; for(i = 0; i < dm->numVertData; ++i, ++vert) - VECCOPY(vert->co, vertCoords[i]); + copy_v3_v3(vert->co, vertCoords[i]); } void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3]) diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index ba5b98ee3cd..9deaa19429f 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -183,8 +183,8 @@ static void ptcache_softbody_interpolate(int index, void *soft_v, void **data, f if(cfra1 == cfra2) return; - VECCOPY(keys[1].co, bp->pos); - VECCOPY(keys[1].vel, bp->vec); + copy_v3_v3(keys[1].co, bp->pos); + copy_v3_v3(keys[1].vel, bp->vec); if(old_data) { memcpy(keys[2].co, old_data, 3 * sizeof(float)); @@ -202,8 +202,8 @@ static void ptcache_softbody_interpolate(int index, void *soft_v, void **data, f mul_v3_fl(keys->vel, 1.0f / dfra); - VECCOPY(bp->pos, keys->co); - VECCOPY(bp->vec, keys->vel); + copy_v3_v3(bp->pos, keys->co); + copy_v3_v3(bp->vec, keys->vel); } static int ptcache_softbody_totpoint(void *soft_v, int UNUSED(cfra)) { @@ -483,8 +483,8 @@ static void ptcache_cloth_interpolate(int index, void *cloth_v, void **data, flo if(cfra1 == cfra2) return; - VECCOPY(keys[1].co, vert->x); - VECCOPY(keys[1].vel, vert->v); + copy_v3_v3(keys[1].co, vert->x); + copy_v3_v3(keys[1].vel, vert->v); if(old_data) { memcpy(keys[2].co, old_data, 3 * sizeof(float)); @@ -502,8 +502,8 @@ static void ptcache_cloth_interpolate(int index, void *cloth_v, void **data, flo mul_v3_fl(keys->vel, 1.0f / dfra); - VECCOPY(vert->x, keys->co); - VECCOPY(vert->v, keys->vel); + copy_v3_v3(vert->x, keys->co); + copy_v3_v3(vert->v, keys->vel); /* should vert->xconst be interpolated somehow too? - jahka */ } @@ -2126,7 +2126,7 @@ int BKE_ptcache_id_exist(PTCacheID *pid, int cfra) } void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startframe, int *endframe, float *timescale) { - Object *ob; + /* Object *ob; */ /* UNUSED */ PointCache *cache; /* float offset; unused for now */ float time, nexttime; @@ -2143,7 +2143,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra * is probably to interpolate results from two frames for that .. */ - ob= pid->ob; + /* ob= pid->ob; */ /* UNUSED */ cache= pid->cache; if(timescale) { diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 3d788b40a17..aed246690bd 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -167,13 +167,11 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) //Convert the vertex to tree coordinates - if(calc->vert) - { - VECCOPY(tmp_co, calc->vert[i].co); + if(calc->vert) { + copy_v3_v3(tmp_co, calc->vert[i].co); } - else - { - VECCOPY(tmp_co, co); + else { + copy_v3_v3(tmp_co, co); } space_transform_apply(&calc->local2target, tmp_co); @@ -198,7 +196,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) if(dist > FLT_EPSILON) weight *= (dist - calc->keepDist)/dist; //Convert the coordinates back to mesh coordinates - VECCOPY(tmp_co, nearest.co); + copy_v3_v3(tmp_co, nearest.co); space_transform_invert(&calc->local2target, tmp_co); interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation @@ -228,11 +226,11 @@ int normal_projection_project_vertex(char options, const float *vert, const floa //Apply space transform (TODO readjust dist) if(transf) { - VECCOPY( tmp_co, vert ); + copy_v3_v3( tmp_co, vert ); space_transform_apply( transf, tmp_co ); co = tmp_co; - VECCOPY( tmp_no, dir ); + copy_v3_v3( tmp_no, dir ); space_transform_apply_normal( transf, tmp_no ); no = tmp_no; @@ -350,17 +348,17 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) /* this coordinated are deformed by vertexCos only for normal projection (to get correct normals) */ /* for other cases calc->varts contains undeformed coordinates and vertexCos should be used */ if(calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { - VECCOPY(tmp_co, calc->vert[i].co); + copy_v3_v3(tmp_co, calc->vert[i].co); normal_short_to_float_v3(tmp_no, calc->vert[i].no); } else { - VECCOPY(tmp_co, co); - VECCOPY(tmp_no, proj_axis); + copy_v3_v3(tmp_co, co); + copy_v3_v3(tmp_no, proj_axis); } } else { - VECCOPY(tmp_co, co); - VECCOPY(tmp_no, proj_axis); + copy_v3_v3(tmp_co, co); + copy_v3_v3(tmp_no, proj_axis); } @@ -443,11 +441,11 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) //Convert the vertex to tree coordinates if(calc->vert) { - VECCOPY(tmp_co, calc->vert[i].co); + copy_v3_v3(tmp_co, calc->vert[i].co); } else { - VECCOPY(tmp_co, co); + copy_v3_v3(tmp_co, co); } space_transform_apply(&calc->local2target, tmp_co); @@ -478,7 +476,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) if(dist > FLT_EPSILON) interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist)/dist); //linear interpolation else - VECCOPY( tmp_co, nearest.co ); + copy_v3_v3( tmp_co, nearest.co ); } //Convert the coordinates back to mesh coordinates -- cgit v1.2.3 From bb8fe0bf4afeaa5ae91329b8d8147b94cc54034a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2011 04:36:37 +0000 Subject: minor edits - remove unneeded type check from convert grease pencil operator. - correct some error prints & use __func__. - make copy_libblock take an ID* argument rather than void*. --- source/blender/blenkernel/intern/action.c | 2 +- source/blender/blenkernel/intern/armature.c | 2 +- source/blender/blenkernel/intern/brush.c | 2 +- source/blender/blenkernel/intern/camera.c | 2 +- source/blender/blenkernel/intern/curve.c | 2 +- source/blender/blenkernel/intern/key.c | 2 +- source/blender/blenkernel/intern/lamp.c | 4 ++-- source/blender/blenkernel/intern/lattice.c | 2 +- source/blender/blenkernel/intern/library.c | 12 +++++------- source/blender/blenkernel/intern/material.c | 4 ++-- source/blender/blenkernel/intern/mball.c | 2 +- source/blender/blenkernel/intern/mesh.c | 2 +- source/blender/blenkernel/intern/node.c | 2 +- source/blender/blenkernel/intern/object.c | 2 +- source/blender/blenkernel/intern/particle.c | 2 +- source/blender/blenkernel/intern/scene.c | 2 +- source/blender/blenkernel/intern/speaker.c | 2 +- source/blender/blenkernel/intern/text.c | 2 +- source/blender/blenkernel/intern/texture.c | 4 ++-- source/blender/blenkernel/intern/world.c | 4 ++-- 20 files changed, 28 insertions(+), 30 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 944f7c6a0b6..5fb03b7bbd0 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -185,7 +185,7 @@ bAction *copy_action (bAction *src) if (src == NULL) return NULL; - dst= copy_libblock(src); + dst= copy_libblock(&src->id); /* duplicate the lists of groups and markers */ BLI_duplicatelist(&dst->groups, &src->groups); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index f19ed859064..50f305e4400 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -204,7 +204,7 @@ bArmature *copy_armature(bArmature *arm) Bone *oldBone, *newBone; Bone *newActBone= NULL; - newArm= copy_libblock (arm); + newArm= copy_libblock(&arm->id); BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); /* Duplicate the childrens' lists*/ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index e78b89441c9..09021e71025 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -144,7 +144,7 @@ Brush *copy_brush(Brush *brush) { Brush *brushn; - brushn= copy_libblock(brush); + brushn= copy_libblock(&brush->id); if (brush->mtex.tex) id_us_plus((ID*)brush->mtex.tex); diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index eeec82c3beb..145eb9363e9 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -68,7 +68,7 @@ Camera *copy_camera(Camera *cam) { Camera *camn; - camn= copy_libblock(cam); + camn= copy_libblock(&cam->id); return camn; } diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index adc08f5cd9f..160f5703a01 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -192,7 +192,7 @@ Curve *copy_curve(Curve *cu) Curve *cun; int a; - cun= copy_libblock(cu); + cun= copy_libblock(&cu->id); cun->nurb.first= cun->nurb.last= NULL; duplicateNurblist( &(cun->nurb), &(cu->nurb)); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index c389800b0d1..eb7d07a6f7d 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -154,7 +154,7 @@ Key *copy_key(Key *key) if(key==NULL) return NULL; - keyn= copy_libblock(key); + keyn= copy_libblock(&key->id); BLI_duplicatelist(&keyn->block, &key->block); diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 974aa660e9f..4edd032dc04 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -106,7 +106,7 @@ Lamp *copy_lamp(Lamp *la) Lamp *lan; int a; - lan= copy_libblock(la); + lan= copy_libblock(&la->id); for(a=0; amtex[a]) { @@ -132,7 +132,7 @@ Lamp *localize_lamp(Lamp *la) Lamp *lan; int a; - lan= copy_libblock(la); + lan= copy_libblock(&la->id); BLI_remlink(&G.main->lamp, lan); for(a=0; aid); ltn->def= MEM_dupallocN(lt->def); ltn->key= copy_key(ltn->key); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0b01c3d6dd1..878b87759b7 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -717,14 +717,11 @@ void copy_libblock_data(ID *id, const ID *id_from, const short do_action) } /* used everywhere in blenkernel */ -void *copy_libblock(void *rt) +void *copy_libblock(ID *id) { - ID *idn, *id; + ID *idn; ListBase *lb; - char *cp, *cpn; size_t idn_len; - - id= rt; lb= which_libbase(G.main, GS(id->name)); idn= alloc_libblock(lb, GS(id->name), id->name+2); @@ -733,8 +730,9 @@ void *copy_libblock(void *rt) idn_len= MEM_allocN_len(idn); if((int)idn_len - (int)sizeof(ID) > 0) { /* signed to allow neg result */ - cp= (char *)id; - cpn= (char *)idn; + const char *cp= (const char *)id; + char *cpn= (char *)idn; + memcpy(cpn+sizeof(ID), cp+sizeof(ID), idn_len - sizeof(ID)); } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 7be3514e0f2..48c6d6b2a19 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -215,7 +215,7 @@ Material *copy_material(Material *ma) Material *man; int a; - man= copy_libblock(ma); + man= copy_libblock(&ma->id); id_lib_extern((ID *)man->group); @@ -247,7 +247,7 @@ Material *localize_material(Material *ma) Material *man; int a; - man= copy_libblock(ma); + man= copy_libblock(&ma->id); BLI_remlink(&G.main->mat, man); /* no increment for texture ID users, in previewrender.c it prevents decrement */ diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 327306b32ee..5c82acde99b 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -120,7 +120,7 @@ MetaBall *copy_mball(MetaBall *mb) MetaBall *mbn; int a; - mbn= copy_libblock(mb); + mbn= copy_libblock(&mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 4a8bc34cdf7..ec9d4873057 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -206,7 +206,7 @@ Mesh *copy_mesh(Mesh *me) MTFace *tface; int a, i; - men= copy_libblock(me); + men= copy_libblock(&me->id); men->mat= MEM_dupallocN(me->mat); for(a=0; atotcol; a++) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 8f609291351..a9b2ffe7529 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -629,7 +629,7 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree) for(newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) if(newtree==ntree) break; if(newtree) { - newtree= copy_libblock(ntree); + newtree= copy_libblock(&ntree->id); } else { newtree= MEM_dupallocN(ntree); copy_libblock_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index ae4e6ea81b8..1d654839969 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1084,7 +1084,7 @@ Object *copy_object(Object *ob) ModifierData *md; int a; - obn= copy_libblock(ob); + obn= copy_libblock(&ob->id); if(ob->totcol) { obn->mat= MEM_dupallocN(ob->mat); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 56e4c91ba5e..1064a5af160 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3569,7 +3569,7 @@ ParticleSettings *psys_copy_settings(ParticleSettings *part) ParticleSettings *partn; int a; - partn= copy_libblock(part); + partn= copy_libblock(&part->id); partn->pd= MEM_dupallocN(part->pd); partn->pd2= MEM_dupallocN(part->pd2); partn->effector_weights= MEM_dupallocN(part->effector_weights); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 66d29b02263..14dfe015894 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -126,7 +126,7 @@ Scene *copy_scene(Scene *sce, int type) scen->r.layers= lb; } else { - scen= copy_libblock(sce); + scen= copy_libblock(&sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); clear_id_newpoins(); diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 018c7a197ff..a14233e9179 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -69,7 +69,7 @@ Speaker *copy_speaker(Speaker *spk) { Speaker *spkn; - spkn= copy_libblock(spk); + spkn= copy_libblock(&spk->id); if(spkn->sound) spkn->sound->id.us++; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 955127a8000..e8be0bb2608 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -431,7 +431,7 @@ Text *copy_text(Text *ta) Text *tan; TextLine *line, *tmp; - tan= copy_libblock(ta); + tan= copy_libblock(&ta->id); /* file name can be NULL */ if(ta->name) { diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 3aa289d0ef8..377eeef117e 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -751,7 +751,7 @@ Tex *copy_texture(Tex *tex) { Tex *texn; - texn= copy_libblock(tex); + texn= copy_libblock(&tex->id); if(texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima); else texn->ima= NULL; @@ -781,7 +781,7 @@ Tex *localize_texture(Tex *tex) { Tex *texn; - texn= copy_libblock(tex); + texn= copy_libblock(&tex->id); BLI_remlink(&G.main->tex, texn); /* image texture: free_texture also doesn't decrease */ diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index c7d2763774d..1d6972b9d61 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -118,7 +118,7 @@ World *copy_world(World *wrld) World *wrldn; int a; - wrldn= copy_libblock(wrld); + wrldn= copy_libblock(&wrld->id); for(a=0; amtex[a]) { @@ -142,7 +142,7 @@ World *localize_world(World *wrld) World *wrldn; int a; - wrldn= copy_libblock(wrld); + wrldn= copy_libblock(&wrld->id); BLI_remlink(&G.main->world, wrldn); for(a=0; a Date: Mon, 7 Nov 2011 12:55:18 +0000 Subject: Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch. --- source/blender/blenkernel/intern/constraint.c | 206 +++ source/blender/blenkernel/intern/context.c | 12 + source/blender/blenkernel/intern/depsgraph.c | 77 +- source/blender/blenkernel/intern/idcode.c | 1 + source/blender/blenkernel/intern/library.c | 11 + source/blender/blenkernel/intern/movieclip.c | 1033 ++++++++++++ source/blender/blenkernel/intern/object.c | 84 +- source/blender/blenkernel/intern/tracking.c | 2168 +++++++++++++++++++++++++ 8 files changed, 3569 insertions(+), 23 deletions(-) create mode 100644 source/blender/blenkernel/intern/movieclip.c create mode 100644 source/blender/blenkernel/intern/tracking.c (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 8b5cf3bd196..f904d6e66df 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -44,6 +44,7 @@ #include "BLI_utildefines.h" #include "DNA_armature_types.h" +#include "DNA_camera_types.h" #include "DNA_constraint_types.h" #include "DNA_modifier_types.h" #include "DNA_object_types.h" @@ -51,15 +52,19 @@ #include "DNA_curve_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" + #include "DNA_lattice_types.h" #include "DNA_scene_types.h" #include "DNA_text_types.h" +#include "DNA_tracking_types.h" +#include "DNA_movieclip_types.h" #include "BKE_action.h" #include "BKE_anim.h" /* for the curve calculation part */ #include "BKE_armature.h" #include "BKE_blender.h" +#include "BKE_camera.h" #include "BKE_constraint.h" #include "BKE_displist.h" #include "BKE_deform.h" @@ -72,6 +77,8 @@ #include "BKE_idprop.h" #include "BKE_shrinkwrap.h" #include "BKE_mesh.h" +#include "BKE_tracking.h" +#include "BKE_movieclip.h" #ifdef WITH_PYTHON #include "BPY_extern.h" @@ -3924,6 +3931,203 @@ static bConstraintTypeInfo CTI_PIVOT = { pivotcon_evaluate /* evaluate */ }; +/* ----------- Follow Track ------------- */ + +static void followtrack_new_data (void *cdata) +{ + bFollowTrackConstraint *data= (bFollowTrackConstraint *)cdata; + + data->clip= NULL; + data->flag|= FOLLOWTRACK_ACTIVECLIP; + data->reference= FOLLOWTRACK_TRACK; +} + +static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +{ + bFollowTrackConstraint *data= con->data; + + func(con, (ID**)&data->clip, userdata); +} + +static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +{ + Scene *scene= cob->scene; + bFollowTrackConstraint *data= con->data; + MovieClip *clip= data->clip; + MovieTrackingTrack *track; + + if(data->flag&FOLLOWTRACK_ACTIVECLIP) + clip= scene->clip; + + if(!clip || !data->track[0]) + return; + + track= BKE_tracking_named_track(&clip->tracking, data->track); + + if(!track) + return; + + if(data->reference==FOLLOWTRACK_BUNDLE) { + if(track->flag&TRACK_HAS_BUNDLE) { + float pos[3], mat[4][4], obmat[4][4]; + + copy_m4_m4(obmat, cob->matrix); + + BKE_get_tracking_mat(cob->scene, NULL, mat); + mul_v3_m4v3(pos, mat, track->bundle_pos); + + cob->matrix[3][0]+= pos[0]; + cob->matrix[3][1]+= pos[1]; + cob->matrix[3][2]+= pos[2]; + } + } else { + Object *camob= cob->scene->camera; + + if(camob) { + MovieClipUser user; + MovieTrackingMarker *marker; + float vec[3], disp[3], axis[3], mat[4][4]; + float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp); + float sensor_x, sensor_y, lens, len, d, ortho_scale= 1.f; + + where_is_object_mat(scene, camob, mat); + + /* camera axis */ + vec[0]= 0.f; + vec[1]= 0.f; + vec[2]= 1.f; + mul_v3_m4v3(axis, mat, vec); + + /* distance to projection plane */ + copy_v3_v3(vec, cob->matrix[3]); + sub_v3_v3(vec, mat[3]); + project_v3_v3v3(disp, vec, axis); + + len= len_v3(disp); + + if(len>FLT_EPSILON) { + float pos[2], rmat[4][4], shiftx= 0.0f, shifty= 0.0f, clipsta= 0.0f, clipend= 0.0f; + short is_ortho= 0, sensor_fit= CAMERA_SENSOR_FIT_AUTO; + Camera *cam= NULL; + + user.framenr= scene->r.cfra; + marker= BKE_tracking_get_marker(track, user.framenr); + + add_v2_v2v2(pos, marker->pos, track->offset); + + object_camera_intrinsics(camob, &cam, &is_ortho, &shiftx, &shifty, &clipsta, &clipend, &lens, &sensor_x, &sensor_y, &sensor_fit); + + if(is_ortho) { + if(cam) + ortho_scale= cam->ortho_scale; + + vec[0]= ortho_scale * (pos[0]-0.5f+shiftx); + vec[1]= ortho_scale * (pos[1]-0.5f+shifty); + vec[2]= -len; + + if(aspect>1.f) vec[1]/= aspect; + else vec[0]*= aspect; + + mul_v3_m4v3(disp, camob->obmat, vec); + + copy_m4_m4(rmat, camob->obmat); + zero_v3(rmat[3]); + mul_m4_m4m4(cob->matrix, rmat, cob->matrix); + + copy_v3_v3(cob->matrix[3], disp); + } + else { + d= (len*sensor_x) / (2.f*lens); + + vec[0]= d*(2.f*(pos[0]+shiftx)-1.f); + vec[1]= d*(2.f*(pos[1]+shifty)-1.f); + vec[2]= -len; + + if(aspect>1.f) vec[1]/= aspect; + else vec[0]*= aspect; + + mul_v3_m4v3(disp, camob->obmat, vec); + + /* apply camera rotation so Z-axis would be co-linear */ + copy_m4_m4(rmat, camob->obmat); + zero_v3(rmat[3]); + mul_m4_m4m4(cob->matrix, rmat, cob->matrix); + + copy_v3_v3(cob->matrix[3], disp); + } + } + } + } +} + +static bConstraintTypeInfo CTI_FOLLOWTRACK = { + CONSTRAINT_TYPE_FOLLOWTRACK, /* type */ + sizeof(bFollowTrackConstraint), /* size */ + "Follow Track", /* name */ + "bFollowTrackConstraint", /* struct name */ + NULL, /* free data */ + NULL, /* relink data */ + followtrack_id_looper, /* id looper */ + NULL, /* copy data */ + followtrack_new_data, /* new data */ + NULL, /* get constraint targets */ + NULL, /* flush constraint targets */ + NULL, /* get target matrix */ + followtrack_evaluate /* evaluate */ +}; + +/* ----------- Camre Solver ------------- */ + +static void camerasolver_new_data (void *cdata) +{ + bCameraSolverConstraint *data= (bCameraSolverConstraint *)cdata; + + data->clip= NULL; + data->flag|= CAMERASOLVER_ACTIVECLIP; +} + +static void camerasolver_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata) +{ + bCameraSolverConstraint *data= con->data; + + func(con, (ID**)&data->clip, userdata); +} + +static void camerasolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) +{ + Scene *scene= cob->scene; + bCameraSolverConstraint *data= con->data; + MovieClip *clip= data->clip; + + if(data->flag&CAMERASOLVER_ACTIVECLIP) + clip= scene->clip; + + if(clip) { + float mat[4][4], obmat[4][4]; + + BKE_tracking_get_interpolated_camera(&clip->tracking, scene->r.cfra, mat); + + copy_m4_m4(obmat, cob->matrix); + mul_m4_m4m4(cob->matrix, mat, obmat); + } +} + +static bConstraintTypeInfo CTI_CAMERASOLVER = { + CONSTRAINT_TYPE_CAMERASOLVER, /* type */ + sizeof(bCameraSolverConstraint), /* size */ + "Camera Solver", /* name */ + "bCameraSolverConstraint", /* struct name */ + NULL, /* free data */ + NULL, /* relink data */ + camerasolver_id_looper, /* id looper */ + NULL, /* copy data */ + camerasolver_new_data, /* new data */ + NULL, /* get constraint targets */ + NULL, /* flush constraint targets */ + NULL, /* get target matrix */ + camerasolver_evaluate /* evaluate */ +}; + /* ************************* Constraints Type-Info *************************** */ /* All of the constraints api functions use bConstraintTypeInfo structs to carry out * and operations that involve constraint specific code. @@ -3962,6 +4166,8 @@ static void constraints_init_typeinfo (void) constraintsTypeInfo[23]= &CTI_TRANSLIKE; /* Copy Transforms Constraint */ constraintsTypeInfo[24]= &CTI_SAMEVOL; /* Maintain Volume Constraint */ constraintsTypeInfo[25]= &CTI_PIVOT; /* Pivot Constraint */ + constraintsTypeInfo[26]= &CTI_FOLLOWTRACK; /* Follow Track Constraint */ + constraintsTypeInfo[27]= &CTI_CAMERASOLVER; /* Camera Solver Constraint */ } /* This function should be used for getting the appropriate type-info when only diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 18c08b617de..9e9a0ca2d54 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -361,6 +361,13 @@ struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) return NULL; } +struct SpaceClip *CTX_wm_space_clip(const bContext *C) +{ + if(C->wm.area && C->wm.area->spacetype==SPACE_CLIP) + return C->wm.area->spacedata.first; + return NULL; +} + void CTX_wm_manager_set(bContext *C, wmWindowManager *wm) { C->wm.manager= wm; @@ -882,6 +889,11 @@ struct Text *CTX_data_edit_text(const bContext *C) return ctx_data_pointer_get(C, "edit_text"); } +struct MovieClip *CTX_data_edit_movieclip(const bContext *C) +{ + return ctx_data_pointer_get(C, "edit_movieclip"); +} + struct EditBone *CTX_data_active_bone(const bContext *C) { return ctx_data_pointer_get(C, "active_bone"); diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 51edee9ea71..79930fdd8bf 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -50,6 +50,7 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_movieclip_types.h" #include "BKE_animsys.h" #include "BKE_action.h" @@ -639,7 +640,26 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - if (cti && cti->get_constraint_targets) { + if(!cti) + continue; + + /* special case for camera tracking -- it doesn't use targets to define relations */ + if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) { + if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) { + bFollowTrackConstraint *data= (bFollowTrackConstraint *)con->data; + + if((data->clip || data->flag&FOLLOWTRACK_ACTIVECLIP) && data->track[0]) { + if(scene->camera) { + node2 = dag_get_node(dag, scene->camera); + dag_add_relation(dag, node2, node, DAG_RL_DATA_OB|DAG_RL_OB_OB, cti->name); + } + } + } + + dag_add_relation(dag,scenenode,node,DAG_RL_SCENE, "Scene Relation"); + addtoroot = 0; + } + else if (cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); for (ct= targets.first; ct; ct= ct->next) { @@ -2127,18 +2147,25 @@ static void dag_object_time_update_flags(Object *ob) ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - if (cti && cti->get_constraint_targets) { - cti->get_constraint_targets(con, &targets); - - for (ct= targets.first; ct; ct= ct->next) { - if (ct->tar) { - ob->recalc |= OB_RECALC_OB; - break; + if (cti) { + /* special case for camera tracking -- it doesn't use targets to define relations */ + if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) { + ob->recalc |= OB_RECALC_OB; + } + else if (cti->get_constraint_targets) { + cti->get_constraint_targets(con, &targets); + + for (ct= targets.first; ct; ct= ct->next) { + if (ct->tar) { + ob->recalc |= OB_RECALC_OB; + break; + } } + + if (cti->flush_constraint_targets) + cti->flush_constraint_targets(con, &targets, 1); } - if (cti->flush_constraint_targets) - cti->flush_constraint_targets(con, &targets, 1); } } } @@ -2511,6 +2538,36 @@ static void dag_id_flush_update(Scene *sce, ID *id) BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH); } + if(idtype == ID_MC) { + for(obt=bmain->object.first; obt; obt= obt->id.next){ + bConstraint *con; + for (con = obt->constraints.first; con; con=con->next) { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER)) { + obt->recalc |= OB_RECALC_OB; + break; + } + } + } + + if(sce->nodetree) { + bNode *node; + + for(node= sce->nodetree->nodes.first; node; node= node->next) { + if(node->id==id) { + nodeUpdate(sce->nodetree, node); + } + } + } + } + + /* camera's matrix is used to orient reconstructed stuff, + so it should happen tracking-related constraints recalculation + when camera is changing (sergey) */ + if(sce->camera && &sce->camera->id == id && object_get_movieclip(sce, sce->camera, 1)) { + dag_id_flush_update(sce, &sce->clip->id); + } + /* update editors */ dag_editors_update(bmain, id); } diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index d305499d3a1..0824a9f6685 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -78,6 +78,7 @@ static IDType idtypes[]= { { ID_VF, "VFont", "fonts", IDTYPE_FLAGS_ISLINKABLE}, { ID_WO, "World", "worlds", IDTYPE_FLAGS_ISLINKABLE}, { ID_WM, "WindowManager", "window_managers", 0}, + { ID_MC, "MovieClip", "movieclips", IDTYPE_FLAGS_ISLINKABLE}, }; static int nidtypes= sizeof(idtypes)/sizeof(idtypes[0]); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 878b87759b7..650f85da5b3 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -70,6 +70,7 @@ #include "DNA_windowmanager_types.h" #include "DNA_world_types.h" #include "DNA_gpencil_types.h" +#include "DNA_movieclip_types.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -111,6 +112,7 @@ #include "BKE_fcurve.h" #include "BKE_speaker.h" #include "BKE_utildefines.h" +#include "BKE_movieclip.h" #include "RNA_access.h" @@ -484,6 +486,8 @@ ListBase *which_libbase(Main *mainlib, short type) return &(mainlib->wm); case ID_GD: return &(mainlib->gpencil); + case ID_MC: + return &(mainlib->movieclip); } return NULL; } @@ -565,6 +569,7 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++]= &(main->scene); lb[a++]= &(main->library); lb[a++]= &(main->wm); + lb[a++]= &(main->movieclip); lb[a]= NULL; @@ -673,6 +678,9 @@ static ID *alloc_libblock_notest(short type) case ID_GD: id = MEM_callocN(sizeof(bGPdata), "Grease Pencil"); break; + case ID_MC: + id = MEM_callocN(sizeof(MovieClip), "Movie Clip"); + break; } return id; } @@ -878,6 +886,9 @@ void free_libblock(ListBase *lb, void *idv) case ID_GD: free_gpencil_data((bGPdata *)id); break; + case ID_MC: + free_movieclip((MovieClip *)id); + break; } if (id->properties) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c new file mode 100644 index 00000000000..18a7ad65dae --- /dev/null +++ b/source/blender/blenkernel/intern/movieclip.c @@ -0,0 +1,1033 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation, + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/movieclip.c + * \ingroup bke + */ + + +#include +#include +#include + +#ifndef WIN32 +#include +#else +#include +#endif + +#include + +#ifdef _WIN32 +#define open _open +#define close _close +#endif + +#include "MEM_guardedalloc.h" + +#include "DNA_constraint_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_movieclip_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_view3d_types.h" + +#include "BLI_utildefines.h" + +#include "BLI_blenlib.h" +#include "BLI_ghash.h" +#include "BLI_math.h" +#include "BLI_mempool.h" +#include "BLI_threads.h" + +#include "BKE_constraint.h" +#include "BKE_library.h" +#include "BKE_global.h" +#include "BKE_main.h" +#include "BKE_utildefines.h" +#include "BKE_movieclip.h" +#include "BKE_image.h" /* openanim */ +#include "BKE_tracking.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" +#include "IMB_moviecache.h" + +/*********************** movieclip buffer loaders *************************/ + +static int sequence_guess_offset(const char *full_name, int head_len, int numlen) +{ + char num[FILE_MAX]= {0}; + + BLI_strncpy(num, full_name+head_len, numlen+1); + + return atoi(num); +} + +static int rendersize_to_proxy(MovieClipUser *user, int flag) +{ + if((flag&MCLIP_USE_PROXY)==0) + return IMB_PROXY_NONE; + + switch(user->render_size) { + case MCLIP_PROXY_RENDER_SIZE_25: + return IMB_PROXY_25; + + case MCLIP_PROXY_RENDER_SIZE_50: + return IMB_PROXY_50; + + case MCLIP_PROXY_RENDER_SIZE_75: + return IMB_PROXY_75; + + case MCLIP_PROXY_RENDER_SIZE_100: + return IMB_PROXY_100; + + case MCLIP_PROXY_RENDER_SIZE_FULL: + return IMB_PROXY_NONE; + } + + return IMB_PROXY_NONE; +} + +static int rendersize_to_number(int render_size) +{ + switch(render_size) { + case MCLIP_PROXY_RENDER_SIZE_25: + return 25; + + case MCLIP_PROXY_RENDER_SIZE_50: + return 50; + + case MCLIP_PROXY_RENDER_SIZE_75: + return 75; + + case MCLIP_PROXY_RENDER_SIZE_100: + return 100; + + case MCLIP_PROXY_RENDER_SIZE_FULL: + return 100; + } + + return 100; +} + +static int get_timecode(MovieClip *clip, int flag) +{ + if((flag&MCLIP_USE_PROXY)==0) + return IMB_TC_NONE; + + return clip->proxy.tc; +} + +static void get_sequence_fname(MovieClip *clip, int framenr, char *name) +{ + unsigned short numlen; + char head[FILE_MAX], tail[FILE_MAX]; + int offset; + + BLI_strncpy(name, clip->name, sizeof(clip->name)); + BLI_stringdec(name, head, tail, &numlen); + + /* movieclips always points to first image from sequence, + autoguess offset for now. could be something smarter in the future */ + offset= sequence_guess_offset(clip->name, strlen(head), numlen); + + if(numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1); + else strncpy(name, clip->name, sizeof(name)); + + if(clip->id.lib) + BLI_path_abs(name, clip->id.lib->filepath); + else + BLI_path_abs(name, G.main->name); +} + +/* supposed to work with sequences only */ +static void get_proxy_fname(MovieClip *clip, int proxy_render_size, int undistorted, int framenr, char *name) +{ + int size= rendersize_to_number(proxy_render_size); + char dir[FILE_MAX], clipdir[FILE_MAX], clipfile[FILE_MAX]; + + BLI_split_dirfile(clip->name, clipdir, clipfile, FILE_MAX, FILE_MAX); + + if(clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) { + strcpy(dir, clip->proxy.dir); + } else { + BLI_snprintf(dir, FILE_MAX, "%s/BL_proxy", clipdir); + } + + if(undistorted) + BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d_undistorted/%08d", dir, clipfile, size, framenr); + else + BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d/%08d", dir, clipfile, size, framenr); + + BLI_path_abs(name, G.main->name); + BLI_path_frame(name, 1, 0); + + strcat(name, ".jpg"); +} + +static ImBuf *movieclip_load_sequence_file(MovieClip *clip, MovieClipUser *user, int framenr, int flag) +{ + struct ImBuf *ibuf; + char name[FILE_MAX]; + int loadflag, size, undistort; + + size= rendersize_to_number(user->render_size); + + undistort= user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT; + + if((flag&MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL) + get_proxy_fname(clip, user->render_size, undistort, framenr, name); + else + get_sequence_fname(clip, framenr, name); + + loadflag= IB_rect|IB_multilayer; + + /* read ibuf */ + ibuf= IMB_loadiffname(name, loadflag); + + return ibuf; +} + +static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, int framenr, int flag) +{ + ImBuf *ibuf= NULL; + int tc= get_timecode(clip, flag); + int proxy= rendersize_to_proxy(user, flag); + char str[FILE_MAX]; + + if(!clip->anim) { + BLI_strncpy(str, clip->name, FILE_MAX); + + if(clip->id.lib) + BLI_path_abs(str, clip->id.lib->filepath); + else + BLI_path_abs(str, G.main->name); + + /* FIXME: make several stream accessible in image editor, too */ + clip->anim= openanim(str, IB_rect, 0); + + if(clip->anim) { + if(clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) { + char dir[FILE_MAX]; + strcpy(dir, clip->proxy.dir); + BLI_path_abs(dir, G.main->name); + IMB_anim_set_index_dir(clip->anim, dir); + } + } + } + + if(clip->anim) { + int dur; + int fra= framenr-1; + + dur= IMB_anim_get_duration(clip->anim, tc); + fra= framenr-1; + + if(fra<0) + fra= 0; + + if(fra>(dur-1)) + fra= dur-1; + + ibuf= IMB_anim_absolute(clip->anim, fra, tc, proxy); + } + + return ibuf; +} + +/*********************** image buffer cache *************************/ + +typedef struct MovieClipCache { + /* regular movie cache */ + struct MovieCache *moviecache; + + /* cache for stable shot */ + int stable_framenr; + float stable_loc[2], stable_scale, stable_angle; + ImBuf *stableibuf; + int proxy; + short render_flag; + + /* cache for undistorted shot */ + int undist_framenr; + float principal[2]; + float k1, k2, k3; + ImBuf *undistibuf; +} MovieClipCache; + +typedef struct MovieClipImBufCacheKey { + int framenr; + int proxy; + short render_flag; +} MovieClipImBufCacheKey; + +static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) +{ + MovieClipImBufCacheKey *key= (MovieClipImBufCacheKey*)userkey; + + *framenr= key->framenr; + *proxy= key->proxy; + *render_flags= key->render_flag; +} + +static unsigned int moviecache_hashhash(const void *keyv) +{ + MovieClipImBufCacheKey *key= (MovieClipImBufCacheKey*)keyv; + int rval= key->framenr; + + return rval; +} + +static int moviecache_hashcmp(const void *av, const void *bv) +{ + const MovieClipImBufCacheKey *a= (MovieClipImBufCacheKey*)av; + const MovieClipImBufCacheKey *b= (MovieClipImBufCacheKey*)bv; + + if(a->framenrframenr) return -1; + else if(a->framenr>b->framenr) return 1; + + if(a->proxyproxy) return -1; + else if(a->proxy>b->proxy) return 1; + + if(a->render_flagrender_flag) return -1; + else if(a->render_flag>b->render_flag) return 1; + + return 0; +} + +static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag) +{ + if(clip->cache) { + MovieClipImBufCacheKey key; + + key.framenr= user?user->framenr:clip->lastframe; + + if(flag&MCLIP_USE_PROXY) { + key.proxy= rendersize_to_proxy(user, flag); + key.render_flag= user->render_flag; + } + else { + key.proxy= IMB_PROXY_NONE; + key.render_flag= 0; + } + + return IMB_moviecache_get(clip->cache->moviecache, &key); + } + + return NULL; +} + +static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag) +{ + MovieClipImBufCacheKey key; + + if(!clip->cache) { + clip->cache= MEM_callocN(sizeof(MovieClipCache), "movieClipCache"); + + clip->cache->moviecache= IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash, + moviecache_hashcmp, moviecache_keydata); + } + + key.framenr= user?user->framenr:clip->lastframe; + + if(flag&MCLIP_USE_PROXY) { + key.proxy= rendersize_to_proxy(user, flag); + key.render_flag= user->render_flag; + } + else { + key.proxy= IMB_PROXY_NONE; + key.render_flag= 0; + } + + IMB_moviecache_put(clip->cache->moviecache, &key, ibuf); +} + +/*********************** common functions *************************/ + +/* only image block itself */ +static MovieClip *movieclip_alloc(const char *name) +{ + MovieClip *clip; + + clip= alloc_libblock(&G.main->movieclip, ID_MC, name); + + clip->aspx= clip->aspy= 1.0f; + + clip->tracking.camera.sensor_width= 35.0f; + clip->tracking.camera.pixel_aspect= 1.0f; + clip->tracking.camera.units= CAMERA_UNITS_MM; + + clip->tracking.settings.frames_limit= 0; + clip->tracking.settings.keyframe1= 1; + clip->tracking.settings.keyframe2= 30; + clip->tracking.settings.dist= 1; + + clip->tracking.stabilization.scaleinf= 1.0f; + clip->tracking.stabilization.locinf= 1.0f; + clip->tracking.stabilization.rotinf= 1.0f; + clip->tracking.stabilization.maxscale= 2.0f; + + clip->proxy.build_size_flag= IMB_PROXY_25; + clip->proxy.build_tc_flag= IMB_TC_RECORD_RUN|IMB_TC_FREE_RUN|IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN; + clip->proxy.quality= 90; + + return clip; +} + +/* checks if image was already loaded, then returns same image + otherwise creates new. + does not load ibuf itself + pass on optional frame for #name images */ +MovieClip *BKE_add_movieclip_file(const char *name) +{ + MovieClip *clip; + MovieClipUser user; + int file, len, width, height; + const char *libname; + char str[FILE_MAX], strtest[FILE_MAX]; + + BLI_strncpy(str, name, sizeof(str)); + BLI_path_abs(str, G.main->name); + + /* exists? */ + file= open(str, O_BINARY|O_RDONLY); + if(file== -1) return NULL; + close(file); + + /* ** first search an identical clip ** */ + for(clip= G.main->movieclip.first; clip; clip= clip->id.next) { + BLI_strncpy(strtest, clip->name, sizeof(clip->name)); + BLI_path_abs(strtest, G.main->name); + + if(strcmp(strtest, str)==0) { + BLI_strncpy(clip->name, name, sizeof(clip->name)); /* for stringcode */ + clip->id.us++; /* officially should not, it doesn't link here! */ + + return clip; + } + } + + /* ** add new movieclip ** */ + + /* create a short library name */ + len= strlen(name); + + while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--; + libname= name+len; + + clip= movieclip_alloc(libname); + BLI_strncpy(clip->name, name, sizeof(clip->name)); + + if(BLI_testextensie_array(name, imb_ext_movie)) clip->source= MCLIP_SRC_MOVIE; + else clip->source= MCLIP_SRC_SEQUENCE; + + user.framenr= 1; + BKE_movieclip_get_size(clip, &user, &width, &height); + if(width && height) { + clip->tracking.camera.principal[0]= ((float)width)/2; + clip->tracking.camera.principal[1]= ((float)height)/2; + + clip->tracking.camera.focal= 24.0f*width/clip->tracking.camera.sensor_width; + } + + return clip; +} + +static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int *width, int *height) +{ + *width= ibuf->x; + *height= ibuf->y; + + if(clip->flag&MCLIP_USE_PROXY) { + switch(user->render_size) { + case MCLIP_PROXY_RENDER_SIZE_25: + (*width)*= 4; + (*height)*= 4; + break; + + case MCLIP_PROXY_RENDER_SIZE_50: + (*width)*= 2.0f; + (*height)*= 2.0f; + break; + + case MCLIP_PROXY_RENDER_SIZE_75: + *width= ((float)*width)*4.0f/3.0f; + *height= ((float)*height)*4.0f/3.0f; + break; + } + } +} + +static int need_undistorted_cache(MovieClipUser *user, int flag) +{ + if (!user) + return 0; + + /* only full undistorted render can be used as on-fly undistorting image */ + if(flag&MCLIP_USE_PROXY) { + if(user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL || (user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT)==0) + return 0; + } + else return 0; + + return 1; +} + +static ImBuf *get_undistorted_cache(MovieClip *clip, MovieClipUser *user) +{ + MovieClipCache *cache= clip->cache; + MovieTrackingCamera *camera= &clip->tracking.camera; + int framenr= user?user->framenr:clip->lastframe; + + /* no cache or no cached undistorted image */ + if(!clip->cache || !clip->cache->undistibuf) + return NULL; + + /* undistortion happened for other frame */ + if(cache->undist_framenr!=framenr) + return NULL; + + /* check for distortion model changes */ + if(!equals_v2v2(camera->principal, cache->principal)) + return NULL; + + if(!equals_v3v3(&camera->k1, &cache->k1)) + return NULL; + + IMB_refImBuf(cache->undistibuf); + + return cache->undistibuf; +} + +static ImBuf *get_undistorted_ibuf(MovieClip *clip, struct MovieDistortion *distoriton, ImBuf *ibuf) +{ + ImBuf *undistibuf; + + /* XXX: because of #27997 do not use float buffers to undistort, + otherwise, undistorted proxy can be darker than it should */ + imb_freerectfloatImBuf(ibuf); + + if(distoriton) + undistibuf= BKE_tracking_distortion_exec(distoriton, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, 1); + else + undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f); + + if(undistibuf->userflags|= IB_RECT_INVALID) { + ibuf->userflags&= ~IB_RECT_INVALID; + IMB_rect_from_float(undistibuf); + } + + IMB_scaleImBuf(undistibuf, ibuf->x, ibuf->y); + + return undistibuf; +} + +static ImBuf *put_undistorted_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf) +{ + MovieClipCache *cache= clip->cache; + MovieTrackingCamera *camera= &clip->tracking.camera; + + copy_v2_v2(cache->principal, camera->principal); + copy_v3_v3(&cache->k1, &camera->k1); + cache->undist_framenr= user?user->framenr:clip->lastframe; + + if(cache->undistibuf) + IMB_freeImBuf(cache->undistibuf); + + cache->undistibuf= get_undistorted_ibuf(clip, NULL, ibuf); + + if(cache->stableibuf) { + /* force stable buffer be re-calculated */ + IMB_freeImBuf(cache->stableibuf); + cache->stableibuf= NULL; + } + + IMB_refImBuf(cache->undistibuf); + + return cache->undistibuf; +} + +ImBuf *BKE_movieclip_get_ibuf(MovieClip *clip, MovieClipUser *user) +{ + ImBuf *ibuf= NULL; + int framenr= user?user->framenr:clip->lastframe; + int cache_undistorted= 0; + + /* cache isn't threadsafe itself and also loading of movies + can't happen from concurent threads that's why we use lock here */ + BLI_lock_thread(LOCK_MOVIECLIP); + + /* try to obtain cached undistorted image first */ + if(need_undistorted_cache(user, clip->flag)) { + ibuf= get_undistorted_cache(clip, user); + if(!ibuf) + cache_undistorted= 1; + } + + if(!ibuf) + ibuf= get_imbuf_cache(clip, user, clip->flag); + + if(!ibuf) { + int use_sequence= 1; + + /* undistorted proxies for movies should be read as image sequence */ + use_sequence&= user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT; + use_sequence&= user->render_size!=MCLIP_PROXY_RENDER_SIZE_FULL; + + if(clip->source==MCLIP_SRC_SEQUENCE || use_sequence) + ibuf= movieclip_load_sequence_file(clip, user, framenr, clip->flag); + else { + ibuf= movieclip_load_movie_file(clip, user, framenr, clip->flag); + } + + if(ibuf) + put_imbuf_cache(clip, user, ibuf, clip->flag); + } + + if(ibuf) { + clip->lastframe= framenr; + real_ibuf_size(clip, user, ibuf, &clip->lastsize[0], &clip->lastsize[1]); + + /* put undistorted frame to cache */ + if(cache_undistorted) { + ImBuf *tmpibuf= ibuf; + ibuf= put_undistorted_cache(clip, user, tmpibuf); + IMB_freeImBuf(tmpibuf); + } + } + + BLI_unlock_thread(LOCK_MOVIECLIP); + + return ibuf; +} + +ImBuf *BKE_movieclip_get_ibuf_flag(MovieClip *clip, MovieClipUser *user, int flag) +{ + ImBuf *ibuf= NULL; + int framenr= user?user->framenr:clip->lastframe; + int cache_undistorted= 0; + + /* cache isn't threadsafe itself and also loading of movies + can't happen from concurent threads that's why we use lock here */ + BLI_lock_thread(LOCK_MOVIECLIP); + + /* try to obtain cached undistorted image first */ + if(need_undistorted_cache(user, flag)) { + ibuf= get_undistorted_cache(clip, user); + if(!ibuf) + cache_undistorted= 1; + } + + ibuf= get_imbuf_cache(clip, user, flag); + + if(!ibuf) { + if(clip->source==MCLIP_SRC_SEQUENCE) { + ibuf= movieclip_load_sequence_file(clip, user, framenr, flag); + } else { + ibuf= movieclip_load_movie_file(clip, user, framenr, flag); + } + + if(ibuf) { + int bits= MCLIP_USE_PROXY|MCLIP_USE_PROXY_CUSTOM_DIR; + + if((flag&bits)==(clip->flag&bits)) + put_imbuf_cache(clip, user, ibuf, clip->flag); + } + } + + /* put undistorted frame to cache */ + if(ibuf && cache_undistorted) { + ImBuf *tmpibuf= ibuf; + ibuf= put_undistorted_cache(clip, user, tmpibuf); + IMB_freeImBuf(tmpibuf); + } + + BLI_unlock_thread(LOCK_MOVIECLIP); + + return ibuf; +} + +ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle) +{ + ImBuf *ibuf, *stableibuf= NULL; + int framenr= user?user->framenr:clip->lastframe; + + ibuf= BKE_movieclip_get_ibuf(clip, user); + + if(!ibuf) + return NULL; + + if(clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) { + float tloc[2], tscale, tangle; + short proxy= IMB_PROXY_NONE; + int render_flag= 0; + + if(clip->flag&MCLIP_USE_PROXY) { + proxy= rendersize_to_proxy(user, clip->flag); + render_flag= user->render_flag; + } + + if(clip->cache->stableibuf && clip->cache->stable_framenr==framenr) { /* there's cached ibuf */ + if(clip->cache->render_flag==render_flag && clip->cache->proxy==proxy) { /* cached ibuf used the same proxy settings */ + stableibuf= clip->cache->stableibuf; + + BKE_tracking_stabilization_data(&clip->tracking, framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle); + + /* check for stabilization parameters */ + if(!equals_v2v2(tloc, clip->cache->stable_loc) || tscale!=clip->cache->stable_scale || tangle!=clip->cache->stable_angle) { + stableibuf= NULL; + } + } + } + + if(!stableibuf) { + if(clip->cache->stableibuf) + IMB_freeImBuf(clip->cache->stableibuf); + + stableibuf= BKE_tracking_stabilize(&clip->tracking, framenr, ibuf, tloc, &tscale, &tangle); + + copy_v2_v2(clip->cache->stable_loc, tloc); + clip->cache->stable_scale= tscale; + clip->cache->stable_angle= tangle; + clip->cache->stable_framenr= framenr; + clip->cache->stableibuf= stableibuf; + clip->cache->proxy= proxy; + clip->cache->render_flag= render_flag; + } + + IMB_refImBuf(stableibuf); + + if(loc) copy_v2_v2(loc, tloc); + if(scale) *scale= tscale; + if(angle) *angle= tangle; + } else { + if(loc) zero_v2(loc); + if(scale) *scale= 1.0f; + if(angle) *angle= 0.0f; + + stableibuf= ibuf; + } + + if(stableibuf!=ibuf) { + IMB_freeImBuf(ibuf); + ibuf= stableibuf; + } + + return ibuf; + +} + +int BKE_movieclip_has_frame(MovieClip *clip, MovieClipUser *user) +{ + ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user); + + if(ibuf) { + IMB_freeImBuf(ibuf); + return 1; + } + + return 0; +} + +void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, int *height) +{ + if(!user || user->framenr==clip->lastframe) { + *width= clip->lastsize[0]; + *height= clip->lastsize[1]; + } else { + ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user); + + if(ibuf && ibuf->x && ibuf->y) { + real_ibuf_size(clip, user, ibuf, width, height); + } else { + *width= 0; + *height= 0; + } + + if(ibuf) + IMB_freeImBuf(ibuf); + } +} + +void BKE_movieclip_aspect(MovieClip *clip, float *aspx, float *aspy) +{ + *aspx= *aspy= 1.0; + + /* x is always 1 */ + *aspy = clip->aspy/clip->aspx/clip->tracking.camera.pixel_aspect; +} + +/* get segments of cached frames. useful for debugging cache policies */ +void BKE_movieclip_get_cache_segments(MovieClip *clip, MovieClipUser *user, int *totseg_r, int **points_r) +{ + *totseg_r= 0; + *points_r= NULL; + + if(clip->cache) { + int proxy= rendersize_to_proxy(user, clip->flag); + + IMB_moviecache_get_cache_segments(clip->cache->moviecache, proxy, user->render_flag, totseg_r, points_r); + } +} + +void BKE_movieclip_user_set_frame(MovieClipUser *iuser, int framenr) +{ + /* TODO: clamp framenr here? */ + + iuser->framenr= framenr; +} + +static void free_buffers(MovieClip *clip) +{ + if(clip->cache) { + IMB_moviecache_free(clip->cache->moviecache); + + if(clip->cache->stableibuf) + IMB_freeImBuf(clip->cache->stableibuf); + + if(clip->cache->undistibuf) + IMB_freeImBuf(clip->cache->undistibuf); + + MEM_freeN(clip->cache); + clip->cache= NULL; + } + + if(clip->anim) { + IMB_free_anim(clip->anim); + clip->anim= FALSE; + } +} + +void BKE_movieclip_reload(MovieClip *clip) +{ + /* clear cache */ + free_buffers(clip); + + clip->tracking.stabilization.ok= 0; + + /* update clip source */ + if(BLI_testextensie_array(clip->name, imb_ext_movie)) clip->source= MCLIP_SRC_MOVIE; + else clip->source= MCLIP_SRC_SEQUENCE; +} + +void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes) +{ + if(scopes->ok) return; + + if(scopes->track_preview) { + IMB_freeImBuf(scopes->track_preview); + scopes->track_preview= NULL; + } + + scopes->marker= NULL; + scopes->track= NULL; + + if(clip) { + if(clip->tracking.act_track) { + MovieTrackingTrack *track= clip->tracking.act_track; + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr); + + if(marker->flag&MARKER_DISABLED) { + scopes->track_disabled= 1; + } else { + ImBuf *ibuf= BKE_movieclip_get_ibuf(clip, user); + + scopes->track_disabled= 0; + + if(ibuf && ibuf->rect) { + ImBuf *tmpibuf; + MovieTrackingMarker undist_marker= *marker; + + if(user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT) { + int width, height; + float aspy= 1.0f/clip->tracking.camera.pixel_aspect;; + + BKE_movieclip_get_size(clip, user, &width, &height); + + undist_marker.pos[0]*= width; + undist_marker.pos[1]*= height*aspy; + + BKE_tracking_invert_intrinsics(&clip->tracking, undist_marker.pos, undist_marker.pos); + + undist_marker.pos[0]/= width; + undist_marker.pos[1]/= height*aspy; + } + + tmpibuf= BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 1, 1, scopes->track_pos, NULL); + + if(tmpibuf->rect_float) + IMB_rect_from_float(tmpibuf); + + if(tmpibuf->rect) + scopes->track_preview= tmpibuf; + else + IMB_freeImBuf(tmpibuf); + } + + IMB_freeImBuf(ibuf); + } + + if((track->flag&TRACK_LOCKED)==0) { + scopes->marker= marker; + scopes->track= track; + scopes->slide_scale[0]= track->pat_max[0]-track->pat_min[0]; + scopes->slide_scale[1]= track->pat_max[1]-track->pat_min[1]; + } + } + } + + scopes->framenr= user->framenr; + scopes->ok= 1; +} + +static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, int undistorted) +{ + char name[FILE_MAXFILE+FILE_MAXDIR]; + int quality, rectx, recty; + int size= size= rendersize_to_number(proxy_render_size); + ImBuf *scaleibuf; + + get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name); + + rectx= ibuf->x*size/100.0f; + recty= ibuf->y*size/100.0f; + + scaleibuf= IMB_dupImBuf(ibuf); + + IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty); + + quality= clip->proxy.quality; + scaleibuf->ftype= JPG | quality; + + /* unsupported feature only confuses other s/w */ + if(scaleibuf->depth==32) + scaleibuf->depth= 24; + + BLI_lock_thread(LOCK_MOVIECLIP); + + BLI_make_existing_file(name); + if(IMB_saveiff(scaleibuf, name, IB_rect)==0) + perror(name); + + BLI_unlock_thread(LOCK_MOVIECLIP); + + IMB_freeImBuf(scaleibuf); +} + +void BKE_movieclip_build_proxy_frame(MovieClip *clip, struct MovieDistortion *distortion, + int cfra, int *build_sizes, int build_count, int undistorted) +{ + ImBuf *ibuf; + MovieClipUser user; + + user.framenr= cfra; + + ibuf= BKE_movieclip_get_ibuf_flag(clip, &user, 0); + + if(ibuf) { + ImBuf *tmpibuf= ibuf; + int i; + + if(undistorted) + tmpibuf= get_undistorted_ibuf(clip, distortion, ibuf); + + for(i= 0; itracking); +} + +void unlink_movieclip(Main *bmain, MovieClip *clip) +{ + bScreen *scr; + ScrArea *area; + SpaceLink *sl; + Scene *sce; + Object *ob; + + for(scr= bmain->screen.first; scr; scr= scr->id.next) { + for(area= scr->areabase.first; area; area= area->next) { + for(sl= area->spacedata.first; sl; sl= sl->next) { + if(sl->spacetype==SPACE_CLIP) { + SpaceClip *sc= (SpaceClip *) sl; + + if(sc->clip==clip) + sc->clip= NULL; + } + else if(sl->spacetype==SPACE_VIEW3D) { + View3D *v3d= (View3D *) sl; + BGpic *bgpic; + + for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) { + if(bgpic->clip==clip) + bgpic->clip= NULL; + } + } + } + } + } + + for(sce= bmain->scene.first; sce; sce= sce->id.next) { + if(sce->clip==clip) + sce->clip= NULL; + } + + for(ob= bmain->object.first; ob; ob= ob->id.next) { + bConstraint *con= ob->constraints.first; + + for (con= ob->constraints.first; con; con= con->next) { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + + if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) { + bFollowTrackConstraint *data= (bFollowTrackConstraint *) con->data; + + if(data->clip==clip) + data->clip= NULL; + } + else if(cti->type==CONSTRAINT_TYPE_CAMERASOLVER) { + bCameraSolverConstraint *data= (bCameraSolverConstraint *) con->data; + + if(data->clip==clip) + data->clip= NULL; + } + } + } + + clip->id.us= 0; +} diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 1d654839969..45bd8f095a4 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -46,6 +46,7 @@ #include "DNA_material_types.h" #include "DNA_meta_types.h" #include "DNA_meshdata_types.h" +#include "DNA_movieclip_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_sequence_types.h" @@ -1810,11 +1811,30 @@ void set_no_parent_ipo(int val) no_parent_ipo= val; } -void where_is_object_time(Scene *scene, Object *ob, float ctime) +static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[4][4]) { - float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY; - float stime=ctime, fac1, fac2; + float *fp1, *fp2; + float fac1, fac2; int a; + + // include framerate + fac1= ( 1.0f / (1.0f + (float)fabs(ob->sf)) ); + if(fac1 >= 1.0f) return 0; + fac2= 1.0f-fac1; + + fp1= obmat[0]; + fp2= slowmat[0]; + for(a=0; a<16; a++, fp1++, fp2++) { + fp1[0]= fac1*fp1[0] + fac2*fp2[0]; + } + + return 1; +} + +void where_is_object_time(Scene *scene, Object *ob, float ctime) +{ + float slowmat[4][4] = MAT4_UNITY; + float stime=ctime; /* new version: correct parent+vertexparent and track+parent */ /* this one only calculates direct attached parent and track */ @@ -1848,16 +1868,8 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) * An old-fashioned hack which probably doesn't really cut it anymore */ if(ob->partype & PARSLOW) { - // include framerate - fac1= ( 1.0f / (1.0f + (float)fabs(ob->sf)) ); - if(fac1 >= 1.0f) return; - fac2= 1.0f-fac1; - - fp1= ob->obmat[0]; - fp2= slowmat[0]; - for(a=0; a<16; a++, fp1++, fp2++) { - fp1[0]= fac1*fp1[0] + fac2*fp2[0]; - } + if(!where_is_object_parslow(ob, ob->obmat, slowmat)) + return; } } else { @@ -1881,6 +1893,27 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) else ob->transflag &= ~OB_NEG_SCALE; } +/* get object transformation matrix without recalculating dependencies and + constraints -- assume dependencies are already solved by depsgraph. + no changes to object and it's parent would be done. + used for bundles orientation in 3d space relative to parented blender camera */ +void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4]) +{ + float slowmat[4][4] = MAT4_UNITY; + + if(ob->parent) { + Object *par= ob->parent; + + solve_parenting(scene, ob, par, obmat, slowmat, 1); + + if(ob->partype & PARSLOW) + where_is_object_parslow(ob, obmat, slowmat); + } + else { + object_to_mat4(ob, obmat); + } +} + static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul) { float totmat[4][4]; @@ -2811,3 +2844,28 @@ void object_relink(Object *ob) ID_NEW(ob->proxy); ID_NEW(ob->proxy_group); } + +MovieClip *object_get_movieclip(Scene *scene, Object *ob, int use_default) +{ + MovieClip *clip= use_default ? scene->clip : NULL; + bConstraint *con= ob->constraints.first, *scon= NULL; + + while(con){ + if(con->type==CONSTRAINT_TYPE_CAMERASOLVER){ + if(scon==NULL || (scon->flag&CONSTRAINT_OFF)) + scon= con; + } + + con= con->next; + } + + if(scon) { + bCameraSolverConstraint *solver= scon->data; + if((solver->flag&CAMERASOLVER_ACTIVECLIP)==0) + clip= solver->clip; + else + clip= scene->clip; + } + + return clip; +} diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c new file mode 100644 index 00000000000..06a985e7d72 --- /dev/null +++ b/source/blender/blenkernel/intern/tracking.c @@ -0,0 +1,2168 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation, + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/tracking.c + * \ingroup bke + */ + +#include +#include +#include +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_gpencil_types.h" +#include "DNA_camera_types.h" +#include "DNA_movieclip_types.h" +#include "DNA_object_types.h" /* SELECT */ +#include "DNA_scene_types.h" + +#include "BLI_utildefines.h" +#include "BLI_math.h" +#include "BLI_math_base.h" +#include "BLI_listbase.h" +#include "BLI_ghash.h" +#include "BLI_path_util.h" + +#include "BKE_global.h" +#include "BKE_tracking.h" +#include "BKE_movieclip.h" +#include "BKE_object.h" +#include "BKE_scene.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#ifdef WITH_LIBMV +#include "libmv-capi.h" +#endif + +typedef struct MovieDistortion { + struct libmv_CameraIntrinsics *intrinsics; +} MovieDistortion; + +/*********************** common functions *************************/ + +void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event) +{ + int a; + float pat_min[2]; + float pat_max[2]; + float max_pyramid_level_factor = 1.0; + if (track->tracker == TRACKER_KLT) { + max_pyramid_level_factor = 1 << (track->pyramid_levels - 1); + } + + /* sort */ + for(a= 0; a<2; a++) { + if(track->pat_min[a]>track->pat_max[a]) + SWAP(float, track->pat_min[a], track->pat_max[a]); + + if(track->search_min[a]>track->search_max[a]) + SWAP(float, track->search_min[a], track->search_max[a]); + } + + /* compute the effective pattern size, which differs from the fine resolution + * pattern size for the pyramid KLT tracker */ + for(a= 0; a<2; a++) { + pat_min[a] = max_pyramid_level_factor * track->pat_min[a]; + pat_max[a] = max_pyramid_level_factor * track->pat_max[a]; + } + + if(event==CLAMP_PAT_DIM) { + for(a= 0; a<2; a++) { + /* search shouldn't be resized smaller than pattern */ + track->search_min[a]= MIN2(pat_min[a], track->search_min[a]); + track->search_max[a]= MAX2(pat_max[a], track->search_max[a]); + } + } + else if(event==CLAMP_PAT_POS) { + float dim[2]; + sub_v2_v2v2(dim, track->pat_max, pat_min); + + for(a= 0; a<2; a++) { + /* pattern shouldn't be moved outside of search */ + if(pat_min[a] < track->search_min[a]) { + track->pat_min[a]= track->search_min[a] - (pat_min[a] - track->pat_min[a]); + track->pat_max[a]= (pat_min[a] - track->pat_min[a])+dim[a]; + } + if(track->pat_max[a] > track->search_max[a]) { + track->pat_max[a]= track->search_max[a] - (pat_max[a] - track->pat_max[a]); + track->pat_min[a]= track->pat_max[a]-dim[a] - (pat_min[a] - track->pat_min[a]); + } + } + } + else if(event==CLAMP_SEARCH_DIM) { + float max_pyramid_level_factor = 1.0; + if (track->tracker == TRACKER_KLT) { + max_pyramid_level_factor = 1 << (track->pyramid_levels - 1); + } + for(a= 0; a<2; a++) { + /* search shouldn't be resized smaller than pattern */ + track->search_min[a]= MIN2(pat_min[a], track->search_min[a]); + track->search_max[a]= MAX2(pat_max[a], track->search_max[a]); + } + } + else if(event==CLAMP_SEARCH_POS) { + float dim[2]; + sub_v2_v2v2(dim, track->search_max, track->search_min); + + for(a= 0; a<2; a++) { + /* search shouldn't be moved inside pattern */ + if(track->search_min[a] > pat_min[a]) { + track->search_min[a]= pat_min[a]; + track->search_max[a]= track->search_min[a]+dim[a]; + } + if(track->search_max[a] < pat_max[a]) { + track->search_max[a]= pat_max[a]; + track->search_min[a]= track->search_max[a]-dim[a]; + } + } + } + + else if(event==CLAMP_PYRAMID_LEVELS || (event==CLAMP_SEARCH_DIM && track->tracker == TRACKER_KLT)) { + float dim[2]; + sub_v2_v2v2(dim, track->pat_max, track->pat_min); + { + float search_ratio = 2.3f * max_pyramid_level_factor; + + /* resize the search area to something sensible based + * on the number of pyramid levels */ + for(a= 0; a<2; a++) { + track->search_min[a]= search_ratio * track->pat_min[a]; + track->search_max[a]= search_ratio * track->pat_max[a]; + } + } + } + + /* marker's center should be in center of pattern */ + if(event==CLAMP_PAT_DIM || event==CLAMP_PAT_POS) { + float dim[2]; + sub_v2_v2v2(dim, track->pat_max, track->pat_min); + + for(a= 0; a<2; a++) { + track->pat_min[a]= -dim[a]/2.0f; + track->pat_max[a]= dim[a]/2.0f; + } + } +} + +void BKE_tracking_track_flag(MovieTrackingTrack *track, int area, int flag, int clear) +{ + if(area==TRACK_AREA_NONE) + return; + + if(clear) { + if(area&TRACK_AREA_POINT) track->flag&= ~flag; + if(area&TRACK_AREA_PAT) track->pat_flag&= ~flag; + if(area&TRACK_AREA_SEARCH) track->search_flag&= ~flag; + } else { + if(area&TRACK_AREA_POINT) track->flag|= flag; + if(area&TRACK_AREA_PAT) track->pat_flag|= flag; + if(area&TRACK_AREA_SEARCH) track->search_flag|= flag; + } +} + +MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, float x, float y, + int framenr, int width, int height) +{ + MovieTrackingTrack *track; + MovieTrackingMarker marker; + + /* pick reasonable defaults */ + float pat[2]= {5.5f, 5.5f}, search[2]= {25.5f, 25.5f}; /* TODO: move to default setting? */ + + pat[0] /= (float)width; + pat[1] /= (float)height; + + search[0] /= (float)width; + search[1] /= (float)height; + + track= MEM_callocN(sizeof(MovieTrackingTrack), "add_marker_exec track"); + strcpy(track->name, "Track"); + + /* default to KLT tracker */ + track->tracker = TRACKER_KLT; + track->pyramid_levels = 2; + + /* set SAD defaults even though it's not selected by default */ + track->minimum_correlation= 0.75f; + + memset(&marker, 0, sizeof(marker)); + marker.pos[0]= x; + marker.pos[1]= y; + marker.framenr= framenr; + + copy_v2_v2(track->pat_max, pat); + negate_v2_v2(track->pat_min, pat); + + copy_v2_v2(track->search_max, search); + negate_v2_v2(track->search_min, search); + + BKE_tracking_insert_marker(track, &marker); + + BLI_addtail(&tracking->tracks, track); + BKE_track_unique_name(tracking, track); + + return track; +} + +void BKE_tracking_insert_marker(MovieTrackingTrack *track, MovieTrackingMarker *marker) +{ + MovieTrackingMarker *old_marker= BKE_tracking_get_marker(track, marker->framenr); + + if(old_marker && old_marker->framenr==marker->framenr) { + *old_marker= *marker; + } else { + int a= track->markersnr; + + while(a--) { + if(track->markers[a].framenrframenr) + break; + } + + track->markersnr++; + + if(track->markers) track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + else track->markers= MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers"); + + memmove(track->markers+a+2, track->markers+a+1, (track->markersnr-a-2)*sizeof(MovieTrackingMarker)); + track->markers[a+1]= *marker; + + track->last_marker= a+1; + } +} + +void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr) +{ + int a= 0; + + while(amarkersnr) { + if(track->markers[a].framenr==framenr) { + if(track->markersnr>1) { + memmove(track->markers+a, track->markers+a+1, (track->markersnr-a-1)*sizeof(MovieTrackingMarker)); + track->markersnr--; + track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + } else { + MEM_freeN(track->markers); + track->markers= NULL; + track->markersnr= 0; + } + + break; + } + + a++; + } +} + +MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int framenr) +{ + int a= track->markersnr-1; + + if(!track->markersnr) + return NULL; + + /* approximate pre-first framenr marker with first marker */ + if(framenrmarkers[0].framenr) + return &track->markers[0]; + + if(track->last_markermarkersnr) + a= track->last_marker; + + if(track->markers[a].framenr<=framenr) { + while(amarkersnr && track->markers[a].framenr<=framenr) { + if(track->markers[a].framenr==framenr) { + track->last_marker= a; + return &track->markers[a]; + } + a++; + } + + /* if there's no marker for exact position, use nearest marker from left side */ + return &track->markers[a-1]; + } else { + while(a>=0 && track->markers[a].framenr>=framenr) { + if(track->markers[a].framenr==framenr) { + track->last_marker= a; + return &track->markers[a]; + } + + a--; + } + + /* if there's no marker for exact position, use nearest marker from left side */ + return &track->markers[a]; + } + + return NULL; +} + +MovieTrackingMarker *BKE_tracking_ensure_marker(MovieTrackingTrack *track, int framenr) +{ + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + + if(marker && marker->framenr!=framenr) { + MovieTrackingMarker marker_new; + + marker_new= *marker; + marker_new.framenr= framenr; + + BKE_tracking_insert_marker(track, &marker_new); + marker= BKE_tracking_get_marker(track, framenr); + } + + return marker; +} + +MovieTrackingMarker *BKE_tracking_exact_marker(MovieTrackingTrack *track, int framenr) +{ + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + + if(marker && marker->framenr!=framenr) + return NULL; + + return marker; +} + +int BKE_tracking_has_marker(MovieTrackingTrack *track, int framenr) +{ + return BKE_tracking_exact_marker(track, framenr) != 0; +} + +void BKE_tracking_free_track(MovieTrackingTrack *track) +{ + if(track->markers) MEM_freeN(track->markers); +} + +MovieTrackingTrack *BKE_tracking_copy_track(MovieTrackingTrack *track) +{ + MovieTrackingTrack *new_track= MEM_dupallocN(track); + + new_track->next= new_track->prev= NULL; + + if(new_track->markers) + new_track->markers= MEM_dupallocN(new_track->markers); + + return new_track; +} + +static void put_disabled_marker(MovieTrackingTrack *track, MovieTrackingMarker *ref_marker, int before, int overwrite) +{ + MovieTrackingMarker marker_new; + + marker_new= *ref_marker; + marker_new.flag&= ~MARKER_TRACKED; + marker_new.flag|= MARKER_DISABLED; + + if(before) marker_new.framenr--; + else marker_new.framenr++; + + if(!BKE_tracking_has_marker(track, marker_new.framenr) || overwrite) + BKE_tracking_insert_marker(track, &marker_new); +} + +void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int action) +{ + int a; + + if(action==TRACK_CLEAR_REMAINED) { + a= 1; + while(amarkersnr) { + if(track->markers[a].framenr>ref_frame) { + track->markersnr= a; + track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + + break; + } + + a++; + } + + if(track->markersnr) + put_disabled_marker(track, &track->markers[track->markersnr-1], 0, 1); + } else if(action==TRACK_CLEAR_UPTO) { + a= track->markersnr-1; + while(a>=0) { + if(track->markers[a].framenr<=ref_frame) { + memmove(track->markers, track->markers+a, (track->markersnr-a)*sizeof(MovieTrackingMarker)); + + track->markersnr= track->markersnr-a; + track->markers= MEM_reallocN(track->markers, sizeof(MovieTrackingMarker)*track->markersnr); + + break; + } + + a--; + } + + if(track->markersnr) + put_disabled_marker(track, &track->markers[0], 1, 1); + } else if(action==TRACK_CLEAR_ALL) { + MovieTrackingMarker *marker, marker_new; + + marker= BKE_tracking_get_marker(track, ref_frame); + marker_new= *marker; + + MEM_freeN(track->markers); + track->markers= NULL; + track->markersnr= 0; + + BKE_tracking_insert_marker(track, &marker_new); + + put_disabled_marker(track, &marker_new, 1, 1); + put_disabled_marker(track, &marker_new, 0, 1); + } +} + +int BKE_tracking_test_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack *src_track) +{ + int i, a= 0, b= 0, tot= dst_track->markersnr+src_track->markersnr; + int count= 0; + + for(i= 0; i=src_track->markersnr) { + b++; + count++; + } + else if(b>=dst_track->markersnr) { + a++; + count++; + } + else if(src_track->markers[a].framenrmarkers[b].framenr) { + a++; + count++; + } else if(src_track->markers[a].framenr>dst_track->markers[b].framenr) { + b++; + count++; + } else { + if((src_track->markers[a].flag&MARKER_DISABLED)==0 && (dst_track->markers[b].flag&MARKER_DISABLED)==0) + return 0; + + a++; + b++; + count++; + } + } + + return count; +} + +void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack *src_track) +{ + int i, a= 0, b= 0, tot; + MovieTrackingMarker *markers; + + tot= BKE_tracking_test_join_tracks(dst_track, src_track); + + markers= MEM_callocN(tot*sizeof(MovieTrackingMarker), "tracking joined tracks"); + + for(i= 0; i=dst_track->markersnr) { + markers[i]= src_track->markers[a++]; + } + else if(a>=src_track->markersnr) { + markers[i]= dst_track->markers[b++]; + } + else if(src_track->markers[a].framenrmarkers[b].framenr) { + markers[i]= src_track->markers[a++]; + } else if(src_track->markers[a].framenr>dst_track->markers[b].framenr) { + markers[i]= dst_track->markers[b++]; + } else { + if((src_track->markers[a].flag&MARKER_DISABLED)) markers[i]= dst_track->markers[b]; + else markers[i]= src_track->markers[a++]; + + a++; + b++; + } + } + + MEM_freeN(dst_track->markers); + + dst_track->markers= markers; + dst_track->markersnr= tot; +} + +void BKE_tracking_free(MovieTracking *tracking) +{ + MovieTrackingTrack *track; + + for(track= tracking->tracks.first; track; track= track->next) { + BKE_tracking_free_track(track); + } + + BLI_freelistN(&tracking->tracks); + + if(tracking->reconstruction.cameras) + MEM_freeN(tracking->reconstruction.cameras); + + if(tracking->stabilization.scaleibuf) + IMB_freeImBuf(tracking->stabilization.scaleibuf); + + if(tracking->camera.intrinsics) + BKE_tracking_distortion_destroy(tracking->camera.intrinsics); +} + +/*********************** tracking *************************/ + +typedef struct TrackContext { + MovieTrackingTrack *track; + +#ifdef WITH_LIBMV + float keyframed_pos[2]; + + /* ** KLT tracker ** */ + struct libmv_RegionTracker *region_tracker; + float *patch; /* keyframed patch */ + + /* ** SAD tracker ** */ + int patsize; /* size of pattern (currently only 16x16 due to libmv side) */ + unsigned char *pattern; /* keyframed pattern */ + unsigned char *warped; /* warped version of reference */ +#endif +} TrackContext; + +typedef struct MovieTrackingContext { + MovieClipUser user; + MovieClip *clip; + + int first_time, frames; + + TrackContext *track_context; + int num_tracks; + + GHash *hash; + MovieTrackingSettings settings; + + short backwards, disable_failed; + int sync_frame; +} MovieTrackingContext; + +MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *user, short backwards, short disable_failed) +{ + MovieTrackingContext *context= MEM_callocN(sizeof(MovieTrackingContext), "trackingContext"); + MovieTracking *tracking= &clip->tracking; + MovieTrackingSettings *settings= &tracking->settings; + MovieTrackingTrack *track; + TrackContext *track_context; + + context->settings= *settings; + context->backwards= backwards; + context->disable_failed= disable_failed; + context->hash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "tracking trackHash"); + context->sync_frame= user->framenr; + context->first_time= 1; + + /* count */ + track= tracking->tracks.first; + while(track) { + if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)==0) { + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr); + + if((marker->flag&MARKER_DISABLED)==0) + context->num_tracks++; + } + + track= track->next; + } + + if(context->num_tracks) { + int width, height; + + BKE_movieclip_get_size(clip, user, &width, &height); + + /* create tracking data */ + context->track_context= MEM_callocN(sizeof(TrackContext)*context->num_tracks, "tracking track_context"); + + track_context= context->track_context; + track= tracking->tracks.first; + while(track) { + if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)==0) { + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr); + + if((marker->flag&MARKER_DISABLED)==0) { + MovieTrackingTrack *new_track= BKE_tracking_copy_track(track); + + track_context->track= new_track; +#ifdef WITH_LIBMV + { + if(track_context->track->tracker==TRACKER_KLT) { + float search_size_x= (track->search_max[0]-track->search_min[0])*width; + float search_size_y= (track->search_max[1]-track->search_min[1])*height; + float pattern_size_x= (track->pat_max[0]-track->pat_min[0])*width; + float pattern_size_y= (track->pat_max[1]-track->pat_min[1])*height; + + /* compute the maximum pyramid size */ + double search_to_pattern_ratio= MIN2(search_size_x, search_size_y) + / MAX2(pattern_size_x, pattern_size_y); + double log2_search_to_pattern_ratio = log(floor(search_to_pattern_ratio)) / M_LN2; + int max_pyramid_levels= floor(log2_search_to_pattern_ratio + 1); + + /* try to accomodate the user's choice of pyramid level in a way + * that doesn't cause the coarsest pyramid pattern to be larger + * than the search size */ + int level= MIN2(track_context->track->pyramid_levels, max_pyramid_levels); + track_context->region_tracker= libmv_regionTrackerNew(100, level); + } + else if(track_context->track->tracker==TRACKER_SAD) { + /* nothing to initialize */ + } + } +#endif + + BLI_ghash_insert(context->hash, new_track, track); + + track_context++; + } + } + + track= track->next; + } + } + + context->clip= clip; + context->user= *user; + + return context; +} + +void BKE_tracking_context_free(MovieTrackingContext *context) +{ + int a; + TrackContext *track_context; + + for(a= 0, track_context= context->track_context; anum_tracks; a++, track_context++) { + BKE_tracking_free_track(context->track_context[a].track); + +#if WITH_LIBMV + if(track_context->region_tracker) + libmv_regionTrackerDestroy(track_context->region_tracker); + + if(track_context->patch) + MEM_freeN(track_context->patch); + + if(track_context->pattern) + MEM_freeN(track_context->pattern); + + if(track_context->warped) + MEM_freeN(track_context->warped); +#endif + + MEM_freeN(track_context->track); + } + + if(context->track_context) + MEM_freeN(context->track_context); + + BLI_ghash_free(context->hash, NULL, NULL); + + MEM_freeN(context); +} + +static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track) +{ + int x, y; + + if((track->flag&(TRACK_DISABLE_RED|TRACK_DISABLE_GREEN|TRACK_DISABLE_BLUE))==0) + return; + + for(y= 0; yy; y++) { + for (x= 0; xx; x++) { + int pixel= ibuf->x*y + x; + + if(ibuf->rect_float) { + float *rrgbf= ibuf->rect_float + pixel*4; + + if(track->flag&TRACK_DISABLE_RED) rrgbf[0]= 0; + if(track->flag&TRACK_DISABLE_GREEN) rrgbf[1]= 0; + if(track->flag&TRACK_DISABLE_BLUE) rrgbf[2]= 0; + } else { + char *rrgb= (char*)ibuf->rect + pixel*4; + + if(track->flag&TRACK_DISABLE_RED) rrgb[0]= 0; + if(track->flag&TRACK_DISABLE_GREEN) rrgb[1]= 0; + if(track->flag&TRACK_DISABLE_BLUE) rrgb[2]= 0; + } + } + } +} + +static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, + float min[2], float max[2], int margin, int anchored, float pos[2], int origin[2]) +{ + ImBuf *tmpibuf; + int x, y; + int x1, y1, x2, y2, w, h; + float mpos[2]; + + copy_v2_v2(mpos, marker->pos); + if(anchored) + add_v2_v2(mpos, track->offset); + + x= mpos[0]*ibuf->x; + y= mpos[1]*ibuf->y; + x1= x-(int)(-min[0]*ibuf->x); + y1= y-(int)(-min[1]*ibuf->y); + x2= x+(int)(max[0]*ibuf->x); + y2= y+(int)(max[1]*ibuf->y); + + /* dimensions should be odd */ + w= (x2-x1)|1; + h= (y2-y1)|1; + + tmpibuf= IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect); + IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1-margin, y1-margin, w+margin*2, h+margin*2); + + if(pos != NULL) { + pos[0]= mpos[0]*ibuf->x-x1+margin; + pos[1]= mpos[1]*ibuf->y-y1+margin; + } + + if(origin != NULL) { + origin[0]= x1-margin; + origin[1]= y1-margin; + } + + disable_imbuf_channels(tmpibuf, track); + + return tmpibuf; +} + +ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, + int margin, int anchored, float pos[2], int origin[2]) +{ + return get_area_imbuf(ibuf, track, marker, track->pat_min, track->pat_max, margin, anchored, pos, origin); +} + +ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, + int margin, int anchored, float pos[2], int origin[2]) +{ + return get_area_imbuf(ibuf, track, marker, track->search_min, track->search_max, margin, anchored, pos, origin); +} + +#ifdef WITH_LIBMV +static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, + int *width_r, int *height_r, float pos[2], int origin[2]) +{ + ImBuf *tmpibuf; + float *pixels, *fp; + int x, y, width, height; + + width= (track->search_max[0]-track->search_min[0])*ibuf->x; + height= (track->search_max[1]-track->search_min[1])*ibuf->y; + + tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); + disable_imbuf_channels(tmpibuf, track); + + *width_r= width; + *height_r= height; + + fp= pixels= MEM_callocN(width*height*sizeof(float), "tracking floatBuf"); + for(y= 0; y<(int)height; y++) { + for (x= 0; x<(int)width; x++) { + int pixel= tmpibuf->x*y + x; + + if(tmpibuf->rect_float) { + float *rrgbf= tmpibuf->rect_float + pixel*4; + + *fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2]; + } else { + unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4; + + *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f; + } + + fp++; + } + } + + IMB_freeImBuf(tmpibuf); + + return pixels; +} + +static unsigned char *get_ucharbuf(ImBuf *ibuf) +{ + int x, y; + unsigned char *pixels, *cp; + + cp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf"); + for(y= 0; yy; y++) { + for (x= 0; xx; x++) { + int pixel= ibuf->x*y + x; + + if(ibuf->rect_float) { + float *rrgbf= ibuf->rect_float + pixel*4; + + *cp= FTOCHAR(0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2]); + } else { + unsigned char *rrgb= (unsigned char*)ibuf->rect + pixel*4; + + *cp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2]; + } + + cp++; + } + } + + return pixels; +} + +static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, + int *width_r, int *height_r, float pos[2], int origin[2]) +{ + ImBuf *tmpibuf; + unsigned char *pixels; + + tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, origin); + disable_imbuf_channels(tmpibuf, track); + + *width_r= tmpibuf->x; + *height_r= tmpibuf->y; + + pixels= get_ucharbuf(tmpibuf); + + IMB_freeImBuf(tmpibuf); + + return pixels; +} + +static ImBuf *get_frame_ibuf(MovieTrackingContext *context, int framenr) +{ + ImBuf *ibuf; + int framenr_old= context->user.framenr; + + context->user.framenr= framenr; + + ibuf= BKE_movieclip_get_ibuf_flag(context->clip, &context->user, 0); + + context->user.framenr= framenr_old; + + return ibuf; +} + +static ImBuf *get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track, + MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed) +{ + int framenr= marker->framenr; + int a= marker-track->markers; + + *marker_keyed= marker; + + while(a>=0 && amarkersnr) { + int next= (context->backwards) ? a+1 : a-1; + int is_keyframed= 0; + MovieTrackingMarker *marker= &track->markers[a]; + MovieTrackingMarker *next_marker= NULL; + + if(next>=0 && nextmarkersnr) + next_marker= &track->markers[next]; + + /* if next mrker is disabled, stop searching keyframe and use current frame as keyframe */ + if(next_marker && next_marker->flag&MARKER_DISABLED) + is_keyframed= 1; + + is_keyframed|= (marker->flag&MARKER_TRACKED)==0; + + if(is_keyframed) { + framenr= marker->framenr; + *marker_keyed= marker; + break; + } + + a= next; + } + + return get_frame_ibuf(context, framenr); +} + +static ImBuf *get_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track, MovieTrackingMarker *marker, + int curfra, MovieTrackingMarker **marker_keyed) +{ + ImBuf *ibuf= NULL; + + if(context->settings.adjframes == 0) { + ibuf= get_keyframed_ibuf(context, track, marker, marker_keyed); + } else { + ibuf= get_frame_ibuf(context, curfra); + + /* use current marker as keyframed position */ + *marker_keyed= marker; + } + + return ibuf; +} + +static void get_warped(TrackContext *track_context, int x, int y, int width, unsigned char *image) +{ + int i, j; + + for(i=0; ipatsize; i++) { + for(j=0; jpatsize; j++) { + track_context->warped[i*track_context->patsize+j]= + image[(y+i-track_context->patsize/2)*width+x+j-track_context->patsize/2]; + } + } +} + +#endif + +void BKE_tracking_sync(MovieTrackingContext *context) +{ + TrackContext *track_context; + MovieTracking *tracking= &context->clip->tracking; + MovieTrackingTrack *track; + ListBase tracks= {NULL, NULL}, new_tracks= {NULL, NULL}; + ListBase *old_tracks= &context->clip->tracking.tracks; + int a, newframe; + + /* duplicate currently tracking tracks to temporary list. + this is needed to keep names in unique state and it's faster to change names + of currently tracking tracks (if needed) */ + for(a= 0, track_context= context->track_context; anum_tracks; a++, track_context++) { + int replace_sel= 0; + MovieTrackingTrack *new_track, *old; + + track= track_context->track; + + /* find original of tracking track in list of previously displayed tracks */ + old= BLI_ghash_lookup(context->hash, track); + if(old) { + MovieTrackingTrack *cur= old_tracks->first; + + while(cur) { + if(cur==old) + break; + + cur= cur->next; + } + + /* original track was found, re-use flags and remove this track */ + if(cur) { + if(cur==tracking->act_track) + replace_sel= 1; + + track->flag= cur->flag; + track->pat_flag= cur->pat_flag; + track->search_flag= cur->search_flag; + + BKE_tracking_free_track(cur); + BLI_freelinkN(old_tracks, cur); + } + } + + new_track= BKE_tracking_copy_track(track); + + BLI_ghash_remove(context->hash, track, NULL, NULL); /* XXX: are we actually need this */ + BLI_ghash_insert(context->hash, track, new_track); + + if(replace_sel) /* update current selection in clip */ + tracking->act_track= new_track; + + BLI_addtail(&tracks, new_track); + } + + /* move all tracks, which aren't tracking */ + track= old_tracks->first; + while(track) { + MovieTrackingTrack *next= track->next; + + track->next= track->prev= NULL; + BLI_addtail(&new_tracks, track); + + track= next; + } + + /* now move all tracks which are currently tracking and keep their names unique */ + track= tracks.first; + while(track) { + MovieTrackingTrack *next= track->next; + + BLI_remlink(&tracks, track); + + track->next= track->prev= NULL; + BLI_addtail(&new_tracks, track); + + BLI_uniquename(&new_tracks, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name)); + + track= next; + } + + context->clip->tracking.tracks= new_tracks; + + if(context->backwards) newframe= context->user.framenr+1; + else newframe= context->user.framenr-1; + + context->sync_frame= newframe; +} + +void BKE_tracking_sync_user(MovieClipUser *user, MovieTrackingContext *context) +{ + user->framenr= context->sync_frame; +} + +int BKE_tracking_next(MovieTrackingContext *context) +{ + ImBuf *ibuf_new; + int curfra= context->user.framenr; + int a, ok= 0; + + /* nothing to track, avoid unneeded frames reading to save time and memory */ + if(!context->num_tracks) + return 0; + + if(context->backwards) context->user.framenr--; + else context->user.framenr++; + + ibuf_new= BKE_movieclip_get_ibuf_flag(context->clip, &context->user, 0); + if(!ibuf_new) + return 0; + + #pragma omp parallel for private(a) shared(ibuf_new, ok) if(context->num_tracks>1) + for(a= 0; anum_tracks; a++) { + TrackContext *track_context= &context->track_context[a]; + MovieTrackingTrack *track= track_context->track; + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, curfra); + + if(marker && (marker->flag&MARKER_DISABLED)==0 && marker->framenr==curfra) { +#ifdef WITH_LIBMV + int width, height, origin[2], tracked= 0, need_readjust= 0; + float pos[2], margin[2]; + double x1, y1, x2, y2; + ImBuf *ibuf= NULL; + MovieTrackingMarker marker_new, *marker_keyed; + int onbound= 0, coords_correct= 0; + int nextfra; + + if(!context->settings.adjframes) need_readjust= context->first_time; + else need_readjust= context->frames%context->settings.adjframes == 0; + + if(context->backwards) nextfra= curfra-1; + else nextfra= curfra+1; + + /* margin from frame boundaries */ + sub_v2_v2v2(margin, track->pat_max, track->pat_min); + + margin[0]= MAX2(margin[0], (float)context->settings.margin / ibuf_new->x); + margin[1]= MAX2(margin[1], (float)context->settings.margin / ibuf_new->y); + + /* do not track markers which are too close to boundary */ + if(marker->pos[0]pos[0]>1.0f-margin[0] || + marker->pos[1]pos[1]>1.0f-margin[1]) { + onbound= 1; + } + else if(track_context->track->tracker==TRACKER_KLT) { + int wndx, wndy; + float *patch_new; + + if(need_readjust) { + /* calculate patch for keyframed position */ + ibuf= get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); + + if(track_context->patch) + MEM_freeN(track_context->patch); + + track_context->patch= get_search_floatbuf(ibuf, track, marker_keyed, &width, &height, track_context->keyframed_pos, origin); + + IMB_freeImBuf(ibuf); + } + + patch_new= get_search_floatbuf(ibuf_new, track, marker, &width, &height, pos, origin); + + x1= track_context->keyframed_pos[0]; + y1= track_context->keyframed_pos[1]; + + x2= pos[0]; + y2= pos[1]; + + wndx= (int)((track->pat_max[0]-track->pat_min[0])*ibuf_new->x)/2; + wndy= (int)((track->pat_max[1]-track->pat_min[1])*ibuf_new->y)/2; + + tracked= libmv_regionTrackerTrack(track_context->region_tracker, track_context->patch, patch_new, + width, height, MAX2(wndx, wndy), x1, y1, &x2, &y2); + + MEM_freeN(patch_new); + } + else if(track_context->track->tracker==TRACKER_SAD) { + unsigned char *image_new; + float correlation; + float warp[3][2]={{0}}; + + if(need_readjust) { + unsigned char *image; + + /* calculate pattern for keyframed position */ + ibuf= get_adjust_ibuf(context, track, marker, curfra, &marker_keyed); + + image= get_search_bytebuf(ibuf, track, marker_keyed, &width, &height, pos, origin); + + memset(warp, 0, sizeof(warp)); + warp[0][0]= 1; + warp[1][1]= 1; + warp[2][0]= pos[0]; + warp[2][1]= pos[1]; + + /* pattern size is hardcoded to 16x16px in libmv */ + track_context->patsize= 16; + + if(!track_context->pattern) + track_context->pattern= MEM_callocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackking pattern"); + + libmv_SADSamplePattern(image, width, warp, track_context->pattern); + + MEM_freeN(image); + IMB_freeImBuf(ibuf); + } + + image_new= get_search_bytebuf(ibuf_new, track, marker, &width, &height, pos, origin); + + if(track_context->warped==NULL) { + unsigned char *image_old; + + ibuf= get_frame_ibuf(context, curfra); + + if(track_context->warped==NULL) + track_context->warped= MEM_callocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackking warped"); + + image_old= get_search_bytebuf(ibuf, track, marker, &width, &height, pos, origin); + get_warped(track_context, pos[0], pos[1], width, image_old); + IMB_freeImBuf(ibuf); + MEM_freeN(image_old); + } + + memset(warp, 0, sizeof(warp)); + warp[0][0]= 1; + warp[1][1]= 1; + warp[2][0]= pos[0]; + warp[2][1]= pos[1]; + + correlation= libmv_SADTrackerTrack(track_context->pattern, track_context->warped, image_new, width, width, height, warp); + + x2= warp[2][0]; + y2= warp[2][1]; + + tracked= track_context->track->minimum_correlation < correlation; + + if(tracked) + get_warped(track_context, x2, y2, width, image_new); + + MEM_freeN(image_new); + } + + coords_correct= !isnan(x2) && !isnan(y2) && finite(x2) && finite(y2); + if(coords_correct && (tracked || !context->disable_failed)) { + if(context->first_time) { + #pragma omp critical + { + /* check if there's no keyframe/tracked markers before tracking marker. + if so -- create disabled marker before currently tracking "segment" */ + put_disabled_marker(track, marker, 1, 0); + } + } + + memset(&marker_new, 0, sizeof(marker_new)); + + if(!onbound) { + marker_new.pos[0]= (origin[0]+x2)/ibuf_new->x; + marker_new.pos[1]= (origin[1]+y2)/ibuf_new->y; + } else { + copy_v2_v2(marker_new.pos, marker->pos); + } + + marker_new.flag|= MARKER_TRACKED; + marker_new.framenr= nextfra; + + #pragma omp critical + { + BKE_tracking_insert_marker(track, &marker_new); + } + + /* make currently tracked segment be finished with disabled marker */ + #pragma omp critical + { + put_disabled_marker(track, &marker_new, 0, 0); + } + } else { + marker_new= *marker; + + marker_new.framenr= nextfra; + marker_new.flag|= MARKER_DISABLED; + + #pragma omp critical + { + BKE_tracking_insert_marker(track, &marker_new); + } + } + + ok= 1; +#endif + } + } + + IMB_freeImBuf(ibuf_new); + + context->first_time= 0; + context->frames++; + + return ok; +} + +#if WITH_LIBMV +static struct libmv_Tracks *create_libmv_tracks(MovieTracking *tracking, int width, int height) +{ + int tracknr= 0; + MovieTrackingTrack *track; + struct libmv_Tracks *tracks= libmv_tracksNew(); + + track= tracking->tracks.first; + while(track) { + int a= 0; + + for(a= 0; amarkersnr; a++) { + MovieTrackingMarker *marker= &track->markers[a]; + + if((marker->flag&MARKER_DISABLED)==0) + libmv_tracksInsert(tracks, marker->framenr, tracknr, + marker->pos[0]*width, marker->pos[1]*height); + } + + track= track->next; + tracknr++; + } + + return tracks; +} + +static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction) +{ + int tracknr= 0; + int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0; + MovieTrackingTrack *track; + MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; + MovieReconstructedCamera *reconstructed; + float origin[3]= {0.0f, 0.0f, 0.0f}; + int ok= 1; + + track= tracking->tracks.first; + while(track) { + double pos[3]; + + if(libmv_reporojectionPointForTrack(libmv_reconstruction, tracknr, pos)) { + track->bundle_pos[0]= pos[0]; + track->bundle_pos[1]= pos[1]; + track->bundle_pos[2]= pos[2]; + + track->flag|= TRACK_HAS_BUNDLE; + track->error= libmv_reporojectionErrorForTrack(libmv_reconstruction, tracknr); + } else { + track->flag&= ~TRACK_HAS_BUNDLE; + ok= 0; + + printf("No bundle for track #%d '%s'\n", tracknr, track->name); + } + + if(track->markersnr) { + if(track->markers[0].framenrmarkers[0].framenr; + if(track->markers[track->markersnr-1].framenr>efra) efra= track->markers[track->markersnr-1].framenr; + } + + track= track->next; + tracknr++; + } + + if(reconstruction->cameras) + MEM_freeN(reconstruction->cameras); + + reconstruction->camnr= 0; + reconstruction->cameras= NULL; + reconstructed= MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera), "temp reconstructed camera"); + + for(a= sfra; a<=efra; a++) { + double matd[4][4]; + + if(libmv_reporojectionCameraForImage(libmv_reconstruction, a, matd)) { + int i, j; + float mat[4][4]; + float error= libmv_reporojectionErrorForImage(libmv_reconstruction, a); + + for(i=0; i<4; i++) + for(j= 0; j<4; j++) + mat[i][j]= matd[i][j]; + + if(!origin_set) { + copy_v3_v3(origin, mat[3]); + origin_set= 1; + } + + if(origin_set) + sub_v3_v3(mat[3], origin); + + copy_m4_m4(reconstructed[reconstruction->camnr].mat, mat); + reconstructed[reconstruction->camnr].framenr= a; + reconstructed[reconstruction->camnr].error= error; + reconstruction->camnr++; + } else { + ok= 0; + printf("No camera for frame %d\n", a); + } + } + + if(reconstruction->camnr) { + reconstruction->cameras= MEM_callocN(reconstruction->camnr*sizeof(MovieReconstructedCamera), "reconstructed camera"); + memcpy(reconstruction->cameras, reconstructed, reconstruction->camnr*sizeof(MovieReconstructedCamera)); + } + + if(origin_set) { + track= tracking->tracks.first; + while(track) { + if(track->flag&TRACK_HAS_BUNDLE) + sub_v3_v3(track->bundle_pos, origin); + + track= track->next; + } + } + + MEM_freeN(reconstructed); + + return ok; +} + +#endif + +float BKE_tracking_solve_reconstruction(MovieTracking *tracking, int width, int height) +{ +#if WITH_LIBMV + { + MovieTrackingCamera *camera= &tracking->camera; + float aspy= 1.0f/tracking->camera.pixel_aspect; + struct libmv_Tracks *tracks= create_libmv_tracks(tracking, width, height*aspy); + struct libmv_Reconstruction *reconstruction = libmv_solveReconstruction(tracks, + tracking->settings.keyframe1, tracking->settings.keyframe2, + camera->focal, + camera->principal[0], camera->principal[1]*aspy, + camera->k1, camera->k2, camera->k3); + float error= libmv_reprojectionError(reconstruction); + + tracking->reconstruction.error= error; + + if(!retrieve_libmv_reconstruct(tracking, reconstruction)) + error= -1.0f; + + libmv_destroyReconstruction(reconstruction); + libmv_tracksDestroy(tracks); + + tracking->reconstruction.flag|= TRACKING_RECONSTRUCTED; + + return error; + } +#endif +} + +void BKE_track_unique_name(MovieTracking *tracking, MovieTrackingTrack *track) +{ + BLI_uniquename(&tracking->tracks, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name)); +} + +MovieTrackingTrack *BKE_tracking_named_track(MovieTracking *tracking, const char *name) +{ + MovieTrackingTrack *track= tracking->tracks.first; + + while(track) { + if(!strcmp(track->name, name)) + return track; + + track= track->next; + } + + return NULL; +} + +static int reconstruction_camera_index(MovieTracking *tracking, int framenr, int nearest) +{ + MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; + MovieReconstructedCamera *cameras= reconstruction->cameras; + int a= 0, d= 1; + + if(!reconstruction->camnr) + return -1; + + if(framenrcameras[reconstruction->camnr-1].framenr) { + if(nearest) return reconstruction->camnr-1; + else return -1; + } + + if(reconstruction->last_cameracamnr) + a= reconstruction->last_camera; + + if(cameras[a].framenr>=framenr) + d= -1; + + while(a>=0 && acamnr) { + int cfra= cameras[a].framenr; + + /* check if needed framenr was "skipped" -- no data for requested frame */ + + if(d>0 && cfra>framenr) { + /* interpolate with previous position */ + if(nearest) return a-1; + else break; + } + + if(d<0 && cfralast_camera= a; + + return a; + } + + a+= d; + } + + return -1; +} + +MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(MovieTracking *tracking, int framenr) +{ + int a= reconstruction_camera_index(tracking, framenr, 0); + + if(a==-1) + return NULL; + + return &tracking->reconstruction.cameras[a]; +} + +void BKE_tracking_get_interpolated_camera(MovieTracking *tracking, int framenr, float mat[4][4]) +{ + MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; + MovieReconstructedCamera *cameras= reconstruction->cameras; + int a= reconstruction_camera_index(tracking, framenr, 1); + + if(a==-1) { + unit_m4(mat); + return; + } + + if(cameras[a].framenr!=framenr && a>0 && acamnr-1) { + float t= ((float)framenr-cameras[a].framenr) / (cameras[a+1].framenr-cameras[a].framenr); + + blend_m4_m4m4(mat, cameras[a].mat, cameras[a+1].mat, t); + } else { + copy_m4_m4(mat, cameras[a].mat); + } +} + +void BKE_get_tracking_mat(Scene *scene, Object *ob, float mat[4][4]) +{ + if(!ob) { + if(scene->camera) ob= scene->camera; + else ob= scene_find_camera(scene); + } + + if(ob) + where_is_object_mat(scene, ob, mat); + else + unit_m4(mat); +} + +void BKE_tracking_camera_shift(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty) +{ + *shiftx= (0.5f*winx-tracking->camera.principal[0]) / winx; + *shifty= (0.5f*winy-tracking->camera.principal[1]) / winx; +} + +void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height) +{ + float focal= tracking->camera.focal; + + camera->sensor_x= tracking->camera.sensor_width; + camera->sensor_fit= CAMERA_SENSOR_FIT_AUTO; + camera->lens= focal*camera->sensor_x/width; + + scene->r.xsch= width*tracking->camera.pixel_aspect; + scene->r.ysch= height; + + scene->r.xasp= 1.0f; + scene->r.yasp= 1.0f; + + BKE_tracking_camera_shift(tracking, width, height, &camera->shiftx, &camera->shifty); +} + +void BKE_tracking_projection_matrix(MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]) +{ + MovieReconstructedCamera *camera; + float lens= tracking->camera.focal*tracking->camera.sensor_width/(float)winx; + float viewfac, pixsize, left, right, bottom, top, clipsta, clipend; + float winmat[4][4]; + float ycor= 1.0f/tracking->camera.pixel_aspect; + float shiftx, shifty, winside= MAX2(winx, winy); + + BKE_tracking_camera_shift(tracking, winx, winy, &shiftx, &shifty); + + clipsta= 0.1f; + clipend= 1000.0f; + + if(winx >= winy) + viewfac= (lens*winx)/tracking->camera.sensor_width; + else + viewfac= (ycor*lens*winy)/tracking->camera.sensor_width; + + pixsize= clipsta/viewfac; + + left= -0.5f*(float)winx + shiftx*winside; + bottom= -0.5f*(ycor)*(float)winy + shifty*winside; + right= 0.5f*(float)winx + shiftx*winside; + top= 0.5f*(ycor)*(float)winy + shifty*winside; + + left *= pixsize; + right *= pixsize; + bottom *= pixsize; + top *= pixsize; + + perspective_m4(winmat, left, right, bottom, top, clipsta, clipend); + + camera= BKE_tracking_get_reconstructed_camera(tracking, framenr); + if(camera) { + float imat[4][4]; + + invert_m4_m4(imat, camera->mat); + mul_m4_m4m4(mat, imat, winmat); + } else copy_m4_m4(mat, winmat); +} + +void BKE_tracking_apply_intrinsics(MovieTracking *tracking, float co[2], float nco[2]) +{ + MovieTrackingCamera *camera= &tracking->camera; + +#ifdef WITH_LIBMV + double x, y; + float aspy= 1.0f/tracking->camera.pixel_aspect; + + /* normalize coords */ + x= (co[0]-camera->principal[0]) / camera->focal; + y= (co[1]-camera->principal[1] * aspy) / camera->focal; + + libmv_applyCameraIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy, + camera->k1, camera->k2, camera->k3, x, y, &x, &y); + + /* result is in image coords already */ + nco[0]= x; + nco[1]= y; +#endif +} + +void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float nco[2]) +{ + MovieTrackingCamera *camera= &tracking->camera; + +#ifdef WITH_LIBMV + double x= co[0], y= co[1]; + float aspy= 1.0f/tracking->camera.pixel_aspect; + + libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy, + camera->k1, camera->k2, camera->k3, x, y, &x, &y); + + nco[0]= x * camera->focal + camera->principal[0]; + nco[1]= y * camera->focal + camera->principal[1] * aspy; +#endif +} + +static int point_in_stroke(bGPDstroke *stroke, float x, float y) +{ + int i, prev; + int count= 0; + bGPDspoint *points= stroke->points; + + prev= stroke->totpoints-1; + + for(i= 0; itotpoints; i++) { + if((points[i].y=y) || (points[prev].y=y)) { + float fac= (y-points[i].y)/(points[prev].y-points[i].y); + + if (points[i].x+fac*(points[prev].x-points[i].x)frames.first; + + while(frame) { + bGPDstroke *stroke= frame->strokes.first; + while(stroke) { + if(point_in_stroke(stroke, x, y)) + return 1; + + stroke= stroke->next; + } + frame= frame->next; + } + + return 0; +} + +static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Features *features, + int framenr, int width, int height, bGPDlayer *layer, int place_outside_layer) +{ +#ifdef WITH_LIBMV + int a; + + a= libmv_countFeatures(features); + while(a--) { + MovieTrackingTrack *track; + double x, y, size, score; + int ok= 1; + float xu, yu; + + libmv_getFeature(features, a, &x, &y, &score, &size); + + xu= x/width; + yu= y/height; + + if(layer) + ok= point_in_layer(layer, xu, yu)!=place_outside_layer; + + if(ok) { + track= BKE_tracking_add_track(tracking, xu, yu, framenr, width, height); + track->flag|= SELECT; + track->pat_flag|= SELECT; + track->search_flag|= SELECT; + } + } +#endif +} + +void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf, + int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer, + int place_outside_layer) +{ +#ifdef WITH_LIBMV + struct libmv_Features *features; + unsigned char *pixels= get_ucharbuf(ibuf); + + features= libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x, margin, min_trackness, min_distance); + + MEM_freeN(pixels); + + retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer, place_outside_layer); + + libmv_destroyFeatures(features); +#endif +} + +MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr) +{ + MovieTrackingTrack *track= tracking->tracks.first; + int cur= 1; + + while(track) { + if(track->flag&TRACK_HAS_BUNDLE) { + if(cur==tracknr) + return track; + + cur++; + } + + track= track->next; + } + + return NULL; +} + +static int stabilization_median_point(MovieTracking *tracking, int framenr, float median[2]) +{ + int ok= 0; + float min[2], max[2]; + MovieTrackingTrack *track; + + INIT_MINMAX2(min, max); + + track= tracking->tracks.first; + while(track) { + if(track->flag&TRACK_USE_2D_STAB) { + MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr); + + DO_MINMAX2(marker->pos, min, max); + + ok= 1; + } + + track= track->next; + } + + median[0]= (max[0]+min[0])/2.0f; + median[1]= (max[1]+min[1])/2.0f; + + return ok; +} + +static void calculate_stabdata(MovieTracking *tracking, int framenr, float width, float height, + float firstmedian[2], float median[2], float loc[2], float *scale, float *angle) +{ + MovieTrackingStabilization *stab= &tracking->stabilization; + + *scale= (stab->scale-1.0f)*stab->scaleinf+1.0f; + *angle= 0.0f; + + loc[0]= (firstmedian[0]-median[0])*width*(*scale); + loc[1]= (firstmedian[1]-median[1])*height*(*scale); + + mul_v2_fl(loc, stab->locinf); + + if(stab->rot_track && stab->rotinf) { + MovieTrackingMarker *marker; + float a[2], b[2]; + float x0= (float)width/2.0f, y0= (float)height/2.0f; + float x= median[0]*width, y= median[1]*height; + + marker= BKE_tracking_get_marker(stab->rot_track, 1); + sub_v2_v2v2(a, marker->pos, firstmedian); + a[0]*= width; + a[1]*= height; + + marker= BKE_tracking_get_marker(stab->rot_track, framenr); + sub_v2_v2v2(b, marker->pos, median); + b[0]*= width; + b[1]*= height; + + *angle= -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); + *angle*= stab->rotinf; + + /* convert to rotation around image center */ + loc[0]-= (x0 + (x-x0)*cos(*angle)-(y-y0)*sin(*angle) - x)*(*scale); + loc[1]-= (y0 + (x-x0)*sin(*angle)+(y-y0)*cos(*angle) - y)*(*scale); + } +} + +static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, int height) +{ + float firstmedian[2]; + MovieTrackingStabilization *stab= &tracking->stabilization; + + if(stab->ok) + return stab->scale; + + if(stabilization_median_point(tracking, 1, firstmedian)) { + int sfra= INT_MAX, efra= INT_MIN, cfra; + float delta[2]= {0.0f, 0.0f}, scalex= 1.0f, scaley= 1.0f; + MovieTrackingTrack *track; + + stab->scale= 1.0f; + + track= tracking->tracks.first; + while(track) { + if(track->flag&TRACK_USE_2D_STAB || track==stab->rot_track) { + if(track->markersnr) { + sfra= MIN2(sfra, track->markers[0].framenr); + efra= MAX2(efra, track->markers[track->markersnr-1].framenr); + } + } + + track= track->next; + } + + for(cfra=sfra; cfra<=efra; cfra++) { + float median[2], near[2]; + float loc[2], scale, angle; + + stabilization_median_point(tracking, cfra, median); + + calculate_stabdata(tracking, cfra, width, height, firstmedian, median, + loc, &scale, &angle); + + if(angle==0.0f) { + loc[0]= fabsf(loc[0]); + loc[1]= fabsf(loc[1]); + + delta[0]= MAX2(delta[0], loc[0]); + delta[1]= MAX2(delta[1], loc[1]); + + near[0]= MIN2(median[0], 1.0f-median[0]); + near[1]= MIN2(median[1], 1.0f-median[1]); + near[0]= MAX2(near[0], 0.05f); + near[1]= MAX2(near[1], 0.05f); + + scalex= 1.0f+delta[0]/(near[0]*width); + scaley= 1.0f+delta[1]/(near[1]*height); + } else { + int i; + float mat[4][4]; + float points[4][2]={{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; + + BKE_tracking_stabdata_to_mat4(width, height, loc, scale, angle, mat); + + for(i= 0; i<4; i++) { + int j; + float a[3]= {0.0f, 0.0f, 0.0f}, b[3]= {0.0f, 0.0f, 0.0f}; + + copy_v3_v3(a, points[i]); + copy_v3_v3(b, points[(i+1)%4]); + + mul_m4_v3(mat, a); + mul_m4_v3(mat, b); + + for(j= 0; j<4; j++) { + float point[3]= {points[j][0], points[j][1], 0.0f}; + float v1[3], v2[3]; + + sub_v3_v3v3(v1, b, a); + sub_v3_v3v3(v2, point, a); + + if(cross_v2v2(v1, v2) >= 0.0f) { + float dist= dist_to_line_v2(point, a, b); + if(i%2==0) { + scalex= MAX2(scalex, (width+2*dist)/width); + } else { + scaley= MAX2(scaley, (height+2*dist)/height); + } + } + } + } + } + } + + stab->scale= MAX2(scalex, scaley); + + if(stab->maxscale>0.0f) + stab->scale= MIN2(stab->scale, stab->maxscale); + } else { + stab->scale= 1.0f; + } + + stab->ok= 1; + + return stab->scale; +} + +static ImBuf* stabilize_alloc_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill) +{ + int flags; + + if(cacheibuf && (cacheibuf->x != srcibuf->x || cacheibuf->y != srcibuf->y)) { + IMB_freeImBuf(cacheibuf); + cacheibuf= NULL; + } + + flags= IB_rect; + + if(srcibuf->rect_float) + flags|= IB_rectfloat; + + if(cacheibuf) { + if(fill) { + float col[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + IMB_rectfill(cacheibuf, col); + } + } + else { + cacheibuf= IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->depth, flags); + cacheibuf->profile= srcibuf->profile; + } + + return cacheibuf; +} + +void BKE_tracking_stabilization_data(MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle) +{ + float firstmedian[2], median[2]; + MovieTrackingStabilization *stab= &tracking->stabilization; + + if((stab->flag&TRACKING_2D_STABILIZATION)==0) { + zero_v2(loc); + *scale= 1.0f; + *angle= 0.0f; + + return; + } + + if(stabilization_median_point(tracking, 1, firstmedian)) { + stabilization_median_point(tracking, framenr, median); + + if((stab->flag&TRACKING_AUTOSCALE)==0) + stab->scale= 1.0f; + + if(!stab->ok) { + if(stab->flag&TRACKING_AUTOSCALE) + stabilization_auto_scale_factor(tracking, width, height); + + calculate_stabdata(tracking, framenr, width, height, firstmedian, median, loc, scale, angle); + + stab->ok= 1; + } else { + calculate_stabdata(tracking, framenr, width, height, firstmedian, median, loc, scale, angle); + } + } else { + zero_v2(loc); + *scale= 1.0f; + *angle= 0.0f; + } +} + +ImBuf *BKE_tracking_stabilize(MovieTracking *tracking, int framenr, ImBuf *ibuf, float loc[2], float *scale, float *angle) +{ + float tloc[2], tscale, tangle; + MovieTrackingStabilization *stab= &tracking->stabilization; + ImBuf *tmpibuf; + float width= ibuf->x, height= ibuf->y; + + if(loc) copy_v2_v2(tloc, loc); + if(scale) tscale= *scale; + + if((stab->flag&TRACKING_2D_STABILIZATION)==0) { + if(loc) zero_v2(loc); + if(scale) *scale= 1.0f; + + return ibuf; + } + + BKE_tracking_stabilization_data(tracking, framenr, width, height, tloc, &tscale, &tangle); + + tmpibuf= stabilize_alloc_ibuf(NULL, ibuf, 1); + + /* scale would be handled by matrix transformation when angle is non-zero */ + if(tscale!=1.0f && tangle==0.0f) { + ImBuf *scaleibuf; + + stabilization_auto_scale_factor(tracking, width, height); + + scaleibuf= stabilize_alloc_ibuf(stab->scaleibuf, ibuf, 0); + stab->scaleibuf= scaleibuf; + + IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); + IMB_scalefastImBuf(scaleibuf, ibuf->x*tscale, ibuf->y*tscale); + + ibuf= scaleibuf; + } + + if(tangle==0.0f) { + /* if angle is zero, then it's much faster to use rect copy + but could be issues with subpixel precisions */ + IMB_rectcpy(tmpibuf, ibuf, tloc[0]-(tscale-1.0f)*width/2.0f, tloc[1]-(tscale-1.0f)*height/2.0f, 0, 0, ibuf->x, ibuf->y); + } else { + float mat[4][4]; + int i, j; + + BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, tloc, tscale, tangle, mat); + invert_m4(mat); + + for(j=0; jy; j++) { + for(i=0; ix;i++) { + float vec[3]= {i, j, 0}; + + mul_v3_m4v3(vec, mat, vec); + + /* TODO: add selector for interpolation method */ + neareast_interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j); + } + } + } + + tmpibuf->userflags|= IB_MIPMAP_INVALID; + + if(tmpibuf->rect_float) + tmpibuf->userflags|= IB_RECT_INVALID; + + if(loc) copy_v2_v2(loc, tloc); + if(scale) *scale= tscale; + if(angle) *angle= tangle; + + return tmpibuf; +} + +void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]) +{ + float lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4]; + float svec[3]= {scale, scale, scale}; + + unit_m4(rmat); + unit_m4(lmat); + unit_m4(smat); + unit_m4(cmat); + + /* image center as rotation center */ + cmat[3][0]= (float)width/2.0f; + cmat[3][1]= (float)height/2.0f; + invert_m4_m4(icmat, cmat); + + size_to_mat4(smat, svec); /* scale matrix */ + add_v2_v2(lmat[3], loc); /* tranlation matrix */ + rotate_m4(rmat, 'Z', angle); /* rotation matrix */ + + /* compose transformation matrix */ + mul_serie_m4(mat, lmat, cmat, rmat, smat, icmat, NULL, NULL, NULL); +} + +MovieDistortion *BKE_tracking_distortion_create(void) +{ + MovieDistortion *distortion; + + distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); + + return distortion; +} + +MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion) +{ + MovieDistortion *new_distortion; + + new_distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create"); + +#ifdef WITH_LIBMV + new_distortion->intrinsics= libmv_CameraIntrinsicsCopy(distortion->intrinsics); +#endif + + return new_distortion; +} + +void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking *tracking, int width, int height) +{ + MovieTrackingCamera *camera= &tracking->camera; + float aspy= 1.0f/tracking->camera.pixel_aspect; + +#ifdef WITH_LIBMV + if(!distortion->intrinsics) { + distortion->intrinsics= libmv_CameraIntrinsicsNew(camera->focal, + camera->principal[0], camera->principal[1] * aspy, + camera->k1, camera->k2, camera->k3, width, height * aspy); + } else { + libmv_CameraIntrinsicsUpdate(distortion->intrinsics, camera->focal, + camera->principal[0], camera->principal[1] * aspy, + camera->k1, camera->k2, camera->k3, width, height * aspy); + } +#endif +} + +ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *tracking, + ImBuf *ibuf, int width, int height, float overscan, int undistort) +{ + ImBuf *resibuf; + + BKE_tracking_distortion_update(distortion, tracking, width, height); + + resibuf= IMB_dupImBuf(ibuf); + + if(ibuf->rect_float) { +#ifdef WITH_LIBMV + if(undistort) { + libmv_CameraIntrinsicsUndistortFloat(distortion->intrinsics, + ibuf->rect_float, resibuf->rect_float, + ibuf->x, ibuf->y, overscan, ibuf->channels); + } else { + libmv_CameraIntrinsicsDistortFloat(distortion->intrinsics, + ibuf->rect_float, resibuf->rect_float, + ibuf->x, ibuf->y, overscan, ibuf->channels); + } +#endif + + ibuf->userflags|= IB_RECT_INVALID; + } else { +#ifdef WITH_LIBMV + if(undistort) { + libmv_CameraIntrinsicsUndistortByte(distortion->intrinsics, + (unsigned char*)ibuf->rect, (unsigned char*)resibuf->rect, + ibuf->x, ibuf->y, overscan, ibuf->channels); + } else { + libmv_CameraIntrinsicsDistortByte(distortion->intrinsics, + (unsigned char*)ibuf->rect, (unsigned char*)resibuf->rect, + ibuf->x, ibuf->y, overscan, ibuf->channels); + } +#endif + } + + return resibuf; +} + +void BKE_tracking_distortion_destroy(MovieDistortion *distortion) +{ +#ifdef WITH_LIBMV + libmv_CameraIntrinsicsDestroy(distortion->intrinsics); +#endif + + MEM_freeN(distortion); +} + +ImBuf *BKE_tracking_undistort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) +{ + MovieTrackingCamera *camera= &tracking->camera; + + if(camera->intrinsics == NULL) + camera->intrinsics= BKE_tracking_distortion_create(); + + return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 1); +} + +ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) +{ + MovieTrackingCamera *camera= &tracking->camera; + + if(camera->intrinsics == NULL) + camera->intrinsics= BKE_tracking_distortion_create(); + + return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0); +} + +/* area - which part of marker should be selected. see TRACK_AREA_* constants */ +void BKE_tracking_select_track(MovieTracking *tracking, MovieTrackingTrack *track, int area, int extend) +{ + if(extend) { + BKE_tracking_track_flag(track, area, SELECT, 0); + } else { + MovieTrackingTrack *cur= tracking->tracks.first; + + while(cur) { + if(cur==track) { + BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1); + BKE_tracking_track_flag(cur, area, SELECT, 0); + } + else { + BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1); + } + + cur= cur->next; + } + } +} + +void BKE_tracking_deselect_track(MovieTrackingTrack *track, int area) +{ + BKE_tracking_track_flag(track, area, SELECT, 1); +} -- cgit v1.2.3 From 7b43abb90e2895292e183fcbca7140447025acd7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 7 Nov 2011 12:56:05 +0000 Subject: Camera tracking integration =========================== Rest of changes from camera tracking gsoc project. This commit includes: - New compositor nodes: * Movie Clip input node * Movie Undistortion node * Transformation node * 2D stabilization node - Slight changes in existing node to prevent code duplication --- source/blender/blenkernel/intern/node.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index a9b2ffe7529..115591863cc 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1790,6 +1790,7 @@ static void registerCompositNodes(ListBase *ntypelist) register_node_type_cmp_value(ntypelist); register_node_type_cmp_rgb(ntypelist); register_node_type_cmp_curve_time(ntypelist); + register_node_type_cmp_movieclip(ntypelist); register_node_type_cmp_composite(ntypelist); register_node_type_cmp_viewer(ntypelist); @@ -1854,6 +1855,9 @@ static void registerCompositNodes(ListBase *ntypelist) register_node_type_cmp_glare(ntypelist); register_node_type_cmp_tonemap(ntypelist); register_node_type_cmp_lensdist(ntypelist); + register_node_type_cmp_transform(ntypelist); + register_node_type_cmp_stabilize2d(ntypelist); + register_node_type_cmp_moviedistortion(ntypelist); } static void registerShaderNodes(ListBase *ntypelist) -- cgit v1.2.3 From 2b6e4f242230d99470ef70c7c00f1809a098d200 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 7 Nov 2011 13:25:17 +0000 Subject: Bugfix [#29064] armature with curve contraint - crash Spline IK and Auto-IK working together on the same bone chain could crash due to the somewhat hacky way that they were sharing the same list for the "iktree" forest. Resolved by doing what I should have done from the beginning, and made Spline-IK save its ik chains off into a separate list. While this fixes the crash, it might be worth investigating outright disabling this from working in this case, since it can be a bit confusing to have it appear to not work. --- source/blender/blenkernel/intern/armature.c | 35 +++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 50f305e4400..a9c29728650 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1818,7 +1818,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos tree->ikData= ikData; /* AND! link the tree to the root */ - BLI_addtail(&pchanRoot->iktree, tree); + BLI_addtail(&pchanRoot->siktree, tree); } /* mark root channel having an IK tree */ @@ -2045,27 +2045,24 @@ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_ tSplineIK_Tree *tree; /* for each pose-tree, execute it if it is spline, otherwise just free it */ - for (tree= pchan_root->iktree.first; tree; tree= pchan_root->iktree.first) { - /* only evaluate if tagged for Spline IK */ - if (tree->type == CONSTRAINT_TYPE_SPLINEIK) { - int i; - - /* walk over each bone in the chain, calculating the effects of spline IK - * - the chain is traversed in the opposite order to storage order (i.e. parent to children) - * so that dependencies are correct - */ - for (i= tree->chainlen-1; i >= 0; i--) { - bPoseChannel *pchan= tree->chain[i]; - splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime); - } - - /* free the tree info specific to SplineIK trees now */ - if (tree->chain) MEM_freeN(tree->chain); - if (tree->free_points) MEM_freeN(tree->points); + while ((tree = pchan_root->siktree.first) != NULL) { + int i; + + /* walk over each bone in the chain, calculating the effects of spline IK + * - the chain is traversed in the opposite order to storage order (i.e. parent to children) + * so that dependencies are correct + */ + for (i= tree->chainlen-1; i >= 0; i--) { + bPoseChannel *pchan= tree->chain[i]; + splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime); } + /* free the tree info specific to SplineIK trees now */ + if (tree->chain) MEM_freeN(tree->chain); + if (tree->free_points) MEM_freeN(tree->points); + /* free this tree */ - BLI_freelinkN(&pchan_root->iktree, tree); + BLI_freelinkN(&pchan_root->siktree, tree); } } -- cgit v1.2.3 From 9b5652215abb91e5aa3ce40664fc0067567382b0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2011 15:19:26 +0000 Subject: minor warning nicer api use --- source/blender/blenkernel/intern/movieclip.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 18a7ad65dae..c7ebef82d6f 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -156,13 +156,10 @@ static void get_sequence_fname(MovieClip *clip, int framenr, char *name) autoguess offset for now. could be something smarter in the future */ offset= sequence_guess_offset(clip->name, strlen(head), numlen); - if(numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1); - else strncpy(name, clip->name, sizeof(name)); + if (numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1); + else BLI_strncpy(name, clip->name, sizeof(name)); - if(clip->id.lib) - BLI_path_abs(name, clip->id.lib->filepath); - else - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id)); } /* supposed to work with sequences only */ @@ -174,7 +171,7 @@ static void get_proxy_fname(MovieClip *clip, int proxy_render_size, int undistor BLI_split_dirfile(clip->name, clipdir, clipfile, FILE_MAX, FILE_MAX); if(clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) { - strcpy(dir, clip->proxy.dir); + BLI_strncpy(dir, clip->proxy.dir, sizeof(dir)); } else { BLI_snprintf(dir, FILE_MAX, "%s/BL_proxy", clipdir); } @@ -194,9 +191,9 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip, MovieClipUser *user, { struct ImBuf *ibuf; char name[FILE_MAX]; - int loadflag, size, undistort; + int loadflag /*, size */ /* UNUSED */, undistort; - size= rendersize_to_number(user->render_size); + /* size= rendersize_to_number(user->render_size); */ undistort= user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT; @@ -222,11 +219,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in if(!clip->anim) { BLI_strncpy(str, clip->name, FILE_MAX); - - if(clip->id.lib) - BLI_path_abs(str, clip->id.lib->filepath); - else - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, ID_BLEND_PATH(G.main, &clip->id)); /* FIXME: make several stream accessible in image editor, too */ clip->anim= openanim(str, IB_rect, 0); @@ -234,7 +227,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in if(clip->anim) { if(clip->flag&MCLIP_USE_PROXY_CUSTOM_DIR) { char dir[FILE_MAX]; - strcpy(dir, clip->proxy.dir); + BLI_strncpy(dir, clip->proxy.dir, sizeof(dir)); BLI_path_abs(dir, G.main->name); IMB_anim_set_index_dir(clip->anim, dir); } @@ -243,7 +236,7 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in if(clip->anim) { int dur; - int fra= framenr-1; + int fra; dur= IMB_anim_get_duration(clip->anim, tc); fra= framenr-1; -- cgit v1.2.3 From 9de67a61aa431012625d4bd8910c6681595c6685 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2011 15:57:52 +0000 Subject: fix for error in own recent commit. --- source/blender/blenkernel/intern/movieclip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index c7ebef82d6f..e3bfdd54ab1 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -157,7 +157,7 @@ static void get_sequence_fname(MovieClip *clip, int framenr, char *name) offset= sequence_guess_offset(clip->name, strlen(head), numlen); if (numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1); - else BLI_strncpy(name, clip->name, sizeof(name)); + else BLI_strncpy(name, clip->name, sizeof(clip->name)); BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id)); } -- cgit v1.2.3 From 9ced8a23fe57e20366d63bc6bfedf0b24f0bf767 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2011 16:26:23 +0000 Subject: quiet warnings when building without libmv --- source/blender/blenkernel/intern/tracking.c | 44 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 06a985e7d72..a834628641a 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -58,7 +58,9 @@ #include "IMB_imbuf.h" #ifdef WITH_LIBMV -#include "libmv-capi.h" +# include "libmv-capi.h" +#else +struct libmv_Features; #endif typedef struct MovieDistortion { @@ -1379,6 +1381,12 @@ float BKE_tracking_solve_reconstruction(MovieTracking *tracking, int width, int return error; } +#else + (void)tracking; + (void)width; + (void)height; + + return -1.0f; #endif } @@ -1581,6 +1589,10 @@ void BKE_tracking_apply_intrinsics(MovieTracking *tracking, float co[2], float n /* result is in image coords already */ nco[0]= x; nco[1]= y; +#else + (void)camera; + (void)co; + (void)nco; #endif } @@ -1597,9 +1609,14 @@ void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float nco[0]= x * camera->focal + camera->principal[0]; nco[1]= y * camera->focal + camera->principal[1] * aspy; +#else + (void)camera; + (void)co; + (void)nco; #endif } +#ifdef WITH_LIBMV static int point_in_stroke(bGPDstroke *stroke, float x, float y) { int i, prev; @@ -1643,7 +1660,6 @@ static int point_in_layer(bGPDlayer *layer, float x, float y) static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Features *features, int framenr, int width, int height, bGPDlayer *layer, int place_outside_layer) { -#ifdef WITH_LIBMV int a; a= libmv_countFeatures(features); @@ -1668,8 +1684,8 @@ static void retrieve_libmv_features(MovieTracking *tracking, struct libmv_Featur track->search_flag|= SELECT; } } -#endif } +#endif void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf, int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer, @@ -1686,6 +1702,15 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf, retrieve_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, layer, place_outside_layer); libmv_destroyFeatures(features); +#else + (void)tracking; + (void)ibuf; + (void)framenr; + (void)margin; + (void)min_trackness; + (void)min_distance; + (void)layer; + (void)place_outside_layer; #endif } @@ -2048,6 +2073,8 @@ MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion) #ifdef WITH_LIBMV new_distortion->intrinsics= libmv_CameraIntrinsicsCopy(distortion->intrinsics); +#else + (void)distortion; #endif return new_distortion; @@ -2068,6 +2095,12 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking * camera->principal[0], camera->principal[1] * aspy, camera->k1, camera->k2, camera->k3, width, height * aspy); } +#else + (void)distortion; + (void)width; + (void)height; + (void)camera; + (void)aspy; #endif } @@ -2108,6 +2141,11 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking * #endif } +#ifndef WITH_LIBMV + (void)overscan; + (void)undistort; +#endif + return resibuf; } -- cgit v1.2.3