diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-21 20:43:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-21 20:43:04 +0400 |
commit | 8cde4e5182fd2bf2bab393db32c0fa460874f82b (patch) | |
tree | 1686f1a2edece343c422c318894e0acf1fb017e2 | |
parent | bcdbc579943f21bbd2f4005c7de265d6ee6dc9f9 (diff) |
add an influence slider to mesh cache.
-rw-r--r-- | release/scripts/startup/bl_ui/properties_data_modifier.py | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 13 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 6 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_meshcache.c | 24 |
6 files changed, 43 insertions, 4 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 99559f47ff6..79846df14ae 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -167,6 +167,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): layout.prop(md, "filepath") layout.label(text="Evaluation:") + layout.prop(md, "factor", slider=True) layout.prop(md, "interpolation") layout.label(text="Time Mapping:") diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index e9217728eae..42a6b90f738 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -255,6 +255,7 @@ void sub_vn_vn(float *array_tar, const float *array_src, const int size); void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); void msub_vn_vn(float *array_tar, const float *array_src, const float f, const int size); void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size); +void interp_vn_vn(float *array_tar, const float *array_src, const float t, const int size); void fill_vn_i(int *array_tar, const int size, const int val); void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val); void fill_vn_fl(float *array_tar, const int size, const float val); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 743d1fc497b..490ed2a99fb 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -711,6 +711,19 @@ void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array } } +void interp_vn_vn(float *array_tar, const float *array_src, const float t, const int size) +{ + const float s = 1.0f - t; + float *tar = array_tar + (size - 1); + const float *src = array_src + (size - 1); + int i = size; + while (i--) { + *(tar) = (s * *(tar)) + (t * *(src)); + tar--; + src--; + } +} + void fill_vn_i(int *array_tar, const int size, const int val) { int *tar = array_tar + (size - 1); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 2f9da059fc0..42ddbd84368 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1174,7 +1174,7 @@ typedef struct MeshCacheModifierData { char interp; - char pad[4]; + float factor; /* play_mode == MOD_MESHCACHE_PLAY_CFEA */ float frame_start; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 653e77f529c..0d88cbf2f27 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -3558,6 +3558,12 @@ static void rna_def_modifier_meshcache(BlenderRNA *brna) RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "factor"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Influence", "Influence of the deformation"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + /* -------------------------------------------------------------------- */ /* Axis Conversion */ prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE); diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index c722eda28ec..d140b8909d4 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -34,12 +34,13 @@ #include "BLI_path_util.h" #include "BLI_math.h" - #include "BKE_DerivedMesh.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_main.h" +#include "MEM_guardedalloc.h" + #include "MOD_meshcache_util.h" /* utility functions */ #include "MOD_modifiertypes.h" @@ -99,6 +100,8 @@ static void initData(ModifierData *md) mcmd->interp = MOD_MESHCACHE_INTERP_LINEAR; mcmd->frame_scale = 1.0f; + mcmd->factor = 1.0f; + /* (Y, Z). Blender default */ mcmd->forward_axis = 1; mcmd->up_axis = 2; @@ -124,6 +127,8 @@ static void copyData(ModifierData *md, ModifierData *target) tmcmd->frame_start = mcmd->frame_start; tmcmd->frame_scale = mcmd->frame_scale; + tmcmd->factor = mcmd->factor; + tmcmd->eval_frame = mcmd->eval_frame; tmcmd->eval_time = mcmd->eval_time; tmcmd->eval_factor = mcmd->eval_factor; @@ -142,14 +147,19 @@ static int isDisabled(ModifierData *md, int UNUSED(useRenderParams)) MeshCacheModifierData *mcmd = (MeshCacheModifierData *) md; /* leave it up to the modifier to check the file is valid on calculation */ - return (mcmd->filepath[0] == '\0'); + return (mcmd->factor <= 0.0f) || (mcmd->filepath[0] == '\0'); } static void meshcache_do( MeshCacheModifierData *mcmd, Object *ob, DerivedMesh *UNUSED(dm), - float (*vertexCos)[3], int numVerts) + float (*vertexCos_)[3], int numVerts) { + float (*vertexCos_Store)[3] = (mcmd->factor < 1.0f) ? + MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL; + float (*vertexCos_Real)[3] = vertexCos_; + float (*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real; + Scene *scene = mcmd->modifier.scene; const float fps = FPS; @@ -263,6 +273,14 @@ static void meshcache_do( } } } + + if (vertexCos_Store) { + if (ok) { + interp_vn_vn(*vertexCos_Real, *vertexCos_Store, mcmd->factor, numVerts * 3); + } + + MEM_freeN(vertexCos_Store); + } } static void deformVerts(ModifierData *md, Object *ob, |