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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-09-16 11:45:49 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-09-23 17:27:23 +0300
commita168c3d282083bb4c02078bbd374f5554eeddce3 (patch)
tree291f6e0a64b09066985013a65abbecfcd96c774c /source/blender/blenkernel/intern
parent69ad44d5b48aa0d2cf00ff6c37be01f7384afe3b (diff)
Modifiers: every modifier now copies mesh settings, fixing texture space issues
Modifier stack evaluation would copy mesh settings other than mesh topology automatically, outside of the individual modifier evaluation. This leads to hard to understand code, and makes it unclear which settings are available in following modifiers, and which only after the entire stack is evaluated. Now every modifier is responsible to ensure the mesh it outputs preserves materials, texture space and other settings, or alters them as needed. Fixes T64739: incorrect texture space for various modifiers Differential Revision: https://developer.blender.org/D5808
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c50
-rw-r--r--source/blender/blenkernel/intern/crazyspace.c6
-rw-r--r--source/blender/blenkernel/intern/mesh.c46
-rw-r--r--source/blender/blenkernel/intern/smoke.c10
4 files changed, 55 insertions, 57 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 010e162f49d..4849d631493 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -729,7 +729,7 @@ static Mesh *create_orco_mesh(Object *ob, Mesh *me, BMEditMesh *em, int layer)
int free;
if (em) {
- mesh = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, NULL);
+ mesh = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, NULL, me);
}
else {
mesh = BKE_mesh_copy_for_eval(me, true);
@@ -797,14 +797,6 @@ static void editmesh_update_statvis_color(const Scene *scene, Object *ob)
BKE_editmesh_statvis_calc(em, me->runtime.edit_data, &scene->toolsettings->statvis);
}
-static void mesh_copy_autosmooth(Mesh *me, Mesh *me_orig)
-{
- if (me_orig->flag & ME_AUTOSMOOTH) {
- me->flag |= ME_AUTOSMOOTH;
- me->smoothresh = me_orig->smoothresh;
- }
-}
-
static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
const CustomData_MeshMasks *final_datamask,
const bool sculpt_dyntopo,
@@ -881,18 +873,8 @@ static void mesh_calc_finalize(const Mesh *mesh_input, Mesh *mesh_eval)
/* Make sure the name is the same. This is because mesh allocation from template does not
* take care of naming. */
BLI_strncpy(mesh_eval->id.name, mesh_input->id.name, sizeof(mesh_eval->id.name));
- /* Make sure materials are preserved from the input. */
- if (mesh_eval->mat != NULL) {
- MEM_freeN(mesh_eval->mat);
- }
- mesh_eval->mat = MEM_dupallocN(mesh_input->mat);
- mesh_eval->totcol = mesh_input->totcol;
/* Make evaluated mesh to share same edit mesh pointer as original and copied meshes. */
mesh_eval->edit_mesh = mesh_input->edit_mesh;
- /* Copy auth-smooth settings which are also not taken care about by mesh allocation from a
- * template. */
- mesh_eval->flag |= (mesh_input->flag & ME_AUTOSMOOTH);
- mesh_eval->smoothresh = mesh_input->smoothresh;
}
static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
@@ -1220,8 +1202,6 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
MEM_freeN(deformed_verts);
deformed_verts = NULL;
}
-
- mesh_copy_autosmooth(mesh_final, mesh_input);
}
/* create an orco mesh in parallel */
@@ -1533,8 +1513,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
/* Evaluate modifiers up to certain index to get the mesh cage. */
int cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
if (r_cage && cageIndex == -1) {
- mesh_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(em_input, &final_datamask, NULL);
- mesh_copy_autosmooth(mesh_cage, mesh_input);
+ mesh_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(
+ em_input, &final_datamask, NULL, mesh_input);
}
/* Clear errors before evaluation. */
@@ -1574,9 +1554,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
}
else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
if (mesh_final == NULL) {
- mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, NULL);
+ mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, NULL, mesh_input);
ASSERT_IS_VALID_MESH(mesh_final);
- mesh_copy_autosmooth(mesh_final, mesh_input);
}
BLI_assert(deformed_verts != NULL);
BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
@@ -1607,11 +1586,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
}
}
else {
- mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, NULL);
+ mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, NULL, mesh_input);
ASSERT_IS_VALID_MESH(mesh_final);
- mesh_copy_autosmooth(mesh_final, mesh_input);
-
if (deformed_verts) {
BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
}
@@ -1674,8 +1651,6 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
MEM_freeN(deformed_verts);
deformed_verts = NULL;
}
-
- mesh_copy_autosmooth(mesh_final, mesh_input);
}
mesh_final->runtime.deformed_only = false;
}
@@ -1695,8 +1670,10 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
me_orig->runtime.edit_data->vertexCos = MEM_dupallocN(deformed_verts);
}
mesh_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(
- em_input, &final_datamask, deformed_verts ? MEM_dupallocN(deformed_verts) : NULL);
- mesh_copy_autosmooth(mesh_cage, mesh_input);
+ em_input,
+ &final_datamask,
+ deformed_verts ? MEM_dupallocN(deformed_verts) : NULL,
+ mesh_input);
}
}
@@ -1730,11 +1707,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
else {
/* this is just a copy of the editmesh, no need to calc normals */
mesh_final = BKE_mesh_from_editmesh_with_coords_thin_wrap(
- em_input, &final_datamask, deformed_verts);
+ em_input, &final_datamask, deformed_verts, mesh_input);
deformed_verts = NULL;
- mesh_copy_autosmooth(mesh_final, mesh_input);
-
/* In this case, we should never have weight-modifying modifiers in stack... */
if (do_init_statvis) {
editmesh_update_statvis_color(scene, ob);
@@ -1854,11 +1829,6 @@ static void mesh_build_data(struct Depsgraph *depsgraph,
&ob->runtime.mesh_eval);
BKE_object_boundbox_calc_from_mesh(ob, ob->runtime.mesh_eval);
- /* Only copy texspace from orig mesh if some modifier (hint: smoke sim, see T58492)
- * did not re-enable that flag (which always get disabled for eval mesh as a start). */
- if (!(ob->runtime.mesh_eval->texflag & ME_AUTOSPACE)) {
- BKE_mesh_texspace_copy_from_object(ob->runtime.mesh_eval, ob);
- }
assign_object_mesh_eval(ob);
diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
index af4bd5d2ebd..6740fc985e9 100644
--- a/source/blender/blenkernel/intern/crazyspace.c
+++ b/source/blender/blenkernel/intern/crazyspace.c
@@ -261,7 +261,8 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(struct Depsgraph *depsgra
float (**deformcos)[3])
{
ModifierData *md;
- Mesh *me;
+ Mesh *me_input = ob->data;
+ Mesh *me = NULL;
int i, a, numleft = 0, numVerts = 0;
int cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
float(*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
@@ -270,7 +271,6 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(struct Depsgraph *depsgra
modifiers_clearErrors(ob);
- me = NULL;
md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
/* compute the deformation matrices and coordinates for the first
@@ -292,7 +292,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(struct Depsgraph *depsgra
data_mask = datamasks->mask;
BLI_linklist_free((LinkNode *)datamasks, NULL);
- me = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, &data_mask, NULL);
+ me = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, &data_mask, NULL, me_input);
deformedVerts = editbmesh_vert_coords_alloc(em, &numVerts);
defmats = MEM_mallocN(sizeof(*defmats) * numVerts, "defmats");
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index a98fc414f31..05d6f2c5ddf 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -657,6 +657,30 @@ Mesh *BKE_mesh_new_nomain(
return mesh;
}
+/* Copy user editable settings that we want to preserve through the modifier stack
+ * or operations where a mesh with new topology is created based on another mesh. */
+void BKE_mesh_copy_settings(Mesh *me_dst, const Mesh *me_src)
+{
+ /* Copy general settings. */
+ me_dst->editflag = me_src->editflag;
+ me_dst->flag = me_src->flag;
+ me_dst->smoothresh = me_src->smoothresh;
+ me_dst->remesh_voxel_size = me_src->remesh_voxel_size;
+ me_dst->remesh_mode = me_src->remesh_mode;
+
+ /* Copy texture space. */
+ me_dst->texflag = me_src->texflag;
+ copy_v3_v3(me_dst->loc, me_src->loc);
+ copy_v3_v3(me_dst->size, me_src->size);
+
+ /* Copy materials. */
+ if (me_dst->mat != NULL) {
+ MEM_freeN(me_dst->mat);
+ }
+ me_dst->mat = MEM_dupallocN(me_src->mat);
+ me_dst->totcol = me_src->totcol;
+}
+
Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
int verts_len,
int edges_len,
@@ -670,7 +694,6 @@ Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL);
- me_dst->mat = MEM_dupallocN(me_src->mat);
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
me_dst->totvert = verts_len;
@@ -680,8 +703,7 @@ Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
me_dst->totpoly = polys_len;
me_dst->cd_flag = me_src->cd_flag;
- me_dst->editflag = me_src->editflag;
- me_dst->texflag = me_src->texflag;
+ BKE_mesh_copy_settings(me_dst, me_src);
CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_CALLOC, verts_len);
CustomData_copy(&me_src->edata, &me_dst->edata, mask.emask, CD_CALLOC, edges_len);
@@ -770,18 +792,24 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me,
});
}
-Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params)
+Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm,
+ const struct BMeshToMeshParams *params,
+ const Mesh *me_settings)
{
BLI_assert(params->calc_object_remap == false);
Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
BM_mesh_bm_to_me(NULL, bm, mesh, params);
+ BKE_mesh_copy_settings(mesh, me_settings);
return mesh;
}
-Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra)
+Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm,
+ const CustomData_MeshMasks *cd_mask_extra,
+ const Mesh *me_settings)
{
Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
BM_mesh_bm_to_me_for_eval(bm, mesh, cd_mask_extra);
+ BKE_mesh_copy_settings(mesh, me_settings);
return mesh;
}
@@ -790,9 +818,10 @@ Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks
*/
Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap(BMEditMesh *em,
const CustomData_MeshMasks *data_mask,
- float (*vertexCos)[3])
+ float (*vertexCos)[3],
+ const Mesh *me_settings)
{
- Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask);
+ Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask, me_settings);
/* Use editmesh directly where possible. */
me->runtime.is_original = true;
if (vertexCos) {
@@ -1916,9 +1945,6 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
{
DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh);
BKE_mesh_texspace_calc(mesh);
- /* Clear autospace flag in evaluated mesh, so that texspace does not get recomputed when bbox is
- * (e.g. after modifiers, etc.) */
- mesh->texflag &= ~ME_AUTOSPACE;
/* We are here because something did change in the mesh. This means we can not trust the existing
* evaluated mesh, and we don't know what parts of the mesh did change. So we simply delete the
* evaluated mesh and let objects to re-create it with updated settings. */
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 74873db179d..e6c414b92da 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3352,14 +3352,16 @@ struct Mesh *smokeModifier_do(
if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain &&
smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN && smd->domain->base_res[0]) {
result = createDomainGeometry(smd->domain, ob);
+ BKE_mesh_copy_settings(result, me);
}
else {
result = BKE_mesh_copy_for_eval(me, false);
}
- /* XXX This is really not a nice hack, but until root of the problem is understood,
- * this should be an acceptable workaround I think.
- * See T58492 for details on the issue. */
- result->texflag |= ME_AUTOSPACE;
+
+ /* Smoke simulation needs a texture space relative to the adaptive domain bounds, not the
+ * original mesh. So recompute it at this point in the modifier stack. See T58492. */
+ BKE_mesh_texspace_calc(result);
+
return result;
}