[Bf-blender-cvs] [cdaf5a10836] blender2.8: Multires: Bring back operator to reshape from object

Sergey Sharybin noreply at git.blender.org
Wed Aug 22 16:59:09 CEST 2018


Commit: cdaf5a108365708351dafe9a35ec9902b9cc867f
Author: Sergey Sharybin
Date:   Wed Aug 22 16:56:52 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBcdaf5a108365708351dafe9a35ec9902b9cc867f

Multires: Bring back operator to reshape from object

Limited to mesh type of source, not sure it ever worked for non-meshes.
While it's possible to support reshape from any object, the actual brain
of operation would need to be recoded to go away from requirement of
vertex indices matching in source and destination.

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

M	source/blender/blenkernel/intern/multires_reshape.c

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

diff --git a/source/blender/blenkernel/intern/multires_reshape.c b/source/blender/blenkernel/intern/multires_reshape.c
index f0d97e71a88..c890951f378 100644
--- a/source/blender/blenkernel/intern/multires_reshape.c
+++ b/source/blender/blenkernel/intern/multires_reshape.c
@@ -406,6 +406,22 @@ static bool multires_reshape_from_vertcos(struct Depsgraph *depsgraph,
 	return true;
 }
 
+static void multires_reshape_init_mmd(MultiresModifierData *reshape_mmd,
+                                      const MultiresModifierData *mmd)
+{
+	/* It is possible that the current subdivision level of multires is lower
+	 * that it's maximum possible one (i.e., viewport is set to a lower level
+	 * for the performance purposes). But even then, we want all the multires
+	 * levels to be reshaped. Most accurate way to do so is to ignore all
+	 * simplifications and calculate deformation modifier for the highest
+	 * possible multires level.
+	 * Alternative would be propagate displacement from current level to a
+	 * higher ones, but that is likely to cause artifacts.
+	 */
+	*reshape_mmd = *mmd;
+	reshape_mmd->lvl = reshape_mmd->totlvl;
+}
+
 /* =============================================================================
  * Public entry points..
  */
@@ -416,15 +432,37 @@ static bool multires_reshape_from_vertcos(struct Depsgraph *depsgraph,
  * matched amount of vertices.
  */
 bool multiresModifier_reshape(
-        struct Depsgraph *UNUSED(depsgraph),
-        MultiresModifierData *UNUSED(mmd),
-        Object *UNUSED(dst),
-        Object *UNUSED(src))
+        struct Depsgraph *depsgraph,
+        MultiresModifierData *mmd,
+        Object *dst,
+        Object *src)
 {
-	/* TODO(sergey): Need to port to a new rehape routines. Old ones were
-	 * based on DerivedMesh and can not used anymore.
+	/* Would be cool to support this eventually, but it is very tricky to match
+	 * vertices order even for meshes, when mixing meshes and other objects it's
+	 * even more tricky.
 	 */
-	return false;
+	if (src->type != OB_MESH) {
+		return false;
+	}
+	MultiresModifierData highest_mmd;
+	multires_reshape_init_mmd(&highest_mmd, mmd);
+	/* Get evaluated vertices locations to reshape to. */
+	Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+	Object *src_eval = DEG_get_evaluated_object(depsgraph, src);
+	Mesh *src_mesh_eval = mesh_get_eval_final(
+	        depsgraph, scene_eval, src_eval, CD_MASK_BAREMESH);
+	int num_deformed_verts;
+	float (*deformed_verts)[3] = BKE_mesh_vertexCos_get(
+	        src_mesh_eval, &num_deformed_verts);
+	bool result = multires_reshape_from_vertcos(
+	        depsgraph,
+	        dst,
+	        &highest_mmd,
+	        deformed_verts,
+	        num_deformed_verts,
+	        false);
+	MEM_freeN(deformed_verts);
+	return result;
 }
 
 bool multiresModifier_reshapeFromDeformModifier(
@@ -433,17 +471,8 @@ bool multiresModifier_reshapeFromDeformModifier(
         Object *object,
         ModifierData *md)
 {
-	/* It is possible that the current subdivision level of multires is lower
-	 * that it's maximum possible one (i.e., viewport is set to a lower level
-	 * for the performance purposes). But even then, we want all the multires
-	 * levels to be reshaped. Most accurate way to do so is to ignore all
-	 * simplifications and calculate deformation modifier for the highest
-	 * possible multires level.
-	 * Alternative would be propagate displacement from current level to a
-	 * higher ones, but that is likely to cause artifacts.
-	 */
-	MultiresModifierData highest_mmd = *mmd;
-	highest_mmd.lvl = highest_mmd.totlvl;
+	MultiresModifierData highest_mmd;
+	multires_reshape_init_mmd(&highest_mmd, mmd);
 	Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
 	/* Perform sanity checks and early output. */
 	if (multires_get_level(
@@ -455,7 +484,9 @@ bool multiresModifier_reshapeFromDeformModifier(
 	 */
 	Mesh *multires_mesh = get_multires_mesh(
 	        depsgraph, scene_eval, &highest_mmd, object);
-	float (*deformed_verts)[3] = BKE_mesh_vertexCos_get(multires_mesh, NULL);
+	int num_deformed_verts;
+	float (*deformed_verts)[3] = BKE_mesh_vertexCos_get(
+	        multires_mesh, &num_deformed_verts);
 	/* Apply deformation modifier on the multires, */
 	const ModifierEvalContext modifier_ctx = {
 	        .depsgraph = depsgraph,
@@ -464,7 +495,6 @@ bool multiresModifier_reshapeFromDeformModifier(
 	modifier_deformVerts_ensure_normals(
 	        md, &modifier_ctx, multires_mesh, deformed_verts,
 	        multires_mesh->totvert);
-	const int num_deformed_verts = multires_mesh->totvert;
 	BKE_id_free(NULL, multires_mesh);
 	/* Reshaping */
 	bool result = multires_reshape_from_vertcos(



More information about the Bf-blender-cvs mailing list