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:
authorSergey Sharybin <sergey.vfx@gmail.com>2010-06-22 00:10:59 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2010-06-22 00:10:59 +0400
commit425da6206f75b9218cf4123ac1b9cdeaf7f86bb1 (patch)
treebb8639d387efd6a37899c520efdd397f67ddb0c7 /source/blender/blenkernel
parent72d21c35adcea937bbf2e2423472c9ca5ed315c6 (diff)
[#22262] Sculpting shape keys using the Smooth brush switches the shape to the Basis
PBVH used the same verts array as mesh data and shape key/reference key coords were applying on the mesh data, so on some refreshing undeformed mesh was displayed. Added utility functions to get vert coords from key block, apply new vert coords on keyblock and function to apply coords on bpvh, so now pbvh uses it's ovn vertex array and no changes are making to the mesh data. Additional change: Store key block name in SculptUndoNode, so now shape wouldn't be copied to wrong keyblock on undo
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_key.h2
-rw-r--r--source/blender/blenkernel/BKE_paint.h4
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c14
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c3
-rw-r--r--source/blender/blenkernel/intern/key.c149
5 files changed, 166 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 6b8f18e9e17..c94955e611e 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -75,6 +75,8 @@ void key_to_latt(struct KeyBlock *kb, struct Lattice *lt);
void latt_to_key(struct Lattice *lt, struct KeyBlock *kb);
void key_to_curve(struct KeyBlock *kb, struct Curve *cu, struct ListBase *nurb);
void curve_to_key(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb);
+float (*key_to_vertcos(struct Object *ob, struct KeyBlock *kb))[3];
+void vertcos_to_key(struct Object *ob, struct KeyBlock *kb, float (*vertCos)[3]);
#ifdef __cplusplus
};
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 81fb724b3a5..cd412ca5a74 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -70,7 +70,7 @@ typedef struct SculptSession {
int totvert, totface;
float *face_normals;
struct Object *ob;
- struct KeyBlock *kb, *refkb;
+ struct KeyBlock *kb;
/* Mesh connectivity */
struct ListBase *fmap;
@@ -94,6 +94,8 @@ typedef struct SculptSession {
struct StrokeCache *cache;
struct GPUDrawObject *drawobject;
+
+ int modifiers_active;
} SculptSession;
void free_sculptsession(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 80f39531b34..9612dac2ac4 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -186,6 +186,16 @@ static ListBase *cdDM_getFaceMap(Object *ob, DerivedMesh *dm)
return cddm->fmap;
}
+static int can_pbvh_draw(Object *ob, DerivedMesh *dm)
+{
+ CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+ Mesh *me= (ob)? ob->data: NULL;
+
+ if(ob->sculpt->modifiers_active) return 0;
+
+ return (cddm->mvert == me->mvert) || ob->sculpt->kb;
+}
+
static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
{
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -200,7 +210,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
return NULL;
if(ob->sculpt->pbvh) {
cddm->pbvh= ob->sculpt->pbvh;
- cddm->pbvh_draw = (cddm->mvert == me->mvert) || ob->sculpt->kb;
+ cddm->pbvh_draw = can_pbvh_draw(ob, dm);
}
/* always build pbvh from original mesh, and only use it for drawing if
@@ -208,7 +218,7 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
that this is actually for, to support a pbvh on a modified mesh */
if(!cddm->pbvh && ob->type == OB_MESH) {
cddm->pbvh = BLI_pbvh_new();
- cddm->pbvh_draw = (cddm->mvert == me->mvert) || ob->sculpt->kb;
+ cddm->pbvh_draw = can_pbvh_draw(ob, dm);
BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert,
me->totface, me->totvert);
}
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index bdeacdf6946..4be5cce38a8 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -2286,9 +2286,6 @@ void DAG_id_flush_update(ID *id, short flag)
/* no point in trying in this cases */
if(!id || id->us <= 1)
id= NULL;
- /* for locked shape keys we make an exception */
- else if(ob_get_key(ob) && (ob->shapeflag & OB_SHAPE_LOCK))
- id= NULL;
}
}
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index f604d307551..84484417f42 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -38,6 +38,7 @@
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
+#include "BLI_math_vector.h"
#include "DNA_anim_types.h"
#include "DNA_key_types.h"
@@ -1719,3 +1720,151 @@ void key_to_mesh(KeyBlock *kb, Mesh *me)
VECCOPY(mvert->co, fp);
}
}
+
+/************************* vert coords ************************/
+float (*key_to_vertcos(Object *ob, KeyBlock *kb))[3]
+{
+ float (*vertCos)[3], *co;
+ float *fp= kb->data;
+ int tot= 0, a;
+
+ /* Count of vertex coords in array */
+ if(ob->type == OB_MESH) {
+ Mesh *me= (Mesh*)ob->data;
+ tot= me->totvert;
+ } else if(ob->type == OB_LATTICE) {
+ Lattice *lt= (Lattice*)ob->data;
+ tot= lt->pntsu*lt->pntsv*lt->pntsw;
+ } else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ Curve *cu= (Curve*)ob->data;
+ tot= count_curveverts(&cu->nurb);
+ }
+
+ if (tot == 0) return NULL;
+
+ vertCos= MEM_callocN(tot*sizeof(*vertCos), "key_to_vertcos vertCos");
+
+ /* Copy coords to array */
+ co= (float*)vertCos;
+
+ if(ELEM(ob->type, OB_MESH, OB_LATTICE)) {
+ for (a= 0; a<tot; a++, fp+=3, co+=3) {
+ copy_v3_v3(co, fp);
+ }
+ } else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ Curve *cu= (Curve*)ob->data;
+ Nurb *nu= cu->nurb.first;
+ BezTriple *bezt;
+ BPoint *bp;
+
+ while (nu) {
+ if(nu->bezt) {
+ int i;
+ bezt= nu->bezt;
+ a= nu->pntsu;
+
+ while (a--) {
+ for (i= 0; i<3; i++) {
+ copy_v3_v3(co, fp);
+ fp+= 3; co+= 3;
+ }
+
+ fp+= 3; /* skip alphas */
+
+ bezt++;
+ }
+ }
+ else {
+ bp= nu->bp;
+ a= nu->pntsu*nu->pntsv;
+
+ while (a--) {
+ copy_v3_v3(co, fp);
+
+ fp+= 4;
+ co+= 3;
+
+ bp++;
+ }
+ }
+
+ nu= nu->next;
+ }
+ }
+
+ return vertCos;
+}
+
+void vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
+{
+ float *co= (float*)vertCos, *fp;
+ int tot= 0, a, elemsize;
+
+ if (kb->data) MEM_freeN(kb->data);
+
+ /* Count of vertex coords in array */
+ if(ob->type == OB_MESH) {
+ Mesh *me= (Mesh*)ob->data;
+ tot= me->totvert;
+ elemsize= me->key->elemsize;
+ } else if(ob->type == OB_LATTICE) {
+ Lattice *lt= (Lattice*)ob->data;
+ tot= lt->pntsu*lt->pntsv*lt->pntsw;
+ elemsize= lt->key->elemsize;
+ } else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ Curve *cu= (Curve*)ob->data;
+ elemsize= cu->key->elemsize;
+ tot= count_curveverts(&cu->nurb);
+ }
+
+ fp= kb->data= MEM_callocN(tot*elemsize, "key_to_vertcos vertCos");
+
+ if (tot == 0) return;
+
+ /* Copy coords to keyblock */
+
+ if(ELEM(ob->type, OB_MESH, OB_LATTICE)) {
+ for (a= 0; a<tot; a++, fp+=3, co+=3) {
+ copy_v3_v3(fp, co);
+ }
+ } else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
+ Curve *cu= (Curve*)ob->data;
+ Nurb *nu= cu->nurb.first;
+ BezTriple *bezt;
+ BPoint *bp;
+
+ while (nu) {
+ if(nu->bezt) {
+ int i;
+ bezt= nu->bezt;
+ a= nu->pntsu;
+
+ while (a--) {
+ for (i= 0; i<3; i++) {
+ copy_v3_v3(fp, co);
+ fp+= 3; co+= 3;
+ }
+
+ fp+= 3; /* skip alphas */
+
+ bezt++;
+ }
+ }
+ else {
+ bp= nu->bp;
+ a= nu->pntsu*nu->pntsv;
+
+ while (a--) {
+ copy_v3_v3(fp, co);
+
+ fp+= 4;
+ co+= 3;
+
+ bp++;
+ }
+ }
+
+ nu= nu->next;
+ }
+ }
+}