[Bf-blender-cvs] [20f7aaf] master: Fix issue discovered while investigating T39950:

Antony Riakiotakis noreply at git.blender.org
Tue May 6 22:44:23 CEST 2014


Commit: 20f7aaf6be0dc186f6551761693133bb562a5be1
Author: Antony Riakiotakis
Date:   Tue May 6 23:30:51 2014 +0300
https://developer.blender.org/rB20f7aaf6be0dc186f6551761693133bb562a5be1

Fix issue discovered while investigating T39950:

Sculpt mode drawing fails after deleting a subsurf modifier
in sculpt mode and undoing.

This was quite difficult to spot. Main cause was that mesh data was not
synchronized properly between undo and sculpt code because we generated
a pbvh on derivedmesh invalidation without really refreshing the rest of
the data. This could result in undo and drawing operating on different
data.

To solve this and avoid bad level calls I had to move quite some code
around. Crazyspace is now moved to blenkernel, as did some sculpt calls
that make sure sculpt data are properly refreshed.

===================================================================

A	source/blender/blenkernel/BKE_crazyspace.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/DerivedMesh.c
A	source/blender/blenkernel/intern/crazyspace.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/include/ED_util.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/util/CMakeLists.txt
D	source/blender/editors/util/crazyspace.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_crazyspace.h b/source/blender/blenkernel/BKE_crazyspace.h
new file mode 100644
index 0000000..89cbd9e
--- /dev/null
+++ b/source/blender/blenkernel/BKE_crazyspace.h
@@ -0,0 +1,54 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BKE_crazyspace.h
+ *  \ingroup bke
+ */
+
+#ifndef __BKE_CRAZYSPACE_H__
+#define __BKE_CRAZYSPACE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct Scene;
+struct Object;
+struct BMEditMesh;
+struct Mesh;
+
+/* crazyspace.c */
+float (*crazyspace_get_mapped_editverts(struct Scene *scene, struct Object *obedit))[3];
+void crazyspace_set_quats_editmesh(struct BMEditMesh *em, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4],
+								   const bool use_select);
+void crazyspace_set_quats_mesh(struct Mesh *me, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4]);
+int sculpt_get_first_deform_matrices(struct Scene *scene, struct Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]);
+void crazyspace_build_sculpt(struct Scene *scene, struct Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index df72cb9..cb52138 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -47,6 +47,7 @@ struct Object;
 struct Paint;
 struct PBVH;
 struct Scene;
+struct Sculpt;
 struct StrokeCache;
 struct Tex;
 struct ImagePool;
@@ -176,4 +177,14 @@ void free_sculptsession(struct Object *ob);
 void free_sculptsession_deformMats(struct SculptSession *ss);
 void sculptsession_bm_to_me(struct Object *ob, bool reorder);
 void sculptsession_bm_to_me_for_render(struct Object *object);
+void sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct Object *ob,
+								 bool need_pmap, bool need_mask);
+struct MultiresModifierData *sculpt_multires_active(struct Scene *scene, struct Object *ob);
+int ED_sculpt_mask_layers_ensure(struct Object *ob,
+								  struct MultiresModifierData *mmd);
+
+enum {
+	ED_SCULPT_MASK_LAYER_CALC_VERT = (1 << 0),
+	ED_SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1)
+};
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 749a5eb..0caf7d1 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -78,7 +78,8 @@ set(SRC
 	intern/colortools.c
 	intern/constraint.c
 	intern/context.c
-	intern/curve.c
+        intern/crazyspace.c
+        intern/curve.c
 	intern/customdata.c
 	intern/customdata_file.c
 	intern/deform.c
@@ -191,6 +192,7 @@ set(SRC
 	BKE_colortools.h
 	BKE_constraint.h
 	BKE_context.h
+        BKE_crazyspace.h
 	BKE_curve.h
 	BKE_customdata.h
 	BKE_customdata_file.h
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 26cc70e..228f4ce 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2251,7 +2251,8 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
 	if ((ob->mode & OB_MODE_SCULPT) && ob->sculpt) {
 		/* create PBVH immediately (would be created on the fly too,
 		 * but this avoids waiting on first stroke) */
-		ob->sculpt->pbvh = ob->derivedFinal->getPBVH(ob, ob->derivedFinal);
+
+		sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, false, false);
 	}
 
 	BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS));
diff --git a/source/blender/editors/util/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
similarity index 99%
rename from source/blender/editors/util/crazyspace.c
rename to source/blender/blenkernel/intern/crazyspace.c
index b90cfad..610a0fe 100644
--- a/source/blender/editors/util/crazyspace.c
+++ b/source/blender/blenkernel/intern/crazyspace.c
@@ -25,8 +25,8 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/editors/util/crazyspace.c
- *  \ingroup edutil
+/** \file blender/blenkernel/intern/crazyspace.c
+ *  \ingroup bke
  */
 
 
@@ -42,14 +42,13 @@
 #include "BLI_math.h"
 #include "BLI_bitmap.h"
 
+#include "BKE_crazyspace.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_modifier.h"
 #include "BKE_multires.h"
 #include "BKE_mesh.h"
 #include "BKE_editmesh.h"
 
-#include "ED_util.h"
-
 typedef struct {
 	float (*vertexcos)[3];
 	BLI_bitmap *vertex_visit;
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 1189b57..d505956 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -37,6 +37,7 @@
 #include "DNA_object_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_space_types.h"
@@ -47,10 +48,14 @@
 
 #include "BKE_brush.h"
 #include "BKE_context.h"
+#include "BKE_crazyspace.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
+#include "BKE_key.h"
 #include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_pbvh.h"
@@ -499,3 +504,239 @@ void free_sculptsession(Object *ob)
 		ob->sculpt = NULL;
 	}
 }
+
+/* Sculpt mode handles multires differently from regular meshes, but only if
+ * it's the last modifier on the stack and it is not on the first level */
+MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob)
+{
+	Mesh *me = (Mesh *)ob->data;
+	ModifierData *md;
+	VirtualModifierData virtualModifierData;
+
+	if (ob->sculpt && ob->sculpt->bm) {
+		/* can't combine multires and dynamic topology */
+		return NULL;
+	}
+
+	if (!CustomData_get_layer(&me->ldata, CD_MDISPS)) {
+		/* multires can't work without displacement layer */
+		return NULL;
+	}
+
+	for (md = modifiers_getVirtualModifierList(ob, &virtualModifierData); md; md = md->next) {
+		if (md->type == eModifierType_Multires) {
+			MultiresModifierData *mmd = (MultiresModifierData *)md;
+
+			if (!modifier_isEnabled(scene, md, eModifierMode_Realtime))
+				continue;
+
+			if (mmd->sculptlvl > 0) return mmd;
+			else return NULL;
+		}
+	}
+
+	return NULL;
+}
+
+
+/* Checks if there are any supported deformation modifiers active */
+static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob)
+{
+	ModifierData *md;
+	Mesh *me = (Mesh *)ob->data;
+	MultiresModifierData *mmd = sculpt_multires_active(scene, ob);
+	VirtualModifierData virtualModifierData;
+
+	if (mmd || ob->sculpt->bm)
+		return 0;
+
+	/* non-locked shape keys could be handled in the same way as deformed mesh */
+	if ((ob->shapeflag & OB_SHAPE_LOCK) == 0 && me->key && ob->shapenr)
+		return 1;
+
+	md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
+
+	/* exception for shape keys because we can edit those */
+	for (; md; md = md->next) {
+		ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+		if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue;
+		if (md->type == eModifierType_ShapeKey) continue;
+
+		if (mti->type == eModifierTypeType_OnlyDeform) return 1;
+		else if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * \param need_mask So the DerivedMesh thats returned has mask data
+ */
+void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
+								 bool need_pmap, bool need_mask)
+{
+	DerivedMesh *dm;
+	SculptSession *ss = ob->sculpt;
+	Mesh *me = ob->data;
+	MultiresModifierData *mmd = sculpt_multires_active(scene, ob);
+
+	ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob);
+	ss->show_diffuse_color = (sd->flags & SCULPT_SHOW_DIFFUSE) != 0;
+
+	if (need_mask) {
+		if (mmd == NULL) {
+			if (!CustomData_has_layer(&me->vdata, CD_PAINT_MASK)) {
+				ED_sculpt_mask_layers_ensure(ob, NULL);
+			}
+		}
+		else {
+			if (!CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) {
+#if 1
+				ED_sculpt_mask_layers_ensure(ob, mmd);
+#else				/* if we wanted to support adding mask data while multi-res painting, we would need to do this */
+				if ((ED_sculpt_mask_layers_ensure(ob, mmd) & ED_SCULPT_MASK_LAYER_CALC_LOOP)) {
+					/* remake the derived mesh */
+					ob->recalc |= OB_RECALC_DATA;
+					BKE_object_handle_update(scene, ob);
+				}
+#endif
+			}
+		}
+	}
+
+	/* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */
+	BKE_mesh_tessface_ensure(me);
+
+	if (!mmd) ss->kb = BKE_keyblock_from_object(ob);
+	else ss->kb = NULL;
+
+	/* needs to be called after we ensure tessface */
+	dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+
+	if (mmd) {
+		ss->multires = mmd;
+		ss->totvert = dm->getNumVerts(dm);
+		ss->totpoly = dm->getNumPolys(dm);
+		ss->mvert = NULL;
+		ss->mpoly = NULL;
+		ss->mloop = NULL;
+		ss->face_normals = NULL;
+	}
+	else {
+		ss->totvert = me->totvert;
+		ss->totpoly = me->totpoly;
+		ss->mvert = me->mvert;
+		ss->mpoly = me->mpoly;
+		ss->mloop = me->mloop;
+		ss->face_normals = NULL;
+		ss->multires = NULL;
+		ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
+	}
+
+	ss->pbvh = dm->getPBVH(ob, dm);
+	ss->pmap = (need_pmap && dm->getPolyMap) ? dm->getPolyM

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list