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/intern/key.c
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/intern/key.c')
-rw-r--r--source/blender/blenkernel/intern/key.c149
1 files changed, 149 insertions, 0 deletions
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;
+ }
+ }
+}