Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_blender_version.h6
-rw-r--r--source/blender/blenkernel/BKE_colortools.h2
-rw-r--r--source/blender/blenkernel/BKE_curveprofile.h2
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h5
-rw-r--r--source/blender/blenkernel/BKE_gpencil_curve.h4
-rw-r--r--source/blender/blenkernel/BKE_image.h29
-rw-r--r--source/blender/blenkernel/BKE_lib_override.h2
-rw-r--r--source/blender/blenkernel/BKE_modifier.h6
-rw-r--r--source/blender/blenkernel/BKE_movieclip.h5
-rw-r--r--source/blender/blenkernel/BKE_node.h3
-rw-r--r--source/blender/blenkernel/BKE_object.h2
-rw-r--r--source/blender/blenkernel/BKE_ocean.h6
-rw-r--r--source/blender/blenkernel/BKE_paint.h103
-rw-r--r--source/blender/blenkernel/BKE_particle.h2
-rw-r--r--source/blender/blenkernel/BKE_persistent_data_handle.hh24
-rw-r--r--source/blender/blenkernel/BKE_screen.h12
-rw-r--r--source/blender/blenkernel/BKE_sequencer.h4
-rw-r--r--source/blender/blenkernel/BKE_simulation.h1
-rw-r--r--source/blender/blenkernel/BKE_subdiv_ccg.h3
-rw-r--r--source/blender/blenkernel/CMakeLists.txt8
-rw-r--r--source/blender/blenkernel/intern/CCGSubSurf.c12
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c14
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c2
-rw-r--r--source/blender/blenkernel/intern/armature.c2
-rw-r--r--source/blender/blenkernel/intern/armature_update.c2
-rw-r--r--source/blender/blenkernel/intern/boids.c2
-rw-r--r--source/blender/blenkernel/intern/brush.c33
-rw-r--r--source/blender/blenkernel/intern/cachefile.c2
-rw-r--r--source/blender/blenkernel/intern/camera.c124
-rw-r--r--source/blender/blenkernel/intern/cloth.c17
-rw-r--r--source/blender/blenkernel/intern/collection.c31
-rw-r--r--source/blender/blenkernel/intern/collision.c301
-rw-r--r--source/blender/blenkernel/intern/colorband.c21
-rw-r--r--source/blender/blenkernel/intern/colortools.c51
-rw-r--r--source/blender/blenkernel/intern/constraint.c35
-rw-r--r--source/blender/blenkernel/intern/context.c97
-rw-r--r--source/blender/blenkernel/intern/curve.c220
-rw-r--r--source/blender/blenkernel/intern/curve_bevel.c272
-rw-r--r--source/blender/blenkernel/intern/curveprofile.c29
-rw-r--r--source/blender/blenkernel/intern/customdata.c63
-rw-r--r--source/blender/blenkernel/intern/customdata_file.c10
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c29
-rw-r--r--source/blender/blenkernel/intern/deform.c83
-rw-r--r--source/blender/blenkernel/intern/displist.c24
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c14
-rw-r--r--source/blender/blenkernel/intern/editmesh_cache.c9
-rw-r--r--source/blender/blenkernel/intern/editmesh_tangent.c4
-rw-r--r--source/blender/blenkernel/intern/effect.c4
-rw-r--r--source/blender/blenkernel/intern/fcurve.c4
-rw-r--r--source/blender/blenkernel/intern/fcurve_driver.c395
-rw-r--r--source/blender/blenkernel/intern/fluid.c136
-rw-r--r--source/blender/blenkernel/intern/fmodifier.c71
-rw-r--r--source/blender/blenkernel/intern/font.c69
-rw-r--r--source/blender/blenkernel/intern/gpencil.c177
-rw-r--r--source/blender/blenkernel/intern/gpencil_curve.c317
-rw-r--r--source/blender/blenkernel/intern/gpencil_geom.c60
-rw-r--r--source/blender/blenkernel/intern/gpencil_modifier.c5
-rw-r--r--source/blender/blenkernel/intern/hair.c4
-rw-r--r--source/blender/blenkernel/intern/icons.c19
-rw-r--r--source/blender/blenkernel/intern/idprop.c33
-rw-r--r--source/blender/blenkernel/intern/idtype.c5
-rw-r--r--source/blender/blenkernel/intern/image.c284
-rw-r--r--source/blender/blenkernel/intern/image_gpu.c774
-rw-r--r--source/blender/blenkernel/intern/ipo.c16
-rw-r--r--source/blender/blenkernel/intern/key.c2
-rw-r--r--source/blender/blenkernel/intern/lattice.c10
-rw-r--r--source/blender/blenkernel/intern/lattice_deform.c2
-rw-r--r--source/blender/blenkernel/intern/layer.c27
-rw-r--r--source/blender/blenkernel/intern/lib_id.c15
-rw-r--r--source/blender/blenkernel/intern/lib_override.c7
-rw-r--r--source/blender/blenkernel/intern/lib_query.c8
-rw-r--r--source/blender/blenkernel/intern/light.c2
-rw-r--r--source/blender/blenkernel/intern/main_idmap.c2
-rw-r--r--source/blender/blenkernel/intern/mask.c137
-rw-r--r--source/blender/blenkernel/intern/mask_evaluate.c13
-rw-r--r--source/blender/blenkernel/intern/mask_rasterize.c70
-rw-r--r--source/blender/blenkernel/intern/material.c44
-rw-r--r--source/blender/blenkernel/intern/mball.c7
-rw-r--r--source/blender/blenkernel/intern/mball_tessellate.c12
-rw-r--r--source/blender/blenkernel/intern/mesh.c56
-rw-r--r--source/blender/blenkernel/intern/mesh_convert.c14
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c34
-rw-r--r--source/blender/blenkernel/intern/mesh_mapping.c7
-rw-r--r--source/blender/blenkernel/intern/mesh_merge.c18
-rw-r--r--source/blender/blenkernel/intern/mesh_mirror.c2
-rw-r--r--source/blender/blenkernel/intern/mesh_remap.c10
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.c33
-rw-r--r--source/blender/blenkernel/intern/modifier.c65
-rw-r--r--source/blender/blenkernel/intern/movieclip.c90
-rw-r--r--source/blender/blenkernel/intern/multires.c29
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_apply_base.c6
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_ccg.c2
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_util.c2
-rw-r--r--source/blender/blenkernel/intern/multires_unsubdivide.c8
-rw-r--r--source/blender/blenkernel/intern/nla.c103
-rw-r--r--source/blender/blenkernel/intern/node.c62
-rw-r--r--source/blender/blenkernel/intern/object.c96
-rw-r--r--source/blender/blenkernel/intern/object_deform.c2
-rw-r--r--source/blender/blenkernel/intern/object_dupli.c83
-rw-r--r--source/blender/blenkernel/intern/object_facemap.c2
-rw-r--r--source/blender/blenkernel/intern/ocean.c23
-rw-r--r--source/blender/blenkernel/intern/packedFile.c29
-rw-r--r--source/blender/blenkernel/intern/paint.c41
-rw-r--r--source/blender/blenkernel/intern/particle.c200
-rw-r--r--source/blender/blenkernel/intern/particle_child.c9
-rw-r--r--source/blender/blenkernel/intern/particle_distribute.c16
-rw-r--r--source/blender/blenkernel/intern/particle_system.c331
-rw-r--r--source/blender/blenkernel/intern/pbvh.c90
-rw-r--r--source/blender/blenkernel/intern/pbvh_bmesh.c14
-rw-r--r--source/blender/blenkernel/intern/pointcache.c81
-rw-r--r--source/blender/blenkernel/intern/pointcloud.c4
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c127
-rw-r--r--source/blender/blenkernel/intern/scene.c174
-rw-r--r--source/blender/blenkernel/intern/screen.c8
-rw-r--r--source/blender/blenkernel/intern/seqcache.c25
-rw-r--r--source/blender/blenkernel/intern/seqeffects.c33
-rw-r--r--source/blender/blenkernel/intern/seqmodifier.c8
-rw-r--r--source/blender/blenkernel/intern/seqprefetch.c2
-rw-r--r--source/blender/blenkernel/intern/sequencer.c184
-rw-r--r--source/blender/blenkernel/intern/shader_fx.c5
-rw-r--r--source/blender/blenkernel/intern/shrinkwrap.c35
-rw-r--r--source/blender/blenkernel/intern/simulation.cc28
-rw-r--r--source/blender/blenkernel/intern/softbody.c31
-rw-r--r--source/blender/blenkernel/intern/sound.c12
-rw-r--r--source/blender/blenkernel/intern/studiolight.c51
-rw-r--r--source/blender/blenkernel/intern/subdiv_ccg.c73
-rw-r--r--source/blender/blenkernel/intern/subdiv_deform.c2
-rw-r--r--source/blender/blenkernel/intern/subdiv_displacement_multires.c9
-rw-r--r--source/blender/blenkernel/intern/subdiv_eval.c2
-rw-r--r--source/blender/blenkernel/intern/subdiv_foreach.c8
-rw-r--r--source/blender/blenkernel/intern/subdiv_mesh.c2
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c36
-rw-r--r--source/blender/blenkernel/intern/text.c37
-rw-r--r--source/blender/blenkernel/intern/texture.c4
-rw-r--r--source/blender/blenkernel/intern/tracking.c183
-rw-r--r--source/blender/blenkernel/intern/tracking_solver.c2
-rw-r--r--source/blender/blenkernel/intern/tracking_stabilize.c56
-rw-r--r--source/blender/blenkernel/intern/undo_system.c5
-rw-r--r--source/blender/blenkernel/intern/unit.c12
-rw-r--r--source/blender/blenkernel/intern/volume.cc25
-rw-r--r--source/blender/blenkernel/intern/volume_render.cc5
-rw-r--r--source/blender/blenkernel/intern/workspace.c12
142 files changed, 4298 insertions, 2923 deletions
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 3df09d08814..6ea113d8828 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -31,15 +31,15 @@ extern "C" {
*/
/* Blender major and minor version. */
-#define BLENDER_VERSION 290
+#define BLENDER_VERSION 291
/* Blender patch version for bugfix releases. */
#define BLENDER_VERSION_PATCH 0
/** Blender release cycle stage: alpha/beta/rc/release. */
-#define BLENDER_VERSION_CYCLE beta
+#define BLENDER_VERSION_CYCLE alpha
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 7
+#define BLENDER_FILE_SUBVERSION 0
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h
index 5a68514a387..1ada83c0163 100644
--- a/source/blender/blenkernel/BKE_colortools.h
+++ b/source/blender/blenkernel/BKE_colortools.h
@@ -69,7 +69,7 @@ void BKE_curvemapping_changed(struct CurveMapping *cumap, const bool rem_doubles
void BKE_curvemapping_changed_all(struct CurveMapping *cumap);
/* call before _all_ evaluation functions */
-void BKE_curvemapping_initialize(struct CurveMapping *cumap);
+void BKE_curvemapping_init(struct CurveMapping *cumap);
/* keep these (const CurveMap) - to help with thread safety */
/* single curve, no table check */
diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h
index 84dbcd25b32..9c72a866fa9 100644
--- a/source/blender/blenkernel/BKE_curveprofile.h
+++ b/source/blender/blenkernel/BKE_curveprofile.h
@@ -71,7 +71,7 @@ void BKE_curveprofile_create_samples(struct CurveProfile *profile,
bool sample_straight_edges,
struct CurveProfilePoint *r_samples);
-void BKE_curveprofile_initialize(struct CurveProfile *profile, short segments_len);
+void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len);
/* Called for a complete update of the widget after modifications */
enum {
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 6defc2ffd68..88eef40ebd2 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -131,6 +131,11 @@ bool BKE_gpencil_merge_materials_table_get(struct Object *ob,
const float sat_threshold,
const float val_threshold,
struct GHash *r_mat_table);
+bool BKE_gpencil_merge_materials(struct Object *ob,
+ const float hue_threshold,
+ const float sat_threshold,
+ const float val_threshold,
+ int *r_removed);
/* statistics functions */
void BKE_gpencil_stats_update(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 3fbd0ce1a51..c61427c6c4a 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -35,9 +35,9 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
struct Scene *scene,
struct Object *ob_gp,
struct Object *ob_cu,
- const bool gpencil_lines,
const bool use_collections,
- const bool only_stroke);
+ const float scale_thickness,
+ const float sample);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index a18084f8bbd..f052ba400fc 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -54,6 +54,7 @@ void BKE_image_free_packedfiles(struct Image *image);
void BKE_image_free_views(struct Image *image);
void BKE_image_free_buffers(struct Image *image);
void BKE_image_free_buffers_ex(struct Image *image, bool do_lock);
+void BKE_image_free_gputextures(struct Image *ima);
/* call from library */
void BKE_image_free(struct Image *image);
@@ -273,6 +274,10 @@ void BKE_image_free_anim_ibufs(struct Image *ima, int except_frame);
/* does all images with type MOVIE or SEQUENCE */
void BKE_image_all_free_anim_ibufs(struct Main *bmain, int except_frame);
+void BKE_image_free_all_gputextures(struct Main *bmain);
+void BKE_image_free_anim_gputextures(struct Main *bmain);
+void BKE_image_free_old_gputextures(struct Main *bmain);
+
bool BKE_image_memorypack(struct Image *ima);
void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const char *basepath);
void BKE_image_packfiles_from_mem(struct ReportList *reports,
@@ -361,6 +366,30 @@ bool BKE_image_has_loaded_ibuf(struct Image *image);
struct ImBuf *BKE_image_get_ibuf_with_name(struct Image *image, const char *name);
struct ImBuf *BKE_image_get_first_ibuf(struct Image *image);
+/* Not to be use directly. */
+struct GPUTexture *BKE_image_create_gpu_texture_from_ibuf(struct Image *image, struct ImBuf *ibuf);
+
+/* Get the GPUTexture for a given `Image`.
+ *
+ * `iuser` and `ibuf` are mutual exclusive parameters. The caller can pass the `ibuf` when already
+ * available. It is also required when requesting the GPUTexture for a render result. */
+struct GPUTexture *BKE_image_get_gpu_texture(struct Image *image,
+ struct ImageUser *iuser,
+ struct ImBuf *ibuf);
+struct GPUTexture *BKE_image_get_gpu_tiles(struct Image *image,
+ struct ImageUser *iuser,
+ struct ImBuf *ibuf);
+struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
+ struct ImageUser *iuser,
+ struct ImBuf *ibuf);
+
+void BKE_image_update_gputexture(
+ struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
+void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap);
+
+/* Delayed free of OpenGL buffers by main thread */
+void BKE_image_free_unused_gpu_textures(void);
+
struct RenderSlot *BKE_image_add_renderslot(struct Image *ima, const char *name);
bool BKE_image_remove_renderslot(struct Image *ima, struct ImageUser *iuser, int slot);
struct RenderSlot *BKE_image_get_renderslot(struct Image *ima, int slot);
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 5af73a1579d..5843992b25c 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -140,7 +140,7 @@ void BKE_lib_override_library_main_update(struct Main *bmain);
/* For now, we just use a temp main list. */
typedef struct Main OverrideLibraryStorage;
-OverrideLibraryStorage *BKE_lib_override_library_operations_store_initialize(void);
+OverrideLibraryStorage *BKE_lib_override_library_operations_store_init(void);
struct ID *BKE_lib_override_library_operations_store_start(
struct Main *bmain, OverrideLibraryStorage *override_storage, struct ID *local);
void BKE_lib_override_library_operations_store_end(OverrideLibraryStorage *override_storage,
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index f9590696c2e..98dc411239e 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -413,9 +413,13 @@ void BKE_modifier_type_panel_id(ModifierType type, char *r_idname);
* default values if pointer is optional.
*/
struct ModifierData *BKE_modifier_new(int type);
+
void BKE_modifier_free_ex(struct ModifierData *md, const int flag);
void BKE_modifier_free(struct ModifierData *md);
+/* Generate new UUID for the given modifier. */
+void BKE_modifier_session_uuid_generate(struct ModifierData *md);
+
bool BKE_modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
void BKE_modifier_copydata_generic(const struct ModifierData *md,
@@ -539,6 +543,8 @@ void BKE_modifier_deform_vertsEM(ModifierData *md,
struct Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(struct Object *ob_eval,
const bool get_cage_mesh);
+void BKE_modifier_check_uuids_unique_and_report(const struct Object *object);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h
index d1f6efc035b..958fbef1f97 100644
--- a/source/blender/blenkernel/BKE_movieclip.h
+++ b/source/blender/blenkernel/BKE_movieclip.h
@@ -112,6 +112,11 @@ bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip,
struct MovieClipUser *user,
struct ImBuf *ibuf);
+struct GPUTexture *BKE_movieclip_get_gpu_texture(struct MovieClip *clip,
+ struct MovieClipUser *cuser);
+
+void BKE_movieclip_free_gputexture(struct MovieClip *clip);
+
/* Dependency graph evaluation. */
void BKE_movieclip_eval_update(struct Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index b9e2531755b..ef46bc0f202 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1330,6 +1330,8 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define SIM_NODE_EMIT_PARTICLES 1009
#define SIM_NODE_TIME 1010
#define SIM_NODE_PARTICLE_ATTRIBUTE 1011
+#define SIM_NODE_AGE_REACHED_EVENT 1012
+#define SIM_NODE_KILL_PARTICLE 1013
/** \} */
@@ -1343,6 +1345,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define FN_NODE_GROUP_INSTANCE_ID 1203
#define FN_NODE_COMBINE_STRINGS 1204
#define FN_NODE_OBJECT_TRANSFORMS 1205
+#define FN_NODE_RANDOM_FLOAT 1206
/** \} */
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 215f4043e34..2029f4d38a1 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -409,6 +409,8 @@ struct Mesh *BKE_object_to_mesh(struct Depsgraph *depsgraph,
void BKE_object_to_mesh_clear(struct Object *object);
+void BKE_object_check_uuids_unique_and_report(const struct Object *object);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_ocean.h b/source/blender/blenkernel/BKE_ocean.h
index 6d488cc3142..1f8cdf27eb1 100644
--- a/source/blender/blenkernel/BKE_ocean.h
+++ b/source/blender/blenkernel/BKE_ocean.h
@@ -69,8 +69,10 @@ typedef struct OceanCache {
struct Ocean *BKE_ocean_add(void);
void BKE_ocean_free_data(struct Ocean *oc);
void BKE_ocean_free(struct Ocean *oc);
-bool BKE_ocean_ensure(struct OceanModifierData *omd);
-void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData const *omd);
+bool BKE_ocean_ensure(struct OceanModifierData *omd, const int resolution);
+void BKE_ocean_init_from_modifier(struct Ocean *ocean,
+ struct OceanModifierData const *omd,
+ const int resolution);
void BKE_ocean_init(struct Ocean *o,
int M,
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index e2381bf68ac..b2794e9d9d6 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -41,6 +41,7 @@ struct EdgeSet;
struct GHash;
struct GridPaintMask;
struct ImagePool;
+struct ListBase;
struct MLoop;
struct MLoopTri;
struct MVert;
@@ -259,10 +260,20 @@ typedef struct SculptPoseIKChain {
/* Cloth Brush */
typedef struct SculptClothLengthConstraint {
- int v1;
- int v2;
+ /* Elements that are affected by the constraint. */
+ /* Element a should always be a mesh vertex with the index stored in elem_index_a as it is always
+ * deformed. Element b could be another vertex of the same mesh or any other position (arbitrary
+ * point, position for a previous state). In that case, elem_index_a and elem_index_b should be
+ * the same to avoid affecting two different vertices when solving the constraints.
+ * *elem_position points to the position which is owned by the element. */
+ int elem_index_a;
+ float *elem_position_a;
+
+ int elem_index_b;
+ float *elem_position_b;
float length;
+ float strength;
} SculptClothLengthConstraint;
typedef struct SculptClothSimulation {
@@ -272,6 +283,11 @@ typedef struct SculptClothSimulation {
int capacity_length_constraints;
float *length_constraint_tweak;
+ /* Position anchors for deformation brushes. These positions are modified by the brush and the
+ * final positions of the simulated vertices are updated with constraints that use these points
+ * as targets. */
+ float (*deformation_pos)[3];
+
float mass;
float damping;
@@ -279,7 +295,9 @@ typedef struct SculptClothSimulation {
float (*pos)[3];
float (*init_pos)[3];
float (*prev_pos)[3];
+ float (*last_iteration_pos)[3];
+ struct ListBase *collider_list;
} SculptClothSimulation;
typedef struct SculptPersistentBase {
@@ -296,6 +314,81 @@ typedef struct SculptVertexInfo {
BLI_bitmap *boundary;
} SculptVertexInfo;
+typedef struct SculptBoundaryEditInfo {
+ /* Vertex index from where the topology propagation reached this vertex. */
+ int original_vertex;
+
+ /* How many steps were needed to reach this vertex from the boundary. */
+ int num_propagation_steps;
+
+ /* Stregth that is used to deform this vertex. */
+ float strength_factor;
+} SculptBoundaryEditInfo;
+
+/* Edge for drawing the boundary preview in the cursor. */
+typedef struct SculptBoundaryPreviewEdge {
+ int v1;
+ int v2;
+} SculptBoundaryPreviewEdge;
+
+typedef struct SculptBoundary {
+ /* Vertex indices of the active boundary. */
+ int *vertices;
+ int vertices_capacity;
+ int num_vertices;
+
+ /* Distance from a vertex in the boundary to initial vertex indexed by vertex index, taking into
+ * account the length of all edges between them. Any vertex that is not in the boundary will have
+ * a distance of 0. */
+ float *distance;
+
+ /* Data for drawing the preview. */
+ SculptBoundaryPreviewEdge *edges;
+ int edges_capacity;
+ int num_edges;
+
+ /* True if the boundary loops into itself. */
+ bool forms_loop;
+
+ /* Initial vertex in the boundary which is closest to the current sculpt active vertex. */
+ int initial_vertex;
+
+ /* Vertex that at max_propagation_steps from the boundary and closest to the original active
+ * vertex that was used to initialize the boundary. This is used as a reference to check how much
+ * the deformation will go into the mesh and to calculate the strength of the brushes. */
+ int pivot_vertex;
+
+ /* Stores the initial positions of the pivot and boundary initial vertex as they may be deformed
+ * during the brush action. This allows to use them as a reference positions and vectors for some
+ * brush effects. */
+ float initial_vertex_position[3];
+ float initial_pivot_position[3];
+
+ /* Maximum number of topology steps that were calculated from the boundary. */
+ int max_propagation_steps;
+
+ /* Indexed by vertex index, contains the topology information needed for boundary deformations.
+ */
+ struct SculptBoundaryEditInfo *edit_info;
+
+ /* Bend Deform type. */
+ struct {
+ float (*pivot_rotation_axis)[3];
+ float (*pivot_positions)[3];
+ } bend;
+
+ /* Slide Deform type. */
+ struct {
+ float (*directions)[3];
+ } slide;
+
+ /* Twist Deform type. */
+ struct {
+ float rotation_axis[3];
+ float pivot_position[3];
+ } twist;
+} SculptBoundary;
+
typedef struct SculptFakeNeighbors {
bool use_fake_neighbors;
@@ -317,6 +410,9 @@ typedef struct SculptSession {
int level;
} multires;
+ /* Depsgraph for the Cloth Brush solver to get the colliders. */
+ struct Depsgraph *depsgraph;
+
/* These are always assigned to base mesh data when using PBVH_FACES and PBVH_GRIDS. */
struct MVert *mvert;
struct MPoly *mpoly;
@@ -394,6 +490,9 @@ typedef struct SculptSession {
float pose_origin[3];
SculptPoseIKChain *pose_ik_chain_preview;
+ /* Boundary Brush Preview */
+ SculptBoundary *boundary_preview;
+
/* Mesh State Persistence */
/* This is freed with the PBVH, so it is always in sync with the mesh. */
SculptPersistentBase *persistent_base;
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 1e7a4ae75fb..7d317538f44 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -579,7 +579,7 @@ void psys_particle_on_dm(struct Mesh *mesh_final,
/* particle_system.c */
void distribute_particles(struct ParticleSimulationData *sim, int from);
-void initialize_particle(struct ParticleSimulationData *sim, struct ParticleData *pa);
+void init_particle(struct ParticleSimulationData *sim, struct ParticleData *pa);
void psys_calc_dmcache(struct Object *ob,
struct Mesh *mesh_final,
struct Mesh *mesh_original,
diff --git a/source/blender/blenkernel/BKE_persistent_data_handle.hh b/source/blender/blenkernel/BKE_persistent_data_handle.hh
index c8e02062f0b..42a853886d7 100644
--- a/source/blender/blenkernel/BKE_persistent_data_handle.hh
+++ b/source/blender/blenkernel/BKE_persistent_data_handle.hh
@@ -68,7 +68,7 @@ class PersistentDataHandle {
uint64_t hash() const
{
- return (uint64_t)handle_;
+ return static_cast<uint64_t>(handle_);
}
};
@@ -84,45 +84,45 @@ class PersistentObjectHandle : public PersistentIDHandle {
class PersistentDataHandleMap {
private:
- Map<int32_t, const ID *> id_by_handle_;
- Map<const ID *, int32_t> handle_by_id_;
+ Map<int32_t, ID *> id_by_handle_;
+ Map<ID *, int32_t> handle_by_id_;
public:
- void add(int32_t handle, const ID &id)
+ void add(int32_t handle, ID &id)
{
BLI_assert(handle >= 0);
handle_by_id_.add(&id, handle);
id_by_handle_.add(handle, &id);
}
- PersistentIDHandle lookup(const ID *id) const
+ PersistentIDHandle lookup(ID *id) const
{
const int handle = handle_by_id_.lookup_default(id, -1);
return PersistentIDHandle(handle);
}
- PersistentObjectHandle lookup(const Object *object) const
+ PersistentObjectHandle lookup(Object *object) const
{
- const int handle = handle_by_id_.lookup_default((const ID *)object, -1);
+ const int handle = handle_by_id_.lookup_default((ID *)object, -1);
return PersistentObjectHandle(handle);
}
- const ID *lookup(const PersistentIDHandle &handle) const
+ ID *lookup(const PersistentIDHandle &handle) const
{
- const ID *id = id_by_handle_.lookup_default(handle.handle_, nullptr);
+ ID *id = id_by_handle_.lookup_default(handle.handle_, nullptr);
return id;
}
- const Object *lookup(const PersistentObjectHandle &handle) const
+ Object *lookup(const PersistentObjectHandle &handle) const
{
- const ID *id = this->lookup((const PersistentIDHandle &)handle);
+ ID *id = this->lookup((const PersistentIDHandle &)handle);
if (id == nullptr) {
return nullptr;
}
if (GS(id->name) != ID_OB) {
return nullptr;
}
- return (const Object *)id;
+ return (Object *)id;
}
};
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 735d6dc6e89..1090deae93f 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -72,7 +72,7 @@ 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 *area, const struct Scene *scene);
+ struct SpaceLink *(*create)(const struct ScrArea *area, const struct Scene *scene);
/* not free spacelink itself */
void (*free)(struct SpaceLink *sl);
@@ -183,6 +183,16 @@ typedef struct ARegionType {
/* return context data */
int (*context)(const struct bContext *C, const char *member, struct bContextDataResult *result);
+ /* Is called whenever the current visible View2D's region changes.
+ *
+ * Used from user code such as view navigation/zoom operators to inform region about changes.
+ * The goal is to support zoom-to-fit features which gets disabled when manual navigation is
+ * performed.
+ *
+ * This callback is not called on indirect changes of the current viewport (which could happen
+ * when the `v2d->tot is changed and `cur` is adopted accordingly). */
+ void (*on_view2d_changed)(const struct bContext *C, struct ARegion *region);
+
/* custom drawing callbacks */
ListBase drawcalls;
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 03f14be8772..b6d901c8ef2 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -627,6 +627,10 @@ void BKE_sequencer_color_balance_apply(struct StripColorBalance *cb,
void BKE_sequencer_all_free_anim_ibufs(struct Scene *scene, int cfra);
bool BKE_sequencer_check_scene_recursion(struct Scene *scene, struct ReportList *reports);
bool BKE_sequencer_render_loop_check(struct Sequence *seq_main, struct Sequence *seq);
+void BKE_sequencer_flag_for_removal(struct Scene *scene,
+ struct ListBase *seqbase,
+ struct Sequence *seq);
+void BKE_sequencer_remove_flagged_sequences(struct Scene *scene, struct ListBase *seqbase);
/* A debug and development function which checks whether sequences have unique UUIDs.
* Errors will be reported to the console. */
diff --git a/source/blender/blenkernel/BKE_simulation.h b/source/blender/blenkernel/BKE_simulation.h
index 98d1cf1e9b5..2c436f2bff8 100644
--- a/source/blender/blenkernel/BKE_simulation.h
+++ b/source/blender/blenkernel/BKE_simulation.h
@@ -31,6 +31,7 @@ void *BKE_simulation_add(struct Main *bmain, const char *name);
void BKE_simulation_data_update(struct Depsgraph *depsgraph,
struct Scene *scene,
struct Simulation *simulation);
+void BKE_simulation_update_dependencies(struct Simulation *simulation, struct Main *bmain);
SimulationState *BKE_simulation_state_add(Simulation *simulation,
const char *type,
diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h
index 2277eb27ef1..7833ba9c046 100644
--- a/source/blender/blenkernel/BKE_subdiv_ccg.h
+++ b/source/blender/blenkernel/BKE_subdiv_ccg.h
@@ -311,6 +311,9 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg,
SubdivCCGNeighbors *r_neighbors);
int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index);
+void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float r_point[3]);
typedef enum SubdivCCGAdjacencyType {
SUBDIV_CCG_ADJACENT_NONE,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d702da55ea8..6f32eb8a90f 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -36,8 +36,8 @@ set(INC
../makesrna
../modifiers
../nodes
- ../simulation
../shader_fx
+ ../simulation
../render/extern/include
../../../intern/ghost
../../../intern/glew-mx
@@ -100,6 +100,7 @@ set(SRC
intern/context.c
intern/crazyspace.c
intern/curve.c
+ intern/curve_bevel.c
intern/curve_decimate.c
intern/curve_deform.c
intern/curveprofile.c
@@ -134,6 +135,7 @@ set(SRC
intern/idtype.c
intern/image.c
intern/image_gen.c
+ intern/image_gpu.c
intern/image_save.c
intern/ipo.c
intern/kelvinlet.c
@@ -363,8 +365,8 @@ set(SRC
BKE_packedFile.h
BKE_paint.h
BKE_particle.h
- BKE_persistent_data_handle.hh
BKE_pbvh.h
+ BKE_persistent_data_handle.hh
BKE_pointcache.h
BKE_pointcloud.h
BKE_report.h
@@ -438,9 +440,9 @@ set(LIB
bf_intern_opensubdiv # Uses stub when disabled.
bf_modifiers
bf_nodes
- bf_simulation
bf_rna
bf_shader_fx
+ bf_simulation
)
if(WITH_BINRELOC)
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index e035d5cbb68..c572b1dacf0 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -32,8 +32,6 @@
#include "CCGSubSurf.h"
#include "CCGSubSurf_intern.h"
-#include "GPU_glew.h"
-
/***/
int BKE_ccg_gridsize(int level)
@@ -715,8 +713,8 @@ CCGError ccgSubSurf_syncFace(
if (f) {
if (f->numVerts != numVerts ||
- memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) ||
- memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts)) {
+ memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) != 0 ||
+ memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts) != 0) {
topologyChanged = 1;
}
}
@@ -786,8 +784,8 @@ CCGError ccgSubSurf_syncFace(
if (f) {
if (f->numVerts != numVerts ||
- memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) ||
- memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts)) {
+ memcmp(FACE_getVerts(f), ss->tempVerts, sizeof(*ss->tempVerts) * numVerts) != 0 ||
+ memcmp(FACE_getEdges(f), ss->tempEdges, sizeof(*ss->tempEdges) * numVerts) != 0) {
topologyChanged = 1;
}
}
@@ -1545,7 +1543,7 @@ void CCG_key(CCGKey *key, const CCGSubSurf *ss, int level)
/* if normals are present, always the last three floats of an
* element */
if (key->has_normals) {
- key->normal_offset = key->elem_size - sizeof(float) * 3;
+ key->normal_offset = key->elem_size - sizeof(float[3]);
}
else {
key->normal_offset = -1;
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 8031e3dadf8..0dc85dfaa18 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -80,11 +80,9 @@
//#define USE_MODIFIER_VALIDATE
#ifdef USE_MODIFIER_VALIDATE
-# define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
# define ASSERT_IS_VALID_MESH(mesh) \
(BLI_assert((mesh == NULL) || (BKE_mesh_is_valid(mesh) == true)))
#else
-# define ASSERT_IS_VALID_DM(dm)
# define ASSERT_IS_VALID_MESH(mesh)
#endif
@@ -671,7 +669,7 @@ static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3]
/* these may not really be the orco's, but it's only for preview.
* could be solver better once, but isn't simple */
- orco = MEM_malloc_arrayN(em->bm->totvert, sizeof(float) * 3, "BMEditMesh Orco");
+ orco = MEM_malloc_arrayN(em->bm->totvert, sizeof(float[3]), "BMEditMesh Orco");
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
copy_v3_v3(orco[i], eve->co);
@@ -774,7 +772,7 @@ static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh *mesh, Mesh *mesh_orc
layerorco = CustomData_get_layer(&mesh->vdata, layer);
}
- memcpy(layerorco, orco, sizeof(float) * 3 * totvert);
+ memcpy(layerorco, orco, sizeof(float[3]) * totvert);
if (free) {
MEM_freeN(orco);
}
@@ -1373,7 +1371,7 @@ float (*editbmesh_vert_coords_alloc(BMEditMesh *em, int *r_vert_len))[3]
*r_vert_len = em->bm->totvert;
- cos = MEM_malloc_arrayN(em->bm->totvert, 3 * sizeof(float), "vertexcos");
+ cos = MEM_malloc_arrayN(em->bm->totvert, sizeof(float[3]), "vertexcos");
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
copy_v3_v3(cos[i], eve->co);
@@ -1812,6 +1810,12 @@ static void mesh_build_data(struct Depsgraph *depsgraph,
BKE_object_boundbox_calc_from_mesh(ob, mesh_eval);
+ /* Make sure that drivers can target shapekey properties.
+ * Note that this causes a potential inconsistency, as the shapekey may have a
+ * different topology than the evaluated mesh. */
+ BLI_assert(mesh->key == NULL || DEG_is_evaluated_id(&mesh->key->id));
+ mesh_eval->key = mesh->key;
+
if ((ob->mode & OB_MODE_ALL_SCULPT) && ob->sculpt) {
if (DEG_is_active(depsgraph)) {
BKE_sculpt_update_object_after_eval(depsgraph, ob);
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index ea5a4bd99d1..5b5e32f1d81 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -1150,7 +1150,7 @@ static int nlaevalchan_validate_index(NlaEvalChannel *nec, int index)
return 0;
}
-/* Initialise default values for NlaEvalChannel from the property data. */
+/* Initialize default values for NlaEvalChannel from the property data. */
static void nlaevalchan_get_default_values(NlaEvalChannel *nec, float *r_values)
{
PointerRNA *ptr = &nec->key.ptr;
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 985be4ac99f..631ce4edd20 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2582,7 +2582,7 @@ void BKE_pose_where_is(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
}
/* 2a. construct the IK tree (standard IK) */
- BIK_initialize_tree(depsgraph, scene, ob, ctime);
+ BIK_init_tree(depsgraph, scene, ob, ctime);
/* 2b. construct the Spline IK trees
* - this is not integrated as an IK plugin, since it should be able
diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c
index d66991aed70..97c717572bc 100644
--- a/source/blender/blenkernel/intern/armature_update.c
+++ b/source/blender/blenkernel/intern/armature_update.c
@@ -658,7 +658,7 @@ void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph, Scene *scene, Object *ob
return;
}
/* construct the IK tree (standard IK) */
- BIK_initialize_tree(depsgraph, scene, object, ctime);
+ BIK_init_tree(depsgraph, scene, object, ctime);
/* construct the Spline IK trees
* - this is not integrated as an IK plugin, since it should be able
* to function in conjunction with standard IK. */
diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c
index a0da1b1677d..a7324ffe738 100644
--- a/source/blender/blenkernel/intern/boids.c
+++ b/source/blender/blenkernel/intern/boids.c
@@ -873,7 +873,7 @@ static Object *boid_find_ground(BoidBrainData *bbd,
return bpa->ground;
}
- float zvec[3] = {0.0f, 0.0f, 2000.0f};
+ const float zvec[3] = {0.0f, 0.0f, 2000.0f};
ParticleCollision col;
ColliderCache *coll;
BVHTreeRayHit hit;
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 7223187831e..8cd30c2241f 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -557,7 +557,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
/* Curve. */
custom_curve = brush->gpencil_settings->curve_sensitivity;
BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(custom_curve);
+ BKE_curvemapping_init(custom_curve);
brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_INK);
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INK;
@@ -594,7 +594,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
/* Curve. */
custom_curve = brush->gpencil_settings->curve_sensitivity;
BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(custom_curve);
+ BKE_curvemapping_init(custom_curve);
brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_INKNOISE);
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INKNOISE;
@@ -631,7 +631,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
/* Curve. */
custom_curve = brush->gpencil_settings->curve_sensitivity;
BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(custom_curve);
+ BKE_curvemapping_init(custom_curve);
brush_gpencil_curvemap_reset(custom_curve->cm, 4, GPCURVE_PRESET_MARKER);
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_MARKER;
@@ -667,12 +667,12 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
/* Curve. */
custom_curve = brush->gpencil_settings->curve_sensitivity;
BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(custom_curve);
+ BKE_curvemapping_init(custom_curve);
brush_gpencil_curvemap_reset(custom_curve->cm, 3, GPCURVE_PRESET_CHISEL_SENSIVITY);
custom_curve = brush->gpencil_settings->curve_strength;
BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(custom_curve);
+ BKE_curvemapping_init(custom_curve);
brush_gpencil_curvemap_reset(custom_curve->cm, 4, GPCURVE_PRESET_CHISEL_STRENGTH);
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_CHISEL;
@@ -1481,6 +1481,11 @@ void BKE_brush_sculpt_reset(Brush *br)
br->curve_preset = BRUSH_CURVE_POW4;
br->spacing = 5;
break;
+ case SCULPT_TOOL_DISPLACEMENT_ERASER:
+ br->curve_preset = BRUSH_CURVE_SMOOTHER;
+ br->spacing = 10;
+ br->alpha = 1.0f;
+ break;
case SCULPT_TOOL_SLIDE_RELAX:
br->spacing = 10;
br->alpha = 1.0f;
@@ -1566,6 +1571,12 @@ void BKE_brush_sculpt_reset(Brush *br)
br->flag &= ~BRUSH_SPACE;
br->flag &= ~BRUSH_SPACE_ATTEN;
break;
+ case SCULPT_TOOL_BOUNDARY:
+ br->flag &= ~BRUSH_ALPHA_PRESSURE;
+ br->flag &= ~BRUSH_SPACE;
+ br->flag &= ~BRUSH_SPACE_ATTEN;
+ br->curve_preset = BRUSH_CURVE_CONSTANT;
+ break;
case SCULPT_TOOL_DRAW_FACE_SETS:
br->alpha = 0.5f;
br->flag &= ~BRUSH_ALPHA_PRESSURE;
@@ -1660,6 +1671,7 @@ void BKE_brush_sculpt_reset(Brush *br)
case SCULPT_TOOL_ROTATE:
case SCULPT_TOOL_ELASTIC_DEFORM:
case SCULPT_TOOL_POSE:
+ case SCULPT_TOOL_BOUNDARY:
case SCULPT_TOOL_SLIDE_RELAX:
br->add_col[0] = 1.0f;
br->add_col[1] = 0.95f;
@@ -1673,6 +1685,7 @@ void BKE_brush_sculpt_reset(Brush *br)
case SCULPT_TOOL_PAINT:
case SCULPT_TOOL_MASK:
case SCULPT_TOOL_DRAW_FACE_SETS:
+ case SCULPT_TOOL_DISPLACEMENT_ERASER:
br->add_col[0] = 0.75f;
br->add_col[1] = 0.75f;
br->add_col[2] = 0.75f;
@@ -1740,7 +1753,7 @@ float BKE_brush_sample_tex_3d(const Scene *scene,
}
else if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
float rotation = -mtex->rot;
- float point_2d[2] = {point[0], point[1]};
+ const float point_2d[2] = {point[0], point[1]};
float x, y;
float co[3];
@@ -1770,7 +1783,7 @@ float BKE_brush_sample_tex_3d(const Scene *scene,
}
else {
float rotation = -mtex->rot;
- float point_2d[2] = {point[0], point[1]};
+ const float point_2d[2] = {point[0], point[1]};
float x = 0.0f, y = 0.0f; /* Quite warnings */
float invradius = 1.0f; /* Quite warnings */
float co[3];
@@ -1853,7 +1866,7 @@ float BKE_brush_sample_masktex(
}
if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
float rotation = -mtex->rot;
- float point_2d[2] = {point[0], point[1]};
+ const float point_2d[2] = {point[0], point[1]};
float x, y;
float co[3];
@@ -1883,7 +1896,7 @@ float BKE_brush_sample_masktex(
}
else {
float rotation = -mtex->rot;
- float point_2d[2] = {point[0], point[1]};
+ const float point_2d[2] = {point[0], point[1]};
float x = 0.0f, y = 0.0f; /* Quite warnings */
float invradius = 1.0f; /* Quite warnings */
float co[3];
@@ -2274,7 +2287,7 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool
int half = side / 2;
int i, j;
- BKE_curvemapping_initialize(br->curve);
+ BKE_curvemapping_init(br->curve);
texcache = BKE_brush_gen_texture_cache(br, half, secondary);
im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
im->x = im->y = side;
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index da9dab36044..9ad6ae84c5c 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -61,6 +61,8 @@ static void cache_file_init_data(ID *id)
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cache_file, id));
cache_file->scale = 1.0f;
+ cache_file->velocity_unit = CACHEFILE_VELOCITY_UNIT_SECOND;
+ BLI_strncpy(cache_file->velocity_name, ".velocities", sizeof(cache_file->velocity_name));
}
static void cache_file_copy_data(Main *UNUSED(bmain),
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 7c0e4064cdb..d8b4150b2b1 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -186,9 +186,8 @@ int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
if (sizex >= sizey) {
return CAMERA_SENSOR_FIT_HOR;
}
- else {
- return CAMERA_SENSOR_FIT_VERT;
- }
+
+ return CAMERA_SENSOR_FIT_VERT;
}
return sensor_fit;
@@ -636,64 +635,63 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params,
return true;
}
- else {
- float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3];
- float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3];
- float plane_isect_pt_1[3], plane_isect_pt_2[3];
+ float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3];
+ float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3];
- /* apply the dist-from-plane's to the transformed plane points */
- for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
- float co[3];
- mul_v3_v3fl(co, data->normal_tx[i], sqrtf_signed(data->dist_vals_sq[i]));
- plane_from_point_normal_v3(plane_tx[i], co, data->normal_tx[i]);
- }
+ float plane_isect_pt_1[3], plane_isect_pt_2[3];
- if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) ||
- (!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no))) {
- return false;
- }
+ /* apply the dist-from-plane's to the transformed plane points */
+ for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
+ float co[3];
+ mul_v3_v3fl(co, data->normal_tx[i], sqrtf_signed(data->dist_vals_sq[i]));
+ plane_from_point_normal_v3(plane_tx[i], co, data->normal_tx[i]);
+ }
- add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no);
- add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no);
+ if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) ||
+ (!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no))) {
+ return false;
+ }
- if (isect_line_line_v3(plane_isect_1,
- plane_isect_1_other,
- plane_isect_2,
- plane_isect_2_other,
- plane_isect_pt_1,
- plane_isect_pt_2) != 0) {
- float cam_plane_no[3];
- float plane_isect_delta[3];
- float plane_isect_delta_len;
+ add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no);
+ add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no);
- float shift_fac = BKE_camera_sensor_size(
- params->sensor_fit, params->sensor_x, params->sensor_y) /
- params->lens;
+ if (isect_line_line_v3(plane_isect_1,
+ plane_isect_1_other,
+ plane_isect_2,
+ plane_isect_2_other,
+ plane_isect_pt_1,
+ plane_isect_pt_2) != 0) {
+ float cam_plane_no[3];
+ float plane_isect_delta[3];
+ float plane_isect_delta_len;
- /* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
- negate_v3_v3(cam_plane_no, data->camera_rotmat[2]);
+ float shift_fac = BKE_camera_sensor_size(
+ params->sensor_fit, params->sensor_x, params->sensor_y) /
+ params->lens;
- sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1);
- plane_isect_delta_len = len_v3(plane_isect_delta);
+ /* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
+ negate_v3_v3(cam_plane_no, data->camera_rotmat[2]);
- if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) {
- copy_v3_v3(r_co, plane_isect_pt_1);
+ sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1);
+ plane_isect_delta_len = len_v3(plane_isect_delta);
- /* offset shift */
- normalize_v3(plane_isect_1_no);
- madd_v3_v3fl(r_co, plane_isect_1_no, params->shifty * plane_isect_delta_len * shift_fac);
- }
- else {
- copy_v3_v3(r_co, plane_isect_pt_2);
+ if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) {
+ copy_v3_v3(r_co, plane_isect_pt_1);
- /* offset shift */
- normalize_v3(plane_isect_2_no);
- madd_v3_v3fl(r_co, plane_isect_2_no, params->shiftx * plane_isect_delta_len * shift_fac);
- }
+ /* offset shift */
+ normalize_v3(plane_isect_1_no);
+ madd_v3_v3fl(r_co, plane_isect_1_no, params->shifty * plane_isect_delta_len * shift_fac);
+ }
+ else {
+ copy_v3_v3(r_co, plane_isect_pt_2);
- return true;
+ /* offset shift */
+ normalize_v3(plane_isect_2_no);
+ madd_v3_v3fl(r_co, plane_isect_2_no, params->shiftx * plane_isect_delta_len * shift_fac);
}
+
+ return true;
}
return false;
@@ -775,11 +773,10 @@ static void camera_stereo3d_model_matrix(const Object *camera,
camera_model_matrix(camera, r_modelmat);
return;
}
- else {
- float size[3];
- mat4_to_size(size, camera->obmat);
- size_to_mat4(sizemat, size);
- }
+
+ float size[3];
+ mat4_to_size(size, camera->obmat);
+ size_to_mat4(sizemat, size);
if (pivot == CAM_S3D_PIVOT_CENTER) {
fac = 0.5f;
@@ -931,9 +928,8 @@ bool BKE_camera_multiview_spherical_stereo(const RenderData *rd, const Object *c
if (camera->type != OB_CAMERA) {
return false;
}
- else {
- cam = camera->data;
- }
+
+ cam = camera->data;
if ((rd->views_format == SCE_VIEWS_FORMAT_STEREO_3D) && ELEM(cam->type, CAM_PANO, CAM_PERSP) &&
((cam->stereo.flag & CAM_S3D_SPHERICAL) != 0)) {
@@ -984,13 +980,12 @@ Object *BKE_camera_multiview_render(const Scene *scene, Object *camera, const ch
if (!is_multiview) {
return camera;
}
- else if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
+ if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
return camera;
}
- else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
- const char *suffix = BKE_scene_multiview_view_suffix_get(&scene->r, viewname);
- return camera_multiview_advanced(scene, camera, suffix);
- }
+ /* SCE_VIEWS_FORMAT_MULTIVIEW */
+ const char *suffix = BKE_scene_multiview_view_suffix_get(&scene->r, viewname);
+ return camera_multiview_advanced(scene, camera, suffix);
}
static float camera_stereo3d_shift_x(const Object *camera, const char *viewname)
@@ -1044,12 +1039,11 @@ float BKE_camera_multiview_shift_x(const RenderData *rd,
if (!is_multiview) {
return data->shiftx;
}
- else if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
+ if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
return data->shiftx;
}
- else { /* SCE_VIEWS_SETUP_BASIC */
- return camera_stereo3d_shift_x(camera, viewname);
- }
+ /* SCE_VIEWS_SETUP_BASIC */
+ return camera_stereo3d_shift_x(camera, viewname);
}
void BKE_camera_multiview_params(const RenderData *rd,
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 467bd68c631..24b4b85d0d4 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -825,7 +825,7 @@ static int cloth_from_object(
MVert *mvert = NULL;
ClothVertex *verts = NULL;
float(*shapekey_rest)[3] = NULL;
- float tnull[3] = {0, 0, 0};
+ const float tnull[3] = {0, 0, 0};
// If we have a clothObject, free it.
if (clmd->clothObject != NULL) {
@@ -1355,7 +1355,7 @@ BLI_INLINE void cross_identity_v3(float r[3][3], const float v[3])
r[2][1] = -v[0];
}
-BLI_INLINE void madd_m3_m3fl(float r[3][3], float m[3][3], float f)
+BLI_INLINE void madd_m3_m3fl(float r[3][3], const float m[3][3], float f)
{
r[0][0] += m[0][0] * f;
r[0][1] += m[0][1] * f;
@@ -1611,7 +1611,6 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
if (use_internal_springs && numpolys > 0) {
BVHTreeFromMesh treedata = {NULL};
unsigned int tar_v_idx;
- BLI_bitmap *verts_used = NULL;
Mesh *tmp_mesh = NULL;
RNG *rng;
@@ -1622,7 +1621,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
BKE_mesh_calc_normals(tmp_mesh);
}
- verts_used = BLI_BITMAP_NEW(mvert_num * mvert_num, __func__);
+ EdgeSet *existing_vert_pairs = BLI_edgeset_new("cloth_sewing_edges_graph");
BKE_bvhtree_from_mesh_get(&treedata, tmp_mesh ? tmp_mesh : mesh, BVHTREE_FROM_LOOPTRI, 2);
rng = BLI_rng_new_srandom(0);
@@ -1635,12 +1634,12 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
clmd->sim_parms->internal_spring_max_diversion,
(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL),
&tar_v_idx)) {
- if (BLI_BITMAP_TEST_BOOL(verts_used, i * mvert_num + tar_v_idx)) {
+ if (BLI_edgeset_haskey(existing_vert_pairs, i, tar_v_idx)) {
+ /* We have already created a spring between these verts! */
continue;
}
- BLI_BITMAP_ENABLE(verts_used, i * mvert_num + tar_v_idx);
- BLI_BITMAP_ENABLE(verts_used, tar_v_idx * mvert_num + i);
+ BLI_edgeset_insert(existing_vert_pairs, i, tar_v_idx);
spring = (ClothSpring *)MEM_callocN(sizeof(ClothSpring), "cloth spring");
@@ -1666,7 +1665,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
}
else {
cloth_free_errorsprings(cloth, edgelist, spring_ref);
- MEM_freeN(verts_used);
+ BLI_edgeset_free(existing_vert_pairs);
free_bvhtree_from_mesh(&treedata);
if (tmp_mesh) {
BKE_mesh_free(tmp_mesh);
@@ -1675,7 +1674,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
}
}
}
- MEM_freeN(verts_used);
+ BLI_edgeset_free(existing_vert_pairs);
free_bvhtree_from_mesh(&treedata);
if (tmp_mesh) {
BKE_mesh_free(tmp_mesh);
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 5c618c8e9ce..0d65ee5faa3 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -540,9 +540,8 @@ const char *BKE_collection_ui_name_get(struct Collection *collection)
if (collection->flag & COLLECTION_IS_MASTER) {
return IFACE_("Scene Collection");
}
- else {
- return collection->id.name + 2;
- }
+
+ return collection->id.name + 2;
}
/** \} */
@@ -617,9 +616,8 @@ Base *BKE_collection_or_layer_objects(const ViewLayer *view_layer, Collection *c
if (collection) {
return BKE_collection_object_cache_get(collection).first;
}
- else {
- return FIRSTBASE(view_layer);
- }
+
+ return FIRSTBASE(view_layer);
}
/** \} */
@@ -671,14 +669,13 @@ static bool collection_object_cyclic_check_internal(Object *object, Collection *
if (dup_collection == collection) {
return true;
}
- else {
- FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (dup_collection, collection_object) {
- if (collection_object_cyclic_check_internal(collection_object, dup_collection)) {
- return true;
- }
+
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (dup_collection, collection_object) {
+ if (collection_object_cyclic_check_internal(collection_object, dup_collection)) {
+ return true;
}
- FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
/* un-flag the object, it's allowed to have the same collection multiple times in parallel */
dup_collection->id.tag |= LIB_TAG_DOIT;
@@ -725,9 +722,8 @@ static Collection *collection_next_find(Main *bmain, Scene *scene, Collection *c
if (scene && collection == scene->master_collection) {
return bmain->collections.first;
}
- else {
- return collection->id.next;
- }
+
+ return collection->id.next;
}
Collection *BKE_collection_object_find(Main *bmain,
@@ -1510,9 +1506,8 @@ bool BKE_collection_objects_select(ViewLayer *view_layer, Collection *collection
if (layer_collection != NULL) {
return BKE_layer_collection_objects_select(view_layer, layer_collection, deselect);
}
- else {
- return collection_objects_select(view_layer, collection, deselect);
- }
+
+ return collection_objects_select(view_layer, collection, deselect);
}
/** \} */
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index f358355912b..05c521e3b94 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -647,6 +647,31 @@ DO_INLINE void collision_interpolateOnTriangle(float to[3],
VECADDMUL(to, v3, w3);
}
+static void cloth_selfcollision_impulse_vert(const float clamp_sq,
+ const float impulse[3],
+ struct ClothVertex *vert)
+{
+ float impulse_len_sq = len_squared_v3(impulse);
+
+ if ((clamp_sq > 0.0f) && (impulse_len_sq > clamp_sq)) {
+ return;
+ }
+
+ if (fabsf(vert->impulse[0]) < fabsf(impulse[0])) {
+ vert->impulse[0] = impulse[0];
+ }
+
+ if (fabsf(vert->impulse[1]) < fabsf(impulse[1])) {
+ vert->impulse[1] = impulse[1];
+ }
+
+ if (fabsf(vert->impulse[2]) < fabsf(impulse[2])) {
+ vert->impulse[2] = impulse[2];
+ }
+
+ vert->impulse_count++;
+}
+
static int cloth_collision_response_static(ClothModifierData *clmd,
CollisionModifierData *collmd,
Object *collob,
@@ -655,18 +680,17 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
const float dt)
{
int result = 0;
- Cloth *cloth1;
- float w1, w2, w3, u1, u2, u3;
- float v1[3], v2[3], relativeVelocity[3];
- float magrelVel;
- float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree);
- const bool is_hair = (clmd->hairdata != NULL);
-
- cloth1 = clmd->clothObject;
+ Cloth *cloth = clmd->clothObject;
+ const float clamp_sq = square_f(clmd->coll_parms->self_clamp * dt);
+ const float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
+ const float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree);
+ const float min_distance = (clmd->coll_parms->epsilon + epsilon2) * (8.0f / 9.0f);
+ const bool is_hair = (clmd->hairdata != NULL);
for (int i = 0; i < collision_count; i++, collpair++) {
float i1[3], i2[3], i3[3];
-
+ float w1, w2, w3, u1, u2, u3;
+ float v1[3], v2[3], relativeVelocity[3];
zero_v3(i1);
zero_v3(i2);
zero_v3(i3);
@@ -679,25 +703,25 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
/* Compute barycentric coordinates and relative "velocity" for both collision points. */
if (is_hair) {
w2 = line_point_factor_v3(
- collpair->pa, cloth1->verts[collpair->ap1].tx, cloth1->verts[collpair->ap2].tx);
+ collpair->pa, cloth->verts[collpair->ap1].tx, cloth->verts[collpair->ap2].tx);
w1 = 1.0f - w2;
- interp_v3_v3v3(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, w2);
+ interp_v3_v3v3(v1, cloth->verts[collpair->ap1].tv, cloth->verts[collpair->ap2].tv, w2);
}
else {
collision_compute_barycentric(collpair->pa,
- cloth1->verts[collpair->ap1].tx,
- cloth1->verts[collpair->ap2].tx,
- cloth1->verts[collpair->ap3].tx,
+ cloth->verts[collpair->ap1].tx,
+ cloth->verts[collpair->ap2].tx,
+ cloth->verts[collpair->ap3].tx,
&w1,
&w2,
&w3);
collision_interpolateOnTriangle(v1,
- cloth1->verts[collpair->ap1].tv,
- cloth1->verts[collpair->ap2].tv,
- cloth1->verts[collpair->ap3].tv,
+ cloth->verts[collpair->ap1].tv,
+ cloth->verts[collpair->ap2].tv,
+ cloth->verts[collpair->ap3].tv,
w1,
w2,
w3);
@@ -723,16 +747,16 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
/* Calculate the normal component of the relative velocity
* (actually only the magnitude - the direction is stored in 'normal'). */
- magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float d = min_distance - collpair->distance;
/* If magrelVel < 0 the edges are approaching each other. */
if (magrelVel > 0.0f) {
/* Calculate Impulse magnitude to stop all motion in normal direction. */
- float magtangent = 0, repulse = 0, d = 0;
+ float magtangent = 0, repulse = 0;
double impulse = 0.0;
float vrel_t_pre[3];
float temp[3];
- float time_multiplier;
/* Calculate tangential velocity. */
copy_v3_v3(temp, collpair->normal);
@@ -750,32 +774,23 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
impulse = magtangent / 1.5;
- VECADDMUL(i1, vrel_t_pre, w1 * impulse);
- VECADDMUL(i2, vrel_t_pre, w2 * impulse);
+ VECADDMUL(i1, vrel_t_pre, (double)w1 * impulse);
+ VECADDMUL(i2, vrel_t_pre, (double)w2 * impulse);
if (!is_hair) {
- VECADDMUL(i3, vrel_t_pre, w3 * impulse);
+ VECADDMUL(i3, vrel_t_pre, (double)w3 * impulse);
}
}
/* Apply velocity stopping impulse. */
impulse = magrelVel / 1.5f;
- VECADDMUL(i1, collpair->normal, w1 * impulse);
- cloth1->verts[collpair->ap1].impulse_count++;
-
- VECADDMUL(i2, collpair->normal, w2 * impulse);
- cloth1->verts[collpair->ap2].impulse_count++;
-
+ VECADDMUL(i1, collpair->normal, (double)w1 * impulse);
+ VECADDMUL(i2, collpair->normal, (double)w2 * impulse);
if (!is_hair) {
- VECADDMUL(i3, collpair->normal, w3 * impulse);
- cloth1->verts[collpair->ap3].impulse_count++;
+ VECADDMUL(i3, collpair->normal, (double)w3 * impulse);
}
- time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
-
- d = clmd->coll_parms->epsilon * 8.0f / 9.0f + epsilon2 * 8.0f / 9.0f - collpair->distance;
-
if ((magrelVel < 0.1f * d * time_multiplier) && (d > ALMOST_ZERO)) {
repulse = MIN2(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
@@ -790,7 +805,6 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
VECADDMUL(i1, collpair->normal, impulse);
VECADDMUL(i2, collpair->normal, impulse);
-
if (!is_hair) {
VECADDMUL(i3, collpair->normal, impulse);
}
@@ -798,60 +812,26 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
result = 1;
}
- else {
- float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
- float d;
-
- d = clmd->coll_parms->epsilon * 8.0f / 9.0f + epsilon2 * 8.0f / 9.0f - collpair->distance;
-
- if (d > ALMOST_ZERO) {
- /* Stay on the safe side and clamp repulse. */
- float repulse = d / time_multiplier;
- float impulse = repulse / 4.5f;
-
- VECADDMUL(i1, collpair->normal, w1 * impulse);
- VECADDMUL(i2, collpair->normal, w2 * impulse);
+ else if (d > ALMOST_ZERO) {
+ /* Stay on the safe side and clamp repulse. */
+ float repulse = d / time_multiplier;
+ float impulse = repulse / 4.5f;
- if (!is_hair) {
- VECADDMUL(i3, collpair->normal, w3 * impulse);
- }
-
- cloth1->verts[collpair->ap1].impulse_count++;
- cloth1->verts[collpair->ap2].impulse_count++;
-
- if (!is_hair) {
- cloth1->verts[collpair->ap3].impulse_count++;
- }
+ VECADDMUL(i1, collpair->normal, w1 * impulse);
+ VECADDMUL(i2, collpair->normal, w2 * impulse);
- result = 1;
+ if (!is_hair) {
+ VECADDMUL(i3, collpair->normal, w3 * impulse);
}
+
+ result = 1;
}
if (result) {
- float clamp = clmd->coll_parms->clamp * dt;
-
- if ((clamp > 0.0f) &&
- ((len_v3(i1) > clamp) || (len_v3(i2) > clamp) || (len_v3(i3) > clamp))) {
- return 0;
- }
-
- for (int j = 0; j < 3; j++) {
- if (cloth1->verts[collpair->ap1].impulse_count > 0 &&
- fabsf(cloth1->verts[collpair->ap1].impulse[j]) < fabsf(i1[j])) {
- cloth1->verts[collpair->ap1].impulse[j] = i1[j];
- }
-
- if (cloth1->verts[collpair->ap2].impulse_count > 0 &&
- fabsf(cloth1->verts[collpair->ap2].impulse[j]) < fabsf(i2[j])) {
- cloth1->verts[collpair->ap2].impulse[j] = i2[j];
- }
-
- if (!is_hair) {
- if (cloth1->verts[collpair->ap3].impulse_count > 0 &&
- fabsf(cloth1->verts[collpair->ap3].impulse[j]) < fabsf(i3[j])) {
- cloth1->verts[collpair->ap3].impulse[j] = i3[j];
- }
- }
+ cloth_selfcollision_impulse_vert(clamp_sq, i1, &cloth->verts[collpair->ap1]);
+ cloth_selfcollision_impulse_vert(clamp_sq, i2, &cloth->verts[collpair->ap2]);
+ if (!is_hair) {
+ cloth_selfcollision_impulse_vert(clamp_sq, i3, &cloth->verts[collpair->ap3]);
}
}
}
@@ -859,47 +839,22 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
return result;
}
-static void cloth_selfcollision_impulse_vert(const float clamp_sq,
- const float impulse[3],
- struct ClothVertex *vert)
-{
- float impulse_len_sq = len_squared_v3(impulse);
-
- if ((clamp_sq > 0.0f) && (impulse_len_sq > clamp_sq)) {
- return;
- }
-
- if (fabsf(vert->impulse[0]) < fabsf(impulse[0])) {
- vert->impulse[0] = impulse[0];
- }
-
- if (fabsf(vert->impulse[1]) < fabsf(impulse[1])) {
- vert->impulse[1] = impulse[1];
- }
-
- if (fabsf(vert->impulse[2]) < fabsf(impulse[2])) {
- vert->impulse[2] = impulse[2];
- }
-
- vert->impulse_count++;
-}
-
static int cloth_selfcollision_response_static(ClothModifierData *clmd,
CollPair *collpair,
uint collision_count,
const float dt)
{
int result = 0;
- Cloth *cloth1;
- float w1, w2, w3, u1, u2, u3;
- float v1[3], v2[3], relativeVelocity[3];
- float magrelVel;
-
- cloth1 = clmd->clothObject;
+ Cloth *cloth = clmd->clothObject;
+ const float clamp_sq = square_f(clmd->coll_parms->self_clamp * dt);
+ const float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
+ const float min_distance = (2.0f * clmd->coll_parms->selfepsilon) * (8.0f / 9.0f);
for (int i = 0; i < collision_count; i++, collpair++) {
float ia[3][3] = {{0.0f}};
float ib[3][3] = {{0.0f}};
+ float w1, w2, w3, u1, u2, u3;
+ float v1[3], v2[3], relativeVelocity[3];
/* Only handle static collisions here. */
if (collpair->flag & (COLLISION_IN_FUTURE | COLLISION_INACTIVE)) {
@@ -908,34 +863,34 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
/* Compute barycentric coordinates for both collision points. */
collision_compute_barycentric(collpair->pa,
- cloth1->verts[collpair->ap1].tx,
- cloth1->verts[collpair->ap2].tx,
- cloth1->verts[collpair->ap3].tx,
+ cloth->verts[collpair->ap1].tx,
+ cloth->verts[collpair->ap2].tx,
+ cloth->verts[collpair->ap3].tx,
&w1,
&w2,
&w3);
collision_compute_barycentric(collpair->pb,
- cloth1->verts[collpair->bp1].tx,
- cloth1->verts[collpair->bp2].tx,
- cloth1->verts[collpair->bp3].tx,
+ cloth->verts[collpair->bp1].tx,
+ cloth->verts[collpair->bp2].tx,
+ cloth->verts[collpair->bp3].tx,
&u1,
&u2,
&u3);
/* Calculate relative "velocity". */
collision_interpolateOnTriangle(v1,
- cloth1->verts[collpair->ap1].tv,
- cloth1->verts[collpair->ap2].tv,
- cloth1->verts[collpair->ap3].tv,
+ cloth->verts[collpair->ap1].tv,
+ cloth->verts[collpair->ap2].tv,
+ cloth->verts[collpair->ap3].tv,
w1,
w2,
w3);
collision_interpolateOnTriangle(v2,
- cloth1->verts[collpair->bp1].tv,
- cloth1->verts[collpair->bp2].tv,
- cloth1->verts[collpair->bp3].tv,
+ cloth->verts[collpair->bp1].tv,
+ cloth->verts[collpair->bp2].tv,
+ cloth->verts[collpair->bp3].tv,
u1,
u2,
u3);
@@ -944,7 +899,8 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
/* Calculate the normal component of the relative velocity
* (actually only the magnitude - the direction is stored in 'normal'). */
- magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float d = min_distance - collpair->distance;
/* TODO: Impulses should be weighed by mass as this is self col,
* this has to be done after mass distribution is implemented. */
@@ -952,10 +908,10 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
/* If magrelVel < 0 the edges are approaching each other. */
if (magrelVel > 0.0f) {
/* Calculate Impulse magnitude to stop all motion in normal direction. */
- float magtangent = 0, repulse = 0, d = 0;
+ float magtangent = 0, repulse = 0;
double impulse = 0.0;
float vrel_t_pre[3];
- float temp[3], time_multiplier;
+ float temp[3];
/* Calculate tangential velocity. */
copy_v3_v3(temp, collpair->normal);
@@ -973,29 +929,25 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
impulse = magtangent / 1.5;
- VECADDMUL(ia[0], vrel_t_pre, w1 * impulse);
- VECADDMUL(ia[1], vrel_t_pre, w2 * impulse);
- VECADDMUL(ia[2], vrel_t_pre, w3 * impulse);
+ VECADDMUL(ia[0], vrel_t_pre, (double)w1 * impulse);
+ VECADDMUL(ia[1], vrel_t_pre, (double)w2 * impulse);
+ VECADDMUL(ia[2], vrel_t_pre, (double)w3 * impulse);
- VECADDMUL(ib[0], vrel_t_pre, -u1 * impulse);
- VECADDMUL(ib[1], vrel_t_pre, -u2 * impulse);
- VECADDMUL(ib[2], vrel_t_pre, -u3 * impulse);
+ VECADDMUL(ib[0], vrel_t_pre, (double)u1 * -impulse);
+ VECADDMUL(ib[1], vrel_t_pre, (double)u2 * -impulse);
+ VECADDMUL(ib[2], vrel_t_pre, (double)u3 * -impulse);
}
/* Apply velocity stopping impulse. */
impulse = magrelVel / 3.0f;
- VECADDMUL(ia[0], collpair->normal, w1 * impulse);
- VECADDMUL(ia[1], collpair->normal, w2 * impulse);
- VECADDMUL(ia[2], collpair->normal, w3 * impulse);
-
- VECADDMUL(ib[0], collpair->normal, -u1 * impulse);
- VECADDMUL(ib[1], collpair->normal, -u2 * impulse);
- VECADDMUL(ib[2], collpair->normal, -u3 * impulse);
+ VECADDMUL(ia[0], collpair->normal, (double)w1 * impulse);
+ VECADDMUL(ia[1], collpair->normal, (double)w2 * impulse);
+ VECADDMUL(ia[2], collpair->normal, (double)w3 * impulse);
- time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
-
- d = clmd->coll_parms->selfepsilon * 8.0f / 9.0f * 2.0f - collpair->distance;
+ VECADDMUL(ib[0], collpair->normal, (double)u1 * -impulse);
+ VECADDMUL(ib[1], collpair->normal, (double)u2 * -impulse);
+ VECADDMUL(ib[2], collpair->normal, (double)u3 * -impulse);
if ((magrelVel < 0.1f * d * time_multiplier) && (d > ALMOST_ZERO)) {
repulse = MIN2(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
@@ -1005,54 +957,43 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
}
repulse = max_ff(impulse, repulse);
-
impulse = repulse / 1.5f;
- VECADDMUL(ia[0], collpair->normal, w1 * impulse);
- VECADDMUL(ia[1], collpair->normal, w2 * impulse);
- VECADDMUL(ia[2], collpair->normal, w3 * impulse);
+ VECADDMUL(ia[0], collpair->normal, (double)w1 * impulse);
+ VECADDMUL(ia[1], collpair->normal, (double)w2 * impulse);
+ VECADDMUL(ia[2], collpair->normal, (double)w3 * impulse);
- VECADDMUL(ib[0], collpair->normal, -u1 * impulse);
- VECADDMUL(ib[1], collpair->normal, -u2 * impulse);
- VECADDMUL(ib[2], collpair->normal, -u3 * impulse);
+ VECADDMUL(ib[0], collpair->normal, (double)u1 * -impulse);
+ VECADDMUL(ib[1], collpair->normal, (double)u2 * -impulse);
+ VECADDMUL(ib[2], collpair->normal, (double)u3 * -impulse);
}
result = 1;
}
- else {
- float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
- float d;
-
- d = clmd->coll_parms->selfepsilon * 8.0f / 9.0f * 2.0f - collpair->distance;
-
- if (d > ALMOST_ZERO) {
- /* Stay on the safe side and clamp repulse. */
- float repulse = d * 1.0f / time_multiplier;
- float impulse = repulse / 9.0f;
+ else if (d > ALMOST_ZERO) {
+ /* Stay on the safe side and clamp repulse. */
+ float repulse = d * 1.0f / time_multiplier;
+ float impulse = repulse / 9.0f;
- VECADDMUL(ia[0], collpair->normal, w1 * impulse);
- VECADDMUL(ia[1], collpair->normal, w2 * impulse);
- VECADDMUL(ia[2], collpair->normal, w3 * impulse);
+ VECADDMUL(ia[0], collpair->normal, w1 * impulse);
+ VECADDMUL(ia[1], collpair->normal, w2 * impulse);
+ VECADDMUL(ia[2], collpair->normal, w3 * impulse);
- VECADDMUL(ib[0], collpair->normal, -u1 * impulse);
- VECADDMUL(ib[1], collpair->normal, -u2 * impulse);
- VECADDMUL(ib[2], collpair->normal, -u3 * impulse);
+ VECADDMUL(ib[0], collpair->normal, u1 * -impulse);
+ VECADDMUL(ib[1], collpair->normal, u2 * -impulse);
+ VECADDMUL(ib[2], collpair->normal, u3 * -impulse);
- result = 1;
- }
+ result = 1;
}
if (result) {
- float clamp_sq = clmd->coll_parms->self_clamp * dt;
- clamp_sq *= clamp_sq;
-
- cloth_selfcollision_impulse_vert(clamp_sq, ia[0], &cloth1->verts[collpair->ap1]);
- cloth_selfcollision_impulse_vert(clamp_sq, ia[1], &cloth1->verts[collpair->ap2]);
- cloth_selfcollision_impulse_vert(clamp_sq, ia[2], &cloth1->verts[collpair->ap3]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ia[0], &cloth->verts[collpair->ap1]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ia[1], &cloth->verts[collpair->ap2]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ia[2], &cloth->verts[collpair->ap3]);
- cloth_selfcollision_impulse_vert(clamp_sq, ib[0], &cloth1->verts[collpair->bp1]);
- cloth_selfcollision_impulse_vert(clamp_sq, ib[1], &cloth1->verts[collpair->bp2]);
- cloth_selfcollision_impulse_vert(clamp_sq, ib[2], &cloth1->verts[collpair->bp3]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ib[0], &cloth->verts[collpair->bp1]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ib[1], &cloth->verts[collpair->bp2]);
+ cloth_selfcollision_impulse_vert(clamp_sq, ib[2], &cloth->verts[collpair->bp3]);
}
}
diff --git a/source/blender/blenkernel/intern/colorband.c b/source/blender/blenkernel/intern/colorband.c
index 499b0305c9d..323a2f0cf53 100644
--- a/source/blender/blenkernel/intern/colorband.c
+++ b/source/blender/blenkernel/intern/colorband.c
@@ -587,7 +587,7 @@ static int vergcband(const void *a1, const void *a2)
if (x1->pos > x2->pos) {
return 1;
}
- else if (x1->pos < x2->pos) {
+ if (x1->pos < x2->pos) {
return -1;
}
return 0;
@@ -620,18 +620,17 @@ CBData *BKE_colorband_element_add(struct ColorBand *coba, float position)
if (coba->tot == MAXCOLORBAND) {
return NULL;
}
- else {
- CBData *xnew;
- xnew = &coba->data[coba->tot];
- xnew->pos = position;
+ CBData *xnew;
- if (coba->tot != 0) {
- BKE_colorband_evaluate(coba, position, &xnew->r);
- }
- else {
- zero_v4(&xnew->r);
- }
+ xnew = &coba->data[coba->tot];
+ xnew->pos = position;
+
+ if (coba->tot != 0) {
+ BKE_colorband_evaluate(coba, position, &xnew->r);
+ }
+ else {
+ zero_v4(&xnew->r);
}
coba->tot++;
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 4f4eb8f9f9d..116d8b1a82f 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -603,28 +603,24 @@ static float curvemap_calc_extend(const CurveMapping *cumap,
/* extrapolate horizontally */
return first[1];
}
- else {
- if (cuma->ext_in[0] == 0.0f) {
- return first[1] + cuma->ext_in[1] * 10000.0f;
- }
- else {
- return first[1] + cuma->ext_in[1] * (x - first[0]) / cuma->ext_in[0];
- }
+
+ if (cuma->ext_in[0] == 0.0f) {
+ return first[1] + cuma->ext_in[1] * 10000.0f;
}
+
+ return first[1] + cuma->ext_in[1] * (x - first[0]) / cuma->ext_in[0];
}
- else if (x >= last[0]) {
+ if (x >= last[0]) {
if ((cumap->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
/* extrapolate horizontally */
return last[1];
}
- else {
- if (cuma->ext_out[0] == 0.0f) {
- return last[1] - cuma->ext_out[1] * 10000.0f;
- }
- else {
- return last[1] + cuma->ext_out[1] * (x - last[0]) / cuma->ext_out[0];
- }
+
+ if (cuma->ext_out[0] == 0.0f) {
+ return last[1] - cuma->ext_out[1] * 10000.0f;
}
+
+ return last[1] + cuma->ext_out[1] * (x - last[0]) / cuma->ext_out[0];
}
return 0.0f;
}
@@ -728,14 +724,14 @@ static void curvemap_make_table(const CurveMapping *cumap, CurveMap *cuma)
bezt[a + 1].vec[1][0],
point,
CM_RESOL - 1,
- 2 * sizeof(float));
+ sizeof(float[2]));
BKE_curve_forward_diff_bezier(bezt[a].vec[1][1],
bezt[a].vec[2][1],
bezt[a + 1].vec[0][1],
bezt[a + 1].vec[1][1],
point + 1,
CM_RESOL - 1,
- 2 * sizeof(float));
+ sizeof(float[2]));
}
/* store first and last handle for extrapolation, unit length */
@@ -870,7 +866,7 @@ static int sort_curvepoints(const void *a1, const void *a2)
if (x1->x > x2->x) {
return 1;
}
- else if (x1->x < x2->x) {
+ if (x1->x < x2->x) {
return -1;
}
return 0;
@@ -984,17 +980,16 @@ float BKE_curvemap_evaluateF(const CurveMapping *cumap, const CurveMap *cuma, fl
if (fi < 0.0f || fi > CM_TABLE) {
return curvemap_calc_extend(cumap, cuma, value, &cuma->table[0].x, &cuma->table[CM_TABLE].x);
}
- else {
- if (i < 0) {
- return cuma->table[0].y;
- }
- if (i >= CM_TABLE) {
- return cuma->table[CM_TABLE].y;
- }
- fi = fi - (float)i;
- return (1.0f - fi) * cuma->table[i].y + (fi)*cuma->table[i + 1].y;
+ if (i < 0) {
+ return cuma->table[0].y;
}
+ if (i >= CM_TABLE) {
+ return cuma->table[CM_TABLE].y;
+ }
+
+ fi = fi - (float)i;
+ return (1.0f - fi) * cuma->table[i].y + (fi)*cuma->table[i + 1].y;
}
/* works with curve 'cur' */
@@ -1202,7 +1197,7 @@ int BKE_curvemapping_RGBA_does_something(const CurveMapping *cumap)
return 0;
}
-void BKE_curvemapping_initialize(CurveMapping *cumap)
+void BKE_curvemapping_init(CurveMapping *cumap)
{
int a;
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 2ef32895db9..e5a9ee53054 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -537,7 +537,7 @@ static void contarget_get_lattice_mat(Object *ob, const char *substring, float m
MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup);
if (dw && dw->weight > 0.0f) {
/* copy coordinates of point to temporary vector, then add to find average */
- memcpy(tvec, co ? co : bp->vec, 3 * sizeof(float));
+ memcpy(tvec, co ? co : bp->vec, sizeof(float[3]));
add_v3_v3(vec, tvec);
grouped++;
@@ -602,8 +602,7 @@ static void constraint_target_to_mat4(Object *ob,
pchan = BKE_pose_channel_find_name(ob->pose, substring);
if (pchan) {
/* Multiply the PoseSpace accumulation/final matrix for this
- * PoseChannel by the Armature Object's Matrix to get a worldspace
- * matrix.
+ * PoseChannel by the Armature Object's Matrix to get a world-space matrix.
*/
bool is_bbone = (pchan->bone) && (pchan->bone->segments > 1) &&
(flag & CONSTRAINT_BBONE_SHAPE);
@@ -2404,7 +2403,7 @@ static void armdef_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
}
}
-static void armdef_accumulate_matrix(float obmat[4][4],
+static void armdef_accumulate_matrix(const float obmat[4][4],
const float iobmat[4][4],
const float basemat[4][4],
const float bonemat[4][4],
@@ -5284,9 +5283,8 @@ const bConstraintTypeInfo *BKE_constraint_typeinfo_from_type(int type)
/* there shouldn't be any segfaults here... */
return constraintsTypeInfo[type];
}
- else {
- CLOG_WARN(&LOG, "No valid constraint type-info data available. Type = %i", type);
- }
+
+ CLOG_WARN(&LOG, "No valid constraint type-info data available. Type = %i", type);
return NULL;
}
@@ -5300,9 +5298,8 @@ const bConstraintTypeInfo *BKE_constraint_typeinfo_get(bConstraint *con)
if (con) {
return BKE_constraint_typeinfo_from_type(con->type);
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/* ************************* General Constraints API ************************** */
@@ -5384,9 +5381,8 @@ bool BKE_constraint_remove(ListBase *list, bConstraint *con)
BLI_freelinkN(list, con);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
bool BKE_constraint_remove_ex(ListBase *list, Object *ob, bConstraint *con, bool clear_dep)
@@ -5399,9 +5395,8 @@ bool BKE_constraint_remove_ex(ListBase *list, Object *ob, bConstraint *con, bool
}
return true;
}
- else {
- return false;
- }
+
+ return false;
}
/* ......... */
@@ -6037,7 +6032,7 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph,
*/
enf = con->enforce;
- /* make copy of worldspace matrix pre-constraint for use with blending later */
+ /* make copy of world-space matrix pre-constraint for use with blending later */
copy_m4_m4(oldmat, cob->matrix);
/* move owner matrix into right space */
@@ -6058,16 +6053,16 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph,
cti->flush_constraint_targets(con, &targets, 1);
}
- /* move owner back into worldspace for next constraint/other business */
+ /* move owner back into world-space for next constraint/other business */
if ((con->flag & CONSTRAINT_SPACEONCE) == 0) {
BKE_constraint_mat_convertspace(
cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD, false);
}
/* Interpolate the enforcement, to blend result of constraint into final owner transform
- * - all this happens in worldspace to prevent any weirdness creeping in
+ * - all this happens in world-space to prevent any weirdness creeping in
* (T26014 and T25725), since some constraints may not convert the solution back to the input
- * space before blending but all are guaranteed to end up in good "worldspace" result.
+ * space before blending but all are guaranteed to end up in good "world-space" result.
*/
/* Note: all kind of stuff here before (caused trouble), much easier to just interpolate,
* or did I miss something? -jahka (r.32105) */
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 30f021b0e81..e9ba3a5f873 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -255,13 +255,12 @@ static void *ctx_wm_python_context_get(const bContext *C,
if (RNA_struct_is_a(result.ptr.type, member_type)) {
return result.ptr.data;
}
- else {
- CLOG_WARN(&LOG,
- "PyContext '%s' is a '%s', expected a '%s'",
- member,
- RNA_struct_identifier(result.ptr.type),
- RNA_struct_identifier(member_type));
- }
+
+ CLOG_WARN(&LOG,
+ "PyContext '%s' is a '%s', expected a '%s'",
+ member,
+ RNA_struct_identifier(result.ptr.type),
+ RNA_struct_identifier(member_type));
}
}
#else
@@ -360,9 +359,8 @@ static void *ctx_data_pointer_get(const bContext *C, const char *member)
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
return result.ptr.data;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
@@ -374,15 +372,14 @@ static int ctx_data_pointer_verify(const bContext *C, const char *member, void *
*pointer = NULL;
return 1;
}
- else if (ctx_data_get((bContext *)C, member, &result) == 1) {
+ if (ctx_data_get((bContext *)C, member, &result) == 1) {
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
*pointer = result.ptr.data;
return 1;
}
- else {
- *pointer = NULL;
- return 0;
- }
+
+ *pointer = NULL;
+ return 0;
}
static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list)
@@ -441,9 +438,8 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
return result.ptr;
}
- else {
- return PointerRNA_NULL;
- }
+
+ return PointerRNA_NULL;
}
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
@@ -454,13 +450,12 @@ PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, Stru
if (RNA_struct_is_a(ptr.type, type)) {
return ptr;
}
- else {
- CLOG_WARN(&LOG,
- "member '%s' is '%s', not '%s'",
- member,
- RNA_struct_identifier(ptr.type),
- RNA_struct_identifier(type));
- }
+
+ CLOG_WARN(&LOG,
+ "member '%s' is '%s', not '%s'",
+ member,
+ RNA_struct_identifier(ptr.type),
+ RNA_struct_identifier(type));
}
return PointerRNA_NULL;
@@ -473,9 +468,8 @@ PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *membe
if (ptr.data && RNA_struct_is_a(ptr.type, type)) {
return ptr;
}
- else {
- return PointerRNA_NULL;
- }
+
+ return PointerRNA_NULL;
}
ListBase CTX_data_collection_get(const bContext *C, const char *member)
@@ -486,10 +480,9 @@ ListBase CTX_data_collection_get(const bContext *C, const char *member)
BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION);
return result.list;
}
- else {
- ListBase list = {NULL, NULL};
- return list;
- }
+
+ ListBase list = {NULL, NULL};
+ return list;
}
/* 1:found, -1:found but not set, 0:not found */
@@ -667,9 +660,8 @@ int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBas
BLI_freelistN(&list);
return tot;
}
- else {
- return 0;
- }
+
+ return 0;
}
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
@@ -985,9 +977,8 @@ Main *CTX_data_main(const bContext *C)
if (ctx_data_pointer_verify(C, "blend_data", (void *)&bmain)) {
return bmain;
}
- else {
- return C->data.main;
- }
+
+ return C->data.main;
}
void CTX_data_main_set(bContext *C, Main *bmain)
@@ -1003,9 +994,8 @@ Scene *CTX_data_scene(const bContext *C)
if (ctx_data_pointer_verify(C, "scene", (void *)&scene)) {
return scene;
}
- else {
- return C->data.scene;
- }
+
+ return C->data.scene;
}
ViewLayer *CTX_data_view_layer(const bContext *C)
@@ -1102,34 +1092,34 @@ enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit,
if (object_mode & OB_MODE_POSE) {
return CTX_MODE_POSE;
}
- else if (object_mode & OB_MODE_SCULPT) {
+ if (object_mode & OB_MODE_SCULPT) {
return CTX_MODE_SCULPT;
}
- else if (object_mode & OB_MODE_WEIGHT_PAINT) {
+ if (object_mode & OB_MODE_WEIGHT_PAINT) {
return CTX_MODE_PAINT_WEIGHT;
}
- else if (object_mode & OB_MODE_VERTEX_PAINT) {
+ if (object_mode & OB_MODE_VERTEX_PAINT) {
return CTX_MODE_PAINT_VERTEX;
}
- else if (object_mode & OB_MODE_TEXTURE_PAINT) {
+ if (object_mode & OB_MODE_TEXTURE_PAINT) {
return CTX_MODE_PAINT_TEXTURE;
}
- else if (object_mode & OB_MODE_PARTICLE_EDIT) {
+ if (object_mode & OB_MODE_PARTICLE_EDIT) {
return CTX_MODE_PARTICLE;
}
- else if (object_mode & OB_MODE_PAINT_GPENCIL) {
+ if (object_mode & OB_MODE_PAINT_GPENCIL) {
return CTX_MODE_PAINT_GPENCIL;
}
- else if (object_mode & OB_MODE_EDIT_GPENCIL) {
+ if (object_mode & OB_MODE_EDIT_GPENCIL) {
return CTX_MODE_EDIT_GPENCIL;
}
- else if (object_mode & OB_MODE_SCULPT_GPENCIL) {
+ if (object_mode & OB_MODE_SCULPT_GPENCIL) {
return CTX_MODE_SCULPT_GPENCIL;
}
- else if (object_mode & OB_MODE_WEIGHT_GPENCIL) {
+ if (object_mode & OB_MODE_WEIGHT_GPENCIL) {
return CTX_MODE_WEIGHT_GPENCIL;
}
- else if (object_mode & OB_MODE_VERTEX_GPENCIL) {
+ if (object_mode & OB_MODE_VERTEX_GPENCIL) {
return CTX_MODE_VERTEX_GPENCIL;
}
}
@@ -1173,9 +1163,8 @@ ToolSettings *CTX_data_tool_settings(const bContext *C)
if (scene) {
return scene->toolsettings;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
int CTX_data_selected_nodes(const bContext *C, ListBase *list)
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 0627d2005d5..45ca89ac47e 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -223,7 +223,7 @@ void BKE_curve_init(Curve *cu, const short curve_type)
cu->vfont->id.us += 4;
cu->str = MEM_malloc_arrayN(12, sizeof(unsigned char), "str");
BLI_strncpy(cu->str, "Text", 12);
- cu->len = cu->len_wchar = cu->pos = 4;
+ cu->len = cu->len_char32 = cu->pos = 4;
cu->strinfo = MEM_calloc_arrayN(12, sizeof(CharInfo), "strinfo new");
cu->totbox = cu->actbox = 1;
cu->tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "textbox");
@@ -725,7 +725,7 @@ float BKE_nurb_calc_length(const Nurb *nu, int resolution)
bezt->vec[1][j],
points + j,
resolu,
- 3 * sizeof(float));
+ sizeof(float[3]));
}
prevpntsit = pntsit = points;
@@ -1726,205 +1726,6 @@ static void forward_diff_bezier_cotangent(const float p0[3],
}
}
-/* ***************** BEVEL ****************** */
-
-void BKE_curve_bevel_make(Object *ob, ListBase *disp)
-{
- DispList *dl, *dlnew;
- Curve *bevcu, *cu;
- float *fp, facx, facy, angle, dangle;
- int nr, a;
-
- cu = ob->data;
- BLI_listbase_clear(disp);
-
- /* if a font object is being edited, then do nothing */
- // XXX if ( ob == obedit && ob->type == OB_FONT ) return;
-
- if (cu->bevobj) {
- if (cu->bevobj->type != OB_CURVE) {
- return;
- }
-
- bevcu = cu->bevobj->data;
- if (bevcu->ext1 == 0.0f && bevcu->ext2 == 0.0f) {
- ListBase bevdisp = {NULL, NULL};
- facx = cu->bevobj->scale[0];
- facy = cu->bevobj->scale[1];
-
- if (cu->bevobj->runtime.curve_cache) {
- dl = cu->bevobj->runtime.curve_cache->disp.first;
- }
- else {
- BLI_assert(cu->bevobj->runtime.curve_cache != NULL);
- dl = NULL;
- }
-
- while (dl) {
- if (ELEM(dl->type, DL_POLY, DL_SEGM)) {
- dlnew = MEM_mallocN(sizeof(DispList), "makebevelcurve1");
- *dlnew = *dl;
- dlnew->verts = MEM_malloc_arrayN(
- dl->parts * dl->nr, 3 * sizeof(float), "makebevelcurve1");
- memcpy(dlnew->verts, dl->verts, 3 * sizeof(float) * dl->parts * dl->nr);
-
- if (dlnew->type == DL_SEGM) {
- dlnew->flag |= (DL_FRONT_CURVE | DL_BACK_CURVE);
- }
-
- BLI_addtail(disp, dlnew);
- fp = dlnew->verts;
- nr = dlnew->parts * dlnew->nr;
- while (nr--) {
- fp[2] = fp[1] * facy;
- fp[1] = -fp[0] * facx;
- fp[0] = 0.0;
- fp += 3;
- }
- }
- dl = dl->next;
- }
-
- BKE_displist_free(&bevdisp);
- }
- }
- else if (cu->ext1 == 0.0f && cu->ext2 == 0.0f) {
- /* pass */
- }
- else if (cu->ext2 == 0.0f) {
- dl = MEM_callocN(sizeof(DispList), "makebevelcurve2");
- dl->verts = MEM_malloc_arrayN(2, sizeof(float[3]), "makebevelcurve2");
- BLI_addtail(disp, dl);
- dl->type = DL_SEGM;
- dl->parts = 1;
- dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
- dl->nr = 2;
-
- fp = dl->verts;
- fp[0] = fp[1] = 0.0;
- fp[2] = -cu->ext1;
- fp[3] = fp[4] = 0.0;
- fp[5] = cu->ext1;
- }
- else if ((cu->flag & (CU_FRONT | CU_BACK)) == 0 && cu->ext1 == 0.0f) {
- /* We make a full round bevel in that case. */
-
- nr = 4 + 2 * cu->bevresol;
-
- dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1");
- dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve p1");
- BLI_addtail(disp, dl);
- dl->type = DL_POLY;
- dl->parts = 1;
- dl->flag = DL_BACK_CURVE;
- dl->nr = nr;
-
- /* a circle */
- fp = dl->verts;
- dangle = (2.0f * (float)M_PI / (nr));
- angle = -(nr - 1) * dangle;
-
- for (a = 0; a < nr; a++) {
- fp[0] = 0.0;
- fp[1] = (cosf(angle) * (cu->ext2));
- fp[2] = (sinf(angle) * (cu->ext2)) - cu->ext1;
- angle += dangle;
- fp += 3;
- }
- }
- else {
- /* The general case for nonzero extrusion or an incomplete loop. */
- dl = MEM_callocN(sizeof(DispList), "makebevelcurve");
- if ((cu->flag & (CU_FRONT | CU_BACK)) == 0) {
- /* The full loop. */
- nr = 4 * cu->bevresol + 6;
- dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
- }
- else if ((cu->flag & CU_FRONT) && (cu->flag & CU_BACK)) {
- /* Half the loop. */
- nr = 2 * (cu->bevresol + 1) + ((cu->ext1 == 0.0f) ? 1 : 2);
- dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
- }
- else {
- /* One quarter of the loop (just front or back). */
- nr = (cu->ext1 == 0.0f) ? cu->bevresol + 2 : cu->bevresol + 3;
- dl->flag = (cu->flag & CU_FRONT) ? DL_FRONT_CURVE : DL_BACK_CURVE;
- }
-
- dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve");
- BLI_addtail(disp, dl);
- /* Use a different type depending on whether the loop is complete or not. */
- dl->type = ((cu->flag & (CU_FRONT | CU_BACK)) == 0) ? DL_POLY : DL_SEGM;
- dl->parts = 1;
- dl->nr = nr;
-
- fp = dl->verts;
- dangle = (float)M_PI_2 / (cu->bevresol + 1);
- angle = 0.0;
-
- /* Build the back section. */
- if (cu->flag & CU_BACK || !(cu->flag & CU_FRONT)) {
- angle = (float)M_PI_2 * 3.0f;
- for (a = 0; a < cu->bevresol + 2; a++) {
- fp[0] = 0.0;
- fp[1] = (float)(cosf(angle) * (cu->ext2));
- fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1;
- angle += dangle;
- fp += 3;
- }
- if ((cu->ext1 != 0.0f) && !(cu->flag & CU_FRONT) && (cu->flag & CU_BACK)) {
- /* Add the extrusion if we're only building the back. */
- fp[0] = 0.0;
- fp[1] = cu->ext2;
- fp[2] = cu->ext1;
- }
- }
-
- /* Build the front section. */
- if (cu->flag & CU_FRONT || !(cu->flag & CU_BACK)) {
- if ((cu->ext1 != 0.0f) && !(cu->flag & CU_BACK) && (cu->flag & CU_FRONT)) {
- /* Add the extrusion if we're only building the back. */
- fp[0] = 0.0;
- fp[1] = cu->ext2;
- fp[2] = -cu->ext1;
- fp += 3;
- }
- /* Don't duplicate the last back vertex. */
- angle = (cu->ext1 == 0.0f && (cu->flag & CU_BACK)) ? dangle : 0;
- int front_len = (cu->ext1 == 0.0f && ((cu->flag & CU_BACK) || !(cu->flag & CU_FRONT))) ?
- cu->bevresol + 1 :
- cu->bevresol + 2;
- for (a = 0; a < front_len; a++) {
- fp[0] = 0.0;
- fp[1] = (float)(cosf(angle) * (cu->ext2));
- fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1;
- angle += dangle;
- fp += 3;
- }
- }
-
- /* Build the other half only if we're building the full loop. */
- if (!(cu->flag & (CU_FRONT | CU_BACK))) {
- for (a = 0; a < cu->bevresol + 1; a++) {
- fp[0] = 0.0;
- fp[1] = (float)(cosf(angle) * (cu->ext2));
- fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1;
- angle += dangle;
- fp += 3;
- }
-
- angle = (float)M_PI;
- for (a = 0; a < cu->bevresol + 1; a++) {
- fp[0] = 0.0;
- fp[1] = (float)(cosf(angle) * (cu->ext2));
- fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1;
- angle += dangle;
- fp += 3;
- }
- }
- }
-}
-
static int cu_isectLL(const float v1[3],
const float v2[3],
const float v3[3],
@@ -2500,7 +2301,7 @@ static void make_bevel_list_3D_tangent(BevList *bl)
while (nr--) {
/* make perpendicular, modify tan in place, is ok */
float cross_tmp[3];
- float zero[3] = {0, 0, 0};
+ const float zero[3] = {0, 0, 0};
cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir);
normalize_v3(cross_tmp);
@@ -3797,7 +3598,10 @@ static void bezier_clamp(
}
/* write changes to a bezier handle */
-static void bezier_output_handle_inner(BezTriple *bezt, bool right, float newval[3], bool endpoint)
+static void bezier_output_handle_inner(BezTriple *bezt,
+ bool right,
+ const float newval[3],
+ bool endpoint)
{
float tmp[3];
@@ -5441,7 +5245,7 @@ void BKE_curve_material_index_remove(Curve *cu, int index)
if (curvetype == OB_FONT) {
struct CharInfo *info = cu->strinfo;
int i;
- for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
+ for (i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr && info->mat_nr >= index) {
info->mat_nr--;
}
@@ -5465,7 +5269,7 @@ bool BKE_curve_material_index_used(Curve *cu, int index)
if (curvetype == OB_FONT) {
struct CharInfo *info = cu->strinfo;
int i;
- for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
+ for (i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr == index) {
return true;
}
@@ -5491,7 +5295,7 @@ void BKE_curve_material_index_clear(Curve *cu)
if (curvetype == OB_FONT) {
struct CharInfo *info = cu->strinfo;
int i;
- for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
+ for (i = cu->len_char32 - 1; i >= 0; i--, info++) {
info->mat_nr = 0;
}
}
@@ -5513,7 +5317,7 @@ bool BKE_curve_material_index_validate(Curve *cu)
CharInfo *info = cu->strinfo;
const int max_idx = max_ii(0, cu->totcol); /* OB_FONT use 1 as first mat index, not 0!!! */
int i;
- for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
+ for (i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr > max_idx) {
info->mat_nr = 0;
is_valid = false;
@@ -5561,7 +5365,7 @@ void BKE_curve_material_remap(Curve *cu, const unsigned int *remap, unsigned int
}
else {
strinfo = cu->strinfo;
- charinfo_len = cu->len_wchar;
+ charinfo_len = cu->len_char32;
}
for (i = 0; i <= charinfo_len; i++) {
diff --git a/source/blender/blenkernel/intern/curve_bevel.c b/source/blender/blenkernel/intern/curve_bevel.c
new file mode 100644
index 00000000000..edf5b82f822
--- /dev/null
+++ b/source/blender/blenkernel/intern/curve_bevel.c
@@ -0,0 +1,272 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup bke
+ *
+ * Handle curve object data bevel options,
+ * both extruding
+ */
+
+#include <string.h>
+
+#include "BLI_listbase.h"
+#include "BLI_math_base.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_displist.h"
+
+typedef enum CurveBevelFillType {
+ BACK = 0,
+ FRONT,
+ HALF,
+ FULL,
+} CurveBevelFillType;
+
+static CurveBevelFillType curve_bevel_get_fill_type(const Curve *curve)
+{
+ if (!(curve->flag & (CU_FRONT | CU_BACK))) {
+ return FULL;
+ }
+ if ((curve->flag & CU_FRONT) && (curve->flag & CU_BACK)) {
+ return HALF;
+ }
+
+ return (curve->flag & CU_FRONT) ? FRONT : BACK;
+}
+
+static void curve_bevel_make_extrude_and_fill(Curve *cu,
+ ListBase *disp,
+ const bool use_extrude,
+ const CurveBevelFillType fill_type)
+{
+ DispList *dl = MEM_callocN(sizeof(DispList), __func__);
+
+ int nr;
+ if (fill_type == FULL) {
+ /* The full loop. */
+ nr = 4 * cu->bevresol + 6;
+ dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
+ }
+ else if (fill_type == HALF) {
+ /* Half the loop. */
+ nr = 2 * (cu->bevresol + 1) + (use_extrude ? 2 : 1);
+ dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
+ }
+ else {
+ /* One quarter of the loop (just front or back). */
+ nr = use_extrude ? cu->bevresol + 3 : cu->bevresol + 2;
+ dl->flag = (fill_type == FRONT) ? DL_FRONT_CURVE : DL_BACK_CURVE;
+ }
+
+ dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), __func__);
+ BLI_addtail(disp, dl);
+ /* Use a different type depending on whether the loop is complete or not. */
+ dl->type = (fill_type == FULL) ? DL_POLY : DL_SEGM;
+ dl->parts = 1;
+ dl->nr = nr;
+
+ float *fp = dl->verts;
+ const float dangle = (float)M_PI_2 / (cu->bevresol + 1);
+ float angle = 0.0f;
+
+ /* Build the back section. */
+ if (ELEM(fill_type, BACK, HALF, FULL)) {
+ angle = (float)M_PI_2 * 3.0f;
+ for (int i = 0; i < cu->bevresol + 2; i++) {
+ fp[0] = 0.0f;
+ fp[1] = (float)(cosf(angle) * (cu->ext2));
+ fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1;
+ angle += dangle;
+ fp += 3;
+ }
+ if (use_extrude && fill_type == BACK) {
+ /* Add the extrusion if we're only building the back. */
+ fp[0] = 0.0f;
+ fp[1] = cu->ext2;
+ fp[2] = cu->ext1;
+ }
+ }
+
+ /* Build the front section. */
+ if (ELEM(fill_type, FRONT, HALF, FULL)) {
+ if (use_extrude && fill_type == FRONT) {
+ /* Add the extrusion if we're only building the front. */
+ fp[0] = 0.0f;
+ fp[1] = cu->ext2;
+ fp[2] = -cu->ext1;
+ fp += 3;
+ }
+ /* Don't duplicate the last back vertex. */
+ angle = (!use_extrude && ELEM(fill_type, HALF, FULL)) ? dangle : 0;
+ int front_len = (!use_extrude && ELEM(fill_type, HALF, FULL)) ? cu->bevresol + 1 :
+ cu->bevresol + 2;
+ for (int i = 0; i < front_len; i++) {
+ fp[0] = 0.0f;
+ fp[1] = (float)(cosf(angle) * (cu->ext2));
+ fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1;
+ angle += dangle;
+ fp += 3;
+ }
+ }
+
+ /* Build the other half only if we're building the full loop. */
+ if (fill_type == FULL) {
+ for (int i = 0; i < cu->bevresol + 1; i++) {
+ fp[0] = 0.0f;
+ fp[1] = (float)(cosf(angle) * (cu->ext2));
+ fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1;
+ angle += dangle;
+ fp += 3;
+ }
+
+ angle = (float)M_PI;
+ for (int i = 0; i < cu->bevresol + 1; i++) {
+ fp[0] = 0.0f;
+ fp[1] = (float)(cosf(angle) * (cu->ext2));
+ fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1;
+ angle += dangle;
+ fp += 3;
+ }
+ }
+}
+
+static void curve_bevel_make_full_circle(Curve *cu, ListBase *disp)
+{
+ const int nr = 4 + 2 * cu->bevresol;
+
+ DispList *dl = MEM_callocN(sizeof(DispList), __func__);
+ dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), __func__);
+ BLI_addtail(disp, dl);
+ dl->type = DL_POLY;
+ dl->parts = 1;
+ dl->flag = DL_BACK_CURVE;
+ dl->nr = nr;
+
+ float *fp = dl->verts;
+ const float dangle = (2.0f * (float)M_PI / (nr));
+ float angle = -(nr - 1) * dangle;
+
+ for (int i = 0; i < nr; i++) {
+ fp[0] = 0.0;
+ fp[1] = (cosf(angle) * (cu->ext2));
+ fp[2] = (sinf(angle) * (cu->ext2)) - cu->ext1;
+ angle += dangle;
+ fp += 3;
+ }
+}
+
+static void curve_bevel_make_only_extrude(Curve *cu, ListBase *disp)
+{
+ DispList *dl = MEM_callocN(sizeof(DispList), __func__);
+ dl->verts = MEM_malloc_arrayN(2, sizeof(float[3]), __func__);
+ BLI_addtail(disp, dl);
+ dl->type = DL_SEGM;
+ dl->parts = 1;
+ dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
+ dl->nr = 2;
+
+ float *fp = dl->verts;
+ fp[0] = fp[1] = 0.0;
+ fp[2] = -cu->ext1;
+ fp[3] = fp[4] = 0.0;
+ fp[5] = cu->ext1;
+}
+
+static void curve_bevel_make_from_object(Curve *cu, ListBase *disp)
+{
+ if (cu->bevobj->type != OB_CURVE) {
+ return;
+ }
+
+ Curve *bevcu = cu->bevobj->data;
+ if (bevcu->ext1 == 0.0f && bevcu->ext2 == 0.0f) {
+ ListBase bevdisp = {NULL, NULL};
+ float facx = cu->bevobj->scale[0];
+ float facy = cu->bevobj->scale[1];
+
+ DispList *dl;
+ if (cu->bevobj->runtime.curve_cache) {
+ dl = cu->bevobj->runtime.curve_cache->disp.first;
+ }
+ else {
+ BLI_assert(cu->bevobj->runtime.curve_cache != NULL);
+ dl = NULL;
+ }
+
+ while (dl) {
+ if (ELEM(dl->type, DL_POLY, DL_SEGM)) {
+ DispList *dlnew = MEM_mallocN(sizeof(DispList), __func__);
+ *dlnew = *dl;
+ dlnew->verts = MEM_malloc_arrayN(dl->parts * dl->nr, sizeof(float[3]), __func__);
+ memcpy(dlnew->verts, dl->verts, sizeof(float[3]) * dl->parts * dl->nr);
+
+ if (dlnew->type == DL_SEGM) {
+ dlnew->flag |= (DL_FRONT_CURVE | DL_BACK_CURVE);
+ }
+
+ BLI_addtail(disp, dlnew);
+ float *fp = dlnew->verts;
+ int nr = dlnew->parts * dlnew->nr;
+ while (nr--) {
+ fp[2] = fp[1] * facy;
+ fp[1] = -fp[0] * facx;
+ fp[0] = 0.0;
+ fp += 3;
+ }
+ }
+ dl = dl->next;
+ }
+
+ BKE_displist_free(&bevdisp);
+ }
+}
+
+void BKE_curve_bevel_make(Object *ob, ListBase *disp)
+{
+ Curve *curve = ob->data;
+
+ const bool use_extrude = curve->ext1 != 0.0f;
+ const bool use_bevel = curve->ext2 != 0.0f;
+
+ BLI_listbase_clear(disp);
+
+ if (curve->bevobj) {
+ curve_bevel_make_from_object(curve, disp);
+ }
+ else if (!(use_extrude || use_bevel)) {
+ /* Pass. */
+ }
+ else if (use_extrude && !use_bevel) {
+ curve_bevel_make_only_extrude(curve, disp);
+ }
+ else {
+ CurveBevelFillType fill_type = curve_bevel_get_fill_type(curve);
+
+ if (!use_extrude && fill_type == FULL) {
+ curve_bevel_make_full_circle(curve, disp);
+ }
+ else {
+ /* The general case for nonzero extrusion or an incomplete loop. */
+ curve_bevel_make_extrude_and_fill(curve, disp, use_extrude, fill_type);
+ }
+ }
+}
diff --git a/source/blender/blenkernel/intern/curveprofile.c b/source/blender/blenkernel/intern/curveprofile.c
index 6919d4fa10f..068f8845e64 100644
--- a/source/blender/blenkernel/intern/curveprofile.c
+++ b/source/blender/blenkernel/intern/curveprofile.c
@@ -254,7 +254,7 @@ void BKE_curveprofile_remove_by_flag(CurveProfile *profile, const short flag)
CurveProfilePoint *BKE_curveprofile_insert(CurveProfile *profile, float x, float y)
{
CurveProfilePoint *new_pt = NULL;
- float new_loc[2] = {x, y};
+ const float new_loc[2] = {x, y};
/* Don't add more control points than the maximum size of the higher resolution table. */
if (profile->path_len == PROF_TABLE_MAX - 1) {
@@ -266,8 +266,8 @@ CurveProfilePoint *BKE_curveprofile_insert(CurveProfile *profile, float x, float
float min_distance = FLT_MAX;
int i_insert = 0;
for (int i = 0; i < profile->path_len - 1; i++) {
- float loc1[2] = {profile->path[i].x, profile->path[i].y};
- float loc2[2] = {profile->path[i + 1].x, profile->path[i + 1].y};
+ const float loc1[2] = {profile->path[i].x, profile->path[i].y};
+ const float loc2[2] = {profile->path[i + 1].x, profile->path[i + 1].y};
distance = dist_squared_to_line_segment_v2(new_loc, loc1, loc2);
if (distance < min_distance) {
@@ -689,9 +689,8 @@ static int sort_points_curvature(const void *in_a, const void *in_b)
if (a->bezt_curvature > b->bezt_curvature) {
return 0;
}
- else {
- return 1;
- }
+
+ return 1;
}
/**
@@ -886,7 +885,7 @@ void BKE_curveprofile_create_samples(CurveProfile *profile,
*/
static void curveprofile_make_table(CurveProfile *profile)
{
- int n_samples = PROF_N_TABLE(profile->path_len);
+ int n_samples = PROF_TABLE_LEN(profile->path_len);
CurveProfilePoint *new_table = MEM_callocN(sizeof(CurveProfilePoint) * (n_samples + 1),
"high-res table");
@@ -1040,7 +1039,7 @@ void BKE_curveprofile_update(CurveProfile *profile, const int update_flags)
* Also sets the number of segments used for the display preview of the locations
* of the sampled points.
*/
-void BKE_curveprofile_initialize(CurveProfile *profile, short segments_len)
+void BKE_curveprofile_init(CurveProfile *profile, short segments_len)
{
if (segments_len != profile->segments_len) {
profile->flag |= PROF_DIRTY_PRESET;
@@ -1055,11 +1054,11 @@ void BKE_curveprofile_initialize(CurveProfile *profile, short segments_len)
* Gives the distance to the next point in the widgets sampled table, in other words the length
* of the \a 'i' edge of the table.
*
- * \note Requires curveprofile_initialize or #BKE_curveprofile_update call before to fill table.
+ * \note Requires #BKE_curveprofile_init or #BKE_curveprofile_update call before to fill table.
*/
static float curveprofile_distance_to_next_table_point(const CurveProfile *profile, int i)
{
- BLI_assert(i < PROF_N_TABLE(profile->path_len));
+ BLI_assert(i < PROF_TABLE_LEN(profile->path_len));
return len_v2v2(&profile->table[i].x, &profile->table[i + 1].x);
}
@@ -1067,12 +1066,12 @@ static float curveprofile_distance_to_next_table_point(const CurveProfile *profi
/**
* Calculates the total length of the profile from the curves sampled in the table.
*
- * \note Requires curveprofile_initialize or #BKE_curveprofile_update call before to fill table.
+ * \note Requires #BKE_curveprofile_init or #BKE_curveprofile_update call before to fill table.
*/
float BKE_curveprofile_total_length(const CurveProfile *profile)
{
float total_length = 0;
- for (int i = 0; i < PROF_N_TABLE(profile->path_len) - 1; i++) {
+ for (int i = 0; i < PROF_TABLE_LEN(profile->path_len) - 1; i++) {
total_length += len_v2v2(&profile->table[i].x, &profile->table[i + 1].x);
}
return total_length;
@@ -1082,7 +1081,7 @@ float BKE_curveprofile_total_length(const CurveProfile *profile)
* Samples evenly spaced positions along the curve profile's table (generated from path). Fills
* an entire table at once for a speedup if all of the results are going to be used anyway.
*
- * \note Requires curveprofile_initialize or #BKE_curveprofile_update call before to fill table.
+ * \note Requires #BKE_curveprofile_init or #BKE_curveprofile_update call before to fill table.
* \note Working, but would conflict with "Sample Straight Edges" option, so this is unused for
* now.
*/
@@ -1145,7 +1144,7 @@ void BKE_curveprofile_create_samples_even_spacing(CurveProfile *profile,
* Travels down (length_portion * path) length and returns the position at that point.
*
* \param length_portion: The portion (0 to 1) of the path's full length to sample at.
- * \note Requires curveprofile_initialize or #BKE_curveprofile_update call before to fill table.
+ * \note Requires #BKE_curveprofile_init or #BKE_curveprofile_update call before to fill table.
*/
void BKE_curveprofile_evaluate_length_portion(const CurveProfile *profile,
float length_portion,
@@ -1160,7 +1159,7 @@ void BKE_curveprofile_evaluate_length_portion(const CurveProfile *profile,
float length_travelled = 0.0f;
while (length_travelled < requested_length) {
/* Check if we reached the last point before the final one. */
- if (i == PROF_N_TABLE(profile->path_len) - 2) {
+ if (i == PROF_TABLE_LEN(profile->path_len) - 2) {
break;
}
float new_length = curveprofile_distance_to_next_table_point(profile, i);
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 707db46a856..f728436a759 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -597,14 +597,14 @@ static void layerSwap_mdisps(void *data, const int *ci)
MEM_freeN(s->disps);
s->totdisp = (s->totdisp / corners) * nverts;
- s->disps = MEM_calloc_arrayN(s->totdisp, sizeof(float) * 3, "mdisp swap");
+ s->disps = MEM_calloc_arrayN(s->totdisp, sizeof(float[3]), "mdisp swap");
return;
}
- d = MEM_calloc_arrayN(s->totdisp, 3 * sizeof(float), "mdisps swap");
+ d = MEM_calloc_arrayN(s->totdisp, sizeof(float[3]), "mdisps swap");
for (S = 0; S < corners; S++) {
- memcpy(d + cornersize * S, s->disps + cornersize * ci[S], cornersize * 3 * sizeof(float));
+ memcpy(d + cornersize * S, s->disps + cornersize * ci[S], sizeof(float[3]) * cornersize);
}
MEM_freeN(s->disps);
@@ -660,10 +660,10 @@ static int layerRead_mdisps(CDataFile *cdf, void *data, int count)
for (i = 0; i < count; i++) {
if (!d[i].disps) {
- d[i].disps = MEM_calloc_arrayN(d[i].totdisp, 3 * sizeof(float), "mdisps read");
+ d[i].disps = MEM_calloc_arrayN(d[i].totdisp, sizeof(float[3]), "mdisps read");
}
- if (!cdf_read_data(cdf, d[i].totdisp * 3 * sizeof(float), d[i].disps)) {
+ if (!cdf_read_data(cdf, sizeof(float[3]) * d[i].totdisp, d[i].disps)) {
CLOG_ERROR(&LOG, "failed to read multires displacement %d/%d %d", i, count, d[i].totdisp);
return 0;
}
@@ -678,7 +678,7 @@ static int layerWrite_mdisps(CDataFile *cdf, const void *data, int count)
int i;
for (i = 0; i < count; i++) {
- if (!cdf_write_data(cdf, d[i].totdisp * 3 * sizeof(float), d[i].disps)) {
+ if (!cdf_write_data(cdf, sizeof(float[3]) * d[i].totdisp, d[i].disps)) {
CLOG_ERROR(&LOG, "failed to write multires displacement %d/%d %d", i, count, d[i].totdisp);
return 0;
}
@@ -694,7 +694,7 @@ static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), const void *data, int
int i;
for (i = 0; i < count; i++) {
- size += d[i].totdisp * 3 * sizeof(float);
+ size += sizeof(float[3]) * d[i].totdisp;
}
return size;
@@ -771,7 +771,7 @@ static void layerCopyValue_mloopcol(const void *source,
if (mixmode == CDT_MIX_REPLACE_ABOVE_THRESHOLD && f < mixfactor) {
return; /* Do Nothing! */
}
- else if (mixmode == CDT_MIX_REPLACE_BELOW_THRESHOLD && f > mixfactor) {
+ if (mixmode == CDT_MIX_REPLACE_BELOW_THRESHOLD && f > mixfactor) {
return; /* Do Nothing! */
}
}
@@ -1358,7 +1358,7 @@ static void layerCopyValue_propcol(const void *source,
if (mixmode == CDT_MIX_REPLACE_ABOVE_THRESHOLD && f < mixfactor) {
return; /* Do Nothing! */
}
- else if (mixmode == CDT_MIX_REPLACE_BELOW_THRESHOLD && f > mixfactor) {
+ if (mixmode == CDT_MIX_REPLACE_BELOW_THRESHOLD && f > mixfactor) {
return; /* Do Nothing! */
}
}
@@ -1564,7 +1564,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 0: CD_MVERT */
{sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
/* 1: CD_MSTICKY */ /* DEPRECATED */
- {sizeof(float) * 2, "", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+ {sizeof(float[2]), "", 1, NULL, NULL, NULL, NULL, NULL, NULL},
/* 2: CD_MDEFORMVERT */
{sizeof(MDeformVert),
"MDeformVert",
@@ -1602,7 +1602,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerMaxNum_tface},
/* 6: CD_MCOL */
/* 4 MCol structs per face */
- {sizeof(MCol) * 4,
+ {sizeof(MCol[4]),
"MCol",
4,
N_("Col"),
@@ -1626,7 +1626,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
{sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, layerDefault_origindex},
/* 8: CD_NORMAL */
/* 3 floats per normal vector */
- {sizeof(float) * 3,
+ {sizeof(float[3]),
"vec3f",
1,
NULL,
@@ -1677,7 +1677,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerSwap_origspace_face,
layerDefault_origspace_face},
/* 14: CD_ORCO */
- {sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+ {sizeof(float[3]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 15: CD_MTEXPOLY */ /* DEPRECATED */
/* note, when we expose the UV Map / TexFace split to the user,
* change this back to face Texture. */
@@ -1725,7 +1725,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
NULL,
layerMaxNum_mloopcol},
/* 18: CD_TANGENT */
- {sizeof(float) * 4 * 4, "", 0, N_("Tangent"), NULL, NULL, NULL, NULL, NULL},
+ {sizeof(float[4][4]), "", 0, N_("Tangent"), NULL, NULL, NULL, NULL, NULL},
/* 19: CD_MDISPS */
{sizeof(MDisps),
"MDisps",
@@ -1747,7 +1747,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerWrite_mdisps,
layerFilesize_mdisps},
/* 20: CD_PREVIEW_MCOL */
- {sizeof(MCol) * 4,
+ {sizeof(MCol[4]),
"MCol",
4,
N_("PreviewCol"),
@@ -1757,9 +1757,9 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerSwap_mcol,
layerDefault_mcol},
/* 21: CD_ID_MCOL */ /* DEPRECATED */
- {sizeof(MCol) * 4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+ {sizeof(MCol[4]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 22: CD_TEXTURE_MCOL */
- {sizeof(MCol) * 4,
+ {sizeof(MCol[4]),
"MCol",
4,
N_("TexturedCol"),
@@ -1769,7 +1769,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerSwap_mcol,
layerDefault_mcol},
/* 23: CD_CLOTH_ORCO */
- {sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+ {sizeof(float[3]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 24: CD_RECAST */
{sizeof(MRecast), "MRecast", 1, N_("Recast"), NULL, NULL, NULL, NULL},
@@ -1781,7 +1781,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 27: CD_SHAPE_KEYINDEX */
{sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 28: CD_SHAPEKEY */
- {sizeof(float) * 3, "", 0, N_("ShapeKey"), NULL, NULL, layerInterp_shapekey},
+ {sizeof(float[3]), "", 0, N_("ShapeKey"), NULL, NULL, layerInterp_shapekey},
/* 29: CD_BWEIGHT */
{sizeof(float), "", 0, N_("BevelWeight"), NULL, NULL, layerInterp_bweight},
/* 30: CD_CREASE */
@@ -2201,13 +2201,13 @@ bool CustomData_merge(const struct CustomData *source,
if (flag & CD_FLAG_NOCOPY) {
continue;
}
- else if (!(mask & CD_TYPE_AS_MASK(type))) {
+ if (!(mask & CD_TYPE_AS_MASK(type))) {
continue;
}
- else if ((maxnumber != -1) && (number >= maxnumber)) {
+ if ((maxnumber != -1) && (number >= maxnumber)) {
continue;
}
- else if (CustomData_get_named_layer_index(dest, type, layer->name) != -1) {
+ if (CustomData_get_named_layer_index(dest, type, layer->name) != -1) {
continue;
}
@@ -2643,11 +2643,13 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
}
if (alloctype == CD_DUPLICATE && layerdata) {
- if (typeInfo->copy) {
- typeInfo->copy(layerdata, newlayerdata, totelem);
- }
- else {
- memcpy(newlayerdata, layerdata, (size_t)totelem * typeInfo->size);
+ if (totelem > 0) {
+ if (typeInfo->copy) {
+ typeInfo->copy(layerdata, newlayerdata, totelem);
+ }
+ else {
+ memcpy(newlayerdata, layerdata, (size_t)totelem * typeInfo->size);
+ }
}
}
else if (alloctype == CD_DEFAULT) {
@@ -4050,9 +4052,8 @@ bool CustomData_data_equals(int type, const void *data1, const void *data2)
if (typeInfo->equal) {
return typeInfo->equal(data1, data2);
}
- else {
- return !memcmp(data1, data2, typeInfo->size);
- }
+
+ return !memcmp(data1, data2, typeInfo->size);
}
void CustomData_data_initminmax(int type, void *min, void *max)
@@ -4409,7 +4410,7 @@ int CustomData_layertype_layers_max(const int type)
if (typeInfo->defaultname == NULL) {
return 1;
}
- else if (typeInfo->layers_max == NULL) {
+ if (typeInfo->layers_max == NULL) {
return -1;
}
diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c
index 1463e50f6e3..4fa232a368b 100644
--- a/source/blender/blenkernel/intern/customdata_file.c
+++ b/source/blender/blenkernel/intern/customdata_file.c
@@ -101,9 +101,8 @@ static int cdf_endian(void)
if (ENDIAN_ORDER == L_ENDIAN) {
return CDF_ENDIAN_LITTLE;
}
- else {
- return CDF_ENDIAN_BIG;
- }
+
+ return CDF_ENDIAN_BIG;
}
CDataFile *cdf_create(int type)
@@ -318,9 +317,8 @@ bool cdf_read_layer(CDataFile *cdf, CDataFileLayer *blay)
if (&cdf->layer[a] == blay) {
break;
}
- else {
- offset += cdf->layer[a].datasize;
- }
+
+ offset += cdf->layer[a].datasize;
}
return (fseek(cdf->readf, offset, SEEK_SET) == 0);
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 8ca26e559b4..1b35fdd1706 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -961,7 +961,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (cddata_type == CD_FAKE_BWEIGHT) {
+ if (cddata_type == CD_FAKE_BWEIGHT) {
const size_t elem_size = sizeof(*((MVert *)NULL));
const size_t data_size = sizeof(((MVert *)NULL)->bweight);
const size_t data_offset = offsetof(MVert, bweight);
@@ -993,7 +993,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (cddata_type == CD_FAKE_MDEFORMVERT) {
+ if (cddata_type == CD_FAKE_MDEFORMVERT) {
bool ret;
cd_src = &me_src->vdata;
@@ -1018,7 +1018,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
me_dst->dvert = CustomData_get_layer(&me_dst->vdata, CD_MDEFORMVERT);
return ret;
}
- else if (cddata_type == CD_FAKE_SHAPEKEY) {
+ if (cddata_type == CD_FAKE_SHAPEKEY) {
/* TODO: leaving shapekeys aside for now, quite specific case,
* since we can't access them from MVert :/ */
return false;
@@ -1049,7 +1049,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (cddata_type == CD_FAKE_CREASE) {
+ if (cddata_type == CD_FAKE_CREASE) {
const size_t elem_size = sizeof(*((MEdge *)NULL));
const size_t data_size = sizeof(((MEdge *)NULL)->crease);
const size_t data_offset = offsetof(MEdge, crease);
@@ -1081,7 +1081,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (cddata_type == CD_FAKE_BWEIGHT) {
+ if (cddata_type == CD_FAKE_BWEIGHT) {
const size_t elem_size = sizeof(*((MEdge *)NULL));
const size_t data_size = sizeof(((MEdge *)NULL)->bweight);
const size_t data_offset = offsetof(MEdge, bweight);
@@ -1113,7 +1113,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (r_map && ELEM(cddata_type, CD_FAKE_SHARP, CD_FAKE_SEAM)) {
+ if (r_map && ELEM(cddata_type, CD_FAKE_SHARP, CD_FAKE_SEAM)) {
const size_t elem_size = sizeof(*((MEdge *)NULL));
const size_t data_size = sizeof(((MEdge *)NULL)->flag);
const size_t data_offset = offsetof(MEdge, flag);
@@ -1136,9 +1136,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
interp_data);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
else if (elem_type == ME_LOOP) {
if (cddata_type == CD_FAKE_UV) {
@@ -1176,9 +1175,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else {
- return false;
- }
+
+ return false;
}
else if (elem_type == ME_POLY) {
if (cddata_type == CD_FAKE_UV) {
@@ -1209,7 +1207,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
return true;
}
- else if (r_map && cddata_type == CD_FAKE_SHARP) {
+ if (r_map && cddata_type == CD_FAKE_SHARP) {
const size_t elem_size = sizeof(*((MPoly *)NULL));
const size_t data_size = sizeof(((MPoly *)NULL)->flag);
const size_t data_offset = offsetof(MPoly, flag);
@@ -1232,9 +1230,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
interp_data);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
return false;
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 98fc5f9a23a..1a32deac776 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -510,36 +510,35 @@ int *BKE_object_defgroup_flip_map(const Object *ob, int *flip_map_len, const boo
if (defbase_tot == 0) {
return NULL;
}
- else {
- bDeformGroup *dg;
- char name_flip[sizeof(dg->name)];
- int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__);
- for (i = 0; i < defbase_tot; i++) {
- map[i] = -1;
- }
+ bDeformGroup *dg;
+ char name_flip[sizeof(dg->name)];
+ int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__);
- for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
- if (map[i] == -1) { /* may be calculated previously */
+ for (i = 0; i < defbase_tot; i++) {
+ map[i] = -1;
+ }
- /* in case no valid value is found, use this */
- if (use_default) {
- map[i] = i;
- }
+ for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
+ if (map[i] == -1) { /* may be calculated previously */
- BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+ /* in case no valid value is found, use this */
+ if (use_default) {
+ map[i] = i;
+ }
- if (!STREQ(name_flip, dg->name)) {
- flip_num = BKE_object_defgroup_name_index(ob, name_flip);
- if (flip_num >= 0) {
- map[i] = flip_num;
- map[flip_num] = i; /* save an extra lookup */
- }
+ BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+
+ if (!STREQ(name_flip, dg->name)) {
+ flip_num = BKE_object_defgroup_name_index(ob, name_flip);
+ if (flip_num >= 0) {
+ map[i] = flip_num;
+ map[flip_num] = i; /* save an extra lookup */
}
}
}
- return map;
}
+ return map;
}
/**
@@ -555,29 +554,28 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
if (defbase_tot == 0) {
return NULL;
}
- else {
- bDeformGroup *dg;
- char name_flip[sizeof(dg->name)];
- int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__);
- for (i = 0; i < defbase_tot; i++) {
- map[i] = use_default ? i : -1;
- }
+ bDeformGroup *dg;
+ char name_flip[sizeof(dg->name)];
+ int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__);
- dg = BLI_findlink(&ob->defbase, defgroup);
+ for (i = 0; i < defbase_tot; i++) {
+ map[i] = use_default ? i : -1;
+ }
- BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
- if (!STREQ(name_flip, dg->name)) {
- flip_num = BKE_object_defgroup_name_index(ob, name_flip);
+ dg = BLI_findlink(&ob->defbase, defgroup);
- if (flip_num != -1) {
- map[defgroup] = flip_num;
- map[flip_num] = defgroup;
- }
- }
+ BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+ if (!STREQ(name_flip, dg->name)) {
+ flip_num = BKE_object_defgroup_name_index(ob, name_flip);
- return map;
+ if (flip_num != -1) {
+ map[defgroup] = flip_num;
+ map[flip_num] = defgroup;
+ }
}
+
+ return map;
}
int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_default)
@@ -658,7 +656,7 @@ float BKE_defvert_array_find_weight_safe(const struct MDeformVert *dvert,
if (defgroup == -1) {
return 1.0f;
}
- else if (dvert == NULL) {
+ if (dvert == NULL) {
return 0.0f;
}
@@ -909,10 +907,9 @@ float BKE_defvert_calc_lock_relative_weight(float weight,
if (weight != 0.0f) {
return 1.0f;
}
- else {
- /* resolve 0/0 to 0 */
- return 0.0f;
- }
+
+ /* resolve 0/0 to 0 */
+ return 0.0f;
}
/* non-degenerate division */
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index a3e1eeb89c7..5c162486c85 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -172,7 +172,7 @@ void BKE_displist_normals_add(ListBase *lb)
while (dl) {
if (dl->type == DL_INDEX3) {
if (dl->nors == NULL) {
- dl->nors = MEM_callocN(sizeof(float) * 3, "dlnors");
+ dl->nors = MEM_callocN(sizeof(float[3]), "dlnors");
if (dl->flag & DL_BACK_CURVE) {
dl->nors[2] = -1.0f;
@@ -184,7 +184,7 @@ void BKE_displist_normals_add(ListBase *lb)
}
else if (dl->type == DL_SURF) {
if (dl->nors == NULL) {
- dl->nors = MEM_callocN(sizeof(float) * 3 * dl->nr * dl->parts, "dlnors");
+ dl->nors = MEM_callocN(sizeof(float[3]) * dl->nr * dl->parts, "dlnors");
vdata = dl->verts;
ndata = dl->nors;
@@ -411,7 +411,7 @@ static void curve_to_displist(Curve *cu,
bezt->vec[1][j],
data + j,
resolu,
- 3 * sizeof(float));
+ sizeof(float[3]));
}
data += 3 * resolu;
@@ -444,7 +444,7 @@ static void curve_to_displist(Curve *cu,
else {
dl->type = DL_SEGM;
}
- BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float));
+ BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3]));
}
else if (nu->type == CU_POLY) {
len = nu->pntsu;
@@ -571,8 +571,8 @@ void BKE_displist_fill(ListBase *dispbase,
dlnew->nr = totvert;
dlnew->parts = tot;
- dlnew->index = MEM_mallocN(tot * 3 * sizeof(int), "dlindex");
- dlnew->verts = MEM_mallocN(totvert * 3 * sizeof(float), "dlverts");
+ dlnew->index = MEM_mallocN(sizeof(int[3]) * tot, "dlindex");
+ dlnew->verts = MEM_mallocN(sizeof(float[3]) * totvert, "dlverts");
/* vert data */
f1 = dlnew->verts;
@@ -641,7 +641,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
if ((cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE)) {
dlnew = MEM_callocN(sizeof(DispList), "filldisp");
BLI_addtail(&front, dlnew);
- dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1");
+ dlnew->verts = fp1 = MEM_mallocN(sizeof(float[3]) * dl->parts, "filldisp1");
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
@@ -662,7 +662,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
if ((cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE)) {
dlnew = MEM_callocN(sizeof(DispList), "filldisp");
BLI_addtail(&back, dlnew);
- dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1");
+ dlnew->verts = fp1 = MEM_mallocN(sizeof(float[3]) * dl->parts, "filldisp1");
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
@@ -948,7 +948,7 @@ static float (*displist_vert_coords_alloc(ListBase *dispbase, int *r_vert_len))[
*r_vert_len += (dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr;
}
- allverts = MEM_mallocN((*r_vert_len) * sizeof(float) * 3, "displist_vert_coords_alloc allverts");
+ allverts = MEM_mallocN(sizeof(float[3]) * (*r_vert_len), "displist_vert_coords_alloc allverts");
fp = (float *)allverts;
for (dl = dispbase->first; dl; dl = dl->next) {
int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr);
@@ -1185,7 +1185,7 @@ static void displist_surf_indices(DispList *dl)
dl->totindex = 0;
- index = dl->index = MEM_mallocN(4 * sizeof(int) * (dl->parts + 1) * (dl->nr + 1),
+ index = dl->index = MEM_mallocN(sizeof(int[4]) * (dl->parts + 1) * (dl->nr + 1),
"index array nurbs");
for (a = 0; a < dl->parts; a++) {
@@ -1274,7 +1274,7 @@ void BKE_displist_make_surf(Depsgraph *depsgraph,
dl->type = DL_SEGM;
}
- BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float));
+ BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, sizeof(float[3]));
}
else {
len = (nu->pntsu * resolu) * (nu->pntsv * resolv);
@@ -1388,7 +1388,7 @@ static void fillBevelCap(Nurb *nu, DispList *dlb, float *prev_fp, ListBase *disp
dl = MEM_callocN(sizeof(DispList), "makeDispListbev2");
dl->verts = MEM_mallocN(sizeof(float[3]) * dlb->nr, "dlverts");
- memcpy(dl->verts, prev_fp, 3 * sizeof(float) * dlb->nr);
+ memcpy(dl->verts, prev_fp, sizeof(float[3]) * dlb->nr);
dl->type = DL_POLY;
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 7b7b7ceb84b..1c61afe5e5a 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -320,7 +320,7 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface)
if (surface->format == MOD_DPAINT_SURFACE_F_PTEX) {
return 0; /* not supported atm */
}
- else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
+ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
const Mesh *canvas_mesh = dynamicPaint_canvas_mesh_get(surface->canvas);
return (canvas_mesh) ? canvas_mesh->totvert : 0;
}
@@ -353,7 +353,7 @@ bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object
Mesh *me = ob->data;
return (CustomData_get_named_layer_index(&me->ldata, CD_MLOOPCOL, name) != -1);
}
- else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
+ if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
return (BKE_object_defgroup_name_index(ob, name) != -1);
}
}
@@ -602,7 +602,7 @@ static bool boundIntersectPoint(Bounds3D *b, const float point[3], const float r
}
/* expand bounds by a new point */
-static void boundInsert(Bounds3D *b, float point[3])
+static void boundInsert(Bounds3D *b, const float point[3])
{
if (!b->valid) {
copy_v3_v3(b->min, point);
@@ -2675,7 +2675,7 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa
int w = bdata->w, h = bdata->h, px = bdata->px, py = bdata->py;
- int final_pixel[2] = {(int)floorf(tgt_pixel[0] * w), (int)floorf(tgt_pixel[1] * h)};
+ const int final_pixel[2] = {(int)floorf(tgt_pixel[0] * w), (int)floorf(tgt_pixel[1] * h)};
/* If current pixel uv is outside of texture */
if (final_pixel[0] < 0 || final_pixel[0] >= w || final_pixel[1] < 0 || final_pixel[1] >= h) {
@@ -3742,7 +3742,7 @@ static bool meshBrush_boundsIntersect(Bounds3D *b1,
if (brush->collision == MOD_DPAINT_COL_VOLUME) {
return boundsIntersect(b1, b2);
}
- else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) {
+ if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) {
return boundsIntersectDist(b1, b2, brush_radius);
}
return true;
@@ -5166,7 +5166,7 @@ static int dynamicPaint_prepareEffectStep(struct Depsgraph *depsgraph,
ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, surface->effector_weights);
/* allocate memory for force data (dir vector + strength) */
- *force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces");
+ *force = MEM_mallocN(sizeof(float[4]) * sData->total_points, "PaintEffectForces");
if (*force) {
DynamicPaintEffectData data = {
@@ -6260,7 +6260,7 @@ static int dynamicPaint_doStep(Depsgraph *depsgraph,
/* calculate brush speed vectors if required */
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) {
- bData->brush_velocity = MEM_callocN(sData->total_points * sizeof(float) * 4,
+ bData->brush_velocity = MEM_callocN(sizeof(float[4]) * sData->total_points,
"Dynamic Paint brush velocity");
/* init adjacency data if not already */
if (!sData->adj_data) {
diff --git a/source/blender/blenkernel/intern/editmesh_cache.c b/source/blender/blenkernel/intern/editmesh_cache.c
index 5017a48d14e..d0509c94fc6 100644
--- a/source/blender/blenkernel/intern/editmesh_cache.c
+++ b/source/blender/blenkernel/intern/editmesh_cache.c
@@ -148,11 +148,10 @@ bool BKE_editmesh_cache_calc_minmax(struct BMEditMesh *em,
}
return true;
}
- else {
- zero_v3(min);
- zero_v3(max);
- return false;
- }
+
+ zero_v3(min);
+ zero_v3(max);
+ return false;
}
/** \} */
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c
index 6fcaf84d4ca..897fc7e692b 100644
--- a/source/blender/blenkernel/intern/editmesh_tangent.c
+++ b/source/blender/blenkernel/intern/editmesh_tangent.c
@@ -274,8 +274,8 @@ static void emDM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool), vo
/**
* \see #BKE_mesh_calc_loop_tangent, same logic but used arrays instead of #BMesh data.
*
- * \note This function is not so normal, its using `bm->ldata` as input,
- * but output's to `dm->loopData`.
+ * \note This function is not so normal, its using #BMesh.ldata as input,
+ * but output's to #Mesh.ldata.
* This is done because #CD_TANGENT is cache data used only for drawing.
*/
void BKE_editmesh_loop_tangent_calc(BMEditMesh *em,
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index a43553ee89f..97f9cebf58b 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -313,10 +313,10 @@ ListBase *BKE_effectors_create(Depsgraph *depsgraph,
if (ob == ob_src) {
continue;
}
- else if (weights->weight[ob->pd->forcefield] == 0.0f) {
+ if (weights->weight[ob->pd->forcefield] == 0.0f) {
continue;
}
- else if (ob->pd->shape == PFIELD_SHAPE_POINTS && BKE_object_get_evaluated_mesh(ob) == NULL) {
+ if (ob->pd->shape == PFIELD_SHAPE_POINTS && BKE_object_get_evaluated_mesh(ob) == NULL) {
continue;
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index acbbf50701a..abed90e7192 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -320,7 +320,7 @@ int BKE_fcurves_filter(ListBase *dst, ListBase *src, const char *dataPrefix, con
if (ELEM(NULL, dst, src, dataPrefix, dataName)) {
return 0;
}
- else if ((dataPrefix[0] == 0) || (dataName[0] == 0)) {
+ if ((dataPrefix[0] == 0) || (dataName[0] == 0)) {
return 0;
}
@@ -915,7 +915,7 @@ void bezt_add_to_cfra_elem(ListBase *lb, BezTriple *bezt)
return;
}
/* should key be inserted before this column? */
- else if (ce->cfra > bezt->vec[1][0]) {
+ if (ce->cfra > bezt->vec[1][0]) {
break;
}
}
diff --git a/source/blender/blenkernel/intern/fcurve_driver.c b/source/blender/blenkernel/intern/fcurve_driver.c
index 10d804f437e..b11a3cb9457 100644
--- a/source/blender/blenkernel/intern/fcurve_driver.c
+++ b/source/blender/blenkernel/intern/fcurve_driver.c
@@ -21,12 +21,6 @@
* \ingroup bke
*/
-// #include <float.h>
-// #include <math.h>
-// #include <stddef.h>
-// #include <stdio.h>
-// #include <string.h>
-
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
@@ -66,17 +60,19 @@ static ThreadMutex python_driver_lock = BLI_MUTEX_INITIALIZER;
static CLG_LogRef LOG = {"bke.fcurve"};
-/* Driver Variables --------------------------- */
+/* -------------------------------------------------------------------- */
+/** \name Driver Variables
+ * \{ */
/* TypeInfo for Driver Variables (dvti) */
typedef struct DriverVarTypeInfo {
- /* evaluation callback */
+ /* Evaluation callback. */
float (*get_value)(ChannelDriver *driver, DriverVar *dvar);
- /* allocation of target slots */
- int num_targets; /* number of target slots required */
- const char *target_names[MAX_DRIVER_TARGETS]; /* UI names that should be given to the slots */
- short target_flags[MAX_DRIVER_TARGETS]; /* flags defining the requirements for each slot */
+ /* Allocation of target slots. */
+ int num_targets; /* Number of target slots required. */
+ const char *target_names[MAX_DRIVER_TARGETS]; /* UI names that should be given to the slots. */
+ short target_flags[MAX_DRIVER_TARGETS]; /* Flags defining the requirements for each slot. */
} DriverVarTypeInfo;
/* Macro to begin definitions */
@@ -85,7 +81,11 @@ typedef struct DriverVarTypeInfo {
/* Macro to end definitions */
#define END_DVAR_TYPEDEF }
-/* ......... */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver Target Utilities
+ * \{ */
static ID *dtar_id_ensure_proxy_from(ID *id)
{
@@ -107,14 +107,14 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
int index = -1;
float value = 0.0f;
- /* sanity check */
+ /* Sanity check. */
if (ELEM(NULL, driver, dtar)) {
return 0.0f;
}
id = dtar_id_ensure_proxy_from(dtar->id);
- /* error check for missing pointer... */
+ /* Error check for missing pointer. */
if (id == NULL) {
if (G.debug & G_DEBUG) {
CLOG_ERROR(&LOG, "driver has an invalid target to use (path = %s)", dtar->rna_path);
@@ -125,12 +125,12 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
return 0.0f;
}
- /* get RNA-pointer for the ID-block given in target */
+ /* Get RNA-pointer for the ID-block given in target. */
RNA_id_pointer_create(id, &id_ptr);
- /* get property to read from, and get value as appropriate */
+ /* Get property to read from, and get value as appropriate. */
if (!RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
- /* path couldn't be resolved */
+ /* Path couldn't be resolved. */
if (G.debug & G_DEBUG) {
CLOG_ERROR(&LOG,
"Driver Evaluation Error: cannot resolve target for %s -> %s",
@@ -144,9 +144,9 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
}
if (RNA_property_array_check(prop)) {
- /* array */
+ /* Array. */
if (index < 0 || index >= RNA_property_array_length(&ptr, prop)) {
- /* out of bounds */
+ /* Out of bounds. */
if (G.debug & G_DEBUG) {
CLOG_ERROR(&LOG,
"Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
@@ -175,7 +175,7 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
}
}
else {
- /* not an array */
+ /* Not an array. */
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
value = (float)RNA_property_boolean_get(&ptr, prop);
@@ -194,7 +194,7 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
}
}
- /* if we're still here, we should be ok... */
+ /* If we're still here, we should be ok. */
dtar->flag &= ~DTAR_FLAG_INVALID;
return value;
}
@@ -214,14 +214,14 @@ bool driver_get_variable_property(ChannelDriver *driver,
ID *id;
int index = -1;
- /* sanity check */
+ /* Sanity check. */
if (ELEM(NULL, driver, dtar)) {
return false;
}
id = dtar_id_ensure_proxy_from(dtar->id);
- /* error check for missing pointer... */
+ /* Error check for missing pointer. */
if (id == NULL) {
if (G.debug & G_DEBUG) {
CLOG_ERROR(&LOG, "driver has an invalid target to use (path = %s)", dtar->rna_path);
@@ -232,19 +232,19 @@ bool driver_get_variable_property(ChannelDriver *driver,
return false;
}
- /* get RNA-pointer for the ID-block given in target */
+ /* Get RNA-pointer for the ID-block given in target. */
RNA_id_pointer_create(id, &id_ptr);
- /* get property to read from, and get value as appropriate */
+ /* Get property to read from, and get value as appropriate. */
if (dtar->rna_path == NULL || dtar->rna_path[0] == '\0') {
ptr = PointerRNA_NULL;
- prop = NULL; /* ok */
+ prop = NULL; /* OK. */
}
else if (RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
- /* ok */
+ /* OK. */
}
else {
- /* path couldn't be resolved */
+ /* Path couldn't be resolved. */
if (G.debug & G_DEBUG) {
CLOG_ERROR(&LOG,
"Driver Evaluation Error: cannot resolve target for %s -> %s",
@@ -265,7 +265,7 @@ bool driver_get_variable_property(ChannelDriver *driver,
*r_prop = prop;
*r_index = index;
- /* if we're still here, we should be ok... */
+ /* If we're still here, we should be ok. */
dtar->flag &= ~DTAR_FLAG_INVALID;
return true;
}
@@ -277,14 +277,14 @@ static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
- /* check if this target has valid data */
+ /* Check if this target has valid data. */
if ((ob == NULL) || (GS(ob->id.name) != ID_OB)) {
- /* invalid target, so will not have enough targets */
+ /* Invalid target, so will not have enough targets. */
driver->flag |= DRIVER_FLAG_INVALID;
dtar->flag |= DTAR_FLAG_INVALID;
}
else {
- /* target seems to be OK now... */
+ /* Target seems to be OK now. */
dtar->flag &= ~DTAR_FLAG_INVALID;
valid_targets++;
}
@@ -294,21 +294,25 @@ static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
return valid_targets;
}
-/* ......... */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver Variable Utilities
+ * \{ */
-/* evaluate 'single prop' driver variable */
+/* Evaluate 'single prop' driver variable. */
static float dvar_eval_singleProp(ChannelDriver *driver, DriverVar *dvar)
{
- /* just evaluate the first target slot */
+ /* Just evaluate the first target slot. */
return dtar_get_prop_val(driver, &dvar->targets[0]);
}
-/* evaluate 'rotation difference' driver variable */
+/* Evaluate 'rotation difference' driver variable. */
static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
{
short valid_targets = driver_check_valid_targets(driver, dvar);
- /* make sure we have enough valid targets to use - all or nothing for now... */
+ /* Make sure we have enough valid targets to use - all or nothing for now. */
if (driver_check_valid_targets(driver, dvar) != 2) {
if (G.debug & G_DEBUG) {
CLOG_WARN(&LOG,
@@ -324,31 +328,31 @@ static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
/* NOTE: for now, these are all just worldspace */
for (int i = 0; i < 2; i++) {
- /* get pointer to loc values to store in */
+ /* Get pointer to loc values to store in. */
DriverTarget *dtar = &dvar->targets[i];
Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
bPoseChannel *pchan;
- /* after the checks above, the targets should be valid here... */
+ /* After the checks above, the targets should be valid here. */
BLI_assert((ob != NULL) && (GS(ob->id.name) == ID_OB));
- /* try to get posechannel */
+ /* Try to get pose-channel. */
pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
- /* check if object or bone */
+ /* Check if object or bone. */
if (pchan) {
- /* bone */
+ /* Bone. */
mat[i] = pchan->pose_mat;
}
else {
- /* object */
+ /* Object. */
mat[i] = ob->obmat;
}
}
float q1[4], q2[4], quat[4], angle;
- /* use the final posed locations */
+ /* Use the final posed locations. */
mat4_to_quat(q1, mat[0]);
mat4_to_quat(q2, mat[1]);
@@ -360,15 +364,18 @@ static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
return (angle > (float)M_PI) ? (float)((2.0f * (float)M_PI) - angle) : (float)(angle);
}
-/* evaluate 'location difference' driver variable */
-/* TODO: this needs to take into account space conversions... */
+/**
+ * Evaluate 'location difference' driver variable.
+ *
+ * TODO: this needs to take into account space conversions.
+ */
static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
{
float loc1[3] = {0.0f, 0.0f, 0.0f};
float loc2[3] = {0.0f, 0.0f, 0.0f};
short valid_targets = driver_check_valid_targets(driver, dvar);
- /* make sure we have enough valid targets to use - all or nothing for now... */
+ /* Make sure we have enough valid targets to use - all or nothing for now. */
if (valid_targets < dvar->num_targets) {
if (G.debug & G_DEBUG) {
CLOG_WARN(&LOG,
@@ -381,72 +388,72 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
}
/* SECOND PASS: get two location values */
- /* NOTE: for now, these are all just worldspace */
+ /* NOTE: for now, these are all just world-space */
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
- /* get pointer to loc values to store in */
+ /* Get pointer to loc values to store in. */
Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
bPoseChannel *pchan;
float tmp_loc[3];
- /* after the checks above, the targets should be valid here... */
+ /* After the checks above, the targets should be valid here. */
BLI_assert((ob != NULL) && (GS(ob->id.name) == ID_OB));
- /* try to get posechannel */
+ /* Try to get pose-channel. */
pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
- /* check if object or bone */
+ /* Check if object or bone. */
if (pchan) {
- /* bone */
+ /* Bone. */
if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
float mat[4][4];
- /* extract transform just like how the constraints do it! */
+ /* Extract transform just like how the constraints do it! */
copy_m4_m4(mat, pchan->pose_mat);
BKE_constraint_mat_convertspace(
ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
- /* ... and from that, we get our transform */
+ /* ... and from that, we get our transform. */
copy_v3_v3(tmp_loc, mat[3]);
}
else {
- /* transform space (use transform values directly) */
+ /* Transform space (use transform values directly). */
copy_v3_v3(tmp_loc, pchan->loc);
}
}
else {
- /* convert to worldspace */
+ /* Convert to worldspace. */
copy_v3_v3(tmp_loc, pchan->pose_head);
mul_m4_v3(ob->obmat, tmp_loc);
}
}
else {
- /* object */
+ /* Object. */
if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
- /* XXX: this should practically be the same as transform space... */
+ /* XXX: this should practically be the same as transform space. */
float mat[4][4];
- /* extract transform just like how the constraints do it! */
+ /* Extract transform just like how the constraints do it! */
copy_m4_m4(mat, ob->obmat);
BKE_constraint_mat_convertspace(
ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, false);
- /* ... and from that, we get our transform */
+ /* ... and from that, we get our transform. */
copy_v3_v3(tmp_loc, mat[3]);
}
else {
- /* transform space (use transform values directly) */
+ /* Transform space (use transform values directly). */
copy_v3_v3(tmp_loc, ob->loc);
}
}
else {
- /* worldspace */
+ /* World-space. */
copy_v3_v3(tmp_loc, ob->obmat[3]);
}
}
- /* copy the location to the right place */
+ /* Copy the location to the right place. */
if (tarIndex) {
copy_v3_v3(loc2, tmp_loc);
}
@@ -456,13 +463,14 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
}
DRIVER_TARGETS_LOOPER_END;
- /* if we're still here, there should now be two targets to use,
- * so just take the length of the vector between these points
- */
+ /* If we're still here, there should now be two targets to use,
+ * so just take the length of the vector between these points. */
return len_v3v3(loc1, loc2);
}
-/* evaluate 'transform channel' driver variable */
+/**
+ * Evaluate 'transform channel' driver variable.
+ */
static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
{
DriverTarget *dtar = &dvar->targets[0];
@@ -473,17 +481,16 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
bool use_eulers = false;
short rot_order = ROT_MODE_EUL;
- /* check if this target has valid data */
+ /* Check if this target has valid data. */
if ((ob == NULL) || (GS(ob->id.name) != ID_OB)) {
- /* invalid target, so will not have enough targets */
+ /* Invalid target, so will not have enough targets. */
driver->flag |= DRIVER_FLAG_INVALID;
dtar->flag |= DTAR_FLAG_INVALID;
return 0.0f;
}
- else {
- /* target should be valid now */
- dtar->flag &= ~DTAR_FLAG_INVALID;
- }
+
+ /* Target should be valid now. */
+ dtar->flag &= ~DTAR_FLAG_INVALID;
/* Try to get pose-channel. */
pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
@@ -495,7 +502,7 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
* but #DTAR_FLAG_LOCAL_CONSTS is for all the common "corrective-shapes-for-limbs" situations.
*/
if (pchan) {
- /* bone */
+ /* Bone. */
if (pchan->rotmode > 0) {
copy_v3_v3(oldEul, pchan->eul);
rot_order = pchan->rotmode;
@@ -504,16 +511,15 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
- /* just like how the constraints do it! */
+ /* Just like how the constraints do it! */
copy_m4_m4(mat, pchan->pose_mat);
BKE_constraint_mat_convertspace(
ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
}
else {
- /* specially calculate local matrix, since chan_mat is not valid
+ /* Specially calculate local matrix, since chan_mat is not valid
* since it stores delta transform of pose_mat so that deforms work
- * so it cannot be used here for "transform" space
- */
+ * so it cannot be used here for "transform" space. */
BKE_pchan_to_mat4(pchan, mat);
}
}
@@ -523,7 +529,7 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
}
}
else {
- /* object */
+ /* Object. */
if (ob->rotmode > 0) {
copy_v3_v3(oldEul, ob->rot);
rot_order = ob->rotmode;
@@ -532,42 +538,39 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
- /* just like how the constraints do it! */
+ /* Just like how the constraints do it! */
copy_m4_m4(mat, ob->obmat);
BKE_constraint_mat_convertspace(
ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, false);
}
else {
- /* transforms to matrix */
+ /* Transforms to matrix. */
BKE_object_to_mat4(ob, mat);
}
}
else {
- /* worldspace matrix - just the good-old one */
+ /* World-space matrix - just the good-old one. */
copy_m4_m4(mat, ob->obmat);
}
}
- /* check which transform */
+ /* Check which transform. */
if (dtar->transChan >= MAX_DTAR_TRANSCHAN_TYPES) {
- /* not valid channel */
+ /* Not valid channel. */
return 0.0f;
}
- else if (dtar->transChan == DTAR_TRANSCHAN_SCALE_AVG) {
+ if (dtar->transChan == DTAR_TRANSCHAN_SCALE_AVG) {
/* Cubic root of the change in volume, equal to the geometric mean
* of scale over all three axes unless the matrix includes shear. */
return cbrtf(mat4_to_volume_scale(mat));
}
- else if (ELEM(dtar->transChan,
- DTAR_TRANSCHAN_SCALEX,
- DTAR_TRANSCHAN_SCALEY,
- DTAR_TRANSCHAN_SCALEZ)) {
+ if (ELEM(dtar->transChan, DTAR_TRANSCHAN_SCALEX, DTAR_TRANSCHAN_SCALEY, DTAR_TRANSCHAN_SCALEZ)) {
/* Extract scale, and choose the right axis,
* inline 'mat4_to_size'. */
return len_v3(mat[dtar->transChan - DTAR_TRANSCHAN_SCALEX]);
}
- else if (dtar->transChan >= DTAR_TRANSCHAN_ROTX) {
- /* extract rotation as eulers (if needed)
+ if (dtar->transChan >= DTAR_TRANSCHAN_ROTX) {
+ /* Extract rotation as eulers (if needed)
* - definitely if rotation order isn't eulers already
* - if eulers, then we have 2 options:
* a) decompose transform matrix as required, then try to make eulers from
@@ -595,10 +598,9 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
return quat[channel];
}
- else {
- /* extract location and choose right axis */
- return mat[3][dtar->transChan];
- }
+
+ /* Extract location and choose right axis. */
+ return mat[3][dtar->transChan];
}
/* Convert a quaternion to pseudo-angles representing the weighted amount of rotation. */
@@ -666,83 +668,90 @@ void BKE_driver_target_matrix_to_rot_channels(
}
}
-/* ......... */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver Variable Type Info
+ * \{ */
/* Table of Driver Variable Type Info Data */
static DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES] = {
- BEGIN_DVAR_TYPEDEF(DVAR_TYPE_SINGLE_PROP) dvar_eval_singleProp, /* eval callback */
- 1, /* number of targets used */
+ BEGIN_DVAR_TYPEDEF(DVAR_TYPE_SINGLE_PROP) dvar_eval_singleProp, /* Eval callback. */
+ 1, /* Number of targets used. */
{"Property"}, /* UI names for targets */
- {0} /* flags */
+ {0} /* Flags. */
END_DVAR_TYPEDEF,
- BEGIN_DVAR_TYPEDEF(DVAR_TYPE_ROT_DIFF) dvar_eval_rotDiff, /* eval callback */
- 2, /* number of targets used */
+ BEGIN_DVAR_TYPEDEF(DVAR_TYPE_ROT_DIFF) dvar_eval_rotDiff, /* Eval callback. */
+ 2, /* Number of targets used. */
{"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */
{DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY,
- DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */
+ DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* Flags. */
END_DVAR_TYPEDEF,
- BEGIN_DVAR_TYPEDEF(DVAR_TYPE_LOC_DIFF) dvar_eval_locDiff, /* eval callback */
- 2, /* number of targets used */
+ BEGIN_DVAR_TYPEDEF(DVAR_TYPE_LOC_DIFF) dvar_eval_locDiff, /* Eval callback. */
+ 2, /* Number of targets used. */
{"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */
{DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY,
- DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */
+ DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* Flags. */
END_DVAR_TYPEDEF,
- BEGIN_DVAR_TYPEDEF(DVAR_TYPE_TRANSFORM_CHAN) dvar_eval_transChan, /* eval callback */
- 1, /* number of targets used */
+ BEGIN_DVAR_TYPEDEF(DVAR_TYPE_TRANSFORM_CHAN) dvar_eval_transChan, /* Eval callback. */
+ 1, /* Number of targets used. */
{"Object/Bone"}, /* UI names for targets */
- {DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* flags */
+ {DTAR_FLAG_STRUCT_REF | DTAR_FLAG_ID_OB_ONLY} /* Flags. */
END_DVAR_TYPEDEF,
};
/* Get driver variable typeinfo */
static const DriverVarTypeInfo *get_dvar_typeinfo(int type)
{
- /* check if valid type */
+ /* Check if valid type. */
if ((type >= 0) && (type < MAX_DVAR_TYPES)) {
return &dvar_types[type];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
-/* Driver API --------------------------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver API
+ * \{ */
/* Perform actual freeing driver variable and remove it from the given list */
void driver_free_variable(ListBase *variables, DriverVar *dvar)
{
- /* sanity checks */
+ /* Sanity checks. */
if (dvar == NULL) {
return;
}
- /* free target vars
+ /* Free target vars:
* - need to go over all of them, not just up to the ones that are used
* currently, since there may be some lingering RNA paths from
* previous users needing freeing
*/
DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
- /* free RNA path if applicable */
+ /* Free RNA path if applicable. */
if (dtar->rna_path) {
MEM_freeN(dtar->rna_path);
}
}
DRIVER_TARGETS_LOOPER_END;
- /* remove the variable from the driver */
+ /* Remove the variable from the driver. */
BLI_freelinkN(variables, dvar);
}
/* Free the driver variable and do extra updates */
void driver_free_variable_ex(ChannelDriver *driver, DriverVar *dvar)
{
- /* remove and free the driver variable */
+ /* Remove and free the driver variable. */
driver_free_variable(&driver->variables, dvar);
- /* since driver variables are cached, the expression needs re-compiling too */
+ /* Since driver variables are cached, the expression needs re-compiling too. */
BKE_driver_invalidate_expression(driver, false, true);
}
@@ -753,9 +762,9 @@ void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars)
BLI_duplicatelist(dst_vars, src_vars);
LISTBASE_FOREACH (DriverVar *, dvar, dst_vars) {
- /* need to go over all targets so that we don't leave any dangling paths */
+ /* 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 */
+ /* Make a copy of target's rna path if available. */
if (dtar->rna_path) {
dtar->rna_path = MEM_dupallocN(dtar->rna_path);
}
@@ -769,25 +778,24 @@ void driver_change_variable_type(DriverVar *dvar, int type)
{
const DriverVarTypeInfo *dvti = get_dvar_typeinfo(type);
- /* sanity check */
+ /* Sanity check. */
if (ELEM(NULL, dvar, dvti)) {
return;
}
- /* set the new settings */
+ /* Set the new settings. */
dvar->type = type;
dvar->num_targets = dvti->num_targets;
- /* make changes to the targets based on the defines for these types
- * NOTE: only need to make sure the ones we're using here are valid...
- */
+ /* Make changes to the targets based on the defines for these types.
+ * NOTE: only need to make sure the ones we're using here are valid. */
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
short flags = dvti->target_flags[tarIndex];
- /* store the flags */
+ /* Store the flags. */
dtar->flag = flags;
- /* object ID types only, or idtype not yet initialized */
+ /* Object ID types only, or idtype not yet initialized. */
if ((flags & DTAR_FLAG_ID_OB_ONLY) || (dtar->idtype == 0)) {
dtar->idtype = ID_OB;
}
@@ -804,12 +812,12 @@ void driver_variable_name_validate(DriverVar *dvar)
'?', ':', ';', '<', '>', '{', '}', '[', ']', '|', ' ', '.', '\t', '\n', '\r',
};
- /* sanity checks */
+ /* Sanity checks. */
if (dvar == NULL) {
return;
}
- /* clear all invalid-name flags */
+ /* Clear all invalid-name flags. */
dvar->flag &= ~DVAR_ALL_INVALID_FLAGS;
/* 0) Zero-length identifiers are not allowed */
@@ -870,16 +878,16 @@ DriverVar *driver_add_new_variable(ChannelDriver *driver)
{
DriverVar *dvar;
- /* sanity checks */
+ /* Sanity checks. */
if (driver == NULL) {
return NULL;
}
- /* make a new variable */
+ /* Make a new variable. */
dvar = MEM_callocN(sizeof(DriverVar), "DriverVar");
BLI_addtail(&driver->variables, dvar);
- /* give the variable a 'unique' name */
+ /* Give the variable a 'unique' name. */
strcpy(dvar->name, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "var"));
BLI_uniquename(&driver->variables,
dvar,
@@ -888,13 +896,13 @@ DriverVar *driver_add_new_variable(ChannelDriver *driver)
offsetof(DriverVar, name),
sizeof(dvar->name));
- /* set the default type to 'single prop' */
+ /* Set the default type to 'single prop'. */
driver_change_variable_type(dvar, DVAR_TYPE_SINGLE_PROP);
- /* since driver variables are cached, the expression needs re-compiling too */
+ /* Since driver variables are cached, the expression needs re-compiling too. */
BKE_driver_invalidate_expression(driver, false, true);
- /* return the target */
+ /* Return the target. */
return dvar;
}
@@ -904,20 +912,20 @@ void fcurve_free_driver(FCurve *fcu)
ChannelDriver *driver;
DriverVar *dvar, *dvarn;
- /* sanity checks */
+ /* Sanity checks. */
if (ELEM(NULL, fcu, fcu->driver)) {
return;
}
driver = fcu->driver;
- /* free driver targets */
+ /* Free driver targets. */
for (dvar = driver->variables.first; dvar; dvar = dvarn) {
dvarn = dvar->next;
driver_free_variable_ex(driver, dvar);
}
#ifdef WITH_PYTHON
- /* free compiled driver expression */
+ /* Free compiled driver expression. */
if (driver->expr_comp) {
BPY_DECREF(driver->expr_comp);
}
@@ -936,27 +944,31 @@ ChannelDriver *fcurve_copy_driver(const ChannelDriver *driver)
{
ChannelDriver *ndriver;
- /* sanity checks */
+ /* Sanity checks. */
if (driver == NULL) {
return NULL;
}
- /* copy all data */
+ /* Copy all data. */
ndriver = MEM_dupallocN(driver);
ndriver->expr_comp = NULL;
ndriver->expr_simple = NULL;
- /* copy variables */
+ /* Copy variables. */
- /* to get rid of refs to non-copied data (that's still used on original) */
+ /* To get rid of refs to non-copied data (that's still used on original). */
BLI_listbase_clear(&ndriver->variables);
driver_variables_copy(&ndriver->variables, &driver->variables);
- /* return the new driver */
+ /* Return the new driver. */
return ndriver;
}
-/* Driver Expression Evaluation --------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver Expression Evaluation
+ * \{ */
/* Index constants for the expression parameter array. */
enum {
@@ -1026,7 +1038,7 @@ static bool driver_evaluate_simple_expr(ChannelDriver *driver,
return true;
default:
- /* arriving here means a bug, not user error */
+ /* Arriving here means a bug, not user error. */
CLOG_ERROR(&LOG, "simple driver expression evaluation failed: '%s'", driver->expression);
return false;
}
@@ -1108,10 +1120,9 @@ bool BKE_driver_expression_depends_on_time(ChannelDriver *driver)
/* Simple expressions can be checked exactly. */
return driver_check_simple_expr_depends_on_time(driver->expr_simple);
}
- else {
- /* Otherwise, heuristically scan the expression string for certain patterns. */
- return python_driver_exression_depends_on_time(driver->expression);
- }
+
+ /* Otherwise, heuristically scan the expression string for certain patterns. */
+ return python_driver_exression_depends_on_time(driver->expression);
}
/* Reset cached compiled expression data */
@@ -1135,22 +1146,25 @@ void BKE_driver_invalidate_expression(ChannelDriver *driver,
#endif
}
-/* Driver Evaluation -------------------------- */
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Driver Evaluation
+ * \{ */
/* Evaluate a Driver Variable to get a value that contributes to the final */
float driver_get_variable_value(ChannelDriver *driver, DriverVar *dvar)
{
const DriverVarTypeInfo *dvti;
- /* sanity check */
+ /* Sanity check. */
if (ELEM(NULL, driver, dvar)) {
return 0.0f;
}
- /* call the relevant callbacks to get the variable value
+ /* Call the relevant callbacks to get the variable value
* using the variable type info, storing the obtained value
- * in dvar->curval so that drivers can be debugged
- */
+ * in `dvar->curval` so that drivers can be debugged. */
dvti = get_dvar_typeinfo(dvar->type);
if (dvti && dvti->get_value) {
@@ -1167,25 +1181,25 @@ static void evaluate_driver_sum(ChannelDriver *driver)
{
DriverVar *dvar;
- /* check how many variables there are first (i.e. just one?) */
+ /* Check how many variables there are first (i.e. just one?). */
if (BLI_listbase_is_single(&driver->variables)) {
- /* just one target, so just use that */
+ /* Just one target, so just use that. */
dvar = driver->variables.first;
driver->curval = driver_get_variable_value(driver, dvar);
return;
}
- /* more than one target, so average the values of the targets */
+ /* More than one target, so average the values of the targets. */
float value = 0.0f;
int tot = 0;
- /* loop through targets, adding (hopefully we don't get any overflow!) */
+ /* Loop through targets, adding (hopefully we don't get any overflow!). */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
value += driver_get_variable_value(driver, dvar);
tot++;
}
- /* perform operations on the total if appropriate */
+ /* Perform operations on the total if appropriate. */
if (driver->type == DRIVER_TYPE_AVERAGE) {
driver->curval = tot ? (value / (float)tot) : 0.0f;
}
@@ -1199,34 +1213,34 @@ static void evaluate_driver_min_max(ChannelDriver *driver)
DriverVar *dvar;
float value = 0.0f;
- /* loop through the variables, getting the values and comparing them to existing ones */
+ /* Loop through the variables, getting the values and comparing them to existing ones. */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
- /* get value */
+ /* Get value. */
float tmp_val = driver_get_variable_value(driver, dvar);
- /* store this value if appropriate */
+ /* Store this value if appropriate. */
if (dvar->prev) {
- /* check if greater/smaller than the baseline */
+ /* Check if greater/smaller than the baseline. */
if (driver->type == DRIVER_TYPE_MAX) {
- /* max? */
+ /* Max? */
if (tmp_val > value) {
value = tmp_val;
}
}
else {
- /* min? */
+ /* Min? */
if (tmp_val < value) {
value = tmp_val;
}
}
}
else {
- /* first item - make this the baseline for comparisons */
+ /* First item - make this the baseline for comparisons. */
value = tmp_val;
}
}
- /* store value in driver */
+ /* Store value in driver. */
driver->curval = value;
}
@@ -1235,62 +1249,63 @@ static void evaluate_driver_python(PathResolvedRNA *anim_rna,
ChannelDriver *driver_orig,
const AnimationEvalContext *anim_eval_context)
{
- /* check for empty or invalid expression */
+ /* Check for empty or invalid expression. */
if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) {
driver->curval = 0.0f;
}
else if (!driver_try_evaluate_simple_expr(
driver, driver_orig, &driver->curval, anim_eval_context->eval_time)) {
#ifdef WITH_PYTHON
- /* this evaluates the expression using Python, and returns its result:
- * - on errors it reports, then returns 0.0f
- */
+ /* This evaluates the expression using Python, and returns its result:
+ * - on errors it reports, then returns 0.0f. */
BLI_mutex_lock(&python_driver_lock);
driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, anim_eval_context);
BLI_mutex_unlock(&python_driver_lock);
-#else /* WITH_PYTHON*/
+#else /* WITH_PYTHON */
UNUSED_VARS(anim_rna, anim_eval_context);
-#endif /* WITH_PYTHON*/
+#endif /* WITH_PYTHON */
}
}
-/* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime"
- * - "evaltime" is the frame at which F-Curve is being evaluated
- * - has to return a float value
- * - driver_orig is where we cache Python expressions, in case of COW
+/**
+ * Evaluate an Channel-Driver to get a 'time' value to use
+ * instead of `anim_eval_context->eval_time`.
+ *
+ * - `anim_eval_context->eval_time` is the frame at which F-Curve is being evaluated.
+ * - Has to return a float value.
+ * - \a driver_orig is where we cache Python expressions, in case of COW
*/
float evaluate_driver(PathResolvedRNA *anim_rna,
ChannelDriver *driver,
ChannelDriver *driver_orig,
const AnimationEvalContext *anim_eval_context)
{
- /* check if driver can be evaluated */
+ /* Check if driver can be evaluated. */
if (driver_orig->flag & DRIVER_FLAG_INVALID) {
return 0.0f;
}
switch (driver->type) {
- case DRIVER_TYPE_AVERAGE: /* average values of driver targets */
- case DRIVER_TYPE_SUM: /* sum values of driver targets */
+ case DRIVER_TYPE_AVERAGE: /* Average values of driver targets. */
+ case DRIVER_TYPE_SUM: /* Sum values of driver targets. */
evaluate_driver_sum(driver);
break;
- case DRIVER_TYPE_MIN: /* smallest value */
- case DRIVER_TYPE_MAX: /* largest value */
+ case DRIVER_TYPE_MIN: /* Smallest value. */
+ case DRIVER_TYPE_MAX: /* Largest value. */
evaluate_driver_min_max(driver);
break;
- case DRIVER_TYPE_PYTHON: /* expression */
+ case DRIVER_TYPE_PYTHON: /* Expression. */
evaluate_driver_python(anim_rna, driver, driver_orig, anim_eval_context);
break;
default:
- /* special 'hack' - just use stored value
+ /* Special 'hack' - just use stored value
* This is currently used as the mechanism which allows animated settings to be able
- * to be changed via the UI.
- */
+ * to be changed via the UI. */
break;
}
- /* return value for driver */
+ /* Return value for driver. */
return driver->curval;
}
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 079b436a3ea..ee7d85ba3fb 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -533,14 +533,14 @@ static bool BKE_fluid_modifier_init(
/* Allocate fluid. */
return BKE_fluid_reallocate_fluid(fds, fds->res, 0);
}
- else if (fmd->type & MOD_FLUID_TYPE_FLOW) {
+ if (fmd->type & MOD_FLUID_TYPE_FLOW) {
if (!fmd->flow) {
BKE_fluid_modifier_create_type_data(fmd);
}
fmd->time = scene_framenr;
return true;
}
- else if (fmd->type & MOD_FLUID_TYPE_EFFEC) {
+ if (fmd->type & MOD_FLUID_TYPE_EFFEC) {
if (!fmd->effector) {
BKE_fluid_modifier_create_type_data(fmd);
}
@@ -575,7 +575,7 @@ static int get_light(ViewLayer *view_layer, float *light)
copy_v3_v3(light, base_tmp->object->obmat[3]);
return 1;
}
- else if (!found_light) {
+ if (!found_light) {
copy_v3_v3(light, base_tmp->object->obmat[3]);
found_light = 1;
}
@@ -655,7 +655,7 @@ typedef struct FluidObjectBB {
int total_cells, valid;
} FluidObjectBB;
-static void bb_boundInsert(FluidObjectBB *bb, float point[3])
+static void bb_boundInsert(FluidObjectBB *bb, const float point[3])
{
int i = 0;
if (!bb->valid) {
@@ -695,7 +695,7 @@ static void bb_allocateData(FluidObjectBB *bb, bool use_velocity, bool use_influ
bb->influence = MEM_calloc_arrayN(bb->total_cells, sizeof(float), "fluid_bb_influence");
}
if (use_velocity) {
- bb->velocity = MEM_calloc_arrayN(bb->total_cells * 3, sizeof(float), "fluid_bb_velocity");
+ bb->velocity = MEM_calloc_arrayN(bb->total_cells, sizeof(float[3]), "fluid_bb_velocity");
}
bb->distances = MEM_malloc_arrayN(bb->total_cells, sizeof(float), "fluid_bb_distances");
@@ -955,7 +955,7 @@ static void obstacles_from_mesh_task_cb(void *__restrict userdata,
for (int y = data->min[1]; y < data->max[1]; y++) {
const int index = manta_get_index(
x - bb->min[0], bb->res[0], y - bb->min[1], bb->res[1], z - bb->min[2]);
- float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f};
+ const float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f};
/* Calculate object velocities. Result in bb->velocity. */
sample_effector(data->fes,
@@ -1021,14 +1021,14 @@ static void obstacles_from_mesh(Object *coll_ob,
/* TODO (sebbas): Make initialization of vertex velocities optional? */
{
- vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "manta_obs_velocity");
+ vert_vel = MEM_callocN(sizeof(float[3]) * numverts, "manta_obs_velocity");
if (fes->numverts != numverts || !fes->verts_old) {
if (fes->verts_old) {
MEM_freeN(fes->verts_old);
}
- fes->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "manta_obs_verts_old");
+ fes->verts_old = MEM_callocN(sizeof(float[3]) * numverts, "manta_obs_verts_old");
fes->numverts = numverts;
}
else {
@@ -1119,6 +1119,7 @@ static void ensure_obstaclefields(FluidDomainSettings *fds)
if (fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE) {
manta_ensure_guiding(fds->fluid, fds->fmd);
}
+ manta_update_pointers(fds->fluid, fds->fmd, false);
}
static void update_obstacleflags(FluidDomainSettings *fds,
@@ -1577,9 +1578,9 @@ static void emit_from_particles(Object *flow_ob,
totchild = psys->totchild * psys->part->disp / 100;
}
- particle_pos = MEM_callocN(sizeof(float) * (totpart + totchild) * 3,
+ particle_pos = MEM_callocN(sizeof(float[3]) * (totpart + totchild),
"manta_flow_particles_pos");
- particle_vel = MEM_callocN(sizeof(float) * (totpart + totchild) * 3,
+ particle_vel = MEM_callocN(sizeof(float[3]) * (totpart + totchild),
"manta_flow_particles_vel");
/* setup particle radius emission if enabled */
@@ -1756,14 +1757,13 @@ static void update_distances(int index,
{0.0f, -1.0f, 1.0f}, {0.0f, -1.0f, -1.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
{-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f},
{-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}};
- size_t ray_cnt = sizeof ray_dirs / sizeof ray_dirs[0];
/* Count ray mesh misses (i.e. no face hit) and cases where the ray direction matches the face
* normal direction. From this information it can be derived whether a cell is inside or
* outside the mesh. */
int miss_cnt = 0, dir_cnt = 0;
- for (int i = 0; i < ray_cnt; i++) {
+ for (int i = 0; i < ARRAY_SIZE(ray_dirs); i++) {
BVHTreeRayHit hit_tree = {0};
hit_tree.index = -1;
hit_tree.dist = PHI_MAX;
@@ -1797,7 +1797,7 @@ static void update_distances(int index,
/* Point lies inside mesh. Use negative sign for distance value.
* This "if statement" has 2 conditions that can be true for points outside mesh. */
- if (!(miss_cnt > 0 || dir_cnt == ray_cnt)) {
+ if (!(miss_cnt > 0 || dir_cnt == ARRAY_SIZE(ray_dirs))) {
min_dist = (-1.0f) * fabsf(min_dist);
}
@@ -2100,13 +2100,13 @@ static void emit_from_mesh(
mloopuv = CustomData_get_layer_named(&me->ldata, CD_MLOOPUV, ffs->uvlayer_name);
if (ffs->flags & FLUID_FLOW_INITVELOCITY) {
- vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "manta_flow_velocity");
+ vert_vel = MEM_callocN(sizeof(float[3]) * numverts, "manta_flow_velocity");
if (ffs->numverts != numverts || !ffs->verts_old) {
if (ffs->verts_old) {
MEM_freeN(ffs->verts_old);
}
- ffs->verts_old = MEM_callocN(sizeof(float) * numverts * 3, "manta_flow_verts_old");
+ ffs->verts_old = MEM_callocN(sizeof(float[3]) * numverts, "manta_flow_verts_old");
ffs->numverts = numverts;
}
else {
@@ -2596,7 +2596,7 @@ static void ensure_flowsfields(FluidDomainSettings *fds)
manta_smoke_ensure_fire(fds->fluid, fds->fmd);
}
if (fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) {
- /* initialize all smoke with "active_color" */
+ /* Initialize all smoke with "active_color". */
manta_smoke_ensure_colors(fds->fluid, fds->fmd);
}
if (fds->type == FLUID_DOMAIN_TYPE_LIQUID &&
@@ -2605,6 +2605,7 @@ static void ensure_flowsfields(FluidDomainSettings *fds)
fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER)) {
manta_liquid_ensure_sndparts(fds->fluid, fds->fmd);
}
+ manta_update_pointers(fds->fluid, fds->fmd, false);
}
static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int numflowobj)
@@ -2617,7 +2618,7 @@ static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int n
FLUID_DOMAIN_ACTIVE_HEAT | FLUID_DOMAIN_ACTIVE_FIRE);
active_fields &= ~prev_flags;
- /* Monitor active fields based on flow settings */
+ /* Monitor active fields based on flow settings. */
for (flow_index = 0; flow_index < numflowobj; flow_index++) {
Object *flow_ob = flowobjs[flow_index];
FluidModifierData *fmd2 = (FluidModifierData *)BKE_modifiers_findby_type(flow_ob,
@@ -2628,6 +2629,7 @@ static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int n
continue;
}
+ /* Activate specific grids if at least one flow object requires this grid. */
if ((fmd2->type & MOD_FLUID_TYPE_FLOW) && fmd2->flow) {
FluidFlowSettings *ffs = fmd2->flow;
if (!ffs) {
@@ -2648,17 +2650,17 @@ static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int n
continue;
}
- /* activate heat field if flow produces any heat */
- if (ffs->temperature) {
+ /* Activate heat field if a flow object produces any heat. */
+ if (ffs->temperature != 0.0) {
active_fields |= FLUID_DOMAIN_ACTIVE_HEAT;
}
- /* activate fuel field if flow adds any fuel */
- if (ffs->fuel_amount &&
- (ffs->type == FLUID_FLOW_TYPE_FIRE || ffs->type == FLUID_FLOW_TYPE_SMOKEFIRE)) {
+ /* Activate fuel field if a flow object is of fire type. */
+ if (ffs->fuel_amount != 0.0 || ffs->type == FLUID_FLOW_TYPE_FIRE ||
+ ffs->type == FLUID_FLOW_TYPE_SMOKEFIRE) {
active_fields |= FLUID_DOMAIN_ACTIVE_FIRE;
}
- /* activate color field if flows add smoke with varying colors */
- if (ffs->density &&
+ /* Activate color field if flows add smoke with varying colors. */
+ if (ffs->density != 0.0 &&
(ffs->type == FLUID_FLOW_TYPE_SMOKE || ffs->type == FLUID_FLOW_TYPE_SMOKEFIRE)) {
if (!(active_fields & FLUID_DOMAIN_ACTIVE_COLOR_SET)) {
copy_v3_v3(fds->active_color, ffs->color);
@@ -2671,11 +2673,11 @@ static void update_flowsflags(FluidDomainSettings *fds, Object **flowobjs, int n
}
}
}
- /* Monitor active fields based on domain settings */
+ /* Monitor active fields based on domain settings. */
if (fds->type == FLUID_DOMAIN_TYPE_GAS && active_fields & FLUID_DOMAIN_ACTIVE_FIRE) {
- /* heat is always needed for fire */
+ /* Heat is always needed for fire. */
active_fields |= FLUID_DOMAIN_ACTIVE_HEAT;
- /* also activate colors if domain smoke color differs from active color */
+ /* Also activate colors if domain smoke color differs from active color. */
if (!(active_fields & FLUID_DOMAIN_ACTIVE_COLOR_SET)) {
copy_v3_v3(fds->active_color, fds->flame_smoke_color);
active_fields |= FLUID_DOMAIN_ACTIVE_COLOR_SET;
@@ -2924,8 +2926,21 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
float *velx_initial = manta_get_in_velocity_x(fds->fluid);
float *vely_initial = manta_get_in_velocity_y(fds->fluid);
float *velz_initial = manta_get_in_velocity_z(fds->fluid);
- uint z;
+ float *forcex = manta_get_force_x(fds->fluid);
+ float *forcey = manta_get_force_y(fds->fluid);
+ float *forcez = manta_get_force_z(fds->fluid);
+
+ BLI_assert(forcex && forcey && forcez);
+
+ /* Either all or no components have to exist. */
+ BLI_assert((color_r && color_g && color_b) || (!color_r && !color_g && !color_b));
+ BLI_assert((color_r_in && color_g_in && color_b_in) ||
+ (!color_r_in && !color_g_in && !color_b_in));
+ BLI_assert((velx_initial && vely_initial && velz_initial) ||
+ (!velx_initial && !vely_initial && !velz_initial));
+
+ uint z;
/* Grid reset before writing again. */
for (z = 0; z < fds->res[0] * fds->res[1] * fds->res[2]; z++) {
/* Only reset static phi on first frame, dynamic phi gets reset every time. */
@@ -2949,7 +2964,7 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
if (heat_in) {
heat_in[z] = heat[z];
}
- if (color_r_in) {
+ if (color_r_in && color_g_in && color_b_in) {
color_r_in[z] = color_r[z];
color_g_in[z] = color_b[z];
color_b_in[z] = color_g[z];
@@ -2961,11 +2976,15 @@ static void update_flowsfluids(struct Depsgraph *depsgraph,
if (emission_in) {
emission_in[z] = 0.0f;
}
- if (velx_initial) {
+ if (velx_initial && vely_initial && velz_initial) {
velx_initial[z] = 0.0f;
vely_initial[z] = 0.0f;
velz_initial[z] = 0.0f;
}
+ /* Reset forces here as update_effectors() is skipped when no external forces are present. */
+ forcex[z] = 0.0f;
+ forcey[z] = 0.0f;
+ forcez[z] = 0.0f;
}
/* Apply emission data for every flow object. */
@@ -3149,13 +3168,13 @@ static void update_effectors_task_cb(void *__restrict userdata,
continue;
}
- /* get velocities from manta grid space and convert to blender units */
+ /* Get velocities from manta grid space and convert to blender units. */
vel[0] = data->velocity_x[index];
vel[1] = data->velocity_y[index];
vel[2] = data->velocity_z[index];
mul_v3_fl(vel, fds->dx);
- /* convert vel to global space */
+ /* Convert vel to global space. */
mag = len_v3(vel);
mul_mat3_m4_v3(fds->obmat, vel);
normalize_v3(vel);
@@ -3166,18 +3185,18 @@ static void update_effectors_task_cb(void *__restrict userdata,
voxel_center[2] = fds->p0[2] + fds->cell_size[2] * ((float)(z + fds->res_min[2]) + 0.5f);
mul_m4_v3(fds->obmat, voxel_center);
- /* do effectors */
+ /* Do effectors. */
pd_point_from_loc(data->scene, voxel_center, vel, index, &epoint);
BKE_effectors_apply(
data->effectors, NULL, fds->effector_weights, &epoint, retvel, NULL, NULL);
- /* convert retvel to local space */
+ /* Convert retvel to local space. */
mag = len_v3(retvel);
mul_mat3_m4_v3(fds->imat, retvel);
normalize_v3(retvel);
mul_v3_fl(retvel, mag);
- /* constrain forces to interval -1 to 1 */
+ /* Constrain forces to interval -1 to 1. */
data->force_x[index] = min_ff(max_ff(-1.0f, retvel[0] * 0.2f), 1.0f);
data->force_y[index] = min_ff(max_ff(-1.0f, retvel[1] * 0.2f), 1.0f);
data->force_z[index] = min_ff(max_ff(-1.0f, retvel[2] * 0.2f), 1.0f);
@@ -3311,7 +3330,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obj
co_offset[2] = (fds->p0[2] + fds->p1[2]) / 2.0f;
/* Normals. */
- normals = MEM_callocN(sizeof(short) * num_normals * 3, "Fluidmesh_tmp_normals");
+ normals = MEM_callocN(sizeof(short[3]) * num_normals, "Fluidmesh_tmp_normals");
/* Loop for vertices and normals. */
for (i = 0, no_s = normals; i < num_verts && i < num_normals; i++, mverts++, no_s += 3) {
@@ -3617,14 +3636,16 @@ static int manta_step(
fds->time_per_frame = time_per_frame;
fds->time_total = time_total;
}
+
/* Total time must not exceed framecount times framelength. Correct tiny errors here. */
CLAMP(fds->time_total, fds->time_total, time_total_old + fds->frame_length);
+ /* Compute shadow grid for gas simulations. Make sure to skip if bake job was canceled early. */
if (fds->type == FLUID_DOMAIN_TYPE_GAS && result) {
manta_smoke_calc_transparency(fds, DEG_get_evaluated_view_layer(depsgraph));
}
- BLI_mutex_unlock(&object_update_lock);
+ BLI_mutex_unlock(&object_update_lock);
return result;
}
@@ -3716,29 +3737,35 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
int mode = fds->cache_type;
/* Do not process modifier if current frame is out of cache range. */
+ bool escape = false;
switch (mode) {
case FLUID_DOMAIN_CACHE_ALL:
case FLUID_DOMAIN_CACHE_MODULAR:
if (fds->cache_frame_offset > 0) {
if (scene_framenr < fds->cache_frame_start ||
scene_framenr > fds->cache_frame_end + fds->cache_frame_offset) {
- return;
+ escape = true;
}
}
else {
if (scene_framenr < fds->cache_frame_start + fds->cache_frame_offset ||
scene_framenr > fds->cache_frame_end) {
- return;
+ escape = true;
}
}
break;
case FLUID_DOMAIN_CACHE_REPLAY:
default:
if (scene_framenr < fds->cache_frame_start || scene_framenr > fds->cache_frame_end) {
- return;
+ escape = true;
}
break;
}
+ /* If modifier will not be processed, update/flush pointers from (old) fluid object once more. */
+ if (escape && fds->fluid) {
+ manta_update_pointers(fds->fluid, fmd, true);
+ return;
+ }
/* Reset fluid if no fluid present. Also resets active fields. */
if (!fds->fluid) {
@@ -3830,7 +3857,15 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
has_mesh = manta_has_mesh(fds->fluid, fmd, scene_framenr);
has_particles = manta_has_particles(fds->fluid, fmd, scene_framenr);
has_guide = manta_has_guiding(fds->fluid, fmd, scene_framenr, guide_parent);
- has_config = false;
+ has_config = manta_read_config(fds->fluid, fmd, scene_framenr);
+
+ /* When reading data from cache (has_config == true) ensure that active fields are allocated.
+ * update_flowsflags() and update_obstacleflags() will not find flow sources hidden from renders.
+ * See also: T72192. */
+ if (has_config) {
+ ensure_flowsfields(fds);
+ ensure_obstaclefields(fds);
+ }
bool baking_data, baking_noise, baking_mesh, baking_particles, baking_guide;
baking_data = fds->cache_flag & FLUID_DOMAIN_BAKING_DATA;
@@ -3947,7 +3982,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
/* Read mesh cache. */
if (with_liquid && with_mesh) {
- has_config = manta_read_config(fds->fluid, fmd, mesh_frame);
+ if (mesh_frame != scene_framenr) {
+ has_config = manta_read_config(fds->fluid, fmd, mesh_frame);
+ }
/* Update mesh data from file is faster than via Python (manta_read_mesh()). */
has_mesh = manta_read_mesh(fds->fluid, fmd, mesh_frame);
@@ -3955,7 +3992,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
/* Read particles cache. */
if (with_liquid && with_particles) {
- has_config = manta_read_config(fds->fluid, fmd, particles_frame);
+ if (particles_frame != scene_framenr) {
+ has_config = manta_read_config(fds->fluid, fmd, particles_frame);
+ }
read_partial = !baking_data && !baking_particles && next_particles;
read_all = !read_partial && with_resumable_cache;
@@ -3970,7 +4009,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
/* Read noise and data cache */
if (with_smoke && with_noise) {
- has_config = manta_read_config(fds->fluid, fmd, noise_frame);
+ if (noise_frame != scene_framenr) {
+ has_config = manta_read_config(fds->fluid, fmd, noise_frame);
+ }
/* Only reallocate when just reading cache or when resuming during bake. */
if (has_data && has_config && manta_needs_realloc(fds->fluid, fmd)) {
@@ -3988,7 +4029,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
}
/* Read data cache only */
else {
- has_config = manta_read_config(fds->fluid, fmd, data_frame);
+ if (data_frame != scene_framenr) {
+ has_config = manta_read_config(fds->fluid, fmd, data_frame);
+ }
if (with_smoke) {
/* Read config and realloc fluid object if needed. */
@@ -4073,6 +4116,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
}
}
+ /* Ensure that fluid pointers are always up to date at the end of modifier processing. */
+ manta_update_pointers(fds->fluid, fmd, false);
+
fds->flags &= ~FLUID_DOMAIN_FILE_LOAD;
fmd->time = scene_framenr;
}
diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index c85283e3653..c973b681fe7 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -285,9 +285,8 @@ static double sinc(double x)
if (fabs(x) < 0.0001) {
return 1.0;
}
- else {
- return sin(M_PI * x) / (M_PI * x);
- }
+
+ return sin(M_PI * x) / (M_PI * x);
}
static void fcm_fn_generator_evaluate(
@@ -525,29 +524,28 @@ int BKE_fcm_envelope_find_index(FCM_EnvelopeData array[],
CLOG_WARN(&LOG, "encountered invalid array");
return 0;
}
- else {
- /* check whether to add before/after/on */
- float framenum;
- /* 'First' Point (when only one point, this case is used) */
- framenum = array[0].time;
- if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
- *r_exists = true;
- return 0;
- }
- else if (frame < framenum) {
- return 0;
- }
+ /* check whether to add before/after/on */
+ float framenum;
- /* 'Last' Point */
- framenum = array[(arraylen - 1)].time;
- if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
- *r_exists = true;
- return (arraylen - 1);
- }
- else if (frame > framenum) {
- return arraylen;
- }
+ /* 'First' Point (when only one point, this case is used) */
+ framenum = array[0].time;
+ if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
+ *r_exists = true;
+ return 0;
+ }
+ if (frame < framenum) {
+ return 0;
+ }
+
+ /* 'Last' Point */
+ framenum = array[(arraylen - 1)].time;
+ if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
+ *r_exists = true;
+ return (arraylen - 1);
+ }
+ if (frame > framenum) {
+ return arraylen;
}
/* most of the time, this loop is just to find where to put it
@@ -1076,9 +1074,8 @@ const FModifierTypeInfo *get_fmodifier_typeinfo(const int type)
/* there shouldn't be any segfaults here... */
return fmodifiersTypeInfo[type];
}
- else {
- CLOG_ERROR(&LOG, "No valid F-Curve Modifier type-info data available. Type = %i", type);
- }
+
+ CLOG_ERROR(&LOG, "No valid F-Curve Modifier type-info data available. Type = %i", type);
return NULL;
}
@@ -1092,9 +1089,8 @@ const FModifierTypeInfo *fmodifier_get_typeinfo(const FModifier *fcm)
if (fcm) {
return get_fmodifier_typeinfo(fcm->type);
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/* API --------------------------- */
@@ -1239,12 +1235,11 @@ bool remove_fmodifier(ListBase *modifiers, FModifier *fcm)
return true;
}
- else {
- /* XXX this case can probably be removed some day, as it shouldn't happen... */
- CLOG_STR_ERROR(&LOG, "no modifier stack given");
- MEM_freeN(fcm);
- return false;
- }
+
+ /* XXX this case can probably be removed some day, as it shouldn't happen... */
+ CLOG_STR_ERROR(&LOG, "no modifier stack given");
+ MEM_freeN(fcm);
+ return false;
}
/* Remove all of a given F-Curve's modifiers */
@@ -1397,13 +1392,13 @@ static float eval_fmodifier_influence(FModifier *fcm, float evaltime)
/* out of range */
return 0.0f;
}
- else if ((evaltime > fcm->sfra) && (evaltime < fcm->sfra + fcm->blendin)) {
+ if ((evaltime > fcm->sfra) && (evaltime < fcm->sfra + fcm->blendin)) {
/* blend in range */
float a = fcm->sfra;
float b = fcm->sfra + fcm->blendin;
return influence * (evaltime - a) / (b - a);
}
- else if ((evaltime < fcm->efra) && (evaltime > fcm->efra - fcm->blendout)) {
+ if ((evaltime < fcm->efra) && (evaltime > fcm->efra - fcm->blendout)) {
/* blend out range */
float a = fcm->efra;
float b = fcm->efra - fcm->blendout;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index dfa5ff6975f..4bedba8f76b 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -193,13 +193,12 @@ static PackedFile *get_builtin_packedfile(void)
return NULL;
}
- else {
- void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin");
- memcpy(mem, builtin_font_data, builtin_font_size);
+ void *mem = MEM_mallocN(builtin_font_size, "vfd_builtin");
- return BKE_packedfile_new_from_memory(mem, builtin_font_size);
- }
+ memcpy(mem, builtin_font_data, builtin_font_size);
+
+ return BKE_packedfile_new_from_memory(mem, builtin_font_size);
}
static VFontData *vfont_get_data(VFont *vfont)
@@ -621,12 +620,11 @@ int BKE_vfont_select_get(Object *ob, int *r_start, int *r_end)
if (start == end + 1) {
return 0;
}
- else {
- BLI_assert(start < end + 1);
- *r_start = start;
- *r_end = end;
- return direction;
- }
+
+ BLI_assert(start < end + 1);
+ *r_start = start;
+ *r_end = end;
+ return direction;
}
void BKE_vfont_select_clamp(Object *ob)
@@ -647,12 +645,11 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info)
if (che == NULL) {
return 0.0f;
}
- else if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) {
+ if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) {
return che->width * cu->smallcaps_scale;
}
- else {
- return che->width;
- }
+
+ return che->width;
}
static void textbox_scale(TextBox *tb_dst, const TextBox *tb_src, float scale)
@@ -797,7 +794,7 @@ static bool vfont_to_curve(Object *ob,
}
else {
char32_t *mem_tmp;
- slen = cu->len_wchar;
+ slen = cu->len_char32;
/* Create unicode string */
mem_tmp = MEM_malloc_arrayN((slen + 1), sizeof(*mem_tmp), "convertedmem");
@@ -1603,32 +1600,32 @@ static bool vfont_to_curve(Object *ob,
}
return true;
}
+
+ ok = true;
+finally:
+ if (r_text) {
+ *r_text = mem;
+ *r_text_len = slen;
+ *r_text_free = (ef == NULL);
+ }
else {
- ok = true;
- finally:
- if (r_text) {
- *r_text = mem;
- *r_text_len = slen;
- *r_text_free = (ef == NULL);
+ if (ef == NULL) {
+ MEM_freeN((void *)mem);
+ }
+ }
+
+ if (chartransdata) {
+ if (ok && r_chartransdata) {
+ *r_chartransdata = chartransdata;
}
else {
- if (ef == NULL) {
- MEM_freeN((void *)mem);
- }
+ MEM_freeN(chartransdata);
}
+ }
- if (chartransdata) {
- if (ok && r_chartransdata) {
- *r_chartransdata = chartransdata;
- }
- else {
- MEM_freeN(chartransdata);
- }
- }
+ /* Store the effective scale, to use for the textbox lines. */
+ cu->fsize_realtime = font_size;
- /* Store the effective scale, to use for the textbox lines. */
- cu->fsize_realtime = font_size;
- }
return ok;
#undef MARGIN_X_MIN
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index eeb55c44d6e..09305434289 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -381,7 +381,7 @@ bGPDframe *BKE_gpencil_frame_addcopy(bGPDlayer *gpl, int cframe)
/* no layer */
return NULL;
}
- else if (gpl->actframe == NULL) {
+ if (gpl->actframe == NULL) {
/* no active frame, so just create a new one from scratch */
return BKE_gpencil_frame_addnew(gpl, cframe);
}
@@ -398,7 +398,7 @@ bGPDframe *BKE_gpencil_frame_addcopy(bGPDlayer *gpl, int cframe)
found = true;
break;
}
- else if (gpf->framenum == cframe) {
+ if (gpf->framenum == cframe) {
/* This only happens when we're editing with framelock on...
* - Delete the new frame and don't do anything else here...
*/
@@ -1009,7 +1009,7 @@ bGPDframe *BKE_gpencil_layer_frame_get(bGPDlayer *gpl, int cframe, eGP_GetFrame_
found = true;
break;
}
- else if ((gpf->next) && (gpf->next->framenum > cframe)) {
+ if ((gpf->next) && (gpf->next->framenum > cframe)) {
found = true;
break;
}
@@ -1484,10 +1484,9 @@ Material *BKE_gpencil_object_material_ensure_from_brush(Main *bmain, Object *ob,
return ma;
}
- else {
- /* using active material instead */
- return BKE_object_material_get(ob, ob->actcol);
- }
+
+ /* using active material instead */
+ return BKE_object_material_get(ob, ob->actcol);
}
/**
@@ -1546,9 +1545,8 @@ Material *BKE_gpencil_object_material_from_brush_get(Object *ob, Brush *brush)
Material *ma = BKE_gpencil_brush_material_get(brush);
return ma;
}
- else {
- return BKE_object_material_get(ob, ob->actcol);
- }
+
+ return BKE_object_material_get(ob, ob->actcol);
}
/**
@@ -1562,9 +1560,8 @@ int BKE_gpencil_object_material_get_index_from_brush(Object *ob, Brush *brush)
if ((brush) && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) {
return BKE_gpencil_object_material_index_get(ob, brush->gpencil_settings->material);
}
- else {
- return ob->actcol - 1;
- }
+
+ return ob->actcol - 1;
}
/**
@@ -1581,9 +1578,8 @@ Material *BKE_gpencil_object_material_ensure_from_active_input_toolsettings(Main
return BKE_gpencil_object_material_ensure_from_active_input_brush(
bmain, ob, ts->gp_paint->paint.brush);
}
- else {
- return BKE_gpencil_object_material_ensure_from_active_input_brush(bmain, ob, NULL);
- }
+
+ return BKE_gpencil_object_material_ensure_from_active_input_brush(bmain, ob, NULL);
}
/**
@@ -1602,7 +1598,7 @@ Material *BKE_gpencil_object_material_ensure_from_active_input_brush(Main *bmain
if (ma) {
return ma;
}
- else if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
+ if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
/* it is easier to just unpin a NULL material, instead of setting a new one */
brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED;
}
@@ -1883,6 +1879,7 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
Material *ma_secondary = NULL;
MaterialGPencilStyle *gp_style_primary = NULL;
MaterialGPencilStyle *gp_style_secondary = NULL;
+ GHash *mat_used = BLI_ghash_int_new(__func__);
short *totcol = BKE_object_material_len_p(ob);
if (totcol == 0) {
@@ -1895,8 +1892,15 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
if (ma_primary == NULL) {
continue;
}
+ for (int idx_secondary = 0; idx_secondary < *totcol; idx_secondary++) {
+ if ((idx_secondary == idx_primary) ||
+ BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) {
+ continue;
+ }
+ if (BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_secondary))) {
+ continue;
+ }
- for (int idx_secondary = idx_primary + 1; idx_secondary < *totcol; idx_secondary++) {
/* Read secondary material to compare with primary material. */
ma_secondary = BKE_gpencil_material(ob, idx_secondary + 1);
if ((ma_secondary == NULL) ||
@@ -1934,6 +1938,11 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
}
float s_hsv_a[3], s_hsv_b[3], f_hsv_a[3], f_hsv_b[3], col[3];
+ zero_v3(s_hsv_a);
+ zero_v3(s_hsv_b);
+ zero_v3(f_hsv_a);
+ zero_v3(f_hsv_b);
+
copy_v3_v3(col, gp_style_primary->stroke_rgba);
rgb_to_hsv_compat_v(col, s_hsv_a);
copy_v3_v3(col, gp_style_secondary->stroke_rgba);
@@ -1944,24 +1953,102 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
copy_v3_v3(col, gp_style_secondary->fill_rgba);
rgb_to_hsv_compat_v(col, f_hsv_b);
- /* Check stroke and fill color (only Hue and Saturation). */
+ /* Check stroke and fill color. */
if ((!compare_ff(s_hsv_a[0], s_hsv_b[0], hue_threshold)) ||
(!compare_ff(s_hsv_a[1], s_hsv_b[1], sat_threshold)) ||
+ (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) ||
(!compare_ff(f_hsv_a[0], f_hsv_b[0], hue_threshold)) ||
(!compare_ff(f_hsv_a[1], f_hsv_b[1], sat_threshold)) ||
- (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) ||
- (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) ||
- (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) ||
- (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold))) {
+ (!compare_ff(f_hsv_a[2], f_hsv_b[2], val_threshold)) ||
+ (!compare_ff(gp_style_primary->stroke_rgba[3],
+ gp_style_secondary->stroke_rgba[3],
+ val_threshold)) ||
+ (!compare_ff(
+ gp_style_primary->fill_rgba[3], gp_style_secondary->fill_rgba[3], val_threshold))) {
continue;
}
/* Save conversion indexes. */
- BLI_ghash_insert(
- r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary));
- changed = true;
+ if (!BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) {
+ BLI_ghash_insert(
+ r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary));
+ changed = true;
+
+ if (!BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_primary))) {
+ BLI_ghash_insert(mat_used, POINTER_FROM_INT(idx_primary), POINTER_FROM_INT(idx_primary));
+ }
+ }
}
}
+ /* Free hash memory. */
+ BLI_ghash_free(mat_used, NULL, NULL);
+
+ return changed;
+}
+
+/**
+ * Merge similar materials
+ * \param ob: Grease pencil object
+ * \param hue_threshold: Threshold for Hue
+ * \param sat_threshold: Threshold for Saturation
+ * \param val_threshold: Threshold for Value
+ * \param r_removed: Number of materials removed
+ * \return True if done
+ */
+bool BKE_gpencil_merge_materials(Object *ob,
+ const float hue_threshold,
+ const float sat_threshold,
+ const float val_threshold,
+ int *r_removed)
+{
+ bGPdata *gpd = ob->data;
+
+ short *totcol = BKE_object_material_len_p(ob);
+ if (totcol == 0) {
+ *r_removed = 0;
+ return 0;
+ }
+
+ /* Review materials. */
+ GHash *mat_table = BLI_ghash_int_new(__func__);
+
+ bool changed = BKE_gpencil_merge_materials_table_get(
+ ob, hue_threshold, sat_threshold, val_threshold, mat_table);
+
+ *r_removed = BLI_ghash_len(mat_table);
+
+ /* Update stroke material index. */
+ if (changed) {
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ if (gpl->flag & GP_LAYER_HIDE) {
+ continue;
+ }
+
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ /* Check if the color is editable. */
+ MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
+ if (gp_style != NULL) {
+ if (gp_style->flag & GP_MATERIAL_HIDE) {
+ continue;
+ }
+ if (((gpl->flag & GP_LAYER_UNLOCK_COLOR) == 0) &&
+ (gp_style->flag & GP_MATERIAL_LOCKED)) {
+ continue;
+ }
+ }
+
+ if (BLI_ghash_haskey(mat_table, POINTER_FROM_INT(gps->mat_nr))) {
+ int *idx = BLI_ghash_lookup(mat_table, POINTER_FROM_INT(gps->mat_nr));
+ gps->mat_nr = POINTER_AS_INT(idx);
+ }
+ }
+ }
+ }
+ }
+
+ /* Free hash memory. */
+ BLI_ghash_free(mat_table, NULL, NULL);
return changed;
}
@@ -2425,31 +2512,29 @@ void BKE_gpencil_parent_matrix_get(const Depsgraph *depsgraph,
unit_m4(diff_mat);
return;
}
- else {
- if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
- mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+
+ if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) {
+ mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+ add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
+ return;
+ }
+ if (gpl->partype == PARBONE) {
+ bPoseChannel *pchan = BKE_pose_channel_find_name(obparent_eval->pose, gpl->parsubstr);
+ if (pchan) {
+ float tmp_mat[4][4];
+ mul_m4_m4m4(tmp_mat, obparent_eval->obmat, pchan->pose_mat);
+ mul_m4_m4m4(diff_mat, tmp_mat, gpl->inverse);
add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
- return;
- }
- else if (gpl->partype == PARBONE) {
- bPoseChannel *pchan = BKE_pose_channel_find_name(obparent_eval->pose, gpl->parsubstr);
- if (pchan) {
- float tmp_mat[4][4];
- mul_m4_m4m4(tmp_mat, obparent_eval->obmat, pchan->pose_mat);
- mul_m4_m4m4(diff_mat, tmp_mat, gpl->inverse);
- add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
- }
- else {
- /* if bone not found use object (armature) */
- mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
- add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
- }
- return;
}
else {
- unit_m4(diff_mat); /* not defined type */
+ /* if bone not found use object (armature) */
+ mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse);
+ add_v3_v3(diff_mat[3], ob_eval->obmat[3]);
}
+ return;
}
+
+ unit_m4(diff_mat); /* not defined type */
}
/**
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index a7adbed6c4b..6b3f752120a 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -50,59 +50,111 @@
#include "DEG_depsgraph_query.h"
/* Helper: Check materials with same color. */
-static int gpencil_check_same_material_color(Object *ob_gp, float color[4], Material **r_mat)
+static int gpencil_check_same_material_color(Object *ob_gp,
+ const float color_stroke[4],
+ const float color_fill[4],
+ const bool do_fill,
+ const bool do_stroke,
+ Material **r_mat)
{
+ int index = -1;
Material *ma = NULL;
+ *r_mat = NULL;
float color_cu[4];
- linearrgb_to_srgb_v3_v3(color_cu, color);
- float hsv1[4];
- rgb_to_hsv_v(color_cu, hsv1);
- hsv1[3] = color[3];
+ float hsv_stroke[4], hsv_fill[4];
+
+ copy_v4_v4(color_cu, color_stroke);
+ zero_v3(hsv_stroke);
+ rgb_to_hsv_v(color_cu, hsv_stroke);
+ hsv_stroke[3] = color_stroke[3];
+
+ copy_v4_v4(color_cu, color_fill);
+ zero_v3(hsv_fill);
+ rgb_to_hsv_v(color_cu, hsv_fill);
+ hsv_fill[3] = color_fill[3];
+
+ bool match_stroke = false;
+ bool match_fill = false;
for (int i = 1; i <= ob_gp->totcol; i++) {
ma = BKE_object_material_get(ob_gp, i);
MaterialGPencilStyle *gp_style = ma->gp_style;
- /* Check color with small tolerance (better in HSV). */
+ const bool fill = (gp_style->fill_style == GP_MATERIAL_FILL_STYLE_SOLID);
+ const bool stroke = (gp_style->fill_style == GP_MATERIAL_STROKE_STYLE_SOLID);
+
+ if (do_fill && !fill) {
+ continue;
+ }
+
+ if (do_stroke && !stroke) {
+ continue;
+ }
+
+ /* Check color with small tolerance (better result in HSV). */
float hsv2[4];
- rgb_to_hsv_v(gp_style->fill_rgba, hsv2);
- hsv2[3] = gp_style->fill_rgba[3];
- if ((gp_style->fill_style == GP_MATERIAL_FILL_STYLE_SOLID) &&
- (compare_v4v4(hsv1, hsv2, 0.01f))) {
- *r_mat = ma;
- return i - 1;
+ if (do_fill) {
+ zero_v3(hsv2);
+ rgb_to_hsv_v(gp_style->fill_rgba, hsv2);
+ hsv2[3] = gp_style->fill_rgba[3];
+ if (compare_v4v4(hsv_fill, hsv2, 0.01f)) {
+ *r_mat = ma;
+ index = i - 1;
+ match_fill = true;
+ }
+ }
+ else {
+ match_fill = true;
+ }
+
+ if (do_stroke) {
+ zero_v3(hsv2);
+ rgb_to_hsv_v(gp_style->stroke_rgba, hsv2);
+ hsv2[3] = gp_style->stroke_rgba[3];
+ if (compare_v4v4(hsv_stroke, hsv2, 0.01f)) {
+ *r_mat = ma;
+ index = i - 1;
+ match_stroke = true;
+ }
+ }
+ else {
+ match_stroke = true;
+ }
+
+ /* If match, don't look for more. */
+ if (match_stroke || match_fill) {
+ break;
}
}
- *r_mat = NULL;
- return -1;
+ if (!match_stroke || !match_fill) {
+ *r_mat = NULL;
+ index = -1;
+ }
+
+ return index;
}
/* Helper: Add gpencil material using curve material as base. */
static Material *gpencil_add_from_curve_material(Main *bmain,
Object *ob_gp,
- const float cu_color[4],
- const bool gpencil_lines,
+ const float stroke_color[4],
+ const float fill_color[4],
+ const bool stroke,
const bool fill,
int *r_idx)
{
- Material *mat_gp = BKE_gpencil_object_material_new(
- bmain, ob_gp, (fill) ? "Material" : "Unassigned", r_idx);
+ Material *mat_gp = BKE_gpencil_object_material_new(bmain, ob_gp, "Material", r_idx);
MaterialGPencilStyle *gp_style = mat_gp->gp_style;
/* Stroke color. */
- if (gpencil_lines) {
- ARRAY_SET_ITEMS(gp_style->stroke_rgba, 0.0f, 0.0f, 0.0f, 1.0f);
+ if (stroke) {
+ copy_v4_v4(mat_gp->gp_style->stroke_rgba, stroke_color);
gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
}
- else {
- linearrgb_to_srgb_v4(gp_style->stroke_rgba, cu_color);
- gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
- }
/* Fill color. */
- linearrgb_to_srgb_v4(gp_style->fill_rgba, cu_color);
- /* Fill is false if the original curve hasn't material assigned, so enable it. */
if (fill) {
+ copy_v4_v4(mat_gp->gp_style->fill_rgba, fill_color);
gp_style->flag |= GP_MATERIAL_FILL_SHOW;
}
@@ -117,13 +169,18 @@ static Material *gpencil_add_from_curve_material(Main *bmain,
/* Helper: Create new stroke section. */
static void gpencil_add_new_points(bGPDstroke *gps,
- float *coord_array,
- float pressure,
- int init,
- int totpoints,
+ const float *coord_array,
+ const float pressure_start,
+ const float pressure_end,
+ const int init,
+ const int totpoints,
const float init_co[3],
- bool last)
+ const bool last)
{
+ BLI_assert(totpoints > 0);
+
+ const float step = 1.0f / ((float)totpoints - 1.0f);
+ float factor = 0.0f;
for (int i = 0; i < totpoints; i++) {
bGPDspoint *pt = &gps->points[i + init];
copy_v3_v3(&pt->x, &coord_array[3 * i]);
@@ -138,8 +195,9 @@ static void gpencil_add_new_points(bGPDstroke *gps,
}
}
- pt->pressure = pressure;
pt->strength = 1.0f;
+ pt->pressure = interpf(pressure_end, pressure_start, factor);
+ factor += step;
}
}
@@ -158,22 +216,90 @@ static Collection *gpencil_get_parent_collection(Scene *scene, Object *ob)
return mycol;
}
+static int gpencil_get_stroke_material_fromcurve(
+ Main *bmain, Object *ob_gp, Object *ob_cu, bool *do_stroke, bool *do_fill)
+{
+ Curve *cu = (Curve *)ob_cu->data;
+
+ Material *mat_gp = NULL;
+ Material *mat_curve_stroke = NULL;
+ Material *mat_curve_fill = NULL;
+
+ float color_stroke[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ float color_fill[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ /* If the curve has 2 materials, the first is considered as Fill and the second as Stroke.
+ * If the has only one material, if the name contains _stroke, the is used
+ * as stroke, else as fill.*/
+ if (ob_cu->totcol >= 2) {
+ *do_stroke = true;
+ *do_fill = true;
+ mat_curve_fill = BKE_object_material_get(ob_cu, 1);
+ mat_curve_stroke = BKE_object_material_get(ob_cu, 2);
+ }
+ else if (ob_cu->totcol == 1) {
+ mat_curve_stroke = BKE_object_material_get(ob_cu, 1);
+ if ((mat_curve_stroke) && (strstr(mat_curve_stroke->id.name, "_stroke") != NULL)) {
+ *do_stroke = true;
+ *do_fill = false;
+ mat_curve_fill = NULL;
+ }
+ else {
+ *do_stroke = false;
+ *do_fill = true;
+ /* Invert materials. */
+ mat_curve_fill = mat_curve_stroke;
+ mat_curve_stroke = NULL;
+ }
+ }
+ else {
+ /* No materials in the curve. */
+ *do_fill = false;
+ return -1;
+ }
+
+ if (mat_curve_stroke) {
+ copy_v4_v4(color_stroke, &mat_curve_stroke->r);
+ }
+ if (mat_curve_fill) {
+ copy_v4_v4(color_fill, &mat_curve_fill->r);
+ }
+
+ int r_idx = gpencil_check_same_material_color(
+ ob_gp, color_stroke, color_fill, *do_stroke, *do_fill, &mat_gp);
+
+ if ((ob_gp->totcol < r_idx) || (r_idx < 0)) {
+ mat_gp = gpencil_add_from_curve_material(
+ bmain, ob_gp, color_stroke, color_fill, *do_stroke, *do_fill, &r_idx);
+ }
+
+ /* Set fill and stroke depending of curve type (3D or 2D). */
+ if ((cu->flag & CU_3D) || ((cu->flag & (CU_FRONT | CU_BACK)) == 0)) {
+ mat_gp->gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
+ mat_gp->gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
+ }
+ else {
+ mat_gp->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
+ mat_gp->gp_style->flag |= GP_MATERIAL_FILL_SHOW;
+ }
+
+ return r_idx;
+}
/* Helper: Convert one spline to grease pencil stroke. */
static void gpencil_convert_spline(Main *bmain,
Object *ob_gp,
Object *ob_cu,
- const bool gpencil_lines,
- const bool only_stroke,
+ const float scale_thickness,
+ const float sample,
bGPDframe *gpf,
Nurb *nu)
{
- Curve *cu = (Curve *)ob_cu->data;
bool cyclic = true;
/* Create Stroke. */
bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "bGPDstroke");
- gps->thickness = 10.0f;
+ gps->thickness = 1.0f;
gps->fill_opacity_fac = 1.0f;
gps->hardeness = 1.0f;
gps->uv_scale = 1.0f;
@@ -203,76 +329,8 @@ static void gpencil_convert_spline(Main *bmain,
/* Materials
* Notice: The color of the material is the color of viewport and not the final shader color.
*/
- Material *mat_gp = NULL;
- bool fill = true;
- /* Check if grease pencil has a material with same color.*/
- float color[4];
- if ((cu->mat) && (*cu->mat)) {
- Material *mat_cu = *cu->mat;
- copy_v4_v4(color, &mat_cu->r);
- }
- else {
- /* Gray (unassigned from SVG add-on) */
- zero_v4(color);
- add_v3_fl(color, 0.6f);
- color[3] = 1.0f;
- fill = false;
- }
-
- /* Special case: If the color was created by the SVG add-on and the name contains '_stroke' and
- * there is only one color, the stroke must not be closed, fill to false and use for
- * stroke the fill color.
- */
- bool do_stroke = false;
- if (ob_cu->totcol == 1) {
- Material *ma_stroke = BKE_object_material_get(ob_cu, 1);
- if ((ma_stroke) && (strstr(ma_stroke->id.name, "_stroke") != NULL)) {
- do_stroke = true;
- }
- }
-
- int r_idx = gpencil_check_same_material_color(ob_gp, color, &mat_gp);
- if ((ob_cu->totcol > 0) && (r_idx < 0)) {
- Material *mat_curve = BKE_object_material_get(ob_cu, 1);
- mat_gp = gpencil_add_from_curve_material(bmain, ob_gp, color, gpencil_lines, fill, &r_idx);
-
- if ((mat_curve) && (mat_curve->gp_style != NULL)) {
- MaterialGPencilStyle *gp_style_cur = mat_curve->gp_style;
- MaterialGPencilStyle *gp_style_gp = mat_gp->gp_style;
-
- copy_v4_v4(gp_style_gp->mix_rgba, gp_style_cur->mix_rgba);
- gp_style_gp->fill_style = gp_style_cur->fill_style;
- gp_style_gp->mix_factor = gp_style_cur->mix_factor;
- }
-
- /* If object has more than 1 material, use second material for stroke color. */
- if ((!only_stroke) && (ob_cu->totcol > 1) && (BKE_object_material_get(ob_cu, 2))) {
- mat_curve = BKE_object_material_get(ob_cu, 2);
- if (mat_curve) {
- linearrgb_to_srgb_v3_v3(mat_gp->gp_style->stroke_rgba, &mat_curve->r);
- mat_gp->gp_style->stroke_rgba[3] = mat_curve->a;
- }
- }
- else if ((only_stroke) || (do_stroke)) {
- /* Also use the first color if the fill is none for stroke color. */
- if (ob_cu->totcol > 0) {
- mat_curve = BKE_object_material_get(ob_cu, 1);
- if (mat_curve) {
- copy_v3_v3(mat_gp->gp_style->stroke_rgba, &mat_curve->r);
- mat_gp->gp_style->stroke_rgba[3] = mat_curve->a;
- /* Set fill and stroke depending of curve type (3D or 2D). */
- if ((cu->flag & CU_3D) || ((cu->flag & (CU_FRONT | CU_BACK)) == 0)) {
- mat_gp->gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
- mat_gp->gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
- }
- else {
- mat_gp->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
- mat_gp->gp_style->flag |= GP_MATERIAL_FILL_SHOW;
- }
- }
- }
- }
- }
+ bool do_stroke, do_fill;
+ int r_idx = gpencil_get_stroke_material_fromcurve(bmain, ob_gp, ob_cu, &do_stroke, &do_fill);
CLAMP_MIN(r_idx, 0);
/* Assign material index to stroke. */
@@ -329,14 +387,18 @@ static void gpencil_convert_spline(Main *bmain,
bezt->vec[1][j],
coord_array + j,
resolu - 1,
- 3 * sizeof(float));
+ sizeof(float[3]));
}
/* Save first point coordinates. */
if (s == 0) {
copy_v3_v3(init_co, &coord_array[0]);
}
/* Add points to the stroke */
- gpencil_add_new_points(gps, coord_array, bezt->radius, init, resolu, init_co, last);
+ float radius_start = prevbezt->radius * scale_thickness;
+ float radius_end = bezt->radius * scale_thickness;
+
+ gpencil_add_new_points(
+ gps, coord_array, radius_start, radius_end, init, resolu, init_co, last);
/* Free memory. */
MEM_SAFE_FREE(coord_array);
@@ -367,7 +429,7 @@ static void gpencil_convert_spline(Main *bmain,
gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
/* Add points. */
- gpencil_add_new_points(gps, coord_array, 1.0f, 0, gps->totpoints, init_co, false);
+ gpencil_add_new_points(gps, coord_array, 1.0f, 1.0f, 0, gps->totpoints, init_co, false);
MEM_SAFE_FREE(coord_array);
}
@@ -378,10 +440,14 @@ static void gpencil_convert_spline(Main *bmain,
}
}
/* Cyclic curve, close stroke. */
- if ((cyclic) && (!do_stroke)) {
+ if (cyclic) {
BKE_gpencil_stroke_close(gps);
}
+ if (sample > 0.0f) {
+ BKE_gpencil_stroke_sample(gps, sample, false);
+ }
+
/* Recalc fill geometry. */
BKE_gpencil_stroke_geometry_update(gps);
}
@@ -393,17 +459,17 @@ static void gpencil_convert_spline(Main *bmain,
* \param scene: Original scene.
* \param ob_gp: Grease pencil object to add strokes.
* \param ob_cu: Curve to convert.
- * \param gpencil_lines: Use lines for strokes.
* \param use_collections: Create layers using collection names.
- * \param only_stroke: The material must be only stroke without fill.
+ * \param scale_thickness: Scale thickness factor.
+ * \param sample: Sample distance, zero to disable.
*/
void BKE_gpencil_convert_curve(Main *bmain,
Scene *scene,
Object *ob_gp,
Object *ob_cu,
- const bool gpencil_lines,
const bool use_collections,
- const bool only_stroke)
+ const float scale_thickness,
+ const float sample)
{
if (ELEM(NULL, ob_gp, ob_cu) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) {
return;
@@ -441,11 +507,32 @@ void BKE_gpencil_convert_curve(Main *bmain,
/* Read all splines of the curve and create a stroke for each. */
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- gpencil_convert_spline(bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, gpf, nu);
+ gpencil_convert_spline(bmain, ob_gp, ob_cu, scale_thickness, sample, gpf, nu);
}
+ /* Merge any similar material. */
+ int removed = 0;
+ BKE_gpencil_merge_materials(ob_gp, 0.001f, 0.001f, 0.001f, &removed);
+
+ /* Remove any unused slot. */
+ int actcol = ob_gp->actcol;
+
+ for (int slot = 1; slot <= ob_gp->totcol; slot++) {
+ while (slot <= ob_gp->totcol && !BKE_object_material_slot_used(ob_gp->data, slot)) {
+ ob_gp->actcol = slot;
+ BKE_object_material_slot_remove(bmain, ob_gp);
+
+ if (actcol >= slot) {
+ actcol--;
+ }
+ }
+ }
+
+ ob_gp->actcol = actcol;
+
/* Tag for recalculation */
DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+ DEG_id_tag_update(&ob_gp->id, ID_RECALC_GEOMETRY);
}
/** \} */
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 579ebc9b9b3..65ce117431b 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -237,7 +237,7 @@ static int stroke_march_next_point(const bGPDstroke *gps,
copy_v3_v3(result, &pt->x);
*pressure = gps->points[next_point_index].pressure;
*strength = gps->points[next_point_index].strength;
- memcpy(vert_color, gps->points[next_point_index].vert_color, sizeof(float) * 4);
+ memcpy(vert_color, gps->points[next_point_index].vert_color, sizeof(float[4]));
*index_from = next_point_index - 1;
*index_to = next_point_index;
@@ -245,24 +245,23 @@ static int stroke_march_next_point(const bGPDstroke *gps,
return 0;
}
- else {
- float ratio = remaining_march / remaining_till_next;
- interp_v3_v3v3(result, step_start, point, ratio);
- *pressure = interpf(
- gps->points[next_point_index].pressure, gps->points[next_point_index - 1].pressure, ratio);
- *strength = interpf(
- gps->points[next_point_index].strength, gps->points[next_point_index - 1].strength, ratio);
- interp_v4_v4v4(vert_color,
- gps->points[next_point_index - 1].vert_color,
- gps->points[next_point_index].vert_color,
- ratio);
- *index_from = next_point_index - 1;
- *index_to = next_point_index;
- *ratio_result = ratio;
+ float ratio = remaining_march / remaining_till_next;
+ interp_v3_v3v3(result, step_start, point, ratio);
+ *pressure = interpf(
+ gps->points[next_point_index].pressure, gps->points[next_point_index - 1].pressure, ratio);
+ *strength = interpf(
+ gps->points[next_point_index].strength, gps->points[next_point_index - 1].strength, ratio);
+ interp_v4_v4v4(vert_color,
+ gps->points[next_point_index - 1].vert_color,
+ gps->points[next_point_index].vert_color,
+ ratio);
- return next_point_index;
- }
+ *index_from = next_point_index - 1;
+ *index_to = next_point_index;
+ *ratio_result = ratio;
+
+ return next_point_index;
}
static int stroke_march_next_point_no_interp(const bGPDstroke *gps,
@@ -306,11 +305,10 @@ static int stroke_march_next_point_no_interp(const bGPDstroke *gps,
copy_v3_v3(result, &pt->x);
return 0;
}
- else {
- float ratio = remaining_march / remaining_till_next;
- interp_v3_v3v3(result, step_start, point, ratio);
- return next_point_index;
- }
+
+ float ratio = remaining_march / remaining_till_next;
+ interp_v3_v3v3(result, step_start, point, ratio);
+ return next_point_index;
}
static int stroke_march_count(const bGPDstroke *gps, const float dist)
@@ -447,7 +445,7 @@ bool BKE_gpencil_stroke_sample(bGPDstroke *gps, const float dist, const bool sel
copy_v3_v3(&pt2->x, last_coord);
new_pt[i].pressure = pt[0].pressure;
new_pt[i].strength = pt[0].strength;
- memcpy(new_pt[i].vert_color, pt[0].vert_color, sizeof(float) * 4);
+ memcpy(new_pt[i].vert_color, pt[0].vert_color, sizeof(float[4]));
if (select) {
new_pt[i].flag |= GP_SPOINT_SELECT;
}
@@ -473,7 +471,7 @@ bool BKE_gpencil_stroke_sample(bGPDstroke *gps, const float dist, const bool sel
copy_v3_v3(&pt2->x, last_coord);
new_pt[i].pressure = pressure;
new_pt[i].strength = strength;
- memcpy(new_pt[i].vert_color, vert_color, sizeof(float) * 4);
+ memcpy(new_pt[i].vert_color, vert_color, sizeof(float[4]));
if (select) {
new_pt[i].flag |= GP_SPOINT_SELECT;
}
@@ -1352,10 +1350,9 @@ bool BKE_gpencil_stroke_trim(bGPDstroke *gps)
if ((lambda <= 0.0f) || (lambda >= 1.0f)) {
continue;
}
- else {
- intersect = true;
- break;
- }
+
+ intersect = true;
+ break;
}
}
}
@@ -2599,10 +2596,9 @@ void BKE_gpencil_stroke_set_random_color(bGPDstroke *gps)
float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
bGPDspoint *pt = &gps->points[0];
- color[0] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->x));
- color[1] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->y));
- color[2] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints, pt->z));
-
+ color[0] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints / 5, pt->x + pt->z));
+ color[1] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints + pt->x, pt->y * pt->z + pt->x));
+ color[2] *= BLI_hash_int_01(BLI_hash_int_2d(gps->totpoints - pt->x, pt->z * pt->x + pt->y));
for (int i = 0; i < gps->totpoints; i++) {
pt = &gps->points[i];
copy_v4_v4(pt->vert_color, color);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index e92bf5a4502..c2e330e8f04 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -348,9 +348,8 @@ const GpencilModifierTypeInfo *BKE_gpencil_modifier_get_info(GpencilModifierType
modifier_gpencil_types[type]->name[0] != '\0') {
return modifier_gpencil_types[type];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/**
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 90761d24b73..2905bfc978a 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -202,8 +202,8 @@ BoundBox *BKE_hair_boundbox_get(Object *ob)
for (int a = 0; a < hair->totpoint; a++) {
float *co = hair_co[a];
float radius = (hair_radius) ? hair_radius[a] : 0.0f;
- float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
- float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
+ const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
DO_MIN(co_min, min);
DO_MAX(co_max, max);
}
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 6da48195aab..bec0da750e1 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -765,9 +765,8 @@ bool BKE_icon_delete(const int icon_id)
icon_free(icon);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
bool BKE_icon_delete_unmanaged(const int icon_id)
@@ -783,15 +782,13 @@ bool BKE_icon_delete_unmanaged(const int icon_id)
BLI_ghash_insert(gIcons, POINTER_FROM_INT(icon_id), icon);
return false;
}
- else {
- icon_free_data(icon_id, icon);
- icon_free(icon);
- return true;
- }
- }
- else {
- return false;
+
+ icon_free_data(icon_id, icon);
+ icon_free(icon);
+ return true;
}
+
+ return false;
}
/* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index c3c67b9ed51..529ae227df9 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -55,10 +55,10 @@ static size_t idp_size_table[] = {
1, /*strings*/
sizeof(int),
sizeof(float),
- sizeof(float) * 3, /*Vector type, deprecated*/
- sizeof(float) * 16, /*Matrix type, deprecated*/
- 0, /*arrays don't have a fixed size*/
- sizeof(ListBase), /*Group type*/
+ sizeof(float[3]), /*Vector type, deprecated*/
+ sizeof(float[16]), /*Matrix type, deprecated*/
+ 0, /*arrays don't have a fixed size*/
+ sizeof(ListBase), /*Group type*/
sizeof(void *),
sizeof(double),
};
@@ -181,7 +181,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
prop->len = newlen;
return;
}
- else if (newlen >= prop->len) {
+ if (newlen >= prop->len) {
prop->len = newlen;
return;
}
@@ -836,17 +836,16 @@ IDProperty *IDP_GetProperties(ID *id, const bool create_if_needed)
if (id->properties) {
return id->properties;
}
- else {
- if (create_if_needed) {
- id->properties = MEM_callocN(sizeof(IDProperty), "IDProperty");
- id->properties->type = IDP_GROUP;
- /* don't overwrite the data's name and type
- * some functions might need this if they
- * don't have a real ID, should be named elsewhere - Campbell */
- /* strcpy(id->name, "top_level_group");*/
- }
- return id->properties;
+
+ if (create_if_needed) {
+ id->properties = MEM_callocN(sizeof(IDProperty), "IDProperty");
+ id->properties->type = IDP_GROUP;
+ /* don't overwrite the data's name and type
+ * some functions might need this if they
+ * don't have a real ID, should be named elsewhere - Campbell */
+ /* strcpy(id->name, "top_level_group");*/
}
+ return id->properties;
}
/**
@@ -856,10 +855,10 @@ bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is
if (prop1 == NULL && prop2 == NULL) {
return true;
}
- else if (prop1 == NULL || prop2 == NULL) {
+ if (prop1 == NULL || prop2 == NULL) {
return is_strict ? false : true;
}
- else if (prop1->type != prop2->type) {
+ if (prop1->type != prop2->type) {
return false;
}
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 1166ad9ad2f..4ab7d362e0e 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -135,9 +135,8 @@ const IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code)
id_types[id_index]->name[0] != '\0') {
return id_types[id_index];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
const IDTypeInfo *BKE_idtype_get_info_from_id(const ID *id)
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 9365ee040c2..7ff34acca7a 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -57,6 +57,7 @@
#include "DNA_packedFile_types.h"
#include "DNA_scene_types.h"
#include "DNA_sequence_types.h"
+#include "DNA_simulation_types.h"
#include "DNA_world_types.h"
#include "BLI_blenlib.h"
@@ -89,7 +90,6 @@
#include "RE_pipeline.h"
-#include "GPU_draw.h"
#include "GPU_texture.h"
#include "BLI_sys_types.h" // for intptr_t support
@@ -392,7 +392,7 @@ void BKE_image_free_buffers_ex(Image *ima, bool do_lock)
ima->rr = NULL;
}
- GPU_free_image(ima);
+ BKE_image_free_gputextures(ima);
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
tile->ok = IMA_OK;
@@ -667,9 +667,8 @@ char BKE_image_alpha_mode_from_extension_ex(const char *filepath)
if (BLI_path_extension_check_n(filepath, ".exr", ".cin", ".dpx", ".hdr", NULL)) {
return IMA_ALPHA_PREMUL;
}
- else {
- return IMA_ALPHA_STRAIGHT;
- }
+
+ return IMA_ALPHA_STRAIGHT;
}
void BKE_image_alpha_mode_from_extension(Image *image)
@@ -1201,57 +1200,56 @@ int BKE_image_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options)
if (imtype == R_IMF_IMTYPE_TARGA) {
return IMB_FTYPE_TGA;
}
- else if (imtype == R_IMF_IMTYPE_RAWTGA) {
+ if (imtype == R_IMF_IMTYPE_RAWTGA) {
r_options->flag = RAWTGA;
return IMB_FTYPE_TGA;
}
- else if (imtype == R_IMF_IMTYPE_IRIS) {
+ if (imtype == R_IMF_IMTYPE_IRIS) {
return IMB_FTYPE_IMAGIC;
}
#ifdef WITH_HDR
- else if (imtype == R_IMF_IMTYPE_RADHDR) {
+ if (imtype == R_IMF_IMTYPE_RADHDR) {
return IMB_FTYPE_RADHDR;
}
#endif
- else if (imtype == R_IMF_IMTYPE_PNG) {
+ if (imtype == R_IMF_IMTYPE_PNG) {
r_options->quality = 15;
return IMB_FTYPE_PNG;
}
#ifdef WITH_DDS
- else if (imtype == R_IMF_IMTYPE_DDS) {
+ if (imtype == R_IMF_IMTYPE_DDS) {
return IMB_FTYPE_DDS;
}
#endif
- else if (imtype == R_IMF_IMTYPE_BMP) {
+ if (imtype == R_IMF_IMTYPE_BMP) {
return IMB_FTYPE_BMP;
}
#ifdef WITH_TIFF
- else if (imtype == R_IMF_IMTYPE_TIFF) {
+ if (imtype == R_IMF_IMTYPE_TIFF) {
return IMB_FTYPE_TIF;
}
#endif
- else if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) {
+ if (imtype == R_IMF_IMTYPE_OPENEXR || imtype == R_IMF_IMTYPE_MULTILAYER) {
return IMB_FTYPE_OPENEXR;
}
#ifdef WITH_CINEON
- else if (imtype == R_IMF_IMTYPE_CINEON) {
+ if (imtype == R_IMF_IMTYPE_CINEON) {
return IMB_FTYPE_CINEON;
}
- else if (imtype == R_IMF_IMTYPE_DPX) {
+ if (imtype == R_IMF_IMTYPE_DPX) {
return IMB_FTYPE_DPX;
}
#endif
#ifdef WITH_OPENJPEG
- else if (imtype == R_IMF_IMTYPE_JP2) {
+ if (imtype == R_IMF_IMTYPE_JP2) {
r_options->flag |= JP2_JP2;
r_options->quality = 90;
return IMB_FTYPE_JP2;
}
#endif
- else {
- r_options->quality = 90;
- return IMB_FTYPE_JPG;
- }
+
+ r_options->quality = 90;
+ return IMB_FTYPE_JPG;
}
char BKE_image_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
@@ -1259,57 +1257,55 @@ char BKE_image_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
if (ftype == 0) {
return R_IMF_IMTYPE_TARGA;
}
- else if (ftype == IMB_FTYPE_IMAGIC) {
+ if (ftype == IMB_FTYPE_IMAGIC) {
return R_IMF_IMTYPE_IRIS;
}
#ifdef WITH_HDR
- else if (ftype == IMB_FTYPE_RADHDR) {
+ if (ftype == IMB_FTYPE_RADHDR) {
return R_IMF_IMTYPE_RADHDR;
}
#endif
- else if (ftype == IMB_FTYPE_PNG) {
+ if (ftype == IMB_FTYPE_PNG) {
return R_IMF_IMTYPE_PNG;
}
#ifdef WITH_DDS
- else if (ftype == IMB_FTYPE_DDS) {
+ if (ftype == IMB_FTYPE_DDS) {
return R_IMF_IMTYPE_DDS;
}
#endif
- else if (ftype == IMB_FTYPE_BMP) {
+ if (ftype == IMB_FTYPE_BMP) {
return R_IMF_IMTYPE_BMP;
}
#ifdef WITH_TIFF
- else if (ftype == IMB_FTYPE_TIF) {
+ if (ftype == IMB_FTYPE_TIF) {
return R_IMF_IMTYPE_TIFF;
}
#endif
- else if (ftype == IMB_FTYPE_OPENEXR) {
+ if (ftype == IMB_FTYPE_OPENEXR) {
return R_IMF_IMTYPE_OPENEXR;
}
#ifdef WITH_CINEON
- else if (ftype == IMB_FTYPE_CINEON) {
+ if (ftype == IMB_FTYPE_CINEON) {
return R_IMF_IMTYPE_CINEON;
}
- else if (ftype == IMB_FTYPE_DPX) {
+ if (ftype == IMB_FTYPE_DPX) {
return R_IMF_IMTYPE_DPX;
}
#endif
- else if (ftype == IMB_FTYPE_TGA) {
+ if (ftype == IMB_FTYPE_TGA) {
if (options && (options->flag & RAWTGA)) {
return R_IMF_IMTYPE_RAWTGA;
}
- else {
- return R_IMF_IMTYPE_TARGA;
- }
+
+ return R_IMF_IMTYPE_TARGA;
}
#ifdef WITH_OPENJPEG
- else if (ftype == IMB_FTYPE_JP2) {
+ if (ftype == IMB_FTYPE_JP2) {
return R_IMF_IMTYPE_JP2;
}
#endif
- else {
- return R_IMF_IMTYPE_JPEG90;
- }
+
+ return R_IMF_IMTYPE_JPEG90;
}
bool BKE_imtype_is_movie(const char imtype)
@@ -1443,78 +1439,77 @@ char BKE_imtype_from_arg(const char *imtype_arg)
if (STREQ(imtype_arg, "TGA")) {
return R_IMF_IMTYPE_TARGA;
}
- else if (STREQ(imtype_arg, "IRIS")) {
+ if (STREQ(imtype_arg, "IRIS")) {
return R_IMF_IMTYPE_IRIS;
}
#ifdef WITH_DDS
- else if (STREQ(imtype_arg, "DDS")) {
+ if (STREQ(imtype_arg, "DDS")) {
return R_IMF_IMTYPE_DDS;
}
#endif
- else if (STREQ(imtype_arg, "JPEG")) {
+ if (STREQ(imtype_arg, "JPEG")) {
return R_IMF_IMTYPE_JPEG90;
}
- else if (STREQ(imtype_arg, "IRIZ")) {
+ if (STREQ(imtype_arg, "IRIZ")) {
return R_IMF_IMTYPE_IRIZ;
}
- else if (STREQ(imtype_arg, "RAWTGA")) {
+ if (STREQ(imtype_arg, "RAWTGA")) {
return R_IMF_IMTYPE_RAWTGA;
}
- else if (STREQ(imtype_arg, "AVIRAW")) {
+ if (STREQ(imtype_arg, "AVIRAW")) {
return R_IMF_IMTYPE_AVIRAW;
}
- else if (STREQ(imtype_arg, "AVIJPEG")) {
+ if (STREQ(imtype_arg, "AVIJPEG")) {
return R_IMF_IMTYPE_AVIJPEG;
}
- else if (STREQ(imtype_arg, "PNG")) {
+ if (STREQ(imtype_arg, "PNG")) {
return R_IMF_IMTYPE_PNG;
}
- else if (STREQ(imtype_arg, "BMP")) {
+ if (STREQ(imtype_arg, "BMP")) {
return R_IMF_IMTYPE_BMP;
}
#ifdef WITH_HDR
- else if (STREQ(imtype_arg, "HDR")) {
+ if (STREQ(imtype_arg, "HDR")) {
return R_IMF_IMTYPE_RADHDR;
}
#endif
#ifdef WITH_TIFF
- else if (STREQ(imtype_arg, "TIFF")) {
+ if (STREQ(imtype_arg, "TIFF")) {
return R_IMF_IMTYPE_TIFF;
}
#endif
#ifdef WITH_OPENEXR
- else if (STREQ(imtype_arg, "OPEN_EXR")) {
+ if (STREQ(imtype_arg, "OPEN_EXR")) {
return R_IMF_IMTYPE_OPENEXR;
}
- else if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) {
+ if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) {
return R_IMF_IMTYPE_MULTILAYER;
}
- else if (STREQ(imtype_arg, "EXR")) {
+ if (STREQ(imtype_arg, "EXR")) {
return R_IMF_IMTYPE_OPENEXR;
}
- else if (STREQ(imtype_arg, "MULTILAYER")) {
+ if (STREQ(imtype_arg, "MULTILAYER")) {
return R_IMF_IMTYPE_MULTILAYER;
}
#endif
- else if (STREQ(imtype_arg, "FFMPEG")) {
+ if (STREQ(imtype_arg, "FFMPEG")) {
return R_IMF_IMTYPE_FFMPEG;
}
#ifdef WITH_CINEON
- else if (STREQ(imtype_arg, "CINEON")) {
+ if (STREQ(imtype_arg, "CINEON")) {
return R_IMF_IMTYPE_CINEON;
}
- else if (STREQ(imtype_arg, "DPX")) {
+ if (STREQ(imtype_arg, "DPX")) {
return R_IMF_IMTYPE_DPX;
}
#endif
#ifdef WITH_OPENJPEG
- else if (STREQ(imtype_arg, "JP2")) {
+ if (STREQ(imtype_arg, "JP2")) {
return R_IMF_IMTYPE_JP2;
}
#endif
- else {
- return R_IMF_IMTYPE_INVALID;
- }
+
+ return R_IMF_IMTYPE_INVALID;
}
static bool do_add_image_extension(char *string,
@@ -1638,13 +1633,11 @@ static bool do_add_image_extension(char *string,
if (BLI_path_extension_check_array(string, imb_ext_image)) {
return BLI_path_extension_replace(string, FILE_MAX, extension);
}
- else {
- return BLI_path_extension_ensure(string, FILE_MAX, extension);
- }
- }
- else {
- return false;
+
+ return BLI_path_extension_ensure(string, FILE_MAX, extension);
}
+
+ return false;
}
int BKE_image_path_ensure_ext_from_imformat(char *string, const ImageFormatData *im_format)
@@ -2884,7 +2877,7 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, const ImageFormatData *imf)
perror(name);
}
- return (ok);
+ return ok;
}
/* same as BKE_imbuf_write() but crappy workaround not to permanently modify
@@ -3012,7 +3005,7 @@ struct anim *openanim(const char *name, int flags, int streamindex, char colorsp
}
IMB_freeImBuf(ibuf);
- return (anim);
+ return anim;
}
/* ************************* New Image API *************** */
@@ -3240,6 +3233,12 @@ static void image_walk_id_all_users(
if (scene->nodetree && scene->use_nodes && !skip_nested_nodes) {
image_walk_ntree_all_users(scene->nodetree, &scene->id, customdata, callback);
}
+ break;
+ }
+ case ID_SIM: {
+ Simulation *simulation = (Simulation *)id;
+ image_walk_ntree_all_users(simulation->nodetree, &simulation->id, customdata, callback);
+ break;
}
default:
break;
@@ -3344,8 +3343,7 @@ static void image_free_tile(Image *ima, ImageTile *tile)
for (int i = 0; i < TEXTARGET_COUNT; i++) {
/* Only two textures depends on all tiles, so if this is a secondary tile we can keep the other
* two. */
- if (tile != ima->tiles.first &&
- !(ELEM(i, TEXTARGET_TEXTURE_2D_ARRAY, TEXTARGET_TEXTURE_TILE_MAPPING))) {
+ if (tile != ima->tiles.first && !(ELEM(i, TEXTARGET_2D_ARRAY, TEXTARGET_TILE_MAPPING))) {
continue;
}
@@ -3543,9 +3541,8 @@ static RenderPass *image_render_pass_get(RenderLayer *rl,
/* no multiview or left eye */
break;
}
- else {
- rp_name = rpass->name;
- }
+
+ rp_name = rpass->name;
}
/* multiview */
else if (rp_name[0] && STREQ(rpass->name, rp_name) && (rpass->view_id == view)) {
@@ -3622,13 +3619,13 @@ ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *la
for (int eye = 0; eye < 2; eye++) {
/* Reallocate GPU tile array. */
- if (ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][eye] != NULL) {
- GPU_texture_free(ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][eye]);
- ima->gputexture[TEXTARGET_TEXTURE_2D_ARRAY][eye] = NULL;
+ if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != NULL) {
+ GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]);
+ ima->gputexture[TEXTARGET_2D_ARRAY][eye] = NULL;
}
- if (ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING][eye] != NULL) {
- GPU_texture_free(ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING][eye]);
- ima->gputexture[TEXTARGET_TEXTURE_TILE_MAPPING][eye] = NULL;
+ if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != NULL) {
+ GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]);
+ ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = NULL;
}
}
@@ -3708,9 +3705,8 @@ RenderPass *BKE_image_multilayer_index(RenderResult *rr, ImageUser *iuser)
iuser->multi_index = index + rp_index;
break;
}
- else {
- index += BLI_listbase_count(&rl->passes);
- }
+
+ index += BLI_listbase_count(&rl->passes);
}
}
@@ -3937,7 +3933,7 @@ static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr)
#endif /* WITH_OPENEXR */
/* common stuff to do with images after loading */
-static void image_initialize_after_load(Image *ima, ImageUser *iuser, ImBuf *UNUSED(ibuf))
+static void image_init_after_load(Image *ima, ImageUser *iuser, ImBuf *UNUSED(ibuf))
{
/* Preview is NULL when it has never been used as an icon before.
* Never handle previews/icons outside of main thread. */
@@ -3981,13 +3977,12 @@ static int image_num_files(Image *ima)
if (!is_multiview) {
return 1;
}
- else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) {
+ if (ima->views_format == R_IMF_VIEWS_STEREO_3D) {
return 1;
}
/* R_IMF_VIEWS_INDIVIDUAL */
- else {
- return BLI_listbase_count(&ima->views);
- }
+
+ return BLI_listbase_count(&ima->views);
}
static ImBuf *load_sequence_single(
@@ -4040,11 +4035,11 @@ static ImBuf *load_sequence_single(
}
}
else {
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
*r_assign = true;
}
#else
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
*r_assign = true;
#endif
}
@@ -4149,7 +4144,7 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int e
BKE_imbuf_stamp_info(ima->rr, ibuf);
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, entry);
}
// else printf("pass not found\n");
@@ -4213,7 +4208,7 @@ static ImBuf *load_movie_single(Image *ima, ImageUser *iuser, int frame, const i
ibuf = IMB_makeSingleUser(IMB_anim_absolute(ia->anim, fra, IMB_TC_RECORD_RUN, IMB_PROXY_NONE));
if (ibuf) {
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
}
else {
tile->ok = 0;
@@ -4358,7 +4353,7 @@ static ImBuf *load_image_single(Image *ima,
else
#endif
{
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
*r_assign = true;
/* make packed file for autopack */
@@ -4472,7 +4467,7 @@ static ImBuf *image_get_ibuf_multilayer(Image *ima, ImageUser *iuser)
if (rpass) {
ibuf = IMB_allocImBuf(ima->rr->rectx, ima->rr->recty, 32, 0);
- image_initialize_after_load(ima, iuser, ibuf);
+ image_init_after_load(ima, iuser, ibuf);
ibuf->rect_float = rpass->rect;
ibuf->flags |= IB_rectfloat;
@@ -4702,7 +4697,7 @@ static int image_get_multiview_index(Image *ima, ImageUser *iuser)
if (is_multilayer) {
return iuser ? iuser->multi_index : index;
}
- else if (is_backdrop) {
+ if (is_backdrop) {
if (BKE_image_is_stereo(ima)) {
/* backdrop hackaround (since there is no iuser */
return ima->eye;
@@ -4839,7 +4834,7 @@ BLI_INLINE bool image_quick_test(Image *ima, const ImageUser *iuser)
if (tile == NULL) {
return false;
}
- else if (tile->ok == 0) {
+ if (tile->ok == 0) {
return false;
}
@@ -5156,58 +5151,57 @@ int BKE_image_user_frame_get(const ImageUser *iuser, int cfra, bool *r_is_in_ran
if (len == 0) {
return 0;
}
- else {
- int framenr;
- cfra = cfra - iuser->sfra + 1;
-
- /* cyclic */
- if (iuser->cycl) {
- cfra = ((cfra) % len);
- if (cfra < 0) {
- cfra += len;
- }
- if (cfra == 0) {
- cfra = len;
- }
- if (r_is_in_range) {
- *r_is_in_range = true;
- }
- }
+ int framenr;
+ cfra = cfra - iuser->sfra + 1;
+ /* cyclic */
+ if (iuser->cycl) {
+ cfra = ((cfra) % len);
if (cfra < 0) {
- cfra = 0;
+ cfra += len;
}
- else if (cfra > len) {
+ if (cfra == 0) {
cfra = len;
}
- else {
- if (r_is_in_range) {
- *r_is_in_range = true;
- }
- }
- /* transform to images space */
- framenr = cfra;
- if (framenr > iuser->frames) {
- framenr = iuser->frames;
+ if (r_is_in_range) {
+ *r_is_in_range = true;
}
+ }
- if (iuser->cycl) {
- framenr = ((framenr) % len);
- while (framenr < 0) {
- framenr += len;
- }
- if (framenr == 0) {
- framenr = len;
- }
+ if (cfra < 0) {
+ cfra = 0;
+ }
+ else if (cfra > len) {
+ cfra = len;
+ }
+ else {
+ if (r_is_in_range) {
+ *r_is_in_range = true;
}
+ }
- /* important to apply after else we cant loop on frames 100 - 110 for eg. */
- framenr += iuser->offset;
+ /* transform to images space */
+ framenr = cfra;
+ if (framenr > iuser->frames) {
+ framenr = iuser->frames;
+ }
- return framenr;
+ if (iuser->cycl) {
+ framenr = ((framenr) % len);
+ while (framenr < 0) {
+ framenr += len;
+ }
+ if (framenr == 0) {
+ framenr = len;
+ }
}
+
+ /* important to apply after else we cant loop on frames 100 - 110 for eg. */
+ framenr += iuser->offset;
+
+ return framenr;
}
void BKE_image_user_frame_calc(Image *ima, ImageUser *iuser, int cfra)
@@ -5373,9 +5367,8 @@ bool BKE_image_has_alpha(struct Image *image)
if (planes == 32) {
return true;
}
- else {
- return false;
- }
+
+ return false;
}
void BKE_image_get_size(Image *image, ImageUser *iuser, int *r_width, int *r_height)
@@ -5841,17 +5834,16 @@ bool BKE_image_clear_renderslot(Image *ima, ImageUser *iuser, int index)
RE_ClearResult(re);
return true;
}
- else {
- RenderSlot *slot = BLI_findlink(&ima->renderslots, index);
- if (!slot) {
- return false;
- }
- if (slot->render) {
- RE_FreeRenderResult(slot->render);
- slot->render = NULL;
- }
- return true;
+
+ RenderSlot *slot = BLI_findlink(&ima->renderslots, index);
+ if (!slot) {
+ return false;
}
+ if (slot->render) {
+ RE_FreeRenderResult(slot->render);
+ slot->render = NULL;
+ }
+ return true;
}
RenderSlot *BKE_image_get_renderslot(Image *ima, int index)
diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c
new file mode 100644
index 00000000000..78a705ae145
--- /dev/null
+++ b/source/blender/blenkernel/intern/image_gpu.c
@@ -0,0 +1,774 @@
+/*
+ * 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 "BLI_boxpack_2d.h"
+#include "BLI_linklist.h"
+#include "BLI_listbase.h"
+#include "BLI_threads.h"
+
+#include "DNA_image_types.h"
+#include "DNA_userdef_types.h"
+
+#include "IMB_colormanagement.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
+#include "BKE_global.h"
+#include "BKE_image.h"
+#include "BKE_main.h"
+
+#include "GPU_extensions.h"
+#include "GPU_state.h"
+#include "GPU_texture.h"
+
+#include "PIL_time.h"
+
+/* Prototypes. */
+static void gpu_free_unused_buffers(void);
+static void image_free_gpu(Image *ima, const bool immediate);
+
+/* -------------------------------------------------------------------- */
+/** \name UDIM gpu texture
+ * \{ */
+
+static bool is_over_resolution_limit(int w, int h)
+{
+ return (w > GPU_texture_size_with_limit(w) || h > GPU_texture_size_with_limit(h));
+}
+
+static int smaller_power_of_2_limit(int num)
+{
+ return power_of_2_min_i(GPU_texture_size_with_limit(num));
+}
+
+static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye)
+{
+ GPUTexture *tilearray = ima->gputexture[TEXTARGET_2D_ARRAY][multiview_eye];
+
+ if (tilearray == NULL) {
+ return 0;
+ }
+
+ float array_w = GPU_texture_width(tilearray);
+ float array_h = GPU_texture_height(tilearray);
+
+ ImageTile *last_tile = (ImageTile *)ima->tiles.last;
+ /* Tiles are sorted by number. */
+ int max_tile = last_tile->tile_number - 1001;
+
+ /* create image */
+ int width = max_tile + 1;
+ float *data = (float *)MEM_callocN(width * 8 * sizeof(float), __func__);
+ for (int i = 0; i < width; i++) {
+ data[4 * i] = -1.0f;
+ }
+ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
+ int i = tile->tile_number - 1001;
+ data[4 * i] = tile->runtime.tilearray_layer;
+
+ float *tile_info = &data[4 * width + 4 * i];
+ tile_info[0] = tile->runtime.tilearray_offset[0] / array_w;
+ tile_info[1] = tile->runtime.tilearray_offset[1] / array_h;
+ tile_info[2] = tile->runtime.tilearray_size[0] / array_w;
+ tile_info[3] = tile->runtime.tilearray_size[1] / array_h;
+ }
+
+ GPUTexture *tex = GPU_texture_create_1d_array(width, 2, GPU_RGBA32F, data, NULL);
+ GPU_texture_mipmap_mode(tex, false, false);
+
+ MEM_freeN(data);
+
+ return tex;
+}
+
+typedef struct PackTile {
+ FixedSizeBoxPack boxpack;
+ ImageTile *tile;
+ float pack_score;
+} PackTile;
+
+static int compare_packtile(const void *a, const void *b)
+{
+ const PackTile *tile_a = (const PackTile *)a;
+ const PackTile *tile_b = (const PackTile *)b;
+
+ return tile_a->pack_score < tile_b->pack_score;
+}
+
+static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
+{
+ int arraywidth = 0, arrayheight = 0;
+ ListBase boxes = {NULL};
+
+ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
+ ImageUser iuser;
+ BKE_imageuser_default(&iuser);
+ iuser.tile = tile->tile_number;
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
+
+ if (ibuf) {
+ PackTile *packtile = (PackTile *)MEM_callocN(sizeof(PackTile), __func__);
+ packtile->tile = tile;
+ packtile->boxpack.w = ibuf->x;
+ packtile->boxpack.h = ibuf->y;
+
+ if (is_over_resolution_limit(packtile->boxpack.w, packtile->boxpack.h)) {
+ packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w);
+ packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h);
+ }
+ arraywidth = max_ii(arraywidth, packtile->boxpack.w);
+ arrayheight = max_ii(arrayheight, packtile->boxpack.h);
+
+ /* We sort the tiles by decreasing size, with an additional penalty term
+ * for high aspect ratios. This improves packing efficiency. */
+ float w = packtile->boxpack.w, h = packtile->boxpack.h;
+ packtile->pack_score = max_ff(w, h) / min_ff(w, h) * w * h;
+
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+ BLI_addtail(&boxes, packtile);
+ }
+ }
+
+ BLI_assert(arraywidth > 0 && arrayheight > 0);
+
+ BLI_listbase_sort(&boxes, compare_packtile);
+ int arraylayers = 0;
+ /* Keep adding layers until all tiles are packed. */
+ while (boxes.first != NULL) {
+ ListBase packed = {NULL};
+ BLI_box_pack_2d_fixedarea(&boxes, arraywidth, arrayheight, &packed);
+ BLI_assert(packed.first != NULL);
+
+ LISTBASE_FOREACH (PackTile *, packtile, &packed) {
+ ImageTile *tile = packtile->tile;
+ int *tileoffset = tile->runtime.tilearray_offset;
+ int *tilesize = tile->runtime.tilearray_size;
+
+ tileoffset[0] = packtile->boxpack.x;
+ tileoffset[1] = packtile->boxpack.y;
+ tilesize[0] = packtile->boxpack.w;
+ tilesize[1] = packtile->boxpack.h;
+ tile->runtime.tilearray_layer = arraylayers;
+ }
+
+ BLI_freelistN(&packed);
+ arraylayers++;
+ }
+
+ const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
+ /* Create Texture without content. */
+ GPUTexture *tex = IMB_touch_gpu_texture(
+ main_ibuf, arraywidth, arrayheight, arraylayers, use_high_bitdepth);
+
+ GPU_texture_bind(tex, 0);
+
+ /* Upload each tile one by one. */
+ LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
+ int tilelayer = tile->runtime.tilearray_layer;
+ int *tileoffset = tile->runtime.tilearray_offset;
+ int *tilesize = tile->runtime.tilearray_size;
+
+ if (tilesize[0] == 0 || tilesize[1] == 0) {
+ continue;
+ }
+
+ ImageUser iuser;
+ BKE_imageuser_default(&iuser);
+ iuser.tile = tile->tile_number;
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
+
+ if (ibuf) {
+ const bool store_premultiplied = ibuf->rect_float ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) :
+ (ima->alpha_mode == IMA_ALPHA_PREMUL);
+ IMB_update_gpu_texture_sub(tex,
+ ibuf,
+ UNPACK2(tileoffset),
+ tilelayer,
+ UNPACK2(tilesize),
+ use_high_bitdepth,
+ store_premultiplied);
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+ }
+
+ if (GPU_mipmap_enabled()) {
+ GPU_texture_generate_mipmap(tex);
+ GPU_texture_mipmap_mode(tex, true, true);
+ if (ima) {
+ ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
+ }
+ }
+ else {
+ GPU_texture_mipmap_mode(tex, false, true);
+ }
+
+ GPU_texture_unbind(tex);
+
+ return tex;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Regular gpu texture
+ * \{ */
+
+static GPUTexture **get_image_gpu_texture_ptr(Image *ima,
+ eGPUTextureTarget textarget,
+ const int multiview_eye)
+{
+ const bool in_range = (textarget >= 0) && (textarget < TEXTARGET_COUNT);
+ BLI_assert(in_range);
+
+ if (in_range) {
+ return &(ima->gputexture[textarget][multiview_eye]);
+ }
+ return NULL;
+}
+
+static GPUTexture *image_gpu_texture_error_create(eGPUTextureTarget textarget)
+{
+ switch (textarget) {
+ case TEXTARGET_2D_ARRAY:
+ return GPU_texture_create_error(2, true);
+ case TEXTARGET_TILE_MAPPING:
+ return GPU_texture_create_error(1, true);
+ case TEXTARGET_2D:
+ default:
+ return GPU_texture_create_error(2, false);
+ }
+}
+
+static GPUTexture *image_get_gpu_texture(Image *ima,
+ ImageUser *iuser,
+ ImBuf *ibuf,
+ eGPUTextureTarget textarget)
+{
+ if (ima == NULL) {
+ return NULL;
+ }
+
+ /* Free any unused GPU textures, since we know we are in a thread with OpenGL
+ * context and might as well ensure we have as much space free as possible. */
+ gpu_free_unused_buffers();
+
+ /* currently, gpu refresh tagging is used by ima sequences */
+ if (ima->gpuflag & IMA_GPU_REFRESH) {
+ image_free_gpu(ima, true);
+ ima->gpuflag &= ~IMA_GPU_REFRESH;
+ }
+
+ /* Tag as in active use for garbage collector. */
+ BKE_image_tag_time(ima);
+
+ /* Test if we already have a texture. */
+ GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, iuser ? iuser->multiview_eye : 0);
+ if (*tex) {
+ return *tex;
+ }
+
+ /* Check if we have a valid image. If not, we return a dummy
+ * texture with zero bind-code so we don't keep trying. */
+ ImageTile *tile = BKE_image_get_tile(ima, 0);
+ if (tile == NULL || tile->ok == 0) {
+ *tex = image_gpu_texture_error_create(textarget);
+ return *tex;
+ }
+
+ /* check if we have a valid image buffer */
+ ImBuf *ibuf_intern = ibuf;
+ if (ibuf_intern == NULL) {
+ ibuf_intern = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ if (ibuf_intern == NULL) {
+ *tex = image_gpu_texture_error_create(textarget);
+ return *tex;
+ }
+ }
+
+ if (textarget == TEXTARGET_2D_ARRAY) {
+ *tex = gpu_texture_create_tile_array(ima, ibuf_intern);
+ }
+ else if (textarget == TEXTARGET_TILE_MAPPING) {
+ *tex = gpu_texture_create_tile_mapping(ima, iuser ? iuser->multiview_eye : 0);
+ }
+ else {
+ const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
+ const bool store_premultiplied = ibuf_intern->rect_float ?
+ (ima ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) : false) :
+ (ima ? (ima->alpha_mode == IMA_ALPHA_PREMUL) : true);
+
+ *tex = IMB_create_gpu_texture(ibuf_intern, use_high_bitdepth, store_premultiplied);
+
+ if (GPU_mipmap_enabled()) {
+ GPU_texture_bind(*tex, 0);
+ GPU_texture_generate_mipmap(*tex);
+ GPU_texture_unbind(*tex);
+ if (ima) {
+ ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
+ }
+ GPU_texture_mipmap_mode(*tex, true, true);
+ }
+ else {
+ GPU_texture_mipmap_mode(*tex, false, true);
+ }
+ }
+
+ /* if `ibuf` was given, we don't own the `ibuf_intern` */
+ if (ibuf == NULL) {
+ BKE_image_release_ibuf(ima, ibuf_intern, NULL);
+ }
+
+ GPU_texture_orig_size_set(*tex, ibuf_intern->x, ibuf_intern->y);
+
+ return *tex;
+}
+
+GPUTexture *BKE_image_get_gpu_texture(Image *image, ImageUser *iuser, ImBuf *ibuf)
+{
+ return image_get_gpu_texture(image, iuser, ibuf, TEXTARGET_2D);
+}
+
+GPUTexture *BKE_image_get_gpu_tiles(Image *image, ImageUser *iuser, ImBuf *ibuf)
+{
+ return image_get_gpu_texture(image, iuser, ibuf, TEXTARGET_2D_ARRAY);
+}
+
+GPUTexture *BKE_image_get_gpu_tilemap(Image *image, ImageUser *iuser, ImBuf *ibuf)
+{
+ return image_get_gpu_texture(image, iuser, ibuf, TEXTARGET_TILE_MAPPING);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delayed GPU texture free
+ *
+ * Image datablocks can be deleted by any thread, but there may not be any active OpenGL context.
+ * In that case we push them into a queue and free the buffers later.
+ * \{ */
+
+static LinkNode *gpu_texture_free_queue = NULL;
+static ThreadMutex gpu_texture_queue_mutex = BLI_MUTEX_INITIALIZER;
+
+static void gpu_free_unused_buffers(void)
+{
+ if (gpu_texture_free_queue == NULL) {
+ return;
+ }
+
+ BLI_mutex_lock(&gpu_texture_queue_mutex);
+
+ while (gpu_texture_free_queue != NULL) {
+ GPUTexture *tex = BLI_linklist_pop(&gpu_texture_free_queue);
+ GPU_texture_free(tex);
+ }
+
+ BLI_mutex_unlock(&gpu_texture_queue_mutex);
+}
+
+void BKE_image_free_unused_gpu_textures()
+{
+ if (BLI_thread_is_main()) {
+ gpu_free_unused_buffers();
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Deletion
+ * \{ */
+
+static void image_free_gpu(Image *ima, const bool immediate)
+{
+ for (int eye = 0; eye < 2; eye++) {
+ for (int i = 0; i < TEXTARGET_COUNT; i++) {
+ if (ima->gputexture[i][eye] != NULL) {
+ if (immediate) {
+ GPU_texture_free(ima->gputexture[i][eye]);
+ }
+ else {
+ BLI_mutex_lock(&gpu_texture_queue_mutex);
+ BLI_linklist_prepend(&gpu_texture_free_queue, ima->gputexture[i][eye]);
+ BLI_mutex_unlock(&gpu_texture_queue_mutex);
+ }
+
+ ima->gputexture[i][eye] = NULL;
+ }
+ }
+ }
+
+ ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
+}
+
+void BKE_image_free_gputextures(Image *ima)
+{
+ image_free_gpu(ima, BLI_thread_is_main());
+}
+
+void BKE_image_free_all_gputextures(Main *bmain)
+{
+ if (bmain) {
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
+ BKE_image_free_gputextures(ima);
+ }
+ }
+}
+
+/* same as above but only free animated images */
+void BKE_image_free_anim_gputextures(Main *bmain)
+{
+ if (bmain) {
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
+ if (BKE_image_is_animated(ima)) {
+ BKE_image_free_gputextures(ima);
+ }
+ }
+ }
+}
+
+void BKE_image_free_old_gputextures(Main *bmain)
+{
+ static int lasttime = 0;
+ int ctime = (int)PIL_check_seconds_timer();
+
+ /*
+ * Run garbage collector once for every collecting period of time
+ * if textimeout is 0, that's the option to NOT run the collector
+ */
+ if (U.textimeout == 0 || ctime % U.texcollectrate || ctime == lasttime) {
+ return;
+ }
+
+ /* of course not! */
+ if (G.is_rendering) {
+ return;
+ }
+
+ lasttime = ctime;
+
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
+ if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) {
+ /* If it's in GL memory, deallocate and set time tag to current time
+ * This gives textures a "second chance" to be used before dying. */
+ if (BKE_image_has_opengl_texture(ima)) {
+ BKE_image_free_gputextures(ima);
+ ima->lastused = ctime;
+ }
+ /* Otherwise, just kill the buffers */
+ else {
+ BKE_image_free_buffers(ima);
+ }
+ }
+ }
+}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Paint Update
+ * \{ */
+
+static ImBuf *update_do_scale(uchar *rect,
+ float *rect_float,
+ int *x,
+ int *y,
+ int *w,
+ int *h,
+ int limit_w,
+ int limit_h,
+ int full_w,
+ int full_h)
+{
+ /* Partial update with scaling. */
+ float xratio = limit_w / (float)full_w;
+ float yratio = limit_h / (float)full_h;
+
+ int part_w = *w, part_h = *h;
+
+ /* Find sub coordinates in scaled image. Take ceiling because we will be
+ * losing 1 pixel due to rounding errors in x,y. */
+ *x *= xratio;
+ *y *= yratio;
+ *w = (int)ceil(xratio * (*w));
+ *h = (int)ceil(yratio * (*h));
+
+ /* ...but take back if we are over the limit! */
+ if (*x + *w > limit_w) {
+ (*w)--;
+ }
+ if (*y + *h > limit_h) {
+ (*h)--;
+ }
+
+ /* Scale pixels. */
+ ImBuf *ibuf = IMB_allocFromBuffer((uint *)rect, rect_float, part_w, part_h, 4);
+ IMB_scaleImBuf(ibuf, *w, *h);
+
+ return ibuf;
+}
+
+static void gpu_texture_update_scaled(GPUTexture *tex,
+ uchar *rect,
+ float *rect_float,
+ int full_w,
+ int full_h,
+ int x,
+ int y,
+ int layer,
+ const int *tile_offset,
+ const int *tile_size,
+ int w,
+ int h)
+{
+ ImBuf *ibuf;
+ if (layer > -1) {
+ ibuf = update_do_scale(
+ rect, rect_float, &x, &y, &w, &h, tile_size[0], tile_size[1], full_w, full_h);
+
+ /* Shift to account for tile packing. */
+ x += tile_offset[0];
+ y += tile_offset[1];
+ }
+ else {
+ /* Partial update with scaling. */
+ int limit_w = smaller_power_of_2_limit(full_w);
+ int limit_h = smaller_power_of_2_limit(full_h);
+
+ ibuf = update_do_scale(rect, rect_float, &x, &y, &w, &h, limit_w, limit_h, full_w, full_h);
+ }
+
+ void *data = (ibuf->rect_float) ? (void *)(ibuf->rect_float) : (void *)(ibuf->rect);
+ eGPUDataFormat data_format = (ibuf->rect_float) ? GPU_DATA_FLOAT : GPU_DATA_UNSIGNED_BYTE;
+
+ GPU_texture_update_sub(tex, data_format, data, x, y, layer, w, h, 1);
+
+ IMB_freeImBuf(ibuf);
+}
+
+static void gpu_texture_update_unscaled(GPUTexture *tex,
+ uchar *rect,
+ float *rect_float,
+ int x,
+ int y,
+ int layer,
+ const int tile_offset[2],
+ int w,
+ int h,
+ int tex_stride,
+ int tex_offset)
+{
+ if (layer > -1) {
+ /* Shift to account for tile packing. */
+ x += tile_offset[0];
+ y += tile_offset[1];
+ }
+
+ void *data = (rect_float) ? (void *)(rect_float + tex_offset) : (void *)(rect + tex_offset);
+ eGPUDataFormat data_format = (rect_float) ? GPU_DATA_FLOAT : GPU_DATA_UNSIGNED_BYTE;
+
+ /* Partial update without scaling. Stride and offset are used to copy only a
+ * subset of a possible larger buffer than what we are updating. */
+ GPU_unpack_row_length_set(tex_stride);
+
+ GPU_texture_update_sub(tex, data_format, data, x, y, layer, w, h, 1);
+ /* Restore default. */
+ GPU_unpack_row_length_set(0);
+}
+
+static void gpu_texture_update_from_ibuf(
+ GPUTexture *tex, Image *ima, ImBuf *ibuf, ImageTile *tile, int x, int y, int w, int h)
+{
+ bool scaled;
+ if (tile != NULL) {
+ int *tilesize = tile->runtime.tilearray_size;
+ scaled = (ibuf->x != tilesize[0]) || (ibuf->y != tilesize[1]);
+ }
+ else {
+ scaled = is_over_resolution_limit(ibuf->x, ibuf->y);
+ }
+
+ if (scaled) {
+ /* Extra padding to account for bleed from neighboring pixels. */
+ const int padding = 4;
+ const int xmax = min_ii(x + w + padding, ibuf->x);
+ const int ymax = min_ii(y + h + padding, ibuf->y);
+ x = max_ii(x - padding, 0);
+ y = max_ii(y - padding, 0);
+ w = xmax - x;
+ h = ymax - y;
+ }
+
+ /* Get texture data pointers. */
+ float *rect_float = ibuf->rect_float;
+ uchar *rect = (uchar *)ibuf->rect;
+ int tex_stride = ibuf->x;
+ int tex_offset = ibuf->channels * (y * ibuf->x + x);
+
+ if (rect_float == NULL) {
+ /* Byte pixels. */
+ if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
+ const bool compress_as_srgb = !IMB_colormanagement_space_is_scene_linear(
+ ibuf->rect_colorspace);
+
+ rect = (uchar *)MEM_mallocN(sizeof(uchar[4]) * w * h, __func__);
+ if (rect == NULL) {
+ return;
+ }
+
+ tex_stride = w;
+ tex_offset = 0;
+
+ /* Convert to scene linear with sRGB compression, and premultiplied for
+ * correct texture interpolation. */
+ const bool store_premultiplied = (ima->alpha_mode == IMA_ALPHA_PREMUL);
+ IMB_colormanagement_imbuf_to_byte_texture(
+ rect, x, y, w, h, ibuf, compress_as_srgb, store_premultiplied);
+ }
+ }
+ else {
+ /* Float pixels. */
+ const bool store_premultiplied = (ima->alpha_mode != IMA_ALPHA_STRAIGHT);
+
+ if (ibuf->channels != 4 || scaled || !store_premultiplied) {
+ rect_float = (float *)MEM_mallocN(sizeof(float[4]) * w * h, __func__);
+ if (rect_float == NULL) {
+ return;
+ }
+
+ tex_stride = w;
+ tex_offset = 0;
+
+ IMB_colormanagement_imbuf_to_float_texture(
+ rect_float, x, y, w, h, ibuf, store_premultiplied);
+ }
+ }
+
+ GPU_texture_bind(tex, 0);
+
+ if (scaled) {
+ /* Slower update where we first have to scale the input pixels. */
+ if (tile != NULL) {
+ int *tileoffset = tile->runtime.tilearray_offset;
+ int *tilesize = tile->runtime.tilearray_size;
+ int tilelayer = tile->runtime.tilearray_layer;
+ gpu_texture_update_scaled(
+ tex, rect, rect_float, ibuf->x, ibuf->y, x, y, tilelayer, tileoffset, tilesize, w, h);
+ }
+ else {
+ gpu_texture_update_scaled(
+ tex, rect, rect_float, ibuf->x, ibuf->y, x, y, -1, NULL, NULL, w, h);
+ }
+ }
+ else {
+ /* Fast update at same resolution. */
+ if (tile != NULL) {
+ int *tileoffset = tile->runtime.tilearray_offset;
+ int tilelayer = tile->runtime.tilearray_layer;
+ gpu_texture_update_unscaled(
+ tex, rect, rect_float, x, y, tilelayer, tileoffset, w, h, tex_stride, tex_offset);
+ }
+ else {
+ gpu_texture_update_unscaled(
+ tex, rect, rect_float, x, y, -1, NULL, w, h, tex_stride, tex_offset);
+ }
+ }
+
+ /* Free buffers if needed. */
+ if (rect && rect != (uchar *)ibuf->rect) {
+ MEM_freeN(rect);
+ }
+ if (rect_float && rect_float != ibuf->rect_float) {
+ MEM_freeN(rect_float);
+ }
+
+ if (GPU_mipmap_enabled()) {
+ GPU_texture_generate_mipmap(tex);
+ }
+ else {
+ ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
+ }
+
+ GPU_texture_unbind(tex);
+}
+
+/* Partial update of texture for texture painting. This is often much
+ * quicker than fully updating the texture for high resolution images. */
+void BKE_image_update_gputexture(Image *ima, ImageUser *iuser, int x, int y, int w, int h)
+{
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ ImageTile *tile = BKE_image_get_tile_from_iuser(ima, iuser);
+
+ if ((ibuf == NULL) || (w == 0) || (h == 0)) {
+ /* Full reload of texture. */
+ BKE_image_free_gputextures(ima);
+ }
+
+ GPUTexture *tex = ima->gputexture[TEXTARGET_2D][0];
+ /* Check if we need to update the main gputexture. */
+ if (tex != NULL && tile == ima->tiles.first) {
+ gpu_texture_update_from_ibuf(tex, ima, ibuf, NULL, x, y, w, h);
+ }
+
+ /* Check if we need to update the array gputexture. */
+ tex = ima->gputexture[TEXTARGET_2D_ARRAY][0];
+ if (tex != NULL) {
+ gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h);
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, NULL);
+}
+
+/* these two functions are called on entering and exiting texture paint mode,
+ * temporary disabling/enabling mipmapping on all images for quick texture
+ * updates with glTexSubImage2D. images that didn't change don't have to be
+ * re-uploaded to OpenGL */
+void BKE_image_paint_set_mipmap(Main *bmain, bool mipmap)
+{
+ LISTBASE_FOREACH (Image *, ima, &bmain->images) {
+ if (BKE_image_has_opengl_texture(ima)) {
+ if (ima->gpuflag & IMA_GPU_MIPMAP_COMPLETE) {
+ for (int eye = 0; eye < 2; eye++) {
+ for (int a = 0; a < TEXTARGET_COUNT; a++) {
+ if (ELEM(a, TEXTARGET_2D, TEXTARGET_2D_ARRAY)) {
+ GPUTexture *tex = ima->gputexture[a][eye];
+ if (tex != NULL) {
+ GPU_texture_mipmap_mode(tex, mipmap, true);
+ }
+ }
+ }
+ }
+ }
+ else {
+ BKE_image_free_gputextures(ima);
+ }
+ }
+ else {
+ ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
+ }
+ }
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 7bf9cb2d0a1..94a142600b6 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -158,7 +158,7 @@ static AdrBit2Path ob_layer_bits[] = {
/* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */
#define RET_ABP(items) \
{ \
- *tot = sizeof(items) / sizeof(AdrBit2Path); \
+ *tot = ARRAY_SIZE(items); \
return items; \
} \
(void)0
@@ -517,9 +517,8 @@ static const char *mtex_adrcodes_to_paths(int adrcode, int *UNUSED(array_index))
BLI_snprintf(buf, 128, "%s.%s", base, prop);
return buf;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/* Texture types */
@@ -1074,10 +1073,9 @@ static char *get_rna_access(ID *id,
return NULL;
}
- else {
- if (array_index) {
- *array_index = dummy_index;
- }
+
+ if (array_index) {
+ *array_index = dummy_index;
}
/* 'buf' _must_ be initialized in this block */
@@ -1976,7 +1974,7 @@ void do_versions_ipos_to_animato(Main *bmain)
CLOG_WARN(&LOG, "Animation data too new to convert (Version %d)", bmain->versionfile);
return;
}
- else if (G.debug & G_DEBUG) {
+ if (G.debug & G_DEBUG) {
printf("INFO: Converting to Animato...\n");
}
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index a71b9cc2a1d..0108befa710 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -569,7 +569,7 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
if (me->edit_mesh && me->edit_mesh->bm->totvert == kb->totelem) {
a = 0;
- co = MEM_mallocN(sizeof(float) * 3 * me->edit_mesh->bm->totvert, "key_block_get_data");
+ co = MEM_mallocN(sizeof(float[3]) * me->edit_mesh->bm->totvert, "key_block_get_data");
BM_ITER_MESH (eve, &iter, me->edit_mesh->bm, BM_VERTS_OF_MESH) {
copy_v3_v3(co[a], eve->co);
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 4d523ffa2e0..4d073593da7 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -356,9 +356,8 @@ bool object_deform_mball(Object *ob, ListBase *dispbase)
return true;
}
- else {
- return false;
- }
+
+ return false;
}
static BPoint *latt_bp(Lattice *lt, int u, int v, int w)
@@ -575,9 +574,8 @@ struct BPoint *BKE_lattice_active_point_get(Lattice *lt)
if ((lt->actbp != LT_ACTBP_NONE) && (lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw)) {
return &lt->def[lt->actbp];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
void BKE_lattice_center_median(Lattice *lt, float cent[3])
diff --git a/source/blender/blenkernel/intern/lattice_deform.c b/source/blender/blenkernel/intern/lattice_deform.c
index 674ee9ed2c5..33f7d9851db 100644
--- a/source/blender/blenkernel/intern/lattice_deform.c
+++ b/source/blender/blenkernel/intern/lattice_deform.c
@@ -80,7 +80,7 @@ LatticeDeformData *BKE_lattice_deform_data_create(const Object *oblatt, const Ob
}
bp = lt->def;
- fp = latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw,
+ fp = latticedata = MEM_mallocN(sizeof(float[3]) * lt->pntsu * lt->pntsv * lt->pntsw,
"latticedata");
/* for example with a particle system: (ob == NULL) */
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 64649d84320..cf6139d9449 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -221,7 +221,7 @@ ViewLayer *BKE_view_layer_add(Scene *scene,
view_layer_new = view_layer_add(name);
BLI_addtail(&scene->view_layers, view_layer_new);
- /* Initialise layercollections */
+ /* Initialize layer-collections. */
BKE_layer_collection_sync(scene, view_layer_new);
layer_collection_exclude_all(view_layer_new->layer_collections.first);
@@ -555,21 +555,19 @@ static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc)
if (lc->flag & LAYER_COLLECTION_HIDE || lc->collection->flag & COLLECTION_RESTRICT_VIEWPORT) {
return true;
}
- else {
- /* Restriction flags stay set, so we need to check parents */
- CollectionParent *parent = lc->collection->parents.first;
- if (parent) {
- lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
+ /* Restriction flags stay set, so we need to check parents */
+ CollectionParent *parent = lc->collection->parents.first;
- return lc && layer_collection_hidden(view_layer, lc);
- }
- else {
- return false;
- }
+ if (parent) {
+ lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
+
+ return lc && layer_collection_hidden(view_layer, lc);
}
return false;
+
+ return false;
}
/**
@@ -1610,10 +1608,9 @@ void BKE_view_layer_selected_editable_objects_iterator_begin(BLI_Iterator *iter,
// First object is valid (selectable and not libdata) -> all good.
return;
}
- else {
- // Object is selectable but not editable -> search for another one.
- BKE_view_layer_selected_editable_objects_iterator_next(iter);
- }
+
+ // Object is selectable but not editable -> search for another one.
+ BKE_view_layer_selected_editable_objects_iterator_next(iter);
}
}
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index a64e550579d..3b7aae98327 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -2203,13 +2203,12 @@ char *BKE_id_to_unique_string_key(const struct ID *id)
if (id->lib == NULL) {
return BLI_strdup(id->name);
}
- else {
- /* Prefix with an ascii character in the range of 32..96 (visible)
- * this ensures we can't have a library ID pair that collide.
- * Where 'LIfooOBbarOBbaz' could be ('LIfoo, OBbarOBbaz') or ('LIfooOBbar', 'OBbaz'). */
- const char ascii_len = strlen(id->lib->id.name + 2) + 32;
- return BLI_sprintfN("%c%s%s", ascii_len, id->lib->id.name, id->name);
- }
+
+ /* Prefix with an ascii character in the range of 32..96 (visible)
+ * this ensures we can't have a library ID pair that collide.
+ * Where 'LIfooOBbarOBbaz' could be ('LIfoo, OBbarOBbaz') or ('LIfooOBbar', 'OBbaz'). */
+ const char ascii_len = strlen(id->lib->id.name + 2) + 32;
+ return BLI_sprintfN("%c%s%s", ascii_len, id->lib->id.name, id->name);
}
void BKE_id_tag_set_atomic(ID *id, int tag)
@@ -2258,7 +2257,7 @@ static int id_order_compare(const void *a, const void *b)
if (*order_a < *order_b) {
return -1;
}
- else if (*order_a > *order_b) {
+ if (*order_a > *order_b) {
return 1;
}
}
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 6929d3a3c4b..5b45148ed63 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -117,9 +117,8 @@ void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_f
BKE_lib_override_library_free(&dst_id->override_library, true);
return;
}
- else {
- BKE_lib_override_library_clear(dst_id->override_library, true);
- }
+
+ BKE_lib_override_library_clear(dst_id->override_library, true);
}
else if (src_id->override_library == NULL) {
/* Virtual overrides of embedded data does not require any extra work. */
@@ -1523,7 +1522,7 @@ void BKE_lib_override_library_main_update(Main *bmain)
*/
/** Initialize an override storage. */
-OverrideLibraryStorage *BKE_lib_override_library_operations_store_initialize(void)
+OverrideLibraryStorage *BKE_lib_override_library_operations_store_init(void)
{
return BKE_main_new();
}
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 00a42b12e07..e687e94073d 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -96,9 +96,8 @@ bool BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, int
}
return true;
}
- else {
- return false;
- }
+
+ return false;
}
int BKE_lib_query_foreachid_process_flags_get(LibraryForeachIDData *data)
@@ -412,6 +411,8 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
return ELEM(id_type_used, ID_MA);
case ID_VO:
return ELEM(id_type_used, ID_MA);
+ case ID_SIM:
+ return ELEM(id_type_used, ID_OB, ID_IM);
case ID_IM:
case ID_VF:
case ID_TXT:
@@ -422,7 +423,6 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
case ID_PAL:
case ID_PC:
case ID_CF:
- case ID_SIM:
/* Those types never use/reference other IDs... */
return false;
case ID_IP:
diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c
index aa1005c663f..f42df6765c4 100644
--- a/source/blender/blenkernel/intern/light.c
+++ b/source/blender/blenkernel/intern/light.c
@@ -58,7 +58,7 @@ static void light_init_data(ID *id)
MEMCPY_STRUCT_AFTER(la, DNA_struct_default_get(Light), id);
la->curfalloff = BKE_curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
- BKE_curvemapping_initialize(la->curfalloff);
+ BKE_curvemapping_init(la->curfalloff);
}
/**
diff --git a/source/blender/blenkernel/intern/main_idmap.c b/source/blender/blenkernel/intern/main_idmap.c
index d5499374e06..718af1f032d 100644
--- a/source/blender/blenkernel/intern/main_idmap.c
+++ b/source/blender/blenkernel/intern/main_idmap.c
@@ -166,7 +166,7 @@ static bool idkey_cmp(const void *a, const void *b)
{
const struct IDNameLib_Key *idkey_a = a;
const struct IDNameLib_Key *idkey_b = b;
- return strcmp(idkey_a->name, idkey_b->name) || (idkey_a->lib != idkey_b->lib);
+ return !STREQ(idkey_a->name, idkey_b->name) || (idkey_a->lib != idkey_b->lib);
}
ID *BKE_main_idmap_lookup_name(struct IDNameLib_Map *id_map,
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 7e859799a4e..444ed0c65b5 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -124,13 +124,11 @@ static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline,
if (spline->flag & MASK_SPLINE_CYCLIC) {
return &points_array[0];
}
- else {
- return NULL;
- }
- }
- else {
- return point + 1;
+
+ return NULL;
}
+
+ return point + 1;
}
static MaskSplinePoint *mask_spline_point_prev(MaskSpline *spline,
@@ -141,13 +139,11 @@ static MaskSplinePoint *mask_spline_point_prev(MaskSpline *spline,
if (spline->flag & MASK_SPLINE_CYCLIC) {
return &points_array[spline->tot_point - 1];
}
- else {
- return NULL;
- }
- }
- else {
- return point - 1;
+
+ return NULL;
}
+
+ return point - 1;
}
BezTriple *BKE_mask_spline_point_next_bezt(MaskSpline *spline,
@@ -158,13 +154,11 @@ BezTriple *BKE_mask_spline_point_next_bezt(MaskSpline *spline,
if (spline->flag & MASK_SPLINE_CYCLIC) {
return &(points_array[0].bezt);
}
- else {
- return NULL;
- }
- }
- else {
- return &((point + 1))->bezt;
+
+ return NULL;
}
+
+ return &((point + 1))->bezt;
}
MaskSplinePoint *BKE_mask_spline_point_array(MaskSpline *spline)
@@ -703,15 +697,14 @@ float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, c
if (!bezt_next) {
return bezt->weight;
}
- else if (u <= 0.0f) {
+ if (u <= 0.0f) {
return bezt->weight;
}
- else if (u >= 1.0f) {
+ if (u >= 1.0f) {
return bezt_next->weight;
}
- else {
- return mask_point_interp_weight(bezt, bezt_next, u);
- }
+
+ return mask_point_interp_weight(bezt, bezt_next, u);
}
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const float u)
@@ -724,53 +717,51 @@ float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const fl
if (!bezt_next) {
return bezt->weight;
}
- else if (u <= 0.0f) {
+ if (u <= 0.0f) {
return bezt->weight;
}
- else if (u >= 1.0f) {
+ if (u >= 1.0f) {
return bezt_next->weight;
}
- else {
- float cur_u = 0.0f, cur_w = 0.0f, next_u = 0.0f, next_w = 0.0f, fac; /* Quite warnings */
- int i;
- for (i = 0; i <= point->tot_uw; i++) {
+ float cur_u = 0.0f, cur_w = 0.0f, next_u = 0.0f, next_w = 0.0f, fac; /* Quite warnings */
+ int i;
- if (i == 0) {
- cur_u = 0.0f;
- cur_w = 1.0f; /* mask_point_interp_weight will scale it */
- }
- else {
- cur_u = point->uw[i - 1].u;
- cur_w = point->uw[i - 1].w;
- }
+ for (i = 0; i <= point->tot_uw; i++) {
- if (i == point->tot_uw) {
- next_u = 1.0f;
- next_w = 1.0f; /* mask_point_interp_weight will scale it */
- }
- else {
- next_u = point->uw[i].u;
- next_w = point->uw[i].w;
- }
-
- if (u >= cur_u && u <= next_u) {
- break;
- }
+ if (i == 0) {
+ cur_u = 0.0f;
+ cur_w = 1.0f; /* mask_point_interp_weight will scale it */
+ }
+ else {
+ cur_u = point->uw[i - 1].u;
+ cur_w = point->uw[i - 1].w;
}
- fac = (u - cur_u) / (next_u - cur_u);
-
- cur_w *= mask_point_interp_weight(bezt, bezt_next, cur_u);
- next_w *= mask_point_interp_weight(bezt, bezt_next, next_u);
-
- if (spline->weight_interp == MASK_SPLINE_INTERP_EASE) {
- return cur_w + (next_w - cur_w) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
+ if (i == point->tot_uw) {
+ next_u = 1.0f;
+ next_w = 1.0f; /* mask_point_interp_weight will scale it */
}
else {
- return (1.0f - fac) * cur_w + fac * next_w;
+ next_u = point->uw[i].u;
+ next_w = point->uw[i].w;
}
+
+ if (u >= cur_u && u <= next_u) {
+ break;
+ }
+ }
+
+ fac = (u - cur_u) / (next_u - cur_u);
+
+ cur_w *= mask_point_interp_weight(bezt, bezt_next, cur_u);
+ next_w *= mask_point_interp_weight(bezt, bezt_next, next_u);
+
+ if (spline->weight_interp == MASK_SPLINE_INTERP_EASE) {
+ return cur_w + (next_w - cur_w) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
}
+
+ return (1.0f - fac) * cur_w + fac * next_w;
}
MaskSplinePointUW *BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePointUW *uw)
@@ -1521,7 +1512,8 @@ static void mask_layer_shape_from_mask_point(BezTriple *bezt,
fp[7] = bezt->radius;
}
-static void mask_layer_shape_to_mask_point(BezTriple *bezt, float fp[MASK_OBJECT_SHAPE_ELEM_SIZE])
+static void mask_layer_shape_to_mask_point(BezTriple *bezt,
+ const float fp[MASK_OBJECT_SHAPE_ELEM_SIZE])
{
copy_v2_v2(bezt->vec[0], &fp[0]);
copy_v2_v2(bezt->vec[1], &fp[2]);
@@ -1642,7 +1634,7 @@ MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, const int fr
if (frame == masklay_shape->frame) {
return masklay_shape;
}
- else if (frame < masklay_shape->frame) {
+ if (frame < masklay_shape->frame) {
break;
}
}
@@ -1667,17 +1659,16 @@ int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay,
*r_masklay_shape_b = NULL;
return 1;
}
- else if (frame < masklay_shape->frame) {
+ if (frame < masklay_shape->frame) {
if (masklay_shape->prev) {
*r_masklay_shape_a = masklay_shape->prev;
*r_masklay_shape_b = masklay_shape;
return 2;
}
- else {
- *r_masklay_shape_a = masklay_shape;
- *r_masklay_shape_b = NULL;
- return 1;
- }
+
+ *r_masklay_shape_a = masklay_shape;
+ *r_masklay_shape_b = NULL;
+ return 1;
}
}
@@ -1686,12 +1677,11 @@ int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay,
*r_masklay_shape_b = NULL;
return 1;
}
- else {
- *r_masklay_shape_a = NULL;
- *r_masklay_shape_b = NULL;
- return 0;
- }
+ *r_masklay_shape_a = NULL;
+ *r_masklay_shape_b = NULL;
+
+ return 0;
}
MaskLayerShape *BKE_mask_layer_shape_verify_frame(MaskLayer *masklay, const int frame)
@@ -1738,12 +1728,11 @@ static int mask_layer_shape_sort_cb(const void *masklay_shape_a_ptr,
if (masklay_shape_a->frame < masklay_shape_b->frame) {
return -1;
}
- else if (masklay_shape_a->frame > masklay_shape_b->frame) {
+ if (masklay_shape_a->frame > masklay_shape_b->frame) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
void BKE_mask_layer_shape_sort(MaskLayer *masklay)
diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c
index 9b281103a0f..2fbf5f8648d 100644
--- a/source/blender/blenkernel/intern/mask_evaluate.c
+++ b/source/blender/blenkernel/intern/mask_evaluate.c
@@ -126,9 +126,8 @@ int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const uns
if (spline->flag & MASK_SPLINE_CYCLIC) {
return spline->tot_point * resol;
}
- else {
- return ((spline->tot_point - 1) * resol) + 1;
- }
+
+ return ((spline->tot_point - 1) * resol) + 1;
}
float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline,
@@ -179,7 +178,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline,
bezt_curr->vec[1][j],
&(*fp)[j],
resol,
- 2 * sizeof(float));
+ sizeof(float[2]));
}
fp += resol;
@@ -688,7 +687,7 @@ static float (*mask_spline_feather_differentiated_points_with_resolution__double
bezt_curr->vec[1][j],
&(*fp)[j],
resol,
- 2 * sizeof(float));
+ sizeof(float[2]));
}
/* scale by the uw's */
@@ -846,7 +845,7 @@ float *BKE_mask_point_segment_diff(MaskSpline *spline,
/* resol+1 because of 'forward_diff_bezier' function */
*tot_diff_point = resol + 1;
- diff_points = fp = MEM_callocN((resol + 1) * 2 * sizeof(float), "mask segment vets");
+ diff_points = fp = MEM_callocN(sizeof(float[2]) * (resol + 1), "mask segment vets");
for (j = 0; j < 2; j++) {
BKE_curve_forward_diff_bezier(bezt->vec[1][j],
@@ -855,7 +854,7 @@ float *BKE_mask_point_segment_diff(MaskSpline *spline,
bezt_next->vec[1][j],
fp + j,
resol,
- 2 * sizeof(float));
+ sizeof(float[2]));
}
copy_v2_v2(fp + 2 * resol, bezt_next->vec[1]);
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c
index 01d44d070b3..92885535f57 100644
--- a/source/blender/blenkernel/intern/mask_rasterize.c
+++ b/source/blender/blenkernel/intern/mask_rasterize.c
@@ -354,43 +354,38 @@ static bool layer_bucket_isect_test(const MaskRasterLayer *layer,
if (isect_point_tri_v2(cent, v1, v2, v3)) {
return true;
}
- else {
- if ((dist_squared_to_line_segment_v2(cent, v1, v2) < bucket_max_rad_squared) ||
- (dist_squared_to_line_segment_v2(cent, v2, v3) < bucket_max_rad_squared) ||
- (dist_squared_to_line_segment_v2(cent, v3, v1) < bucket_max_rad_squared)) {
- return true;
- }
- else {
- // printf("skip tri\n");
- return false;
- }
- }
- }
- else {
- const float *v1 = cos[face[0]];
- const float *v2 = cos[face[1]];
- const float *v3 = cos[face[2]];
- const float *v4 = cos[face[3]];
- if (isect_point_tri_v2(cent, v1, v2, v3)) {
+ if ((dist_squared_to_line_segment_v2(cent, v1, v2) < bucket_max_rad_squared) ||
+ (dist_squared_to_line_segment_v2(cent, v2, v3) < bucket_max_rad_squared) ||
+ (dist_squared_to_line_segment_v2(cent, v3, v1) < bucket_max_rad_squared)) {
return true;
}
- else if (isect_point_tri_v2(cent, v1, v3, v4)) {
- return true;
- }
- else {
- if ((dist_squared_to_line_segment_v2(cent, v1, v2) < bucket_max_rad_squared) ||
- (dist_squared_to_line_segment_v2(cent, v2, v3) < bucket_max_rad_squared) ||
- (dist_squared_to_line_segment_v2(cent, v3, v4) < bucket_max_rad_squared) ||
- (dist_squared_to_line_segment_v2(cent, v4, v1) < bucket_max_rad_squared)) {
- return true;
- }
- else {
- // printf("skip quad\n");
- return false;
- }
- }
+
+ // printf("skip tri\n");
+ return false;
+ }
+
+ const float *v1 = cos[face[0]];
+ const float *v2 = cos[face[1]];
+ const float *v3 = cos[face[2]];
+ const float *v4 = cos[face[3]];
+
+ if (isect_point_tri_v2(cent, v1, v2, v3)) {
+ return true;
+ }
+ if (isect_point_tri_v2(cent, v1, v3, v4)) {
+ return true;
}
+
+ if ((dist_squared_to_line_segment_v2(cent, v1, v2) < bucket_max_rad_squared) ||
+ (dist_squared_to_line_segment_v2(cent, v2, v3) < bucket_max_rad_squared) ||
+ (dist_squared_to_line_segment_v2(cent, v3, v4) < bucket_max_rad_squared) ||
+ (dist_squared_to_line_segment_v2(cent, v4, v1) < bucket_max_rad_squared)) {
+ return true;
+ }
+
+ // printf("skip quad\n");
+ return false;
}
static void layer_bucket_init_dummy(MaskRasterLayer *layer)
@@ -791,7 +786,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
co_feather[2] = 1.0f;
if (spline->flag & MASK_SPLINE_NOINTERSECT) {
- diff_feather_points_flip = MEM_mallocN(sizeof(float) * 2 * tot_diff_feather_points,
+ diff_feather_points_flip = MEM_mallocN(sizeof(float[2]) * tot_diff_feather_points,
"diff_feather_points_flip");
for (j = 0; j < tot_diff_point; j++) {
@@ -944,7 +939,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
ListBase isect_remedgebase = {NULL, NULL};
/* now we have all the splines */
- face_coords = MEM_mallocN((sizeof(float) * 3) * sf_vert_tot, "maskrast_face_coords");
+ face_coords = MEM_mallocN((sizeof(float[3])) * sf_vert_tot, "maskrast_face_coords");
/* init bounds */
BLI_rctf_init_minmax(&bounds);
@@ -1348,9 +1343,8 @@ static float layer_bucket_depth_from_xy(MaskRasterLayer *layer, const float xy[2
}
return best_dist;
}
- else {
- return 1.0f;
- }
+
+ return 1.0f;
}
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2])
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index b0b542f6000..0520ba3faae 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -268,27 +268,27 @@ Material ***BKE_object_material_array_p(Object *ob)
Mesh *me = ob->data;
return &(me->mat);
}
- else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
+ if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
Curve *cu = ob->data;
return &(cu->mat);
}
- else if (ob->type == OB_MBALL) {
+ if (ob->type == OB_MBALL) {
MetaBall *mb = ob->data;
return &(mb->mat);
}
- else if (ob->type == OB_GPENCIL) {
+ if (ob->type == OB_GPENCIL) {
bGPdata *gpd = ob->data;
return &(gpd->mat);
}
- else if (ob->type == OB_HAIR) {
+ if (ob->type == OB_HAIR) {
Hair *hair = ob->data;
return &(hair->mat);
}
- else if (ob->type == OB_POINTCLOUD) {
+ if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
return &(pointcloud->mat);
}
- else if (ob->type == OB_VOLUME) {
+ if (ob->type == OB_VOLUME) {
Volume *volume = ob->data;
return &(volume->mat);
}
@@ -301,27 +301,27 @@ short *BKE_object_material_len_p(Object *ob)
Mesh *me = ob->data;
return &(me->totcol);
}
- else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
+ if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
Curve *cu = ob->data;
return &(cu->totcol);
}
- else if (ob->type == OB_MBALL) {
+ if (ob->type == OB_MBALL) {
MetaBall *mb = ob->data;
return &(mb->totcol);
}
- else if (ob->type == OB_GPENCIL) {
+ if (ob->type == OB_GPENCIL) {
bGPdata *gpd = ob->data;
return &(gpd->totcol);
}
- else if (ob->type == OB_HAIR) {
+ if (ob->type == OB_HAIR) {
Hair *hair = ob->data;
return &(hair->totcol);
}
- else if (ob->type == OB_POINTCLOUD) {
+ if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
return &(pointcloud->totcol);
}
- else if (ob->type == OB_VOLUME) {
+ if (ob->type == OB_VOLUME) {
Volume *volume = ob->data;
return &(volume->totcol);
}
@@ -582,7 +582,7 @@ Material **BKE_object_material_get_p(Object *ob, short act)
if (act > ob->totcol) {
return NULL;
}
- else if (act <= 0) {
+ if (act <= 0) {
if (act < 0) {
CLOG_ERROR(&LOG, "Negative material index!");
}
@@ -627,9 +627,8 @@ Material *BKE_gpencil_material(Object *ob, short act)
if (ma != NULL) {
return ma;
}
- else {
- return BKE_material_default_gpencil();
- }
+
+ return BKE_material_default_gpencil();
}
MaterialGPencilStyle *BKE_gpencil_material_settings(Object *ob, short act)
@@ -642,9 +641,8 @@ MaterialGPencilStyle *BKE_gpencil_material_settings(Object *ob, short act)
return ma->gp_style;
}
- else {
- return BKE_material_default_gpencil()->gp_style;
- }
+
+ return BKE_material_default_gpencil()->gp_style;
}
void BKE_object_material_resize(Main *bmain, Object *ob, const short totcol, bool do_id_user)
@@ -959,14 +957,13 @@ void BKE_object_material_array_assign(Main *bmain,
const bool to_object_only)
{
int actcol_orig = ob->actcol;
- short i;
while ((ob->totcol > totcol) && BKE_object_material_slot_remove(bmain, ob)) {
/* pass */
}
/* now we have the right number of slots */
- for (i = 0; i < totcol; i++) {
+ for (int i = 0; i < totcol; i++) {
if (to_object_only && ob->matbits[i] == 0) {
/* If we only assign to object, and that slot uses obdata material, do nothing. */
continue;
@@ -1136,9 +1133,8 @@ static bNode *nodetree_uv_node_recursive(bNode *node)
if (inode->typeinfo->nclass == NODE_CLASS_INPUT && inode->typeinfo->type == SH_NODE_UVMAP) {
return inode;
}
- else {
- return nodetree_uv_node_recursive(inode);
- }
+
+ return nodetree_uv_node_recursive(inode);
}
}
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index 94e5f435a43..de07c96e3f0 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -281,7 +281,7 @@ float *BKE_mball_make_orco(Object *ob, ListBase *dispbase)
size[2] = bb->vec[1][2] - loc[2];
dl = dispbase->first;
- orcodata = MEM_mallocN(sizeof(float) * 3 * dl->nr, "MballOrco");
+ orcodata = MEM_mallocN(sizeof(float[3]) * dl->nr, "MballOrco");
data = dl->verts;
orco = orcodata;
@@ -341,9 +341,8 @@ bool BKE_mball_is_basis_for(Object *ob1, Object *ob2)
if (STREQ(basis1name, basis2name)) {
return BKE_mball_is_basis(ob1);
}
- else {
- return false;
- }
+
+ return false;
}
bool BKE_mball_is_any_selected(const MetaBall *mb)
diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c
index 72b99bea0f4..2a7d3f1797d 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.c
+++ b/source/blender/blenkernel/intern/mball_tessellate.c
@@ -405,7 +405,7 @@ static float densfunc(const MetaElem *ball, float x, float y, float z)
}
/**
- * Computes density at given position form all metaballs which contain this point in their box.
+ * Computes density at given position form all meta-balls which contain this point in their box.
* Traverses BVH using a queue.
*/
static float metaball(PROCESS *process, float x, float y, float z)
@@ -1276,8 +1276,8 @@ static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Obje
new_ml = BLI_memarena_alloc(process->pgn_elements, sizeof(MetaElem));
*(new_ml) = *ml;
new_ml->bb = BLI_memarena_alloc(process->pgn_elements, sizeof(BoundBox));
- new_ml->mat = BLI_memarena_alloc(process->pgn_elements, 4 * 4 * sizeof(float));
- new_ml->imat = BLI_memarena_alloc(process->pgn_elements, 4 * 4 * sizeof(float));
+ new_ml->mat = BLI_memarena_alloc(process->pgn_elements, sizeof(float[4][4]));
+ new_ml->imat = BLI_memarena_alloc(process->pgn_elements, sizeof(float[4][4]));
/* too big stiffness seems only ugly due to linear interpolation
* no need to have possibility for too big stiffness */
@@ -1443,9 +1443,9 @@ void BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBa
if (process.totelem > 0) {
build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb);
- /* Don't polygonize metaballs with too high resolution (base mball to small)
- * note: Eps was 0.0001f but this was giving problems for blood animation for durian,
- * using 0.00001f. */
+ /* Don't polygonize meta-balls with too high resolution (base mball to small)
+ * note: Eps was 0.0001f but this was giving problems for blood animation for
+ * the open movie "Sintel", using 0.00001f. */
if (ob->scale[0] > 0.00001f * (process.allbb.max[0] - process.allbb.min[0]) ||
ob->scale[1] > 0.00001f * (process.allbb.max[1] - process.allbb.min[1]) ||
ob->scale[2] > 0.00001f * (process.allbb.max[2] - process.allbb.min[2])) {
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 4822df3f063..2a16d0eb0f8 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -599,9 +599,8 @@ bool BKE_mesh_has_custom_loop_normals(Mesh *me)
if (me->edit_mesh) {
return CustomData_has_layer(&me->edit_mesh->bm->ldata, CD_CUSTOMLOOPNORMAL);
}
- else {
- return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
- }
+
+ return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
}
/** Free (or release) any data used by this mesh (does not free the mesh itself). */
@@ -1104,9 +1103,8 @@ Mesh *BKE_mesh_from_object(Object *ob)
if (ob->type == OB_MESH) {
return ob->data;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
void BKE_mesh_assign_object(Main *bmain, Object *ob, Mesh *me)
@@ -1278,12 +1276,11 @@ int BKE_mesh_edge_other_vert(const MEdge *e, int v)
if (e->v1 == v) {
return e->v2;
}
- else if (e->v2 == v) {
+ if (e->v2 == v) {
return e->v1;
}
- else {
- return -1;
- }
+
+ return -1;
}
/**
@@ -1414,30 +1411,29 @@ void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
if (UNLIKELY(mesh->cd_flag)) {
return;
}
- else {
- MVert *mv;
- MEdge *med;
- int i;
- for (mv = mesh->mvert, i = 0; i < mesh->totvert; mv++, i++) {
- if (mv->bweight != 0) {
- mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
- break;
- }
+ MVert *mv;
+ MEdge *med;
+ int i;
+
+ for (mv = mesh->mvert, i = 0; i < mesh->totvert; mv++, i++) {
+ if (mv->bweight != 0) {
+ mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
+ break;
}
+ }
- for (med = mesh->medge, i = 0; i < mesh->totedge; med++, i++) {
- if (med->bweight != 0) {
- mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
- if (mesh->cd_flag & ME_CDFLAG_EDGE_CREASE) {
- break;
- }
+ for (med = mesh->medge, i = 0; i < mesh->totedge; med++, i++) {
+ if (med->bweight != 0) {
+ mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
+ if (mesh->cd_flag & ME_CDFLAG_EDGE_CREASE) {
+ break;
}
- if (med->crease != 0) {
- mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE;
- if (mesh->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
- break;
- }
+ }
+ if (med->crease != 0) {
+ mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE;
+ if (mesh->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
+ break;
}
}
}
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index a0f3bc9e74d..76a6d23bc8f 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -314,11 +314,11 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob,
*r_allvert = mvert = MEM_calloc_arrayN(totvert, sizeof(MVert), "nurbs_init mvert");
*r_alledge = medge = MEM_calloc_arrayN(totedge, sizeof(MEdge), "nurbs_init medge");
*r_allloop = mloop = MEM_calloc_arrayN(
- totpoly, 4 * sizeof(MLoop), "nurbs_init mloop"); // totloop
+ totpoly, sizeof(MLoop[4]), "nurbs_init mloop"); // totloop
*r_allpoly = mpoly = MEM_calloc_arrayN(totpoly, sizeof(MPoly), "nurbs_init mloop");
if (r_alluv) {
- *r_alluv = mloopuv = MEM_calloc_arrayN(totpoly, 4 * sizeof(MLoopUV), "nurbs_init mloopuv");
+ *r_alluv = mloopuv = MEM_calloc_arrayN(totpoly, sizeof(MLoopUV[4]), "nurbs_init mloopuv");
}
/* verts and faces */
@@ -1298,11 +1298,11 @@ static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src)
mesh_src->totvert,
kb->name,
kb->totelem);
- array = MEM_calloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__);
+ array = MEM_calloc_arrayN((size_t)mesh_src->totvert, sizeof(float[3]), __func__);
}
else {
- array = MEM_malloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__);
- memcpy(array, kb->data, (size_t)mesh_src->totvert * 3 * sizeof(float));
+ array = MEM_malloc_arrayN((size_t)mesh_src->totvert, sizeof(float[3]), __func__);
+ memcpy(array, kb->data, sizeof(float[3]) * (size_t)mesh_src->totvert);
}
CustomData_add_layer_named(
@@ -1405,7 +1405,7 @@ static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int act
cos = CustomData_get_layer_n(&mesh_src->vdata, CD_SHAPEKEY, i);
kb->totelem = mesh_src->totvert;
- kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, 3 * sizeof(float), __func__);
+ kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, sizeof(float[3]), __func__);
if (kb->uid == actshape_uid) {
MVert *mvert = mesh_src->mvert;
@@ -1427,7 +1427,7 @@ static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int act
}
kb->totelem = mesh_src->totvert;
- kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), __func__);
+ kb->data = MEM_calloc_arrayN(kb->totelem, sizeof(float[3]), __func__);
CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", kb->name);
}
}
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 49957b584ad..fe4b8a60796 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -1408,7 +1408,7 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops,
return false;
}
/* Smooth loop/edge... */
- else if (BLI_BITMAP_TEST(skip_loops, mlfan_vert_index)) {
+ if (BLI_BITMAP_TEST(skip_loops, mlfan_vert_index)) {
if (mlfan_vert_index == ml_curr_index) {
/* We walked around a whole cyclic smooth fan without finding any already-processed loop,
* means we can use initial ml_curr/ml_prev edge as start for this smooth fan. */
@@ -1417,10 +1417,9 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops,
/* ... already checked in some previous looping, we can abort. */
return false;
}
- else {
- /* ... we can skip it in future, and keep checking the smooth fan. */
- BLI_BITMAP_ENABLE(skip_loops, mlfan_vert_index);
- }
+
+ /* ... we can skip it in future, and keep checking the smooth fan. */
+ BLI_BITMAP_ENABLE(skip_loops, mlfan_vert_index);
}
}
@@ -2315,22 +2314,21 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const
return area_tri_v3(
mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co);
}
- else {
- int i;
- const MLoop *l_iter = loopstart;
- float area;
- float(*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
-
- /* pack vertex cos into an array for area_poly_v3 */
- for (i = 0; i < mpoly->totloop; i++, l_iter++) {
- copy_v3_v3(vertexcos[i], mvarray[l_iter->v].co);
- }
- /* finally calculate the area */
- area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop);
+ int i;
+ const MLoop *l_iter = loopstart;
+ float area;
+ float(*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
- return area;
+ /* pack vertex cos into an array for area_poly_v3 */
+ for (i = 0; i < mpoly->totloop; i++, l_iter++) {
+ copy_v3_v3(vertexcos[i], mvarray[l_iter->v].co);
}
+
+ /* finally calculate the area */
+ area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop);
+
+ return area;
}
float BKE_mesh_calc_area(const Mesh *me)
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 686f58a0ceb..3572939f78c 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -1047,10 +1047,9 @@ static bool mesh_check_island_boundary_uv(const MPoly *UNUSED(mp),
}
return false;
}
- else {
- /* Edge is UV boundary if tagged as seam. */
- return (me->flag & ME_SEAM) != 0;
- }
+
+ /* Edge is UV boundary if tagged as seam. */
+ return (me->flag & ME_SEAM) != 0;
}
static bool mesh_calc_islands_loop_poly_uv(MVert *UNUSED(verts),
diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c
index 1b9b8ea6572..ef28e9958fc 100644
--- a/source/blender/blenkernel/intern/mesh_merge.c
+++ b/source/blender/blenkernel/intern/mesh_merge.c
@@ -115,11 +115,10 @@ static int cddm_poly_compare(MLoop *mloop_array,
same_loops = true;
break; /* Polys are identical */
}
- else {
- compare_completed = true;
- same_loops = false;
- break; /* Polys are different */
- }
+
+ compare_completed = true;
+ same_loops = false;
+ break; /* Polys are different */
}
mloop_source++;
@@ -201,9 +200,8 @@ static bool poly_gset_compare_fn(const void *k1, const void *k2)
/* Equality - note that this does not mean equality of polys */
return false;
}
- else {
- return true;
- }
+
+ return true;
}
/**
@@ -412,7 +410,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
/* In this mode, all vertices merged is enough to dump face */
continue;
}
- else if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_EQUAL) {
+ if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_EQUAL) {
/* Additional condition for face dump: target vertices must make up an identical face */
/* The test has 2 steps: (1) first step is fast ghash lookup, but not failproof */
/* (2) second step is thorough but more costly poly compare */
@@ -578,7 +576,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
BLI_assert(created_edges == 0);
continue;
}
- else if (UNLIKELY(c < 3)) {
+ if (UNLIKELY(c < 3)) {
STACK_DISCARD(oldl, c);
STACK_DISCARD(mloop, c);
if (created_edges > 0) {
diff --git a/source/blender/blenkernel/intern/mesh_mirror.c b/source/blender/blenkernel/intern/mesh_mirror.c
index d9be9a99b2b..46764a56e60 100644
--- a/source/blender/blenkernel/intern/mesh_mirror.c
+++ b/source/blender/blenkernel/intern/mesh_mirror.c
@@ -197,7 +197,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis(MirrorModifierData *mmd,
if (do_vtargetmap) {
/* second half is filled with -1 */
- vtargetmap = MEM_malloc_arrayN(maxVerts, 2 * sizeof(int), "MOD_mirror tarmap");
+ vtargetmap = MEM_malloc_arrayN(maxVerts, sizeof(int[2]), "MOD_mirror tarmap");
vtmap_a = vtargetmap;
vtmap_b = vtargetmap + maxVerts;
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index a4991675d2d..a8937f74dee 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -73,9 +73,8 @@ static bool mesh_remap_bvhtree_query_nearest(BVHTreeFromMesh *treedata,
*r_hit_dist = sqrtf(nearest->dist_sq);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
static bool mesh_remap_bvhtree_query_raycast(BVHTreeFromMesh *treedata,
@@ -107,9 +106,8 @@ static bool mesh_remap_bvhtree_query_raycast(BVHTreeFromMesh *treedata,
*r_hit_dist = rayhit->dist;
return true;
}
- else {
- return false;
- }
+
+ return false;
}
/** \} */
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index 4d8c0568eb6..338420641cf 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -111,7 +111,7 @@ static int int64_cmp(const void *v1, const void *v2)
if (x1 > x2) {
return 1;
}
- else if (x1 < x2) {
+ if (x1 < x2) {
return -1;
}
@@ -125,28 +125,28 @@ static int search_face_cmp(const void *v1, const void *v2)
if (sfa->es[0].edval > sfb->es[0].edval) {
return 1;
}
- else if (sfa->es[0].edval < sfb->es[0].edval) {
+ if (sfa->es[0].edval < sfb->es[0].edval) {
return -1;
}
- else if (sfa->es[1].edval > sfb->es[1].edval) {
+ if (sfa->es[1].edval > sfb->es[1].edval) {
return 1;
}
- else if (sfa->es[1].edval < sfb->es[1].edval) {
+ if (sfa->es[1].edval < sfb->es[1].edval) {
return -1;
}
- else if (sfa->es[2].edval > sfb->es[2].edval) {
+ if (sfa->es[2].edval > sfb->es[2].edval) {
return 1;
}
- else if (sfa->es[2].edval < sfb->es[2].edval) {
+ if (sfa->es[2].edval < sfb->es[2].edval) {
return -1;
}
- else if (sfa->es[3].edval > sfb->es[3].edval) {
+ if (sfa->es[3].edval > sfb->es[3].edval) {
return 1;
}
- else if (sfa->es[3].edval < sfb->es[3].edval) {
+ if (sfa->es[3].edval < sfb->es[3].edval) {
return -1;
}
@@ -214,6 +214,7 @@ static int search_polyloop_cmp(const void *v1, const void *v2)
*
* \return false if no changes needed to be made.
*/
+/* NOLINTNEXTLINE: readability-function-size */
bool BKE_mesh_validate_arrays(Mesh *mesh,
MVert *mverts,
unsigned int totvert,
@@ -1082,9 +1083,8 @@ bool BKE_mesh_validate(Mesh *me, const bool do_verbose, const bool cddata_check_
DEG_id_tag_update(&me->id, ID_RECALC_GEOMETRY);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
/**
@@ -1161,9 +1161,8 @@ bool BKE_mesh_validate_material_indices(Mesh *me)
DEG_id_tag_update(&me->id, ID_RECALC_GEOMETRY);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
/** \} */
@@ -1341,13 +1340,13 @@ static int vergedgesort(const void *v1, const void *v2)
if (x1->v1 > x2->v1) {
return 1;
}
- else if (x1->v1 < x2->v1) {
+ if (x1->v1 < x2->v1) {
return -1;
}
- else if (x1->v2 > x2->v2) {
+ if (x1->v2 > x2->v2) {
return 1;
}
- else if (x1->v2 < x2->v2) {
+ if (x1->v2 < x2->v2) {
return -1;
}
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 327e8bfca7a..afd02d7001e 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -41,6 +41,7 @@
#include "BLI_linklist.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
+#include "BLI_session_uuid.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
@@ -112,9 +113,8 @@ const ModifierTypeInfo *BKE_modifier_get_info(ModifierType type)
if (type < NUM_MODIFIER_TYPES && modifier_types[type] && modifier_types[type]->name[0] != '\0') {
return modifier_types[type];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/**
@@ -151,6 +151,8 @@ ModifierData *BKE_modifier_new(int type)
mti->initData(md);
}
+ BKE_modifier_session_uuid_generate(md);
+
return md;
}
@@ -193,6 +195,11 @@ void BKE_modifier_free(ModifierData *md)
BKE_modifier_free_ex(md, 0);
}
+void BKE_modifier_session_uuid_generate(ModifierData *md)
+{
+ md->session_uuid = BLI_session_uuid_generate();
+}
+
bool BKE_modifier_unique_name(ListBase *modifiers, ModifierData *md)
{
if (modifiers && md) {
@@ -369,6 +376,17 @@ void BKE_modifier_copydata_ex(ModifierData *md, ModifierData *target, const int
mti->foreachObjectLink(target, NULL, (ObjectWalkFunc)modifier_copy_data_id_us_cb, NULL);
}
}
+
+ if (flag & LIB_ID_CREATE_NO_MAIN) {
+ /* Make sure UUID is the same between the source and the target.
+ * This is needed in the cases when UUID is to be preserved and when there is no copyData
+ * callback, or the copyData does not do full byte copy of the modifier data. */
+ target->session_uuid = md->session_uuid;
+ }
+ else {
+ /* In the case copyData made full byte copy force UUID to be re-generated. */
+ BKE_modifier_session_uuid_generate(md);
+ }
}
void BKE_modifier_copydata(ModifierData *md, ModifierData *target)
@@ -919,11 +937,10 @@ const char *BKE_modifier_path_relbase(Main *bmain, Object *ob)
if (G.relbase_valid || ID_IS_LINKED(ob)) {
return ID_BLEND_PATH(bmain, &ob->id);
}
- else {
- /* last resort, better then using "" which resolves to the current
- * working directory */
- return BKE_tempdir_session();
- }
+
+ /* last resort, better then using "" which resolves to the current
+ * working directory */
+ return BKE_tempdir_session();
}
const char *BKE_modifier_path_relbase_from_global(Object *ob)
@@ -931,11 +948,10 @@ const char *BKE_modifier_path_relbase_from_global(Object *ob)
if (G.relbase_valid || ID_IS_LINKED(ob)) {
return ID_BLEND_PATH_FROM_GLOBAL(&ob->id);
}
- else {
- /* last resort, better then using "" which resolves to the current
- * working directory */
- return BKE_tempdir_session();
- }
+
+ /* last resort, better then using "" which resolves to the current
+ * working directory */
+ return BKE_tempdir_session();
}
/* initializes the path with either */
@@ -1074,3 +1090,26 @@ struct ModifierData *BKE_modifier_get_evaluated(Depsgraph *depsgraph,
}
return BKE_modifiers_findby_name(object_eval, md->name);
}
+
+void BKE_modifier_check_uuids_unique_and_report(const Object *object)
+{
+ struct GSet *used_uuids = BLI_gset_new(
+ BLI_session_uuid_ghash_hash, BLI_session_uuid_ghash_compare, "modifier used uuids");
+
+ LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
+ const SessionUUID *session_uuid = &md->session_uuid;
+ if (!BLI_session_uuid_is_generated(session_uuid)) {
+ printf("Modifier %s -> %s does not have UUID generated.\n", object->id.name + 2, md->name);
+ continue;
+ }
+
+ if (BLI_gset_lookup(used_uuids, session_uuid) != NULL) {
+ printf("Modifier %s -> %s has duplicate UUID generated.\n", object->id.name + 2, md->name);
+ continue;
+ }
+
+ BLI_gset_insert(used_uuids, (void *)session_uuid);
+ }
+
+ BLI_gset_free(used_uuids, NULL);
+}
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 4a65c6ff5e7..dcac7b01899 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -717,9 +717,8 @@ static bool put_imbuf_cache(
IMB_moviecache_put(clip->cache->moviecache, &key, ibuf);
return true;
}
- else {
- return IMB_moviecache_put_if_possible(clip->cache->moviecache, &key, ibuf);
- }
+
+ return IMB_moviecache_put_if_possible(clip->cache->moviecache, &key, ibuf);
}
static bool moviecache_check_free_proxy(ImBuf *UNUSED(ibuf), void *userkey, void *UNUSED(userdata))
@@ -1866,3 +1865,88 @@ void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, MovieClip
DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
movieclip_selection_sync(clip, (MovieClip *)clip->id.orig_id);
}
+
+/* -------------------------------------------------------------------- */
+/** \name GPU textures
+ * \{ */
+
+static GPUTexture **movieclip_get_gputexture_ptr(MovieClip *clip,
+ MovieClipUser *cuser,
+ eGPUTextureTarget textarget)
+{
+ /* Check if we have an existing entry for that clip user. */
+ MovieClip_RuntimeGPUTexture *tex;
+ for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) {
+ if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) {
+ break;
+ }
+ }
+
+ /* If not, allocate a new one. */
+ if (tex == NULL) {
+ tex = (MovieClip_RuntimeGPUTexture *)MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture),
+ __func__);
+
+ for (int i = 0; i < TEXTARGET_COUNT; i++) {
+ tex->gputexture[i] = NULL;
+ }
+
+ memcpy(&tex->user, cuser, sizeof(MovieClipUser));
+ BLI_addtail(&clip->runtime.gputextures, tex);
+ }
+
+ return &tex->gputexture[textarget];
+}
+
+GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser)
+{
+ if (clip == NULL) {
+ return NULL;
+ }
+
+ GPUTexture **tex = movieclip_get_gputexture_ptr(clip, cuser, TEXTARGET_2D);
+ if (*tex) {
+ return *tex;
+ }
+
+ /* check if we have a valid image buffer */
+ ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, cuser);
+ if (ibuf == NULL) {
+ *tex = GPU_texture_create_error(2, false);
+ return *tex;
+ }
+
+ /* This only means RGBA16F instead of RGBA32F. */
+ const bool high_bitdepth = false;
+ const bool store_premultiplied = ibuf->rect_float ? false : true;
+ *tex = IMB_create_gpu_texture(ibuf, high_bitdepth, store_premultiplied);
+
+ /* Do not generate mips for movieclips... too slow. */
+ GPU_texture_mipmap_mode(*tex, false, true);
+
+ IMB_freeImBuf(ibuf);
+
+ return *tex;
+}
+
+void BKE_movieclip_free_gputexture(struct MovieClip *clip)
+{
+ /* number of gpu textures to keep around as cache
+ * We don't want to keep too many GPU textures for
+ * movie clips around, as they can be large.*/
+ const int MOVIECLIP_NUM_GPUTEXTURES = 1;
+
+ while (BLI_listbase_count(&clip->runtime.gputextures) > MOVIECLIP_NUM_GPUTEXTURES) {
+ MovieClip_RuntimeGPUTexture *tex = (MovieClip_RuntimeGPUTexture *)BLI_pophead(
+ &clip->runtime.gputextures);
+ for (int i = 0; i < TEXTARGET_COUNT; i++) {
+ /* free glsl image binding */
+ if (tex->gputexture[i]) {
+ GPU_texture_free(tex->gputexture[i]);
+ tex->gputexture[i] = NULL;
+ }
+ }
+ MEM_freeN(tex);
+ }
+}
+/** \} */
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 71d49dd1c19..6e1168d8a16 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -241,7 +241,7 @@ static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level)
md->hidden = subd;
}
-static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level)
+static MDisps *multires_mdisps_init_hidden(Mesh *me, int level)
{
MDisps *mdisps = CustomData_add_layer(&me->ldata, CD_MDISPS, CD_CALLOC, NULL, me->totloop);
int gridsize = BKE_ccg_gridsize(level);
@@ -407,15 +407,14 @@ int multires_get_level(const Scene *scene,
return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->renderlvl, true) :
mmd->renderlvl;
}
- else if (ob->mode == OB_MODE_SCULPT) {
+ if (ob->mode == OB_MODE_SCULPT) {
return mmd->sculptlvl;
}
- else if (ignore_simplify) {
+ if (ignore_simplify) {
return mmd->lvl;
}
- else {
- return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->lvl, false) : mmd->lvl;
- }
+
+ return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->lvl, false) : mmd->lvl;
}
void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl)
@@ -553,7 +552,7 @@ static int get_levels_from_disps(Object *ob)
if (md->totdisp == lvl_totdisp) {
break;
}
- else if (md->totdisp < lvl_totdisp) {
+ if (md->totdisp < lvl_totdisp) {
totlvl--;
}
else {
@@ -609,7 +608,7 @@ static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl)
/* reallocate displacements to be filled in */
for (i = 0; i < totloop; i++) {
int totdisp = multires_grid_tot[lvl];
- float(*disps)[3] = MEM_calloc_arrayN(totdisp, 3 * sizeof(float), "multires disps");
+ float(*disps)[3] = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps");
if (mdisps[i].disps) {
MEM_freeN(mdisps[i].disps);
@@ -727,7 +726,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
float(*disps)[3], (*ndisps)[3], (*hdisps)[3];
int totdisp = multires_grid_tot[lvl];
- disps = MEM_calloc_arrayN(totdisp, 3 * sizeof(float), "multires disps");
+ disps = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps");
if (mdisp->disps != NULL) {
ndisps = disps;
@@ -868,7 +867,7 @@ static void multires_subdivide_legacy(
mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
if (!mdisps) {
- mdisps = multires_mdisps_initialize_hidden(me, totlvl);
+ mdisps = multires_mdisps_init_hidden(me, totlvl);
}
if (mdisps->disps && !updateblock && lvl != 0) {
@@ -1541,7 +1540,7 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp)
int x, y, S;
float(*disps)[3], (*out)[3], u = 0.0f, v = 0.0f; /* Quite gcc barking. */
- disps = MEM_calloc_arrayN(newtotdisp, 3 * sizeof(float), "multires disps");
+ disps = MEM_calloc_arrayN(newtotdisp, sizeof(float[3]), "multires disps");
out = disps;
for (S = 0; S < nvert; S++) {
@@ -1601,7 +1600,7 @@ void multires_load_old_250(Mesh *me)
for (j = 0; j < nvert; j++, k++) {
mdisps2[k].disps = MEM_calloc_arrayN(
- totdisp, 3 * sizeof(float), "multires disp in conversion");
+ totdisp, sizeof(float[3]), "multires disp in conversion");
mdisps2[k].totdisp = totdisp;
mdisps2[k].level = mdisps[i].level;
memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp * j, totdisp);
@@ -1673,7 +1672,7 @@ static void create_old_vert_face_map(ListBase **map,
IndexNode *node = NULL;
(*map) = MEM_calloc_arrayN(totvert, sizeof(ListBase), "vert face map");
- (*mem) = MEM_calloc_arrayN(totface, 4 * sizeof(IndexNode), "vert face map mem");
+ (*mem) = MEM_calloc_arrayN(totface, sizeof(IndexNode[4]), "vert face map mem");
node = *mem;
/* Find the users */
@@ -1695,7 +1694,7 @@ static void create_old_vert_edge_map(ListBase **map,
IndexNode *node = NULL;
(*map) = MEM_calloc_arrayN(totvert, sizeof(ListBase), "vert edge map");
- (*mem) = MEM_calloc_arrayN(totedge, 2 * sizeof(IndexNode), "vert edge map mem");
+ (*mem) = MEM_calloc_arrayN(totedge, sizeof(IndexNode[2]), "vert edge map mem");
node = *mem;
/* Find the users */
@@ -2377,7 +2376,7 @@ void multires_topology_changed(Mesh *me)
if (!mdisp->totdisp || !mdisp->disps) {
if (grid) {
mdisp->totdisp = grid;
- mdisp->disps = MEM_calloc_arrayN(3 * sizeof(float), mdisp->totdisp, "mdisp topology");
+ mdisp->disps = MEM_calloc_arrayN(sizeof(float[3]), mdisp->totdisp, "mdisp topology");
}
continue;
diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.c b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
index 105e56e4219..6e7e2b90c05 100644
--- a/source/blender/blenkernel/intern/multires_reshape_apply_base.c
+++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
@@ -72,7 +72,7 @@ void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *resh
/* Assumes no is normalized; return value's sign is negative if v is on the other side of the
* plane. */
-static float v3_dist_from_plane(float v[3], float center[3], float no[3])
+static float v3_dist_from_plane(const float v[3], const float center[3], const float no[3])
{
float s[3];
sub_v3_v3v3(s, v, center);
@@ -99,7 +99,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
base_mesh->totloop);
float(*origco)[3] = MEM_calloc_arrayN(
- base_mesh->totvert, 3 * sizeof(float), "multires apply base origco");
+ base_mesh->totvert, sizeof(float[3]), "multires apply base origco");
for (int i = 0; i < base_mesh->totvert; i++) {
copy_v3_v3(origco[i], base_mesh->mvert[i].co);
}
@@ -140,7 +140,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
fake_poly.totloop = p->totloop;
fake_poly.loopstart = 0;
fake_loops = MEM_malloc_arrayN(p->totloop, sizeof(MLoop), "fake_loops");
- fake_co = MEM_malloc_arrayN(p->totloop, 3 * sizeof(float), "fake_co");
+ fake_co = MEM_malloc_arrayN(p->totloop, sizeof(float[3]), "fake_co");
for (int k = 0; k < p->totloop; k++) {
const int vndx = base_mesh->mloop[p->loopstart + k].v;
diff --git a/source/blender/blenkernel/intern/multires_reshape_ccg.c b/source/blender/blenkernel/intern/multires_reshape_ccg.c
index 8273845e820..55f7766c878 100644
--- a/source/blender/blenkernel/intern/multires_reshape_ccg.c
+++ b/source/blender/blenkernel/intern/multires_reshape_ccg.c
@@ -58,7 +58,7 @@ bool multires_reshape_assign_final_coords_from_ccg(const MultiresReshapeContext
BLI_assert(grid_element.displacement != NULL);
memcpy(grid_element.displacement,
CCG_grid_elem_co(&reshape_level_key, ccg_grid, x, y),
- sizeof(float) * 3);
+ sizeof(float[3]));
if (reshape_level_key.has_mask) {
BLI_assert(grid_element.mask != NULL);
diff --git a/source/blender/blenkernel/intern/multires_reshape_util.c b/source/blender/blenkernel/intern/multires_reshape_util.c
index e9a779dafeb..c8179dd8a2d 100644
--- a/source/blender/blenkernel/intern/multires_reshape_util.c
+++ b/source/blender/blenkernel/intern/multires_reshape_util.c
@@ -522,7 +522,7 @@ static void allocate_displacement_grid(MDisps *displacement_grid, const int leve
{
const int grid_size = BKE_subdiv_grid_size_from_level(level);
const int grid_area = grid_size * grid_size;
- float(*disps)[3] = MEM_calloc_arrayN(grid_area, 3 * sizeof(float), "multires disps");
+ float(*disps)[3] = MEM_calloc_arrayN(grid_area, sizeof(float[3]), "multires disps");
if (displacement_grid->disps != NULL) {
MEM_freeN(displacement_grid->disps);
}
diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.c b/source/blender/blenkernel/intern/multires_unsubdivide.c
index fa1a53f946e..e3d670f7c39 100644
--- a/source/blender/blenkernel/intern/multires_unsubdivide.c
+++ b/source/blender/blenkernel/intern/multires_unsubdivide.c
@@ -111,7 +111,7 @@ static BMVert *unsubdivide_find_any_pole(BMesh *bm, int *elem_id, int elem)
if (is_vertex_in_id(v, elem_id, elem) && is_vertex_pole_three(v)) {
return v;
}
- else if (is_vertex_in_id(v, elem_id, elem) && is_vertex_pole(v)) {
+ if (is_vertex_in_id(v, elem_id, elem) && is_vertex_pole(v)) {
pole = v;
}
}
@@ -677,7 +677,7 @@ static void store_grid_data(MultiresUnsubdivideContext *context,
const int grid_size = BKE_ccg_gridsize(context->num_original_levels);
const int face_grid_size = BKE_ccg_gridsize(context->num_original_levels + 1);
const int face_grid_area = face_grid_size * face_grid_size;
- float(*face_grid)[3] = MEM_calloc_arrayN(face_grid_area, 3 * sizeof(float), "face_grid");
+ float(*face_grid)[3] = MEM_calloc_arrayN(face_grid_area, sizeof(float[3]), "face_grid");
for (int i = 0; i < poly->totloop; i++) {
const int loop_index = poly->loopstart + i;
@@ -731,7 +731,7 @@ static void multires_unsubdivide_extract_single_grid_from_face_edge(
const int unsubdiv_grid_size = grid->grid_size = BKE_ccg_gridsize(context->num_total_levels);
grid->grid_size = unsubdiv_grid_size;
grid->grid_co = MEM_calloc_arrayN(
- unsubdiv_grid_size * unsubdiv_grid_size, 3 * sizeof(float), "grids coordinates");
+ unsubdiv_grid_size * unsubdiv_grid_size, sizeof(float[3]), "grids coordinates");
/* Get the vertex on the corner of the grid. This vertex was tagged previously as it also exist
* on the base mesh. */
@@ -1198,7 +1198,7 @@ static void multires_create_grids_in_unsubdivided_base_mesh(MultiresUnsubdivideC
/* Allocate the MDISPS grids and copy the extracted data from context. */
for (int i = 0; i < totloop; i++) {
- float(*disps)[3] = MEM_calloc_arrayN(totdisp, 3 * sizeof(float), "multires disps");
+ float(*disps)[3] = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps");
if (mdisps[i].disps) {
MEM_freeN(mdisps[i].disps);
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 7012688686b..1ba82b352d1 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -480,46 +480,41 @@ static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short
if (mode == NLATIME_CONVERT_MAP) {
return strip->end - scale * (cframe - strip->actstart);
}
- else if (mode == NLATIME_CONVERT_UNMAP) {
+ if (mode == NLATIME_CONVERT_UNMAP) {
return (strip->end + (strip->actstart * scale - cframe)) / scale;
}
- else { /* if (mode == NLATIME_CONVERT_EVAL) */
- if (IS_EQF((float)cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
- /* This case prevents the motion snapping back to the first frame at the end of the strip
- * by catching the case where repeats is a whole number, which means that the end of the
- * strip could also be interpreted as the end of the start of a repeat. */
- return strip->actstart;
- }
- else {
- /* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
- * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
- */
- return strip->actend - fmodf(cframe - strip->start, actlength * scale) / scale;
- }
+ /* if (mode == NLATIME_CONVERT_EVAL) */
+ if (IS_EQF((float)cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
+ /* This case prevents the motion snapping back to the first frame at the end of the strip
+ * by catching the case where repeats is a whole number, which means that the end of the
+ * strip could also be interpreted as the end of the start of a repeat. */
+ return strip->actstart;
}
+
+ /* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
+ * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
+ */
+ return strip->actend - fmodf(cframe - strip->start, actlength * scale) / scale;
}
- else {
- if (mode == NLATIME_CONVERT_MAP) {
- return strip->start + scale * (cframe - strip->actstart);
- }
- else if (mode == NLATIME_CONVERT_UNMAP) {
- return strip->actstart + (cframe - strip->start) / scale;
- }
- else { /* if (mode == NLATIME_CONVERT_EVAL) */
- if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
- /* This case prevents the motion snapping back to the first frame at the end of the strip
- * by catching the case where repeats is a whole number, which means that the end of the
- * strip could also be interpreted as the end of the start of a repeat. */
- return strip->actend;
- }
- else {
- /* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
- * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
- */
- return strip->actstart + fmodf(cframe - strip->start, actlength * scale) / scale;
- }
- }
+
+ if (mode == NLATIME_CONVERT_MAP) {
+ return strip->start + scale * (cframe - strip->actstart);
+ }
+ if (mode == NLATIME_CONVERT_UNMAP) {
+ return strip->actstart + (cframe - strip->start) / scale;
+ }
+ /* if (mode == NLATIME_CONVERT_EVAL) */
+ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
+ /* This case prevents the motion snapping back to the first frame at the end of the strip
+ * by catching the case where repeats is a whole number, which means that the end of the
+ * strip could also be interpreted as the end of the start of a repeat. */
+ return strip->actend;
}
+
+ /* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
+ * - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
+ */
+ return strip->actstart + fmodf(cframe - strip->start, actlength * scale) / scale;
}
/* non clipped mapping for strip-time <-> global time (for Transitions)
@@ -537,18 +532,15 @@ static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short
if (mode == NLATIME_CONVERT_MAP) {
return strip->end - (length * cframe);
}
- else {
- return (strip->end - cframe) / length;
- }
+
+ return (strip->end - cframe) / length;
}
- else {
- if (mode == NLATIME_CONVERT_MAP) {
- return (length * cframe) + strip->start;
- }
- else {
- return (cframe - strip->start) / length;
- }
+
+ if (mode == NLATIME_CONVERT_MAP) {
+ return (length * cframe) + strip->start;
}
+
+ return (cframe - strip->start) / length;
}
/* non clipped mapping for strip-time <-> global time
@@ -882,11 +874,10 @@ bool BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip)
return true;
}
- else { /* failed... no room before */
- return false;
- }
+ /* failed... no room before */
+ return false;
}
- else if (strip->end > mstrip->end) {
+ if (strip->end > mstrip->end) {
/* check if strip to the right (if it exists) starts before the
* end of the strip we're trying to add
*/
@@ -897,14 +888,12 @@ bool BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip)
return true;
}
- else { /* failed... no room after */
- return false;
- }
- }
- else {
- /* just try to add to the meta-strip (no dimension changes needed) */
- return BKE_nlastrips_add_strip(&mstrip->strips, strip);
+ /* failed... no room after */
+ return false;
}
+
+ /* just try to add to the meta-strip (no dimension changes needed) */
+ return BKE_nlastrips_add_strip(&mstrip->strips, strip);
}
/* Adjust the settings of NLA-Strips contained within a Meta-Strip (recursively),
@@ -1034,7 +1023,7 @@ NlaTrack *BKE_nlatrack_find_tweaked(AnimData *adt)
if (BLI_findindex(&nlt->strips, adt->actstrip) != -1) {
return nlt;
}
- else if (G.debug & G_DEBUG) {
+ if (G.debug & G_DEBUG) {
printf("%s: Active strip (%p, %s) not in NLA track found (%p, %s)\n",
__func__,
adt->actstrip,
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 20d65e52b09..a89285a28c1 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -61,6 +61,7 @@
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_node.h"
+#include "BKE_simulation.h"
#include "BLI_ghash.h"
#include "BLI_threads.h"
@@ -845,12 +846,12 @@ static void socket_id_user_increment(bNodeSocket *sock)
switch ((eNodeSocketDatatype)sock->type) {
case SOCK_OBJECT: {
bNodeSocketValueObject *default_value = sock->default_value;
- id_us_plus(&default_value->value->id);
+ id_us_plus((ID *)default_value->value);
break;
}
case SOCK_IMAGE: {
bNodeSocketValueImage *default_value = sock->default_value;
- id_us_plus(&default_value->value->id);
+ id_us_plus((ID *)default_value->value);
break;
}
case SOCK_FLOAT:
@@ -1265,9 +1266,8 @@ bNode *nodeFindRootParent(bNode *node)
if (node->parent) {
return nodeFindRootParent(node->parent);
}
- else {
- return node->type == NODE_FRAME ? node : NULL;
- }
+
+ return node->type == NODE_FRAME ? node : NULL;
}
/**
@@ -1279,7 +1279,7 @@ bool nodeIsChildOf(const bNode *parent, const bNode *child)
if (parent == child) {
return true;
}
- else if (child->parent) {
+ if (child->parent) {
return nodeIsChildOf(parent, child->parent);
}
return false;
@@ -1338,9 +1338,8 @@ static void iter_backwards_ex(const bNodeTree *ntree,
if (link->fromnode->iter_flag & recursion_mask) {
continue;
}
- else {
- link->fromnode->iter_flag |= recursion_mask;
- }
+
+ link->fromnode->iter_flag |= recursion_mask;
if (!callback(link->fromnode, link->tonode, userdata)) {
return;
@@ -1918,7 +1917,7 @@ bNodePreview *BKE_node_preview_verify(
}
if (preview->rect == NULL) {
- preview->rect = MEM_callocN(4 * xsize + xsize * ysize * sizeof(char) * 4, "node preview rect");
+ preview->rect = MEM_callocN(4 * xsize + xsize * ysize * sizeof(char[4]), "node preview rect");
preview->xsize = xsize;
preview->ysize = ysize;
}
@@ -2056,7 +2055,7 @@ static void node_preview_sync(bNodePreview *to, bNodePreview *from)
if (to->rect && from->rect) {
int xsize = to->xsize;
int ysize = to->ysize;
- memcpy(to->rect, from->rect, xsize * ysize * sizeof(char) * 4);
+ memcpy(to->rect, from->rect, xsize * ysize * sizeof(char[4]));
}
}
@@ -2493,6 +2492,7 @@ ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree)
&bmain->textures,
&bmain->scenes,
&bmain->linestyles,
+ &bmain->simulations,
NULL};
for (int i = 0; lists[i] != NULL; i++) {
@@ -2580,9 +2580,8 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
return ltree;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/* sync local composite with real tree */
@@ -2987,9 +2986,8 @@ bNode *nodeGetActiveID(bNodeTree *ntree, short idtype)
return node_get_active_id_recursive(
ntree->active_viewer_key, NODE_INSTANCE_KEY_BASE, ntree, idtype);
}
- else {
- return NULL;
- }
+
+ return NULL;
}
bool nodeSetActiveID(bNodeTree *ntree, short idtype, ID *id)
@@ -3125,9 +3123,8 @@ int nodeSocketLinkLimit(struct bNodeSocket *sock)
int limit = (sock->in_out == SOCK_IN) ? stype->input_link_limit : stype->output_link_limit;
return limit;
}
- else {
- return sock->limit;
- }
+
+ return sock->limit;
}
/* ************** Node Clipboard *********** */
@@ -3417,9 +3414,8 @@ bool BKE_node_instance_hash_tag_key(bNodeInstanceHash *hash, bNodeInstanceKey ke
entry->tag = 1;
return true;
}
- else {
- return false;
- }
+
+ return false;
}
void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash,
@@ -3637,6 +3633,16 @@ void ntreeUpdateAllUsers(Main *main, ID *ngroup)
FOREACH_NODETREE_END;
}
+static void ntreeUpdateSimulationDependencies(Main *main, bNodeTree *simulation_ntree)
+{
+ FOREACH_NODETREE_BEGIN (main, ntree, owner_id) {
+ if (GS(owner_id->name) == ID_SIM && ntree == simulation_ntree) {
+ BKE_simulation_update_dependencies((Simulation *)owner_id, main);
+ }
+ }
+ FOREACH_NODETREE_END;
+}
+
void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
{
bNode *node;
@@ -3679,7 +3685,6 @@ void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
ntreeInterfaceTypeUpdate(ntree);
}
- /* XXX hack, should be done by depsgraph!! */
if (bmain) {
ntreeUpdateAllUsers(bmain, &ntree->id);
}
@@ -3695,6 +3700,11 @@ void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
ntree_validate_links(ntree);
}
+ if (bmain != NULL && ntree->typeinfo == ntreeType_Simulation &&
+ (ntree->id.flag & LIB_EMBEDDED_DATA)) {
+ ntreeUpdateSimulationDependencies(bmain, ntree);
+ }
+
/* clear update flags */
for (node = ntree->nodes.first; node; node = node->next) {
node->update = 0;
@@ -3819,6 +3829,7 @@ static bool node_poll_instance_default(bNode *node, bNodeTree *ntree)
return node->typeinfo->poll(node->typeinfo, ntree);
}
+/* NOLINTNEXTLINE: readability-function-size */
void node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
{
/* Use static type info header to map static int type to identifier string and RNA struct type.
@@ -4336,6 +4347,8 @@ static void registerSimulationNodes(void)
register_node_type_sim_emit_particles();
register_node_type_sim_time();
register_node_type_sim_particle_attribute();
+ register_node_type_sim_age_reached_event();
+ register_node_type_sim_kill_particle();
}
static void registerFunctionNodes(void)
@@ -4346,6 +4359,7 @@ static void registerFunctionNodes(void)
register_node_type_fn_group_instance_id();
register_node_type_fn_combine_strings();
register_node_type_fn_object_transforms();
+ register_node_type_fn_random_float();
}
void init_nodesystem(void)
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index ecb2256d080..31420b3adc6 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -666,14 +666,14 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
if (ob->type == OB_HAIR) {
return (mti->modifyHair != NULL) || (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
}
- else if (ob->type == OB_POINTCLOUD) {
+ if (ob->type == OB_POINTCLOUD) {
return (mti->modifyPointCloud != NULL) ||
(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
}
- else if (ob->type == OB_VOLUME) {
+ if (ob->type == OB_VOLUME) {
return (mti->modifyVolume != NULL);
}
- else if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
+ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
if (ob->type == OB_LATTICE && (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly) == 0) {
return false;
}
@@ -1597,9 +1597,8 @@ bool BKE_object_pose_context_check(const Object *ob)
if ((ob) && (ob->type == OB_ARMATURE) && (ob->pose) && (ob->mode & OB_MODE_POSE)) {
return true;
}
- else {
- return false;
- }
+
+ return false;
}
Object *BKE_object_pose_armature_get(Object *ob)
@@ -2409,7 +2408,7 @@ static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
/* ctime is now a proper var setting of Curve which gets set by Animato like any other var
* that's animated, but this will only work if it actually is animated.
*
- * We divide the curvetime calculated in the previous step by the length of the path,
+ * We divide the curve-time calculated in the previous step by the length of the path,
* to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range.
*/
if (cu->pathlen) {
@@ -3207,9 +3206,8 @@ bool BKE_object_empty_image_frame_is_visible_in_view3d(const Object *ob, const R
if (rv3d->is_persp) {
return (visibility_flag & OB_EMPTY_IMAGE_HIDE_PERSPECTIVE) == 0;
}
- else {
- return (visibility_flag & OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC) == 0;
- }
+
+ return (visibility_flag & OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC) == 0;
}
bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
@@ -3269,31 +3267,30 @@ bool BKE_object_minmax_dupli(Depsgraph *depsgraph,
if ((ob->transflag & OB_DUPLI) == 0) {
return ok;
}
- else {
- ListBase *lb;
- DupliObject *dob;
- lb = object_duplilist(depsgraph, scene, ob);
- for (dob = lb->first; dob; dob = dob->next) {
- if ((use_hidden == false) && (dob->no_draw != 0)) {
- /* pass */
- }
- else {
- BoundBox *bb = BKE_object_boundbox_get(dob->ob);
-
- if (bb) {
- int i;
- for (i = 0; i < 8; i++) {
- float vec[3];
- mul_v3_m4v3(vec, dob->mat, bb->vec[i]);
- minmax_v3v3_v3(r_min, r_max, vec);
- }
- ok = true;
+ ListBase *lb;
+ DupliObject *dob;
+ lb = object_duplilist(depsgraph, scene, ob);
+ for (dob = lb->first; dob; dob = dob->next) {
+ if ((use_hidden == false) && (dob->no_draw != 0)) {
+ /* pass */
+ }
+ else {
+ BoundBox *bb = BKE_object_boundbox_get(dob->ob);
+
+ if (bb) {
+ int i;
+ for (i = 0; i < 8; i++) {
+ float vec[3];
+ mul_v3_m4v3(vec, dob->mat, bb->vec[i]);
+ minmax_v3v3_v3(r_min, r_max, vec);
}
+
+ ok = true;
}
}
- free_object_duplilist(lb); /* does restore */
}
+ free_object_duplilist(lb); /* does restore */
return ok;
}
@@ -3636,9 +3633,8 @@ static int pc_cmp(const void *a, const void *b)
if (POINTER_AS_INT(ad->data) > POINTER_AS_INT(bd->data)) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
int BKE_object_insert_ptcache(Object *ob)
@@ -3917,12 +3913,11 @@ bool BKE_object_flag_test_recursive(const Object *ob, short flag)
if (ob->flag & flag) {
return true;
}
- else if (ob->parent) {
+ if (ob->parent) {
return BKE_object_flag_test_recursive(ob->parent, flag);
}
- else {
- return false;
- }
+
+ return false;
}
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
@@ -3970,15 +3965,20 @@ int BKE_object_is_modified(Scene *scene, Object *ob)
return flag;
}
-/* Check of objects moves in time. */
-/* NOTE: This function is currently optimized for usage in combination
- * with mti->canDeform, so modifiers can quickly check if their target
- * objects moves (causing deformation motion blur) or not.
+/**
+ * Check of objects moves in time.
+ *
+ * \note This function is currently optimized for usage in combination
+ * with modifier deformation checks (#eModifierTypeType_OnlyDeform),
+ * so modifiers can quickly check if their target objects moves
+ * (causing deformation motion blur) or not.
*
* This makes it possible to give some degree of false-positives here,
* but it's currently an acceptable tradeoff between complexity and check
* speed. In combination with checks of modifier stack and real life usage
- * percentage of false-positives shouldn't be that height.
+ * percentage of false-positives shouldn't be that high.
+ *
+ * \note This function does not consider physics systems.
*/
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
{
@@ -4024,15 +4024,15 @@ static bool constructive_modifier_is_deform_modified(ModifierData *md)
(amd->curve_ob != NULL && object_moves_in_time(amd->curve_ob)) ||
(amd->offset_ob != NULL && object_moves_in_time(amd->offset_ob));
}
- else if (md->type == eModifierType_Mirror) {
+ if (md->type == eModifierType_Mirror) {
MirrorModifierData *mmd = (MirrorModifierData *)md;
return mmd->mirror_ob != NULL && object_moves_in_time(mmd->mirror_ob);
}
- else if (md->type == eModifierType_Screw) {
+ if (md->type == eModifierType_Screw) {
ScrewModifierData *smd = (ScrewModifierData *)md;
return smd->ob_axis != NULL && object_moves_in_time(smd->ob_axis);
}
- else if (md->type == eModifierType_MeshSequenceCache) {
+ if (md->type == eModifierType_MeshSequenceCache) {
/* NOTE: Not ideal because it's unknown whether topology changes or not.
* This will be detected later, so by assuming it's only deformation
* going on here we allow to bake deform-only mesh to Alembic and have
@@ -4714,3 +4714,9 @@ void BKE_object_to_mesh_clear(Object *object)
BKE_id_free(NULL, object->runtime.object_as_temp_mesh);
object->runtime.object_as_temp_mesh = NULL;
}
+
+void BKE_object_check_uuids_unique_and_report(const Object *object)
+{
+ BKE_pose_check_uuids_unique_and_report(object->pose);
+ BKE_modifier_check_uuids_unique_and_report(object);
+}
diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c
index 51ec89cf77d..04f7529c6cd 100644
--- a/source/blender/blenkernel/intern/object_deform.c
+++ b/source/blender/blenkernel/intern/object_deform.c
@@ -145,7 +145,7 @@ MDeformVert *BKE_object_defgroup_data_create(ID *id)
me->dvert = CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, me->totvert);
return me->dvert;
}
- else if (GS(id->name) == ID_LT) {
+ if (GS(id->name) == ID_LT) {
Lattice *lt = (Lattice *)id;
lt->dvert = MEM_callocN(sizeof(MDeformVert) * lt->pntsu * lt->pntsv * lt->pntsw,
"lattice deformVert");
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index fa2ea0a8e8f..d69f4a39263 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -38,6 +38,7 @@
#include "DNA_collection_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_vfont_types.h"
@@ -744,6 +745,68 @@ static const DupliGenerator gen_dupli_verts_font = {
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Dupli-Vertices Implementation (#OB_DUPLIVERTS for #PointCloud)
+ * \{ */
+
+static void make_child_duplis_pointcloud(const DupliContext *ctx,
+ void *UNUSED(userdata),
+ Object *child)
+{
+ const Object *parent = ctx->object;
+ const PointCloud *pointcloud = parent->data;
+ const float(*co)[3] = pointcloud->co;
+ const float *radius = pointcloud->radius;
+ const float(*rotation)[4] = NULL; /* TODO: add optional rotation attribute. */
+ const float(*orco)[3] = NULL; /* TODO: add optional texture coordinate attribute. */
+
+ /* Relative transform from parent to child space. */
+ float child_imat[4][4];
+ mul_m4_m4m4(child_imat, child->imat, parent->obmat);
+
+ for (int i = 0; i < pointcloud->totpoint; i++) {
+ /* Transform matrix from point position, radius and rotation. */
+ float quat[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+ float size[3] = {1.0f, 1.0f, 1.0f};
+ if (radius) {
+ copy_v3_fl(size, radius[i]);
+ }
+ if (rotation) {
+ copy_v4_v4(quat, rotation[i]);
+ }
+
+ float space_mat[4][4];
+ loc_quat_size_to_mat4(space_mat, co[i], quat, size);
+
+ /* Make offset relative to child object using relative child transform,
+ * and apply object matrix after local vertex transform. */
+ mul_mat3_m4_v3(child_imat, space_mat[3]);
+
+ /* Create dupli object. */
+ float obmat[4][4];
+ mul_m4_m4m4(obmat, child->obmat, space_mat);
+ DupliObject *dob = make_dupli(ctx, child, obmat, i);
+ if (orco) {
+ copy_v3_v3(dob->orco, orco[i]);
+ }
+
+ /* Recursion. */
+ make_recursive_duplis(ctx, child, space_mat, i);
+ }
+}
+
+static void make_duplis_pointcloud(const DupliContext *ctx)
+{
+ make_child_duplis(ctx, NULL, make_child_duplis_pointcloud);
+}
+
+static const DupliGenerator gen_dupli_verts_pointcloud = {
+ OB_DUPLIVERTS, /* type */
+ make_duplis_pointcloud /* make_duplis */
+};
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Dupli-Faces Implementation (#OB_DUPLIFACES)
* \{ */
@@ -1277,13 +1340,12 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
if (psys_get_particle_state(&sim, a, &state, 0) == 0) {
continue;
}
- else {
- float tquat[4];
- normalize_qt_qt(tquat, state.rot);
- quat_to_mat4(pamat, tquat);
- copy_v3_v3(pamat[3], state.co);
- pamat[3][3] = 1.0f;
- }
+
+ float tquat[4];
+ normalize_qt_qt(tquat, state.rot);
+ quat_to_mat4(pamat, tquat);
+ copy_v3_v3(pamat[3], state.co);
+ pamat[3][3] = 1.0f;
}
if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
@@ -1423,13 +1485,16 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
if (transflag & OB_DUPLIPARTS) {
return &gen_dupli_particles;
}
- else if (transflag & OB_DUPLIVERTS) {
+ if (transflag & OB_DUPLIVERTS) {
if (ctx->object->type == OB_MESH) {
return &gen_dupli_verts;
}
- else if (ctx->object->type == OB_FONT) {
+ if (ctx->object->type == OB_FONT) {
return &gen_dupli_verts_font;
}
+ if (ctx->object->type == OB_POINTCLOUD) {
+ return &gen_dupli_verts_pointcloud;
+ }
}
else if (transflag & OB_DUPLIFACES) {
if (ctx->object->type == OB_MESH) {
diff --git a/source/blender/blenkernel/intern/object_facemap.c b/source/blender/blenkernel/intern/object_facemap.c
index 10a3e35e382..c44ec2b510e 100644
--- a/source/blender/blenkernel/intern/object_facemap.c
+++ b/source/blender/blenkernel/intern/object_facemap.c
@@ -55,7 +55,7 @@ static bool fmap_unique_check(void *arg, const char *name)
for (fmap = data->ob->fmaps.first; fmap; fmap = fmap->next) {
if (data->fm != fmap) {
- if (!strcmp(fmap->name, name)) {
+ if (STREQ(fmap->name, name)) {
return true;
}
}
diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index f94ef946851..ff7cbff06bf 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -753,18 +753,25 @@ struct Ocean *BKE_ocean_add(void)
return oc;
}
-bool BKE_ocean_ensure(struct OceanModifierData *omd)
+bool BKE_ocean_ensure(struct OceanModifierData *omd, const int resolution)
{
if (omd->ocean) {
- return false;
+ /* Check that the ocean has the same resolution than we want now. */
+ if (omd->ocean->_M == resolution * resolution) {
+ return false;
+ }
+
+ BKE_ocean_free(omd->ocean);
}
omd->ocean = BKE_ocean_add();
- BKE_ocean_init_from_modifier(omd->ocean, omd);
+ BKE_ocean_init_from_modifier(omd->ocean, omd, resolution);
return true;
}
-void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData const *omd)
+void BKE_ocean_init_from_modifier(struct Ocean *ocean,
+ struct OceanModifierData const *omd,
+ const int resolution)
{
short do_heightfield, do_chop, do_normals, do_jacobian;
@@ -774,9 +781,10 @@ void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData
do_jacobian = (omd->flag & MOD_OCEAN_GENERATE_FOAM);
BKE_ocean_free_data(ocean);
+
BKE_ocean_init(ocean,
- omd->resolution * omd->resolution,
- omd->resolution * omd->resolution,
+ resolution * resolution,
+ resolution * resolution,
omd->spatial_size,
omd->spatial_size,
omd->wind_velocity,
@@ -1607,7 +1615,8 @@ void BKE_ocean_bake(struct Ocean *UNUSED(o),
}
void BKE_ocean_init_from_modifier(struct Ocean *UNUSED(ocean),
- struct OceanModifierData const *UNUSED(omd))
+ struct OceanModifierData const *UNUSED(omd),
+ int UNUSED(resolution))
{
}
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 2cd5588ccb8..6793f5e1169 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -80,7 +80,7 @@ int BKE_packedfile_seek(PackedFile *pf, int offset, int whence)
pf->seek = seek;
}
- return (oldseek);
+ return oldseek;
}
void BKE_packedfile_rewind(PackedFile *pf)
@@ -108,7 +108,7 @@ int BKE_packedfile_read(PackedFile *pf, void *data, int size)
size = -1;
}
- return (size);
+ return size;
}
int BKE_packedfile_count_all(Main *bmain)
@@ -234,7 +234,7 @@ PackedFile *BKE_packedfile_new(ReportList *reports, const char *filename, const
// XXX waitcursor(0);
- return (pf);
+ return pf;
}
/* no libraries for now */
@@ -365,7 +365,7 @@ int BKE_packedfile_write_to_file(ReportList *reports,
if (guimode) {
} // XXX waitcursor(0);
- return (ret_value);
+ return ret_value;
}
/**
@@ -415,11 +415,10 @@ enum ePF_FileCompare BKE_packedfile_compare_to_file(const char *ref_file_name,
ret_val = PF_CMP_DIFFERS;
break;
}
- else {
- if (memcmp(buf, ((char *)pf->data) + i, len)) {
- ret_val = PF_CMP_DIFFERS;
- break;
- }
+
+ if (memcmp(buf, ((char *)pf->data) + i, len) != 0) {
+ ret_val = PF_CMP_DIFFERS;
+ break;
}
}
@@ -427,7 +426,7 @@ enum ePF_FileCompare BKE_packedfile_compare_to_file(const char *ref_file_name,
}
}
- return (ret_val);
+ return ret_val;
}
/**
@@ -580,7 +579,7 @@ int BKE_packedfile_unpack_vfont(Main *bmain,
}
}
- return (ret_value);
+ return ret_value;
}
int BKE_packedfile_unpack_sound(Main *bmain,
@@ -610,7 +609,7 @@ int BKE_packedfile_unpack_sound(Main *bmain,
}
}
- return (ret_value);
+ return ret_value;
}
int BKE_packedfile_unpack_image(Main *bmain,
@@ -663,7 +662,7 @@ int BKE_packedfile_unpack_image(Main *bmain,
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_RELOAD);
}
- return (ret_value);
+ return ret_value;
}
int BKE_packedfile_unpack_volume(Main *bmain,
@@ -693,7 +692,7 @@ int BKE_packedfile_unpack_volume(Main *bmain,
}
}
- return (ret_value);
+ return ret_value;
}
int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
@@ -724,7 +723,7 @@ int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
}
}
- return (ret_value);
+ return ret_value;
}
void BKE_packedfile_pack_all_libraries(Main *bmain, ReportList *reports)
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 0ba5ec43318..19d5c34ad73 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -426,7 +426,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
if (sima->mode == SI_MODE_PAINT) {
return &ts->imapaint.paint;
}
- else if (sima->mode == SI_MODE_UV) {
+ if (sima->mode == SI_MODE_UV) {
return &ts->uvsculpt->paint;
}
}
@@ -460,7 +460,7 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C)
if (sima->mode == SI_MODE_PAINT) {
return PAINT_MODE_TEXTURE_2D;
}
- else if (sima->mode == SI_MODE_UV) {
+ if (sima->mode == SI_MODE_UV) {
return PAINT_MODE_SCULPT_UV;
}
}
@@ -715,7 +715,7 @@ static int palettecolor_compare_hsv(const void *a1, const void *a2)
if (ps1->h > ps2->h) {
return 1;
}
- else if (ps1->h < ps2->h) {
+ if (ps1->h < ps2->h) {
return -1;
}
@@ -723,7 +723,7 @@ static int palettecolor_compare_hsv(const void *a1, const void *a2)
if (ps1->s > ps2->s) {
return 1;
}
- else if (ps1->s < ps2->s) {
+ if (ps1->s < ps2->s) {
return -1;
}
@@ -731,7 +731,7 @@ static int palettecolor_compare_hsv(const void *a1, const void *a2)
if (1.0f - ps1->v > 1.0f - ps2->v) {
return 1;
}
- else if (1.0f - ps1->v < 1.0f - ps2->v) {
+ if (1.0f - ps1->v < 1.0f - ps2->v) {
return -1;
}
@@ -747,7 +747,7 @@ static int palettecolor_compare_svh(const void *a1, const void *a2)
if (ps1->s > ps2->s) {
return 1;
}
- else if (ps1->s < ps2->s) {
+ if (ps1->s < ps2->s) {
return -1;
}
@@ -755,7 +755,7 @@ static int palettecolor_compare_svh(const void *a1, const void *a2)
if (1.0f - ps1->v > 1.0f - ps2->v) {
return 1;
}
- else if (1.0f - ps1->v < 1.0f - ps2->v) {
+ if (1.0f - ps1->v < 1.0f - ps2->v) {
return -1;
}
@@ -763,7 +763,7 @@ static int palettecolor_compare_svh(const void *a1, const void *a2)
if (ps1->h > ps2->h) {
return 1;
}
- else if (ps1->h < ps2->h) {
+ if (ps1->h < ps2->h) {
return -1;
}
@@ -778,7 +778,7 @@ static int palettecolor_compare_vhs(const void *a1, const void *a2)
if (1.0f - ps1->v > 1.0f - ps2->v) {
return 1;
}
- else if (1.0f - ps1->v < 1.0f - ps2->v) {
+ if (1.0f - ps1->v < 1.0f - ps2->v) {
return -1;
}
@@ -786,7 +786,7 @@ static int palettecolor_compare_vhs(const void *a1, const void *a2)
if (ps1->h > ps2->h) {
return 1;
}
- else if (ps1->h < ps2->h) {
+ if (ps1->h < ps2->h) {
return -1;
}
@@ -794,7 +794,7 @@ static int palettecolor_compare_vhs(const void *a1, const void *a2)
if (ps1->s > ps2->s) {
return 1;
}
- else if (ps1->s < ps2->s) {
+ if (ps1->s < ps2->s) {
return -1;
}
@@ -811,7 +811,7 @@ static int palettecolor_compare_luminance(const void *a1, const void *a2)
if (lumi1 > lumi2) {
return -1;
}
- else if (lumi1 < lumi2) {
+ if (lumi1 < lumi2) {
return 1;
}
@@ -1424,9 +1424,8 @@ MultiresModifierData *BKE_sculpt_multires_active(Scene *scene, Object *ob)
if (mmd->sculptlvl > 0) {
return mmd;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
}
@@ -1468,7 +1467,7 @@ static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob)
if (mti->type == eModifierTypeType_OnlyDeform) {
return true;
}
- else if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) {
+ if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) {
return true;
}
}
@@ -1493,6 +1492,8 @@ static void sculpt_update_object(Depsgraph *depsgraph,
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob);
const bool use_face_sets = (ob->mode & OB_MODE_SCULPT) != 0;
+ ss->depsgraph = depsgraph;
+
ss->deform_modifiers_active = sculpt_modifiers_active(scene, sd, ob);
ss->show_mask = (sd->flags & SCULPT_HIDE_MASK) == 0;
ss->show_face_sets = (sd->flags & SCULPT_HIDE_FACE_SETS) == 0;
@@ -1691,7 +1692,6 @@ void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
CustomData_add_layer(&orig_me->vdata, CD_PROP_COLOR, CD_DEFAULT, NULL, orig_me->totvert);
BKE_mesh_update_customdata_pointers(orig_me, true);
DEG_id_tag_update(&orig_me->id, ID_RECALC_GEOMETRY);
- return;
}
void BKE_sculpt_update_object_for_edit(
@@ -2029,8 +2029,7 @@ bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const View3D *v3d)
const bool full_shading = (v3d && (v3d->shading.type > OB_SOLID));
return !(ss->shapekey_active || ss->deform_modifiers_active || full_shading);
}
- else {
- /* Multires and dyntopo always draw directly from the PBVH. */
- return true;
- }
+
+ /* Multires and dyntopo always draw directly from the PBVH. */
+ return true;
}
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index a003daf1042..b3da6c53b34 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -512,9 +512,8 @@ bool psys_check_edited(ParticleSystem *psys)
if (psys->part && psys->part->type == PART_HAIR) {
return (psys->flag & PSYS_EDITED || (psys->edit && psys->edit->edited));
}
- else {
- return (psys->pointcache->edit && psys->pointcache->edit->edited);
- }
+
+ return (psys->pointcache->edit && psys->pointcache->edit->edited);
}
void psys_find_group_weights(ParticleSettings *part)
@@ -1653,12 +1652,11 @@ int psys_particle_dm_face_lookup(Mesh *mesh_final,
// printf("\tNO CD_ORIGSPACE, assuming not needed\n");
return findex_orig;
}
- else {
- printf("\tNO CD_ORIGSPACE, error out of range\n");
- return DMCACHE_NOTFOUND;
- }
+
+ printf("\tNO CD_ORIGSPACE, error out of range\n");
+ return DMCACHE_NOTFOUND;
}
- else if (findex_orig >= mesh_original->totface) {
+ if (findex_orig >= mesh_original->totface) {
return DMCACHE_NOTFOUND; /* index not in the original mesh */
}
@@ -1919,7 +1917,7 @@ static void psys_particle_on_shape(int UNUSED(distr),
float orco[3])
{
/* TODO */
- float zerovec[3] = {0.0f, 0.0f, 0.0f};
+ const float zerovec[3] = {0.0f, 0.0f, 0.0f};
if (vec) {
copy_v3_v3(vec, zerovec);
}
@@ -2170,10 +2168,10 @@ int do_guides(Depsgraph *depsgraph,
{
ParticleKey key;
- float par_co[3] = {0.0f, 0.0f, 0.0f};
- float par_vel[3] = {0.0f, 0.0f, 0.0f};
- float par_rot[4] = {1.0f, 0.0f, 0.0f, 0.0f};
- float orco_offset[3] = {0.0f, 0.0f, 0.0f};
+ const float par_co[3] = {0.0f, 0.0f, 0.0f};
+ const float par_vel[3] = {0.0f, 0.0f, 0.0f};
+ const float par_rot[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+ const float orco_offset[3] = {0.0f, 0.0f, 0.0f};
copy_v3_v3(key.co, vec_to_point);
do_kink(&key,
@@ -2555,9 +2553,8 @@ static void psys_thread_create_path(ParticleTask *task,
if (!needupdate) {
return;
}
- else {
- memset(child_keys, 0, sizeof(*child_keys) * (ctx->segments + 1));
- }
+
+ memset(child_keys, 0, sizeof(*child_keys) * (ctx->segments + 1));
}
/* get parent paths */
@@ -3483,7 +3480,7 @@ static void triatomat(float *v1, float *v2, float *v3, float (*uv)[2], float mat
{
float det, w1, w2, d1[2], d2[2];
- memset(mat, 0, sizeof(float) * 4 * 4);
+ memset(mat, 0, sizeof(float[4][4]));
mat[3][3] = 1.0f;
/* first axis is the normal */
@@ -3871,7 +3868,7 @@ void BKE_particlesettings_clump_curve_init(ParticleSettings *part)
cumap->cm[0].curve[1].x = 1.0f;
cumap->cm[0].curve[1].y = 1.0f;
- BKE_curvemapping_initialize(cumap);
+ BKE_curvemapping_init(cumap);
part->clumpcurve = cumap;
}
@@ -3885,7 +3882,7 @@ void BKE_particlesettings_rough_curve_init(ParticleSettings *part)
cumap->cm[0].curve[1].x = 1.0f;
cumap->cm[0].curve[1].y = 1.0f;
- BKE_curvemapping_initialize(cumap);
+ BKE_curvemapping_init(cumap);
part->roughcurve = cumap;
}
@@ -3899,7 +3896,7 @@ void BKE_particlesettings_twist_curve_init(ParticleSettings *part)
cumap->cm[0].curve[1].x = 1.0f;
cumap->cm[0].curve[1].y = 1.0f;
- BKE_curvemapping_initialize(cumap);
+ BKE_curvemapping_init(cumap);
part->twistcurve = cumap;
}
@@ -4388,7 +4385,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
short cpa_from;
/* initialize keys to zero */
- memset(keys, 0, 4 * sizeof(ParticleKey));
+ memset(keys, 0, sizeof(ParticleKey[4]));
t = state->time;
CLAMP(t, 0.0f, 1.0f);
@@ -4666,10 +4663,9 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
psys_get_particle_on_path(sim, p, state, 1);
return 1;
}
- else {
- cpa = sim->psys->child + p - totpart;
- pa = sim->psys->particles + cpa->parent;
- }
+
+ cpa = sim->psys->child + p - totpart;
+ pa = sim->psys->particles + cpa->parent;
}
else {
pa = sim->psys->particles + p;
@@ -4691,106 +4687,105 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
psys_get_particle_on_path(sim, p, state, 1);
return 1;
}
- else {
- if (cpa) {
- float mat[4][4];
- ParticleKey *key1;
- float t = (cfra - pa->time) / pa->lifetime;
- float par_orco[3] = {0.0f, 0.0f, 0.0f};
- key1 = &pa->state;
- offset_child(cpa, key1, key1->rot, state, part->childflat, part->childrad);
+ if (cpa) {
+ float mat[4][4];
+ ParticleKey *key1;
+ float t = (cfra - pa->time) / pa->lifetime;
+ const float par_orco[3] = {0.0f, 0.0f, 0.0f};
- CLAMP(t, 0.0f, 1.0f);
+ key1 = &pa->state;
+ offset_child(cpa, key1, key1->rot, state, part->childflat, part->childrad);
- unit_m4(mat);
- ParticleChildModifierContext modifier_ctx = {NULL};
- modifier_ctx.thread_ctx = NULL;
- modifier_ctx.sim = sim;
- modifier_ctx.ptex = NULL;
- modifier_ctx.cpa = cpa;
- modifier_ctx.orco = cpa->fuv;
- modifier_ctx.par_co = key1->co;
- modifier_ctx.par_vel = key1->vel;
- modifier_ctx.par_rot = key1->rot;
- modifier_ctx.par_orco = par_orco;
- modifier_ctx.parent_keys = psys->childcache ? psys->childcache[p - totpart] : NULL;
+ CLAMP(t, 0.0f, 1.0f);
- do_child_modifiers(&modifier_ctx, mat, state, t);
+ unit_m4(mat);
+ ParticleChildModifierContext modifier_ctx = {NULL};
+ modifier_ctx.thread_ctx = NULL;
+ modifier_ctx.sim = sim;
+ modifier_ctx.ptex = NULL;
+ modifier_ctx.cpa = cpa;
+ modifier_ctx.orco = cpa->fuv;
+ modifier_ctx.par_co = key1->co;
+ modifier_ctx.par_vel = key1->vel;
+ modifier_ctx.par_rot = key1->rot;
+ modifier_ctx.par_orco = par_orco;
+ modifier_ctx.parent_keys = psys->childcache ? psys->childcache[p - totpart] : NULL;
- if (psys->lattice_deform_data) {
- BKE_lattice_deform_data_eval_co(
- psys->lattice_deform_data, state->co, psys->lattice_strength);
- }
+ do_child_modifiers(&modifier_ctx, mat, state, t);
+
+ if (psys->lattice_deform_data) {
+ BKE_lattice_deform_data_eval_co(
+ psys->lattice_deform_data, state->co, psys->lattice_strength);
+ }
+ }
+ else {
+ if (pa->state.time == cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) {
+ copy_particle_key(state, &pa->state, 1);
+ }
+ else if (pa->prev_state.time == cfra) {
+ copy_particle_key(state, &pa->prev_state, 1);
}
else {
- if (pa->state.time == cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) {
- copy_particle_key(state, &pa->state, 1);
- }
- else if (pa->prev_state.time == cfra) {
- copy_particle_key(state, &pa->prev_state, 1);
- }
- else {
- float dfra, frs_sec = sim->scene->r.frs_sec;
- /* let's interpolate to try to be as accurate as possible */
- if (pa->state.time + 2.f >= state->time && pa->prev_state.time - 2.f <= state->time) {
- if (pa->prev_state.time >= pa->state.time || pa->prev_state.time < 0.f) {
- /* prev_state is wrong so let's not use it,
- * this can happen at frames 1, 0 or particle birth. */
- dfra = state->time - pa->state.time;
+ float dfra, frs_sec = sim->scene->r.frs_sec;
+ /* let's interpolate to try to be as accurate as possible */
+ if (pa->state.time + 2.f >= state->time && pa->prev_state.time - 2.f <= state->time) {
+ if (pa->prev_state.time >= pa->state.time || pa->prev_state.time < 0.f) {
+ /* prev_state is wrong so let's not use it,
+ * this can happen at frames 1, 0 or particle birth. */
+ dfra = state->time - pa->state.time;
- copy_particle_key(state, &pa->state, 1);
+ copy_particle_key(state, &pa->state, 1);
- madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec);
- }
- else {
- ParticleKey keys[4];
- float keytime;
+ madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec);
+ }
+ else {
+ ParticleKey keys[4];
+ float keytime;
- copy_particle_key(keys + 1, &pa->prev_state, 1);
- copy_particle_key(keys + 2, &pa->state, 1);
+ copy_particle_key(keys + 1, &pa->prev_state, 1);
+ copy_particle_key(keys + 2, &pa->state, 1);
- dfra = keys[2].time - keys[1].time;
+ dfra = keys[2].time - keys[1].time;
- keytime = (state->time - keys[1].time) / dfra;
+ keytime = (state->time - keys[1].time) / dfra;
- /* convert velocity to timestep size */
- mul_v3_fl(keys[1].vel, dfra * timestep);
- mul_v3_fl(keys[2].vel, dfra * timestep);
+ /* convert velocity to timestep size */
+ mul_v3_fl(keys[1].vel, dfra * timestep);
+ mul_v3_fl(keys[2].vel, dfra * timestep);
- psys_interpolate_particle(-1, keys, keytime, state, 1);
+ psys_interpolate_particle(-1, keys, keytime, state, 1);
- /* convert back to real velocity */
- mul_v3_fl(state->vel, 1.f / (dfra * timestep));
+ /* convert back to real velocity */
+ mul_v3_fl(state->vel, 1.f / (dfra * timestep));
- interp_v3_v3v3(state->ave, keys[1].ave, keys[2].ave, keytime);
- interp_qt_qtqt(state->rot, keys[1].rot, keys[2].rot, keytime);
- }
+ interp_v3_v3v3(state->ave, keys[1].ave, keys[2].ave, keytime);
+ interp_qt_qtqt(state->rot, keys[1].rot, keys[2].rot, keytime);
}
- else if (pa->state.time + 1.f >= state->time && pa->state.time - 1.f <= state->time) {
- /* linear interpolation using only pa->state */
+ }
+ else if (pa->state.time + 1.f >= state->time && pa->state.time - 1.f <= state->time) {
+ /* linear interpolation using only pa->state */
- dfra = state->time - pa->state.time;
+ dfra = state->time - pa->state.time;
- copy_particle_key(state, &pa->state, 1);
+ copy_particle_key(state, &pa->state, 1);
- madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec);
- }
- else {
- /* Extrapolating over big ranges is not accurate
- * so let's just give something close to reasonable back. */
- copy_particle_key(state, &pa->state, 0);
- }
+ madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec);
}
-
- if (sim->psys->lattice_deform_data) {
- BKE_lattice_deform_data_eval_co(
- sim->psys->lattice_deform_data, state->co, psys->lattice_strength);
+ else {
+ /* Extrapolating over big ranges is not accurate
+ * so let's just give something close to reasonable back. */
+ copy_particle_key(state, &pa->state, 0);
}
}
- return 1;
+ if (sim->psys->lattice_deform_data) {
+ BKE_lattice_deform_data_eval_co(
+ sim->psys->lattice_deform_data, state->co, psys->lattice_strength);
+ }
}
+
+ return 1;
}
void psys_get_dupli_texture(ParticleSystem *psys,
@@ -4844,9 +4839,8 @@ void psys_get_dupli_texture(ParticleSystem *psys,
orco);
return;
}
- else {
- pa = psys->particles + cpa->pa[0];
- }
+
+ pa = psys->particles + cpa->pa[0];
}
if ((part->from == PART_FROM_FACE) && (psmd->mesh_final != NULL) && !is_grid) {
diff --git a/source/blender/blenkernel/intern/particle_child.c b/source/blender/blenkernel/intern/particle_child.c
index dcd2a0b8fae..da5fdc85561 100644
--- a/source/blender/blenkernel/intern/particle_child.c
+++ b/source/blender/blenkernel/intern/particle_child.c
@@ -305,10 +305,9 @@ static bool check_path_length(int k,
/* something over the maximum step value */
return false;
}
- else {
- *cur_length += step_length;
- return true;
- }
+
+ *cur_length += step_length;
+ return true;
}
void psys_apply_child_modifiers(ParticleThreadContext *ctx,
@@ -685,7 +684,7 @@ static void do_rough(const float loc[3],
}
static void do_rough_end(
- const float loc[3], float mat[4][4], float t, float fac, float shape, ParticleKey *state)
+ const float loc[3], const float mat[4][4], float t, float fac, float shape, ParticleKey *state)
{
float rough[2];
float roughfac;
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index e0dccd4d14a..fad93245a04 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -382,7 +382,7 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount)
x -= (float)floor(x);
}
- jit2 = MEM_mallocN(12 + 2 * sizeof(float) * num, "initjit");
+ jit2 = MEM_mallocN(12 + sizeof(float[2]) * num, "initjit");
for (i = 0; i < 4; i++) {
BLI_jitterate1((float(*)[2])jit, (float(*)[2])jit2, num, rad1);
@@ -829,22 +829,20 @@ static int distribute_compare_orig_index(const void *p1, const void *p2, void *u
if (index1 < index2) {
return -1;
}
- else if (index1 == index2) {
+ if (index1 == index2) {
/* this pointer comparison appears to make qsort stable for glibc,
* and apparently on solaris too, makes the renders reproducible */
if (p1 < p2) {
return -1;
}
- else if (p1 == p2) {
+ if (p1 == p2) {
return 0;
}
- else {
- return 1;
- }
- }
- else {
+
return 1;
}
+
+ return 1;
}
static void distribute_invalid(ParticleSimulationData *sim, int from)
@@ -1282,7 +1280,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
hammersley_create(jit, jitlevel + 1, psys->seed, part->jitfac);
}
BLI_array_randomize(
- jit, 2 * sizeof(float), jitlevel, psys->seed); /* for custom jit or even distribution */
+ jit, sizeof(float[2]), jitlevel, psys->seed); /* for custom jit or even distribution */
}
/* Setup things for threaded distribution */
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index bec9cbbad79..7bfc0ca764f 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -106,9 +106,8 @@ static int particles_are_dynamic(ParticleSystem *psys)
if (psys->part->type == PART_HAIR) {
return psys->flag & PSYS_HAIR_DYNAMICS;
}
- else {
- return ELEM(psys->part->phystype, PART_PHYS_NEWTON, PART_PHYS_BOIDS, PART_PHYS_FLUID);
- }
+
+ return ELEM(psys->part->phystype, PART_PHYS_NEWTON, PART_PHYS_BOIDS, PART_PHYS_FLUID);
}
float psys_get_current_display_percentage(ParticleSystem *psys, const bool use_render_params)
@@ -131,12 +130,11 @@ static int tot_particles(ParticleSystem *psys, PTCacheID *pid)
if (pid && psys->pointcache->flag & PTCACHE_EXTERNAL) {
return pid->cache->totpoint;
}
- else if (psys->part->distr == PART_DISTR_GRID && psys->part->from != PART_FROM_VERT) {
+ if (psys->part->distr == PART_DISTR_GRID && psys->part->from != PART_FROM_VERT) {
return psys->part->grid_res * psys->part->grid_res * psys->part->grid_res - psys->totunexist;
}
- else {
- return psys->part->totpart - psys->totunexist;
- }
+
+ return psys->part->totpart - psys->totunexist;
}
void psys_reset(ParticleSystem *psys, int mode)
@@ -570,7 +568,7 @@ void psys_thread_context_free(ParticleThreadContext *ctx)
}
}
-static void initialize_particle_texture(ParticleSimulationData *sim, ParticleData *pa, int p)
+static void init_particle_texture(ParticleSimulationData *sim, ParticleData *pa, int p)
{
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
@@ -595,7 +593,7 @@ static void initialize_particle_texture(ParticleSimulationData *sim, ParticleDat
}
/* set particle parameters that don't change during particle's life */
-void initialize_particle(ParticleSimulationData *sim, ParticleData *pa)
+void init_particle(ParticleSimulationData *sim, ParticleData *pa)
{
ParticleSettings *part = sim->psys->part;
float birth_time = (float)(pa - sim->psys->particles) / (float)sim->psys->totpart;
@@ -629,7 +627,7 @@ static void initialize_all_particles(ParticleSimulationData *sim)
LOOP_PARTICLES
{
if (!(emit_from_volume_grid && (pa->flag & PARS_UNEXIST) != 0)) {
- initialize_particle(sim, pa);
+ init_particle(sim, pa);
}
}
}
@@ -1092,7 +1090,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
* We could only do it now because we'll need to know coordinate
* before sampling the texture.
*/
- initialize_particle_texture(sim, pa, p);
+ init_particle_texture(sim, pa, p);
if (part->phystype == PART_PHYS_BOIDS && pa->boid) {
BoidParticle *bpa = pa->boid;
@@ -1709,13 +1707,12 @@ static void sph_evaluate_func(BVHTree *tree,
BLI_bvhtree_range_query(tree, co, interaction_radius, callback, pfr);
break;
}
- else {
- BLI_rw_mutex_lock(&psys_bvhtree_rwlock, THREAD_LOCK_READ);
- BLI_bvhtree_range_query(psys[i]->bvhtree, co, interaction_radius, callback, pfr);
+ BLI_rw_mutex_lock(&psys_bvhtree_rwlock, THREAD_LOCK_READ);
- BLI_rw_mutex_unlock(&psys_bvhtree_rwlock);
- }
+ BLI_bvhtree_range_query(psys[i]->bvhtree, co, interaction_radius, callback, pfr);
+
+ BLI_rw_mutex_unlock(&psys_bvhtree_rwlock);
}
}
static void sph_density_accum_cb(void *userdata, int index, const float co[3], float squared_dist)
@@ -2612,9 +2609,8 @@ static float collision_newton_rhapson(ParticleCollision *col,
d1 = 0.f;
continue;
}
- else {
- return -1.f;
- }
+
+ return -1.f;
}
dd = (t1 - t0) / (d1 - d0);
@@ -2634,7 +2630,7 @@ static float collision_newton_rhapson(ParticleCollision *col,
d1 = 0.f;
continue;
}
- else if (iter == 1 && (t1 < -COLLISION_ZERO || t1 > 1.f)) {
+ if (iter == 1 && (t1 < -COLLISION_ZERO || t1 > 1.f)) {
return -1.f;
}
@@ -2648,9 +2644,8 @@ static float collision_newton_rhapson(ParticleCollision *col,
return t1;
}
- else {
- return -1.f;
- }
+
+ return -1.f;
}
}
return -1.0;
@@ -2927,164 +2922,163 @@ static int collision_response(ParticleSimulationData *sim,
return 0;
}
/* figure out velocity and other data after collision */
- else {
- /* velocity directly before collision to be modified into velocity directly after collision */
- float v0[3];
- /* normal component of v0 */
- float v0_nor[3];
- /* tangential component of v0 */
- float v0_tan[3];
- /* tangential component of collision surface velocity */
- float vc_tan[3];
- float v0_dot, vc_dot;
- float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_rng_get_float(rng) - 0.5f);
- float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_rng_get_float(rng) - 0.5f);
- float distance, nor[3], dot;
-
- CLAMP(damp, 0.0f, 1.0f);
- CLAMP(frict, 0.0f, 1.0f);
-
- /* get exact velocity right before collision */
- madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1);
-
- /* Convert collider velocity from `1/frame_step` to `1/s` TODO:
- * here we assume 1 frame step for collision modifier. */
- mul_v3_fl(pce->vel, col->inv_timestep);
-
- /* calculate tangential particle velocity */
- v0_dot = dot_v3v3(pce->nor, v0);
- madd_v3_v3v3fl(v0_tan, v0, pce->nor, -v0_dot);
-
- /* calculate tangential collider velocity */
- vc_dot = dot_v3v3(pce->nor, pce->vel);
- madd_v3_v3v3fl(vc_tan, pce->vel, pce->nor, -vc_dot);
-
- /* handle friction effects (tangential and angular velocity) */
- if (frict > 0.0f) {
- /* angular <-> linear velocity */
- if (dynamic_rotation) {
- float vr_tan[3], v1_tan[3], ave[3];
-
- /* linear velocity of particle surface */
- cross_v3_v3v3(vr_tan, pce->nor, pa->state.ave);
- mul_v3_fl(vr_tan, pa->size);
-
- /* change to coordinates that move with the collision plane */
- sub_v3_v3v3(v1_tan, v0_tan, vc_tan);
-
- /* The resulting velocity is a weighted average of particle cm & surface
- * velocity. This weight (related to particle's moment of inertia) could
- * be made a parameter for angular <-> linear conversion.
- */
- madd_v3_v3fl(v1_tan, vr_tan, -0.4);
- mul_v3_fl(v1_tan, 1.0f / 1.4f); /* 1/(1+0.4) */
- /* rolling friction is around 0.01 of sliding friction
- * (could be made a parameter) */
- mul_v3_fl(v1_tan, 1.0f - 0.01f * frict);
-
- /* surface_velocity is opposite to cm velocity */
- negate_v3_v3(vr_tan, v1_tan);
-
- /* get back to global coordinates */
- add_v3_v3(v1_tan, vc_tan);
-
- /* convert to angular velocity*/
- cross_v3_v3v3(ave, vr_tan, pce->nor);
- mul_v3_fl(ave, 1.0f / MAX2(pa->size, 0.001f));
-
- /* only friction will cause change in linear & angular velocity */
- interp_v3_v3v3(pa->state.ave, pa->state.ave, ave, frict);
- interp_v3_v3v3(v0_tan, v0_tan, v1_tan, frict);
- }
- else {
- /* just basic friction (unphysical due to the friction model used in Blender) */
- interp_v3_v3v3(v0_tan, v0_tan, vc_tan, frict);
- }
+ /* velocity directly before collision to be modified into velocity directly after collision */
+ float v0[3];
+ /* normal component of v0 */
+ float v0_nor[3];
+ /* tangential component of v0 */
+ float v0_tan[3];
+ /* tangential component of collision surface velocity */
+ float vc_tan[3];
+ float v0_dot, vc_dot;
+ float damp = pd->pdef_damp + pd->pdef_rdamp * 2 * (BLI_rng_get_float(rng) - 0.5f);
+ float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_rng_get_float(rng) - 0.5f);
+ float distance, nor[3], dot;
+
+ CLAMP(damp, 0.0f, 1.0f);
+ CLAMP(frict, 0.0f, 1.0f);
+
+ /* get exact velocity right before collision */
+ madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1);
+
+ /* Convert collider velocity from `1/frame_step` to `1/s` TODO:
+ * here we assume 1 frame step for collision modifier. */
+ mul_v3_fl(pce->vel, col->inv_timestep);
+
+ /* calculate tangential particle velocity */
+ v0_dot = dot_v3v3(pce->nor, v0);
+ madd_v3_v3v3fl(v0_tan, v0, pce->nor, -v0_dot);
+
+ /* calculate tangential collider velocity */
+ vc_dot = dot_v3v3(pce->nor, pce->vel);
+ madd_v3_v3v3fl(vc_tan, pce->vel, pce->nor, -vc_dot);
+
+ /* handle friction effects (tangential and angular velocity) */
+ if (frict > 0.0f) {
+ /* angular <-> linear velocity */
+ if (dynamic_rotation) {
+ float vr_tan[3], v1_tan[3], ave[3];
+
+ /* linear velocity of particle surface */
+ cross_v3_v3v3(vr_tan, pce->nor, pa->state.ave);
+ mul_v3_fl(vr_tan, pa->size);
+
+ /* change to coordinates that move with the collision plane */
+ sub_v3_v3v3(v1_tan, v0_tan, vc_tan);
+
+ /* The resulting velocity is a weighted average of particle cm & surface
+ * velocity. This weight (related to particle's moment of inertia) could
+ * be made a parameter for angular <-> linear conversion.
+ */
+ madd_v3_v3fl(v1_tan, vr_tan, -0.4);
+ mul_v3_fl(v1_tan, 1.0f / 1.4f); /* 1/(1+0.4) */
+
+ /* rolling friction is around 0.01 of sliding friction
+ * (could be made a parameter) */
+ mul_v3_fl(v1_tan, 1.0f - 0.01f * frict);
+
+ /* surface_velocity is opposite to cm velocity */
+ negate_v3_v3(vr_tan, v1_tan);
+
+ /* get back to global coordinates */
+ add_v3_v3(v1_tan, vc_tan);
+
+ /* convert to angular velocity*/
+ cross_v3_v3v3(ave, vr_tan, pce->nor);
+ mul_v3_fl(ave, 1.0f / MAX2(pa->size, 0.001f));
+
+ /* only friction will cause change in linear & angular velocity */
+ interp_v3_v3v3(pa->state.ave, pa->state.ave, ave, frict);
+ interp_v3_v3v3(v0_tan, v0_tan, v1_tan, frict);
}
+ else {
+ /* just basic friction (unphysical due to the friction model used in Blender) */
+ interp_v3_v3v3(v0_tan, v0_tan, vc_tan, frict);
+ }
+ }
- /* Stickiness was possibly added before,
- * so cancel that before calculating new normal velocity.
- * Otherwise particles go flying out of the surface
- * because of high reversed sticky velocity. */
- if (v0_dot < 0.0f) {
- v0_dot += pd->pdef_stickness;
- if (v0_dot > 0.0f) {
- v0_dot = 0.0f;
- }
+ /* Stickiness was possibly added before,
+ * so cancel that before calculating new normal velocity.
+ * Otherwise particles go flying out of the surface
+ * because of high reversed sticky velocity. */
+ if (v0_dot < 0.0f) {
+ v0_dot += pd->pdef_stickness;
+ if (v0_dot > 0.0f) {
+ v0_dot = 0.0f;
}
+ }
- /* damping and flipping of velocity around normal */
- v0_dot *= 1.0f - damp;
- vc_dot *= through ? damp : 1.0f;
+ /* damping and flipping of velocity around normal */
+ v0_dot *= 1.0f - damp;
+ vc_dot *= through ? damp : 1.0f;
- /* calculate normal particle velocity */
- /* special case for object hitting the particle from behind */
- if (through == 0 && ((vc_dot > 0.0f && v0_dot > 0.0f && vc_dot > v0_dot) ||
- (vc_dot < 0.0f && v0_dot < 0.0f && vc_dot < v0_dot))) {
- mul_v3_v3fl(v0_nor, pce->nor, vc_dot);
- }
- else if (v0_dot > 0.f) {
- mul_v3_v3fl(v0_nor, pce->nor, vc_dot + v0_dot);
- }
- else {
- mul_v3_v3fl(v0_nor, pce->nor, vc_dot + (through ? 1.0f : -1.0f) * v0_dot);
- }
+ /* calculate normal particle velocity */
+ /* special case for object hitting the particle from behind */
+ if (through == 0 && ((vc_dot > 0.0f && v0_dot > 0.0f && vc_dot > v0_dot) ||
+ (vc_dot < 0.0f && v0_dot < 0.0f && vc_dot < v0_dot))) {
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot);
+ }
+ else if (v0_dot > 0.f) {
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot + v0_dot);
+ }
+ else {
+ mul_v3_v3fl(v0_nor, pce->nor, vc_dot + (through ? 1.0f : -1.0f) * v0_dot);
+ }
- /* combine components together again */
- add_v3_v3v3(v0, v0_nor, v0_tan);
+ /* combine components together again */
+ add_v3_v3v3(v0, v0_nor, v0_tan);
- if (col->boid) {
- /* keep boids above ground */
- BoidParticle *bpa = pa->boid;
- if (bpa->data.mode == eBoidMode_OnLand || co[2] <= col->boid_z) {
- co[2] = col->boid_z;
- v0[2] = 0.0f;
- }
+ if (col->boid) {
+ /* keep boids above ground */
+ BoidParticle *bpa = pa->boid;
+ if (bpa->data.mode == eBoidMode_OnLand || co[2] <= col->boid_z) {
+ co[2] = col->boid_z;
+ v0[2] = 0.0f;
}
+ }
- /* re-apply acceleration to final location and velocity */
- madd_v3_v3v3fl(pa->state.co, co, v0, dt2);
- madd_v3_v3fl(pa->state.co, col->acc, 0.5f * dt2 * dt2);
- madd_v3_v3v3fl(pa->state.vel, v0, col->acc, dt2);
+ /* re-apply acceleration to final location and velocity */
+ madd_v3_v3v3fl(pa->state.co, co, v0, dt2);
+ madd_v3_v3fl(pa->state.co, col->acc, 0.5f * dt2 * dt2);
+ madd_v3_v3v3fl(pa->state.vel, v0, col->acc, dt2);
- /* make sure particle stays on the right side of the surface */
- if (!through) {
- distance = collision_point_distance_with_normal(co, pce, -1.f, col, nor);
+ /* make sure particle stays on the right side of the surface */
+ if (!through) {
+ distance = collision_point_distance_with_normal(co, pce, -1.f, col, nor);
- if (distance < col->radius + COLLISION_MIN_DISTANCE) {
- madd_v3_v3fl(co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
- }
+ if (distance < col->radius + COLLISION_MIN_DISTANCE) {
+ madd_v3_v3fl(co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
+ }
- dot = dot_v3v3(nor, v0);
- if (dot < 0.f) {
- madd_v3_v3fl(v0, nor, -dot);
- }
+ dot = dot_v3v3(nor, v0);
+ if (dot < 0.f) {
+ madd_v3_v3fl(v0, nor, -dot);
+ }
- distance = collision_point_distance_with_normal(pa->state.co, pce, 1.f, col, nor);
+ distance = collision_point_distance_with_normal(pa->state.co, pce, 1.f, col, nor);
- if (distance < col->radius + COLLISION_MIN_DISTANCE) {
- madd_v3_v3fl(pa->state.co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
- }
+ if (distance < col->radius + COLLISION_MIN_DISTANCE) {
+ madd_v3_v3fl(pa->state.co, nor, col->radius + COLLISION_MIN_DISTANCE - distance);
+ }
- dot = dot_v3v3(nor, pa->state.vel);
- if (dot < 0.f) {
- madd_v3_v3fl(pa->state.vel, nor, -dot);
- }
+ dot = dot_v3v3(nor, pa->state.vel);
+ if (dot < 0.f) {
+ madd_v3_v3fl(pa->state.vel, nor, -dot);
}
+ }
- /* add stickiness to surface */
- madd_v3_v3fl(pa->state.vel, pce->nor, -pd->pdef_stickness);
+ /* add stickiness to surface */
+ madd_v3_v3fl(pa->state.vel, pce->nor, -pd->pdef_stickness);
- /* set coordinates for next iteration */
- copy_v3_v3(col->co1, co);
- copy_v3_v3(col->co2, pa->state.co);
+ /* set coordinates for next iteration */
+ copy_v3_v3(col->co1, co);
+ copy_v3_v3(col->co2, pa->state.co);
- copy_v3_v3(col->ve1, v0);
- copy_v3_v3(col->ve2, pa->state.vel);
+ copy_v3_v3(col->ve1, v0);
+ copy_v3_v3(col->ve2, pa->state.vel);
- col->f = f;
- }
+ col->f = f;
/* if permeability random roll succeeded, disable collider for this sim step */
if (through) {
@@ -3676,12 +3670,11 @@ static float sync_timestep(ParticleSystem *psys, float t_frac)
if (t_frac == 1.0f) {
return psys->dt_frac;
}
- else if (t_frac + (psys->dt_frac * TIMESTEP_EXPANSION_TOLERANCE) >= 1.0f) {
+ if (t_frac + (psys->dt_frac * TIMESTEP_EXPANSION_TOLERANCE) >= 1.0f) {
return 1.0f - t_frac;
}
- else {
- return psys->dt_frac;
- }
+
+ return psys->dt_frac;
}
/************************************************/
@@ -4372,7 +4365,7 @@ static void particles_fluid_step(ParticleSimulationData *sim,
max_size = MAX3(size[0] / (float)upres, size[1] / (float)upres, size[2] / (float)upres);
/* Set particle position. */
- float posParticle[3] = {posX, posY, posZ};
+ const float posParticle[3] = {posX, posY, posZ};
copy_v3_v3(pa->state.co, posParticle);
/* Normalize to unit cube around 0. */
@@ -4405,7 +4398,7 @@ static void particles_fluid_step(ParticleSimulationData *sim,
pa->state.co[0], pa->state.co[1], pa->state.co[2]);
# endif
/* Set particle velocity. */
- float velParticle[3] = {velX, velY, velZ};
+ const float velParticle[3] = {velX, velY, velZ};
copy_v3_v3(pa->state.vel, velParticle);
mul_v3_fl(pa->state.vel, fds->dx);
# if 0
@@ -4537,11 +4530,11 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
return;
}
/* Cache is supposed to be baked, but no data was found so bail out */
- else if (cache->flag & PTCACHE_BAKED) {
+ if (cache->flag & PTCACHE_BAKED) {
psys_reset(psys, PSYS_RESET_CACHE_MISS);
return;
}
- else if (cache_result == PTCACHE_READ_OLD) {
+ if (cache_result == PTCACHE_READ_OLD) {
psys->cfra = (float)cache->simframe;
cached_step(sim, psys->cfra, use_render_params);
}
@@ -4584,7 +4577,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
psys->dt_frac = get_base_time_step(part);
}
else if ((int)cfra == startframe) {
- /* Variable time step; initialise to subframes */
+ /* Variable time step; initialize to sub-frames. */
psys->dt_frac = get_base_time_step(part);
}
else if (psys->dt_frac < MIN_TIMESTEP) {
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 92a47f24240..1e4ea19adb6 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -109,18 +109,15 @@ int BB_widest_axis(const BB *bb)
if (dim[0] > dim[2]) {
return 0;
}
- else {
- return 2;
- }
+
+ return 2;
}
- else {
- if (dim[1] > dim[2]) {
- return 1;
- }
- else {
- return 2;
- }
+
+ if (dim[1] > dim[2]) {
+ return 1;
}
+
+ return 2;
}
void BBC_update_centroid(BBC *bbc)
@@ -275,9 +272,8 @@ static int map_insert_vert(
*value_p = POINTER_FROM_INT(value_i);
return value_i;
}
- else {
- return POINTER_AS_INT(*value_p);
- }
+
+ return POINTER_AS_INT(*value_p);
}
/* Find vertices used by the faces in this node and update the draw buffers */
@@ -804,14 +800,13 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter)
/* immediately hit leaf node */
return node;
}
- else {
- /* come back later when children are done */
- pbvh_stack_push(iter, node, true);
- /* push two child nodes on the stack */
- pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset + 1, false);
- pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
- }
+ /* come back later when children are done */
+ pbvh_stack_push(iter, node, true);
+
+ /* push two child nodes on the stack */
+ pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset + 1, false);
+ pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
}
return NULL;
@@ -838,10 +833,9 @@ static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
/* immediately hit leaf node */
return node;
}
- else {
- pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset + 1, false);
- pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
- }
+
+ pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset + 1, false);
+ pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
}
return NULL;
@@ -1391,16 +1385,15 @@ static int pbvh_flush_bb(PBVH *pbvh, PBVHNode *node, int flag)
return update;
}
- else {
- update |= pbvh_flush_bb(pbvh, pbvh->nodes + node->children_offset, flag);
- update |= pbvh_flush_bb(pbvh, pbvh->nodes + node->children_offset + 1, flag);
- if (update & PBVH_UpdateBB) {
- update_node_vb(pbvh, node);
- }
- if (update & PBVH_UpdateOriginalBB) {
- node->orig_vb = node->vb;
- }
+ update |= pbvh_flush_bb(pbvh, pbvh->nodes + node->children_offset, flag);
+ update |= pbvh_flush_bb(pbvh, pbvh->nodes + node->children_offset + 1, flag);
+
+ if (update & PBVH_UpdateBB) {
+ update_node_vb(pbvh, node);
+ }
+ if (update & PBVH_UpdateOriginalBB) {
+ node->orig_vb = node->vb;
}
return update;
@@ -1667,9 +1660,8 @@ bool BKE_pbvh_has_faces(const PBVH *pbvh)
if (pbvh->type == PBVH_BMESH) {
return (pbvh->bm->totface != 0);
}
- else {
- return (pbvh->totprim != 0);
- }
+
+ return (pbvh->totprim != 0);
}
void BKE_pbvh_bounding_box(const PBVH *pbvh, float min[3], float max[3])
@@ -2029,9 +2021,8 @@ bool ray_face_intersection_quad(const float ray_start[3],
*depth = depth_test;
return true;
}
- else {
- return false;
- }
+
+ return false;
}
bool ray_face_intersection_tri(const float ray_start[3],
@@ -2047,9 +2038,8 @@ bool ray_face_intersection_tri(const float ray_start[3],
*depth = depth_test;
return true;
}
- else {
- return false;
- }
+
+ return false;
}
/* Take advantage of the fact we know this wont be an intersection.
@@ -2100,9 +2090,8 @@ bool ray_face_nearest_quad(const float ray_start[3],
}
return true;
}
- else {
- return false;
- }
+
+ return false;
}
bool ray_face_nearest_tri(const float ray_start[3],
@@ -2122,9 +2111,8 @@ bool ray_face_nearest_tri(const float ray_start[3],
*depth = depth_test;
return true;
}
- else {
- return false;
- }
+
+ return false;
}
static bool pbvh_faces_node_raycast(PBVH *pbvh,
@@ -2357,7 +2345,7 @@ void BKE_pbvh_raycast_project_ray_root(
struct IsectRayAABB_Precalc ray;
float ray_normal_inv[3];
float offset = 1.0f + 1e-3f;
- float offset_vec[3] = {1e-3f, 1e-3f, 1e-3f};
+ const float offset_vec[3] = {1e-3f, 1e-3f, 1e-3f};
if (original) {
BKE_pbvh_node_get_original_BB(pbvh->nodes, bb_min_root, bb_max_root);
@@ -2617,7 +2605,7 @@ static PlaneAABBIsect test_frustum_aabb(const float bb_min[3],
if (dot_v3v3(planes[i], vmin) + planes[i][3] < 0) {
return ISECT_OUTSIDE;
}
- else if (dot_v3v3(planes[i], vmax) + planes[i][3] <= 0) {
+ if (dot_v3v3(planes[i], vmax) + planes[i][3] <= 0) {
ret = ISECT_INTERSECT;
}
}
@@ -2924,7 +2912,7 @@ PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node)
{
if (!node->color_buffer.color) {
- node->color_buffer.color = MEM_callocN(node->uniq_verts * sizeof(float) * 4, "Color buffer");
+ node->color_buffer.color = MEM_callocN(sizeof(float[4]) * node->uniq_verts, "Color buffer");
}
return &node->color_buffer;
}
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index e87c7c8d46d..a04fa1506d0 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -184,14 +184,13 @@ static BMVert *bm_vert_hash_lookup_chain(GHash *deleted_verts, BMVert *v)
/* not remapped*/
return v;
}
- else if (*v_next_p == NULL) {
+ if (*v_next_p == NULL) {
/* removed and not remapped */
return NULL;
}
- else {
- /* remapped */
- v = *v_next_p;
- }
+
+ /* remapped */
+ v = *v_next_p;
}
}
@@ -1738,9 +1737,8 @@ static void pbvh_bmesh_node_limit_ensure_fast(
candidate = i_iter;
break;
}
- else {
- num_child2++;
- }
+
+ num_child2++;
}
if (candidate != -1) {
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 4b09f7542c7..64e642462af 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -126,19 +126,19 @@ static CLG_LogRef LOG = {"bke.pointcache"};
static int ptcache_data_size[] = {
sizeof(unsigned int), // BPHYS_DATA_INDEX
- 3 * sizeof(float), // BPHYS_DATA_LOCATION
- 3 * sizeof(float), // BPHYS_DATA_VELOCITY
- 4 * sizeof(float), // BPHYS_DATA_ROTATION
- 3 * sizeof(float), // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST
+ sizeof(float[3]), // BPHYS_DATA_LOCATION
+ sizeof(float[3]), // BPHYS_DATA_VELOCITY
+ sizeof(float[4]), // BPHYS_DATA_ROTATION
+ sizeof(float[3]), // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST
sizeof(float), // BPHYS_DATA_SIZE
- 3 * sizeof(float), // BPHYS_DATA_TIMES
+ sizeof(float[3]), // BPHYS_DATA_TIMES
sizeof(BoidData), // case BPHYS_DATA_BOIDS
};
static int ptcache_extra_datasize[] = {
0,
sizeof(ParticleSpring),
- sizeof(float) * 3,
+ sizeof(float[3]),
};
/* forward declarations */
@@ -212,8 +212,8 @@ static void ptcache_softbody_read(
BodyPoint *bp = soft->bpoint + index;
if (old_data) {
- memcpy(bp->pos, data, 3 * sizeof(float));
- memcpy(bp->vec, data + 3, 3 * sizeof(float));
+ memcpy(bp->pos, data, sizeof(float[3]));
+ memcpy(bp->vec, data + 3, sizeof(float[3]));
}
else {
PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, bp->pos);
@@ -241,8 +241,8 @@ static void ptcache_softbody_interpolate(int index,
copy_v3_v3(keys[1].vel, bp->vec);
if (old_data) {
- memcpy(keys[2].co, old_data, 3 * sizeof(float));
- memcpy(keys[2].vel, old_data + 3, 3 * sizeof(float));
+ memcpy(keys[2].co, old_data, sizeof(float[3]));
+ memcpy(keys[2].vel, old_data + 3, sizeof(float[3]));
}
else {
BKE_ptcache_make_particle_key(keys + 2, 0, data, cfra2);
@@ -545,9 +545,9 @@ static void ptcache_cloth_read(
ClothVertex *vert = cloth->verts + index;
if (old_data) {
- memcpy(vert->x, data, 3 * sizeof(float));
- memcpy(vert->xconst, data + 3, 3 * sizeof(float));
- memcpy(vert->v, data + 6, 3 * sizeof(float));
+ memcpy(vert->x, data, sizeof(float[3]));
+ memcpy(vert->xconst, data + 3, sizeof(float[3]));
+ memcpy(vert->v, data + 6, sizeof(float[3]));
}
else {
PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, vert->x);
@@ -577,8 +577,8 @@ static void ptcache_cloth_interpolate(int index,
copy_v3_v3(keys[1].vel, vert->v);
if (old_data) {
- memcpy(keys[2].co, old_data, 3 * sizeof(float));
- memcpy(keys[2].vel, old_data + 6, 3 * sizeof(float));
+ memcpy(keys[2].co, old_data, sizeof(float[3]));
+ memcpy(keys[2].vel, old_data + 6, sizeof(float[3]));
}
else {
BKE_ptcache_make_particle_key(keys + 2, 0, data, cfra2);
@@ -1404,9 +1404,8 @@ static int ptcache_dynamicpaint_totpoint(void *sd, int UNUSED(cfra))
if (!surface->data) {
return 0;
}
- else {
- return surface->data->total_points;
- }
+
+ return surface->data->total_points;
}
static void ptcache_dynamicpaint_error(void *UNUSED(sd), const char *UNUSED(message))
@@ -1422,7 +1421,7 @@ static int ptcache_dynamicpaint_write(PTCacheFile *pf, void *dp_v)
int cache_compress = 1;
/* version header */
- ptcache_file_write(pf, DPAINT_CACHE_VERSION, 1, sizeof(char) * 4);
+ ptcache_file_write(pf, DPAINT_CACHE_VERSION, 1, sizeof(char[4]));
if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->data) {
int total_points = surface->data->total_points;
@@ -1460,7 +1459,7 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v)
char version[4];
/* version header */
- ptcache_file_read(pf, version, 1, sizeof(char) * 4);
+ ptcache_file_read(pf, version, 1, sizeof(char[4]));
if (!STREQLEN(version, DPAINT_CACHE_VERSION, 4)) {
CLOG_ERROR(&LOG, "Dynamic Paint: Invalid cache version: '%c%c%c%c'!", UNPACK4(version));
return 0;
@@ -1511,7 +1510,7 @@ static int ptcache_rigidbody_write(int index, void *rb_v, void **data, int UNUSE
if (ob && ob->rigidbody_object) {
RigidBodyOb *rbo = ob->rigidbody_object;
- if (rbo->type == RBO_TYPE_ACTIVE) {
+ if (rbo->type == RBO_TYPE_ACTIVE && rbo->shared->physics_object != NULL) {
#ifdef WITH_BULLET
RB_body_get_position(rbo->shared->physics_object, rbo->pos);
RB_body_get_orientation(rbo->shared->physics_object, rbo->orn);
@@ -1539,8 +1538,8 @@ static void ptcache_rigidbody_read(
if (rbo->type == RBO_TYPE_ACTIVE) {
if (old_data) {
- memcpy(rbo->pos, data, 3 * sizeof(float));
- memcpy(rbo->orn, data + 3, 4 * sizeof(float));
+ memcpy(rbo->pos, data, sizeof(float[3]));
+ memcpy(rbo->orn, data + 3, sizeof(float[4]));
}
else {
PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, rbo->pos);
@@ -1578,8 +1577,8 @@ static void ptcache_rigidbody_interpolate(int index,
copy_qt_qt(keys[1].rot, rbo->orn);
if (old_data) {
- memcpy(keys[2].co, data, 3 * sizeof(float));
- memcpy(keys[2].rot, data + 3, 4 * sizeof(float));
+ memcpy(keys[2].co, data, sizeof(float[3]));
+ memcpy(keys[2].rot, data + 3, sizeof(float[4]));
}
else {
BKE_ptcache_make_particle_key(&keys[2], 0, data, cfra2);
@@ -2128,7 +2127,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
return BLI_path_slash_ensure(filename); /* new strlen() */
}
- else if (G.relbase_valid || lib) {
+ if (G.relbase_valid || lib) {
char file[MAX_PTCACHE_PATH]; /* we don't want the dir, only the file */
BLI_split_file_part(blendfilename, file, sizeof(file));
@@ -2277,7 +2276,7 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result,
size_t out_len = len;
#endif
unsigned char *in;
- unsigned char *props = MEM_callocN(16 * sizeof(char), "tmp");
+ unsigned char *props = MEM_callocN(sizeof(char[16]), "tmp");
ptcache_file_read(pf, &compressed, 1, sizeof(unsigned char));
if (compressed) {
@@ -2323,7 +2322,7 @@ static int ptcache_file_compressed_write(
int r = 0;
unsigned char compressed = 0;
size_t out_len = 0;
- unsigned char *props = MEM_callocN(16 * sizeof(char), "tmp");
+ unsigned char *props = MEM_callocN(sizeof(char[16]), "tmp");
size_t sizeOfIt = 5;
(void)mode; /* unused when building w/o compression */
@@ -2521,9 +2520,8 @@ int BKE_ptcache_mem_index_find(PTCacheMem *pm, unsigned int index)
return -1;
}
- else {
- return (index < pm->totpoint ? index : -1);
- }
+
+ return (index < pm->totpoint ? index : -1);
}
void BKE_ptcache_mem_pointers_init(PTCacheMem *pm)
@@ -2625,13 +2623,13 @@ static void ptcache_mem_clear(PTCacheMem *pm)
static int ptcache_old_elemsize(PTCacheID *pid)
{
if (pid->type == PTCACHE_TYPE_SOFTBODY) {
- return 6 * sizeof(float);
+ return sizeof(float[6]);
}
- else if (pid->type == PTCACHE_TYPE_PARTICLES) {
+ if (pid->type == PTCACHE_TYPE_PARTICLES) {
return sizeof(ParticleKey);
}
- else if (pid->type == PTCACHE_TYPE_CLOTH) {
- return 9 * sizeof(float);
+ if (pid->type == PTCACHE_TYPE_CLOTH) {
+ return sizeof(float[9]);
}
return 0;
@@ -3585,16 +3583,15 @@ int BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
return BLI_exists(filename);
}
- else {
- PTCacheMem *pm = pid->cache->mem_cache.first;
- for (; pm; pm = pm->next) {
- if (pm->frame == cfra) {
- return 1;
- }
+ PTCacheMem *pm = pid->cache->mem_cache.first;
+
+ for (; pm; pm = pm->next) {
+ if (pm->frame == cfra) {
+ return 1;
}
- return 0;
}
+ return 0;
}
void BKE_ptcache_id_time(
PTCacheID *pid, Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c
index df5d93beccb..21889acba3c 100644
--- a/source/blender/blenkernel/intern/pointcloud.c
+++ b/source/blender/blenkernel/intern/pointcloud.c
@@ -169,8 +169,8 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
for (int a = 0; a < pointcloud->totpoint; a++) {
float *co = pointcloud_co[a];
float radius = (pointcloud_radius) ? pointcloud_radius[a] : 0.0f;
- float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
- float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
+ const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
DO_MIN(co_min, min);
DO_MAX(co_max, max);
}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 4752782eaeb..ece7d0f9136 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -466,10 +466,10 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
return shape;
}
-/* Create new physics sim collision shape for object and store it,
- * or remove the existing one first and replace...
+/* Helper function to create physics collision shape for object.
+ * Returns a new collision shape.
*/
-static void rigidbody_validate_sim_shape(Object *ob, bool rebuild)
+static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw, Object *ob)
{
RigidBodyOb *rbo = ob->rigidbody_object;
rbCollisionShape *new_shape = NULL;
@@ -484,12 +484,7 @@ static void rigidbody_validate_sim_shape(Object *ob, bool rebuild)
/* sanity check */
if (rbo == NULL) {
- return;
- }
-
- /* don't create a new shape if we already have one and don't want to rebuild it */
- if (rbo->shared->physics_shape && !rebuild) {
- return;
+ return NULL;
}
/* if automatically determining dimensions, use the Object's boundbox
@@ -539,7 +534,7 @@ static void rigidbody_validate_sim_shape(Object *ob, bool rebuild)
break;
case RB_SHAPE_CONVEXH:
- /* try to emged collision margin */
+ /* try to embed collision margin */
has_volume = (MIN3(size[0], size[1], size[2]) > 0.0f);
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && has_volume) {
@@ -555,18 +550,69 @@ static void rigidbody_validate_sim_shape(Object *ob, bool rebuild)
case RB_SHAPE_TRIMESH:
new_shape = rigidbody_get_shape_trimesh_from_mesh(ob);
break;
+ case RB_SHAPE_COMPOUND:
+ new_shape = RB_shape_new_compound();
+ rbCollisionShape *childShape = NULL;
+ float loc[3], rot[4];
+ float mat[4][4];
+ /* Add children to the compound shape */
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, childObject) {
+ if (childObject->parent == ob) {
+ childShape = rigidbody_validate_sim_shape_helper(rbw, childObject);
+ if (childShape) {
+ BKE_object_matrix_local_get(childObject, mat);
+ mat4_to_loc_quat(loc, rot, mat);
+ RB_compound_add_child_shape(new_shape, childShape, loc, rot);
+ }
+ }
+ }
+ FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+
+ break;
}
- /* use box shape if we can't fall back to old shape */
- if (new_shape == NULL && rbo->shared->physics_shape == NULL) {
+ /* use box shape if it failed to create new shape */
+ if (new_shape == NULL) {
new_shape = RB_shape_new_box(size[0], size[1], size[2]);
}
+ if (new_shape) {
+ RB_shape_set_margin(new_shape, RBO_GET_MARGIN(rbo));
+ }
+
+ return new_shape;
+}
+
+/* Create new physics sim collision shape for object and store it,
+ * or remove the existing one first and replace...
+ */
+static void rigidbody_validate_sim_shape(RigidBodyWorld *rbw, Object *ob, bool rebuild)
+{
+ RigidBodyOb *rbo = ob->rigidbody_object;
+ rbCollisionShape *new_shape = NULL;
+
+ /* sanity check */
+ if (rbo == NULL) {
+ return;
+ }
+
+ /* don't create a new shape if we already have one and don't want to rebuild it */
+ if (rbo->shared->physics_shape && !rebuild) {
+ return;
+ }
+
+ /* Also don't create a shape if this object is parent of a compound shape */
+ if (ob->parent != NULL && ob->parent->rigidbody_object != NULL &&
+ ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND) {
+ return;
+ }
+
+ new_shape = rigidbody_validate_sim_shape_helper(rbw, ob);
+
/* assign new collision shape if creation was successful */
if (new_shape) {
if (rbo->shared->physics_shape) {
RB_shape_delete(rbo->shared->physics_shape);
}
rbo->shared->physics_shape = new_shape;
- RB_shape_set_margin(rbo->shared->physics_shape, RBO_GET_MARGIN(rbo));
}
}
@@ -750,7 +796,7 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
/* FIXME we shouldn't always have to rebuild collision shapes when rebuilding objects,
* but it's needed for constraints to update correctly. */
if (rbo->shared->physics_shape == NULL || rebuild) {
- rigidbody_validate_sim_shape(ob, true);
+ rigidbody_validate_sim_shape(rbw, ob, true);
}
if (rbo->shared->physics_object) {
@@ -760,6 +806,12 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
/* remove rigid body if it already exists before creating a new one */
if (rbo->shared->physics_object) {
RB_body_delete(rbo->shared->physics_object);
+ rbo->shared->physics_object = NULL;
+ }
+ /* Don't create rigid body object if the parent is a compound shape */
+ if (ob->parent != NULL && ob->parent->rigidbody_object != NULL &&
+ ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND) {
+ return;
}
mat4_to_loc_quat(loc, rot, ob->obmat);
@@ -793,7 +845,7 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
}
- if (rbw && rbw->shared->physics_world) {
+ if (rbw && rbw->shared->physics_world && rbo->shared->physics_object) {
RB_dworld_add_body(rbw->shared->physics_world, rbo->shared->physics_object, rbo->col_groups);
}
}
@@ -1179,9 +1231,12 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
* - object must exist
* - cannot add rigid body if it already exists
*/
- if (ob == NULL || (ob->rigidbody_object != NULL)) {
+ if (ob == NULL) {
return NULL;
}
+ if (ob->rigidbody_object != NULL) {
+ return ob->rigidbody_object;
+ }
/* create new settings data, and link it up */
rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb");
@@ -1530,7 +1585,11 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
int n = 0;
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, object) {
(void)object;
- n++;
+ /* Ignore if this object is the direct child of an object with a compound shape */
+ if (object->parent == NULL || object->parent->rigidbody_object == NULL ||
+ object->parent->rigidbody_object->shape != RB_SHAPE_COMPOUND) {
+ n++;
+ }
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
@@ -1541,8 +1600,12 @@ static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
int i = 0;
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, object) {
- rbw->objects[i] = object;
- i++;
+ /* Ignore if this object is the direct child of an object with a compound shape */
+ if (object->parent == NULL || object->parent->rigidbody_object == NULL ||
+ object->parent->rigidbody_object->shape != RB_SHAPE_COMPOUND) {
+ rbw->objects[i] = object;
+ i++;
+ }
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
}
@@ -1754,11 +1817,13 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph,
/* refresh shape... */
if (rbo->flag & RBO_FLAG_NEEDS_RESHAPE) {
/* mesh/shape data changed, so force shape refresh */
- rigidbody_validate_sim_shape(ob, true);
+ rigidbody_validate_sim_shape(rbw, ob, true);
/* now tell RB sim about it */
/* XXX: we assume that this can only get applied for active/passive shapes
* that will be included as rigidbodies. */
- RB_body_set_collision_shape(rbo->shared->physics_object, rbo->shared->physics_shape);
+ if (rbo->shared->physics_object != NULL && rbo->shared->physics_shape != NULL) {
+ RB_body_set_collision_shape(rbo->shared->physics_object, rbo->shared->physics_shape);
+ }
}
}
rbo->flag &= ~(RBO_FLAG_NEEDS_VALIDATE | RBO_FLAG_NEEDS_RESHAPE);
@@ -1817,7 +1882,8 @@ static void rigidbody_update_simulation_post_step(Depsgraph *depsgraph, RigidBod
Base *base = BKE_view_layer_base_find(view_layer, ob);
RigidBodyOb *rbo = ob->rigidbody_object;
/* Reset kinematic state for transformed objects. */
- if (rbo && base && (base->flag & BASE_SELECTED) && (G.moving & G_TRANSFORM_OBJ)) {
+ if (rbo && base && (base->flag & BASE_SELECTED) && (G.moving & G_TRANSFORM_OBJ) &&
+ rbo->shared->physics_object) {
RB_body_set_kinematic_state(rbo->shared->physics_object,
rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
RB_body_set_mass(rbo->shared->physics_object, RBO_GET_MASS(rbo));
@@ -1840,8 +1906,13 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
{
RigidBodyOb *rbo = ob->rigidbody_object;
+ /* True if the shape of this object's parent is of type compound */
+ bool obCompoundParent = (ob->parent != NULL && ob->parent->rigidbody_object != NULL &&
+ ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND);
+
/* keep original transform for kinematic and passive objects */
- if (ELEM(NULL, rbw, rbo) || rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE) {
+ if (ELEM(NULL, rbw, rbo) || rbo->flag & RBO_FLAG_KINEMATIC || rbo->type == RBO_TYPE_PASSIVE ||
+ obCompoundParent) {
return;
}
@@ -1963,7 +2034,11 @@ void BKE_rigidbody_rebuild_world(Depsgraph *depsgraph, Scene *scene, float ctime
int n = 0;
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, object) {
(void)object;
- n++;
+ /* Ignore if this object is the direct child of an object with a compound shape */
+ if (object->parent == NULL || object->parent->rigidbody_object == NULL ||
+ object->parent->rigidbody_object->shape != RB_SHAPE_COMPOUND) {
+ n++;
+ }
}
FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
@@ -2000,7 +2075,7 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
return;
}
/* make sure we don't go out of cache frame range */
- else if (ctime > endframe) {
+ if (ctime > endframe) {
ctime = endframe;
}
@@ -2008,7 +2083,7 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
if (rbw->shared->physics_world == NULL && !(cache->flag & PTCACHE_BAKED)) {
return;
}
- else if (rbw->objects == NULL) {
+ if (rbw->objects == NULL) {
rigidbody_update_ob_array(rbw);
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 5ae2f4b9005..7e25e8c96ae 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -127,7 +127,7 @@ static void scene_init_data(ID *id)
mblur_shutter_curve = &scene->r.mblur_shutter_curve;
BKE_curvemapping_set_defaults(mblur_shutter_curve, 1, 0.0f, 0.0f, 1.0f, 1.0f);
- BKE_curvemapping_initialize(mblur_shutter_curve);
+ BKE_curvemapping_init(mblur_shutter_curve);
BKE_curvemap_reset(mblur_shutter_curve->cm,
&mblur_shutter_curve->clipr,
CURVE_PRESET_MAX,
@@ -140,13 +140,13 @@ static void scene_init_data(ID *id)
/* grease pencil multiframe falloff curve */
scene->toolsettings->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
CurveMapping *gp_falloff_curve = scene->toolsettings->gp_sculpt.cur_falloff;
- BKE_curvemapping_initialize(gp_falloff_curve);
+ BKE_curvemapping_init(gp_falloff_curve);
BKE_curvemap_reset(
gp_falloff_curve->cm, &gp_falloff_curve->clipr, CURVE_PRESET_GAUSS, CURVEMAP_SLOPE_POSITIVE);
scene->toolsettings->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
CurveMapping *gp_primitive_curve = scene->toolsettings->gp_sculpt.cur_primitive;
- BKE_curvemapping_initialize(gp_primitive_curve);
+ BKE_curvemapping_init(gp_primitive_curve);
BKE_curvemap_reset(gp_primitive_curve->cm,
&gp_primitive_curve->clipr,
CURVE_PRESET_BELL,
@@ -839,83 +839,78 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type)
return sce_copy;
}
- else {
- eDupli_ID_Flags duplicate_flags = U.dupflag | USER_DUP_OBJECT;
- BKE_id_copy(bmain, (ID *)sce, (ID **)&sce_copy);
- id_us_min(&sce_copy->id);
- id_us_ensure_real(&sce_copy->id);
+ eDupli_ID_Flags duplicate_flags = U.dupflag | USER_DUP_OBJECT;
- BKE_animdata_duplicate_id_action(bmain, &sce_copy->id, duplicate_flags);
+ BKE_id_copy(bmain, (ID *)sce, (ID **)&sce_copy);
+ id_us_min(&sce_copy->id);
+ id_us_ensure_real(&sce_copy->id);
- /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks. */
+ BKE_animdata_duplicate_id_action(bmain, &sce_copy->id, duplicate_flags);
- if (type == SCE_COPY_FULL) {
- /* Scene duplication is always root of duplication currently. */
- const bool is_subprocess = false;
+ /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks. */
- if (!is_subprocess) {
- BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
- BKE_main_id_clear_newpoins(bmain);
- /* In case root duplicated ID is linked, assume we want to get a local copy of it and
- * duplicate all expected linked data. */
- if (ID_IS_LINKED(sce)) {
- duplicate_flags |= USER_DUP_LINKED_ID;
- }
+ if (type == SCE_COPY_FULL) {
+ /* Scene duplication is always root of duplication currently. */
+ const bool is_subprocess = false;
+
+ if (!is_subprocess) {
+ BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
+ BKE_main_id_clear_newpoins(bmain);
+ /* In case root duplicated ID is linked, assume we want to get a local copy of it and
+ * duplicate all expected linked data. */
+ if (ID_IS_LINKED(sce)) {
+ duplicate_flags |= USER_DUP_LINKED_ID;
}
+ }
- /* Copy Freestyle LineStyle datablocks. */
- LISTBASE_FOREACH (ViewLayer *, view_layer_dst, &sce_copy->view_layers) {
- LISTBASE_FOREACH (
- FreestyleLineSet *, lineset, &view_layer_dst->freestyle_config.linesets) {
- BKE_id_copy_for_duplicate(bmain, (ID *)lineset->linestyle, duplicate_flags);
- }
+ /* Copy Freestyle LineStyle datablocks. */
+ LISTBASE_FOREACH (ViewLayer *, view_layer_dst, &sce_copy->view_layers) {
+ LISTBASE_FOREACH (FreestyleLineSet *, lineset, &view_layer_dst->freestyle_config.linesets) {
+ BKE_id_copy_for_duplicate(bmain, (ID *)lineset->linestyle, duplicate_flags);
}
+ }
- /* Full copy of world (included animations) */
- BKE_id_copy_for_duplicate(bmain, (ID *)sce->world, duplicate_flags);
+ /* Full copy of world (included animations) */
+ BKE_id_copy_for_duplicate(bmain, (ID *)sce->world, duplicate_flags);
- /* Full copy of GreasePencil. */
- BKE_id_copy_for_duplicate(bmain, (ID *)sce->gpd, duplicate_flags);
+ /* Full copy of GreasePencil. */
+ BKE_id_copy_for_duplicate(bmain, (ID *)sce->gpd, duplicate_flags);
- /* Deep-duplicate collections and objects (using preferences' settings for which sub-data to
- * duplicate along the object itself). */
- BKE_collection_duplicate(bmain,
- NULL,
- sce_copy->master_collection,
- duplicate_flags,
- LIB_ID_DUPLICATE_IS_SUBPROCESS);
+ /* Deep-duplicate collections and objects (using preferences' settings for which sub-data to
+ * duplicate along the object itself). */
+ BKE_collection_duplicate(
+ bmain, NULL, sce_copy->master_collection, duplicate_flags, LIB_ID_DUPLICATE_IS_SUBPROCESS);
- if (!is_subprocess) {
- /* This code will follow into all ID links using an ID tagged with LIB_TAG_NEW.*/
- BKE_libblock_relink_to_newid(&sce_copy->id);
+ if (!is_subprocess) {
+ /* This code will follow into all ID links using an ID tagged with LIB_TAG_NEW.*/
+ BKE_libblock_relink_to_newid(&sce_copy->id);
#ifndef NDEBUG
- /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those
- * flags. */
- ID *id_iter;
- FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
- BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
- }
- FOREACH_MAIN_ID_END;
+ /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those
+ * flags. */
+ ID *id_iter;
+ FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
+ BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
+ }
+ FOREACH_MAIN_ID_END;
#endif
- /* Cleanup. */
- BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
- BKE_main_id_clear_newpoins(bmain);
+ /* Cleanup. */
+ BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
+ BKE_main_id_clear_newpoins(bmain);
- BKE_main_collection_sync(bmain);
- }
+ BKE_main_collection_sync(bmain);
}
- else {
- /* Remove sequencer if not full copy */
- /* XXX Why in Hell? :/ */
- remove_sequencer_fcurves(sce_copy);
- BKE_sequencer_editing_free(sce_copy, true);
- }
-
- return sce_copy;
}
+ else {
+ /* Remove sequencer if not full copy */
+ /* XXX Why in Hell? :/ */
+ remove_sequencer_fcurves(sce_copy);
+ BKE_sequencer_editing_free(sce_copy, true);
+ }
+
+ return sce_copy;
}
void BKE_scene_groups_relink(Scene *sce)
@@ -1007,7 +1002,7 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name)
return NULL;
}
-/* Used by metaballs, return *all* objects (including duplis)
+/* Used by meta-balls, return *all* objects (including duplis)
* existing in the scene (including scene's sets). */
int BKE_scene_base_iter_next(
Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob)
@@ -1078,7 +1073,7 @@ int BKE_scene_base_iter_next(
else {
if (iter->phase != F_DUPLI) {
if (depsgraph && (*base)->object->transflag & OB_DUPLI) {
- /* collections cannot be duplicated for metaballs yet,
+ /* Collections cannot be duplicated for meta-balls yet,
* this enters eternal loop because of
* makeDispListMBall getting called inside of collection_duplilist */
if ((*base)->object->instance_collection == NULL) {
@@ -1642,7 +1637,7 @@ bool BKE_scene_remove_render_view(Scene *scene, SceneRenderView *srv)
if (act == -1) {
return false;
}
- else if (scene->r.views.first == scene->r.views.last) {
+ if (scene->r.views.first == scene->r.views.last) {
/* ensure 1 view is kept */
return false;
}
@@ -1663,13 +1658,11 @@ int get_render_subsurf_level(const RenderData *r, int lvl, bool for_render)
if (for_render) {
return min_ii(r->simplify_subsurf_render, lvl);
}
- else {
- return min_ii(r->simplify_subsurf, lvl);
- }
- }
- else {
- return lvl;
+
+ return min_ii(r->simplify_subsurf, lvl);
}
+
+ return lvl;
}
int get_render_child_particle_number(const RenderData *r, int num, bool for_render)
@@ -1678,13 +1671,11 @@ int get_render_child_particle_number(const RenderData *r, int num, bool for_rend
if (for_render) {
return (int)(r->simplify_particles_render * num);
}
- else {
- return (int)(r->simplify_particles * num);
- }
- }
- else {
- return num;
+
+ return (int)(r->simplify_particles * num);
}
+
+ return num;
}
/**
@@ -1699,7 +1690,7 @@ Base *_setlooper_base_step(Scene **sce_iter, ViewLayer *view_layer, Base *base)
/* Common case, step to the next. */
return base->next;
}
- else if ((base == NULL) && (view_layer != NULL)) {
+ if ((base == NULL) && (view_layer != NULL)) {
/* First time looping, return the scenes first base. */
/* For the first loop we should get the layer from workspace when available. */
if (view_layer->object_bases.first) {
@@ -2018,9 +2009,8 @@ const char *BKE_scene_multiview_render_view_name_get(const RenderData *rd, const
if (srv) {
return srv->name;
}
- else {
- return "";
- }
+
+ return "";
}
int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
@@ -2041,9 +2031,8 @@ int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
if (STREQ(viewname, srv->name)) {
return nr;
}
- else {
- nr += 1;
- }
+
+ nr += 1;
}
}
@@ -2094,9 +2083,8 @@ const char *BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char
if (srv) {
return srv->suffix;
}
- else {
- return viewname;
- }
+
+ return viewname;
}
const char *BKE_scene_multiview_view_id_suffix_get(const RenderData *rd, const int view_id)
@@ -2104,10 +2092,9 @@ const char *BKE_scene_multiview_view_id_suffix_get(const RenderData *rd, const i
if ((rd->scemode & R_MULTIVIEW) == 0) {
return "";
}
- else {
- const char *viewname = BKE_scene_multiview_render_view_name_get(rd, view_id);
- return BKE_scene_multiview_view_suffix_get(rd, viewname);
- }
+
+ const char *viewname = BKE_scene_multiview_render_view_name_get(rd, view_id);
+ return BKE_scene_multiview_view_suffix_get(rd, viewname);
}
void BKE_scene_multiview_view_prefix_get(Scene *scene,
@@ -2175,10 +2162,9 @@ int BKE_scene_multiview_num_videos_get(const RenderData *rd)
if (rd->im_format.views_format == R_IMF_VIEWS_STEREO_3D) {
return 1;
}
- else {
- /* R_IMF_VIEWS_INDIVIDUAL */
- return BKE_scene_multiview_num_views_get(rd);
- }
+
+ /* R_IMF_VIEWS_INDIVIDUAL */
+ return BKE_scene_multiview_num_views_get(rd);
}
/* Manipulation of depsgraph storage. */
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index c510b3a2dfb..3a49c180172 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -159,15 +159,15 @@ void BKE_screen_foreach_id_screen_area(LibraryForeachIDData *data, ScrArea *area
break;
}
case SPACE_OUTLINER: {
- SpaceOutliner *so = (SpaceOutliner *)sl;
+ SpaceOutliner *space_outliner = (SpaceOutliner *)sl;
- BKE_LIB_FOREACHID_PROCESS_ID(data, so->search_tse.id, IDWALK_CB_NOP);
+ BKE_LIB_FOREACHID_PROCESS_ID(data, space_outliner->search_tse.id, IDWALK_CB_NOP);
- if (so->treestore != NULL) {
+ if (space_outliner->treestore != NULL) {
TreeStoreElem *tselem;
BLI_mempool_iter iter;
- BLI_mempool_iternew(so->treestore, &iter);
+ BLI_mempool_iternew(space_outliner->treestore, &iter);
while ((tselem = BLI_mempool_iterstep(&iter))) {
BKE_LIB_FOREACHID_PROCESS_ID(data, tselem->id, IDWALK_CB_NOP);
}
diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c
index fa4951da161..7d2858050be 100644
--- a/source/blender/blenkernel/intern/seqcache.c
+++ b/source/blender/blenkernel/intern/seqcache.c
@@ -444,7 +444,7 @@ static void seq_disk_cache_delete_invalid_files(SeqDiskCache *disk_cache,
while (cache_file) {
next_file = cache_file->next;
if (cache_file->cache_type & invalidate_types) {
- if (strcmp(cache_dir, cache_file->dir) == 0) {
+ if (STREQ(cache_dir, cache_file->dir)) {
int cfra_start = seq_cache_frame_index_to_cfra(seq, cache_file->start_frame);
if (cfra_start > range_start && cfra_start <= range_end) {
seq_disk_cache_delete_file(disk_cache, cache_file);
@@ -483,10 +483,9 @@ static size_t deflate_imbuf_to_file(ImBuf *ibuf,
return BLI_gzip_mem_to_file_at_pos(
ibuf->rect, header_entry->size_raw, file, header_entry->offset, level);
}
- else {
- return BLI_gzip_mem_to_file_at_pos(
- ibuf->rect_float, header_entry->size_raw, file, header_entry->offset, level);
- }
+
+ return BLI_gzip_mem_to_file_at_pos(
+ ibuf->rect_float, header_entry->size_raw, file, header_entry->offset, level);
}
static size_t inflate_file_to_imbuf(ImBuf *ibuf, FILE *file, DiskCacheHeaderEntry *header_entry)
@@ -495,10 +494,9 @@ static size_t inflate_file_to_imbuf(ImBuf *ibuf, FILE *file, DiskCacheHeaderEntr
return BLI_ungzip_file_to_mem_at_pos(
ibuf->rect, header_entry->size_raw, file, header_entry->offset);
}
- else {
- return BLI_ungzip_file_to_mem_at_pos(
- ibuf->rect_float, header_entry->size_raw, file, header_entry->offset);
- }
+
+ return BLI_ungzip_file_to_mem_at_pos(
+ ibuf->rect_float, header_entry->size_raw, file, header_entry->offset);
}
static void seq_disk_cache_read_header(FILE *file, DiskCacheHeader *header)
@@ -1304,11 +1302,10 @@ bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context,
BKE_sequencer_cache_put(context, seq, cfra, type, ibuf, cost, skip_disk_cache);
return true;
}
- else {
- seq_cache_set_temp_cache_linked(scene, scene->ed->cache->last_key);
- scene->ed->cache->last_key = NULL;
- return false;
- }
+
+ seq_cache_set_temp_cache_linked(scene, scene->ed->cache->last_key);
+ scene->ed->cache->last_key = NULL;
+ return false;
}
void BKE_sequencer_cache_put(const SeqRenderData *context,
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 4a2ad88bb28..afec9b835a5 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -303,10 +303,10 @@ static void do_alphaover_effect_float(
mfac = 1.0f - (fac2 * rt1[3]);
if (fac <= 0.0f) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else if (mfac <= 0) {
- memcpy(rt, rt1, 4 * sizeof(float));
+ memcpy(rt, rt1, sizeof(float[4]));
}
else {
rt[0] = fac * rt1[0] + mfac * rt2[0];
@@ -330,10 +330,10 @@ static void do_alphaover_effect_float(
mfac = 1.0f - (fac4 * rt1[3]);
if (fac <= 0.0f) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else if (mfac <= 0.0f) {
- memcpy(rt, rt1, 4 * sizeof(float));
+ memcpy(rt, rt1, sizeof(float[4]));
}
else {
rt[0] = fac * rt1[0] + mfac * rt2[0];
@@ -499,16 +499,16 @@ static void do_alphaunder_effect_float(
* 'skybuf' can be crossed in
*/
if (rt2[3] <= 0 && fac2 >= 1.0f) {
- memcpy(rt, rt1, 4 * sizeof(float));
+ memcpy(rt, rt1, sizeof(float[4]));
}
else if (rt2[3] >= 1.0f) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else {
fac = fac2 * (1.0f - rt2[3]);
if (fac == 0) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else {
rt[0] = fac * rt1[0] + rt2[0];
@@ -530,16 +530,16 @@ static void do_alphaunder_effect_float(
x = xo;
while (x--) {
if (rt2[3] <= 0 && fac4 >= 1.0f) {
- memcpy(rt, rt1, 4 * sizeof(float));
+ memcpy(rt, rt1, sizeof(float[4]));
}
else if (rt2[3] >= 1.0f) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else {
fac = fac4 * (1.0f - rt2[3]);
if (fac == 0) {
- memcpy(rt, rt2, 4 * sizeof(float));
+ memcpy(rt, rt2, sizeof(float[4]));
}
else {
rt[0] = fac * rt1[0] + rt2[0];
@@ -2522,7 +2522,7 @@ static void RVBlurBitmap2_float(float *map, int width, int height, float blur, i
}
/* Allocate memory for the tempmap and the blur filter matrix */
- temp = MEM_mallocN((width * height * 4 * sizeof(float)), "blurbitmaptemp");
+ temp = MEM_mallocN(sizeof(float[4]) * width * height, "blurbitmaptemp");
if (!temp) {
return;
}
@@ -2746,8 +2746,8 @@ static void do_glow_effect_byte(Sequence *seq,
float *outbuf, *inbuf;
GlowVars *glow = (GlowVars *)seq->effectdata;
- inbuf = MEM_mallocN(4 * sizeof(float) * x * y, "glow effect input");
- outbuf = MEM_mallocN(4 * sizeof(float) * x * y, "glow effect output");
+ inbuf = MEM_mallocN(sizeof(float[4]) * x * y, "glow effect input");
+ outbuf = MEM_mallocN(sizeof(float[4]) * x * y, "glow effect output");
IMB_buffer_float_from_byte(inbuf, rect1, IB_PROFILE_SRGB, IB_PROFILE_SRGB, false, x, y, x, x);
IMB_buffer_float_premultiply(inbuf, x, y);
@@ -3269,9 +3269,8 @@ float BKE_sequencer_speed_effect_target_frame_get(const SeqRenderData *context,
if (input == 0) { /* Current frame. */
return floor(seq->start + s->frameMap[nr]);
}
- else { /* Next frame. */
- return ceil(seq->start + s->frameMap[nr]);
- }
+ /* Next frame. */
+ return ceil(seq->start + s->frameMap[nr]);
}
static float speed_effect_interpolation_ratio_get(SpeedControlVars *s, Sequence *seq, float cfra)
@@ -4024,7 +4023,7 @@ static int early_out_fade(Sequence *UNUSED(seq), float facf0, float facf1)
if (facf0 == 0.0f && facf1 == 0.0f) {
return EARLY_USE_INPUT_1;
}
- else if (facf0 == 1.0f && facf1 == 1.0f) {
+ if (facf0 == 1.0f && facf1 == 1.0f) {
return EARLY_USE_INPUT_2;
}
return EARLY_DO_EFFECT;
diff --git a/source/blender/blenkernel/intern/seqmodifier.c b/source/blender/blenkernel/intern/seqmodifier.c
index a630170d6d5..a38fe252731 100644
--- a/source/blender/blenkernel/intern/seqmodifier.c
+++ b/source/blender/blenkernel/intern/seqmodifier.c
@@ -393,10 +393,10 @@ static void curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *m
{
CurvesModifierData *cmd = (CurvesModifierData *)smd;
- float black[3] = {0.0f, 0.0f, 0.0f};
- float white[3] = {1.0f, 1.0f, 1.0f};
+ const float black[3] = {0.0f, 0.0f, 0.0f};
+ const float white[3] = {1.0f, 1.0f, 1.0f};
- BKE_curvemapping_initialize(&cmd->curve_mapping);
+ BKE_curvemapping_init(&cmd->curve_mapping);
BKE_curvemapping_premultiply(&cmd->curve_mapping, 0);
BKE_curvemapping_set_black_white(&cmd->curve_mapping, black, white);
@@ -525,7 +525,7 @@ static void hue_correct_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImB
{
HueCorrectModifierData *hcmd = (HueCorrectModifierData *)smd;
- BKE_curvemapping_initialize(&hcmd->curve_mapping);
+ BKE_curvemapping_init(&hcmd->curve_mapping);
modifier_apply_threaded(ibuf, mask, hue_correct_apply_threaded, &hcmd->curve_mapping);
}
diff --git a/source/blender/blenkernel/intern/seqprefetch.c b/source/blender/blenkernel/intern/seqprefetch.c
index ff3829bdebb..795086fffa4 100644
--- a/source/blender/blenkernel/intern/seqprefetch.c
+++ b/source/blender/blenkernel/intern/seqprefetch.c
@@ -138,7 +138,7 @@ static bool seq_prefetch_job_is_waiting(Scene *scene)
static Sequence *sequencer_prefetch_get_original_sequence(Sequence *seq, ListBase *seqbase)
{
LISTBASE_FOREACH (Sequence *, seq_orig, seqbase) {
- if (strcmp(seq->name, seq_orig->name) == 0) {
+ if (STREQ(seq->name, seq_orig->name)) {
return seq_orig;
}
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index d147ad9ee87..a2a45ae56b3 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -1356,9 +1356,8 @@ const char *BKE_sequence_give_name(Sequence *seq)
if (!(seq->type & SEQ_TYPE_EFFECT)) {
return seq->strip->dir;
}
- else {
- return "Effect";
- }
+
+ return "Effect";
}
return name;
}
@@ -1662,13 +1661,12 @@ static int seq_num_files(Scene *scene, char views_format, const bool is_multivie
if (!is_multiview) {
return 1;
}
- else if (views_format == R_IMF_VIEWS_STEREO_3D) {
+ if (views_format == R_IMF_VIEWS_STEREO_3D) {
return 1;
}
/* R_IMF_VIEWS_INDIVIDUAL */
- else {
- return BKE_scene_multiview_num_views_get(&scene->r);
- }
+
+ return BKE_scene_multiview_num_views_get(&scene->r);
}
static void seq_proxy_index_dir_set(struct anim *anim, const char *base_dir)
@@ -1959,9 +1957,8 @@ static ImBuf *seq_proxy_fetch(const SeqRenderData *context, Sequence *seq, int c
return ibuf;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
static void seq_proxy_build_frame(const SeqRenderData *context,
@@ -2056,9 +2053,8 @@ static bool seq_proxy_multiview_context_invalid(Sequence *seq, Scene *scene, con
if (BLI_access(str, R_OK) == 0) {
return false;
}
- else {
- return view_id != 0;
- }
+
+ return view_id != 0;
}
return false;
}
@@ -2426,7 +2422,7 @@ static void color_balance_byte_float(StripColorBalance *cb_,
while (p < e) {
if (m) {
- float t[3] = {m[0] / 255.0f, m[1] / 255.0f, m[2] / 255.0f};
+ const float t[3] = {m[0] / 255.0f, m[1] / 255.0f, m[2] / 255.0f};
p[0] = p[0] * (1.0f - t[0]) + t[0] * cb_tab[0][p[0]];
p[1] = p[1] * (1.0f - t[1]) + t[1] * cb_tab[1][p[1]];
@@ -3381,35 +3377,34 @@ static ImBuf *seq_render_mask(const SeqRenderData *context, Mask *mask, float nr
if (!mask) {
return NULL;
}
- else {
- AnimData *adt;
- Mask *mask_temp;
- MaskRasterHandle *mr_handle;
- mask_temp = BKE_mask_copy_nolib(mask);
+ AnimData *adt;
+ Mask *mask_temp;
+ MaskRasterHandle *mr_handle;
- BKE_mask_evaluate(mask_temp, mask->sfra + nr, true);
+ mask_temp = BKE_mask_copy_nolib(mask);
- /* anim-data */
- adt = BKE_animdata_from_id(&mask->id);
- const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
- context->depsgraph, mask->sfra + nr);
- BKE_animsys_evaluate_animdata(&mask_temp->id, adt, &anim_eval_context, ADT_RECALC_ANIM, false);
+ BKE_mask_evaluate(mask_temp, mask->sfra + nr, true);
- maskbuf = MEM_mallocN(sizeof(float) * context->rectx * context->recty, __func__);
+ /* anim-data */
+ adt = BKE_animdata_from_id(&mask->id);
+ const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
+ context->depsgraph, mask->sfra + nr);
+ BKE_animsys_evaluate_animdata(&mask_temp->id, adt, &anim_eval_context, ADT_RECALC_ANIM, false);
- mr_handle = BKE_maskrasterize_handle_new();
+ maskbuf = MEM_mallocN(sizeof(float) * context->rectx * context->recty, __func__);
- BKE_maskrasterize_handle_init(
- mr_handle, mask_temp, context->rectx, context->recty, true, true, true);
+ mr_handle = BKE_maskrasterize_handle_new();
- BKE_mask_free(mask_temp);
- MEM_freeN(mask_temp);
+ BKE_maskrasterize_handle_init(
+ mr_handle, mask_temp, context->rectx, context->recty, true, true, true);
- BKE_maskrasterize_buffer(mr_handle, context->rectx, context->recty, maskbuf);
+ BKE_mask_free(mask_temp);
+ MEM_freeN(mask_temp);
- BKE_maskrasterize_handle_free(mr_handle);
- }
+ BKE_maskrasterize_buffer(mr_handle, context->rectx, context->recty, maskbuf);
+
+ BKE_maskrasterize_handle_free(mr_handle);
if (make_float) {
/* pixels */
@@ -3657,7 +3652,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context,
ibufs_arr[view_id] = IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rectfloat);
memcpy(ibufs_arr[view_id]->rect_float,
rres.rectf,
- 4 * sizeof(float) * rres.rectx * rres.recty);
+ sizeof(float[4]) * rres.rectx * rres.recty);
if (rres.rectz) {
addzbuffloatImBuf(ibufs_arr[view_id]);
@@ -3853,9 +3848,8 @@ static float seq_estimate_render_cost_end(Scene *scene, clock_t begin)
if (time_max != 0) {
return time_spent / time_max;
}
- else {
- return 1;
- }
+
+ return 1;
}
static ImBuf *seq_render_preprocess_ibuf(const SeqRenderData *context,
@@ -3956,7 +3950,7 @@ static int seq_get_early_out_for_blend_mode(Sequence *seq)
if (early_out == EARLY_USE_INPUT_2) {
return EARLY_USE_INPUT_1;
}
- else if (early_out == EARLY_USE_INPUT_1) {
+ if (early_out == EARLY_USE_INPUT_1) {
return EARLY_USE_INPUT_2;
}
}
@@ -4459,9 +4453,8 @@ int BKE_sequence_tx_get_final_left(Sequence *seq, bool metaclip)
return max_ii(BKE_sequence_tx_get_final_left(seq, false),
BKE_sequence_tx_get_final_left((Sequence *)seq->tmp, true));
}
- else {
- return (seq->start - seq->startstill) + seq->startofs;
- }
+
+ return (seq->start - seq->startstill) + seq->startofs;
}
int BKE_sequence_tx_get_final_right(Sequence *seq, bool metaclip)
{
@@ -4470,9 +4463,8 @@ int BKE_sequence_tx_get_final_right(Sequence *seq, bool metaclip)
return min_ii(BKE_sequence_tx_get_final_right(seq, false),
BKE_sequence_tx_get_final_right((Sequence *)seq->tmp, true));
}
- else {
- return ((seq->start + seq->len) + seq->endstill) - seq->endofs;
- }
+
+ return ((seq->start + seq->len) + seq->endstill) - seq->endofs;
}
void BKE_sequence_tx_set_final_left(Sequence *seq, int val)
@@ -4764,9 +4756,8 @@ bool BKE_sequence_base_shuffle_ex(ListBase *seqbasep,
BKE_sequence_calc(evil_scene, test);
return false;
}
- else {
- return true;
- }
+
+ return true;
}
bool BKE_sequence_base_shuffle(ListBase *seqbasep, Sequence *test, Scene *evil_scene)
@@ -5011,7 +5002,7 @@ ListBase *BKE_sequence_seqbase(ListBase *seqbase, Sequence *seq)
if (seq == iseq) {
return seqbase;
}
- else if (iseq->seqbase.first && (lb = BKE_sequence_seqbase(&iseq->seqbase, seq))) {
+ if (iseq->seqbase.first && (lb = BKE_sequence_seqbase(&iseq->seqbase, seq))) {
return lb;
}
}
@@ -5029,7 +5020,7 @@ Sequence *BKE_sequence_metastrip(ListBase *seqbase, Sequence *meta, Sequence *se
if (seq == iseq) {
return meta;
}
- else if (iseq->seqbase.first && (rval = BKE_sequence_metastrip(&iseq->seqbase, iseq, seq))) {
+ if (iseq->seqbase.first && (rval = BKE_sequence_metastrip(&iseq->seqbase, iseq, seq))) {
return rval;
}
}
@@ -5214,8 +5205,8 @@ Sequence *BKE_sequence_get_by_name(ListBase *seqbase, const char *name, bool rec
if (STREQ(name, iseq->name + 2)) {
return iseq;
}
- else if (recursive && (iseq->seqbase.first) &&
- (rseq = BKE_sequence_get_by_name(&iseq->seqbase, name, 1))) {
+ if (recursive && (iseq->seqbase.first) &&
+ (rseq = BKE_sequence_get_by_name(&iseq->seqbase, name, 1))) {
return rseq;
}
}
@@ -5237,7 +5228,7 @@ Sequence *BKE_sequencer_from_elem(ListBase *seqbase, StripElem *se)
(ARRAY_HAS_ITEM(se, iseq->strip->stripdata, iseq->len))) {
break;
}
- else if ((seq_found = BKE_sequencer_from_elem(&iseq->seqbase, se))) {
+ if ((seq_found = BKE_sequencer_from_elem(&iseq->seqbase, se))) {
iseq = seq_found;
break;
}
@@ -5277,24 +5268,22 @@ int BKE_sequencer_active_get_pair(Scene *scene, Sequence **seq_act, Sequence **s
if (*seq_act == NULL) {
return 0;
}
- else {
- Sequence *seq;
- *seq_other = NULL;
+ Sequence *seq;
- for (seq = ed->seqbasep->first; seq; seq = seq->next) {
- if (seq->flag & SELECT && (seq != (*seq_act))) {
- if (*seq_other) {
- return 0;
- }
- else {
- *seq_other = seq;
- }
+ *seq_other = NULL;
+
+ for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+ if (seq->flag & SELECT && (seq != (*seq_act))) {
+ if (*seq_other) {
+ return 0;
}
- }
- return (*seq_other != NULL);
+ *seq_other = seq;
+ }
}
+
+ return (*seq_other != NULL);
}
Mask *BKE_sequencer_mask_get(Scene *scene)
@@ -5304,9 +5293,8 @@ Mask *BKE_sequencer_mask_get(Scene *scene)
if (seq_act && seq_act->type == SEQ_TYPE_MASK) {
return seq_act->mask;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/* api like funcs for adding */
@@ -6112,6 +6100,64 @@ bool BKE_sequencer_render_loop_check(Sequence *seq_main, Sequence *seq)
return false;
}
+static void sequencer_flag_users_for_removal(Scene *scene, ListBase *seqbase, Sequence *seq)
+{
+ LISTBASE_FOREACH (Sequence *, user_seq, seqbase) {
+ /* Look in metas for usage of seq. */
+ if (user_seq->type == SEQ_TYPE_META) {
+ sequencer_flag_users_for_removal(scene, &user_seq->seqbase, seq);
+ }
+
+ /* Clear seq from modifiers. */
+ SequenceModifierData *smd;
+ for (smd = user_seq->modifiers.first; smd; smd = smd->next) {
+ if (smd->mask_sequence == seq) {
+ smd->mask_sequence = NULL;
+ }
+ }
+
+ /* Remove effects, that use seq. */
+ if ((user_seq->seq1 && user_seq->seq1 == seq) || (user_seq->seq2 && user_seq->seq2 == seq) ||
+ (user_seq->seq3 && user_seq->seq3 == seq)) {
+ user_seq->flag |= SEQ_FLAG_DELETE;
+ /* Strips can be used as mask even if not in same seqbase. */
+ sequencer_flag_users_for_removal(scene, &scene->ed->seqbase, user_seq);
+ }
+ }
+}
+
+/* Flag seq and its users (effects) for removal. */
+void BKE_sequencer_flag_for_removal(Scene *scene, ListBase *seqbase, Sequence *seq)
+{
+ if (seq == NULL || (seq->flag & SEQ_FLAG_DELETE) != 0) {
+ return;
+ }
+
+ /* Flag and remove meta children. */
+ if (seq->type == SEQ_TYPE_META) {
+ LISTBASE_FOREACH (Sequence *, meta_child, &seq->seqbase) {
+ BKE_sequencer_flag_for_removal(scene, &seq->seqbase, meta_child);
+ }
+ }
+
+ seq->flag |= SEQ_FLAG_DELETE;
+ sequencer_flag_users_for_removal(scene, seqbase, seq);
+}
+
+/* Remove all flagged sequences, return true if sequence is removed. */
+void BKE_sequencer_remove_flagged_sequences(Scene *scene, ListBase *seqbase)
+{
+ LISTBASE_FOREACH_MUTABLE (Sequence *, seq, seqbase) {
+ if (seq->flag & SEQ_FLAG_DELETE) {
+ if (seq->type == SEQ_TYPE_META) {
+ BKE_sequencer_remove_flagged_sequences(scene, &seq->seqbase);
+ }
+ BLI_remlink(seqbase, seq);
+ BKE_sequence_free(scene, seq, true);
+ }
+ }
+}
+
void BKE_sequencer_check_uuids_unique_and_report(const Scene *scene)
{
if (scene->ed == NULL) {
diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c
index 2923298c5d5..b3d350f5ccd 100644
--- a/source/blender/blenkernel/intern/shader_fx.c
+++ b/source/blender/blenkernel/intern/shader_fx.c
@@ -160,9 +160,8 @@ const ShaderFxTypeInfo *BKE_shaderfx_get_info(ShaderFxType type)
if (type < NUM_SHADER_FX_TYPES && type > 0 && shader_fx_types[type]->name[0] != '\0') {
return shader_fx_types[type];
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/**
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 29f4c7dc6c1..0ff5bdda9e9 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -136,30 +136,29 @@ bool BKE_shrinkwrap_init_tree(
return data->bvh != NULL;
}
- else {
- if (mesh->totpoly <= 0) {
- return false;
- }
- data->bvh = BKE_bvhtree_from_mesh_get(&data->treeData, mesh, BVHTREE_FROM_LOOPTRI, 4);
+ if (mesh->totpoly <= 0) {
+ return false;
+ }
- if (data->bvh == NULL) {
- return false;
- }
+ data->bvh = BKE_bvhtree_from_mesh_get(&data->treeData, mesh, BVHTREE_FROM_LOOPTRI, 4);
- if (force_normals || BKE_shrinkwrap_needs_normals(shrinkType, shrinkMode)) {
- data->pnors = CustomData_get_layer(&mesh->pdata, CD_NORMAL);
- if ((mesh->flag & ME_AUTOSMOOTH) != 0) {
- data->clnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
- }
- }
+ if (data->bvh == NULL) {
+ return false;
+ }
- if (shrinkType == MOD_SHRINKWRAP_TARGET_PROJECT) {
- data->boundary = mesh->runtime.shrinkwrap_data;
+ if (force_normals || BKE_shrinkwrap_needs_normals(shrinkType, shrinkMode)) {
+ data->pnors = CustomData_get_layer(&mesh->pdata, CD_NORMAL);
+ if ((mesh->flag & ME_AUTOSMOOTH) != 0) {
+ data->clnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
}
+ }
- return true;
+ if (shrinkType == MOD_SHRINKWRAP_TARGET_PROJECT) {
+ data->boundary = mesh->runtime.shrinkwrap_data;
}
+
+ return true;
}
/* Frees the tree data if necessary. */
@@ -761,7 +760,7 @@ static void target_project_tri_deviation(void *userdata, const float x[3], float
{
TargetProjectTriData *data = userdata;
- float w[3] = {x[0], x[1], 1.0f - x[0] - x[1]};
+ const float w[3] = {x[0], x[1], 1.0f - x[0] - x[1]};
interp_v3_v3v3v3(data->co_interp, data->vtri_co[0], data->vtri_co[1], data->vtri_co[2], w);
interp_v3_v3v3v3(data->no_interp, data->vtri_no[0], data->vtri_no[1], data->vtri_no[2], w);
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index 95340e4e29c..6b03721cab8 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -112,8 +112,8 @@ static void simulation_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons
BKE_simulation_state_copy_data(state_src, state_dst);
}
- BLI_duplicatelist(&simulation_dst->persistent_data_handles,
- &simulation_src->persistent_data_handles);
+ BLI_listbase_clear(&simulation_dst->dependencies);
+ BLI_duplicatelist(&simulation_dst->dependencies, &simulation_src->dependencies);
}
static void simulation_free_data(ID *id)
@@ -130,7 +130,7 @@ static void simulation_free_data(ID *id)
BKE_simulation_state_remove_all(simulation);
- BLI_freelistN(&simulation->persistent_data_handles);
+ BLI_freelistN(&simulation->dependencies);
}
static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
@@ -140,9 +140,8 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
BKE_library_foreach_ID_embedded(data, (ID **)&simulation->nodetree);
}
- LISTBASE_FOREACH (
- PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) {
- BKE_LIB_FOREACHID_PROCESS_ID(data, handle_item->id, IDWALK_CB_USER);
+ LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+ BKE_LIB_FOREACHID_PROCESS_ID(data, dependency->id, IDWALK_CB_USER);
}
}
@@ -284,25 +283,32 @@ void BKE_simulation_data_update(Depsgraph *depsgraph, Scene *scene, Simulation *
blender::sim::update_simulation_in_depsgraph(depsgraph, scene, simulation);
}
+void BKE_simulation_update_dependencies(Simulation *simulation, Main *bmain)
+{
+ bool dependencies_changed = blender::sim::update_simulation_dependencies(simulation);
+ if (dependencies_changed) {
+ DEG_relations_tag_update(bmain);
+ }
+}
+
using StateTypeMap = blender::Map<std::string, std::unique_ptr<SimulationStateType>>;
template<typename T>
static void add_state_type(StateTypeMap &map,
- const char *name,
void (*init)(T *state),
void (*reset)(T *state),
void (*remove)(T *state),
void (*copy)(const T *src, T *dst))
{
SimulationStateType state_type{
- name,
- (int)sizeof(T),
+ BKE_simulation_get_state_type_name<T>(),
+ static_cast<int>(sizeof(T)),
(StateInitFunction)init,
(StateResetFunction)reset,
(StateRemoveFunction)remove,
(StateCopyFunction)copy,
};
- map.add_new(name, std::make_unique<SimulationStateType>(state_type));
+ map.add_new(state_type.name, std::make_unique<SimulationStateType>(state_type));
}
static StateTypeMap init_state_types()
@@ -310,7 +316,6 @@ static StateTypeMap init_state_types()
StateTypeMap map;
add_state_type<ParticleSimulationState>(
map,
- SIM_TYPE_NAME_PARTICLE_SIMULATION,
[](ParticleSimulationState *state) { CustomData_reset(&state->attributes); },
[](ParticleSimulationState *state) {
CustomData_free(&state->attributes, state->tot_particles);
@@ -330,7 +335,6 @@ static StateTypeMap init_state_types()
add_state_type<ParticleMeshEmitterSimulationState>(
map,
- SIM_TYPE_NAME_PARTICLE_MESH_EMITTER,
[](ParticleMeshEmitterSimulationState *UNUSED(state)) {},
[](ParticleMeshEmitterSimulationState *state) { state->last_birth_time = 0.0f; },
[](ParticleMeshEmitterSimulationState *UNUSED(state)) {},
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index d31f5f61597..6a6f74d9fb4 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -230,7 +230,7 @@ static float _final_goal(Object *ob, BodyPoint *bp) /*jow_go_for2_5 */
}
f = sb->mingoal + bp->goal * fabsf(sb->maxgoal - sb->mingoal);
f = pow(f, 4.0f);
- return (f);
+ return f;
}
}
CLOG_ERROR(&LOG, "sb or bp == NULL");
@@ -1051,7 +1051,7 @@ static int sb_detect_aabb_collisionCached(float UNUSED(force[3]),
/* --- the aabb section*/
/* +++ the face external section*/
-static int sb_detect_face_pointCached(float face_v1[3],
+static int sb_detect_face_pointCached(const float face_v1[3],
const float face_v2[3],
const float face_v3[3],
float *damp,
@@ -1149,7 +1149,7 @@ static int sb_detect_face_pointCached(float face_v1[3],
return deflected;
}
-static int sb_detect_face_collisionCached(float face_v1[3],
+static int sb_detect_face_collisionCached(const float face_v1[3],
const float face_v2[3],
const float face_v3[3],
float *damp,
@@ -1328,7 +1328,7 @@ static void scan_for_ext_face_forces(Object *ob, float timenow)
/* +++ the spring external section*/
-static int sb_detect_edge_collisionCached(float edge_v1[3],
+static int sb_detect_edge_collisionCached(const float edge_v1[3],
const float edge_v2[3],
float *damp,
float force[3],
@@ -1619,7 +1619,7 @@ static int choose_winner(
case 3:
copy_v3_v3(w, cc);
}
- return (winner);
+ return winner;
}
static int sb_detect_vertex_collisionCached(float opco[3],
@@ -1833,7 +1833,7 @@ static int sb_deflect_face(Object *ob,
deflected = sb_detect_vertex_collisionCachedEx(
s_actpos, facenormal, cf, force, ob, time, vel, intrusion);
#endif
- return (deflected);
+ return deflected;
}
/* hiding this for now .. but the jacobian may pop up on other tasks .. so i'd like to keep it */
@@ -1991,13 +1991,13 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene,
}
else {
CLOG_ERROR(&LOG, "expected a SB here");
- return (999);
+ return 999;
}
/* debugerin */
if (sb->totpoint < ifirst) {
printf("Aye 998");
- return (998);
+ return 998;
}
/* debugerin */
@@ -3214,12 +3214,11 @@ static int object_has_edges(Object *ob)
if (ob->type == OB_MESH) {
return ((Mesh *)ob->data)->totedge;
}
- else if (ob->type == OB_LATTICE) {
+ if (ob->type == OB_LATTICE) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
/* SB global visible functions */
@@ -3284,8 +3283,8 @@ void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float ls
if (!sb || !sb->bpoint) {
return;
}
- opos = MEM_callocN((sb->totpoint) * 3 * sizeof(float), "SB_OPOS");
- rpos = MEM_callocN((sb->totpoint) * 3 * sizeof(float), "SB_RPOS");
+ opos = MEM_callocN(sizeof(float[3]) * sb->totpoint, "SB_OPOS");
+ rpos = MEM_callocN(sizeof(float[3]) * sb->totpoint, "SB_RPOS");
/* might filter vertex selection with a vertex group */
for (a = 0, bp = sb->bpoint, rp = sb->scratch->Ref.ivert; a < sb->totpoint; a++, bp++, rp++) {
copy_v3_v3(rpos[a], rp->pos);
@@ -3566,7 +3565,7 @@ void sbObjectStep(struct Depsgraph *depsgraph,
BKE_ptcache_invalidate(cache);
return;
}
- else if (framenr > endframe) {
+ if (framenr > endframe) {
framenr = endframe;
}
@@ -3634,7 +3633,7 @@ void sbObjectStep(struct Depsgraph *depsgraph,
return;
}
- else if (cache_result == PTCACHE_READ_OLD) {
+ if (cache_result == PTCACHE_READ_OLD) {
/* pass */
}
else if (/*ob->id.lib || */
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 1fcfc9b060f..b72c5e99b43 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -898,9 +898,8 @@ double BKE_sound_sync_scene(Scene *scene)
if (scene->audio.flag & AUDIO_SYNC) {
return AUD_getSynchronizerPosition(scene->playback_handle);
}
- else {
- return AUD_Handle_getPosition(scene->playback_handle);
- }
+
+ return AUD_Handle_getPosition(scene->playback_handle);
}
return NAN_FLT;
}
@@ -922,9 +921,8 @@ int BKE_sound_scene_playing(Scene *scene)
if (scene->audio.flag & AUDIO_SYNC) {
return AUD_isSynchronizerPlaying();
}
- else {
- return -1;
- }
+
+ return -1;
}
void BKE_sound_free_waveform(bSound *sound)
@@ -959,7 +957,7 @@ void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop)
if (info.length > 0) {
int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
- waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples");
+ waveform->data = MEM_mallocN(sizeof(float[3]) * length, "SoundWaveform.samples");
waveform->length = AUD_readSound(
sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND, stop);
}
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 46341652544..10830a3d4ba 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -366,23 +366,22 @@ static float *studiolight_multilayer_convert_pass(ImBuf *ibuf,
if (channels == 4) {
return rect;
}
- else {
- float *new_rect = MEM_callocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
-
- IMB_buffer_float_from_float(new_rect,
- rect,
- channels,
- IB_PROFILE_LINEAR_RGB,
- IB_PROFILE_LINEAR_RGB,
- false,
- ibuf->x,
- ibuf->y,
- ibuf->x,
- ibuf->x);
- MEM_freeN(rect);
- return new_rect;
- }
+ float *new_rect = MEM_callocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
+
+ IMB_buffer_float_from_float(new_rect,
+ rect,
+ channels,
+ IB_PROFILE_LINEAR_RGB,
+ IB_PROFILE_LINEAR_RGB,
+ false,
+ ibuf->x,
+ ibuf->y,
+ ibuf->x,
+ ibuf->x);
+
+ MEM_freeN(rect);
+ return new_rect;
}
static void studiolight_multilayer_addpass(void *base,
@@ -694,7 +693,7 @@ static void studiolight_calculate_cubemap_vector_weight(
static void studiolight_spherical_harmonics_calculate_coefficients(StudioLight *sl, float (*sh)[3])
{
float weight_accum = 0.0f;
- memset(sh, 0, sizeof(float) * 3 * STUDIOLIGHT_SH_COEFS_LEN);
+ memset(sh, 0, sizeof(float[3]) * STUDIOLIGHT_SH_COEFS_LEN);
for (int face = 0; face < 6; face++) {
ITER_PIXELS (float,
@@ -1229,12 +1228,11 @@ static int studiolight_cmp(const void *a, const void *b)
if (flagorder1 < flagorder2) {
return -1;
}
- else if (flagorder1 > flagorder2) {
+ if (flagorder1 > flagorder2) {
return 1;
}
- else {
- return BLI_strcasecmp(sl1->name, sl2->name);
- }
+
+ return BLI_strcasecmp(sl1->name, sl2->name);
}
/* icons */
@@ -1245,7 +1243,7 @@ static int studiolight_cmp(const void *a, const void *b)
static uint alpha_circle_mask(float u, float v, float inner_edge, float outer_edge)
{
/* Coords from center. */
- float co[2] = {u - 0.5f, v - 0.5f};
+ const float co[2] = {u - 0.5f, v - 0.5f};
float dist = len_v2(co);
float alpha = 1.0f + (inner_edge - dist) / (outer_edge - inner_edge);
uint mask = (uint)floorf(255.0f * min_ff(max_ff(alpha, 0.0f), 1.0f));
@@ -1277,7 +1275,7 @@ static void studiolight_radiance_preview(uint *icon_buffer, StudioLight *sl)
uint alphamask = alpha_circle_mask(dx, dy, 0.5f - texel_size[0], 0.5f);
if (alphamask != 0) {
float normal[3], direction[3], color[4];
- float incoming[3] = {0.0f, 0.0f, -1.0f};
+ const float incoming[3] = {0.0f, 0.0f, -1.0f};
sphere_normal_from_uv(normal, dx, dy);
reflect_v3_v3v3(direction, incoming, normal);
/* We want to see horizon not poles. */
@@ -1496,10 +1494,9 @@ struct StudioLight *BKE_studiolight_find(const char *name, int flag)
if ((sl->flag & flag)) {
return sl;
}
- else {
- /* flags do not match, so use default */
- return BKE_studiolight_find_default(flag);
- }
+
+ /* flags do not match, so use default */
+ return BKE_studiolight_find_default(flag);
}
}
/* When not found, use the default studio light */
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c
index bc1b79f62c5..0997b42a19f 100644
--- a/source/blender/blenkernel/intern/subdiv_ccg.c
+++ b/source/blender/blenkernel/intern/subdiv_ccg.c
@@ -85,7 +85,7 @@ static int element_size_bytes_get(const SubdivCCG *subdiv_ccg)
static void subdiv_ccg_init_layers(SubdivCCG *subdiv_ccg, const SubdivToCCGSettings *settings)
{
/* CCG always contains coordinates. Rest of layers are coming after them. */
- int layer_offset = sizeof(float) * 3;
+ int layer_offset = sizeof(float[3]);
/* Mask. */
if (settings->need_mask) {
subdiv_ccg->has_mask = true;
@@ -103,7 +103,7 @@ static void subdiv_ccg_init_layers(SubdivCCG *subdiv_ccg, const SubdivToCCGSetti
if (settings->need_normal) {
subdiv_ccg->has_normal = true;
subdiv_ccg->normal_offset = layer_offset;
- layer_offset += sizeof(float) * 3;
+ layer_offset += sizeof(float[3]);
}
else {
subdiv_ccg->has_normal = false;
@@ -234,7 +234,7 @@ static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_
SubdivCCG *subdiv_ccg = data->subdiv_ccg;
const int ptex_face_index = data->face_ptex_offset[face_index];
const int grid_size = subdiv_ccg->grid_size;
- const float grid_size_1_inv = 1.0f / (float)(grid_size - 1);
+ const float grid_size_1_inv = 1.0f / (grid_size - 1);
const int element_size = element_size_bytes_get(subdiv_ccg);
SubdivCCGFace *faces = subdiv_ccg->faces;
SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces;
@@ -243,9 +243,9 @@ static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_
const int grid_index = face->start_grid_index + corner;
unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index];
for (int y = 0; y < grid_size; y++) {
- const float grid_v = (float)y * grid_size_1_inv;
+ const float grid_v = y * grid_size_1_inv;
for (int x = 0; x < grid_size; x++) {
- const float grid_u = (float)x * grid_size_1_inv;
+ const float grid_u = x * grid_size_1_inv;
float u, v;
BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, &u, &v);
const size_t grid_element_index = (size_t)y * grid_size + x;
@@ -265,7 +265,7 @@ static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_
{
SubdivCCG *subdiv_ccg = data->subdiv_ccg;
const int grid_size = subdiv_ccg->grid_size;
- const float grid_size_1_inv = 1.0f / (float)(grid_size - 1);
+ const float grid_size_1_inv = 1.0f / (grid_size - 1);
const int element_size = element_size_bytes_get(subdiv_ccg);
SubdivCCGFace *faces = subdiv_ccg->faces;
SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces;
@@ -275,9 +275,9 @@ static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_
const int ptex_face_index = data->face_ptex_offset[face_index] + corner;
unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index];
for (int y = 0; y < grid_size; y++) {
- const float u = 1.0f - ((float)y * grid_size_1_inv);
+ const float u = 1.0f - (y * grid_size_1_inv);
for (int x = 0; x < grid_size; x++) {
- const float v = 1.0f - ((float)x * grid_size_1_inv);
+ const float v = 1.0f - (x * grid_size_1_inv);
const size_t grid_element_index = (size_t)y * grid_size + x;
const size_t grid_element_offset = grid_element_index * element_size;
subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]);
@@ -709,7 +709,7 @@ static void subdiv_ccg_recalc_inner_face_normals(SubdivCCG *subdiv_ccg,
CCGElem *grid = subdiv_ccg->grids[grid_index];
if (tls->face_normals == NULL) {
tls->face_normals = MEM_malloc_arrayN(
- grid_size_1 * grid_size_1, 3 * sizeof(float), "CCG TLS normals");
+ grid_size_1 * grid_size_1, sizeof(float[3]), "CCG TLS normals");
}
for (int y = 0; y < grid_size - 1; y++) {
for (int x = 0; x < grid_size - 1; x++) {
@@ -766,7 +766,7 @@ static void subdiv_ccg_average_inner_face_normals(SubdivCCG *subdiv_ccg,
counter++;
}
/* Normalize and store. */
- mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / (float)counter);
+ mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / counter);
}
}
}
@@ -1009,7 +1009,7 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg,
CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0);
element_accumulator_add(&center_accumulator, subdiv_ccg, key, grid_center_element);
}
- element_accumulator_mul_fl(&center_accumulator, 1.0f / (float)num_face_grids);
+ element_accumulator_mul_fl(&center_accumulator, 1.0f / num_face_grids);
for (int corner = 0; corner < num_face_grids; corner++) {
CCGElem *grid = grids[face->start_grid_index + corner];
CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0);
@@ -1066,7 +1066,7 @@ static void subdiv_ccg_average_grids_boundary(SubdivCCG *subdiv_ccg,
}
}
for (int i = 1; i < grid_size2 - 1; i++) {
- element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / (float)num_adjacent_faces);
+ element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / num_adjacent_faces);
}
/* Copy averaged value to all the other faces. */
for (int face_index = 0; face_index < num_adjacent_faces; face_index++) {
@@ -1118,7 +1118,7 @@ static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg,
key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]);
element_accumulator_add(&accumulator, subdiv_ccg, key, grid_element);
}
- element_accumulator_mul_fl(&accumulator, 1.0f / (float)num_adjacent_faces);
+ element_accumulator_mul_fl(&accumulator, 1.0f / num_adjacent_faces);
/* Copy averaged value to all the other faces. */
for (int face_index = 0; face_index < num_adjacent_faces; face_index++) {
CCGElem *grid_element = subdiv_ccg_coord_to_elem(
@@ -1618,7 +1618,7 @@ static int prev_adjacent_edge_point_index(const SubdivCCG *subdiv_ccg, const int
return point_index - 1;
}
-/* When the point index corresponds to a grid corner, returs the point index which corresponds to
+/* When the point index corresponds to a grid corner, returns the point index which corresponds to
* the corner of the adjacent grid, as the adjacent edge has two separate points for each grid
* corner at the middle of the edge. */
static int adjacent_grid_corner_point_index_on_edge(const SubdivCCG *subdiv_ccg,
@@ -1650,7 +1650,7 @@ static void neighbor_coords_edge_get(const SubdivCCG *subdiv_ccg,
if (include_duplicates) {
num_duplicates += num_adjacent_faces - 1;
if (is_corner) {
- /* When the coord is a grid corner, add an extra duplicate per adajacent grid in all adjacent
+ /* When the coord is a grid corner, add an extra duplicate per adjacent grid in all adjacent
* faces to the edge. */
num_duplicates += num_adjacent_faces;
}
@@ -1933,4 +1933,47 @@ void BKE_subdiv_ccg_grid_hidden_ensure(SubdivCCG *subdiv_ccg, int grid_index)
subdiv_ccg->grid_hidden[grid_index] = BLI_BITMAP_NEW(key.grid_area, __func__);
}
+static void subdiv_ccg_coord_to_ptex_coord(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ int *r_ptex_face_index,
+ float *r_u,
+ float *r_v)
+{
+ Subdiv *subdiv = subdiv_ccg->subdiv;
+
+ const float grid_size = subdiv_ccg->grid_size;
+ const float grid_size_1_inv = 1.0f / (grid_size - 1);
+
+ const float grid_u = coord->x * grid_size_1_inv;
+ const float grid_v = coord->y * grid_size_1_inv;
+
+ const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, coord->grid_index);
+ const SubdivCCGFace *faces = subdiv_ccg->faces;
+ const SubdivCCGFace *face = &faces[face_index];
+ const int *face_ptex_offset = BKE_subdiv_face_ptex_offset_get(subdiv);
+ *r_ptex_face_index = face_ptex_offset[face_index];
+
+ const float corner = coord->grid_index - face->start_grid_index;
+
+ if (face->num_grids == 4) {
+ BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, r_u, r_v);
+ }
+ else {
+ *r_ptex_face_index += corner;
+ *r_u = 1.0f - grid_v;
+ *r_v = 1.0f - grid_u;
+ }
+}
+
+void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord,
+ float r_point[3])
+{
+ Subdiv *subdiv = subdiv_ccg->subdiv;
+ int ptex_face_index;
+ float u, v;
+ subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v);
+ BKE_subdiv_eval_limit_point(subdiv, ptex_face_index, u, v, r_point);
+}
+
/** \} */
diff --git a/source/blender/blenkernel/intern/subdiv_deform.c b/source/blender/blenkernel/intern/subdiv_deform.c
index f03cf4c4d21..2c900fbd600 100644
--- a/source/blender/blenkernel/intern/subdiv_deform.c
+++ b/source/blender/blenkernel/intern/subdiv_deform.c
@@ -214,7 +214,7 @@ void BKE_subdiv_deform_coarse_vertices(struct Subdiv *subdiv,
}
}
- /* Initialize subdivion mesh creation context. */
+ /* Initialize subdivision mesh creation context. */
SubdivDeformContext subdiv_context = {0};
subdiv_context.coarse_mesh = coarse_mesh;
subdiv_context.subdiv = subdiv;
diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.c b/source/blender/blenkernel/intern/subdiv_displacement_multires.c
index 617f37834f9..a63c2994687 100644
--- a/source/blender/blenkernel/intern/subdiv_displacement_multires.c
+++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.c
@@ -128,10 +128,10 @@ BLI_INLINE eAverageWith read_displacement_grid(const MDisps *displacement_grid,
if (x == 0 && y == 0) {
return AVERAGE_WITH_ALL;
}
- else if (x == 0) {
+ if (x == 0) {
return AVERAGE_WITH_PREV;
}
- else if (y == 0) {
+ if (y == 0) {
return AVERAGE_WITH_NEXT;
}
return AVERAGE_WITH_NONE;
@@ -321,9 +321,8 @@ static int displacement_get_face_corner(MultiresDisplacementData *data,
float dummy_corner_u, dummy_corner_v;
return BKE_subdiv_rotate_quad_to_corner(u, v, &dummy_corner_u, &dummy_corner_v);
}
- else {
- return poly_corner->corner;
- }
+
+ return poly_corner->corner;
}
static void initialize(SubdivDisplacement *displacement)
diff --git a/source/blender/blenkernel/intern/subdiv_eval.c b/source/blender/blenkernel/intern/subdiv_eval.c
index 1c10a9a1935..baee8a80f5a 100644
--- a/source/blender/blenkernel/intern/subdiv_eval.c
+++ b/source/blender/blenkernel/intern/subdiv_eval.c
@@ -46,7 +46,7 @@ bool BKE_subdiv_eval_begin(Subdiv *subdiv)
* or when OpenSubdiv is disabled */
return false;
}
- else if (subdiv->evaluator == NULL) {
+ if (subdiv->evaluator == NULL) {
BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE);
subdiv->evaluator = openSubdiv_createEvaluatorFromTopologyRefiner(subdiv->topology_refiner);
BKE_subdiv_stats_end(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE);
diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c
index ff7f6fad5f0..4400e9c976f 100644
--- a/source/blender/blenkernel/intern/subdiv_foreach.c
+++ b/source/blender/blenkernel/intern/subdiv_foreach.c
@@ -1040,7 +1040,7 @@ static void subdiv_foreach_boundary_edges(SubdivForeachTaskContext *ctx,
static void rotate_indices(const int rot, int *a, int *b, int *c, int *d)
{
- int values[4] = {*a, *b, *c, *d};
+ const int values[4] = {*a, *b, *c, *d};
*a = values[(0 - rot + 4) % 4];
*b = values[(1 - rot + 4) % 4];
*c = values[(2 - rot + 4) % 4];
@@ -1123,10 +1123,10 @@ static int subdiv_foreach_loops_corner_index(const float u,
if (u + du <= 0.5f && v + dv <= 0.5f) {
return 0;
}
- else if (u >= 0.5f && v + dv <= 0.5f) {
+ if (u >= 0.5f && v + dv <= 0.5f) {
return 1;
}
- else if (u >= 0.5f && v >= 0.5f) {
+ if (u >= 0.5f && v >= 0.5f) {
return 2;
}
return 3;
@@ -1746,7 +1746,7 @@ static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdat
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
const Mesh *coarse_mesh = ctx->coarse_mesh;
const MEdge *coarse_edge = &coarse_mesh->medge[coarse_edge_index];
- /* Subdivion vertices which corresponds to edge's v1 and v2. */
+ /* Subdivision vertices which corresponds to edge's v1 and v2. */
const int subdiv_v1_index = ctx->vertices_corner_offset + coarse_edge->v1;
const int subdiv_v2_index = ctx->vertices_corner_offset + coarse_edge->v2;
/* First subdivided inner vertex of the edge. */
diff --git a/source/blender/blenkernel/intern/subdiv_mesh.c b/source/blender/blenkernel/intern/subdiv_mesh.c
index 987cc0311c7..8f97fb82db7 100644
--- a/source/blender/blenkernel/intern/subdiv_mesh.c
+++ b/source/blender/blenkernel/intern/subdiv_mesh.c
@@ -1207,7 +1207,7 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv,
return NULL;
}
}
- /* Initialize subdivion mesh creation context. */
+ /* Initialize subdivision mesh creation context. */
SubdivMeshContext subdiv_context = {0};
subdiv_context.settings = settings;
subdiv_context.coarse_mesh = coarse_mesh;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 7a0a5645b80..45dca79342e 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -150,7 +150,7 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int numLaye
ifc.vertDataSize = sizeof(float) * numLayers;
normalOffset += sizeof(float) * numLayers;
if (flags & CCG_CALC_NORMALS) {
- ifc.vertDataSize += sizeof(float) * 3;
+ ifc.vertDataSize += sizeof(float[3]);
}
if (flags & CCG_ALLOC_MASK) {
ifc.vertDataSize += sizeof(float);
@@ -203,12 +203,11 @@ static int getEdgeIndex(CCGSubSurf *ss, CCGEdge *e, int x, int edgeSize)
if (x == 0) {
return v0idx;
}
- else if (x == edgeSize - 1) {
+ if (x == edgeSize - 1) {
return v1idx;
}
- else {
- return edgeBase + x - 1;
- }
+
+ return edgeBase + x - 1;
}
static int getFaceIndex(
@@ -221,42 +220,39 @@ static int getFaceIndex(
CCGVert *v = ccgSubSurf_getFaceVert(f, S);
return *((int *)ccgSubSurf_getVertUserData(ss, v));
}
- else if (x == gridSize - 1) {
+ if (x == gridSize - 1) {
CCGVert *v = ccgSubSurf_getFaceVert(f, S);
CCGEdge *e = ccgSubSurf_getFaceEdge(f, S);
int edgeBase = *((int *)ccgSubSurf_getEdgeUserData(ss, e));
if (v == ccgSubSurf_getEdgeVert0(e)) {
return edgeBase + (gridSize - 1 - y) - 1;
}
- else {
- return edgeBase + (edgeSize - 2 - 1) - ((gridSize - 1 - y) - 1);
- }
+
+ return edgeBase + (edgeSize - 2 - 1) - ((gridSize - 1 - y) - 1);
}
- else if (y == gridSize - 1) {
+ if (y == gridSize - 1) {
CCGVert *v = ccgSubSurf_getFaceVert(f, S);
CCGEdge *e = ccgSubSurf_getFaceEdge(f, (S + numVerts - 1) % numVerts);
int edgeBase = *((int *)ccgSubSurf_getEdgeUserData(ss, e));
if (v == ccgSubSurf_getEdgeVert0(e)) {
return edgeBase + (gridSize - 1 - x) - 1;
}
- else {
- return edgeBase + (edgeSize - 2 - 1) - ((gridSize - 1 - x) - 1);
- }
+
+ return edgeBase + (edgeSize - 2 - 1) - ((gridSize - 1 - x) - 1);
}
- else if (x == 0 && y == 0) {
+ if (x == 0 && y == 0) {
return faceBase;
}
- else if (x == 0) {
+ if (x == 0) {
S = (S + numVerts - 1) % numVerts;
return faceBase + 1 + (gridSize - 2) * S + (y - 1);
}
- else if (y == 0) {
+ if (y == 0) {
return faceBase + 1 + (gridSize - 2) * S + (x - 1);
}
- else {
- return faceBase + 1 + (gridSize - 2) * numVerts + S * (gridSize - 2) * (gridSize - 2) +
- (y - 1) * (gridSize - 2) + (x - 1);
- }
+
+ return faceBase + 1 + (gridSize - 2) * numVerts + S * (gridSize - 2) * (gridSize - 2) +
+ (y - 1) * (gridSize - 2) + (x - 1);
}
static void get_face_uv_map_vert(
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 5f85e1a1664..8a055423d6f 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -812,9 +812,8 @@ int txt_calc_tab_right(TextLine *tl, int ch)
return i - ch;
}
- else {
- return 0;
- }
+
+ return 0;
}
void txt_move_left(Text *text, const bool sel)
@@ -1664,9 +1663,8 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
txt_move_to(text, newl, newc + strlen(findstr), 1);
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
/** \} */
@@ -1797,7 +1795,7 @@ void txt_delete_char(Text *text)
txt_make_dirty(text);
return;
}
- else if (text->curc == text->curl->len) { /* Appending two lines */
+ if (text->curc == text->curl->len) { /* Appending two lines */
if (text->curl->next) {
txt_combine_lines(text, text->curl, text->curl->next);
txt_pop_sel(text);
@@ -1844,7 +1842,7 @@ void txt_backspace_char(Text *text)
txt_make_dirty(text);
return;
}
- else if (text->curc == 0) { /* Appending two lines */
+ if (text->curc == 0) { /* Appending two lines */
if (!text->curl->prev) {
return;
}
@@ -2052,10 +2050,9 @@ static void txt_select_prefix(Text *text, const char *add, bool skip_blank_lines
}
break;
}
- else {
- text->curl = text->curl->next;
- num++;
- }
+
+ text->curl = text->curl->next;
+ num++;
}
while (num > 0) {
@@ -2140,10 +2137,9 @@ static bool txt_select_unprefix(Text *text, const char *remove, const bool requi
}
break;
}
- else {
- text->curl = text->curl->next;
- num++;
- }
+
+ text->curl = text->curl->next;
+ num++;
}
if (unindented_first) {
@@ -2253,9 +2249,8 @@ int txt_setcurr_tab_spaces(Text *text, int space)
if (i == text->curc) {
return i;
}
- else {
- i++;
- }
+
+ i++;
}
if (strstr(text->curl->line, word)) {
/* if we find a ':' on this line, then add a tab but not if it is:
@@ -2270,7 +2265,7 @@ int txt_setcurr_tab_spaces(Text *text, int space)
if (ch == '#') {
break;
}
- else if (ch == ':') {
+ if (ch == ':') {
is_indent = 1;
}
else if (ch != ' ' && ch != '\t') {
@@ -2309,7 +2304,7 @@ int text_check_bracket(const char ch)
if (ch == opens[a]) {
return a + 1;
}
- else if (ch == close[a]) {
+ if (ch == close[a]) {
return -(a + 1);
}
}
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index e2c3c20e36e..8d5a0497e28 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -664,11 +664,11 @@ bool BKE_texture_dependsOnTime(const struct Tex *texture)
if (texture->ima && BKE_image_is_animated(texture->ima)) {
return true;
}
- else if (texture->adt) {
+ if (texture->adt) {
/* assume anything in adt means the texture is animated */
return true;
}
- else if (texture->type == TEX_NOISE) {
+ if (texture->type == TEX_NOISE) {
/* noise always varies with time */
return true;
}
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index f17467e4a26..7c34562e119 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -1188,38 +1188,36 @@ MovieTrackingMarker *BKE_tracking_marker_insert(MovieTrackingTrack *track,
return old_marker;
}
- else {
- int a = track->markersnr;
- /* find position in array where to add new marker */
- while (a--) {
- if (track->markers[a].framenr < marker->framenr) {
- break;
- }
+ int a = track->markersnr;
+
+ /* find position in array where to add new marker */
+ while (a--) {
+ if (track->markers[a].framenr < marker->framenr) {
+ break;
}
+ }
- track->markersnr++;
+ track->markersnr++;
- if (track->markers) {
- track->markers = MEM_reallocN(track->markers,
- sizeof(MovieTrackingMarker) * track->markersnr);
- }
- else {
- track->markers = MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers");
- }
+ if (track->markers) {
+ track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr);
+ }
+ else {
+ track->markers = MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers");
+ }
- /* shift array to "free" space for new marker */
- memmove(track->markers + a + 2,
- track->markers + a + 1,
- (track->markersnr - a - 2) * sizeof(MovieTrackingMarker));
+ /* shift array to "free" space for new marker */
+ memmove(track->markers + a + 2,
+ track->markers + a + 1,
+ (track->markersnr - a - 2) * sizeof(MovieTrackingMarker));
- /* put new marker */
- track->markers[a + 1] = *marker;
+ /* put new marker */
+ track->markers[a + 1] = *marker;
- track->last_marker = a + 1;
+ track->last_marker = a + 1;
- return &track->markers[a + 1];
- }
+ return &track->markers[a + 1];
}
void BKE_tracking_marker_delete(MovieTrackingTrack *track, int framenr)
@@ -1337,21 +1335,20 @@ MovieTrackingMarker *BKE_tracking_marker_get(MovieTrackingTrack *track, int fram
/* if there's no marker for exact position, use nearest marker from left side */
return &track->markers[a - 1];
}
- else {
- while (a >= 0 && track->markers[a].framenr >= framenr) {
- if (track->markers[a].framenr == framenr) {
- track->last_marker = a;
- return &track->markers[a];
- }
+ while (a >= 0 && track->markers[a].framenr >= framenr) {
+ if (track->markers[a].framenr == framenr) {
+ track->last_marker = a;
- a--;
+ return &track->markers[a];
}
- /* if there's no marker for exact position, use nearest marker from left side */
- return &track->markers[a];
+ a--;
}
+ /* if there's no marker for exact position, use nearest marker from left side */
+ return &track->markers[a];
+
return NULL;
}
@@ -1655,32 +1652,31 @@ MovieTrackingPlaneMarker *BKE_tracking_plane_marker_insert(MovieTrackingPlaneTra
return old_plane_marker;
}
- else {
- int a = plane_track->markersnr;
- /* Find position in array where to add new marker. */
- /* TODO(sergey): we could use bisect to speed things up. */
- while (a--) {
- if (plane_track->markers[a].framenr < plane_marker->framenr) {
- break;
- }
+ int a = plane_track->markersnr;
+
+ /* Find position in array where to add new marker. */
+ /* TODO(sergey): we could use bisect to speed things up. */
+ while (a--) {
+ if (plane_track->markers[a].framenr < plane_marker->framenr) {
+ break;
}
+ }
- plane_track->markersnr++;
- plane_track->markers = MEM_reallocN(plane_track->markers,
- sizeof(MovieTrackingPlaneMarker) * plane_track->markersnr);
+ plane_track->markersnr++;
+ plane_track->markers = MEM_reallocN(plane_track->markers,
+ sizeof(MovieTrackingPlaneMarker) * plane_track->markersnr);
- /* Shift array to "free" space for new marker. */
- memmove(plane_track->markers + a + 2,
- plane_track->markers + a + 1,
- (plane_track->markersnr - a - 2) * sizeof(MovieTrackingPlaneMarker));
+ /* Shift array to "free" space for new marker. */
+ memmove(plane_track->markers + a + 2,
+ plane_track->markers + a + 1,
+ (plane_track->markersnr - a - 2) * sizeof(MovieTrackingPlaneMarker));
- /* Put new marker to an array. */
- plane_track->markers[a + 1] = *plane_marker;
- plane_track->last_marker = a + 1;
+ /* Put new marker to an array. */
+ plane_track->markers[a + 1] = *plane_marker;
+ plane_track->last_marker = a + 1;
- return &plane_track->markers[a + 1];
- }
+ return &plane_track->markers[a + 1];
}
void BKE_tracking_plane_marker_delete(MovieTrackingPlaneTrack *plane_track, int framenr)
@@ -1748,21 +1744,20 @@ MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get(MovieTrackingPlaneTrack
/* If there's no marker for exact position, use nearest marker from left side. */
return &plane_track->markers[a - 1];
}
- else {
- while (a >= 0 && plane_track->markers[a].framenr >= framenr) {
- if (plane_track->markers[a].framenr == framenr) {
- plane_track->last_marker = a;
- return &plane_track->markers[a];
- }
+ while (a >= 0 && plane_track->markers[a].framenr >= framenr) {
+ if (plane_track->markers[a].framenr == framenr) {
+ plane_track->last_marker = a;
- a--;
+ return &plane_track->markers[a];
}
- /* If there's no marker for exact position, use nearest marker from left side. */
- return &plane_track->markers[a];
+ a--;
}
+ /* If there's no marker for exact position, use nearest marker from left side. */
+ return &plane_track->markers[a];
+
return NULL;
}
@@ -1988,18 +1983,16 @@ static int reconstructed_camera_index_get(MovieTrackingReconstruction *reconstru
if (nearest) {
return 0;
}
- else {
- return -1;
- }
+
+ return -1;
}
if (framenr > cameras[reconstruction->camnr - 1].framenr) {
if (nearest) {
return reconstruction->camnr - 1;
}
- else {
- return -1;
- }
+
+ return -1;
}
if (reconstruction->last_camera < reconstruction->camnr) {
@@ -2020,9 +2013,8 @@ static int reconstructed_camera_index_get(MovieTrackingReconstruction *reconstru
if (nearest) {
return a - 1;
}
- else {
- break;
- }
+
+ break;
}
if (d < 0 && cfra < framenr) {
@@ -2030,9 +2022,8 @@ static int reconstructed_camera_index_get(MovieTrackingReconstruction *reconstru
if (nearest) {
return a;
}
- else {
- break;
- }
+
+ break;
}
if (cfra == framenr) {
@@ -2705,9 +2696,8 @@ static int channels_alpha_sort(const void *a, const void *b)
if (BLI_strcasecmp(channel_a->track->name, channel_b->track->name) > 0) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
static int channels_total_track_sort(const void *a, const void *b)
@@ -2718,9 +2708,8 @@ static int channels_total_track_sort(const void *a, const void *b)
if (channel_a->total_frames > channel_b->total_frames) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
static int channels_longest_segment_sort(const void *a, const void *b)
@@ -2731,9 +2720,8 @@ static int channels_longest_segment_sort(const void *a, const void *b)
if (channel_a->max_segment > channel_b->max_segment) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
static int channels_average_error_sort(const void *a, const void *b)
@@ -2744,9 +2732,8 @@ static int channels_average_error_sort(const void *a, const void *b)
if (channel_a->track->error > channel_b->track->error) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
static int channels_alpha_inverse_sort(const void *a, const void *b)
@@ -2754,9 +2741,8 @@ static int channels_alpha_inverse_sort(const void *a, const void *b)
if (channels_alpha_sort(a, b)) {
return 0;
}
- else {
- return 1;
- }
+
+ return 1;
}
static int channels_total_track_inverse_sort(const void *a, const void *b)
@@ -2764,9 +2750,8 @@ static int channels_total_track_inverse_sort(const void *a, const void *b)
if (channels_total_track_sort(a, b)) {
return 0;
}
- else {
- return 1;
- }
+
+ return 1;
}
static int channels_longest_segment_inverse_sort(const void *a, const void *b)
@@ -2774,9 +2759,8 @@ static int channels_longest_segment_inverse_sort(const void *a, const void *b)
if (channels_longest_segment_sort(a, b)) {
return 0;
}
- else {
- return 1;
- }
+
+ return 1;
}
static int channels_average_error_inverse_sort(const void *a, const void *b)
@@ -2787,9 +2771,8 @@ static int channels_average_error_inverse_sort(const void *a, const void *b)
if (channel_a->track->error < channel_b->track->error) {
return 1;
}
- else {
- return 0;
- }
+
+ return 0;
}
/* Calculate frames segments at which track is tracked continuously. */
@@ -2840,7 +2823,7 @@ static void tracking_dopesheet_channels_segments_calc(MovieTrackingDopesheetChan
return;
}
- channel->segments = MEM_callocN(2 * sizeof(int) * channel->tot_segment,
+ channel->segments = MEM_callocN(sizeof(int[2]) * channel->tot_segment,
"tracking channel segments");
/* create segments */
@@ -2965,7 +2948,7 @@ static int coverage_from_count(int count)
if (count < 8) {
return TRACKING_COVERAGE_BAD;
}
- else if (count < 16) {
+ if (count < 16) {
return TRACKING_COVERAGE_ACCEPTABLE;
}
return TRACKING_COVERAGE_OK;
diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c
index 46870a03e62..7df8bf62b16 100644
--- a/source/blender/blenkernel/intern/tracking_solver.c
+++ b/source/blender/blenkernel/intern/tracking_solver.c
@@ -335,7 +335,7 @@ bool BKE_tracking_reconstruction_check(MovieTracking *tracking,
/* TODO: check for number of tracks? */
return true;
}
- else if ((tracking->settings.reconstruction_flag & TRACKING_USE_KEYFRAME_SELECTION) == 0) {
+ if ((tracking->settings.reconstruction_flag & TRACKING_USE_KEYFRAME_SELECTION) == 0) {
/* automatic keyframe selection does not require any pre-process checks */
if (reconstruct_count_tracks_on_both_keyframes(tracking, object) < 8) {
BLI_strncpy(error_msg,
diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c
index e09e92588c6..46e3e10b01b 100644
--- a/source/blender/blenkernel/intern/tracking_stabilize.c
+++ b/source/blender/blenkernel/intern/tracking_stabilize.c
@@ -215,7 +215,7 @@ static void use_values_from_fcurves(StabContext *ctx, bool toggle)
/* Prepare per call private working area.
* Used for access to possibly animated values: retrieve available F-curves.
*/
-static StabContext *initialize_stabilization_working_context(MovieClip *clip)
+static StabContext *init_stabilization_working_context(MovieClip *clip)
{
StabContext *ctx = MEM_callocN(sizeof(StabContext), "2D stabilization animation runtime data");
ctx->clip = clip;
@@ -357,9 +357,8 @@ static MovieTrackingMarker *get_closest_marker(StabContext *ctx,
if ((next_higher - ref_frame) < (ref_frame - next_lower)) {
return BKE_tracking_marker_get_exact(track, next_higher);
}
- else {
- return BKE_tracking_marker_get_exact(track, next_lower);
- }
+
+ return BKE_tracking_marker_get_exact(track, next_lower);
}
/* Retrieve tracking data, if available and applicable for this frame.
@@ -377,11 +376,10 @@ static MovieTrackingMarker *get_tracking_data_point(StabContext *ctx,
*r_weight = get_animated_weight(ctx, track, framenr);
return marker;
}
- else {
- /* No marker at this frame (=gap) or marker disabled. */
- *r_weight = 0.0f;
- return NULL;
- }
+
+ /* No marker at this frame (=gap) or marker disabled. */
+ *r_weight = 0.0f;
+ return NULL;
}
/* Define the reference point for rotation/scale measurement and compensation.
@@ -841,14 +839,14 @@ static int establish_track_initialization_order(StabContext *ctx, TrackInitOrder
*
* NOTE: when done, this track is marked as initialized
*/
-static void initialize_track_for_stabilization(StabContext *ctx,
- MovieTrackingTrack *track,
- int reference_frame,
- float aspect,
- const float average_translation[2],
- const float pivot[2],
- const float average_angle,
- const float average_scale_step)
+static void init_track_for_stabilization(StabContext *ctx,
+ MovieTrackingTrack *track,
+ int reference_frame,
+ float aspect,
+ const float average_translation[2],
+ const float pivot[2],
+ const float average_angle,
+ const float average_scale_step)
{
float pos[2], angle, len;
TrackStabilizationBase *local_data = access_stabilization_baseline_data(ctx, track);
@@ -876,7 +874,7 @@ static void initialize_track_for_stabilization(StabContext *ctx,
local_data->is_init_for_stabilization = true;
}
-static void initialize_all_tracks(StabContext *ctx, float aspect)
+static void init_all_tracks(StabContext *ctx, float aspect)
{
size_t track_len = 0;
MovieClip *clip = ctx->clip;
@@ -936,14 +934,14 @@ static void initialize_all_tracks(StabContext *ctx, float aspect)
&average_angle,
&average_scale_step);
}
- initialize_track_for_stabilization(ctx,
- track,
- reference_frame,
- aspect,
- average_translation,
- pivot,
- average_angle,
- average_scale_step);
+ init_track_for_stabilization(ctx,
+ track,
+ reference_frame,
+ aspect,
+ average_translation,
+ pivot,
+ average_angle,
+ average_scale_step);
}
cleanup:
@@ -1094,7 +1092,7 @@ static void stabilization_data_to_mat4(float pixel_aspect,
{
float translation_mat[4][4], rotation_mat[4][4], scale_mat[4][4], pivot_mat[4][4],
inv_pivot_mat[4][4], aspect_mat[4][4], inv_aspect_mat[4][4];
- float scale_vector[3] = {scale, scale, 1.0f};
+ const float scale_vector[3] = {scale, scale, 1.0f};
unit_m4(translation_mat);
unit_m4(rotation_mat);
@@ -1257,9 +1255,9 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect
*/
static StabContext *init_stabilizer(MovieClip *clip, int size, float aspect)
{
- StabContext *ctx = initialize_stabilization_working_context(clip);
+ StabContext *ctx = init_stabilization_working_context(clip);
BLI_assert(ctx != NULL);
- initialize_all_tracks(ctx, aspect);
+ init_all_tracks(ctx, aspect);
if (ctx->stab->flag & TRACKING_AUTOSCALE) {
ctx->stab->scale = 1.0;
ctx->stab->scale = calculate_autoscale_factor(ctx, size, aspect);
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 0809e8dda6d..0a0f81f7829 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -476,9 +476,8 @@ UndoStep *BKE_undosys_step_push_init_with_type(UndoStack *ustack,
undosys_stack_validate(ustack, false);
return us;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
UndoStep *BKE_undosys_step_push_init(UndoStack *ustack, bContext *C, const char *name)
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index efe10b02940..8414f93ddaa 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -130,7 +130,7 @@ typedef struct bUnitCollection {
/* Keep table lignment. */
/* clang-format off */
-#define UNIT_COLLECTION_LENGTH(def) (sizeof(def) / sizeof(bUnitDef) - 1)
+#define UNIT_COLLECTION_LENGTH(def) (ARRAY_SIZE(def) - 1)
#define NULL_UNIT {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
/* Dummy */
@@ -970,9 +970,8 @@ double bUnit_PreferredInputUnitScalar(const struct UnitSettings *settings, int t
if (unit) {
return unit->scalar;
}
- else {
- return bUnit_BaseScalar(units.system, type);
- }
+
+ return bUnit_BaseScalar(units.system, type);
}
/* make a copy of the string that replaces the units with numbers
@@ -1155,9 +1154,8 @@ double bUnit_BaseScalar(int system, int type)
if (usys) {
return unit_default(usys)->scalar;
}
- else {
- return 1.0;
- }
+
+ return 1.0;
}
/* external access */
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index 633ad250a67..54fb0f612d1 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -367,9 +367,8 @@ struct VolumeGrid {
if (is_loaded && entry && !entry->error_msg.empty()) {
return entry->error_msg.c_str();
}
- else {
- return NULL;
- }
+
+ return NULL;
}
const bool grid_is_loaded() const
@@ -1087,34 +1086,34 @@ VolumeGridType BKE_volume_grid_type(const VolumeGrid *volume_grid)
if (grid->isType<openvdb::FloatGrid>()) {
return VOLUME_GRID_FLOAT;
}
- else if (grid->isType<openvdb::Vec3fGrid>()) {
+ if (grid->isType<openvdb::Vec3fGrid>()) {
return VOLUME_GRID_VECTOR_FLOAT;
}
- else if (grid->isType<openvdb::BoolGrid>()) {
+ if (grid->isType<openvdb::BoolGrid>()) {
return VOLUME_GRID_BOOLEAN;
}
- else if (grid->isType<openvdb::DoubleGrid>()) {
+ if (grid->isType<openvdb::DoubleGrid>()) {
return VOLUME_GRID_DOUBLE;
}
- else if (grid->isType<openvdb::Int32Grid>()) {
+ if (grid->isType<openvdb::Int32Grid>()) {
return VOLUME_GRID_INT;
}
- else if (grid->isType<openvdb::Int64Grid>()) {
+ if (grid->isType<openvdb::Int64Grid>()) {
return VOLUME_GRID_INT64;
}
- else if (grid->isType<openvdb::Vec3IGrid>()) {
+ if (grid->isType<openvdb::Vec3IGrid>()) {
return VOLUME_GRID_VECTOR_INT;
}
- else if (grid->isType<openvdb::Vec3dGrid>()) {
+ if (grid->isType<openvdb::Vec3dGrid>()) {
return VOLUME_GRID_VECTOR_DOUBLE;
}
- else if (grid->isType<openvdb::StringGrid>()) {
+ if (grid->isType<openvdb::StringGrid>()) {
return VOLUME_GRID_STRING;
}
- else if (grid->isType<openvdb::MaskGrid>()) {
+ if (grid->isType<openvdb::MaskGrid>()) {
return VOLUME_GRID_MASK;
}
- else if (grid->isType<openvdb::points::PointDataGrid>()) {
+ if (grid->isType<openvdb::points::PointDataGrid>()) {
return VOLUME_GRID_POINTS;
}
#else
diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc
index 135c6f78fef..98d3617c822 100644
--- a/source/blender/blenkernel/intern/volume_render.cc
+++ b/source/blender/blenkernel/intern/volume_render.cc
@@ -363,7 +363,6 @@ float BKE_volume_density_scale(const Volume *volume, const float matrix[4][4])
mul_mat3_m4_v3(matrix, unit);
return 1.0f / len_v3(unit);
}
- else {
- return 1.0f;
- }
+
+ return 1.0f;
}
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 4625fd76293..f653a190704 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -157,9 +157,8 @@ static void *workspace_relation_get_data_matching_parent(const ListBase *relatio
if (relation != NULL) {
return relation->value;
}
- else {
- return NULL;
- }
+
+ return NULL;
}
/**
@@ -397,10 +396,9 @@ bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_
if ((*owner_id == '\0') || ((workspace->flags & WORKSPACE_USE_FILTER_BY_ORIGIN) == 0)) {
return true;
}
- else {
- /* We could use hash lookup, for now this list is highly likely under < ~16 items. */
- return BLI_findstring(&workspace->owner_ids, owner_id, offsetof(wmOwnerID, name)) != NULL;
- }
+
+ /* We could use hash lookup, for now this list is highly likely under < ~16 items. */
+ return BLI_findstring(&workspace->owner_ids, owner_id, offsetof(wmOwnerID, name)) != NULL;
}
void BKE_workspace_id_tag_all_visible(Main *bmain, int tag)