diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-06 12:10:19 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-06 12:10:19 +0300 |
commit | 43f895a59247ea4058cb3f019cd4dabd9ad9b0e4 (patch) | |
tree | 51469fde8affa6b20f67d12a4602c5f109c1a204 /source/blender/blenkernel | |
parent | 52606afaa60462db45e783607255f56c06fd8d73 (diff) | |
parent | 480ff89bf7cfb1f9ffd5ce66fbd5c65288ef04c0 (diff) |
Merge branch 'master' into functions
Diffstat (limited to 'source/blender/blenkernel')
109 files changed, 2689 insertions, 2364 deletions
diff --git a/source/blender/blenkernel/BKE_addon.h b/source/blender/blenkernel/BKE_addon.h index 7bb1761dfbe..741be17bb25 100644 --- a/source/blender/blenkernel/BKE_addon.h +++ b/source/blender/blenkernel/BKE_addon.h @@ -33,7 +33,7 @@ typedef struct bAddonPrefType { char idname[64]; // best keep the same size as BKE_ST_MAXNAME /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } bAddonPrefType; #else diff --git a/source/blender/blenkernel/BKE_anim_data.h b/source/blender/blenkernel/BKE_anim_data.h new file mode 100644 index 00000000000..071254be783 --- /dev/null +++ b/source/blender/blenkernel/BKE_anim_data.h @@ -0,0 +1,95 @@ +/* + * 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) 2009 Blender Foundation, Joshua Leung + * All rights reserved. + */ + +#ifndef __BKE_ANIM_DATA_H__ +#define __BKE_ANIM_DATA_H__ + +/** \file + * \ingroup bke + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "BLI_sys_types.h" /* for bool */ + +struct AnimData; +struct ID; +struct Main; +struct ReportList; +struct bAction; + +/* ************************************* */ +/* AnimData API */ + +/* Check if the given ID-block can have AnimData */ +bool id_type_can_have_animdata(const short id_type); +bool id_can_have_animdata(const struct ID *id); + +/* Get AnimData from the given ID-block */ +struct AnimData *BKE_animdata_from_id(struct ID *id); + +/* Add AnimData to the given ID-block */ +struct AnimData *BKE_animdata_add_id(struct ID *id); + +/* Set active action used by AnimData from the given ID-block */ +bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct bAction *act); + +/* Free AnimData */ +void BKE_animdata_free(struct ID *id, const bool do_id_user); + +/* Return true if the ID-block has non-empty AnimData. */ +bool BKE_animdata_id_is_animated(const struct ID *id); + +/* Copy AnimData */ +struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag); + +/* Copy AnimData */ +bool BKE_animdata_copy_id(struct Main *bmain, + struct ID *id_to, + struct ID *id_from, + const int flag); + +/* Copy AnimData Actions */ +void BKE_animdata_copy_id_action(struct Main *bmain, struct ID *id, const bool set_newid); + +/* Merge copies of data from source AnimData block */ +typedef enum eAnimData_MergeCopy_Modes { + /* Keep destination action */ + ADT_MERGECOPY_KEEP_DST = 0, + + /* Use src action (make a new copy) */ + ADT_MERGECOPY_SRC_COPY = 1, + + /* Use src action (but just reference the existing version) */ + ADT_MERGECOPY_SRC_REF = 2, +} eAnimData_MergeCopy_Modes; + +void BKE_animdata_merge_copy(struct Main *bmain, + struct ID *dst_id, + struct ID *src_id, + eAnimData_MergeCopy_Modes action_mode, + bool fix_drivers); + +#ifdef __cplusplus +} +#endif + +#endif /* __BKE_ANIM_DATA_H__*/ diff --git a/source/blender/blenkernel/BKE_anim_path.h b/source/blender/blenkernel/BKE_anim_path.h new file mode 100644 index 00000000000..64bcedefa58 --- /dev/null +++ b/source/blender/blenkernel/BKE_anim_path.h @@ -0,0 +1,51 @@ +/* + * 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. + */ +#ifndef __BKE_ANIM_PATH_H__ +#define __BKE_ANIM_PATH_H__ + +/** \file + * \ingroup bke + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct ListBase; +struct Object; +struct Path; + +/* ---------------------------------------------------- */ +/* Curve Paths */ + +void free_path(struct Path *path); +void calc_curvepath(struct Object *ob, struct ListBase *nurbs); +int where_on_path(struct Object *ob, + float ctime, + float vec[4], + float dir[3], + float quat[4], + float *radius, + float *weight); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/blenkernel/BKE_anim_visualization.h b/source/blender/blenkernel/BKE_anim_visualization.h new file mode 100644 index 00000000000..5dcbfa0919e --- /dev/null +++ b/source/blender/blenkernel/BKE_anim_visualization.h @@ -0,0 +1,56 @@ +/* + * 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. + */ +#ifndef __BKE_ANIM_VISUALIZATION_H__ +#define __BKE_ANIM_VISUALIZATION_H__ + +/** \file + * \ingroup bke + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Object; +struct ReportList; +struct Scene; +struct bAnimVizSettings; +struct bMotionPath; +struct bPoseChannel; + +/* ---------------------------------------------------- */ +/* Animation Visualization */ + +void animviz_settings_init(struct bAnimVizSettings *avs); + +struct bMotionPath *animviz_copy_motionpath(const struct bMotionPath *mpath_src); + +void animviz_free_motionpath_cache(struct bMotionPath *mpath); +void animviz_free_motionpath(struct bMotionPath *mpath); + +struct bMotionPath *animviz_verify_motionpaths(struct ReportList *reports, + struct Scene *scene, + struct Object *ob, + struct bPoseChannel *pchan); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 9da17d777cd..a8915c178d4 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -28,6 +28,8 @@ extern "C" { #endif +#include "BLI_sys_types.h" /* for bool */ + struct AnimData; struct Depsgraph; struct FCurve; @@ -47,58 +49,6 @@ struct bActionGroup; struct bContext; /* ************************************* */ -/* AnimData API */ - -/* Check if the given ID-block can have AnimData */ -bool id_type_can_have_animdata(const short id_type); -bool id_can_have_animdata(const struct ID *id); - -/* Get AnimData from the given ID-block */ -struct AnimData *BKE_animdata_from_id(struct ID *id); - -/* Add AnimData to the given ID-block */ -struct AnimData *BKE_animdata_add_id(struct ID *id); - -/* Set active action used by AnimData from the given ID-block */ -bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct bAction *act); - -/* Free AnimData */ -void BKE_animdata_free(struct ID *id, const bool do_id_user); - -/* Return true if the ID-block has non-empty AnimData. */ -bool BKE_animdata_id_is_animated(const struct ID *id); - -/* Copy AnimData */ -struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag); - -/* Copy AnimData */ -bool BKE_animdata_copy_id(struct Main *bmain, - struct ID *id_to, - struct ID *id_from, - const int flag); - -/* Copy AnimData Actions */ -void BKE_animdata_copy_id_action(struct Main *bmain, struct ID *id, const bool set_newid); - -/* Merge copies of data from source AnimData block */ -typedef enum eAnimData_MergeCopy_Modes { - /* Keep destination action */ - ADT_MERGECOPY_KEEP_DST = 0, - - /* Use src action (make a new copy) */ - ADT_MERGECOPY_SRC_COPY = 1, - - /* Use src action (but just reference the existing version) */ - ADT_MERGECOPY_SRC_REF = 2, -} eAnimData_MergeCopy_Modes; - -void BKE_animdata_merge_copy(struct Main *bmain, - struct ID *dst_id, - struct ID *src_id, - eAnimData_MergeCopy_Modes action_mode, - bool fix_drivers); - -/* ************************************* */ /* KeyingSets API */ /* Used to create a new 'custom' KeyingSet for the user, diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 9e2a124491c..c4fb19ea355 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -178,7 +178,7 @@ struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C); void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm); void CTX_wm_window_set(bContext *C, struct wmWindow *win); void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */ -void CTX_wm_area_set(bContext *C, struct ScrArea *sa); +void CTX_wm_area_set(bContext *C, struct ScrArea *area); void CTX_wm_region_set(bContext *C, struct ARegion *region); void CTX_wm_menu_set(bContext *C, struct ARegion *menu); void CTX_wm_gizmo_group_set(bContext *C, struct wmGizmoGroup *gzgroup); diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_duplilist.h index 38af96c2ff0..71b6d06b450 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_duplilist.h @@ -16,8 +16,8 @@ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. */ -#ifndef __BKE_ANIM_H__ -#define __BKE_ANIM_H__ +#ifndef __BKE_DUPLILIST_H__ +#define __BKE_DUPLILIST_H__ /** \file * \ingroup bke @@ -31,40 +31,7 @@ struct Depsgraph; struct ListBase; struct Object; struct ParticleSystem; -struct Path; -struct ReportList; struct Scene; -struct bAnimVizSettings; -struct bMotionPath; -struct bPoseChannel; - -/* ---------------------------------------------------- */ -/* Animation Visualization */ - -void animviz_settings_init(struct bAnimVizSettings *avs); - -struct bMotionPath *animviz_copy_motionpath(const struct bMotionPath *mpath_src); - -void animviz_free_motionpath_cache(struct bMotionPath *mpath); -void animviz_free_motionpath(struct bMotionPath *mpath); - -struct bMotionPath *animviz_verify_motionpaths(struct ReportList *reports, - struct Scene *scene, - struct Object *ob, - struct bPoseChannel *pchan); - -/* ---------------------------------------------------- */ -/* Curve Paths */ - -void free_path(struct Path *path); -void calc_curvepath(struct Object *ob, struct ListBase *nurbs); -int where_on_path(struct Object *ob, - float ctime, - float vec[4], - float dir[3], - float quat[4], - float *radius, - float *weight); /* ---------------------------------------------------- */ /* Dupli-Geometry */ diff --git a/source/blender/blenkernel/BKE_fluid.h b/source/blender/blenkernel/BKE_fluid.h index 2c5742d3dc7..e8b4c819c62 100644 --- a/source/blender/blenkernel/BKE_fluid.h +++ b/source/blender/blenkernel/BKE_fluid.h @@ -75,6 +75,9 @@ void BKE_fluid_particle_system_create(struct Main *bmain, const int psys_type); void BKE_fluid_particle_system_destroy(struct Object *ob, const int particle_type); +void BKE_fluid_cache_startframe_set(struct FluidDomainSettings *settings, int value); +void BKE_fluid_cache_endframe_set(struct FluidDomainSettings *settings, int value); + void BKE_fluid_cachetype_mesh_set(struct FluidDomainSettings *settings, int cache_mesh_format); void BKE_fluid_cachetype_data_set(struct FluidDomainSettings *settings, int cache_data_format); void BKE_fluid_cachetype_particle_set(struct FluidDomainSettings *settings, diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 8cd3081389e..faa331aa02d 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -68,21 +68,21 @@ struct bGPdata; /* Vertex Color macros. */ #define GPENCIL_USE_VERTEX_COLOR(toolsettings) \ - ((toolsettings->gp_paint->mode == GPPAINT_FLAG_USE_VERTEXCOLOR)) + (((toolsettings)->gp_paint->mode == GPPAINT_FLAG_USE_VERTEXCOLOR)) #define GPENCIL_USE_VERTEX_COLOR_STROKE(toolsettings, brush) \ ((GPENCIL_USE_VERTEX_COLOR(toolsettings) && \ - ((brush->gpencil_settings->vertex_mode == GPPAINT_MODE_STROKE) || \ - (brush->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)))) + (((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_STROKE) || \ + ((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)))) #define GPENCIL_USE_VERTEX_COLOR_FILL(toolsettings, brush) \ ((GPENCIL_USE_VERTEX_COLOR(toolsettings) && \ - ((brush->gpencil_settings->vertex_mode == GPPAINT_MODE_FILL) || \ - (brush->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)))) + (((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_FILL) || \ + ((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)))) #define GPENCIL_TINT_VERTEX_COLOR_STROKE(brush) \ - ((brush->gpencil_settings->vertex_mode == GPPAINT_MODE_STROKE) || \ - (brush->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)) + (((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_STROKE) || \ + ((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)) #define GPENCIL_TINT_VERTEX_COLOR_FILL(brush) \ - ((brush->gpencil_settings->vertex_mode == GPPAINT_MODE_FILL) || \ - (brush->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)) + (((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_FILL) || \ + ((brush)->gpencil_settings->vertex_mode == GPPAINT_MODE_BOTH)) /* ------------ Grease-Pencil API ------------------ */ diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 93bcfe5323d..05545216217 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -183,7 +183,7 @@ const char *BKE_idtype_idcode_to_translation_context(const short idcode); bool BKE_idtype_idcode_is_linkable(const short idcode); bool BKE_idtype_idcode_is_valid(const short idcode); -short BKE_idtype_idcode_from_name(const char *name); +short BKE_idtype_idcode_from_name(const char *idtype_name); uint64_t BKE_idtype_idcode_to_idfilter(const short idcode); short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter); diff --git a/source/blender/blenkernel/BKE_keyconfig.h b/source/blender/blenkernel/BKE_keyconfig.h index 711d0292f75..bc33cc2669e 100644 --- a/source/blender/blenkernel/BKE_keyconfig.h +++ b/source/blender/blenkernel/BKE_keyconfig.h @@ -37,7 +37,7 @@ typedef struct wmKeyConfigPrefType_Runtime { char idname[64]; /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } wmKeyConfigPrefType_Runtime; #else diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index 306d889fba4..ed1f67350c3 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -225,11 +225,11 @@ int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]); #define MAIN_VERSION_ATLEAST(main, ver, subver) \ ((main)->versionfile > (ver) || \ - (main->versionfile == (ver) && (main)->subversionfile >= (subver))) + ((main)->versionfile == (ver) && (main)->subversionfile >= (subver))) #define MAIN_VERSION_OLDER(main, ver, subver) \ ((main)->versionfile < (ver) || \ - (main->versionfile == (ver) && (main)->subversionfile < (subver))) + ((main)->versionfile == (ver) && (main)->subversionfile < (subver))) #define BLEN_THUMB_SIZE 128 diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index cef26345980..dca677343ce 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -238,10 +238,10 @@ void BKE_mask_clipboard_paste_to_layer(struct Main *bmain, struct MaskLayer *mas #define MASKPOINT_ISSEL_KNOT(p) (((p)->bezt.f2 & SELECT) != 0) #define MASKPOINT_ISSEL_HANDLE(point, which_handle) \ - (((which_handle == MASK_WHICH_HANDLE_STICK) ? \ + ((((which_handle) == MASK_WHICH_HANDLE_STICK) ? \ ((((point)->bezt.f1 | (point)->bezt.f3) & SELECT)) : \ - ((which_handle == MASK_WHICH_HANDLE_LEFT) ? ((point)->bezt.f1 & SELECT) : \ - ((point)->bezt.f3 & SELECT))) != 0) + (((which_handle) == MASK_WHICH_HANDLE_LEFT) ? ((point)->bezt.f1 & SELECT) : \ + ((point)->bezt.f3 & SELECT))) != 0) #define MASKPOINT_SEL_ALL(p) \ { \ diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index dc06f56861a..38fe974c228 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -268,7 +268,7 @@ typedef struct bNodeType { NodeGPUExecFunction gpufunc; /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } bNodeType; /* nodetype->nclass, for add-menu and themes */ @@ -350,7 +350,7 @@ typedef struct bNodeTreeType { void (*node_add_init)(struct bNodeTree *ntree, struct bNode *bnode); /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } bNodeTreeType; /** \} */ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 75198cd3f63..70a44d6d8ce 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -277,7 +277,7 @@ void BKE_object_eval_uber_data(struct Depsgraph *depsgraph, void BKE_object_eval_assign_data(struct Object *object, struct ID *data, bool is_owned); void BKE_object_eval_boundbox(struct Depsgraph *depsgraph, struct Object *object); -void BKE_object_synchronize_to_original(struct Depsgraph *depsgraph, struct Object *object); +void BKE_object_sync_to_original(struct Depsgraph *depsgraph, struct Object *object); void BKE_object_eval_ptcache_reset(struct Depsgraph *depsgraph, struct Scene *scene, diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 881f3356a86..012188bed96 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -283,7 +283,11 @@ typedef struct SculptClothSimulation { typedef struct SculptSession { /* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */ - struct MultiresModifierData *multires; /* Special handling for multires meshes */ + struct { /* Special handling for multires meshes */ + bool active; + struct MultiresModifierData *modifier; + int level; + } multires; struct MVert *mvert; struct MPoly *mpoly; struct MLoop *mloop; @@ -296,6 +300,7 @@ typedef struct SculptSession { int *pmap_mem; /* Mesh Face Sets */ + int totfaces; int *face_sets; /* BMesh for dynamic topology sculpting */ @@ -333,6 +338,9 @@ typedef struct SculptSession { /* Cursor data and active vertex for tools */ int active_vertex_index; + int active_face_index; + int active_grid_index; + float cursor_radius; float cursor_location[3]; float cursor_normal[3]; diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 16a7e4d38d0..a59ce816e26 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -81,6 +81,9 @@ typedef struct PBVHFrustumPlanes { int num_planes; } PBVHFrustumPlanes; +void BKE_pbvh_set_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes); +void BKE_pbvh_get_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes); + /* Callbacks */ /* returns 1 if the search should continue from this node, 0 otherwise */ @@ -155,6 +158,7 @@ bool BKE_pbvh_node_raycast(PBVH *bvh, struct IsectRayPrecalc *isect_precalc, float *depth, int *active_vertex_index, + int *active_face_grid_index, float *face_normal); bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, @@ -189,7 +193,8 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *bvh, void BKE_pbvh_draw_cb(PBVH *bvh, bool show_vcol, bool update_only_visible, - PBVHFrustumPlanes *frustum, + PBVHFrustumPlanes *update_frustum, + PBVHFrustumPlanes *draw_frustum, void (*draw_fn)(void *user_data, struct GPU_PBVH_Buffers *buffers), void *user_data); @@ -219,6 +224,8 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden, int totgrid, int gridsize); +void BKE_pbvh_sync_face_sets_to_grids(PBVH *bvh); + /* multires level, only valid for type == PBVH_GRIDS */ const struct CCGKey *BKE_pbvh_get_grid_key(const PBVH *pbvh); @@ -298,6 +305,8 @@ void BKE_pbvh_grids_update(PBVH *bvh, void **gridfaces, struct DMFlagMat *flagmats, unsigned int **grid_hidden); +void BKE_pbvh_subdiv_cgg_set(PBVH *bvh, struct SubdivCCG *subdiv_ccg); +void BKE_pbvh_face_sets_set(PBVH *bvh, int *face_sets); void BKE_pbvh_face_sets_color_set(PBVH *bvh, int seed, int color_default); diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 9d4d53bf27f..b4aa0ac2b93 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -121,16 +121,16 @@ void BKE_rigidbody_remove_constraint(struct Main *bmain, /* get mass of Rigid Body Object to supply to RigidBody simulators */ #define RBO_GET_MASS(rbo) \ - ((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || \ - (rbo->flag & RBO_FLAG_DISABLED))) ? \ + (((rbo) && (((rbo)->type == RBO_TYPE_PASSIVE) || ((rbo)->flag & RBO_FLAG_KINEMATIC) || \ + ((rbo)->flag & RBO_FLAG_DISABLED))) ? \ (0.0f) : \ - (rbo->mass)) + ((rbo)->mass)) /* Get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, * convex hull always uses custom margin. */ #define RBO_GET_MARGIN(rbo) \ - ((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || \ - rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? \ - (rbo->margin) : \ + (((rbo)->flag & RBO_FLAG_USE_MARGIN || (rbo)->shape == RB_SHAPE_CONVEXH || \ + (rbo)->shape == RB_SHAPE_TRIMESH || (rbo)->shape == RB_SHAPE_CONE) ? \ + ((rbo)->margin) : \ (0.04f)) /* -------------- */ diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 2231cc36861..c49b6e27bba 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -72,25 +72,25 @@ typedef struct SpaceType { /* Initial allocation, after this WM will call init() too. Some editors need * area and scene data (e.g. frame range) to set their initial scrolling. */ - struct SpaceLink *(*new)(const struct ScrArea *sa, const struct Scene *scene); + struct SpaceLink *(*new)(const struct ScrArea *area, const struct Scene *scene); /* not free spacelink itself */ void (*free)(struct SpaceLink *sl); /* init is to cope with file load, screen (size) changes, check handlers */ - void (*init)(struct wmWindowManager *wm, struct ScrArea *sa); + void (*init)(struct wmWindowManager *wm, struct ScrArea *area); /* exit is called when the area is hidden or removed */ - void (*exit)(struct wmWindowManager *wm, struct ScrArea *sa); + void (*exit)(struct wmWindowManager *wm, struct ScrArea *area); /* Listeners can react to bContext changes */ void (*listener)(struct wmWindow *win, - struct ScrArea *sa, + struct ScrArea *area, struct wmNotifier *wmn, struct Scene *scene); /* called when the mouse moves out of the area */ - void (*deactivate)(struct ScrArea *sa); + void (*deactivate)(struct ScrArea *area); /* refresh context, called after filereads, ED_area_tag_refresh() */ - void (*refresh)(const struct bContext *C, struct ScrArea *sa); + void (*refresh)(const struct bContext *C, struct ScrArea *area); /* after a spacedata copy, an init should result in exact same situation */ struct SpaceLink *(*duplicate)(struct SpaceLink *sl); @@ -109,10 +109,13 @@ typedef struct SpaceType { int (*context)(const struct bContext *C, const char *member, struct bContextDataResult *result); /* Used when we want to replace an ID by another (or NULL). */ - void (*id_remap)(struct ScrArea *sa, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id); + void (*id_remap)(struct ScrArea *area, + struct SpaceLink *sl, + struct ID *old_id, + struct ID *new_id); - int (*space_subtype_get)(struct ScrArea *sa); - void (*space_subtype_set)(struct ScrArea *sa, int value); + int (*space_subtype_get)(struct ScrArea *area); + void (*space_subtype_set)(struct ScrArea *area, int value); void (*space_subtype_item_extend)(struct bContext *C, EnumPropertyItem **item, int *totitem); /* region type definitions */ @@ -144,7 +147,7 @@ typedef struct ARegionType { int (*snap_size)(const struct ARegion *region, int size, int axis); /* contextual changes should be handled here */ void (*listener)(struct wmWindow *win, - struct ScrArea *sa, + struct ScrArea *area, struct ARegion *region, struct wmNotifier *wmn, const struct Scene *scene); @@ -152,8 +155,8 @@ typedef struct ARegionType { void (*message_subscribe)(const struct bContext *C, struct WorkSpace *workspace, struct Scene *scene, - struct bScreen *sc, - struct ScrArea *sa, + struct bScreen *screen, + struct ScrArea *area, struct ARegion *region, struct wmMsgBus *mbus); @@ -167,7 +170,7 @@ typedef struct ARegionType { /* add own items to keymap */ void (*keymap)(struct wmKeyConfig *keyconf); /* allows default cursor per region */ - void (*cursor)(struct wmWindow *win, struct ScrArea *sa, struct ARegion *region); + void (*cursor)(struct wmWindow *win, struct ScrArea *area, struct ARegion *region); /* return context data */ int (*context)(const struct bContext *C, const char *member, struct bContextDataResult *result); @@ -219,18 +222,18 @@ typedef struct PanelType { /* verify if the panel should draw or not */ bool (*poll)(const struct bContext *C, struct PanelType *pt); /* draw header (optional) */ - void (*draw_header)(const struct bContext *C, struct Panel *pa); + void (*draw_header)(const struct bContext *C, struct Panel *panel); /* draw header preset (optional) */ - void (*draw_header_preset)(const struct bContext *C, struct Panel *pa); + void (*draw_header_preset)(const struct bContext *C, struct Panel *panel); /* draw entirely, view changes should be handled here */ - void (*draw)(const struct bContext *C, struct Panel *pa); + void (*draw)(const struct bContext *C, struct Panel *panel); /* sub panels */ struct PanelType *parent; ListBase children; /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } PanelType; /* uilist types */ @@ -268,7 +271,7 @@ typedef struct uiListType { uiListFilterItemsFunc filter_items; /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } uiListType; /* header types */ @@ -285,7 +288,7 @@ typedef struct HeaderType { void (*draw)(const struct bContext *C, struct Header *header); /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } HeaderType; typedef struct Header { @@ -310,7 +313,7 @@ typedef struct MenuType { void (*draw)(const struct bContext *C, struct Menu *menu); /* RNA integration */ - ExtensionRNA ext; + ExtensionRNA rna_ext; } MenuType; typedef struct Menu { @@ -333,44 +336,48 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2); void BKE_spacedata_draw_locks(int set); struct ARegion *BKE_spacedata_find_region_type(const struct SpaceLink *slink, - const struct ScrArea *sa, + const struct ScrArea *area, int region_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BKE_spacedata_callback_id_remap_set( - void (*func)(struct ScrArea *sa, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id)); -void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID *id); +void BKE_spacedata_callback_id_remap_set(void (*func)( + struct ScrArea *area, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id)); +void BKE_spacedata_id_unref(struct ScrArea *area, struct SpaceLink *sl, struct ID *id); /* area/regions */ struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *region); void BKE_area_region_free(struct SpaceType *st, struct ARegion *region); void BKE_area_region_panels_free(struct ListBase *panels); -void BKE_screen_area_free(struct ScrArea *sa); +void BKE_screen_area_free(struct ScrArea *area); /* Gizmo-maps of a region need to be freed with the region. * Uses callback to avoid low-level call. */ void BKE_region_callback_free_gizmomap_set(void (*callback)(struct wmGizmoMap *)); void BKE_region_callback_refresh_tag_gizmomap_set(void (*callback)(struct wmGizmoMap *)); -struct ARegion *BKE_area_find_region_type(const struct ScrArea *sa, int type); -struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa); -struct ARegion *BKE_area_find_region_xy(struct ScrArea *sa, const int regiontype, int x, int y); -struct ARegion *BKE_screen_find_region_xy(struct bScreen *sc, const int regiontype, int x, int y) - ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +struct ARegion *BKE_area_find_region_type(const struct ScrArea *area, int type); +struct ARegion *BKE_area_find_region_active_win(struct ScrArea *area); +struct ARegion *BKE_area_find_region_xy(struct ScrArea *area, const int regiontype, int x, int y); +struct ARegion *BKE_screen_find_region_xy(struct bScreen *screen, + const int regiontype, + int x, + int y) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); -struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, +struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *screen, struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); -struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min); +struct ScrArea *BKE_screen_find_big_area(struct bScreen *screen, + const int spacetype, + const short min); struct ScrArea *BKE_screen_area_map_find_area_xy(const struct ScrAreaMap *areamap, const int spacetype, int x, int y); -struct ScrArea *BKE_screen_find_area_xy(struct bScreen *sc, const int spacetype, int x, int y); +struct ScrArea *BKE_screen_find_area_xy(struct bScreen *screen, const int spacetype, int x, int y); -void BKE_screen_gizmo_tag_refresh(struct bScreen *sc); +void BKE_screen_gizmo_tag_refresh(struct bScreen *screen); void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene); -void BKE_screen_view3d_scene_sync(struct bScreen *sc, struct Scene *scene); +void BKE_screen_view3d_scene_sync(struct bScreen *screen, struct Scene *scene); bool BKE_screen_is_fullscreen_area(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); bool BKE_screen_is_used(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); @@ -382,15 +389,17 @@ float BKE_screen_view3d_zoom_from_fac(float zoomfac); void BKE_screen_view3d_shading_init(struct View3DShading *shading); /* screen */ -void BKE_screen_free(struct bScreen *sc); +void BKE_screen_free(struct bScreen *screen); void BKE_screen_area_map_free(struct ScrAreaMap *area_map) ATTR_NONNULL(); -struct ScrEdge *BKE_screen_find_edge(struct bScreen *sc, struct ScrVert *v1, struct ScrVert *v2); +struct ScrEdge *BKE_screen_find_edge(struct bScreen *screen, + struct ScrVert *v1, + struct ScrVert *v2); void BKE_screen_sort_scrvert(struct ScrVert **v1, struct ScrVert **v2); -void BKE_screen_remove_double_scrverts(struct bScreen *sc); -void BKE_screen_remove_double_scredges(struct bScreen *sc); -void BKE_screen_remove_unused_scredges(struct bScreen *sc); -void BKE_screen_remove_unused_scrverts(struct bScreen *sc); +void BKE_screen_remove_double_scrverts(struct bScreen *screen); +void BKE_screen_remove_double_scredges(struct bScreen *screen); +void BKE_screen_remove_unused_scredges(struct bScreen *screen); +void BKE_screen_remove_unused_scrverts(struct bScreen *screen); void BKE_screen_header_alignment_reset(struct bScreen *screen); diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 556cd7105a9..1b4ca1350ad 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -493,7 +493,7 @@ typedef struct SeqLoadInfo { #define SEQ_DUPE_ALL (1 << 3) /* otherwise only selected are copied */ /* use as an api function */ -typedef struct Sequence *(*SeqLoadFunc)(struct bContext *, ListBase *, struct SeqLoadInfo *); +typedef struct Sequence *(*SeqLoadFn)(struct bContext *, ListBase *, struct SeqLoadInfo *); struct Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine, int type); diff --git a/source/blender/blenkernel/BKE_sequencer_offscreen.h b/source/blender/blenkernel/BKE_sequencer_offscreen.h index c753b4b566f..cc822e97270 100644 --- a/source/blender/blenkernel/BKE_sequencer_offscreen.h +++ b/source/blender/blenkernel/BKE_sequencer_offscreen.h @@ -47,7 +47,7 @@ typedef struct ImBuf *(*SequencerDrawView)(struct Depsgraph *depsgraph, const char *viewname, struct GPUOffScreen *ofs, char err_out[256]); -extern SequencerDrawView sequencer_view3d_cb; +extern SequencerDrawView sequencer_view3d_fn; #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_shader_fx.h b/source/blender/blenkernel/BKE_shader_fx.h index d6d0f0f71de..c8386a42c9a 100644 --- a/source/blender/blenkernel/BKE_shader_fx.h +++ b/source/blender/blenkernel/BKE_shader_fx.h @@ -35,9 +35,9 @@ struct Object; struct ShaderFxData; #define SHADER_FX_ACTIVE(_fx, _is_render) \ - (((_fx->mode & eShaderFxMode_Realtime) && (_is_render == false)) || \ - ((_fx->mode & eShaderFxMode_Render) && (_is_render == true))) -#define SHADER_FX_EDIT(_fx, _is_edit) (((_fx->mode & eShaderFxMode_Editmode) == 0) && (_is_edit)) + ((((_fx)->mode & eShaderFxMode_Realtime) && (_is_render == false)) || \ + (((_fx)->mode & eShaderFxMode_Render) && (_is_render == true))) +#define SHADER_FX_EDIT(_fx, _is_edit) ((((_fx)->mode & eShaderFxMode_Editmode) == 0) && (_is_edit)) typedef enum { /* Should not be used, only for None type */ diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h index f8534371b17..6f886a4b850 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.h +++ b/source/blender/blenkernel/BKE_subdiv_ccg.h @@ -218,8 +218,8 @@ typedef struct SubdivCCG { /* Create CCG representation of subdivision surface. * - * NOTE: CCG stores dense verticies in a grid-like storage. There is no edges or - * polygons informations for the high-poly surface. + * NOTE: CCG stores dense vertices in a grid-like storage. There is no edges or + * polygons information's for the high-poly surface. * * NOTE: Subdiv is expected to be refined and ready for evaluation. * NOTE: CCG becomes an owner of subdiv. @@ -305,6 +305,8 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, const bool include_duplicates, SubdivCCGNeighbors *r_neighbors); +int BKE_subdiv_cgg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_subdiv_deform.h b/source/blender/blenkernel/BKE_subdiv_deform.h index 11ef225de27..735cd20a6c8 100644 --- a/source/blender/blenkernel/BKE_subdiv_deform.h +++ b/source/blender/blenkernel/BKE_subdiv_deform.h @@ -34,10 +34,10 @@ struct Mesh; struct Subdiv; /* Special version of subdivision surface which calculates final positions for coarse vertices. - * Effectively is pushsing the coarse positions to the limit surface. + * Effectively is pushing the coarse positions to the limit surface. * * One of the usage examples is calculation of crazy space of subdivision modifier, allowing to - * paint on a deformed mesh with subsurf on it. + * paint on a deformed mesh with sub-surf on it. * * vertex_cos are supposed to hold coordinates of the coarse mesh. */ void BKE_subdiv_deform_coarse_vertices(struct Subdiv *subdiv, diff --git a/source/blender/blenkernel/BKE_subdiv_eval.h b/source/blender/blenkernel/BKE_subdiv_eval.h index 3f682716928..aa27df88be8 100644 --- a/source/blender/blenkernel/BKE_subdiv_eval.h +++ b/source/blender/blenkernel/BKE_subdiv_eval.h @@ -38,7 +38,10 @@ bool BKE_subdiv_eval_begin(struct Subdiv *subdiv); /* coarse_vertex_cos is an optional argument which allows to override coordinates of the coarse * mesh. */ -bool BKE_subdiv_eval_update_from_mesh(struct Subdiv *subdiv, +bool BKE_subdiv_eval_begin_from_mesh(struct Subdiv *subdiv, + const struct Mesh *mesh, + const float (*coarse_vertex_cos)[3]); +bool BKE_subdiv_eval_refine_from_mesh(struct Subdiv *subdiv, const struct Mesh *mesh, const float (*coarse_vertex_cos)[3]); diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 00498e30abc..20236745438 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -462,7 +462,7 @@ void BKE_tracking_get_rna_path_prefix_for_plane_track( #define MARKER_VISIBLE(sc, track, marker) \ (((marker)->flag & MARKER_DISABLED) == 0 || ((sc)->flag & SC_HIDE_DISABLED) == 0 || \ - (sc->clip->tracking.act_track == track)) + ((sc)->clip->tracking.act_track == track)) #define TRACK_CLEAR_UPTO 0 #define TRACK_CLEAR_REMAINED 1 diff --git a/source/blender/blenkernel/BKE_volume.h b/source/blender/blenkernel/BKE_volume.h index 3125ad0326e..224f3ede45d 100644 --- a/source/blender/blenkernel/BKE_volume.h +++ b/source/blender/blenkernel/BKE_volume.h @@ -85,6 +85,7 @@ bool BKE_volume_is_loaded(const struct Volume *volume); int BKE_volume_num_grids(const struct Volume *volume); const char *BKE_volume_grids_error_msg(const struct Volume *volume); +const char *BKE_volume_grids_frame_filepath(const struct Volume *volume); VolumeGrid *BKE_volume_grid_get(const struct Volume *volume, int grid_index); VolumeGrid *BKE_volume_grid_active_get(const struct Volume *volume); VolumeGrid *BKE_volume_grid_find(const struct Volume *volume, const char *name); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 7634cd082fb..f718f25ee3d 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -71,8 +71,10 @@ set(SRC intern/DerivedMesh.c intern/action.c intern/addon.c - intern/anim.c + intern/anim_data.c + intern/anim_path.c intern/anim_sys.c + intern/anim_visualization.c intern/appdir.c intern/armature.c intern/armature_update.c @@ -255,7 +257,9 @@ set(SRC BKE_DerivedMesh.h BKE_action.h BKE_addon.h - BKE_anim.h + BKE_anim_data.h + BKE_anim_path.h + BKE_anim_visualization.h BKE_animsys.h BKE_appdir.h BKE_armature.h @@ -291,6 +295,7 @@ set(SRC BKE_deform.h BKE_displist.h BKE_displist_tangent.h + BKE_duplilist.h BKE_dynamicpaint.h BKE_editlattice.h BKE_editmesh.h diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index c332939e906..478609f2f3f 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -43,7 +43,7 @@ #include "BLT_translation.h" #include "BKE_action.h" -#include "BKE_anim.h" +#include "BKE_anim_visualization.h" #include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_constraint.h" diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c new file mode 100644 index 00000000000..41bfc5b59e4 --- /dev/null +++ b/source/blender/blenkernel/intern/anim_data.c @@ -0,0 +1,1435 @@ +/* + * 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) 2009 Blender Foundation, Joshua Leung + * All rights reserved. + */ + +/** \file + * \ingroup bke + */ +#include "MEM_guardedalloc.h" + +#include <string.h> + +#include "BKE_action.h" +#include "BKE_anim_data.h" +#include "BKE_animsys.h" +#include "BKE_context.h" +#include "BKE_fcurve.h" +#include "BKE_global.h" +#include "BKE_lib_id.h" +#include "BKE_main.h" +#include "BKE_nla.h" +#include "BKE_node.h" +#include "BKE_report.h" + +#include "DNA_ID.h" +#include "DNA_anim_types.h" +#include "DNA_light_types.h" +#include "DNA_node_types.h" +#include "DNA_space_types.h" +#include "DNA_windowmanager_types.h" +#include "DNA_world_types.h" + +#include "BLI_alloca.h" +#include "BLI_dynstr.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_utildefines.h" + +#include "DEG_depsgraph.h" + +#include "RNA_access.h" + +#include "CLG_log.h" + +static CLG_LogRef LOG = {"bke.anim_sys"}; + +/* ***************************************** */ +/* AnimData API */ + +/* Getter/Setter -------------------------------------------- */ + +/* Check if ID can have AnimData */ +bool id_type_can_have_animdata(const short id_type) +{ + /* Only some ID-blocks have this info for now */ + /* TODO: finish adding this for the other blocktypes */ + switch (id_type) { + /* has AnimData */ + case ID_OB: + case ID_ME: + case ID_MB: + case ID_CU: + case ID_AR: + case ID_LT: + case ID_KE: + case ID_PA: + case ID_MA: + case ID_TE: + case ID_NT: + case ID_LA: + case ID_CA: + case ID_WO: + case ID_LS: + case ID_LP: + case ID_SPK: + case ID_SCE: + case ID_MC: + case ID_MSK: + case ID_GD: + case ID_CF: + case ID_HA: + case ID_PT: + case ID_VO: + return true; + + /* no AnimData */ + default: + return false; + } +} + +bool id_can_have_animdata(const ID *id) +{ + /* sanity check */ + if (id == NULL) { + return false; + } + + return id_type_can_have_animdata(GS(id->name)); +} + +/* Get AnimData from the given ID-block. In order for this to work, we assume that + * the AnimData pointer is stored immediately after the given ID-block in the struct, + * as per IdAdtTemplate. + */ +AnimData *BKE_animdata_from_id(ID *id) +{ + /* only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdAdtTemplate, and extract the + * AnimData that way + */ + if (id_can_have_animdata(id)) { + IdAdtTemplate *iat = (IdAdtTemplate *)id; + return iat->adt; + } + else { + return NULL; + } +} + +/* Add AnimData to the given ID-block. In order for this to work, we assume that + * the AnimData pointer is stored immediately after the given ID-block in the struct, + * as per IdAdtTemplate. Also note that + */ +AnimData *BKE_animdata_add_id(ID *id) +{ + /* Only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdAdtTemplate, and add the AnimData + * to it using the template + */ + if (id_can_have_animdata(id)) { + IdAdtTemplate *iat = (IdAdtTemplate *)id; + + /* check if there's already AnimData, in which case, don't add */ + if (iat->adt == NULL) { + AnimData *adt; + + /* add animdata */ + adt = iat->adt = MEM_callocN(sizeof(AnimData), "AnimData"); + + /* set default settings */ + adt->act_influence = 1.0f; + } + + return iat->adt; + } + else { + return NULL; + } +} + +/* Action Setter --------------------------------------- */ + +/** + * Called when user tries to change the active action of an AnimData block + * (via RNA, Outliner, etc.) + */ +bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) +{ + AnimData *adt = BKE_animdata_from_id(id); + bool ok = false; + + /* animdata validity check */ + if (adt == NULL) { + BKE_report(reports, RPT_WARNING, "No AnimData to set action on"); + return ok; + } + + /* active action is only editable when it is not a tweaking strip + * see rna_AnimData_action_editable() in rna_animation.c + */ + if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) { + /* cannot remove, otherwise things turn to custard */ + BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA"); + return ok; + } + + /* manage usercount for current action */ + if (adt->action) { + id_us_min((ID *)adt->action); + } + + /* assume that AnimData's action can in fact be edited... */ + if (act) { + /* action must have same type as owner */ + if (ELEM(act->idroot, 0, GS(id->name))) { + /* can set */ + adt->action = act; + id_us_plus((ID *)adt->action); + ok = true; + } + else { + /* cannot set */ + BKE_reportf( + reports, + RPT_ERROR, + "Could not set action '%s' onto ID '%s', as it does not have suitably rooted paths " + "for this purpose", + act->id.name + 2, + id->name); + /* ok = false; */ + } + } + else { + /* just clearing the action... */ + adt->action = NULL; + ok = true; + } + + return ok; +} + +/* Freeing -------------------------------------------- */ + +/* Free AnimData used by the nominated ID-block, and clear ID-block's AnimData pointer */ +void BKE_animdata_free(ID *id, const bool do_id_user) +{ + /* Only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdAdtTemplate + */ + if (id_can_have_animdata(id)) { + IdAdtTemplate *iat = (IdAdtTemplate *)id; + AnimData *adt = iat->adt; + + /* check if there's any AnimData to start with */ + if (adt) { + if (do_id_user) { + /* unlink action (don't free, as it's in its own list) */ + if (adt->action) { + id_us_min(&adt->action->id); + } + /* same goes for the temporarily displaced action */ + if (adt->tmpact) { + id_us_min(&adt->tmpact->id); + } + } + + /* free nla data */ + BKE_nla_tracks_free(&adt->nla_tracks, do_id_user); + + /* free drivers - stored as a list of F-Curves */ + free_fcurves(&adt->drivers); + + /* free driver array cache */ + MEM_SAFE_FREE(adt->driver_array); + + /* free overrides */ + /* TODO... */ + + /* free animdata now */ + MEM_freeN(adt); + iat->adt = NULL; + } + } +} + +bool BKE_animdata_id_is_animated(const struct ID *id) +{ + if (id == NULL) { + return false; + } + + const AnimData *adt = BKE_animdata_from_id((ID *)id); + if (adt == NULL) { + return false; + } + + if (adt->action != NULL && !BLI_listbase_is_empty(&adt->action->curves)) { + return true; + } + + return !BLI_listbase_is_empty(&adt->drivers) || !BLI_listbase_is_empty(&adt->nla_tracks) || + !BLI_listbase_is_empty(&adt->overrides); +} + +/* Copying -------------------------------------------- */ + +/** + * Make a copy of the given AnimData - to be used when copying data-blocks. + * \param flag: Control ID pointers management, + * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_lib_id.h + * \return The copied animdata. + */ +AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) +{ + AnimData *dadt; + + const bool do_action = (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0; + const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0; + + /* sanity check before duplicating struct */ + if (adt == NULL) { + return NULL; + } + dadt = MEM_dupallocN(adt); + + /* make a copy of action - at worst, user has to delete copies... */ + if (do_action) { + BLI_assert(bmain != NULL); + BLI_assert(dadt->action == NULL || dadt->action != dadt->tmpact); + BKE_id_copy_ex(bmain, (ID *)dadt->action, (ID **)&dadt->action, flag); + BKE_id_copy_ex(bmain, (ID *)dadt->tmpact, (ID **)&dadt->tmpact, flag); + } + else if (do_id_user) { + id_us_plus((ID *)dadt->action); + id_us_plus((ID *)dadt->tmpact); + } + + /* duplicate NLA data */ + BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks, flag); + + /* duplicate drivers (F-Curves) */ + copy_fcurves(&dadt->drivers, &adt->drivers); + dadt->driver_array = NULL; + + /* don't copy overrides */ + BLI_listbase_clear(&dadt->overrides); + + /* return */ + return dadt; +} + +/** + * \param flag: Control ID pointers management, + * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_lib_id.h + * \return true is successfully copied. + */ +bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) +{ + AnimData *adt; + + if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name))) { + return false; + } + + BKE_animdata_free(id_to, (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0); + + adt = BKE_animdata_from_id(id_from); + if (adt) { + IdAdtTemplate *iat = (IdAdtTemplate *)id_to; + iat->adt = BKE_animdata_copy(bmain, adt, flag); + } + + return true; +} + +void BKE_animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid) +{ + AnimData *adt = BKE_animdata_from_id(id); + if (adt) { + if (adt->action) { + id_us_min((ID *)adt->action); + adt->action = set_newid ? ID_NEW_SET(adt->action, BKE_action_copy(bmain, adt->action)) : + BKE_action_copy(bmain, adt->action); + } + if (adt->tmpact) { + id_us_min((ID *)adt->tmpact); + adt->tmpact = set_newid ? ID_NEW_SET(adt->tmpact, BKE_action_copy(bmain, adt->tmpact)) : + BKE_action_copy(bmain, adt->tmpact); + } + } + bNodeTree *ntree = ntreeFromID(id); + if (ntree) { + BKE_animdata_copy_id_action(bmain, &ntree->id, set_newid); + } +} + +/* Merge copies of the data from the src AnimData into the destination AnimData */ +void BKE_animdata_merge_copy( + Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers) +{ + AnimData *src = BKE_animdata_from_id(src_id); + AnimData *dst = BKE_animdata_from_id(dst_id); + + /* sanity checks */ + if (ELEM(NULL, dst, src)) { + return; + } + + // TODO: we must unset all "tweakmode" flags + if ((src->flag & ADT_NLA_EDIT_ON) || (dst->flag & ADT_NLA_EDIT_ON)) { + CLOG_ERROR( + &LOG, + "Merging AnimData blocks while editing NLA is dangerous as it may cause data corruption"); + return; + } + + /* handle actions... */ + if (action_mode == ADT_MERGECOPY_SRC_COPY) { + /* make a copy of the actions */ + dst->action = BKE_action_copy(bmain, src->action); + dst->tmpact = BKE_action_copy(bmain, src->tmpact); + } + else if (action_mode == ADT_MERGECOPY_SRC_REF) { + /* make a reference to it */ + dst->action = src->action; + id_us_plus((ID *)dst->action); + + dst->tmpact = src->tmpact; + id_us_plus((ID *)dst->tmpact); + } + + /* duplicate NLA data */ + if (src->nla_tracks.first) { + ListBase tracks = {NULL, NULL}; + + BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks, 0); + BLI_movelisttolist(&dst->nla_tracks, &tracks); + } + + /* duplicate drivers (F-Curves) */ + if (src->drivers.first) { + ListBase drivers = {NULL, NULL}; + + copy_fcurves(&drivers, &src->drivers); + + /* Fix up all driver targets using the old target id + * - This assumes that the src ID is being merged into the dst ID + */ + if (fix_drivers) { + FCurve *fcu; + + for (fcu = drivers.first; fcu; fcu = fcu->next) { + ChannelDriver *driver = fcu->driver; + DriverVar *dvar; + + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { + DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { + if (dtar->id == src_id) { + dtar->id = dst_id; + } + } + DRIVER_TARGETS_LOOPER_END; + } + } + } + + BLI_movelisttolist(&dst->drivers, &drivers); + } +} + +/* Sub-ID Regrouping ------------------------------------------- */ + +/** + * Helper heuristic for determining if a path is compatible with the basepath + * + * \param path: Full RNA-path from some data (usually an F-Curve) to compare + * \param basepath: Shorter path fragment to look for + * \return Whether there is a match + */ +static bool animpath_matches_basepath(const char path[], const char basepath[]) +{ + /* we need start of path to be basepath */ + return (path && basepath) && STRPREFIX(path, basepath); +} + +/* Move F-Curves in src action to dst action, setting up all the necessary groups + * for this to happen, but only if the F-Curves being moved have the appropriate + * "base path". + * - This is used when data moves from one data-block to another, causing the + * F-Curves to need to be moved over too + */ +void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const char basepath[]) +{ + FCurve *fcu, *fcn = NULL; + + /* sanity checks */ + if (ELEM(NULL, srcAct, dstAct, basepath)) { + if (G.debug & G_DEBUG) { + CLOG_ERROR(&LOG, + "srcAct: %p, dstAct: %p, basepath: %p has insufficient info to work with", + (void *)srcAct, + (void *)dstAct, + (void *)basepath); + } + return; + } + + /* clear 'temp' flags on all groups in src, as we'll be needing them later + * to identify groups that we've managed to empty out here + */ + action_groups_clear_tempflags(srcAct); + + /* iterate over all src F-Curves, moving over the ones that need to be moved */ + for (fcu = srcAct->curves.first; fcu; fcu = fcn) { + /* store next pointer in case we move stuff */ + fcn = fcu->next; + + /* should F-Curve be moved over? + * - we only need the start of the path to match basepath + */ + if (animpath_matches_basepath(fcu->rna_path, basepath)) { + bActionGroup *agrp = NULL; + + /* if grouped... */ + if (fcu->grp) { + /* make sure there will be a matching group on the other side for the migrants */ + agrp = BKE_action_group_find_name(dstAct, fcu->grp->name); + + if (agrp == NULL) { + /* add a new one with a similar name (usually will be the same though) */ + agrp = action_groups_add_new(dstAct, fcu->grp->name); + } + + /* old groups should be tagged with 'temp' flags so they can be removed later + * if we remove everything from them + */ + fcu->grp->flag |= AGRP_TEMP; + } + + /* perform the migration now */ + action_groups_remove_channel(srcAct, fcu); + + if (agrp) { + action_groups_add_channel(dstAct, agrp, fcu); + } + else { + BLI_addtail(&dstAct->curves, fcu); + } + } + } + + /* cleanup groups (if present) */ + if (srcAct->groups.first) { + bActionGroup *agrp, *grp = NULL; + + for (agrp = srcAct->groups.first; agrp; agrp = grp) { + grp = agrp->next; + + /* only tagged groups need to be considered - clearing these tags or removing them */ + if (agrp->flag & AGRP_TEMP) { + /* if group is empty and tagged, then we can remove as this operation + * moved out all the channels that were formerly here + */ + if (BLI_listbase_is_empty(&agrp->channels)) { + BLI_freelinkN(&srcAct->groups, agrp); + } + else { + agrp->flag &= ~AGRP_TEMP; + } + } + } + } +} + +/* Transfer the animation data from srcID to dstID where the srcID + * animation data is based off "basepath", creating new AnimData and + * associated data as necessary + */ +void BKE_animdata_separate_by_basepath(Main *bmain, ID *srcID, ID *dstID, ListBase *basepaths) +{ + AnimData *srcAdt = NULL, *dstAdt = NULL; + LinkData *ld; + + /* sanity checks */ + if (ELEM(NULL, srcID, dstID)) { + if (G.debug & G_DEBUG) { + CLOG_ERROR(&LOG, "no source or destination ID to separate AnimData with"); + } + return; + } + + /* get animdata from src, and create for destination (if needed) */ + srcAdt = BKE_animdata_from_id(srcID); + dstAdt = BKE_animdata_add_id(dstID); + + if (ELEM(NULL, srcAdt, dstAdt)) { + if (G.debug & G_DEBUG) { + CLOG_ERROR(&LOG, "no AnimData for this pair of ID's"); + } + return; + } + + /* active action */ + if (srcAdt->action) { + /* Set up an action if necessary, + * and name it in a similar way so that it can be easily found again. */ + if (dstAdt->action == NULL) { + dstAdt->action = BKE_action_add(bmain, srcAdt->action->id.name + 2); + } + else if (dstAdt->action == srcAdt->action) { + CLOG_WARN(&LOG, + "Argh! Source and Destination share animation! " + "('%s' and '%s' both use '%s') Making new empty action", + srcID->name, + dstID->name, + srcAdt->action->id.name); + + /* TODO: review this... */ + id_us_min(&dstAdt->action->id); + dstAdt->action = BKE_action_add(bmain, dstAdt->action->id.name + 2); + } + + /* loop over base paths, trying to fix for each one... */ + for (ld = basepaths->first; ld; ld = ld->next) { + const char *basepath = (const char *)ld->data; + action_move_fcurves_by_basepath(srcAdt->action, dstAdt->action, basepath); + } + } + + /* drivers */ + if (srcAdt->drivers.first) { + FCurve *fcu, *fcn = NULL; + + /* check each driver against all the base paths to see if any should go */ + for (fcu = srcAdt->drivers.first; fcu; fcu = fcn) { + fcn = fcu->next; + + /* try each basepath in turn, but stop on the first one which works */ + for (ld = basepaths->first; ld; ld = ld->next) { + const char *basepath = (const char *)ld->data; + + if (animpath_matches_basepath(fcu->rna_path, basepath)) { + /* just need to change lists */ + BLI_remlink(&srcAdt->drivers, fcu); + BLI_addtail(&dstAdt->drivers, fcu); + + /* TODO: add depsgraph flushing calls? */ + + /* can stop now, as moved already */ + break; + } + } + } + } +} + +/** + * Temporary wrapper for driver operators for buttons to make it easier to create + * such drivers by rerouting all paths through the active object instead so that + * they will get picked up by the dependency system. + * + * \param C: Context pointer - for getting active data + * \param[in,out] ptr: RNA pointer for property's data-block. + * May be modified as result of path remapping. + * \param prop: RNA definition of property to add for + * \return MEM_alloc'd string representing the path to the property from the given #PointerRNA + */ +char *BKE_animdata_driver_path_hack(bContext *C, + PointerRNA *ptr, + PropertyRNA *prop, + char *base_path) +{ + ID *id = ptr->owner_id; + ScrArea *area = CTX_wm_area(C); + + /* get standard path which may be extended */ + char *basepath = base_path ? base_path : RNA_path_from_ID_to_property(ptr, prop); + char *path = basepath; /* in case no remapping is needed */ + + /* Remapping will only be performed in the Properties Editor, as only this + * restricts the subspace of options to the 'active' data (a manageable state) + */ + /* TODO: watch out for pinned context? */ + if ((area) && (area->spacetype == SPACE_PROPERTIES)) { + Object *ob = CTX_data_active_object(C); + + if (ob && id) { + /* TODO: after material textures were removed, this function serves + * no purpose anymore, but could be used again so was not removed. */ + + /* fix RNA pointer, as we've now changed the ID root by changing the paths */ + if (basepath != path) { + /* rebase provided pointer so that it starts from object... */ + RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr); + } + } + } + + /* the path should now have been corrected for use */ + return path; +} + +/* 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 bool check_rna_path_is_valid(ID *owner_id, const char *path) +{ + PointerRNA id_ptr, ptr; + PropertyRNA *prop = NULL; + + /* make initial RNA pointer to start resolving from */ + RNA_id_pointer_create(owner_id, &id_ptr); + + /* try to resolve */ + return RNA_path_resolve_property(&id_ptr, path, &ptr, &prop); +} + +/* 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, + const char *oldName, + const char *newName, + char *oldpath, + bool verify_paths) +{ + char *prefixPtr = strstr(oldpath, prefix); + char *oldNamePtr = strstr(oldpath, oldName); + int prefixLen = strlen(prefix); + int oldNameLen = strlen(oldName); + + /* only start fixing the path if the prefix and oldName feature in the path, + * and prefix occurs immediately before oldName + */ + if ((prefixPtr && oldNamePtr) && (prefixPtr + prefixLen == oldNamePtr)) { + /* if we haven't aren't able to resolve the path now, try again after fixing it */ + if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) { + DynStr *ds = BLI_dynstr_new(); + const char *postfixPtr = oldNamePtr + oldNameLen; + char *newPath = NULL; + + /* add the part of the string that goes up to the start of the prefix */ + if (prefixPtr > oldpath) { + BLI_dynstr_nappend(ds, oldpath, prefixPtr - oldpath); + } + + /* add the prefix */ + BLI_dynstr_append(ds, prefix); + + /* add the new name (complete with brackets) */ + BLI_dynstr_append(ds, newName); + + /* add the postfix */ + BLI_dynstr_append(ds, postfixPtr); + + /* create new path, and cleanup old data */ + newPath = BLI_dynstr_get_cstring(ds); + BLI_dynstr_free(ds); + + /* check if the new path will solve our problems */ + /* TODO: will need to check whether this step really helps in practice */ + if (!verify_paths || check_rna_path_is_valid(owner_id, newPath)) { + /* free the old path, and return the new one, since we've solved the issues */ + MEM_freeN(oldpath); + return newPath; + } + else { + /* still couldn't resolve the path... so, might as well just leave it alone */ + MEM_freeN(newPath); + } + } + } + + /* the old path doesn't need to be changed */ + return oldpath; +} + +/* Check RNA-Paths for a list of F-Curves */ +static bool fcurves_path_rename_fix(ID *owner_id, + const char *prefix, + const char *oldName, + const char *newName, + const char *oldKey, + const char *newKey, + ListBase *curves, + bool verify_paths) +{ + FCurve *fcu; + bool is_changed = false; + /* We need to check every curve. */ + for (fcu = curves->first; fcu; fcu = fcu->next) { + if (fcu->rna_path == NULL) { + continue; + } + const char *old_path = fcu->rna_path; + /* Firstly, handle the F-Curve's own path. */ + fcu->rna_path = rna_path_rename_fix( + owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + /* if path changed and the F-Curve is grouped, check if its group also needs renaming + * (i.e. F-Curve is first of a bone's F-Curves; + * hence renaming this should also trigger rename) */ + if (fcu->rna_path != old_path) { + bActionGroup *agrp = fcu->grp; + is_changed = true; + if ((agrp != NULL) && STREQ(oldName, agrp->name)) { + BLI_strncpy(agrp->name, newName, sizeof(agrp->name)); + } + } + } + return is_changed; +} + +/* Check RNA-Paths for a list of Drivers */ +static bool drivers_path_rename_fix(ID *owner_id, + ID *ref_id, + const char *prefix, + const char *oldName, + const char *newName, + const char *oldKey, + const char *newKey, + ListBase *curves, + bool verify_paths) +{ + bool is_changed = false; + FCurve *fcu; + /* We need to check every curve - drivers are F-Curves too. */ + for (fcu = curves->first; fcu; fcu = fcu->next) { + /* firstly, handle the F-Curve's own path */ + if (fcu->rna_path != NULL) { + const char *old_rna_path = fcu->rna_path; + fcu->rna_path = rna_path_rename_fix( + owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); + is_changed |= (fcu->rna_path != old_rna_path); + } + if (fcu->driver == NULL) { + continue; + } + ChannelDriver *driver = fcu->driver; + DriverVar *dvar; + /* driver variables */ + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { + /* only change the used targets, since the others will need fixing manually anyway */ + DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { + /* rename RNA path */ + if (dtar->rna_path && dtar->id) { + const char *old_rna_path = dtar->rna_path; + dtar->rna_path = rna_path_rename_fix( + dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths); + is_changed |= (dtar->rna_path != old_rna_path); + } + /* also fix the bone-name (if applicable) */ + if (strstr(prefix, "bones")) { + if (((dtar->id) && (GS(dtar->id->name) == ID_OB) && + (!ref_id || ((Object *)(dtar->id))->data == ref_id)) && + (dtar->pchan_name[0]) && STREQ(oldName, dtar->pchan_name)) { + is_changed = true; + BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name)); + } + } + } + DRIVER_TARGETS_LOOPER_END; + } + } + return is_changed; +} + +/* Fix all RNA-Paths for Actions linked to NLA Strips */ +static bool nlastrips_path_rename_fix(ID *owner_id, + const char *prefix, + const char *oldName, + const char *newName, + const char *oldKey, + const char *newKey, + ListBase *strips, + bool verify_paths) +{ + NlaStrip *strip; + bool is_changed = false; + /* Recursively check strips, fixing only actions. */ + for (strip = strips->first; strip; strip = strip->next) { + /* fix strip's action */ + if (strip->act != NULL) { + is_changed |= fcurves_path_rename_fix( + owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths); + } + /* Ignore own F-Curves, since those are local. */ + /* Check sub-strips (if metas) */ + is_changed |= nlastrips_path_rename_fix( + owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths); + } + return is_changed; +} + +/* Rename Sub-ID Entities in RNA Paths ----------------------- */ + +/* Fix up the given RNA-Path + * + * This is just an external wrapper for the RNA-Path fixing function, + * with input validity checks on top of the basic method. + * + * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> + * i.e. pose.bones["Bone"] + */ +char *BKE_animsys_fix_rna_path_rename(ID *owner_id, + char *old_path, + const char *prefix, + const char *oldName, + const char *newName, + int oldSubscript, + int newSubscript, + bool verify_paths) +{ + char *oldN, *newN; + char *result; + + /* if no action, no need to proceed */ + if (ELEM(NULL, owner_id, old_path)) { + if (G.debug & G_DEBUG) { + CLOG_WARN(&LOG, "early abort"); + } + return old_path; + } + + /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ + if ((oldName != NULL) && (newName != NULL)) { + /* pad the names with [" "] so that only exact matches are made */ + const size_t name_old_len = strlen(oldName); + const size_t name_new_len = strlen(newName); + char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); + char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); + + BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); + BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); + oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); + newN = BLI_sprintfN("[\"%s\"]", name_new_esc); + } + else { + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); + } + + /* fix given path */ + if (G.debug & G_DEBUG) { + printf("%s | %s | oldpath = %p ", oldN, newN, old_path); + } + result = rna_path_rename_fix(owner_id, prefix, oldN, newN, old_path, verify_paths); + if (G.debug & G_DEBUG) { + printf("path rename result = %p\n", result); + } + + /* free the temp names */ + MEM_freeN(oldN); + MEM_freeN(newN); + + /* return the resulting path - may be the same path again if nothing changed */ + return result; +} + +/* Fix all RNA_Paths in the given Action, relative to the given ID block + * + * This is just an external wrapper for the F-Curve fixing function, + * with input validity checks on top of the basic method. + * + * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> + * i.e. pose.bones["Bone"] + */ +void BKE_action_fix_paths_rename(ID *owner_id, + bAction *act, + const char *prefix, + const char *oldName, + const char *newName, + int oldSubscript, + int newSubscript, + bool verify_paths) +{ + char *oldN, *newN; + + /* if no action, no need to proceed */ + if (ELEM(NULL, owner_id, act)) { + return; + } + + /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ + if ((oldName != NULL) && (newName != NULL)) { + /* pad the names with [" "] so that only exact matches are made */ + const size_t name_old_len = strlen(oldName); + const size_t name_new_len = strlen(newName); + char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); + char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); + + BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); + BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); + oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); + newN = BLI_sprintfN("[\"%s\"]", name_new_esc); + } + else { + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); + } + + /* fix paths in action */ + fcurves_path_rename_fix( + owner_id, prefix, oldName, newName, oldN, newN, &act->curves, verify_paths); + + /* free the temp names */ + MEM_freeN(oldN); + MEM_freeN(newN); +} + +/* Fix all RNA-Paths in the AnimData block used by the given ID block + * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> + * i.e. pose.bones["Bone"] + */ +void BKE_animdata_fix_paths_rename(ID *owner_id, + AnimData *adt, + ID *ref_id, + const char *prefix, + const char *oldName, + const char *newName, + int oldSubscript, + int newSubscript, + bool verify_paths) +{ + NlaTrack *nlt; + char *oldN, *newN; + /* If no AnimData, no need to proceed. */ + if (ELEM(NULL, owner_id, adt)) { + return; + } + bool is_self_changed = false; + /* Name sanitation logic - shared with BKE_action_fix_paths_rename(). */ + if ((oldName != NULL) && (newName != NULL)) { + /* Pad the names with [" "] so that only exact matches are made. */ + const size_t name_old_len = strlen(oldName); + const size_t name_new_len = strlen(newName); + char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); + char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); + + BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); + BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); + oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); + newN = BLI_sprintfN("[\"%s\"]", name_new_esc); + } + else { + oldN = BLI_sprintfN("[%d]", oldSubscript); + newN = BLI_sprintfN("[%d]", newSubscript); + } + /* Active action and temp action. */ + if (adt->action != NULL) { + if (fcurves_path_rename_fix( + owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths)) { + DEG_id_tag_update(&adt->action->id, ID_RECALC_COPY_ON_WRITE); + } + } + if (adt->tmpact) { + if (fcurves_path_rename_fix( + owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths)) { + DEG_id_tag_update(&adt->tmpact->id, ID_RECALC_COPY_ON_WRITE); + } + } + /* Drivers - Drivers are really F-Curves */ + is_self_changed |= drivers_path_rename_fix( + owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); + /* NLA Data - Animation Data for Strips */ + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + is_self_changed |= nlastrips_path_rename_fix( + owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); + } + /* Tag owner ID if it */ + if (is_self_changed) { + DEG_id_tag_update(owner_id, ID_RECALC_COPY_ON_WRITE); + } + /* free the temp names */ + MEM_freeN(oldN); + MEM_freeN(newN); +} + +/* Remove FCurves with Prefix -------------------------------------- */ + +/* Check RNA-Paths for a list of F-Curves */ +static bool fcurves_path_remove_fix(const char *prefix, ListBase *curves) +{ + FCurve *fcu, *fcn; + bool any_removed = false; + if (!prefix) { + return any_removed; + } + + /* we need to check every curve... */ + for (fcu = curves->first; fcu; fcu = fcn) { + fcn = fcu->next; + + if (fcu->rna_path) { + if (STRPREFIX(fcu->rna_path, prefix)) { + BLI_remlink(curves, fcu); + free_fcurve(fcu); + any_removed = true; + } + } + } + return any_removed; +} + +/* Check RNA-Paths for a list of F-Curves */ +static bool nlastrips_path_remove_fix(const char *prefix, ListBase *strips) +{ + NlaStrip *strip; + bool any_removed = false; + + /* recursively check strips, fixing only actions... */ + for (strip = strips->first; strip; strip = strip->next) { + /* fix strip's action */ + if (strip->act) { + any_removed |= fcurves_path_remove_fix(prefix, &strip->act->curves); + } + + /* check sub-strips (if metas) */ + any_removed |= nlastrips_path_remove_fix(prefix, &strip->strips); + } + return any_removed; +} + +bool BKE_animdata_fix_paths_remove(ID *id, const char *prefix) +{ + /* Only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdAdtTemplate + */ + if (!id_can_have_animdata(id)) { + return false; + } + bool any_removed = false; + IdAdtTemplate *iat = (IdAdtTemplate *)id; + AnimData *adt = iat->adt; + /* check if there's any AnimData to start with */ + if (adt) { + /* free fcurves */ + if (adt->action != NULL) { + any_removed |= fcurves_path_remove_fix(prefix, &adt->action->curves); + } + if (adt->tmpact != NULL) { + any_removed |= fcurves_path_remove_fix(prefix, &adt->tmpact->curves); + } + /* free drivers - stored as a list of F-Curves */ + any_removed |= fcurves_path_remove_fix(prefix, &adt->drivers); + /* NLA Data - Animation Data for Strips */ + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { + any_removed |= nlastrips_path_remove_fix(prefix, &nlt->strips); + } + } + return any_removed; +} + +/* Apply Op to All FCurves in Database --------------------------- */ + +/* "User-Data" wrapper used by BKE_fcurves_main_cb() */ +typedef struct AllFCurvesCbWrapper { + ID_FCurve_Edit_Callback func; /* Operation to apply on F-Curve */ + void *user_data; /* Custom data for that operation */ +} AllFCurvesCbWrapper; + +/* Helper for adt_apply_all_fcurves_cb() - Apply wrapped operator to list of F-Curves */ +static void fcurves_apply_cb(ID *id, + ListBase *fcurves, + ID_FCurve_Edit_Callback func, + void *user_data) +{ + FCurve *fcu; + + for (fcu = fcurves->first; fcu; fcu = fcu->next) { + func(id, fcu, user_data); + } +} + +/* Helper for adt_apply_all_fcurves_cb() - Recursively go through each NLA strip */ +static void nlastrips_apply_all_curves_cb(ID *id, ListBase *strips, AllFCurvesCbWrapper *wrapper) +{ + NlaStrip *strip; + + for (strip = strips->first; strip; strip = strip->next) { + /* fix strip's action */ + if (strip->act) { + fcurves_apply_cb(id, &strip->act->curves, wrapper->func, wrapper->user_data); + } + + /* check sub-strips (if metas) */ + nlastrips_apply_all_curves_cb(id, &strip->strips, wrapper); + } +} + +/* Helper for BKE_fcurves_main_cb() - Dispatch wrapped operator to all F-Curves */ +static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, void *wrapper_data) +{ + AllFCurvesCbWrapper *wrapper = wrapper_data; + NlaTrack *nlt; + + if (adt->action) { + fcurves_apply_cb(id, &adt->action->curves, wrapper->func, wrapper->user_data); + } + + if (adt->tmpact) { + fcurves_apply_cb(id, &adt->tmpact->curves, wrapper->func, wrapper->user_data); + } + + /* free drivers - stored as a list of F-Curves */ + fcurves_apply_cb(id, &adt->drivers, wrapper->func, wrapper->user_data); + + /* NLA Data - Animation Data for Strips */ + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + nlastrips_apply_all_curves_cb(id, &nlt->strips, wrapper); + } +} + +void BKE_fcurves_id_cb(ID *id, ID_FCurve_Edit_Callback func, void *user_data) +{ + AnimData *adt = BKE_animdata_from_id(id); + if (adt != NULL) { + AllFCurvesCbWrapper wrapper = {func, user_data}; + adt_apply_all_fcurves_cb(id, adt, &wrapper); + } +} + +/* apply the given callback function on all F-Curves attached to data in main database */ +void BKE_fcurves_main_cb(Main *bmain, ID_FCurve_Edit_Callback func, void *user_data) +{ + /* Wrap F-Curve operation stuff to pass to the general AnimData-level func */ + AllFCurvesCbWrapper wrapper = {func, user_data}; + + /* Use the AnimData-based function so that we don't have to reimplement all that stuff */ + BKE_animdata_main_cb(bmain, adt_apply_all_fcurves_cb, &wrapper); +} + +/* Whole Database Ops -------------------------------------------- */ + +/* apply the given callback function on all data in main database */ +void BKE_animdata_main_cb(Main *bmain, ID_AnimData_Edit_Callback func, void *user_data) +{ + ID *id; + + /* standard data version */ +#define ANIMDATA_IDS_CB(first) \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + if (adt) \ + func(id, adt, user_data); \ + } \ + (void)0 + + /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */ +#define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + NtId_Type *ntp = (NtId_Type *)id; \ + if (ntp->nodetree) { \ + AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ + if (adt2) \ + func(id, adt2, user_data); \ + } \ + if (adt) \ + func(id, adt, user_data); \ + } \ + (void)0 + + /* nodes */ + ANIMDATA_IDS_CB(bmain->nodetrees.first); + + /* textures */ + ANIMDATA_NODETREE_IDS_CB(bmain->textures.first, Tex); + + /* lights */ + ANIMDATA_NODETREE_IDS_CB(bmain->lights.first, Light); + + /* materials */ + ANIMDATA_NODETREE_IDS_CB(bmain->materials.first, Material); + + /* cameras */ + ANIMDATA_IDS_CB(bmain->cameras.first); + + /* shapekeys */ + ANIMDATA_IDS_CB(bmain->shapekeys.first); + + /* metaballs */ + ANIMDATA_IDS_CB(bmain->metaballs.first); + + /* curves */ + ANIMDATA_IDS_CB(bmain->curves.first); + + /* armatures */ + ANIMDATA_IDS_CB(bmain->armatures.first); + + /* lattices */ + ANIMDATA_IDS_CB(bmain->lattices.first); + + /* meshes */ + ANIMDATA_IDS_CB(bmain->meshes.first); + + /* particles */ + ANIMDATA_IDS_CB(bmain->particles.first); + + /* speakers */ + ANIMDATA_IDS_CB(bmain->speakers.first); + + /* movie clips */ + ANIMDATA_IDS_CB(bmain->movieclips.first); + + /* objects */ + ANIMDATA_IDS_CB(bmain->objects.first); + + /* masks */ + ANIMDATA_IDS_CB(bmain->masks.first); + + /* worlds */ + ANIMDATA_NODETREE_IDS_CB(bmain->worlds.first, World); + + /* scenes */ + ANIMDATA_NODETREE_IDS_CB(bmain->scenes.first, Scene); + + /* line styles */ + ANIMDATA_IDS_CB(bmain->linestyles.first); + + /* grease pencil */ + ANIMDATA_IDS_CB(bmain->gpencils.first); + + /* palettes */ + ANIMDATA_IDS_CB(bmain->palettes.first); + + /* cache files */ + ANIMDATA_IDS_CB(bmain->cachefiles.first); + + /* hairs */ + ANIMDATA_IDS_CB(bmain->hairs.first); + + /* pointclouds */ + ANIMDATA_IDS_CB(bmain->pointclouds.first); + + /* volumes */ + ANIMDATA_IDS_CB(bmain->volumes.first); +} + +/* Fix all RNA-Paths throughout the database (directly access the Global.main version) + * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> + * i.e. pose.bones["Bone"] + */ +/* TODO: use BKE_animdata_main_cb for looping over all data */ +void BKE_animdata_fix_paths_rename_all(ID *ref_id, + const char *prefix, + const char *oldName, + const char *newName) +{ + Main *bmain = G.main; /* XXX UGLY! */ + ID *id; + + /* macro for less typing + * - whether animdata exists is checked for by the main renaming callback, though taking + * this outside of the function may make things slightly faster? + */ +#define RENAMEFIX_ANIM_IDS(first) \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ + } \ + (void)0 + + /* another version of this macro for nodetrees */ +#define RENAMEFIX_ANIM_NODETREE_IDS(first, NtId_Type) \ + for (id = first; id; id = id->next) { \ + AnimData *adt = BKE_animdata_from_id(id); \ + NtId_Type *ntp = (NtId_Type *)id; \ + if (ntp->nodetree) { \ + AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ + BKE_animdata_fix_paths_rename( \ + (ID *)ntp->nodetree, adt2, ref_id, prefix, oldName, newName, 0, 0, 1); \ + } \ + BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ + } \ + (void)0 + + /* nodes */ + RENAMEFIX_ANIM_IDS(bmain->nodetrees.first); + + /* textures */ + RENAMEFIX_ANIM_NODETREE_IDS(bmain->textures.first, Tex); + + /* lights */ + RENAMEFIX_ANIM_NODETREE_IDS(bmain->lights.first, Light); + + /* materials */ + RENAMEFIX_ANIM_NODETREE_IDS(bmain->materials.first, Material); + + /* cameras */ + RENAMEFIX_ANIM_IDS(bmain->cameras.first); + + /* shapekeys */ + RENAMEFIX_ANIM_IDS(bmain->shapekeys.first); + + /* metaballs */ + RENAMEFIX_ANIM_IDS(bmain->metaballs.first); + + /* curves */ + RENAMEFIX_ANIM_IDS(bmain->curves.first); + + /* armatures */ + RENAMEFIX_ANIM_IDS(bmain->armatures.first); + + /* lattices */ + RENAMEFIX_ANIM_IDS(bmain->lattices.first); + + /* meshes */ + RENAMEFIX_ANIM_IDS(bmain->meshes.first); + + /* particles */ + RENAMEFIX_ANIM_IDS(bmain->particles.first); + + /* speakers */ + RENAMEFIX_ANIM_IDS(bmain->speakers.first); + + /* movie clips */ + RENAMEFIX_ANIM_IDS(bmain->movieclips.first); + + /* objects */ + RENAMEFIX_ANIM_IDS(bmain->objects.first); + + /* masks */ + RENAMEFIX_ANIM_IDS(bmain->masks.first); + + /* worlds */ + RENAMEFIX_ANIM_NODETREE_IDS(bmain->worlds.first, World); + + /* linestyles */ + RENAMEFIX_ANIM_IDS(bmain->linestyles.first); + + /* grease pencil */ + RENAMEFIX_ANIM_IDS(bmain->gpencils.first); + + /* cache files */ + RENAMEFIX_ANIM_IDS(bmain->cachefiles.first); + + /* hairs */ + RENAMEFIX_ANIM_IDS(bmain->hairs.first); + + /* pointclouds */ + RENAMEFIX_ANIM_IDS(bmain->pointclouds.first); + + /* volumes */ + RENAMEFIX_ANIM_IDS(bmain->volumes.first); + + /* scenes */ + RENAMEFIX_ANIM_NODETREE_IDS(bmain->scenes.first, Scene); +} diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim_path.c index 8804e7ae26c..e073bd6fc82 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim_path.c @@ -23,236 +23,22 @@ #include "MEM_guardedalloc.h" -#include <stdlib.h> +#include <float.h> -#include "BLI_dlrbTree.h" -#include "BLI_listbase.h" -#include "BLI_math.h" - -#include "BLT_translation.h" - -#include "DNA_anim_types.h" -#include "DNA_armature_types.h" +#include "DNA_curve_types.h" #include "DNA_key_types.h" -#include "DNA_scene_types.h" +#include "DNA_object_types.h" + +#include "BLI_math_vector.h" -#include "BKE_action.h" -#include "BKE_anim.h" -#include "BKE_animsys.h" +#include "BKE_anim_path.h" #include "BKE_curve.h" #include "BKE_key.h" -#include "BKE_main.h" -#include "BKE_object.h" -#include "BKE_particle.h" -#include "BKE_report.h" -#include "BKE_scene.h" - -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_build.h" -#include "DEG_depsgraph_query.h" - -#include "GPU_batch.h" #include "CLG_log.h" static CLG_LogRef LOG = {"bke.anim"}; -/* --------------------- */ -/* forward declarations */ - -/* ******************************************************************** */ -/* Animation Visualization */ - -/* Initialize the default settings for animation visualization */ -void animviz_settings_init(bAnimVizSettings *avs) -{ - /* sanity check */ - if (avs == NULL) { - return; - } - - /* path settings */ - avs->path_bc = avs->path_ac = 10; - - avs->path_sf = 1; /* xxx - take from scene instead? */ - avs->path_ef = 250; /* xxx - take from scene instead? */ - - avs->path_viewflag = (MOTIONPATH_VIEW_KFRAS | MOTIONPATH_VIEW_KFNOS); - - avs->path_step = 1; - - avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS; -} - -/* ------------------- */ - -/* Free the given motion path's cache */ -void animviz_free_motionpath_cache(bMotionPath *mpath) -{ - /* sanity check */ - if (mpath == NULL) { - return; - } - - /* free the path if necessary */ - if (mpath->points) { - MEM_freeN(mpath->points); - } - - GPU_VERTBUF_DISCARD_SAFE(mpath->points_vbo); - GPU_BATCH_DISCARD_SAFE(mpath->batch_line); - GPU_BATCH_DISCARD_SAFE(mpath->batch_points); - - /* reset the relevant parameters */ - mpath->points = NULL; - mpath->length = 0; -} - -/* Free the given motion path instance and its data - * NOTE: this frees the motion path given! - */ -void animviz_free_motionpath(bMotionPath *mpath) -{ - /* sanity check */ - if (mpath == NULL) { - return; - } - - /* free the cache first */ - animviz_free_motionpath_cache(mpath); - - /* now the instance itself */ - MEM_freeN(mpath); -} - -/* ------------------- */ - -/* Make a copy of motionpath data, so that viewing with copy on write works */ -bMotionPath *animviz_copy_motionpath(const bMotionPath *mpath_src) -{ - bMotionPath *mpath_dst; - - if (mpath_src == NULL) { - return NULL; - } - - mpath_dst = MEM_dupallocN(mpath_src); - mpath_dst->points = MEM_dupallocN(mpath_src->points); - - /* should get recreated on draw... */ - mpath_dst->points_vbo = NULL; - mpath_dst->batch_line = NULL; - mpath_dst->batch_points = NULL; - - return mpath_dst; -} - -/* ------------------- */ - -/** - * Setup motion paths for the given data. - * \note Only used when explicitly calculating paths on bones which may/may not be consider already - * - * \param scene: Current scene (for frame ranges, etc.) - * \param ob: Object to add paths for (must be provided) - * \param pchan: Posechannel to add paths for (optional; if not provided, object-paths are assumed) - */ -bMotionPath *animviz_verify_motionpaths(ReportList *reports, - Scene *scene, - Object *ob, - bPoseChannel *pchan) -{ - bAnimVizSettings *avs; - bMotionPath *mpath, **dst; - - /* sanity checks */ - if (ELEM(NULL, scene, ob)) { - return NULL; - } - - /* get destination data */ - if (pchan) { - /* paths for posechannel - assume that posechannel belongs to the object */ - avs = &ob->pose->avs; - dst = &pchan->mpath; - } - else { - /* paths for object */ - avs = &ob->avs; - dst = &ob->mpath; - } - - /* avoid 0 size allocs */ - if (avs->path_sf >= avs->path_ef) { - BKE_reportf(reports, - RPT_ERROR, - "Motion path frame extents invalid for %s (%d to %d)%s", - (pchan) ? pchan->name : ob->id.name, - avs->path_sf, - avs->path_ef, - (avs->path_sf == avs->path_ef) ? TIP_(", cannot have single-frame paths") : ""); - return NULL; - } - - /* if there is already a motionpath, just return that, - * provided it's settings are ok (saves extra free+alloc) - */ - if (*dst != NULL) { - int expected_length = avs->path_ef - avs->path_sf; - - mpath = *dst; - - /* Path is "valid" if length is valid, - * but must also be of the same length as is being requested. */ - if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0)) { - /* outer check ensures that we have some curve data for this path */ - if (mpath->length == expected_length) { - /* return/use this as it is already valid length */ - return mpath; - } - else { - /* clear the existing path (as the range has changed), and reallocate below */ - animviz_free_motionpath_cache(mpath); - } - } - } - else { - /* create a new motionpath, and assign it */ - mpath = MEM_callocN(sizeof(bMotionPath), "bMotionPath"); - *dst = mpath; - } - - /* set settings from the viz settings */ - mpath->start_frame = avs->path_sf; - mpath->end_frame = avs->path_ef; - - mpath->length = mpath->end_frame - mpath->start_frame; - - if (avs->path_bakeflag & MOTIONPATH_BAKE_HEADS) { - mpath->flag |= MOTIONPATH_FLAG_BHEAD; - } - else { - mpath->flag &= ~MOTIONPATH_FLAG_BHEAD; - } - - /* set default custom values */ - mpath->color[0] = 1.0; /* Red */ - mpath->color[1] = 0.0; - mpath->color[2] = 0.0; - - mpath->line_thickness = 2; - mpath->flag |= MOTIONPATH_FLAG_LINES; /* draw lines by default */ - - /* allocate a cache */ - mpath->points = MEM_callocN(sizeof(bMotionPathVert) * mpath->length, "bMotionPathVerts"); - - /* tag viz settings as currently having some path(s) which use it */ - avs->path_bakeflag |= MOTIONPATH_BAKE_HAS_PATHS; - - /* return it */ - return mpath; -} - /* ******************************************************************** */ /* Curve Paths - for curve deforms and/or curve following */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 2027dbe6c23..18320ef0f8d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -51,6 +51,7 @@ #include "DNA_world_types.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_fcurve.h" @@ -76,1382 +77,6 @@ static CLG_LogRef LOG = {"bke.anim_sys"}; -/* ***************************************** */ -/* AnimData API */ - -/* Getter/Setter -------------------------------------------- */ - -/* Check if ID can have AnimData */ -bool id_type_can_have_animdata(const short id_type) -{ - /* Only some ID-blocks have this info for now */ - /* TODO: finish adding this for the other blocktypes */ - switch (id_type) { - /* has AnimData */ - case ID_OB: - case ID_ME: - case ID_MB: - case ID_CU: - case ID_AR: - case ID_LT: - case ID_KE: - case ID_PA: - case ID_MA: - case ID_TE: - case ID_NT: - case ID_LA: - case ID_CA: - case ID_WO: - case ID_LS: - case ID_LP: - case ID_SPK: - case ID_SCE: - case ID_MC: - case ID_MSK: - case ID_GD: - case ID_CF: - case ID_HA: - case ID_PT: - case ID_VO: - return true; - - /* no AnimData */ - default: - return false; - } -} - -bool id_can_have_animdata(const ID *id) -{ - /* sanity check */ - if (id == NULL) { - return false; - } - - return id_type_can_have_animdata(GS(id->name)); -} - -/* Get AnimData from the given ID-block. In order for this to work, we assume that - * the AnimData pointer is stored immediately after the given ID-block in the struct, - * as per IdAdtTemplate. - */ -AnimData *BKE_animdata_from_id(ID *id) -{ - /* only some ID-blocks have this info for now, so we cast the - * types that do to be of type IdAdtTemplate, and extract the - * AnimData that way - */ - if (id_can_have_animdata(id)) { - IdAdtTemplate *iat = (IdAdtTemplate *)id; - return iat->adt; - } - else { - return NULL; - } -} - -/* Add AnimData to the given ID-block. In order for this to work, we assume that - * the AnimData pointer is stored immediately after the given ID-block in the struct, - * as per IdAdtTemplate. Also note that - */ -AnimData *BKE_animdata_add_id(ID *id) -{ - /* Only some ID-blocks have this info for now, so we cast the - * types that do to be of type IdAdtTemplate, and add the AnimData - * to it using the template - */ - if (id_can_have_animdata(id)) { - IdAdtTemplate *iat = (IdAdtTemplate *)id; - - /* check if there's already AnimData, in which case, don't add */ - if (iat->adt == NULL) { - AnimData *adt; - - /* add animdata */ - adt = iat->adt = MEM_callocN(sizeof(AnimData), "AnimData"); - - /* set default settings */ - adt->act_influence = 1.0f; - } - - return iat->adt; - } - else { - return NULL; - } -} - -/* Action Setter --------------------------------------- */ - -/** - * Called when user tries to change the active action of an AnimData block - * (via RNA, Outliner, etc.) - */ -bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) -{ - AnimData *adt = BKE_animdata_from_id(id); - bool ok = false; - - /* animdata validity check */ - if (adt == NULL) { - BKE_report(reports, RPT_WARNING, "No AnimData to set action on"); - return ok; - } - - /* active action is only editable when it is not a tweaking strip - * see rna_AnimData_action_editable() in rna_animation.c - */ - if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) { - /* cannot remove, otherwise things turn to custard */ - BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA"); - return ok; - } - - /* manage usercount for current action */ - if (adt->action) { - id_us_min((ID *)adt->action); - } - - /* assume that AnimData's action can in fact be edited... */ - if (act) { - /* action must have same type as owner */ - if (ELEM(act->idroot, 0, GS(id->name))) { - /* can set */ - adt->action = act; - id_us_plus((ID *)adt->action); - ok = true; - } - else { - /* cannot set */ - BKE_reportf( - reports, - RPT_ERROR, - "Could not set action '%s' onto ID '%s', as it does not have suitably rooted paths " - "for this purpose", - act->id.name + 2, - id->name); - /* ok = false; */ - } - } - else { - /* just clearing the action... */ - adt->action = NULL; - ok = true; - } - - return ok; -} - -/* Freeing -------------------------------------------- */ - -/* Free AnimData used by the nominated ID-block, and clear ID-block's AnimData pointer */ -void BKE_animdata_free(ID *id, const bool do_id_user) -{ - /* Only some ID-blocks have this info for now, so we cast the - * types that do to be of type IdAdtTemplate - */ - if (id_can_have_animdata(id)) { - IdAdtTemplate *iat = (IdAdtTemplate *)id; - AnimData *adt = iat->adt; - - /* check if there's any AnimData to start with */ - if (adt) { - if (do_id_user) { - /* unlink action (don't free, as it's in its own list) */ - if (adt->action) { - id_us_min(&adt->action->id); - } - /* same goes for the temporarily displaced action */ - if (adt->tmpact) { - id_us_min(&adt->tmpact->id); - } - } - - /* free nla data */ - BKE_nla_tracks_free(&adt->nla_tracks, do_id_user); - - /* free drivers - stored as a list of F-Curves */ - free_fcurves(&adt->drivers); - - /* free driver array cache */ - MEM_SAFE_FREE(adt->driver_array); - - /* free overrides */ - /* TODO... */ - - /* free animdata now */ - MEM_freeN(adt); - iat->adt = NULL; - } - } -} - -bool BKE_animdata_id_is_animated(const struct ID *id) -{ - if (id == NULL) { - return false; - } - - const AnimData *adt = BKE_animdata_from_id((ID *)id); - if (adt == NULL) { - return false; - } - - if (adt->action != NULL && !BLI_listbase_is_empty(&adt->action->curves)) { - return true; - } - - return !BLI_listbase_is_empty(&adt->drivers) || !BLI_listbase_is_empty(&adt->nla_tracks) || - !BLI_listbase_is_empty(&adt->overrides); -} - -/* Copying -------------------------------------------- */ - -/** - * Make a copy of the given AnimData - to be used when copying data-blocks. - * \param flag: Control ID pointers management, - * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_lib_id.h - * \return The copied animdata. - */ -AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) -{ - AnimData *dadt; - - const bool do_action = (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0; - const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0; - - /* sanity check before duplicating struct */ - if (adt == NULL) { - return NULL; - } - dadt = MEM_dupallocN(adt); - - /* make a copy of action - at worst, user has to delete copies... */ - if (do_action) { - BLI_assert(bmain != NULL); - BLI_assert(dadt->action == NULL || dadt->action != dadt->tmpact); - BKE_id_copy_ex(bmain, (ID *)dadt->action, (ID **)&dadt->action, flag); - BKE_id_copy_ex(bmain, (ID *)dadt->tmpact, (ID **)&dadt->tmpact, flag); - } - else if (do_id_user) { - id_us_plus((ID *)dadt->action); - id_us_plus((ID *)dadt->tmpact); - } - - /* duplicate NLA data */ - BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks, flag); - - /* duplicate drivers (F-Curves) */ - copy_fcurves(&dadt->drivers, &adt->drivers); - dadt->driver_array = NULL; - - /* don't copy overrides */ - BLI_listbase_clear(&dadt->overrides); - - /* return */ - return dadt; -} - -/** - * \param flag: Control ID pointers management, - * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_lib_id.h - * \return true is successfully copied. - */ -bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) -{ - AnimData *adt; - - if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name))) { - return false; - } - - BKE_animdata_free(id_to, (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0); - - adt = BKE_animdata_from_id(id_from); - if (adt) { - IdAdtTemplate *iat = (IdAdtTemplate *)id_to; - iat->adt = BKE_animdata_copy(bmain, adt, flag); - } - - return true; -} - -void BKE_animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid) -{ - AnimData *adt = BKE_animdata_from_id(id); - if (adt) { - if (adt->action) { - id_us_min((ID *)adt->action); - adt->action = set_newid ? ID_NEW_SET(adt->action, BKE_action_copy(bmain, adt->action)) : - BKE_action_copy(bmain, adt->action); - } - if (adt->tmpact) { - id_us_min((ID *)adt->tmpact); - adt->tmpact = set_newid ? ID_NEW_SET(adt->tmpact, BKE_action_copy(bmain, adt->tmpact)) : - BKE_action_copy(bmain, adt->tmpact); - } - } - bNodeTree *ntree = ntreeFromID(id); - if (ntree) { - BKE_animdata_copy_id_action(bmain, &ntree->id, set_newid); - } -} - -/* Merge copies of the data from the src AnimData into the destination AnimData */ -void BKE_animdata_merge_copy( - Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers) -{ - AnimData *src = BKE_animdata_from_id(src_id); - AnimData *dst = BKE_animdata_from_id(dst_id); - - /* sanity checks */ - if (ELEM(NULL, dst, src)) { - return; - } - - // TODO: we must unset all "tweakmode" flags - if ((src->flag & ADT_NLA_EDIT_ON) || (dst->flag & ADT_NLA_EDIT_ON)) { - CLOG_ERROR( - &LOG, - "Merging AnimData blocks while editing NLA is dangerous as it may cause data corruption"); - return; - } - - /* handle actions... */ - if (action_mode == ADT_MERGECOPY_SRC_COPY) { - /* make a copy of the actions */ - dst->action = BKE_action_copy(bmain, src->action); - dst->tmpact = BKE_action_copy(bmain, src->tmpact); - } - else if (action_mode == ADT_MERGECOPY_SRC_REF) { - /* make a reference to it */ - dst->action = src->action; - id_us_plus((ID *)dst->action); - - dst->tmpact = src->tmpact; - id_us_plus((ID *)dst->tmpact); - } - - /* duplicate NLA data */ - if (src->nla_tracks.first) { - ListBase tracks = {NULL, NULL}; - - BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks, 0); - BLI_movelisttolist(&dst->nla_tracks, &tracks); - } - - /* duplicate drivers (F-Curves) */ - if (src->drivers.first) { - ListBase drivers = {NULL, NULL}; - - copy_fcurves(&drivers, &src->drivers); - - /* Fix up all driver targets using the old target id - * - This assumes that the src ID is being merged into the dst ID - */ - if (fix_drivers) { - FCurve *fcu; - - for (fcu = drivers.first; fcu; fcu = fcu->next) { - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { - if (dtar->id == src_id) { - dtar->id = dst_id; - } - } - DRIVER_TARGETS_LOOPER_END; - } - } - } - - BLI_movelisttolist(&dst->drivers, &drivers); - } -} - -/* Sub-ID Regrouping ------------------------------------------- */ - -/** - * Helper heuristic for determining if a path is compatible with the basepath - * - * \param path: Full RNA-path from some data (usually an F-Curve) to compare - * \param basepath: Shorter path fragment to look for - * \return Whether there is a match - */ -static bool animpath_matches_basepath(const char path[], const char basepath[]) -{ - /* we need start of path to be basepath */ - return (path && basepath) && STRPREFIX(path, basepath); -} - -/* Move F-Curves in src action to dst action, setting up all the necessary groups - * for this to happen, but only if the F-Curves being moved have the appropriate - * "base path". - * - This is used when data moves from one data-block to another, causing the - * F-Curves to need to be moved over too - */ -void action_move_fcurves_by_basepath(bAction *srcAct, bAction *dstAct, const char basepath[]) -{ - FCurve *fcu, *fcn = NULL; - - /* sanity checks */ - if (ELEM(NULL, srcAct, dstAct, basepath)) { - if (G.debug & G_DEBUG) { - CLOG_ERROR(&LOG, - "srcAct: %p, dstAct: %p, basepath: %p has insufficient info to work with", - (void *)srcAct, - (void *)dstAct, - (void *)basepath); - } - return; - } - - /* clear 'temp' flags on all groups in src, as we'll be needing them later - * to identify groups that we've managed to empty out here - */ - action_groups_clear_tempflags(srcAct); - - /* iterate over all src F-Curves, moving over the ones that need to be moved */ - for (fcu = srcAct->curves.first; fcu; fcu = fcn) { - /* store next pointer in case we move stuff */ - fcn = fcu->next; - - /* should F-Curve be moved over? - * - we only need the start of the path to match basepath - */ - if (animpath_matches_basepath(fcu->rna_path, basepath)) { - bActionGroup *agrp = NULL; - - /* if grouped... */ - if (fcu->grp) { - /* make sure there will be a matching group on the other side for the migrants */ - agrp = BKE_action_group_find_name(dstAct, fcu->grp->name); - - if (agrp == NULL) { - /* add a new one with a similar name (usually will be the same though) */ - agrp = action_groups_add_new(dstAct, fcu->grp->name); - } - - /* old groups should be tagged with 'temp' flags so they can be removed later - * if we remove everything from them - */ - fcu->grp->flag |= AGRP_TEMP; - } - - /* perform the migration now */ - action_groups_remove_channel(srcAct, fcu); - - if (agrp) { - action_groups_add_channel(dstAct, agrp, fcu); - } - else { - BLI_addtail(&dstAct->curves, fcu); - } - } - } - - /* cleanup groups (if present) */ - if (srcAct->groups.first) { - bActionGroup *agrp, *grp = NULL; - - for (agrp = srcAct->groups.first; agrp; agrp = grp) { - grp = agrp->next; - - /* only tagged groups need to be considered - clearing these tags or removing them */ - if (agrp->flag & AGRP_TEMP) { - /* if group is empty and tagged, then we can remove as this operation - * moved out all the channels that were formerly here - */ - if (BLI_listbase_is_empty(&agrp->channels)) { - BLI_freelinkN(&srcAct->groups, agrp); - } - else { - agrp->flag &= ~AGRP_TEMP; - } - } - } - } -} - -/* Transfer the animation data from srcID to dstID where the srcID - * animation data is based off "basepath", creating new AnimData and - * associated data as necessary - */ -void BKE_animdata_separate_by_basepath(Main *bmain, ID *srcID, ID *dstID, ListBase *basepaths) -{ - AnimData *srcAdt = NULL, *dstAdt = NULL; - LinkData *ld; - - /* sanity checks */ - if (ELEM(NULL, srcID, dstID)) { - if (G.debug & G_DEBUG) { - CLOG_ERROR(&LOG, "no source or destination ID to separate AnimData with"); - } - return; - } - - /* get animdata from src, and create for destination (if needed) */ - srcAdt = BKE_animdata_from_id(srcID); - dstAdt = BKE_animdata_add_id(dstID); - - if (ELEM(NULL, srcAdt, dstAdt)) { - if (G.debug & G_DEBUG) { - CLOG_ERROR(&LOG, "no AnimData for this pair of ID's"); - } - return; - } - - /* active action */ - if (srcAdt->action) { - /* Set up an action if necessary, - * and name it in a similar way so that it can be easily found again. */ - if (dstAdt->action == NULL) { - dstAdt->action = BKE_action_add(bmain, srcAdt->action->id.name + 2); - } - else if (dstAdt->action == srcAdt->action) { - CLOG_WARN(&LOG, - "Argh! Source and Destination share animation! " - "('%s' and '%s' both use '%s') Making new empty action", - srcID->name, - dstID->name, - srcAdt->action->id.name); - - /* TODO: review this... */ - id_us_min(&dstAdt->action->id); - dstAdt->action = BKE_action_add(bmain, dstAdt->action->id.name + 2); - } - - /* loop over base paths, trying to fix for each one... */ - for (ld = basepaths->first; ld; ld = ld->next) { - const char *basepath = (const char *)ld->data; - action_move_fcurves_by_basepath(srcAdt->action, dstAdt->action, basepath); - } - } - - /* drivers */ - if (srcAdt->drivers.first) { - FCurve *fcu, *fcn = NULL; - - /* check each driver against all the base paths to see if any should go */ - for (fcu = srcAdt->drivers.first; fcu; fcu = fcn) { - fcn = fcu->next; - - /* try each basepath in turn, but stop on the first one which works */ - for (ld = basepaths->first; ld; ld = ld->next) { - const char *basepath = (const char *)ld->data; - - if (animpath_matches_basepath(fcu->rna_path, basepath)) { - /* just need to change lists */ - BLI_remlink(&srcAdt->drivers, fcu); - BLI_addtail(&dstAdt->drivers, fcu); - - /* TODO: add depsgraph flushing calls? */ - - /* can stop now, as moved already */ - break; - } - } - } - } -} - -/** - * Temporary wrapper for driver operators for buttons to make it easier to create - * such drivers by rerouting all paths through the active object instead so that - * they will get picked up by the dependency system. - * - * \param C: Context pointer - for getting active data - * \param[in,out] ptr: RNA pointer for property's data-block. - * May be modified as result of path remapping. - * \param prop: RNA definition of property to add for - * \return MEM_alloc'd string representing the path to the property from the given #PointerRNA - */ -char *BKE_animdata_driver_path_hack(bContext *C, - PointerRNA *ptr, - PropertyRNA *prop, - char *base_path) -{ - ID *id = ptr->owner_id; - ScrArea *sa = CTX_wm_area(C); - - /* get standard path which may be extended */ - char *basepath = base_path ? base_path : RNA_path_from_ID_to_property(ptr, prop); - char *path = basepath; /* in case no remapping is needed */ - - /* Remapping will only be performed in the Properties Editor, as only this - * restricts the subspace of options to the 'active' data (a manageable state) - */ - /* TODO: watch out for pinned context? */ - if ((sa) && (sa->spacetype == SPACE_PROPERTIES)) { - Object *ob = CTX_data_active_object(C); - - if (ob && id) { - /* TODO: after material textures were removed, this function serves - * no purpose anymore, but could be used again so was not removed. */ - - /* fix RNA pointer, as we've now changed the ID root by changing the paths */ - if (basepath != path) { - /* rebase provided pointer so that it starts from object... */ - RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr); - } - } - } - - /* the path should now have been corrected for use */ - return path; -} - -/* 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 bool check_rna_path_is_valid(ID *owner_id, const char *path) -{ - PointerRNA id_ptr, ptr; - PropertyRNA *prop = NULL; - - /* make initial RNA pointer to start resolving from */ - RNA_id_pointer_create(owner_id, &id_ptr); - - /* try to resolve */ - return RNA_path_resolve_property(&id_ptr, path, &ptr, &prop); -} - -/* 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, - const char *oldName, - const char *newName, - char *oldpath, - bool verify_paths) -{ - char *prefixPtr = strstr(oldpath, prefix); - char *oldNamePtr = strstr(oldpath, oldName); - int prefixLen = strlen(prefix); - int oldNameLen = strlen(oldName); - - /* only start fixing the path if the prefix and oldName feature in the path, - * and prefix occurs immediately before oldName - */ - if ((prefixPtr && oldNamePtr) && (prefixPtr + prefixLen == oldNamePtr)) { - /* if we haven't aren't able to resolve the path now, try again after fixing it */ - if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) { - DynStr *ds = BLI_dynstr_new(); - const char *postfixPtr = oldNamePtr + oldNameLen; - char *newPath = NULL; - - /* add the part of the string that goes up to the start of the prefix */ - if (prefixPtr > oldpath) { - BLI_dynstr_nappend(ds, oldpath, prefixPtr - oldpath); - } - - /* add the prefix */ - BLI_dynstr_append(ds, prefix); - - /* add the new name (complete with brackets) */ - BLI_dynstr_append(ds, newName); - - /* add the postfix */ - BLI_dynstr_append(ds, postfixPtr); - - /* create new path, and cleanup old data */ - newPath = BLI_dynstr_get_cstring(ds); - BLI_dynstr_free(ds); - - /* check if the new path will solve our problems */ - /* TODO: will need to check whether this step really helps in practice */ - if (!verify_paths || check_rna_path_is_valid(owner_id, newPath)) { - /* free the old path, and return the new one, since we've solved the issues */ - MEM_freeN(oldpath); - return newPath; - } - else { - /* still couldn't resolve the path... so, might as well just leave it alone */ - MEM_freeN(newPath); - } - } - } - - /* the old path doesn't need to be changed */ - return oldpath; -} - -/* Check RNA-Paths for a list of F-Curves */ -static bool fcurves_path_rename_fix(ID *owner_id, - const char *prefix, - const char *oldName, - const char *newName, - const char *oldKey, - const char *newKey, - ListBase *curves, - bool verify_paths) -{ - FCurve *fcu; - bool is_changed = false; - /* We need to check every curve. */ - for (fcu = curves->first; fcu; fcu = fcu->next) { - if (fcu->rna_path == NULL) { - continue; - } - const char *old_path = fcu->rna_path; - /* Firstly, handle the F-Curve's own path. */ - fcu->rna_path = rna_path_rename_fix( - owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); - /* if path changed and the F-Curve is grouped, check if its group also needs renaming - * (i.e. F-Curve is first of a bone's F-Curves; - * hence renaming this should also trigger rename) */ - if (fcu->rna_path != old_path) { - bActionGroup *agrp = fcu->grp; - is_changed = true; - if ((agrp != NULL) && STREQ(oldName, agrp->name)) { - BLI_strncpy(agrp->name, newName, sizeof(agrp->name)); - } - } - } - return is_changed; -} - -/* Check RNA-Paths for a list of Drivers */ -static bool drivers_path_rename_fix(ID *owner_id, - ID *ref_id, - const char *prefix, - const char *oldName, - const char *newName, - const char *oldKey, - const char *newKey, - ListBase *curves, - bool verify_paths) -{ - bool is_changed = false; - FCurve *fcu; - /* We need to check every curve - drivers are F-Curves too. */ - for (fcu = curves->first; fcu; fcu = fcu->next) { - /* firstly, handle the F-Curve's own path */ - if (fcu->rna_path != NULL) { - const char *old_rna_path = fcu->rna_path; - fcu->rna_path = rna_path_rename_fix( - owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); - is_changed |= (fcu->rna_path != old_rna_path); - } - if (fcu->driver == NULL) { - continue; - } - ChannelDriver *driver = fcu->driver; - DriverVar *dvar; - /* driver variables */ - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - /* only change the used targets, since the others will need fixing manually anyway */ - DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { - /* rename RNA path */ - if (dtar->rna_path && dtar->id) { - const char *old_rna_path = dtar->rna_path; - dtar->rna_path = rna_path_rename_fix( - dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths); - is_changed |= (dtar->rna_path != old_rna_path); - } - /* also fix the bone-name (if applicable) */ - if (strstr(prefix, "bones")) { - if (((dtar->id) && (GS(dtar->id->name) == ID_OB) && - (!ref_id || ((Object *)(dtar->id))->data == ref_id)) && - (dtar->pchan_name[0]) && STREQ(oldName, dtar->pchan_name)) { - is_changed = true; - BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name)); - } - } - } - DRIVER_TARGETS_LOOPER_END; - } - } - return is_changed; -} - -/* Fix all RNA-Paths for Actions linked to NLA Strips */ -static bool nlastrips_path_rename_fix(ID *owner_id, - const char *prefix, - const char *oldName, - const char *newName, - const char *oldKey, - const char *newKey, - ListBase *strips, - bool verify_paths) -{ - NlaStrip *strip; - bool is_changed = false; - /* Recursively check strips, fixing only actions. */ - for (strip = strips->first; strip; strip = strip->next) { - /* fix strip's action */ - if (strip->act != NULL) { - is_changed |= fcurves_path_rename_fix( - owner_id, prefix, oldName, newName, oldKey, newKey, &strip->act->curves, verify_paths); - } - /* Ignore own F-Curves, since those are local. */ - /* Check sub-strips (if metas) */ - is_changed |= nlastrips_path_rename_fix( - owner_id, prefix, oldName, newName, oldKey, newKey, &strip->strips, verify_paths); - } - return is_changed; -} - -/* Rename Sub-ID Entities in RNA Paths ----------------------- */ - -/* Fix up the given RNA-Path - * - * This is just an external wrapper for the RNA-Path fixing function, - * with input validity checks on top of the basic method. - * - * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] - */ -char *BKE_animsys_fix_rna_path_rename(ID *owner_id, - char *old_path, - const char *prefix, - const char *oldName, - const char *newName, - int oldSubscript, - int newSubscript, - bool verify_paths) -{ - char *oldN, *newN; - char *result; - - /* if no action, no need to proceed */ - if (ELEM(NULL, owner_id, old_path)) { - if (G.debug & G_DEBUG) { - CLOG_WARN(&LOG, "early abort"); - } - return old_path; - } - - /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ - if ((oldName != NULL) && (newName != NULL)) { - /* pad the names with [" "] so that only exact matches are made */ - const size_t name_old_len = strlen(oldName); - const size_t name_new_len = strlen(newName); - char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); - char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); - - BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); - BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); - oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); - newN = BLI_sprintfN("[\"%s\"]", name_new_esc); - } - else { - oldN = BLI_sprintfN("[%d]", oldSubscript); - newN = BLI_sprintfN("[%d]", newSubscript); - } - - /* fix given path */ - if (G.debug & G_DEBUG) { - printf("%s | %s | oldpath = %p ", oldN, newN, old_path); - } - result = rna_path_rename_fix(owner_id, prefix, oldN, newN, old_path, verify_paths); - if (G.debug & G_DEBUG) { - printf("path rename result = %p\n", result); - } - - /* free the temp names */ - MEM_freeN(oldN); - MEM_freeN(newN); - - /* return the resulting path - may be the same path again if nothing changed */ - return result; -} - -/* Fix all RNA_Paths in the given Action, relative to the given ID block - * - * This is just an external wrapper for the F-Curve fixing function, - * with input validity checks on top of the basic method. - * - * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] - */ -void BKE_action_fix_paths_rename(ID *owner_id, - bAction *act, - const char *prefix, - const char *oldName, - const char *newName, - int oldSubscript, - int newSubscript, - bool verify_paths) -{ - char *oldN, *newN; - - /* if no action, no need to proceed */ - if (ELEM(NULL, owner_id, act)) { - return; - } - - /* Name sanitation logic - copied from BKE_animdata_fix_paths_rename() */ - if ((oldName != NULL) && (newName != NULL)) { - /* pad the names with [" "] so that only exact matches are made */ - const size_t name_old_len = strlen(oldName); - const size_t name_new_len = strlen(newName); - char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); - char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); - - BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); - BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); - oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); - newN = BLI_sprintfN("[\"%s\"]", name_new_esc); - } - else { - oldN = BLI_sprintfN("[%d]", oldSubscript); - newN = BLI_sprintfN("[%d]", newSubscript); - } - - /* fix paths in action */ - fcurves_path_rename_fix( - owner_id, prefix, oldName, newName, oldN, newN, &act->curves, verify_paths); - - /* free the temp names */ - MEM_freeN(oldN); - MEM_freeN(newN); -} - -/* Fix all RNA-Paths in the AnimData block used by the given ID block - * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] - */ -void BKE_animdata_fix_paths_rename(ID *owner_id, - AnimData *adt, - ID *ref_id, - const char *prefix, - const char *oldName, - const char *newName, - int oldSubscript, - int newSubscript, - bool verify_paths) -{ - NlaTrack *nlt; - char *oldN, *newN; - /* If no AnimData, no need to proceed. */ - if (ELEM(NULL, owner_id, adt)) { - return; - } - bool is_self_changed = false; - /* Name sanitation logic - shared with BKE_action_fix_paths_rename(). */ - if ((oldName != NULL) && (newName != NULL)) { - /* Pad the names with [" "] so that only exact matches are made. */ - const size_t name_old_len = strlen(oldName); - const size_t name_new_len = strlen(newName); - char *name_old_esc = BLI_array_alloca(name_old_esc, (name_old_len * 2) + 1); - char *name_new_esc = BLI_array_alloca(name_new_esc, (name_new_len * 2) + 1); - - BLI_strescape(name_old_esc, oldName, (name_old_len * 2) + 1); - BLI_strescape(name_new_esc, newName, (name_new_len * 2) + 1); - oldN = BLI_sprintfN("[\"%s\"]", name_old_esc); - newN = BLI_sprintfN("[\"%s\"]", name_new_esc); - } - else { - oldN = BLI_sprintfN("[%d]", oldSubscript); - newN = BLI_sprintfN("[%d]", newSubscript); - } - /* Active action and temp action. */ - if (adt->action != NULL) { - if (fcurves_path_rename_fix( - owner_id, prefix, oldName, newName, oldN, newN, &adt->action->curves, verify_paths)) { - DEG_id_tag_update(&adt->action->id, ID_RECALC_COPY_ON_WRITE); - } - } - if (adt->tmpact) { - if (fcurves_path_rename_fix( - owner_id, prefix, oldName, newName, oldN, newN, &adt->tmpact->curves, verify_paths)) { - DEG_id_tag_update(&adt->tmpact->id, ID_RECALC_COPY_ON_WRITE); - } - } - /* Drivers - Drivers are really F-Curves */ - is_self_changed |= drivers_path_rename_fix( - owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths); - /* NLA Data - Animation Data for Strips */ - for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { - is_self_changed |= nlastrips_path_rename_fix( - owner_id, prefix, oldName, newName, oldN, newN, &nlt->strips, verify_paths); - } - /* Tag owner ID if it */ - if (is_self_changed) { - DEG_id_tag_update(owner_id, ID_RECALC_COPY_ON_WRITE); - } - /* free the temp names */ - MEM_freeN(oldN); - MEM_freeN(newN); -} - -/* Remove FCurves with Prefix -------------------------------------- */ - -/* Check RNA-Paths for a list of F-Curves */ -static bool fcurves_path_remove_fix(const char *prefix, ListBase *curves) -{ - FCurve *fcu, *fcn; - bool any_removed = false; - if (!prefix) { - return any_removed; - } - - /* we need to check every curve... */ - for (fcu = curves->first; fcu; fcu = fcn) { - fcn = fcu->next; - - if (fcu->rna_path) { - if (STRPREFIX(fcu->rna_path, prefix)) { - BLI_remlink(curves, fcu); - free_fcurve(fcu); - any_removed = true; - } - } - } - return any_removed; -} - -/* Check RNA-Paths for a list of F-Curves */ -static bool nlastrips_path_remove_fix(const char *prefix, ListBase *strips) -{ - NlaStrip *strip; - bool any_removed = false; - - /* recursively check strips, fixing only actions... */ - for (strip = strips->first; strip; strip = strip->next) { - /* fix strip's action */ - if (strip->act) { - any_removed |= fcurves_path_remove_fix(prefix, &strip->act->curves); - } - - /* check sub-strips (if metas) */ - any_removed |= nlastrips_path_remove_fix(prefix, &strip->strips); - } - return any_removed; -} - -bool BKE_animdata_fix_paths_remove(ID *id, const char *prefix) -{ - /* Only some ID-blocks have this info for now, so we cast the - * types that do to be of type IdAdtTemplate - */ - if (!id_can_have_animdata(id)) { - return false; - } - bool any_removed = false; - IdAdtTemplate *iat = (IdAdtTemplate *)id; - AnimData *adt = iat->adt; - /* check if there's any AnimData to start with */ - if (adt) { - /* free fcurves */ - if (adt->action != NULL) { - any_removed |= fcurves_path_remove_fix(prefix, &adt->action->curves); - } - if (adt->tmpact != NULL) { - any_removed |= fcurves_path_remove_fix(prefix, &adt->tmpact->curves); - } - /* free drivers - stored as a list of F-Curves */ - any_removed |= fcurves_path_remove_fix(prefix, &adt->drivers); - /* NLA Data - Animation Data for Strips */ - for (NlaTrack *nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { - any_removed |= nlastrips_path_remove_fix(prefix, &nlt->strips); - } - } - return any_removed; -} - -/* Apply Op to All FCurves in Database --------------------------- */ - -/* "User-Data" wrapper used by BKE_fcurves_main_cb() */ -typedef struct AllFCurvesCbWrapper { - ID_FCurve_Edit_Callback func; /* Operation to apply on F-Curve */ - void *user_data; /* Custom data for that operation */ -} AllFCurvesCbWrapper; - -/* Helper for adt_apply_all_fcurves_cb() - Apply wrapped operator to list of F-Curves */ -static void fcurves_apply_cb(ID *id, - ListBase *fcurves, - ID_FCurve_Edit_Callback func, - void *user_data) -{ - FCurve *fcu; - - for (fcu = fcurves->first; fcu; fcu = fcu->next) { - func(id, fcu, user_data); - } -} - -/* Helper for adt_apply_all_fcurves_cb() - Recursively go through each NLA strip */ -static void nlastrips_apply_all_curves_cb(ID *id, ListBase *strips, AllFCurvesCbWrapper *wrapper) -{ - NlaStrip *strip; - - for (strip = strips->first; strip; strip = strip->next) { - /* fix strip's action */ - if (strip->act) { - fcurves_apply_cb(id, &strip->act->curves, wrapper->func, wrapper->user_data); - } - - /* check sub-strips (if metas) */ - nlastrips_apply_all_curves_cb(id, &strip->strips, wrapper); - } -} - -/* Helper for BKE_fcurves_main_cb() - Dispatch wrapped operator to all F-Curves */ -static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, void *wrapper_data) -{ - AllFCurvesCbWrapper *wrapper = wrapper_data; - NlaTrack *nlt; - - if (adt->action) { - fcurves_apply_cb(id, &adt->action->curves, wrapper->func, wrapper->user_data); - } - - if (adt->tmpact) { - fcurves_apply_cb(id, &adt->tmpact->curves, wrapper->func, wrapper->user_data); - } - - /* free drivers - stored as a list of F-Curves */ - fcurves_apply_cb(id, &adt->drivers, wrapper->func, wrapper->user_data); - - /* NLA Data - Animation Data for Strips */ - for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { - nlastrips_apply_all_curves_cb(id, &nlt->strips, wrapper); - } -} - -void BKE_fcurves_id_cb(ID *id, ID_FCurve_Edit_Callback func, void *user_data) -{ - AnimData *adt = BKE_animdata_from_id(id); - if (adt != NULL) { - AllFCurvesCbWrapper wrapper = {func, user_data}; - adt_apply_all_fcurves_cb(id, adt, &wrapper); - } -} - -/* apply the given callback function on all F-Curves attached to data in main database */ -void BKE_fcurves_main_cb(Main *bmain, ID_FCurve_Edit_Callback func, void *user_data) -{ - /* Wrap F-Curve operation stuff to pass to the general AnimData-level func */ - AllFCurvesCbWrapper wrapper = {func, user_data}; - - /* Use the AnimData-based function so that we don't have to reimplement all that stuff */ - BKE_animdata_main_cb(bmain, adt_apply_all_fcurves_cb, &wrapper); -} - -/* Whole Database Ops -------------------------------------------- */ - -/* apply the given callback function on all data in main database */ -void BKE_animdata_main_cb(Main *bmain, ID_AnimData_Edit_Callback func, void *user_data) -{ - ID *id; - - /* standard data version */ -#define ANIMDATA_IDS_CB(first) \ - for (id = first; id; id = id->next) { \ - AnimData *adt = BKE_animdata_from_id(id); \ - if (adt) \ - func(id, adt, user_data); \ - } \ - (void)0 - - /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */ -#define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \ - for (id = first; id; id = id->next) { \ - AnimData *adt = BKE_animdata_from_id(id); \ - NtId_Type *ntp = (NtId_Type *)id; \ - if (ntp->nodetree) { \ - AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ - if (adt2) \ - func(id, adt2, user_data); \ - } \ - if (adt) \ - func(id, adt, user_data); \ - } \ - (void)0 - - /* nodes */ - ANIMDATA_IDS_CB(bmain->nodetrees.first); - - /* textures */ - ANIMDATA_NODETREE_IDS_CB(bmain->textures.first, Tex); - - /* lights */ - ANIMDATA_NODETREE_IDS_CB(bmain->lights.first, Light); - - /* materials */ - ANIMDATA_NODETREE_IDS_CB(bmain->materials.first, Material); - - /* cameras */ - ANIMDATA_IDS_CB(bmain->cameras.first); - - /* shapekeys */ - ANIMDATA_IDS_CB(bmain->shapekeys.first); - - /* metaballs */ - ANIMDATA_IDS_CB(bmain->metaballs.first); - - /* curves */ - ANIMDATA_IDS_CB(bmain->curves.first); - - /* armatures */ - ANIMDATA_IDS_CB(bmain->armatures.first); - - /* lattices */ - ANIMDATA_IDS_CB(bmain->lattices.first); - - /* meshes */ - ANIMDATA_IDS_CB(bmain->meshes.first); - - /* particles */ - ANIMDATA_IDS_CB(bmain->particles.first); - - /* speakers */ - ANIMDATA_IDS_CB(bmain->speakers.first); - - /* movie clips */ - ANIMDATA_IDS_CB(bmain->movieclips.first); - - /* objects */ - ANIMDATA_IDS_CB(bmain->objects.first); - - /* masks */ - ANIMDATA_IDS_CB(bmain->masks.first); - - /* worlds */ - ANIMDATA_NODETREE_IDS_CB(bmain->worlds.first, World); - - /* scenes */ - ANIMDATA_NODETREE_IDS_CB(bmain->scenes.first, Scene); - - /* line styles */ - ANIMDATA_IDS_CB(bmain->linestyles.first); - - /* grease pencil */ - ANIMDATA_IDS_CB(bmain->gpencils.first); - - /* palettes */ - ANIMDATA_IDS_CB(bmain->palettes.first); - - /* cache files */ - ANIMDATA_IDS_CB(bmain->cachefiles.first); - - /* hairs */ - ANIMDATA_IDS_CB(bmain->hairs.first); - - /* pointclouds */ - ANIMDATA_IDS_CB(bmain->pointclouds.first); - - /* volumes */ - ANIMDATA_IDS_CB(bmain->volumes.first); -} - -/* Fix all RNA-Paths throughout the database (directly access the Global.main version) - * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> - * i.e. pose.bones["Bone"] - */ -/* TODO: use BKE_animdata_main_cb for looping over all data */ -void BKE_animdata_fix_paths_rename_all(ID *ref_id, - const char *prefix, - const char *oldName, - const char *newName) -{ - Main *bmain = G.main; /* XXX UGLY! */ - ID *id; - - /* macro for less typing - * - whether animdata exists is checked for by the main renaming callback, though taking - * this outside of the function may make things slightly faster? - */ -#define RENAMEFIX_ANIM_IDS(first) \ - for (id = first; id; id = id->next) { \ - AnimData *adt = BKE_animdata_from_id(id); \ - BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ - } \ - (void)0 - - /* another version of this macro for nodetrees */ -#define RENAMEFIX_ANIM_NODETREE_IDS(first, NtId_Type) \ - for (id = first; id; id = id->next) { \ - AnimData *adt = BKE_animdata_from_id(id); \ - NtId_Type *ntp = (NtId_Type *)id; \ - if (ntp->nodetree) { \ - AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ - BKE_animdata_fix_paths_rename( \ - (ID *)ntp->nodetree, adt2, ref_id, prefix, oldName, newName, 0, 0, 1); \ - } \ - BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1); \ - } \ - (void)0 - - /* nodes */ - RENAMEFIX_ANIM_IDS(bmain->nodetrees.first); - - /* textures */ - RENAMEFIX_ANIM_NODETREE_IDS(bmain->textures.first, Tex); - - /* lights */ - RENAMEFIX_ANIM_NODETREE_IDS(bmain->lights.first, Light); - - /* materials */ - RENAMEFIX_ANIM_NODETREE_IDS(bmain->materials.first, Material); - - /* cameras */ - RENAMEFIX_ANIM_IDS(bmain->cameras.first); - - /* shapekeys */ - RENAMEFIX_ANIM_IDS(bmain->shapekeys.first); - - /* metaballs */ - RENAMEFIX_ANIM_IDS(bmain->metaballs.first); - - /* curves */ - RENAMEFIX_ANIM_IDS(bmain->curves.first); - - /* armatures */ - RENAMEFIX_ANIM_IDS(bmain->armatures.first); - - /* lattices */ - RENAMEFIX_ANIM_IDS(bmain->lattices.first); - - /* meshes */ - RENAMEFIX_ANIM_IDS(bmain->meshes.first); - - /* particles */ - RENAMEFIX_ANIM_IDS(bmain->particles.first); - - /* speakers */ - RENAMEFIX_ANIM_IDS(bmain->speakers.first); - - /* movie clips */ - RENAMEFIX_ANIM_IDS(bmain->movieclips.first); - - /* objects */ - RENAMEFIX_ANIM_IDS(bmain->objects.first); - - /* masks */ - RENAMEFIX_ANIM_IDS(bmain->masks.first); - - /* worlds */ - RENAMEFIX_ANIM_NODETREE_IDS(bmain->worlds.first, World); - - /* linestyles */ - RENAMEFIX_ANIM_IDS(bmain->linestyles.first); - - /* grease pencil */ - RENAMEFIX_ANIM_IDS(bmain->gpencils.first); - - /* cache files */ - RENAMEFIX_ANIM_IDS(bmain->cachefiles.first); - - /* hairs */ - RENAMEFIX_ANIM_IDS(bmain->hairs.first); - - /* pointclouds */ - RENAMEFIX_ANIM_IDS(bmain->pointclouds.first); - - /* volumes */ - RENAMEFIX_ANIM_IDS(bmain->volumes.first); - - /* scenes */ - RENAMEFIX_ANIM_NODETREE_IDS(bmain->scenes.first, Scene); -} - /* *********************************** */ /* KeyingSet API */ @@ -1917,7 +542,7 @@ static void animsys_evaluate_fcurves(PointerRNA *ptr, bool flush_to_original) { /* Calculate then execute each curve. */ - for (FCurve *fcu = list->first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, list) { /* Check if this F-Curve doesn't belong to a muted group. */ if ((fcu->grp != NULL) && (fcu->grp->flag & AGRP_MUTED)) { continue; @@ -2470,7 +1095,7 @@ static void nlaeval_free(NlaEvalData *nlaeval) nlaeval_snapshot_free_data(&nlaeval->eval_snapshot); /* Delete channels. */ - for (NlaEvalChannel *nec = nlaeval->channels.first; nec; nec = nec->next) { + LISTBASE_FOREACH (NlaEvalChannel *, nec, &nlaeval->channels) { nlaevalchan_free_data(nec); } @@ -3329,7 +1954,7 @@ void nladata_flush_channels(PointerRNA *ptr, } /* for each channel with accumulated values, write its value on the property it affects */ - for (NlaEvalChannel *nec = channels->channels.first; nec; nec = nec->next) { + LISTBASE_FOREACH (NlaEvalChannel *, nec, &channels->channels) { NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_find_channel(snapshot, nec); PathResolvedRNA rna = {nec->key.ptr, nec->key.prop, -1}; @@ -3360,7 +1985,7 @@ static void nla_eval_domain_action(PointerRNA *ptr, return; } - for (FCurve *fcu = act->curves.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { /* check if this curve should be skipped */ if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) { continue; @@ -3395,7 +2020,7 @@ static void nla_eval_domain_strips(PointerRNA *ptr, ListBase *strips, GSet *touched_actions) { - for (NlaStrip *strip = strips->first; strip; strip = strip->next) { + LISTBASE_FOREACH (NlaStrip *, strip, strips) { /* check strip's action */ if (strip->act) { nla_eval_domain_action(ptr, channels, strip->act, touched_actions); @@ -3419,7 +2044,7 @@ static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, } /* NLA Data - Animation Data for Strips */ - for (NlaTrack *nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) { /* solo and muting are mutually exclusive... */ if (adt->flag & ADT_NLA_SOLO_TRACK) { /* skip if there is a solo track, but this isn't it */ @@ -3805,7 +2430,7 @@ bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, */ void BKE_animsys_free_nla_keyframing_context_cache(struct ListBase *cache) { - for (NlaKeyframingContext *ctx = cache->first; ctx; ctx = ctx->next) { + LISTBASE_FOREACH (NlaKeyframingContext *, ctx, cache) { MEM_SAFE_FREE(ctx->eval_strip); nlaeval_free(&ctx->nla_channels); } @@ -4113,7 +2738,7 @@ void BKE_animsys_update_driver_array(ID *id) adt->driver_array = MEM_mallocN(sizeof(FCurve *) * num_drivers, "adt->driver_array"); int driver_index = 0; - for (FCurve *fcu = adt->drivers.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { adt->driver_array[driver_index++] = fcu; } } diff --git a/source/blender/blenkernel/intern/anim_visualization.c b/source/blender/blenkernel/intern/anim_visualization.c new file mode 100644 index 00000000000..04dbe4102cc --- /dev/null +++ b/source/blender/blenkernel/intern/anim_visualization.c @@ -0,0 +1,228 @@ +/* + * 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. + */ + +/** \file + * \ingroup bke + */ +#include "MEM_guardedalloc.h" + +#include "DNA_action_types.h" +#include "DNA_anim_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BLT_translation.h" + +#include "BKE_anim_visualization.h" +#include "BKE_report.h" + +#include "GPU_batch.h" + +/* ******************************************************************** */ +/* Animation Visualization */ + +/* Initialize the default settings for animation visualization */ +void animviz_settings_init(bAnimVizSettings *avs) +{ + /* sanity check */ + if (avs == NULL) { + return; + } + + /* path settings */ + avs->path_bc = avs->path_ac = 10; + + avs->path_sf = 1; /* xxx - take from scene instead? */ + avs->path_ef = 250; /* xxx - take from scene instead? */ + + avs->path_viewflag = (MOTIONPATH_VIEW_KFRAS | MOTIONPATH_VIEW_KFNOS); + + avs->path_step = 1; + + avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS; +} + +/* ------------------- */ + +/* Free the given motion path's cache */ +void animviz_free_motionpath_cache(bMotionPath *mpath) +{ + /* sanity check */ + if (mpath == NULL) { + return; + } + + /* free the path if necessary */ + if (mpath->points) { + MEM_freeN(mpath->points); + } + + GPU_VERTBUF_DISCARD_SAFE(mpath->points_vbo); + GPU_BATCH_DISCARD_SAFE(mpath->batch_line); + GPU_BATCH_DISCARD_SAFE(mpath->batch_points); + + /* reset the relevant parameters */ + mpath->points = NULL; + mpath->length = 0; +} + +/* Free the given motion path instance and its data + * NOTE: this frees the motion path given! + */ +void animviz_free_motionpath(bMotionPath *mpath) +{ + /* sanity check */ + if (mpath == NULL) { + return; + } + + /* free the cache first */ + animviz_free_motionpath_cache(mpath); + + /* now the instance itself */ + MEM_freeN(mpath); +} + +/* ------------------- */ + +/* Make a copy of motionpath data, so that viewing with copy on write works */ +bMotionPath *animviz_copy_motionpath(const bMotionPath *mpath_src) +{ + bMotionPath *mpath_dst; + + if (mpath_src == NULL) { + return NULL; + } + + mpath_dst = MEM_dupallocN(mpath_src); + mpath_dst->points = MEM_dupallocN(mpath_src->points); + + /* should get recreated on draw... */ + mpath_dst->points_vbo = NULL; + mpath_dst->batch_line = NULL; + mpath_dst->batch_points = NULL; + + return mpath_dst; +} + +/* ------------------- */ + +/** + * Setup motion paths for the given data. + * \note Only used when explicitly calculating paths on bones which may/may not be consider already + * + * \param scene: Current scene (for frame ranges, etc.) + * \param ob: Object to add paths for (must be provided) + * \param pchan: Posechannel to add paths for (optional; if not provided, object-paths are assumed) + */ +bMotionPath *animviz_verify_motionpaths(ReportList *reports, + Scene *scene, + Object *ob, + bPoseChannel *pchan) +{ + bAnimVizSettings *avs; + bMotionPath *mpath, **dst; + + /* sanity checks */ + if (ELEM(NULL, scene, ob)) { + return NULL; + } + + /* get destination data */ + if (pchan) { + /* paths for posechannel - assume that posechannel belongs to the object */ + avs = &ob->pose->avs; + dst = &pchan->mpath; + } + else { + /* paths for object */ + avs = &ob->avs; + dst = &ob->mpath; + } + + /* avoid 0 size allocs */ + if (avs->path_sf >= avs->path_ef) { + BKE_reportf(reports, + RPT_ERROR, + "Motion path frame extents invalid for %s (%d to %d)%s", + (pchan) ? pchan->name : ob->id.name, + avs->path_sf, + avs->path_ef, + (avs->path_sf == avs->path_ef) ? TIP_(", cannot have single-frame paths") : ""); + return NULL; + } + + /* if there is already a motionpath, just return that, + * provided it's settings are ok (saves extra free+alloc) + */ + if (*dst != NULL) { + int expected_length = avs->path_ef - avs->path_sf; + + mpath = *dst; + + /* Path is "valid" if length is valid, + * but must also be of the same length as is being requested. */ + if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0)) { + /* outer check ensures that we have some curve data for this path */ + if (mpath->length == expected_length) { + /* return/use this as it is already valid length */ + return mpath; + } + else { + /* clear the existing path (as the range has changed), and reallocate below */ + animviz_free_motionpath_cache(mpath); + } + } + } + else { + /* create a new motionpath, and assign it */ + mpath = MEM_callocN(sizeof(bMotionPath), "bMotionPath"); + *dst = mpath; + } + + /* set settings from the viz settings */ + mpath->start_frame = avs->path_sf; + mpath->end_frame = avs->path_ef; + + mpath->length = mpath->end_frame - mpath->start_frame; + + if (avs->path_bakeflag & MOTIONPATH_BAKE_HEADS) { + mpath->flag |= MOTIONPATH_FLAG_BHEAD; + } + else { + mpath->flag &= ~MOTIONPATH_FLAG_BHEAD; + } + + /* set default custom values */ + mpath->color[0] = 1.0; /* Red */ + mpath->color[1] = 0.0; + mpath->color[2] = 0.0; + + mpath->line_thickness = 2; + mpath->flag |= MOTIONPATH_FLAG_LINES; /* draw lines by default */ + + /* allocate a cache */ + mpath->points = MEM_callocN(sizeof(bMotionPathVert) * mpath->length, "bMotionPathVerts"); + + /* tag viz settings as currently having some path(s) which use it */ + avs->path_bakeflag |= MOTIONPATH_BAKE_HAS_PATHS; + + /* return it */ + return mpath; +} diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 9c88ffb5d52..daf364432f4 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -51,8 +51,7 @@ #include "DNA_scene_types.h" #include "BKE_action.h" -#include "BKE_anim.h" -#include "BKE_animsys.h" +#include "BKE_anim_visualization.h" #include "BKE_armature.h" #include "BKE_constraint.h" #include "BKE_curve.h" @@ -191,7 +190,7 @@ bArmature *BKE_armature_from_object(Object *ob) int BKE_armature_bonelist_count(ListBase *lb) { int i = 0; - for (Bone *bone = lb->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { i += 1 + BKE_armature_bonelist_count(&bone->childbase); } @@ -304,7 +303,7 @@ static void armature_transform_recurse(ListBase *bonebase, const Bone *bone_parent, const float arm_mat_parent_inv[4][4]) { - for (Bone *bone = bonebase->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, bonebase) { /* Store the initial bone roll in a matrix, this is needed even for child bones * so any change in head/tail doesn't cause the roll to change. @@ -425,7 +424,7 @@ Bone *BKE_armature_find_bone_name(bArmature *arm, const char *name) static void armature_bone_from_name_insert_recursive(GHash *bone_hash, ListBase *lb) { - for (Bone *bone = lb->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, lb) { BLI_ghash_insert(bone_hash, bone->name, bone); armature_bone_from_name_insert_recursive(bone_hash, &bone->childbase); } @@ -475,7 +474,7 @@ bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag) static void armature_refresh_layer_used_recursive(bArmature *arm, ListBase *bones) { - for (Bone *bone = bones->first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, bones) { arm->layer_used |= bone->layer; armature_refresh_layer_used_recursive(arm, &bone->childbase); } @@ -2523,7 +2522,7 @@ void BKE_armature_where_is(bArmature *arm) /* if bone layer is protected, copy the data from from->pose * when used with linked libraries this copies from the linked pose into the local pose */ -static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected) +static void pose_proxy_sync(Object *ob, Object *from, int layer_protected) { bPose *pose = ob->pose, *frompose = from->pose; bPoseChannel *pchan, *pchanp; @@ -2702,7 +2701,7 @@ static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int */ void BKE_pose_clear_pointers(bPose *pose) { - for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { pchan->bone = NULL; pchan->child = NULL; } @@ -2710,7 +2709,7 @@ void BKE_pose_clear_pointers(bPose *pose) void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose) { - for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { pchan->bone = BKE_armature_find_bone_name(armature, pchan->name); } } @@ -2786,7 +2785,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ * using COW tag was working this morning, but not anymore... */ if (ob->proxy != NULL && (ob->id.tag & LIB_TAG_NO_MAIN) == 0) { BKE_object_copy_proxy_drivers(ob, ob->proxy); - pose_proxy_synchronize(ob, ob->proxy, arm->layer_protected); + pose_proxy_sync(ob, ob->proxy, arm->layer_protected); } BKE_pose_update_constraint_flags(pose); /* for IK detection for example */ diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index e51b9ea85d1..d0a5e4348b9 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -35,7 +35,7 @@ #include "DNA_scene_types.h" #include "BKE_action.h" -#include "BKE_anim.h" +#include "BKE_anim_path.h" #include "BKE_armature.h" #include "BKE_curve.h" #include "BKE_displist.h" diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 70ab52828f2..b3a4de02451 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -182,7 +182,7 @@ static void userdef_free_keymaps(UserDef *userdef) { for (wmKeyMap *km = userdef->user_keymaps.first, *km_next; km; km = km_next) { km_next = km->next; - for (wmKeyMapDiffItem *kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) { if (kmdi->add_item) { keymap_item_free(kmdi->add_item); MEM_freeN(kmdi->add_item); @@ -193,7 +193,7 @@ static void userdef_free_keymaps(UserDef *userdef) } } - for (wmKeyMapItem *kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { keymap_item_free(kmi); } @@ -250,7 +250,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts) userdef_free_addons(userdef); if (clear_fonts) { - for (uiFont *font = userdef->uifonts.first; font; font = font->next) { + LISTBASE_FOREACH (uiFont *, font, &userdef->uifonts) { BLF_unload_id(font->blf_id); } BLF_default_set(-1); diff --git a/source/blender/blenkernel/intern/blender_user_menu.c b/source/blender/blenkernel/intern/blender_user_menu.c index ad34ef03e04..edd89357fd5 100644 --- a/source/blender/blenkernel/intern/blender_user_menu.c +++ b/source/blender/blenkernel/intern/blender_user_menu.c @@ -38,7 +38,7 @@ bUserMenu *BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context) { - for (bUserMenu *um = lb->first; um; um = um->next) { + LISTBASE_FOREACH (bUserMenu *, um, lb) { if ((space_type == um->space_type) && (STREQ(context, um->context))) { return um; } diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 6bf47a8c280..d862132480a 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -345,7 +345,7 @@ static void setup_app_data(bContext *C, wmWindowManager *wm = bmain->wm.first; if (wm) { - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (win->scene && win->scene != curscene) { BKE_scene_set_background(bmain, win->scene); } diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 605fba18d89..d23b643ce70 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -39,7 +39,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_cachefile.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 30c2822e08b..71a2b6f703a 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -38,7 +38,6 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" #include "BKE_camera.h" #include "BKE_idtype.h" #include "BKE_layer.h" @@ -913,7 +912,7 @@ static Object *camera_multiview_advanced(const Scene *scene, Object *camera, con name[0] = '\0'; /* we need to take the better match, thus the len_suffix_max test */ - for (const SceneRenderView *srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (const SceneRenderView *, srv, &scene->r.views) { const int len_suffix = strlen(srv->suffix); if ((len_suffix < len_suffix_max) || (len_name < len_suffix)) { diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index d39df4cc6a3..83a6949430e 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -106,10 +106,10 @@ static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons BLI_listbase_clear(&collection_dst->children); BLI_listbase_clear(&collection_dst->parents); - for (CollectionChild *child = collection_src->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection_src->children) { collection_child_add(collection_dst, child->collection, flag, false); } - for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection_src->gobject) { collection_object_add(bmain, collection_dst, cob->ob, flag, false); } } @@ -223,9 +223,8 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) } else { /* Link child collections into parent collection. */ - for (CollectionChild *child = collection->children.first; child; child = child->next) { - for (CollectionParent *cparent = collection->parents.first; cparent; - cparent = cparent->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; collection_child_add(parent, child->collection, 0, true); } @@ -234,8 +233,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) CollectionObject *cob = collection->gobject.first; while (cob != NULL) { /* Link child object into parent collections. */ - for (CollectionParent *cparent = collection->parents.first; cparent; - cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; collection_object_add(bmain, parent, cob->ob, 0, true); } @@ -305,7 +303,7 @@ static Collection *collection_duplicate_recursive(Main *bmain, if (do_objects) { /* We can loop on collection_old's objects, that list is currently identical the collection_new * objects, and won't be changed here. */ - for (CollectionObject *cob = collection_old->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection_old->gobject) { Object *ob_old = cob->ob; Object *ob_new = (Object *)ob_old->id.newid; @@ -321,7 +319,7 @@ static Collection *collection_duplicate_recursive(Main *bmain, /* We can loop on collection_old's children, * that list is currently identical the collection_new' children, and won't be changed here. */ - for (CollectionChild *child = collection_old->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection_old->children) { Collection *child_collection_old = child->collection; collection_duplicate_recursive( @@ -440,7 +438,7 @@ static void collection_object_cache_fill(ListBase *lb, Collection *collection, i { int child_restrict = collection->flag | parent_restrict; - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { Base *base = BLI_findptr(lb, cob->ob, offsetof(Base, object)); if (base == NULL) { @@ -460,7 +458,7 @@ static void collection_object_cache_fill(ListBase *lb, Collection *collection, i } } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { collection_object_cache_fill(lb, child->collection, child_restrict); } } @@ -487,7 +485,7 @@ static void collection_object_cache_free(Collection *collection) collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; BLI_freelistN(&collection->object_cache); - for (CollectionParent *parent = collection->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { collection_object_cache_free(parent->collection); } } @@ -645,8 +643,7 @@ static void collection_tag_update_parent_recursive(Main *bmain, DEG_id_tag_update_ex(bmain, &collection->id, flag); - for (CollectionParent *collection_parent = collection->parents.first; collection_parent; - collection_parent = collection_parent->next) { + LISTBASE_FOREACH (CollectionParent *, collection_parent, &collection->parents) { if (collection_parent->collection->flag & COLLECTION_IS_MASTER) { /* We don't care about scene/master collection here. */ continue; @@ -952,7 +949,7 @@ bool BKE_collection_is_in_scene(Collection *collection) return true; } - for (CollectionParent *cparent = collection->parents.first; cparent; cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { if (BKE_collection_is_in_scene(cparent->collection)) { return true; } @@ -977,7 +974,7 @@ bool BKE_collection_find_cycle(Collection *new_ancestor, Collection *collection) return true; } - for (CollectionParent *parent = new_ancestor->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &new_ancestor->parents) { if (BKE_collection_find_cycle(parent->collection, collection)) { return true; } @@ -993,7 +990,7 @@ static CollectionChild *collection_find_child(Collection *parent, Collection *co static bool collection_find_child_recursive(Collection *parent, Collection *collection) { - for (CollectionChild *child = parent->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &parent->children) { if (child->collection == collection) { return true; } @@ -1168,7 +1165,7 @@ static Collection *collection_from_index_recursive(Collection *collection, (*index_current)++; - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { Collection *nested = collection_from_index_recursive(child->collection, index, index_current); if (nested != NULL) { return nested; @@ -1197,7 +1194,7 @@ static bool collection_objects_select(ViewLayer *view_layer, Collection *collect return false; } - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base) { @@ -1216,7 +1213,7 @@ static bool collection_objects_select(ViewLayer *view_layer, Collection *collect } } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { if (collection_objects_select(view_layer, collection, deselect)) { changed = true; } @@ -1289,8 +1286,7 @@ bool BKE_collection_move(Main *bmain, GHash *view_layer_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection( view_layer, collection); @@ -1352,7 +1348,7 @@ static void scene_collection_callback(Collection *collection, { callback(collection, data); - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { scene_collection_callback(child->collection, callback, data); } } diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 9230746cd1d..7cc40007e26 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -1380,7 +1380,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, int num = 0; Object **objects = MEM_callocN(sizeof(Object *) * maxnum, __func__); - for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); @@ -1418,7 +1418,7 @@ ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collecti return NULL; } - for (CollisionRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 04adb642fc0..c91bf4e7f5b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -52,7 +52,7 @@ #include "DNA_tracking_types.h" #include "BKE_action.h" -#include "BKE_anim.h" /* for the curve calculation part */ +#include "BKE_anim_path.h" #include "BKE_armature.h" #include "BKE_bvhutils.h" #include "BKE_cachefile.h" @@ -2513,7 +2513,7 @@ static void armdef_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targ /* Process all targets. This can't use ct->matrix, as armdef_get_tarmat is not * called in solve for efficiency because the constraint needs bone data anyway. */ - for (bConstraintTarget *ct = targets->first; ct; ct = ct->next) { + LISTBASE_FOREACH (bConstraintTarget *, ct, targets) { if (ct->weight <= 0.0f) { continue; } @@ -5497,7 +5497,7 @@ void BKE_constraints_active_set(ListBase *list, bConstraint *con) static bConstraint *constraint_list_find_from_target(ListBase *constraints, bConstraintTarget *tgt) { - for (bConstraint *con = constraints->first; con; con = con->next) { + LISTBASE_FOREACH (bConstraint *, con, constraints) { ListBase *targets = NULL; if (con->type == CONSTRAINT_TYPE_PYTHON) { @@ -5531,7 +5531,7 @@ bConstraint *BKE_constraint_find_from_target(Object *ob, } if (ob->pose != NULL) { - for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { result = constraint_list_find_from_target(&pchan->constraints, tgt); if (result != NULL) { diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index f6db23111a1..8de12139306 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -278,8 +278,8 @@ static void *ctx_wm_python_context_get(const bContext *C, static int ctx_data_get(bContext *C, const char *member, bContextDataResult *result) { - bScreen *sc; - ScrArea *sa; + bScreen *screen; + ScrArea *area; ARegion *region; int done = 0, recursion = C->data.recursion; int ret = 0; @@ -327,17 +327,17 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res } } } - if (done != 1 && recursion < 3 && (sa = CTX_wm_area(C))) { + if (done != 1 && recursion < 3 && (area = CTX_wm_area(C))) { C->data.recursion = 3; - if (sa->type && sa->type->context) { - ret = sa->type->context(C, member, result); + if (area->type && area->type->context) { + ret = area->type->context(C, member, result); if (ret) { done = -(-ret | -done); } } } - if (done != 1 && recursion < 4 && (sc = CTX_wm_screen(C))) { - bContextDataCallback cb = sc->context; + if (done != 1 && recursion < 4 && (screen = CTX_wm_screen(C))) { + bContextDataCallback cb = screen->context; C->data.recursion = 4; if (cb) { ret = cb(C, member, result); @@ -543,8 +543,8 @@ ListBase CTX_data_dir_get_ex(const bContext *C, { bContextDataResult result; ListBase lb; - bScreen *sc; - ScrArea *sa; + bScreen *screen; + ScrArea *area; ARegion *region; int a; @@ -588,9 +588,9 @@ ListBase CTX_data_dir_get_ex(const bContext *C, } } } - if ((sa = CTX_wm_area(C)) && sa->type && sa->type->context) { + if ((area = CTX_wm_area(C)) && area->type && area->type->context) { memset(&result, 0, sizeof(result)); - sa->type->context(C, "", &result); + area->type->context(C, "", &result); if (result.dir) { for (a = 0; result.dir[a]; a++) { @@ -598,8 +598,8 @@ ListBase CTX_data_dir_get_ex(const bContext *C, } } } - if ((sc = CTX_wm_screen(C)) && sc->context) { - bContextDataCallback cb = sc->context; + if ((screen = CTX_wm_screen(C)) && screen->context) { + bContextDataCallback cb = screen->context; memset(&result, 0, sizeof(result)); cb(C, "", &result); @@ -716,8 +716,8 @@ ScrArea *CTX_wm_area(const bContext *C) SpaceLink *CTX_wm_space_data(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - return (sa) ? sa->spacedata.first : NULL; + ScrArea *area = CTX_wm_area(C); + return (area) ? area->spacedata.first : NULL; } ARegion *CTX_wm_region(const bContext *C) @@ -757,19 +757,19 @@ struct ReportList *CTX_wm_reports(const bContext *C) View3D *CTX_wm_view3d(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_VIEW3D) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_VIEW3D) { + return area->spacedata.first; } return NULL; } RegionView3D *CTX_wm_region_view3d(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); + ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); - if (sa && sa->spacetype == SPACE_VIEW3D) { + if (area && area->spacetype == SPACE_VIEW3D) { if (region && region->regiontype == RGN_TYPE_WINDOW) { return region->regiondata; } @@ -779,135 +779,135 @@ RegionView3D *CTX_wm_region_view3d(const bContext *C) struct SpaceText *CTX_wm_space_text(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_TEXT) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_TEXT) { + return area->spacedata.first; } return NULL; } struct SpaceConsole *CTX_wm_space_console(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_CONSOLE) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_CONSOLE) { + return area->spacedata.first; } return NULL; } struct SpaceImage *CTX_wm_space_image(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_IMAGE) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_IMAGE) { + return area->spacedata.first; } return NULL; } struct SpaceProperties *CTX_wm_space_properties(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_PROPERTIES) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_PROPERTIES) { + return area->spacedata.first; } return NULL; } struct SpaceFile *CTX_wm_space_file(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_FILE) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_FILE) { + return area->spacedata.first; } return NULL; } struct SpaceSeq *CTX_wm_space_seq(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_SEQ) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_SEQ) { + return area->spacedata.first; } return NULL; } struct SpaceOutliner *CTX_wm_space_outliner(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_OUTLINER) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_OUTLINER) { + return area->spacedata.first; } return NULL; } struct SpaceNla *CTX_wm_space_nla(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_NLA) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_NLA) { + return area->spacedata.first; } return NULL; } struct SpaceNode *CTX_wm_space_node(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_NODE) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_NODE) { + return area->spacedata.first; } return NULL; } struct SpaceGraph *CTX_wm_space_graph(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_GRAPH) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_GRAPH) { + return area->spacedata.first; } return NULL; } struct SpaceAction *CTX_wm_space_action(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_ACTION) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_ACTION) { + return area->spacedata.first; } return NULL; } struct SpaceInfo *CTX_wm_space_info(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_INFO) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_INFO) { + return area->spacedata.first; } return NULL; } struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_USERPREF) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_USERPREF) { + return area->spacedata.first; } return NULL; } struct SpaceClip *CTX_wm_space_clip(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_CLIP) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_CLIP) { + return area->spacedata.first; } return NULL; } struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C) { - ScrArea *sa = CTX_wm_area(C); - if (sa && sa->spacetype == SPACE_TOPBAR) { - return sa->spacedata.first; + ScrArea *area = CTX_wm_area(C); + if (area && area->spacetype == SPACE_TOPBAR) { + return area->spacedata.first; } return NULL; } diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index ba1c75196db..5b463059f18 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -46,7 +46,6 @@ #include "DNA_scene_types.h" #include "DNA_vfont_types.h" -#include "BKE_animsys.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_font.h" @@ -4613,7 +4612,7 @@ void BKE_nurb_direction_switch(Nurb *nu) void BKE_curve_nurbs_vert_coords_get(ListBase *lb, float (*vert_coords)[3], int vert_len) { float *co = vert_coords[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; for (int i = 0; i < nu->pntsu; i++, bezt++) { @@ -4693,7 +4692,7 @@ void BKE_curve_nurbs_vert_coords_apply(ListBase *lb, { const float *co = vert_coords[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; @@ -4731,7 +4730,7 @@ float (*BKE_curve_nurbs_key_vert_coords_alloc(ListBase *lb, float *key, int *r_v float(*cos)[3] = MEM_malloc_arrayN(vert_len, sizeof(*cos), __func__); float *co = cos[0]; - for (Nurb *nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; @@ -5169,7 +5168,7 @@ bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3]) use_radius = false; } /* Do bounding box based on splines. */ - for (Nurb *nu = nurb_lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, nurb_lb) { BKE_nurb_minmax(nu, use_radius, min, max); } const bool result = (BLI_listbase_is_empty(nurb_lb) == false); diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index dc2f603aa5c..907e7eb66ec 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -42,7 +42,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_anim.h" +#include "BKE_anim_path.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_font.h" diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 1054988f22f..4c78c88d168 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -46,7 +46,6 @@ #include "DNA_scene_types.h" #include "DNA_texture_types.h" -#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_bvhutils.h" /* bvh tree */ #include "BKE_collection.h" diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index f7ddc4385ac..e1e818a5a34 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -49,7 +49,7 @@ #include "PIL_time.h" -#include "BKE_anim.h" /* needed for where_on_path */ +#include "BKE_anim_path.h" /* needed for where_on_path */ #include "BKE_bvhutils.h" #include "BKE_collection.h" #include "BKE_collision.h" @@ -247,7 +247,7 @@ ListBase *BKE_effector_relations_create(Depsgraph *depsgraph, add_effector_relation(relations, ob, NULL, ob->pd); } - for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) { + LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { ParticleSettings *part = psys->part; if (psys_check_enabled(ob, psys, for_render)) { @@ -286,7 +286,7 @@ ListBase *BKE_effectors_create(Depsgraph *depsgraph, return NULL; } - for (EffectorRelation *relation = relations->first; relation; relation = relation->next) { + LISTBASE_FOREACH (EffectorRelation *, relation, relations) { /* Get evaluated object. */ Object *ob = (Object *)DEG_get_evaluated_id(depsgraph, &relation->ob->id); @@ -329,7 +329,7 @@ ListBase *BKE_effectors_create(Depsgraph *depsgraph, void BKE_effectors_free(ListBase *lb) { if (lb) { - for (EffectorCache *eff = lb->first; eff; eff = eff->next) { + LISTBASE_FOREACH (EffectorCache *, eff, lb) { if (eff->guide_data) { MEM_freeN(eff->guide_data); } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 3e21fd26875..cd933553d8d 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -45,6 +45,7 @@ #include "BLT_translation.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_constraint.h" @@ -1943,7 +1944,7 @@ void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars) BLI_assert(BLI_listbase_is_empty(dst_vars)); BLI_duplicatelist(dst_vars, src_vars); - for (DriverVar *dvar = dst_vars->first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, dst_vars) { /* need to go over all targets so that we don't leave any dangling paths */ DRIVER_TARGETS_LOOPER_BEGIN (dvar) { /* make a copy of target's rna path if available */ @@ -2170,7 +2171,7 @@ static ExprPyLike_Parsed *driver_compile_simple_expr_impl(ChannelDriver *driver) names[VAR_INDEX_FRAME] = "frame"; - for (DriverVar *dvar = driver->variables.first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { names[i++] = dvar->name; } @@ -2195,7 +2196,7 @@ static bool driver_evaluate_simple_expr(ChannelDriver *driver, vars[VAR_INDEX_FRAME] = time; - for (DriverVar *dvar = driver->variables.first; dvar; dvar = dvar->next) { + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { vars[i++] = driver_get_variable_value(driver, dvar); } diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index b095e6dbeec..cbb933725eb 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -1232,52 +1232,31 @@ static void update_obstacles(Depsgraph *depsgraph, continue; } - /* Length of one adaptive frame. If using adaptive stepping, length is smaller than actual - * frame length */ - float adaptframe_length = time_per_frame / frame_length; - /* Adaptive frame length as percentage */ - CLAMP(adaptframe_length, 0.0f, 1.0f); - - /* More splitting because of emission subframe: If no subframes present, sample_size is 1. */ - float sample_size = 1.0f / (float)(subframes + 1); - /* First frame cannot have any subframes because there is (obviously) no previous frame from * where subframes could come from. */ if (is_first_frame) { subframes = 0; } - int subframe; + /* More splitting because of emission subframe: If no subframes present, sample_size is 1. */ + float sample_size = 1.0f / (float)(subframes + 1); float subframe_dt = dt * sample_size; /* Emission loop. When not using subframes this will loop only once. */ - for (subframe = subframes; subframe >= 0; subframe--) { + for (int subframe = 0; subframe <= subframes; subframe++) { /* Temporary emission map used when subframes are enabled, i.e. at least one subframe. */ FluidObjectBB bb_temp = {NULL}; /* Set scene time */ /* Handle emission subframe */ - if (subframe > 0 && !is_first_frame) { - scene->r.subframe = adaptframe_length - - sample_size * (float)(subframe) * (dt / frame_length); + if (subframe < subframes || time_per_frame + dt + FLT_EPSILON < frame_length) { + scene->r.subframe = (time_per_frame + (subframe + 1.0f) * subframe_dt) / frame_length; scene->r.cfra = frame - 1; } - /* Last frame in this loop (subframe == suframes). Can be real end frame or in between - * frames (adaptive frame). */ else { - /* Handle adaptive subframe (ie has subframe fraction). Need to set according scene - * subframe parameter. */ - if (time_per_frame < frame_length) { - scene->r.subframe = adaptframe_length; - scene->r.cfra = frame - 1; - } - /* Handle absolute endframe (ie no subframe fraction). Need to set the scene subframe - * parameter to 0 and advance current scene frame. */ - else { - scene->r.subframe = 0.0f; - scene->r.cfra = frame; - } + scene->r.subframe = 0.0f; + scene->r.cfra = frame; } /* Sanity check: subframe portion must be between 0 and 1. */ CLAMP(scene->r.subframe, 0.0f, 1.0f); @@ -2768,53 +2747,31 @@ static void update_flowsfluids(struct Depsgraph *depsgraph, continue; } - /* Length of one adaptive frame. If using adaptive stepping, length is smaller than actual - * frame length */ - float adaptframe_length = time_per_frame / frame_length; - /* Adaptive frame length as percentage */ - CLAMP(adaptframe_length, 0.0f, 1.0f); - - /* More splitting because of emission subframe: If no subframes present, sample_size is 1. */ - float sample_size = 1.0f / (float)(subframes + 1); - /* First frame cannot have any subframes because there is (obviously) no previous frame from * where subframes could come from. */ if (is_first_frame) { subframes = 0; } - int subframe; + /* More splitting because of emission subframe: If no subframes present, sample_size is 1. */ + float sample_size = 1.0f / (float)(subframes + 1); float subframe_dt = dt * sample_size; /* Emission loop. When not using subframes this will loop only once. */ - for (subframe = subframes; subframe >= 0; subframe--) { - + for (int subframe = 0; subframe <= subframes; subframe++) { /* Temporary emission map used when subframes are enabled, i.e. at least one subframe. */ FluidObjectBB bb_temp = {NULL}; /* Set scene time */ - /* Handle emission subframe */ - if (subframe > 0 && !is_first_frame) { - scene->r.subframe = adaptframe_length - - sample_size * (float)(subframe) * (dt / frame_length); + if (subframe < subframes || time_per_frame + dt + FLT_EPSILON < frame_length) { + scene->r.subframe = (time_per_frame + (subframe + 1.0f) * subframe_dt) / frame_length; scene->r.cfra = frame - 1; } - /* Last frame in this loop (subframe == suframes). Can be real end frame or in between - * frames (adaptive frame). */ else { - /* Handle adaptive subframe (ie has subframe fraction). Need to set according scene - * subframe parameter. */ - if (time_per_frame < frame_length) { - scene->r.subframe = adaptframe_length; - scene->r.cfra = frame - 1; - } - /* Handle absolute endframe (ie no subframe fraction). Need to set the scene subframe - * parameter to 0 and advance current scene frame. */ - else { - scene->r.subframe = 0.0f; - scene->r.cfra = frame; - } + scene->r.subframe = 0.0f; + scene->r.cfra = frame; } + /* Sanity check: subframe portion must be between 0 and 1. */ CLAMP(scene->r.subframe, 0.0f, 1.0f); # ifdef DEBUG_PRINT @@ -3716,8 +3673,14 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, uint numobj = 0; FluidModifierData *mmd_parent = NULL; - bool is_startframe; + bool is_startframe, has_advanced; is_startframe = (scene_framenr == mds->cache_frame_start); + has_advanced = (scene_framenr == mmd->time + 1); + + /* Do not process modifier if current frame is out of cache range. */ + if (scene_framenr < mds->cache_frame_start || scene_framenr > mds->cache_frame_end) { + return; + } /* Reset fluid if no fluid present. */ if (!mds->fluid) { @@ -3809,6 +3772,20 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, read_cache = false; bake_cache = baking_data || baking_noise || baking_mesh || baking_particles || baking_guide; + bool next_data, next_noise, next_mesh, next_particles, next_guide; + next_data = manta_has_data(mds->fluid, mmd, scene_framenr + 1); + next_noise = manta_has_noise(mds->fluid, mmd, scene_framenr + 1); + next_mesh = manta_has_mesh(mds->fluid, mmd, scene_framenr + 1); + next_particles = manta_has_particles(mds->fluid, mmd, scene_framenr + 1); + next_guide = manta_has_guiding(mds->fluid, mmd, scene_framenr + 1, guide_parent); + + bool prev_data, prev_noise, prev_mesh, prev_particles, prev_guide; + prev_data = manta_has_data(mds->fluid, mmd, scene_framenr - 1); + prev_noise = manta_has_noise(mds->fluid, mmd, scene_framenr - 1); + prev_mesh = manta_has_mesh(mds->fluid, mmd, scene_framenr - 1); + prev_particles = manta_has_particles(mds->fluid, mmd, scene_framenr - 1); + prev_guide = manta_has_guiding(mds->fluid, mmd, scene_framenr - 1, guide_parent); + bool with_gdomain; with_gdomain = (mds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN); @@ -3867,6 +3844,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, default: /* Always trying to read the cache in replay mode. */ read_cache = true; + bake_cache = false; break; } @@ -3951,7 +3929,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, BKE_fluid_reallocate_fluid(mds, mds->res, 1); } /* Read data cache */ - if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { + if (!baking_data && !baking_particles && !baking_mesh && next_data) { has_data = manta_update_smoke_structures(mds->fluid, mmd, data_frame); } else { @@ -3976,18 +3954,21 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, break; case FLUID_DOMAIN_CACHE_REPLAY: default: - baking_data = !has_data; + baking_data = !has_data && (is_startframe || prev_data); if (with_smoke && with_noise) { - baking_noise = !has_noise; + baking_noise = !has_noise && (is_startframe || prev_noise); } if (with_liquid && with_mesh) { - baking_mesh = !has_mesh; + baking_mesh = !has_mesh && (is_startframe || prev_mesh); } if (with_liquid && with_particles) { - baking_particles = !has_particles; + baking_particles = !has_particles && (is_startframe || prev_particles); } - bake_cache = baking_data || baking_noise || baking_mesh || baking_particles; + /* Only bake if time advanced by one frame. */ + if (is_startframe || has_advanced) { + bake_cache = baking_data || baking_noise || baking_mesh || baking_particles; + } break; } @@ -4471,6 +4452,18 @@ void BKE_fluid_particle_system_destroy(struct Object *ob, const int particle_typ * Use for versioning, even when fluids are disabled. * \{ */ +void BKE_fluid_cache_startframe_set(FluidDomainSettings *settings, int value) +{ + settings->cache_frame_start = (value > settings->cache_frame_end) ? settings->cache_frame_end : + value; +} + +void BKE_fluid_cache_endframe_set(FluidDomainSettings *settings, int value) +{ + settings->cache_frame_end = (value < settings->cache_frame_start) ? settings->cache_frame_start : + value; +} + void BKE_fluid_cachetype_mesh_set(FluidDomainSettings *settings, int cache_mesh_format) { if (cache_mesh_format == settings->cache_mesh_format) { diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 1d5a908e226..c85283e3653 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1358,7 +1358,7 @@ uint evaluate_fmodifiers_storage_size_per_modifier(ListBase *modifiers) uint max_size = 0; - for (FModifier *fcm = modifiers->first; fcm; fcm = fcm->next) { + LISTBASE_FOREACH (FModifier *, fcm, modifiers) { const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); if (fmi == NULL) { diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index e25603e0af5..e8ff2ccc1af 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -48,7 +48,7 @@ #include "DNA_packedFile_types.h" #include "DNA_vfont_types.h" -#include "BKE_anim.h" +#include "BKE_anim_path.h" #include "BKE_curve.h" #include "BKE_font.h" #include "BKE_global.h" @@ -734,7 +734,7 @@ static bool vfont_to_curve(Object *ob, float twidth = 0, maxlen = 0; int i, slen, j; int curbox; - int selstart, selend; + int selstart = 0, selend = 0; int cnr = 0, lnr = 0, wsnr = 0; const char32_t *mem = NULL; char32_t ascii; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index fc7f15348bc..a0fa07f4a41 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -541,7 +541,12 @@ bGPDstroke *BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness) gps->flag = GP_STROKE_3DSPACE; gps->totpoints = totpoints; - gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); + if (gps->totpoints > 0) { + gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); + } + else { + gps->points = NULL; + } /* initialize triangle memory to dummy data */ gps->triangles = NULL; @@ -639,7 +644,7 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src) /* copy strokes */ BLI_listbase_clear(&gpf_dst->strokes); - for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) { + LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) { /* make copy of source stroke */ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); BLI_addtail(&gpf_dst->strokes, gps_dst); @@ -660,7 +665,7 @@ void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src, struct bGPDframe *gpf_ds /* copy strokes */ BLI_listbase_clear(&gpf_dst->strokes); - for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) { + LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) { /* make copy of source stroke */ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); BLI_addtail(&gpf_dst->strokes, gps_dst); diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 6bdcc9cfbcb..874672f4a73 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -1685,7 +1685,7 @@ static Collection *gpencil_get_parent_collection(Scene *scene, Object *ob) { Collection *mycol = NULL; FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) { - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { if ((mycol == NULL) && (cob->ob == ob)) { mycol = collection; } @@ -1976,7 +1976,7 @@ void BKE_gpencil_convert_curve(Main *bmain, bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_COPY); /* Read all splines of the curve and create a stroke for each. */ - for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { gpencil_convert_spline(bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, gpf, nu); } diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c index e17c6a00144..5cdb7761540 100644 --- a/source/blender/blenkernel/intern/hair.c +++ b/source/blender/blenkernel/intern/hair.c @@ -30,7 +30,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_hair.h" diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 554b8d93db3..5530a126ffc 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -800,7 +800,7 @@ void IDP_RelinkProperty(struct IDProperty *prop) switch (prop->type) { case IDP_GROUP: { - for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { + LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { IDP_RelinkProperty(loop); } break; diff --git a/source/blender/blenkernel/intern/idprop_utils.c b/source/blender/blenkernel/intern/idprop_utils.c index a7dd6afd10d..f8a1113f69b 100644 --- a/source/blender/blenkernel/intern/idprop_utils.c +++ b/source/blender/blenkernel/intern/idprop_utils.c @@ -22,6 +22,7 @@ #include <string.h> #include "BLI_dynstr.h" +#include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_utildefines.h" @@ -166,7 +167,7 @@ static void idp_repr_fn_recursive(struct ReprState *state, const IDProperty *pro } case IDP_GROUP: { STR_APPEND_STR("{"); - for (const IDProperty *subprop = prop->data.group.first; subprop; subprop = subprop->next) { + LISTBASE_FOREACH (const IDProperty *, subprop, &prop->data.group) { if (subprop != prop->data.group.first) { STR_APPEND_STR(", "); } diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index b7fc167cf33..5a6e8f532c9 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -124,10 +124,10 @@ const IDTypeInfo *BKE_idtype_get_info_from_id(const ID *id) return BKE_idtype_get_info_from_idcode(GS(id->name)); } -static const IDTypeInfo *idtype_get_info_from_name(const char *str) +static const IDTypeInfo *idtype_get_info_from_name(const char *idtype_name) { for (int i = ARRAY_SIZE(id_types); i--;) { - if (id_types[i] != NULL && STREQ(str, id_types[i]->name)) { + if (id_types[i] != NULL && STREQ(idtype_name, id_types[i]->name)) { return id_types[i]; } } @@ -179,14 +179,14 @@ const char *BKE_idtype_idcode_to_translation_context(const short idcode) } /** - * Convert a name into an idcode (ie. ID_SCE) + * Convert an IDType name into an idcode (ie. ID_SCE) * - * \param name: The name to convert. - * \return The code for the name, or 0 if invalid. + * \param idtype_name: The IDType's 'user visible name' to convert. + * \return The idcode for the name, or 0 if invalid. */ -short BKE_idtype_idcode_from_name(const char *name) +short BKE_idtype_idcode_from_name(const char *idtype_name) { - const IDTypeInfo *id_type = idtype_get_info_from_name(name); + const IDTypeInfo *id_type = idtype_get_info_from_name(idtype_name); BLI_assert(id_type); return id_type != NULL ? id_type->id_code : 0; } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 5dca9bf2ac5..f58e7c06d7f 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -3101,7 +3101,7 @@ static void image_walk_ntree_all_users( { switch (ntree->type) { case NTREE_SHADER: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id) { if (node->type == SH_NODE_TEX_IMAGE) { NodeTexImage *tex = node->storage; @@ -3117,7 +3117,7 @@ static void image_walk_ntree_all_users( } break; case NTREE_TEXTURE: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id && node->type == TEX_NODE_IMAGE) { Image *ima = (Image *)node->id; ImageUser *iuser = node->storage; @@ -3126,7 +3126,7 @@ static void image_walk_ntree_all_users( } break; case NTREE_COMPOSIT: - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id && node->type == CMP_NODE_IMAGE) { Image *ima = (Image *)node->id; ImageUser *iuser = node->storage; @@ -3189,19 +3189,19 @@ static void image_walk_id_all_users( } case ID_CA: { Camera *cam = (Camera *)id; - for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) { + LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) { callback(bgpic->ima, NULL, &bgpic->iuser, customdata); } break; } case ID_WM: { wmWindowManager *wm = (wmWindowManager *)id; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - if (sa->spacetype == SPACE_IMAGE) { - SpaceImage *sima = sa->spacedata.first; + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + if (area->spacetype == SPACE_IMAGE) { + SpaceImage *sima = area->spacedata.first; callback(sima->image, NULL, &sima->iuser, customdata); } } @@ -3761,7 +3761,7 @@ static void image_init_multilayer_multiview(Image *ima, RenderResult *rr) BKE_image_free_views(ima); if (rr) { - for (RenderView *rv = rr->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &rr->views) { ImageView *iv = MEM_callocN(sizeof(ImageView), "Viewer Image View"); STRNCPY(iv->name, rv->name); BLI_addtail(&ima->views, iv); diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c index bd570c9688b..b2e0f234f1e 100644 --- a/source/blender/blenkernel/intern/image_save.c +++ b/source/blender/blenkernel/intern/image_save.c @@ -54,13 +54,13 @@ void BKE_image_save_options_init(ImageSaveOptions *opts, Main *bmain, Scene *sce } static void image_save_post(ReportList *reports, - Main *bmain, Image *ima, ImBuf *ibuf, int ok, ImageSaveOptions *opts, int save_copy, - const char *filepath) + const char *filepath, + bool *r_colorspace_changed) { if (!ok) { BKE_reportf(reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); @@ -114,7 +114,7 @@ static void image_save_post(ReportList *reports, IMB_colormanagement_colorspace_from_ibuf_ftype(&ima->colorspace_settings, ibuf); if (!BKE_color_managed_colorspace_settings_equals(&old_colorspace_settings, &ima->colorspace_settings)) { - BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE); + *r_colorspace_changed = true; } } @@ -138,8 +138,11 @@ static void imbuf_save_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf) * \note ``ima->name`` and ``ibuf->name`` should end up the same. * \note for multiview the first ``ibuf`` is important to get the settings. */ -static bool image_save_single( - ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, ImageSaveOptions *opts) +static bool image_save_single(ReportList *reports, + Image *ima, + ImageUser *iuser, + ImageSaveOptions *opts, + bool *r_colorspace_changed) { void *lock; ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock); @@ -223,7 +226,7 @@ static bool image_save_single( if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { /* save render result */ ok = RE_WriteRenderResult(reports, rr, opts->filepath, imf, NULL, layer); - image_save_post(reports, bmain, ima, ibuf, ok, opts, true, opts->filepath); + image_save_post(reports, ima, ibuf, ok, opts, true, opts->filepath, r_colorspace_changed); BKE_image_release_ibuf(ima, ibuf, lock); } /* regular mono pipeline */ @@ -237,8 +240,14 @@ static bool image_save_single( ok = BKE_imbuf_write_as(colormanaged_ibuf, opts->filepath, imf, save_copy); imbuf_save_post(ibuf, colormanaged_ibuf); } - image_save_post( - reports, bmain, ima, ibuf, ok, opts, (is_exr_rr ? true : save_copy), opts->filepath); + image_save_post(reports, + ima, + ibuf, + ok, + opts, + (is_exr_rr ? true : save_copy), + opts->filepath, + r_colorspace_changed); BKE_image_release_ibuf(ima, ibuf, lock); } /* individual multiview images */ @@ -260,7 +269,7 @@ static bool image_save_single( if (is_exr_rr) { BKE_scene_multiview_view_filepath_get(&opts->scene->r, opts->filepath, view, filepath); ok_view = RE_WriteRenderResult(reports, rr, filepath, imf, view, layer); - image_save_post(reports, bmain, ima, ibuf, ok_view, opts, true, filepath); + image_save_post(reports, ima, ibuf, ok_view, opts, true, filepath, r_colorspace_changed); } else { /* copy iuser to get the correct ibuf for this view */ @@ -293,7 +302,7 @@ static bool image_save_single( ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &opts->im_format, save_copy); imbuf_save_post(ibuf, colormanaged_ibuf); - image_save_post(reports, bmain, ima, ibuf, ok_view, opts, true, filepath); + image_save_post(reports, ima, ibuf, ok_view, opts, true, filepath, r_colorspace_changed); BKE_image_release_ibuf(ima, ibuf, lock); } ok &= ok_view; @@ -307,7 +316,7 @@ static bool image_save_single( else if (opts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) { if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { ok = RE_WriteRenderResult(reports, rr, opts->filepath, imf, NULL, layer); - image_save_post(reports, bmain, ima, ibuf, ok, opts, true, opts->filepath); + image_save_post(reports, ima, ibuf, ok, opts, true, opts->filepath, r_colorspace_changed); BKE_image_release_ibuf(ima, ibuf, lock); } else { @@ -393,6 +402,8 @@ bool BKE_image_save( ImageUser save_iuser; BKE_imageuser_default(&save_iuser); + bool colorspace_changed = false; + if (ima->source == IMA_SRC_TILED) { /* Verify filepath for tiles images. */ if (BLI_stringdec(opts->filepath, NULL, NULL, NULL) != 1001) { @@ -410,7 +421,7 @@ bool BKE_image_save( } /* Save image - or, for tiled images, the first tile. */ - bool ok = image_save_single(reports, bmain, ima, iuser, opts); + bool ok = image_save_single(reports, ima, iuser, opts, &colorspace_changed); if (ok && ima->source == IMA_SRC_TILED) { char filepath[FILE_MAX]; @@ -431,10 +442,14 @@ bool BKE_image_save( BLI_stringenc(opts->filepath, head, tail, numlen, tile->tile_number); iuser->tile = tile->tile_number; - ok = ok && image_save_single(reports, bmain, ima, iuser, opts); + ok = ok && image_save_single(reports, ima, iuser, opts, &colorspace_changed); } BLI_strncpy(opts->filepath, filepath, sizeof(opts->filepath)); } + if (colorspace_changed) { + BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE); + } + return ok; } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 269235176cd..b0b88a13a75 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -58,7 +58,7 @@ #include "BLT_translation.h" #include "BKE_action.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_idtype.h" diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index e5567a43cd7..2ca6e54b5c8 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -43,7 +43,6 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BKE_animsys.h" #include "BKE_curve.h" #include "BKE_customdata.h" #include "BKE_deform.h" diff --git a/source/blender/blenkernel/intern/keyconfig.c b/source/blender/blenkernel/intern/keyconfig.c index 84f48441cf9..ada5fc5b6aa 100644 --- a/source/blender/blenkernel/intern/keyconfig.c +++ b/source/blender/blenkernel/intern/keyconfig.c @@ -209,7 +209,7 @@ void BKE_keyconfig_pref_filter_items(struct UserDef *userdef, bool (*filter_fn)(wmKeyMapItem *kmi, void *user_data), void *user_data) { - for (wmKeyMap *keymap = userdef->user_keymaps.first; keymap; keymap = keymap->next) { + LISTBASE_FOREACH (wmKeyMap *, keymap, &userdef->user_keymaps) { BKE_keyconfig_keymap_filter_item(keymap, params, filter_fn, user_data); } } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 3f353d6d576..d371af93bb7 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -45,8 +45,7 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BKE_anim.h" -#include "BKE_animsys.h" +#include "BKE_anim_path.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_idtype.h" diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index ffa1eecc87b..d8f0bda8c22 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -83,7 +83,7 @@ static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc) view_layer->active_collection = NULL; } - for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { layer_collection_free(view_layer, nlc); } @@ -109,8 +109,7 @@ static Base *object_base_new(Object *ob) * none linked to the workspace yet. */ ViewLayer *BKE_view_layer_default_view(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (!(view_layer->flag & VIEW_LAYER_RENDER)) { return view_layer; } @@ -123,8 +122,7 @@ ViewLayer *BKE_view_layer_default_view(const Scene *scene) /* Returns the default view layer to render if we need to render just one. */ ViewLayer *BKE_view_layer_default_render(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (view_layer->flag & VIEW_LAYER_RENDER) { return view_layer; } @@ -137,8 +135,7 @@ ViewLayer *BKE_view_layer_default_render(const Scene *scene) /* Returns view layer with matching name, or NULL if not found. */ ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (STREQ(view_layer->name, layer_name)) { return view_layer; } @@ -262,12 +259,12 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user) BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL); } - for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, &view_layer->layer_collections) { layer_collection_free(view_layer, lc); } BLI_freelistN(&view_layer->layer_collections); - for (ViewLayerEngineData *sled = view_layer->drawdata.first; sled; sled = sled->next) { + LISTBASE_FOREACH (ViewLayerEngineData *, sled, &view_layer->drawdata) { if (sled->storage) { if (sled->free) { sled->free(sled->storage); @@ -295,7 +292,7 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user) */ void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if ((base->flag & BASE_SELECTED) != 0) { base->object->flag |= tag; } @@ -307,7 +304,7 @@ void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag) static bool find_scene_collection_in_scene_collections(ListBase *lb, const LayerCollection *lc) { - for (LayerCollection *lcn = lb->first; lcn; lcn = lcn->next) { + LISTBASE_FOREACH (LayerCollection *, lcn, lb) { if (lcn == lc) { return true; } @@ -327,7 +324,7 @@ static bool find_scene_collection_in_scene_collections(ListBase *lb, const Layer */ Object *BKE_view_layer_camera_find(ViewLayer *view_layer) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (base->object->type == OB_CAMERA) { return base->object; } @@ -341,8 +338,7 @@ Object *BKE_view_layer_camera_find(ViewLayer *view_layer) */ ViewLayer *BKE_view_layer_find_from_collection(const Scene *scene, LayerCollection *lc) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (find_scene_collection_in_scene_collections(&view_layer->layer_collections, lc)) { return view_layer; } @@ -364,7 +360,7 @@ static void view_layer_bases_hash_create(ViewLayer *view_layer) view_layer->object_bases_hash = BLI_ghash_new( BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (base->object) { BLI_ghash_insert(view_layer->object_bases_hash, base->object, base); } @@ -455,7 +451,7 @@ void BKE_view_layer_copy_data(Scene *scene_dst, /* Copy layer collections and object bases. */ /* Inline 'BLI_duplicatelist' and update the active base. */ BLI_listbase_clear(&view_layer_dst->object_bases); - for (Base *base_src = view_layer_src->object_bases.first; base_src; base_src = base_src->next) { + LISTBASE_FOREACH (Base *, base_src, &view_layer_src->object_bases) { Base *base_dst = MEM_dupallocN(base_src); BLI_addtail(&view_layer_dst->object_bases, base_dst); if (view_layer_src->basact == base_src) { @@ -506,7 +502,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con /* WM can be missing on startup. */ wmWindowManager *wm = bmain->wm.first; if (wm) { - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (win->scene == scene && STREQ(win->view_layer_name, oldname)) { STRNCPY(win->view_layer_name, view_layer->name); } @@ -524,7 +520,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con */ static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i) { - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { if (*i == number) { return lc; } @@ -532,7 +528,7 @@ static LayerCollection *collection_from_index(ListBase *lb, const int number, in (*i)++; } - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { LayerCollection *lc_nested = collection_from_index(&lc->layer_collections, number, i); if (lc_nested) { return lc_nested; @@ -635,7 +631,7 @@ LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, Lay static int collection_count(ListBase *lb) { int i = 0; - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { i += collection_count(&lc->layer_collections) + 1; } return i; @@ -655,7 +651,7 @@ int BKE_layer_collection_count(ViewLayer *view_layer) */ static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i) { - for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { + LISTBASE_FOREACH (LayerCollection *, lcol, lb) { if (lcol == lc) { return *i; } @@ -663,7 +659,7 @@ static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i (*i)++; } - for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) { + LISTBASE_FOREACH (LayerCollection *, lcol, lb) { int i_nested = index_from_collection(&lcol->layer_collections, lc, i); if (i_nested != -1) { return i_nested; @@ -733,7 +729,7 @@ static short layer_collection_sync(ViewLayer *view_layer, ListBase new_lb_layer = {NULL, NULL}; short runtime_flag = 0; - for (const CollectionChild *child = lb_scene->first; child; child = child->next) { + LISTBASE_FOREACH (const CollectionChild *, child, lb_scene) { Collection *collection = child->collection; LayerCollection *lc = BLI_findptr(lb_layer, collection, offsetof(LayerCollection, collection)); @@ -792,7 +788,7 @@ static short layer_collection_sync(ViewLayer *view_layer, } /* Sync objects, except if collection was excluded. */ - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { if (cob->ob == NULL) { continue; } @@ -877,7 +873,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) } /* Clear visible and selectable flags to be reset. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { base->flag &= ~g_base_collection_flags; base->flag_from_collection &= ~g_base_collection_flags; } @@ -898,7 +894,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) ~(0)); /* Any remaining object bases are to be removed. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (view_layer->basact == base) { view_layer->basact = NULL; } @@ -911,7 +907,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) BLI_freelistN(&view_layer->object_bases); view_layer->object_bases = new_object_bases; - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { BKE_base_eval_flags(base); } @@ -927,8 +923,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) void BKE_scene_collection_sync(const Scene *scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { BKE_layer_collection_sync(scene, view_layer); } } @@ -951,8 +946,7 @@ void BKE_main_collection_sync_remap(const Main *bmain) /* TODO: try to make this faster */ for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { MEM_SAFE_FREE(view_layer->object_bases_array); if (view_layer->object_bases_hash) { @@ -988,7 +982,7 @@ bool BKE_layer_collection_objects_select(ViewLayer *view_layer, LayerCollection bool changed = false; if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base) { @@ -1008,7 +1002,7 @@ bool BKE_layer_collection_objects_select(ViewLayer *view_layer, LayerCollection } } - for (LayerCollection *iter = lc->layer_collections.first; iter; iter = iter->next) { + LISTBASE_FOREACH (LayerCollection *, iter, &lc->layer_collections) { changed |= BKE_layer_collection_objects_select(view_layer, iter, deselect); } @@ -1022,7 +1016,7 @@ bool BKE_layer_collection_has_selected_objects(ViewLayer *view_layer, LayerColle } if (!(lc->flag & LAYER_COLLECTION_EXCLUDE)) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); if (base && (base->flag & BASE_SELECTED) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) { @@ -1031,7 +1025,7 @@ bool BKE_layer_collection_has_selected_objects(ViewLayer *view_layer, LayerColle } } - for (LayerCollection *iter = lc->layer_collections.first; iter; iter = iter->next) { + LISTBASE_FOREACH (LayerCollection *, iter, &lc->layer_collections) { if (BKE_layer_collection_has_selected_objects(view_layer, iter)) { return true; } @@ -1047,8 +1041,7 @@ bool BKE_layer_collection_has_layer_collection(LayerCollection *lc_parent, return true; } - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc_child)) { return true; } @@ -1063,7 +1056,7 @@ void BKE_base_set_visible(Scene *scene, ViewLayer *view_layer, Base *base, bool { if (!extend) { /* Make only one base visible. */ - for (Base *other = view_layer->object_bases.first; other; other = other->next) { + LISTBASE_FOREACH (Base *, other, &view_layer->object_bases) { other->flag |= BASE_HIDDEN; } @@ -1134,7 +1127,7 @@ bool BKE_object_is_visible_in_viewport(const struct View3D *v3d, const struct Ob static void layer_collection_flag_set_recursive(LayerCollection *lc, const int flag) { lc->flag |= flag; - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_flag_set_recursive(lc_iter, flag); } } @@ -1142,7 +1135,7 @@ static void layer_collection_flag_set_recursive(LayerCollection *lc, const int f static void layer_collection_flag_unset_recursive(LayerCollection *lc, const int flag) { lc->flag &= ~flag; - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_flag_unset_recursive(lc_iter, flag); } } @@ -1165,8 +1158,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, if (!extend) { /* Hide all collections . */ - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { layer_collection_flag_set_recursive(lc_iter, LAYER_COLLECTION_HIDE); } } @@ -1177,8 +1169,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, } else { LayerCollection *lc_parent = lc; - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1188,8 +1179,7 @@ void BKE_layer_collection_isolate_global(Scene *scene, while (lc_parent != lc) { lc_parent->flag &= ~LAYER_COLLECTION_HIDE; - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1210,8 +1200,7 @@ static void layer_collection_local_visibility_set_recursive(LayerCollection *lay const int local_collections_uuid) { layer_collection->local_collections_bits |= local_collections_uuid; - for (LayerCollection *child = layer_collection->layer_collections.first; child; - child = child->next) { + LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { layer_collection_local_visibility_set_recursive(child, local_collections_uuid); } } @@ -1220,8 +1209,7 @@ static void layer_collection_local_visibility_unset_recursive(LayerCollection *l const int local_collections_uuid) { layer_collection->local_collections_bits &= ~local_collections_uuid; - for (LayerCollection *child = layer_collection->layer_collections.first; child; - child = child->next) { + LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { layer_collection_local_visibility_unset_recursive(child, local_collections_uuid); } } @@ -1236,8 +1224,7 @@ static void layer_collection_local_sync(ViewLayer *view_layer, } if (visible) { - for (CollectionObject *cob = layer_collection->collection->gobject.first; cob; - cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &layer_collection->collection->gobject) { BLI_assert(cob->ob); Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->local_collections_bits |= local_collections_uuid; @@ -1256,7 +1243,7 @@ void BKE_layer_collection_local_sync(ViewLayer *view_layer, View3D *v3d) const unsigned short local_collections_uuid = v3d->local_collections_uuid; /* Reset flags and set the bases visible by default. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { base->local_collections_bits &= ~local_collections_uuid; } @@ -1280,8 +1267,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, if (!extend) { /* Hide all collections. */ - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { layer_collection_local_visibility_unset_recursive(lc_iter, v3d->local_collections_uuid); } } @@ -1292,8 +1278,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, } else { LayerCollection *lc_parent = lc; - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1303,8 +1288,7 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, while (lc_parent != lc) { lc_parent->local_collections_bits |= v3d->local_collections_uuid; - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { lc_parent = lc_iter; break; @@ -1322,12 +1306,12 @@ void BKE_layer_collection_isolate_local(ViewLayer *view_layer, static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCollection *lc) { if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->flag &= ~BASE_HIDDEN; } } - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_bases_show_recursive(view_layer, lc_iter); } } @@ -1335,12 +1319,12 @@ static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCo static void layer_collection_bases_hide_recursive(ViewLayer *view_layer, LayerCollection *lc) { if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(view_layer, cob->ob); base->flag |= BASE_HIDDEN; } } - for (LayerCollection *lc_iter = lc->layer_collections.first; lc_iter; lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc->layer_collections) { layer_collection_bases_hide_recursive(view_layer, lc_iter); } } @@ -1384,7 +1368,7 @@ static LayerCollection *find_layer_collection_by_scene_collection(LayerCollectio return lc; } - for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { LayerCollection *found = find_layer_collection_by_scene_collection(nlc, collection); if (found) { return found; @@ -1425,8 +1409,7 @@ bool BKE_view_layer_has_collection(ViewLayer *view_layer, const Collection *coll */ bool BKE_scene_has_object(Scene *scene, Object *ob) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { Base *base = BKE_view_layer_base_find(view_layer, ob); if (base) { return true; @@ -1768,7 +1751,7 @@ static void layer_eval_view_layer(struct Depsgraph *depsgraph, view_layer->object_bases_array = MEM_malloc_arrayN( num_object_bases, sizeof(Base *), "view_layer->object_bases_array"); int base_index = 0; - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { view_layer->object_bases_array[base_index++] = base; } } diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index a524db3c909..286ee4a8723 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -81,7 +81,7 @@ #include "BLT_translation.h" #include "BKE_action.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_armature.h" #include "BKE_bpath.h" #include "BKE_brush.h" @@ -901,7 +901,7 @@ void BKE_main_id_flag_all(Main *bmain, const int flag, const bool value) void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) { int lb_len = 0; - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (id->lib == NULL) { lb_len += 1; } @@ -914,7 +914,7 @@ void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) ID **id_array = MEM_mallocN(sizeof(*id_array) * lb_len, __func__); GSet *gset = BLI_gset_str_new_ex(__func__, lb_len); int i = 0; - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (id->lib == NULL) { id_array[i] = id; i++; @@ -2218,14 +2218,14 @@ void BKE_id_ordered_list(ListBase *ordered_lb, const ListBase *lb) { BLI_listbase_clear(ordered_lb); - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { BLI_addtail(ordered_lb, BLI_genericNodeN(id)); } BLI_listbase_sort(ordered_lb, id_order_compare); int num = 0; - for (LinkData *link = ordered_lb->first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, ordered_lb) { int *order = id_order_get(link->data); if (order) { *order = num++; @@ -2250,7 +2250,7 @@ void BKE_id_reorder(const ListBase *lb, ID *id, ID *relative, bool after) if (after) { /* Insert after. */ - for (ID *other = lb->first; other; other = other->next) { + LISTBASE_FOREACH (ID *, other, lb) { int *order = id_order_get(other); if (*order > relative_order) { (*order)++; @@ -2261,7 +2261,7 @@ void BKE_id_reorder(const ListBase *lb, ID *id, ID *relative, bool after) } else { /* Insert before. */ - for (ID *other = lb->first; other; other = other->next) { + LISTBASE_FOREACH (ID *, other, lb) { int *order = id_order_get(other); if (*order < relative_order) { (*order)--; diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index e1f4f36b822..245e4f43452 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -57,7 +57,7 @@ #include "BLI_listbase.h" #include "BKE_action.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_armature.h" #include "BKE_brush.h" #include "BKE_cachefile.h" diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index 42d1806a41a..5b75b8ac181 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -153,7 +153,7 @@ void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_i BLI_ghash_clear(override->runtime, NULL, NULL); } - for (IDOverrideLibraryProperty *op = override->properties.first; op; op = op->next) { + LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) { lib_override_library_property_clear(op); } BLI_freelistN(&override->properties); @@ -371,7 +371,7 @@ void lib_override_library_property_clear(IDOverrideLibraryProperty *op) MEM_freeN(op->rna_path); - for (IDOverrideLibraryPropertyOperation *opop = op->operations.first; opop; opop = opop->next) { + LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) { lib_override_library_property_operation_clear(opop); } BLI_freelistN(&op->operations); diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c index 886fb4241a4..9c0fa33157c 100644 --- a/source/blender/blenkernel/intern/lib_query.c +++ b/source/blender/blenkernel/intern/lib_query.c @@ -61,9 +61,10 @@ #include "BLI_ghash.h" #include "BLI_linklist_stack.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_collection.h" #include "BKE_constraint.h" #include "BKE_fcurve.h" @@ -181,7 +182,7 @@ static void library_foreach_idproperty_ID_link(LibraryForeachIDData *data, switch (prop->type) { case IDP_GROUP: { - for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { + LISTBASE_FOREACH (IDProperty *, loop, &prop->data.group) { library_foreach_idproperty_ID_link(data, loop, flag); } break; @@ -337,7 +338,7 @@ static void library_foreach_bone(LibraryForeachIDData *data, Bone *bone) { library_foreach_idproperty_ID_link(data, bone->prop, IDWALK_CB_USER); - for (Bone *curbone = bone->childbase.first; curbone; curbone = curbone->next) { + LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { library_foreach_bone(data, curbone); } @@ -346,7 +347,7 @@ static void library_foreach_bone(LibraryForeachIDData *data, Bone *bone) static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBase *lb) { - for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, lb) { /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = (lc->collection != NULL && @@ -364,13 +365,13 @@ static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBas */ static void library_foreach_collection(LibraryForeachIDData *data, Collection *collection) { - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { FOREACH_CALLBACK_INVOKE(data, cob->ob, IDWALK_CB_USER); } - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { FOREACH_CALLBACK_INVOKE(data, child->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_USER); } - for (CollectionParent *parent = collection->parents.first; parent; parent = parent->next) { + LISTBASE_FOREACH (CollectionParent *, parent, &collection->parents) { /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = ((parent->collection != NULL && @@ -398,7 +399,7 @@ static void library_foreach_screen_area(LibraryForeachIDData *data, ScrArea *are { FOREACH_CALLBACK_INVOKE(data, area->full, IDWALK_CB_NOP); - for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { switch (sl->spacetype) { case SPACE_VIEW3D: { View3D *v3d = (View3D *)sl; @@ -677,7 +678,7 @@ static void library_foreach_ID_link(Main *bmain, CALLBACK_INVOKE(seq->mask, IDWALK_CB_USER); CALLBACK_INVOKE(seq->sound, IDWALK_CB_USER); library_foreach_idproperty_ID_link(&data, seq->prop, IDWALK_CB_USER); - for (SequenceModifierData *smd = seq->modifiers.first; smd; smd = smd->next) { + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { CALLBACK_INVOKE(smd->mask_id, IDWALK_CB_USER); } @@ -698,21 +699,19 @@ static void library_foreach_ID_link(Main *bmain, for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { CALLBACK_INVOKE(view_layer->mat_override, IDWALK_CB_USER); - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { CALLBACK_INVOKE(base->object, IDWALK_CB_NOP); } library_foreach_layer_collection(&data, &view_layer->layer_collections); - for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; - fmc = fmc->next) { + LISTBASE_FOREACH (FreestyleModuleConfig *, fmc, &view_layer->freestyle_config.modules) { if (fmc->script) { CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP); } } - for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; - fls = fls->next) { + LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) { if (fls->group) { CALLBACK_INVOKE(fls->group, IDWALK_CB_USER); } @@ -723,7 +722,7 @@ static void library_foreach_ID_link(Main *bmain, } } - for (TimeMarker *marker = scene->markers.first; marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, &scene->markers) { CALLBACK_INVOKE(marker->camera, IDWALK_CB_NOP); } @@ -880,7 +879,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_AR: { bArmature *arm = (bArmature *)id; - for (Bone *bone = arm->bonebase.first; bone; bone = bone->next) { + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { library_foreach_bone(&data, bone); } break; @@ -967,7 +966,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_CA: { Camera *camera = (Camera *)id; CALLBACK_INVOKE(camera->dof.focus_object, IDWALK_CB_NOP); - for (CameraBGImage *bgpic = camera->bg_images.first; bgpic; bgpic = bgpic->next) { + LISTBASE_FOREACH (CameraBGImage *, bgpic, &camera->bg_images) { if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) { CALLBACK_INVOKE(bgpic->ima, IDWALK_CB_USER); } @@ -1099,7 +1098,7 @@ static void library_foreach_ID_link(Main *bmain, } } - for (ParticleDupliWeight *dw = psett->instance_weights.first; dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &psett->instance_weights) { CALLBACK_INVOKE(dw->ob, IDWALK_CB_NOP); } break; @@ -1194,7 +1193,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_AC: { bAction *act = (bAction *)id; - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { CALLBACK_INVOKE(marker->camera, IDWALK_CB_NOP); } break; @@ -1203,7 +1202,7 @@ static void library_foreach_ID_link(Main *bmain, case ID_WM: { wmWindowManager *wm = (wmWindowManager *)id; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE); /* This pointer can be NULL during old files reading, better be safe than sorry. */ @@ -1214,7 +1213,7 @@ static void library_foreach_ID_link(Main *bmain, BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace); } if (data.flag & IDWALK_INCLUDE_UI) { - for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) { library_foreach_screen_area(&data, area); } } @@ -1226,7 +1225,7 @@ static void library_foreach_ID_link(Main *bmain, WorkSpace *workspace = (WorkSpace *)id; ListBase *layouts = BKE_workspace_layouts_get(workspace); - for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + LISTBASE_FOREACH (WorkSpaceLayout *, layout, layouts) { bScreen *screen = BKE_workspace_layout_screen_get(layout); /* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer. @@ -1279,7 +1278,7 @@ static void library_foreach_ID_link(Main *bmain, if (data.flag & IDWALK_INCLUDE_UI) { bScreen *screen = (bScreen *)id; - for (ScrArea *area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { library_foreach_screen_area(&data, area); } } @@ -1709,7 +1708,7 @@ void BKE_library_indirectly_used_data_tag_clear(Main *bmain) do_loop = false; while (i--) { - for (ID *id = lb_array[i]->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb_array[i]) { if (id->lib == NULL || id->tag & LIB_TAG_DOIT) { /* Local or non-indirectly-used ID (so far), no need to check it further. */ continue; diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index aec0f808f64..3ecd1c81b27 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -37,7 +37,6 @@ #include "BLI_math.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" #include "BKE_colortools.h" #include "BKE_icons.h" #include "BKE_idtype.h" diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c index 4675897cb0e..22f12831aa0 100644 --- a/source/blender/blenkernel/intern/lightprobe.c +++ b/source/blender/blenkernel/intern/lightprobe.c @@ -29,7 +29,6 @@ #include "BLI_utildefines.h" -#include "BKE_animsys.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_lightprobe.h" diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index db39931a9d2..42506e0d7c8 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -39,7 +39,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_context.h" diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 16ec4c0a313..5516e877b10 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -54,7 +54,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_brush.h" #include "BKE_curve.h" #include "BKE_displist.h" @@ -1122,7 +1121,7 @@ static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree, ForEachTexNodeCallback callback, void *userdata) { - for (bNode *node = nodetree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) { if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) { if (!callback(node, userdata)) { diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index b708c030152..4294d279c36 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -50,7 +50,6 @@ #include "BKE_main.h" -#include "BKE_animsys.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_idtype.h" @@ -431,9 +430,8 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { Object *ob = base->object; if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) { if (ob != bob) { @@ -464,7 +462,7 @@ bool BKE_mball_minmax_ex( INIT_MINMAX(min, max); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { if ((ml->flag & flag) == flag) { const float scale_mb = (ml->rad * 0.5f) * scale; int i; @@ -494,7 +492,7 @@ bool BKE_mball_minmax(const MetaBall *mb, float min[3], float max[3]) { INIT_MINMAX(min, max); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { minmax_v3v3_v3(min, max, &ml->x); } @@ -507,7 +505,7 @@ bool BKE_mball_center_median(const MetaBall *mb, float r_cent[3]) zero_v3(r_cent); - for (const MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { add_v3_v3(r_cent, &ml->x); total++; } @@ -539,7 +537,7 @@ void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_prop mat4_to_quat(quat, mat); - for (MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { mul_m4_v3(mat, &ml->x); mul_qt_qtqt(ml->quat, quat, ml->quat); @@ -559,7 +557,7 @@ void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_prop void BKE_mball_translate(MetaBall *mb, const float offset[3]) { - for (MetaElem *ml = mb->elems.first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { add_v3_v3(&ml->x, offset); } } @@ -568,7 +566,7 @@ void BKE_mball_translate(MetaBall *mb, const float offset[3]) int BKE_mball_select_count(const MetaBall *mb) { int sel = 0; - for (const MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) { if (ml->flag & SELECT) { sel++; } @@ -590,7 +588,7 @@ int BKE_mball_select_count_multi(Base **bases, int bases_len) bool BKE_mball_select_all(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if ((ml->flag & SELECT) == 0) { ml->flag |= SELECT; changed = true; @@ -613,7 +611,7 @@ bool BKE_mball_select_all_multi_ex(Base **bases, int bases_len) bool BKE_mball_deselect_all(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { if ((ml->flag & SELECT) != 0) { ml->flag &= ~SELECT; changed = true; @@ -637,7 +635,7 @@ bool BKE_mball_deselect_all_multi_ex(Base **bases, int bases_len) bool BKE_mball_select_swap(MetaBall *mb) { bool changed = false; - for (MetaElem *ml = mb->editelems->first; ml; ml = ml->next) { + LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { ml->flag ^= SELECT; changed = true; } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index a59337bc4a2..2a86b899290 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -41,7 +41,7 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_editmesh.h" #include "BKE_global.h" #include "BKE_idtype.h" diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 0b3650fd40a..17fd7b18bab 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -1012,7 +1012,7 @@ void BKE_mesh_loop_manifold_fan_around_vert_next(const MLoop *mloops, static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopSplitTaskData *data) { MLoopNorSpaceArray *lnors_spacearr = common_data->lnors_spacearr; - short(*clnors_data)[2] = common_data->clnors_data; + const short(*clnors_data)[2] = common_data->clnors_data; const MVert *mverts = common_data->mverts; const MEdge *medges = common_data->medges; diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 1935dc0cf6f..1964dba7593 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -53,7 +53,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idtype.h" @@ -1744,7 +1743,7 @@ bool BKE_movieclip_put_frame_if_possible(MovieClip *clip, MovieClipUser *user, I return result; } -static void movieclip_selection_synchronize(MovieClip *clip_dst, const MovieClip *clip_src) +static void movieclip_selection_sync(MovieClip *clip_dst, const MovieClip *clip_src) { BLI_assert(clip_dst != clip_src); MovieTracking *tracking_dst = &clip_dst->tracking, tracking_src = clip_src->tracking; @@ -1811,5 +1810,5 @@ void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, Main *bmain, MovieCl void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, MovieClip *clip) { DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip); - movieclip_selection_synchronize(clip, (MovieClip *)clip->id.orig_id); + movieclip_selection_sync(clip, (MovieClip *)clip->id.orig_id); } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 6ccfabcb5d2..69cd338e15f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -473,7 +473,8 @@ void multires_flush_sculpt_updates(Object *object) } SculptSession *sculpt_session = object->sculpt; - if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || sculpt_session->multires == NULL) { + if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || !sculpt_session->multires.active || + sculpt_session->multires.modifier == NULL) { return; } @@ -488,7 +489,7 @@ void multires_flush_sculpt_updates(Object *object) Mesh *mesh = object->data; multiresModifier_reshapeFromCCG( - sculpt_session->multires->totlvl, mesh, sculpt_session->subdiv_ccg); + sculpt_session->multires.modifier->totlvl, mesh, sculpt_session->subdiv_ccg); subdiv_ccg->dirty.coords = false; subdiv_ccg->dirty.hidden = false; diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.c b/source/blender/blenkernel/intern/multires_reshape_apply_base.c index d480c46f2d0..90736de12e1 100644 --- a/source/blender/blenkernel/intern/multires_reshape_apply_base.c +++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.c @@ -177,7 +177,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape void multires_reshape_apply_base_refine_from_base(MultiresReshapeContext *reshape_context) { - BKE_subdiv_eval_update_from_mesh(reshape_context->subdiv, reshape_context->base_mesh, NULL); + BKE_subdiv_eval_refine_from_mesh(reshape_context->subdiv, reshape_context->base_mesh, NULL); } void multires_reshape_apply_base_refine_from_deform(MultiresReshapeContext *reshape_context) @@ -192,7 +192,7 @@ void multires_reshape_apply_base_refine_from_deform(MultiresReshapeContext *resh float(*deformed_verts)[3] = BKE_multires_create_deformed_base_mesh_vert_coords( depsgraph, object, mmd, NULL); - BKE_subdiv_eval_update_from_mesh( + BKE_subdiv_eval_refine_from_mesh( reshape_context->subdiv, reshape_context->base_mesh, deformed_verts); MEM_freeN(deformed_verts); diff --git a/source/blender/blenkernel/intern/multires_reshape_smooth.c b/source/blender/blenkernel/intern/multires_reshape_smooth.c index 8b10d729901..514608a0f1d 100644 --- a/source/blender/blenkernel/intern/multires_reshape_smooth.c +++ b/source/blender/blenkernel/intern/multires_reshape_smooth.c @@ -400,7 +400,7 @@ static char get_effective_edge_crease_char( const MultiresReshapeSmoothContext *reshape_smooth_context, const MEdge *base_edge) { const MultiresReshapeContext *reshape_context = reshape_smooth_context->reshape_context; - if (reshape_context->mmd->simple) { + if (reshape_context->subdiv->settings.is_simple) { return 255; } return base_edge->crease; @@ -929,7 +929,7 @@ typedef void(ReshapeSubdivCoarsePositionCb)( const Vertex *vertex, float r_P[3]); -/* Refine subdivision surface topology at a reshape level for new coarse verticies positions. */ +/* Refine subdivision surface topology at a reshape level for new coarse vertices positions. */ static void reshape_subdiv_refine(const MultiresReshapeSmoothContext *reshape_smooth_context, ReshapeSubdivCoarsePositionCb coarse_position_cb) { diff --git a/source/blender/blenkernel/intern/multires_reshape_util.c b/source/blender/blenkernel/intern/multires_reshape_util.c index 759306f9422..5b6e211cc9b 100644 --- a/source/blender/blenkernel/intern/multires_reshape_util.c +++ b/source/blender/blenkernel/intern/multires_reshape_util.c @@ -67,7 +67,7 @@ Subdiv *multires_reshape_create_subdiv(Depsgraph *depsgraph, SubdivSettings subdiv_settings; BKE_multires_subdiv_settings_init(&subdiv_settings, mmd); Subdiv *subdiv = BKE_subdiv_new_from_mesh(&subdiv_settings, base_mesh); - if (!BKE_subdiv_eval_update_from_mesh(subdiv, base_mesh, NULL)) { + if (!BKE_subdiv_eval_begin_from_mesh(subdiv, base_mesh, NULL)) { BKE_subdiv_free(subdiv); return NULL; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 06ddf4a8582..c3c538f3424 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -50,6 +50,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_global.h" #include "BKE_idprop.h" @@ -112,7 +113,7 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c /* Since source nodes and sockets are unique pointers we can put everything in a single map. */ GHash *new_pointers = BLI_ghash_ptr_new(__func__); - for (const bNode *node_src = ntree_src->nodes.first; node_src; node_src = node_src->next) { + LISTBASE_FOREACH (const bNode *, node_src, &ntree_src->nodes) { bNode *new_node = BKE_node_copy_ex(ntree_dst, node_src, flag_subdata, true); BLI_ghash_insert(new_pointers, (void *)node_src, new_node); /* Store mapping to inputs. */ @@ -1633,7 +1634,7 @@ void nodePositionRelative(bNode *from_node, void nodePositionPropagate(bNode *node) { - for (bNodeSocket *nsock = node->inputs.first; nsock; nsock = nsock->next) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) { if (nsock->link != NULL) { bNodeLink *link = nsock->link; nodePositionRelative(link->fromnode, link->tonode, link->fromsock, link->tosock); @@ -2661,7 +2662,7 @@ void ntreeInterfaceTypeUpdate(bNodeTree *ntree) bNode *ntreeFindType(const bNodeTree *ntree, int type) { if (ntree) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == type) { return node; } @@ -3395,7 +3396,7 @@ void ntreeUpdateAllNew(Main *main) * might have been set in file reading or versioning. */ FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { if (owner_id->tag & LIB_TAG_NEW) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->typeinfo->group_update_func) { node->typeinfo->group_update_func(ntree, node); } @@ -3413,7 +3414,7 @@ void ntreeUpdateAllUsers(Main *main, ID *ngroup) FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { bool need_update = false; - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->id == ngroup) { if (node->typeinfo->group_update_func) { node->typeinfo->group_update_func(ntree, node); @@ -3624,9 +3625,9 @@ void node_type_base(bNodeType *ntype, int type, const char *name, short nclass, #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \ case ID: \ BLI_strncpy(ntype->idname, #Category #StructName, sizeof(ntype->idname)); \ - ntype->ext.srna = RNA_struct_find(#Category #StructName); \ - BLI_assert(ntype->ext.srna != NULL); \ - RNA_struct_blender_type_set(ntype->ext.srna, ntype); \ + ntype->rna_ext.srna = RNA_struct_find(#Category #StructName); \ + BLI_assert(ntype->rna_ext.srna != NULL); \ + RNA_struct_blender_type_set(ntype->rna_ext.srna, ntype); \ break; switch (type) { @@ -4141,8 +4142,8 @@ void free_nodesystem(void) { if (nodetypes_hash) { NODE_TYPES_BEGIN (nt) { - if (nt->ext.free) { - nt->ext.free(nt->ext.data); + if (nt->rna_ext.free) { + nt->rna_ext.free(nt->rna_ext.data); } } NODE_TYPES_END; @@ -4168,8 +4169,8 @@ void free_nodesystem(void) if (nodetreetypes_hash) { NODE_TREE_TYPES_BEGIN (nt) { - if (nt->ext.free) { - nt->ext.free(nt->ext.data); + if (nt->rna_ext.free) { + nt->rna_ext.free(nt->rna_ext.data); } } NODE_TREE_TYPES_END; @@ -4244,7 +4245,7 @@ bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter, void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index) { BLI_assert(layer_index != -1); - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) { if (node->custom1 == layer_index) { node->custom1 = 0; diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 7a2e9583aa1..733f112f80c 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -68,7 +68,9 @@ #include "BKE_DerivedMesh.h" #include "BKE_action.h" -#include "BKE_anim.h" +#include "BKE_anim_data.h" +#include "BKE_anim_path.h" +#include "BKE_anim_visualization.h" #include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_camera.h" @@ -77,6 +79,7 @@ #include "BKE_curve.h" #include "BKE_deform.h" #include "BKE_displist.h" +#include "BKE_duplilist.h" #include "BKE_editmesh.h" #include "BKE_effect.h" #include "BKE_fcurve.h" diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c index 1217d230d0d..474142e8555 100644 --- a/source/blender/blenkernel/intern/object_dupli.c +++ b/source/blender/blenkernel/intern/object_dupli.c @@ -40,9 +40,8 @@ #include "DNA_scene_types.h" #include "DNA_vfont_types.h" -#include "BKE_anim.h" -#include "BKE_animsys.h" #include "BKE_collection.h" +#include "BKE_duplilist.h" #include "BKE_editmesh.h" #include "BKE_font.h" #include "BKE_global.h" diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index dd06e4f1753..c5ef5acb08b 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -37,7 +37,6 @@ #include "BKE_DerivedMesh.h" #include "BKE_action.h" -#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_constraint.h" #include "BKE_curve.h" @@ -273,7 +272,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o /** * TODO(sergey): Ensure that bounding box is already calculated, and move this - * into #BKE_object_synchronize_to_original(). + * into #BKE_object_sync_to_original(). */ void BKE_object_eval_boundbox(Depsgraph *depsgraph, Object *object) { @@ -290,7 +289,7 @@ void BKE_object_eval_boundbox(Depsgraph *depsgraph, Object *object) } } -void BKE_object_synchronize_to_original(Depsgraph *depsgraph, Object *object) +void BKE_object_sync_to_original(Depsgraph *depsgraph, Object *object) { if (!DEG_is_active(depsgraph)) { return; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 719336f7351..c5d60b29aca 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -44,7 +44,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_brush.h" #include "BKE_ccg.h" #include "BKE_colortools.h" @@ -1522,9 +1521,12 @@ static void sculpt_update_object( /* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path, * so no extra checks is needed here. */ if (mmd) { - ss->multires = mmd; + ss->multires.active = true; + ss->multires.modifier = mmd; + ss->multires.level = mmd->sculptlvl; ss->totvert = me_eval->totvert; ss->totpoly = me_eval->totpoly; + ss->totfaces = me->totpoly; ss->mvert = NULL; ss->mpoly = NULL; ss->mloop = NULL; @@ -1532,25 +1534,28 @@ static void sculpt_update_object( else { ss->totvert = me->totvert; ss->totpoly = me->totpoly; + ss->totfaces = me->totpoly; ss->mvert = me->mvert; ss->mpoly = me->mpoly; ss->mloop = me->mloop; - ss->multires = NULL; + ss->multires.active = false; + ss->multires.modifier = NULL; + ss->multires.level = 0; ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); + } - /* Sculpt Face Sets. */ - if (!CustomData_has_layer(&me->pdata, CD_SCULPT_FACE_SETS)) { - ss->face_sets = CustomData_add_layer( - &me->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, me->totpoly); - for (int i = 0; i < me->totpoly; i++) { - ss->face_sets[i] = 1; - } - - /* Set the default face set color if the datalayer did not exist. */ - me->face_sets_color_default = 1; + /* Sculpt Face Sets. */ + if (!CustomData_has_layer(&me->pdata, CD_SCULPT_FACE_SETS)) { + ss->face_sets = CustomData_add_layer( + &me->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, me->totpoly); + for (int i = 0; i < me->totpoly; i++) { + ss->face_sets[i] = 1; } - ss->face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS); + + /* Set the default face set color if the datalayer did not exist. */ + me->face_sets_color_default = 1; } + ss->face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS); ss->subdiv_ccg = me_eval->runtime.subdiv_ccg; @@ -1558,6 +1563,9 @@ static void sculpt_update_object( BLI_assert(pbvh == ss->pbvh); UNUSED_VARS_NDEBUG(pbvh); + BKE_pbvh_subdiv_cgg_set(ss->pbvh, ss->subdiv_ccg); + BKE_pbvh_face_sets_set(ss->pbvh, ss->face_sets); + BKE_pbvh_face_sets_color_set(ss->pbvh, me->face_sets_color_seed, me->face_sets_color_default); if (need_pmap && ob->type == OB_MESH && !ss->pmap) { diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index f110a2bd3ae..587dd5be2f2 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -50,9 +50,7 @@ #include "BLT_translation.h" -#include "BKE_anim.h" -#include "BKE_animsys.h" - +#include "BKE_anim_path.h" #include "BKE_boids.h" #include "BKE_cloth.h" #include "BKE_collection.h" @@ -481,7 +479,7 @@ void psys_find_group_weights(ParticleSettings *part) instance_collection_objects = BKE_collection_object_cache_get(part->instance_collection); } - for (ParticleDupliWeight *dw = part->instance_weights.first; dw; dw = dw->next) { + LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) { if (dw->ob == NULL) { Base *base = BLI_findlink(&instance_collection_objects, dw->index); if (base != NULL) { diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 9a4ce8acb11..06622f0d009 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -383,6 +383,25 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden, return totquad; } +void BKE_pbvh_sync_face_sets_to_grids(PBVH *bvh) +{ + const int gridsize = bvh->gridkey.grid_size; + for (int i = 0; i < bvh->totgrid; i++) { + BLI_bitmap *gh = bvh->grid_hidden[i]; + const int face_index = BKE_subdiv_cgg_grid_to_face_index(bvh->subdiv_ccg, i); + if (!gh && bvh->face_sets[face_index] < 0) { + gh = bvh->grid_hidden[i] = BLI_BITMAP_NEW(bvh->gridkey.grid_area, "partialvis_update_grids"); + } + if (gh) { + for (int y = 0; y < gridsize; y++) { + for (int x = 0; x < gridsize; x++) { + BLI_BITMAP_SET(gh, y * gridsize + x, bvh->face_sets[face_index] < 0); + } + } + } + } +} + static void build_grid_leaf_node(PBVH *bvh, PBVHNode *node) { int totquads = BKE_pbvh_count_grid_quads( @@ -1289,10 +1308,14 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata, switch (bvh->type) { case PBVH_GRIDS: GPU_pbvh_grid_buffers_update(node->draw_buffers, + bvh->subdiv_ccg, bvh->grids, bvh->grid_flag_mats, node->prim_indices, node->totprim, + bvh->face_sets, + bvh->face_sets_color_seed, + bvh->face_sets_color_default, &bvh->gridkey, update_flags); break; @@ -2098,6 +2121,7 @@ static bool pbvh_faces_node_raycast(PBVH *bvh, struct IsectRayPrecalc *isect_precalc, float *depth, int *r_active_vertex_index, + int *r_active_face_index, float *r_face_normal) { const MVert *vert = bvh->verts; @@ -2143,6 +2167,7 @@ static bool pbvh_faces_node_raycast(PBVH *bvh, if (len_squared_v3v3(location, co[j]) < len_squared_v3v3(location, nearest_vertex_co)) { copy_v3_v3(nearest_vertex_co, co[j]); *r_active_vertex_index = mloop[lt->tri[j]].v; + *r_active_face_index = lt->poly; } } } @@ -2160,6 +2185,7 @@ static bool pbvh_grids_node_raycast(PBVH *bvh, struct IsectRayPrecalc *isect_precalc, float *depth, int *r_active_vertex_index, + int *r_active_grid_index, float *r_face_normal) { const int totgrid = node->totprim; @@ -2213,15 +2239,23 @@ static bool pbvh_grids_node_raycast(PBVH *bvh, if (r_active_vertex_index) { float location[3] = {0.0}; madd_v3_v3v3fl(location, ray_start, ray_normal, *depth); + + const int x_it[4] = {0, 1, 1, 0}; + const int y_it[4] = {0, 0, 1, 1}; + for (int j = 0; j < 4; j++) { if (len_squared_v3v3(location, co[j]) < len_squared_v3v3(location, nearest_vertex_co)) { copy_v3_v3(nearest_vertex_co, co[j]); - *r_active_vertex_index = gridkey->grid_area * grid_index + y * gridkey->grid_size + - x; + + *r_active_vertex_index = gridkey->grid_area * grid_index + + (y + y_it[j]) * gridkey->grid_size + (x + x_it[j]); } } } + if (r_active_grid_index) { + *r_active_grid_index = grid_index; + } } } } @@ -2243,6 +2277,7 @@ bool BKE_pbvh_node_raycast(PBVH *bvh, struct IsectRayPrecalc *isect_precalc, float *depth, int *active_vertex_index, + int *active_face_grid_index, float *face_normal) { bool hit = false; @@ -2261,6 +2296,7 @@ bool BKE_pbvh_node_raycast(PBVH *bvh, isect_precalc, depth, active_vertex_index, + active_face_grid_index, face_normal); break; case PBVH_GRIDS: @@ -2272,6 +2308,7 @@ bool BKE_pbvh_node_raycast(PBVH *bvh, isect_precalc, depth, active_vertex_index, + active_face_grid_index, face_normal); break; case PBVH_BMESH: @@ -2646,7 +2683,8 @@ static bool pbvh_draw_search_cb(PBVHNode *node, void *data_v) void BKE_pbvh_draw_cb(PBVH *bvh, bool show_vcol, bool update_only_visible, - PBVHFrustumPlanes *frustum, + PBVHFrustumPlanes *update_frustum, + PBVHFrustumPlanes *draw_frustum, void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), void *user_data) { @@ -2667,7 +2705,7 @@ void BKE_pbvh_draw_cb(PBVH *bvh, } /* Gather visible nodes. */ - PBVHDrawSearchData data = {.frustum = frustum, .accum_update_flag = 0}; + PBVHDrawSearchData data = {.frustum = update_frustum, .accum_update_flag = 0}; BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &data, &nodes, &totnode); if (update_only_visible && (data.accum_update_flag & update_flag)) { @@ -2685,7 +2723,15 @@ void BKE_pbvh_draw_cb(PBVH *bvh, } node->flag &= ~(PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers); + } + + MEM_SAFE_FREE(nodes); + + PBVHDrawSearchData draw_data = {.frustum = draw_frustum, .accum_update_flag = 0}; + BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &draw_data, &nodes, &totnode); + for (int a = 0; a < totnode; a++) { + PBVHNode *node = nodes[a]; if (!(node->flag & PBVH_FullyHidden)) { draw_fn(user_data, node->draw_buffers); } @@ -2961,6 +3007,22 @@ void pbvh_show_face_sets_set(PBVH *bvh, bool show_face_sets) bvh->show_face_sets = show_face_sets; } +void BKE_pbvh_set_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes) +{ + bvh->num_planes = planes->num_planes; + for (int i = 0; i < bvh->num_planes; i++) { + copy_v4_v4(bvh->planes[i], planes->planes[i]); + } +} + +void BKE_pbvh_get_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes) +{ + planes->num_planes = bvh->num_planes; + for (int i = 0; i < planes->num_planes; i++) { + copy_v4_v4(planes->planes[i], bvh->planes[i]); + } +} + void BKE_pbvh_parallel_range_settings(PBVHParallelSettings *settings, bool use_threading, int totnode) @@ -2974,3 +3036,13 @@ MVert *BKE_pbvh_get_verts(const PBVH *bvh) BLI_assert(bvh->type == PBVH_FACES); return bvh->verts; } + +void BKE_pbvh_subdiv_cgg_set(PBVH *bvh, SubdivCCG *subdiv_ccg) +{ + bvh->subdiv_ccg = subdiv_ccg; +} + +void BKE_pbvh_face_sets_set(PBVH *bvh, int *face_sets) +{ + bvh->face_sets = face_sets; +} diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h index af92f11e219..d3e42ac7705 100644 --- a/source/blender/blenkernel/intern/pbvh_intern.h +++ b/source/blender/blenkernel/intern/pbvh_intern.h @@ -138,6 +138,7 @@ struct PBVH { int face_sets_color_seed; int face_sets_color_default; + int *face_sets; /* Grid Data */ CCGKey gridkey; @@ -167,7 +168,11 @@ struct PBVH { int cd_vert_node_offset; int cd_face_node_offset; + float planes[6][4]; + int num_planes; + struct BMLog *bm_log; + struct SubdivCCG *subdiv_ccg; }; /* pbvh.c */ diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 76088867997..78e7dec9f38 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -51,7 +51,6 @@ #include "PIL_time.h" -#include "BKE_anim.h" #include "BKE_appdir.h" #include "BKE_cloth.h" #include "BKE_collection.h" @@ -1840,7 +1839,7 @@ PTCacheID BKE_ptcache_id_find(Object *ob, Scene *scene, PointCache *cache) ListBase pidlist; BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR); - for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) { + LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { if (pid->cache == cache) { result = *pid; break; diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c index 3e4cc5c6185..31b8de53291 100644 --- a/source/blender/blenkernel/intern/pointcloud.c +++ b/source/blender/blenkernel/intern/pointcloud.c @@ -30,7 +30,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_idtype.h" diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index b12402d74fc..20f7add0c74 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -59,13 +59,14 @@ #include "BLT_translation.h" #include "BKE_action.h" -#include "BKE_anim.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_cachefile.h" #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_curveprofile.h" +#include "BKE_duplilist.h" #include "BKE_editmesh.h" #include "BKE_fcurve.h" #include "BKE_freestyle.h" @@ -668,10 +669,9 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) if (type == SCE_COPY_FULL) { /* Copy Freestyle LineStyle datablocks. */ - for (ViewLayer *view_layer_dst = sce_copy->view_layers.first; view_layer_dst; - view_layer_dst = view_layer_dst->next) { - for (FreestyleLineSet *lineset = view_layer_dst->freestyle_config.linesets.first; lineset; - lineset = lineset->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer_dst, &sce_copy->view_layers) { + LISTBASE_FOREACH ( + FreestyleLineSet *, lineset, &view_layer_dst->freestyle_config.linesets) { if (lineset->linestyle) { id_us_min(&lineset->linestyle->id); BKE_id_copy_ex( @@ -731,8 +731,7 @@ Scene *BKE_scene_add(Main *bmain, const char *name) */ bool BKE_scene_object_find(Scene *scene, Object *ob) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (BLI_findptr(&view_layer->object_bases, ob, offsetof(Base, object))) { return true; } @@ -742,9 +741,8 @@ bool BKE_scene_object_find(Scene *scene, Object *ob) Object *BKE_scene_object_find_by_name(const Scene *scene, const char *name) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (STREQ(base->object->id.name + 2, name)) { return base->object; } @@ -772,9 +770,8 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) } /* copy layers and flags from bases to objects */ - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { ob = base->object; /* collection patch... */ BKE_scene_object_base_flag_sync_from_base(base); @@ -928,7 +925,7 @@ int BKE_scene_base_iter_next( Scene *BKE_scene_find_from_collection(const Main *bmain, const Collection *collection) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - for (ViewLayer *layer = scene->view_layers.first; layer; layer = layer->next) { + LISTBASE_FOREACH (ViewLayer *, layer, &scene->view_layers) { if (BKE_view_layer_has_collection(layer, collection)) { return scene; } @@ -954,7 +951,7 @@ Object *BKE_scene_camera_switch_find(Scene *scene) Object *camera = NULL; Object *first_camera = NULL; - for (TimeMarker *m = scene->markers.first; m; m = m->next) { + LISTBASE_FOREACH (TimeMarker *, m, &scene->markers) { if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0) { if ((m->frame <= cfra) && (m->frame > frame)) { camera = m->camera; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index dbf460fdea2..997e807a253 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -104,16 +104,16 @@ static void spacetype_free(SpaceType *st) BLI_freelistN(&art->drawcalls); for (pt = art->paneltypes.first; pt; pt = pt->next) { - if (pt->ext.free) { - pt->ext.free(pt->ext.data); + if (pt->rna_ext.free) { + pt->rna_ext.free(pt->rna_ext.data); } BLI_freelistN(&pt->children); } for (ht = art->headertypes.first; ht; ht = ht->next) { - if (ht->ext.free) { - ht->ext.free(ht->ext.data); + if (ht->rna_ext.free) { + ht->rna_ext.free(ht->rna_ext.data); } } @@ -230,11 +230,11 @@ static void panel_list_copy(ListBase *newlb, const ListBase *lb) BLI_duplicatelist(newlb, lb); /* copy panel pointers */ - Panel *newpa = newlb->first; - Panel *pa = lb->first; - for (; newpa; newpa = newpa->next, pa = pa->next) { - newpa->activedata = NULL; - panel_list_copy(&newpa->children, &pa->children); + Panel *new_panel = newlb->first; + Panel *panel = lb->first; + for (; new_panel; new_panel = new_panel->next, panel = panel->next) { + new_panel->activedata = NULL; + panel_list_copy(&new_panel->children, &panel->children); } } @@ -338,15 +338,17 @@ void BKE_spacedata_draw_locks(int set) /** * Version of #BKE_area_find_region_type that also works if \a slink - * is not the active space of \a sa. + * is not the active space of \a area. */ -ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, const ScrArea *sa, int region_type) +ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, + const ScrArea *area, + int region_type) { - const bool is_slink_active = slink == sa->spacedata.first; - const ListBase *regionbase = (is_slink_active) ? &sa->regionbase : &slink->regionbase; + const bool is_slink_active = slink == area->spacedata.first; + const ListBase *regionbase = (is_slink_active) ? &area->regionbase : &slink->regionbase; ARegion *region = NULL; - BLI_assert(BLI_findindex(&sa->spacedata, slink) != -1); + BLI_assert(BLI_findindex(&area->spacedata, slink) != -1); for (region = regionbase->first; region; region = region->next) { if (region->regiontype == region_type) { break; @@ -354,26 +356,26 @@ ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, const ScrArea *s } /* Should really unit test this instead. */ - BLI_assert(!is_slink_active || region == BKE_area_find_region_type(sa, region_type)); + BLI_assert(!is_slink_active || region == BKE_area_find_region_type(area, region_type)); return region; } -static void (*spacedata_id_remap_cb)(struct ScrArea *sa, +static void (*spacedata_id_remap_cb)(struct ScrArea *area, struct SpaceLink *sl, ID *old_id, ID *new_id) = NULL; -void BKE_spacedata_callback_id_remap_set(void (*func)(ScrArea *sa, SpaceLink *sl, ID *, ID *)) +void BKE_spacedata_callback_id_remap_set(void (*func)(ScrArea *area, SpaceLink *sl, ID *, ID *)) { spacedata_id_remap_cb = func; } /* UNUSED!!! */ -void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID *id) +void BKE_spacedata_id_unref(struct ScrArea *area, struct SpaceLink *sl, struct ID *id) { if (spacedata_id_remap_cb) { - spacedata_id_remap_cb(sa, sl, id, NULL); + spacedata_id_remap_cb(area, sl, id, NULL); } } @@ -387,16 +389,16 @@ void BKE_region_callback_refresh_tag_gizmomap_set(void (*callback)(struct wmGizm region_refresh_tag_gizmomap_callback = callback; } -void BKE_screen_gizmo_tag_refresh(struct bScreen *sc) +void BKE_screen_gizmo_tag_refresh(struct bScreen *screen) { if (region_refresh_tag_gizmomap_callback == NULL) { return; } - ScrArea *sa; + ScrArea *area; ARegion *region; - for (sa = sc->areabase.first; sa; sa = sa->next) { - for (region = sa->regionbase.first; region; region = region->next) { + for (area = screen->areabase.first; area; area = area->next) { + for (region = area->regionbase.first; region; region = region->next) { if (region->gizmo_map != NULL) { region_refresh_tag_gizmomap_callback(region->gizmo_map); } @@ -416,13 +418,13 @@ void BKE_region_callback_free_gizmomap_set(void (*callback)(struct wmGizmoMap *) void BKE_area_region_panels_free(ListBase *lb) { - Panel *pa, *pa_next; - for (pa = lb->first; pa; pa = pa_next) { - pa_next = pa->next; - if (pa->activedata) { - MEM_freeN(pa->activedata); + Panel *panel, *panel_next; + for (panel = lb->first; panel; panel = panel_next) { + panel_next = panel->next; + if (panel->activedata) { + MEM_freeN(panel->activedata); } - BKE_area_region_panels_free(&pa->children); + BKE_area_region_panels_free(&panel->children); } BLI_freelistN(lb); @@ -482,21 +484,21 @@ void BKE_area_region_free(SpaceType *st, ARegion *region) } /* not area itself */ -void BKE_screen_area_free(ScrArea *sa) +void BKE_screen_area_free(ScrArea *area) { - SpaceType *st = BKE_spacetype_from_id(sa->spacetype); + SpaceType *st = BKE_spacetype_from_id(area->spacetype); ARegion *region; - for (region = sa->regionbase.first; region; region = region->next) { + for (region = area->regionbase.first; region; region = region->next) { BKE_area_region_free(st, region); } - MEM_SAFE_FREE(sa->global); - BLI_freelistN(&sa->regionbase); + MEM_SAFE_FREE(area->global); + BLI_freelistN(&area->regionbase); - BKE_spacedata_freelist(&sa->spacedata); + BKE_spacedata_freelist(&area->spacedata); - BLI_freelistN(&sa->actionzones); + BLI_freelistN(&area->actionzones); } void BKE_screen_area_map_free(ScrAreaMap *area_map) @@ -512,19 +514,19 @@ void BKE_screen_area_map_free(ScrAreaMap *area_map) } /** Free (or release) any data used by this screen (does not free the screen itself). */ -void BKE_screen_free(bScreen *sc) +void BKE_screen_free(bScreen *screen) { - screen_free_data(&sc->id); + screen_free_data(&screen->id); } /* ***************** Screen edges & verts ***************** */ -ScrEdge *BKE_screen_find_edge(bScreen *sc, ScrVert *v1, ScrVert *v2) +ScrEdge *BKE_screen_find_edge(bScreen *screen, ScrVert *v1, ScrVert *v2) { ScrEdge *se; BKE_screen_sort_scrvert(&v1, &v2); - for (se = sc->edgebase.first; se; se = se->next) { + for (se = screen->edgebase.first; se; se = se->next) { if (se->v1 == v1 && se->v2 == v2) { return se; } @@ -544,13 +546,13 @@ void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2) } } -void BKE_screen_remove_double_scrverts(bScreen *sc) +void BKE_screen_remove_double_scrverts(bScreen *screen) { ScrVert *v1, *verg; ScrEdge *se; - ScrArea *sa; + ScrArea *area; - verg = sc->vertbase.first; + verg = screen->vertbase.first; while (verg) { if (verg->newv == NULL) { /* !!! */ v1 = verg->next; @@ -568,7 +570,7 @@ void BKE_screen_remove_double_scrverts(bScreen *sc) } /* replace pointers in edges and faces */ - se = sc->edgebase.first; + se = screen->edgebase.first; while (se) { if (se->v1->newv) { se->v1 = se->v1->newv; @@ -580,47 +582,47 @@ void BKE_screen_remove_double_scrverts(bScreen *sc) BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); se = se->next; } - sa = sc->areabase.first; - while (sa) { - if (sa->v1->newv) { - sa->v1 = sa->v1->newv; + area = screen->areabase.first; + while (area) { + if (area->v1->newv) { + area->v1 = area->v1->newv; } - if (sa->v2->newv) { - sa->v2 = sa->v2->newv; + if (area->v2->newv) { + area->v2 = area->v2->newv; } - if (sa->v3->newv) { - sa->v3 = sa->v3->newv; + if (area->v3->newv) { + area->v3 = area->v3->newv; } - if (sa->v4->newv) { - sa->v4 = sa->v4->newv; + if (area->v4->newv) { + area->v4 = area->v4->newv; } - sa = sa->next; + area = area->next; } /* remove */ - verg = sc->vertbase.first; + verg = screen->vertbase.first; while (verg) { v1 = verg->next; if (verg->newv) { - BLI_remlink(&sc->vertbase, verg); + BLI_remlink(&screen->vertbase, verg); MEM_freeN(verg); } verg = v1; } } -void BKE_screen_remove_double_scredges(bScreen *sc) +void BKE_screen_remove_double_scredges(bScreen *screen) { ScrEdge *verg, *se, *sn; /* compare */ - verg = sc->edgebase.first; + verg = screen->edgebase.first; while (verg) { se = verg->next; while (se) { sn = se->next; if (verg->v1 == se->v1 && verg->v2 == se->v2) { - BLI_remlink(&sc->edgebase, se); + BLI_remlink(&screen->edgebase, se); MEM_freeN(se); } se = sn; @@ -629,51 +631,51 @@ void BKE_screen_remove_double_scredges(bScreen *sc) } } -void BKE_screen_remove_unused_scredges(bScreen *sc) +void BKE_screen_remove_unused_scredges(bScreen *screen) { ScrEdge *se, *sen; - ScrArea *sa; + ScrArea *area; int a = 0; /* sets flags when edge is used in area */ - sa = sc->areabase.first; - while (sa) { - se = BKE_screen_find_edge(sc, sa->v1, sa->v2); + area = screen->areabase.first; + while (area) { + se = BKE_screen_find_edge(screen, area->v1, area->v2); if (se == NULL) { printf("error: area %d edge 1 doesn't exist\n", a); } else { se->flag = 1; } - se = BKE_screen_find_edge(sc, sa->v2, sa->v3); + se = BKE_screen_find_edge(screen, area->v2, area->v3); if (se == NULL) { printf("error: area %d edge 2 doesn't exist\n", a); } else { se->flag = 1; } - se = BKE_screen_find_edge(sc, sa->v3, sa->v4); + se = BKE_screen_find_edge(screen, area->v3, area->v4); if (se == NULL) { printf("error: area %d edge 3 doesn't exist\n", a); } else { se->flag = 1; } - se = BKE_screen_find_edge(sc, sa->v4, sa->v1); + se = BKE_screen_find_edge(screen, area->v4, area->v1); if (se == NULL) { printf("error: area %d edge 4 doesn't exist\n", a); } else { se->flag = 1; } - sa = sa->next; + area = area->next; a++; } - se = sc->edgebase.first; + se = screen->edgebase.first; while (se) { sen = se->next; if (se->flag == 0) { - BLI_remlink(&sc->edgebase, se); + BLI_remlink(&screen->edgebase, se); MEM_freeN(se); } else { @@ -683,25 +685,25 @@ void BKE_screen_remove_unused_scredges(bScreen *sc) } } -void BKE_screen_remove_unused_scrverts(bScreen *sc) +void BKE_screen_remove_unused_scrverts(bScreen *screen) { ScrVert *sv, *svn; ScrEdge *se; /* we assume edges are ok */ - se = sc->edgebase.first; + se = screen->edgebase.first; while (se) { se->v1->flag = 1; se->v2->flag = 1; se = se->next; } - sv = sc->vertbase.first; + sv = screen->vertbase.first; while (sv) { svn = sv->next; if (sv->flag == 0) { - BLI_remlink(&sc->vertbase, sv); + BLI_remlink(&screen->vertbase, sv); MEM_freeN(sv); } else { @@ -714,15 +716,15 @@ void BKE_screen_remove_unused_scrverts(bScreen *sc) /* ***************** Utilities ********************** */ /** - * Find a region of type \a region_type in the currently active space of \a sa. + * Find a region of type \a region_type in the currently active space of \a area. * * \note This does _not_ work if the region to look up is not in the active * space. Use #BKE_spacedata_find_region_type if that may be the case. */ -ARegion *BKE_area_find_region_type(const ScrArea *sa, int region_type) +ARegion *BKE_area_find_region_type(const ScrArea *area, int region_type) { - if (sa) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { + if (area) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == region_type) { return region; } @@ -732,87 +734,87 @@ ARegion *BKE_area_find_region_type(const ScrArea *sa, int region_type) return NULL; } -ARegion *BKE_area_find_region_active_win(ScrArea *sa) +ARegion *BKE_area_find_region_active_win(ScrArea *area) { - if (sa) { - ARegion *region = BLI_findlink(&sa->regionbase, sa->region_active_win); + if (area) { + ARegion *region = BLI_findlink(&area->regionbase, area->region_active_win); if (region && (region->regiontype == RGN_TYPE_WINDOW)) { return region; } /* fallback to any */ - return BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + return BKE_area_find_region_type(area, RGN_TYPE_WINDOW); } return NULL; } -ARegion *BKE_area_find_region_xy(ScrArea *sa, const int regiontype, int x, int y) +ARegion *BKE_area_find_region_xy(ScrArea *area, const int regiontype, int x, int y) { - ARegion *ar_found = NULL; - if (sa) { + ARegion *region_found = NULL; + if (area) { ARegion *region; - for (region = sa->regionbase.first; region; region = region->next) { + for (region = area->regionbase.first; region; region = region->next) { if ((regiontype == RGN_TYPE_ANY) || (region->regiontype == regiontype)) { if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { - ar_found = region; + region_found = region; break; } } } } - return ar_found; + return region_found; } /** * \note This is only for screen level regions (typically menus/popups). */ -ARegion *BKE_screen_find_region_xy(bScreen *sc, const int regiontype, int x, int y) +ARegion *BKE_screen_find_region_xy(bScreen *screen, const int regiontype, int x, int y) { - ARegion *ar_found = NULL; - for (ARegion *region = sc->regionbase.first; region; region = region->next) { + ARegion *region_found = NULL; + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { if ((regiontype == RGN_TYPE_ANY) || (region->regiontype == regiontype)) { if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { - ar_found = region; + region_found = region; break; } } } - return ar_found; + return region_found; } /** * \note Ideally we can get the area from the context, * there are a few places however where this isn't practical. */ -ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, SpaceLink *sl) +ScrArea *BKE_screen_find_area_from_space(struct bScreen *screen, SpaceLink *sl) { - ScrArea *sa; + ScrArea *area; - for (sa = sc->areabase.first; sa; sa = sa->next) { - if (BLI_findindex(&sa->spacedata, sl) != -1) { + for (area = screen->areabase.first; area; area = area->next) { + if (BLI_findindex(&area->spacedata, sl) != -1) { break; } } - return sa; + return area; } /** * \note Using this function is generally a last resort, you really want to be * using the context when you can - campbell */ -ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short min) +ScrArea *BKE_screen_find_big_area(bScreen *screen, const int spacetype, const short min) { - ScrArea *sa, *big = NULL; + ScrArea *area, *big = NULL; int size, maxsize = 0; - for (sa = sc->areabase.first; sa; sa = sa->next) { - if ((spacetype == SPACE_TYPE_ANY) || (sa->spacetype == spacetype)) { - if (min <= sa->winx && min <= sa->winy) { - size = sa->winx * sa->winy; + for (area = screen->areabase.first; area; area = area->next) { + if ((spacetype == SPACE_TYPE_ANY) || (area->spacetype == spacetype)) { + if (min <= area->winx && min <= area->winy) { + size = area->winx * area->winy; if (size > maxsize) { maxsize = size; - big = sa; + big = area; } } } @@ -826,19 +828,19 @@ ScrArea *BKE_screen_area_map_find_area_xy(const ScrAreaMap *areamap, int x, int y) { - for (ScrArea *sa = areamap->areabase.first; sa; sa = sa->next) { - if (BLI_rcti_isect_pt(&sa->totrct, x, y)) { - if ((spacetype == SPACE_TYPE_ANY) || (sa->spacetype == spacetype)) { - return sa; + LISTBASE_FOREACH (ScrArea *, area, &areamap->areabase) { + if (BLI_rcti_isect_pt(&area->totrct, x, y)) { + if ((spacetype == SPACE_TYPE_ANY) || (area->spacetype == spacetype)) { + return area; } break; } } return NULL; } -ScrArea *BKE_screen_find_area_xy(bScreen *sc, const int spacetype, int x, int y) +ScrArea *BKE_screen_find_area_xy(bScreen *screen, const int spacetype, int x, int y) { - return BKE_screen_area_map_find_area_xy(AREAMAP_FROM_SCREEN(sc), spacetype, x, y); + return BKE_screen_area_map_find_area_xy(AREAMAP_FROM_SCREEN(screen), spacetype, x, y); } void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene) @@ -861,13 +863,13 @@ void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene) } } -void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene) +void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene) { /* are there cameras in the views that are not in the scene? */ - ScrArea *sa; - for (sa = sc->areabase.first; sa; sa = sa->next) { + ScrArea *area; + for (area = screen->areabase.first; area; area = area->next) { SpaceLink *sl; - for (sl = sa->spacedata.first; sl; sl = sl->next) { + for (sl = area->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; BKE_screen_view3d_sync(v3d, scene); @@ -913,17 +915,17 @@ bool BKE_screen_is_used(const bScreen *screen) void BKE_screen_header_alignment_reset(bScreen *screen) { int alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (ELEM(region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { - if (ELEM(sa->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_PROPERTIES)) { + if (ELEM(area->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_PROPERTIES)) { region->alignment = RGN_ALIGN_TOP; continue; } region->alignment = alignment; } if (region->regiontype == RGN_TYPE_FOOTER) { - if (ELEM(sa->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_PROPERTIES)) { + if (ELEM(area->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_PROPERTIES)) { region->alignment = RGN_ALIGN_BOTTOM; continue; } diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 7c34b676e69..6acc50f30e9 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -30,6 +30,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_listbase.h" #include "BLI_math.h" /* windows needs for M_PI */ #include "BLI_path_util.h" #include "BLI_rect.h" @@ -3165,7 +3166,6 @@ void BKE_sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, bool for /* XXX - new in 2.5x. should we use the animation system this way? * The fcurve is needed because many frames need evaluating at once - campbell */ fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0, NULL); - if (!v->frameMap || v->length != seq->len) { if (v->frameMap) { MEM_freeN(v->frameMap); diff --git a/source/blender/blenkernel/intern/seqprefetch.c b/source/blender/blenkernel/intern/seqprefetch.c index 8c7d119857a..1bd02212908 100644 --- a/source/blender/blenkernel/intern/seqprefetch.c +++ b/source/blender/blenkernel/intern/seqprefetch.c @@ -39,6 +39,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_layer.h" diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 9fb28fe250a..bb1d8cb2e9b 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -58,6 +58,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_animsys.h" #include "BKE_fcurve.h" #include "BKE_global.h" @@ -120,7 +121,7 @@ static ThreadMutex seq_render_mutex = BLI_MUTEX_INITIALIZER; #define SELECT 1 ListBase seqbase_clipboard; int seqbase_clipboard_frame; -SequencerDrawView sequencer_view3d_cb = NULL; /* NULL in background mode */ +SequencerDrawView sequencer_view3d_fn = NULL; /* NULL in background mode */ #if 0 /* unused function */ static void printf_strip(Sequence *seq) @@ -152,28 +153,28 @@ static void sequencer_state_init(SeqRenderState *state) } int BKE_sequencer_base_recursive_apply(ListBase *seqbase, - int (*apply_func)(Sequence *seq, void *), + int (*apply_fn)(Sequence *seq, void *), void *arg) { Sequence *iseq; for (iseq = seqbase->first; iseq; iseq = iseq->next) { - if (BKE_sequencer_recursive_apply(iseq, apply_func, arg) == -1) { + if (BKE_sequencer_recursive_apply(iseq, apply_fn, arg) == -1) { return -1; /* bail out */ } } return 1; } -int BKE_sequencer_recursive_apply(Sequence *seq, int (*apply_func)(Sequence *, void *), void *arg) +int BKE_sequencer_recursive_apply(Sequence *seq, int (*apply_fn)(Sequence *, void *), void *arg) { - int ret = apply_func(seq, arg); + int ret = apply_fn(seq, arg); if (ret == -1) { return -1; /* bail out */ } if (ret && seq->seqbase.first) { - ret = BKE_sequencer_base_recursive_apply(&seq->seqbase, apply_func, arg); + ret = BKE_sequencer_base_recursive_apply(&seq->seqbase, apply_fn, arg); } return ret; @@ -752,10 +753,10 @@ static int metaseq_end(Sequence *metaseq) return metaseq->start + metaseq->len - metaseq->endofs; } -static void seq_update_sound_bounds_recursive_rec(Scene *scene, - Sequence *metaseq, - int start, - int end) +static void seq_update_sound_bounds_recursive_impl(Scene *scene, + Sequence *metaseq, + int start, + int end) { Sequence *seq; @@ -763,7 +764,7 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, * since sound is played outside of evaluating the imbufs, */ for (seq = metaseq->seqbase.first; seq; seq = seq->next) { if (seq->type == SEQ_TYPE_META) { - seq_update_sound_bounds_recursive_rec( + seq_update_sound_bounds_recursive_impl( scene, seq, max_ii(start, metaseq_start(seq)), min_ii(end, metaseq_end(seq))); } else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { @@ -790,7 +791,7 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, static void seq_update_sound_bounds_recursive(Scene *scene, Sequence *metaseq) { - seq_update_sound_bounds_recursive_rec( + seq_update_sound_bounds_recursive_impl( scene, metaseq, metaseq_start(metaseq), metaseq_end(metaseq)); } @@ -1138,7 +1139,7 @@ int BKE_sequencer_cmp_time_startdisp(const void *a, const void *b) return (seq_a->startdisp > seq_b->startdisp); } -static int clear_scene_in_allseqs_cb(Sequence *seq, void *arg_pt) +static int clear_scene_in_allseqs_fn(Sequence *seq, void *arg_pt) { if (seq->scene == (Scene *)arg_pt) { seq->scene = NULL; @@ -1154,7 +1155,7 @@ void BKE_sequencer_clear_scene_in_allseqs(Main *bmain, Scene *scene) for (scene_iter = bmain->scenes.first; scene_iter; scene_iter = scene_iter->id.next) { if (scene_iter != scene && scene_iter->ed) { BKE_sequencer_base_recursive_apply( - &scene_iter->ed->seqbase, clear_scene_in_allseqs_cb, scene); + &scene_iter->ed->seqbase, clear_scene_in_allseqs_fn, scene); } } } @@ -1184,7 +1185,7 @@ static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui) } } -static int seqbase_unique_name_recursive_cb(Sequence *seq, void *arg_pt) +static int seqbase_unique_name_recursive_fn(Sequence *seq, void *arg_pt) { if (seq->seqbase.first) { seqbase_unique_name(&seq->seqbase, (SeqUniqueInfo *)arg_pt); @@ -1216,7 +1217,7 @@ void BKE_sequence_base_unique_name_recursive(ListBase *seqbasep, Sequence *seq) while (sui.match) { sui.match = 0; seqbase_unique_name(seqbasep, &sui); - BKE_sequencer_base_recursive_apply(seqbasep, seqbase_unique_name_recursive_cb, &sui); + BKE_sequencer_base_recursive_apply(seqbasep, seqbase_unique_name_recursive_fn, &sui); } BLI_strncpy(seq->name + 2, sui.name_dest, sizeof(seq->name) - 2); @@ -1458,7 +1459,7 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr memset(seq_arr, 0, sizeof(Sequence *) * (MAXSEQ + 1)); - for (Sequence *seq = seqbase->first; seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, seqbase) { if ((seq->startdisp <= cfra) && (seq->enddisp > cfra)) { if ((seq->type & SEQ_TYPE_EFFECT) && !(seq->flag & SEQ_MUTE)) { @@ -3498,7 +3499,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, is_frame_update = (orig_data.cfra != scene->r.cfra) || (orig_data.subframe != scene->r.subframe); - if ((sequencer_view3d_cb && do_seq_gl && camera) && is_thread_main) { + if ((sequencer_view3d_fn && do_seq_gl && camera) && is_thread_main) { char err_out[256] = "unknown"; const int width = (scene->r.xsch * scene->r.size) / 100; const int height = (scene->r.ysch * scene->r.size) / 100; @@ -3519,7 +3520,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, /* opengl offscreen render */ depsgraph = BKE_scene_get_depsgraph(context->bmain, scene, view_layer, true); BKE_scene_graph_update_for_newframe(depsgraph, context->bmain); - ibuf = sequencer_view3d_cb( + ibuf = sequencer_view3d_fn( /* set for OpenGL render (NULL when scrubbing) */ depsgraph, scene, diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index d81ebe0fb64..980cc2a59fd 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -28,7 +28,6 @@ #include "BLT_translation.h" -#include "BKE_animsys.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_main.h" diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index 3c1a9c4d3d6..521aeb60e66 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -589,7 +589,7 @@ Mesh *BKE_subdiv_to_ccg_mesh(Subdiv *subdiv, { /* Make sure evaluator is ready. */ BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_SUBDIV_TO_CCG); - if (!BKE_subdiv_eval_update_from_mesh(subdiv, coarse_mesh, NULL)) { + if (!BKE_subdiv_eval_begin_from_mesh(subdiv, coarse_mesh, NULL)) { if (coarse_mesh->totpoly) { return NULL; } @@ -1780,3 +1780,14 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, } #endif } + +int BKE_subdiv_cgg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index) +{ + // Subdiv *subdiv = subdiv_ccg->subdiv; /* UNUSED */ + // OpenSubdiv_TopologyRefiner *topology_refiner = subdiv->topology_refiner; /* UNUSED */ + SubdivCCGFace *face = subdiv_ccg->grid_faces[grid_index]; + + // const int face_grid_index = grid_index - face->start_grid_index; /* UNUSED */ + const int face_index = face - subdiv_ccg->faces; + return face_index; +} diff --git a/source/blender/blenkernel/intern/subdiv_deform.c b/source/blender/blenkernel/intern/subdiv_deform.c index b5fd3ae63eb..db0a51c390b 100644 --- a/source/blender/blenkernel/intern/subdiv_deform.c +++ b/source/blender/blenkernel/intern/subdiv_deform.c @@ -194,7 +194,7 @@ void BKE_subdiv_deform_coarse_vertices(struct Subdiv *subdiv, BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_SUBDIV_TO_MESH); /* Make sure evaluator is up to date with possible new topology, and that * is refined for the new positions of coarse vertices. */ - if (!BKE_subdiv_eval_update_from_mesh(subdiv, coarse_mesh, vertex_cos)) { + if (!BKE_subdiv_eval_begin_from_mesh(subdiv, coarse_mesh, vertex_cos)) { /* This could happen in two situations: * - OpenSubdiv is disabled. * - Something totally bad happened, and OpenSubdiv rejected our diff --git a/source/blender/blenkernel/intern/subdiv_eval.c b/source/blender/blenkernel/intern/subdiv_eval.c index 78e0e42753a..1c10a9a1935 100644 --- a/source/blender/blenkernel/intern/subdiv_eval.c +++ b/source/blender/blenkernel/intern/subdiv_eval.c @@ -121,13 +121,20 @@ static void set_face_varying_data_from_uv(Subdiv *subdiv, } } -bool BKE_subdiv_eval_update_from_mesh(Subdiv *subdiv, - const Mesh *mesh, - const float (*coarse_vertex_cos)[3]) +bool BKE_subdiv_eval_begin_from_mesh(Subdiv *subdiv, + const Mesh *mesh, + const float (*coarse_vertex_cos)[3]) { if (!BKE_subdiv_eval_begin(subdiv)) { return false; } + return BKE_subdiv_eval_refine_from_mesh(subdiv, mesh, coarse_vertex_cos); +} + +bool BKE_subdiv_eval_refine_from_mesh(Subdiv *subdiv, + const Mesh *mesh, + const float (*coarse_vertex_cos)[3]) +{ if (subdiv->evaluator == NULL) { /* NOTE: This situation is supposed to be handled by begin(). */ BLI_assert(!"Is not supposed to happen"); diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c index 6e39f9f302b..b31fb2c9312 100644 --- a/source/blender/blenkernel/intern/subdiv_foreach.c +++ b/source/blender/blenkernel/intern/subdiv_foreach.c @@ -1880,7 +1880,7 @@ bool BKE_subdiv_foreach_subdiv_geometry(Subdiv *subdiv, * the tasks into it. * NOTE: Watch out for callbacks which needs to run for loose geometry as they * currently are relying on the fact that face/grid callbacks will tag non- - * loose geomtry. */ + * loose geometry. */ BLI_task_parallel_range( 0, coarse_mesh->totpoly, &ctx, subdiv_foreach_task, ¶llel_range_settings); diff --git a/source/blender/blenkernel/intern/subdiv_mesh.c b/source/blender/blenkernel/intern/subdiv_mesh.c index cdb766f2507..bd091108b11 100644 --- a/source/blender/blenkernel/intern/subdiv_mesh.c +++ b/source/blender/blenkernel/intern/subdiv_mesh.c @@ -1168,7 +1168,7 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv, BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_SUBDIV_TO_MESH); /* Make sure evaluator is up to date with possible new topology, and that * it is refined for the new positions of coarse vertices. */ - if (!BKE_subdiv_eval_update_from_mesh(subdiv, coarse_mesh, NULL)) { + if (!BKE_subdiv_eval_begin_from_mesh(subdiv, coarse_mesh, NULL)) { /* This could happen in two situations: * - OpenSubdiv is disabled. * - Something totally bad happened, and OpenSubdiv rejected our diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 94c41777cea..3cdf3b40ce3 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -164,7 +164,7 @@ static void text_copy_data(Main *UNUSED(bmain), text_dst->compiled = NULL; /* Walk down, reconstructing. */ - for (TextLine *line_src = text_src->lines.first; line_src; line_src = line_src->next) { + LISTBASE_FOREACH (TextLine *, line_src, &text_src->lines) { TextLine *line_dst = MEM_mallocN(sizeof(*line_dst), __func__); line_dst->line = BLI_strdup(line_src->line); @@ -1311,12 +1311,12 @@ void txt_sel_set(Text *text, int startl, int startc, int endl, int endc) char *txt_to_buf_for_undo(Text *text, int *r_buf_len) { int buf_len = 0; - for (const TextLine *l = text->lines.first; l; l = l->next) { + LISTBASE_FOREACH (const TextLine *, l, &text->lines) { buf_len += l->len + 1; } char *buf = MEM_mallocN(buf_len, __func__); char *buf_step = buf; - for (const TextLine *l = text->lines.first; l; l = l->next) { + LISTBASE_FOREACH (const TextLine *, l, &text->lines) { memcpy(buf_step, l->line, l->len); buf_step += l->len; *buf_step++ = '\n'; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index b0f000d6e04..fe10861f96e 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -29,6 +29,7 @@ #include "MEM_guardedalloc.h" #include "BLI_kdopbvh.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_math_color.h" #include "BLI_utildefines.h" @@ -49,7 +50,6 @@ #include "BKE_main.h" -#include "BKE_animsys.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_icons.h" @@ -697,7 +697,7 @@ static void texture_nodes_fetch_images_for_pool(Tex *texture, bNodeTree *ntree, struct ImagePool *pool) { - for (bNode *node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == SH_NODE_TEX_IMAGE && node->id != NULL) { Image *image = (Image *)node->id; BKE_image_pool_acquire_ibuf(image, &texture->iuser, pool); diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index 5c1f6caad9d..46870a03e62 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -600,7 +600,7 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, sub_v3_v3(camera->mat[3], first_camera_delta); } - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (track->flag & TRACK_HAS_BUNDLE) { mul_v3_v3(track->bundle_pos, scale); sub_v3_v3(track->bundle_pos, first_camera_delta); diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index b111dee80ad..e776e9bedb0 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -110,7 +110,7 @@ static ListBase g_undo_types = {NULL, NULL}; static const UndoType *BKE_undosys_type_from_context(bContext *C) { - for (const UndoType *ut = g_undo_types.first; ut; ut = ut->next) { + LISTBASE_FOREACH (const UndoType *, ut, &g_undo_types) { /* No poll means we don't check context. */ if (ut->poll && ut->poll(C)) { return ut; @@ -143,7 +143,7 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref) * for now it's not too bad since it only runs when we access undo! */ Main *bmain = user_data; ListBase *lb = which_libbase(bmain, GS(id_ref->name)); - for (ID *id = lb->first; id; id = id->next) { + LISTBASE_FOREACH (ID *, id, lb) { if (STREQ(id_ref->name, id->name) && (id->lib == NULL)) { id_ref->ptr = id; break; @@ -857,7 +857,7 @@ static void UNUSED_FUNCTION(BKE_undosys_foreach_ID_ref(UndoStack *ustack, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)) { - for (UndoStep *us = ustack->steps.first; us; us = us->next) { + LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) { const UndoType *ut = us->type; if (ut->step_foreach_ID_ref != NULL) { ut->step_foreach_ID_ref(us, foreach_ID_ref_fn, user_data); @@ -876,13 +876,14 @@ void BKE_undosys_print(UndoStack *ustack) printf("Undo %d Steps (*: active, #=applied, M=memfile-active, S=skip)\n", BLI_listbase_count(&ustack->steps)); int index = 0; - for (UndoStep *us = ustack->steps.first; us; us = us->next) { - printf("[%c%c%c%c] %3d type='%s', name='%s'\n", + LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) { + printf("[%c%c%c%c] %3d {%p} type='%s', name='%s'\n", (us == ustack->step_active) ? '*' : ' ', us->is_applied ? '#' : ' ', (us == ustack->step_active_memfile) ? 'M' : ' ', us->skip ? 'S' : ' ', index, + (void *)us, us->type->name, us->name); index++; diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index 6e00a942283..9d9e8423bcf 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -33,7 +33,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_global.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -901,6 +901,16 @@ const char *BKE_volume_grids_error_msg(const Volume *volume) #endif } +const char *BKE_volume_grids_frame_filepath(const Volume *volume) +{ +#ifdef WITH_OPENVDB + return volume->runtime.grids->filepath; +#else + UNUSED_VARS(volume); + return ""; +#endif +} + VolumeGrid *BKE_volume_grid_get(const Volume *volume, int grid_index) { #ifdef WITH_OPENVDB diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 66a3c2cdced..c65d55785c1 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -396,7 +396,7 @@ void BKE_workspace_id_tag_all_visible(Main *bmain, int tag) { BKE_main_id_tag_listbase(&bmain->workspaces, tag, false); wmWindowManager *wm = bmain->wm.first; - for (wmWindow *win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); workspace->id.tag |= tag; } diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 3492a35b242..f2219ad1cf8 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -35,7 +35,6 @@ #include "BLI_listbase.h" #include "BLI_utildefines.h" -#include "BKE_animsys.h" #include "BKE_icons.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" |