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:
authorSybren A. Stüvel <sybren@blender.org>2020-08-13 13:53:21 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-08-13 14:56:41 +0300
commitcb2565195e72ee4dc5c0b53b7cd5037b2169d55f (patch)
tree5288e2157e252264f84516736ae24d9025654505 /source/blender/bmesh
parent46aa30240005bfbb527e1f3e2a9279eb61e19a54 (diff)
Fix T65148: Drivers can't access shape keys
It was impossible for drivers to use shape key properties, modifiers generate a new mesh. After mesh evaluation the shape keys are no longer necessary, and because of this the `key` pointer was not copied. As drivers work on evaluated data, however, they do need this `key` pointer. This commit makes the `key` pointer available in evaluated meshes, but this is somewhat dangerous. There was an explicit reason why the key on result was kept at null pointer: to have the evaluated mesh in a consistent state. Assigning this pointer makes it potentially inconsistent, as the evaluated mesh and the original shape key may have different topologies. Reviewed By: sergey Differential Revision: https://developer.blender.org/D7785
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r--source/blender/bmesh/CMakeLists.txt1
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_convert.c15
2 files changed, 13 insertions, 3 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt
index b97b5cc95f2..0eeb0d21b5b 100644
--- a/source/blender/bmesh/CMakeLists.txt
+++ b/source/blender/bmesh/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../makesdna
../../../intern/atomic
../../../intern/eigen
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.c b/source/blender/bmesh/intern/bmesh_mesh_convert.c
index 8db125970fd..4671df90d53 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.c
@@ -90,6 +90,8 @@
#include "BKE_key.h"
#include "BKE_main.h"
+#include "DEG_depsgraph_query.h"
+
#include "bmesh.h"
#include "intern/bmesh_private.h" /* For element checking. */
@@ -231,7 +233,13 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
/* -------------------------------------------------------------------- */
/* Shape Key */
- int tot_shape_keys = me->key ? BLI_listbase_count(&me->key->block) : 0;
+ int tot_shape_keys = 0;
+ if (me->key != NULL && DEG_is_original_id(&me->id)) {
+ /* Evaluated meshes can be topologically inconsistent with their shape keys.
+ * Shape keys are also already integrated into the state of the evaluated
+ * mesh, so considering them here would kind of apply them twice. */
+ tot_shape_keys = BLI_listbase_count(&me->key->block);
+ }
if (is_new == false) {
tot_shape_keys = min_ii(tot_shape_keys, CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY));
}
@@ -239,7 +247,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
BLI_array_alloca(shape_key_table, tot_shape_keys) :
NULL;
- if ((params->active_shapekey != 0) && (me->key != NULL)) {
+ if ((params->active_shapekey != 0) && tot_shape_keys > 0) {
actkey = BLI_findlink(&me->key->block, params->active_shapekey - 1);
}
else {
@@ -298,7 +306,8 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
- const int cd_shape_key_offset = me->key ? CustomData_get_offset(&bm->vdata, CD_SHAPEKEY) : -1;
+ const int cd_shape_key_offset = tot_shape_keys ? CustomData_get_offset(&bm->vdata, CD_SHAPEKEY) :
+ -1;
const int cd_shape_keyindex_offset = is_new && (tot_shape_keys || params->add_key_index) ?
CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) :
-1;