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>2018-08-22 17:56:52 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-08-22 17:59:00 +0300
commitcdaf5a108365708351dafe9a35ec9902b9cc867f (patch)
treea20b8f6aa0cd5867ec7f25f000d89823402badbd /source/blender/blenkernel/intern/multires_reshape.c
parent564a378bd1f43b8d9e78b00675fee27fb98bbc7d (diff)
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.
Diffstat (limited to 'source/blender/blenkernel/intern/multires_reshape.c')
-rw-r--r--source/blender/blenkernel/intern/multires_reshape.c70
1 files changed, 50 insertions, 20 deletions
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(