Page MenuHome

Regression: Converting a curve to mesh does not take the use of a bevel object into account when you have Keep Original checked in the Redo Panel.
Closed, ResolvedPublic

Description

System Information
Operating system: Windows-10-10.0.18362 64 Bits
Graphics card: GeForce GTX 960M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.86

Blender Version
Broken: version: 2.80 (sub 72), branch: blender2.7, commit date: 2019-05-29 18:17, hash: rBfee600f47980
Worked: version 2.79

Short description of error
EDIT: Converting a curve to mesh does not take the use of a bevel object into account, when you have Keep Original checked in the Redo Panel.

Exact steps for others to reproduce the error

  1. Create two curves
  2. Use one as the "path" curve and the other as the "bevel object" in Properties editor -> Object Data tab -> Geometry -> Bevel -> Object field
  3. EDIT: Select the "path" curve and convert it to mesh via Object -> Convert to -> Mesh from Curve/Meta/Surf/Text and check Keep Original.

Results in the "path" curve being converted to mesh, not the generated mesh from using the "bevel object" as it happens in version 2.79.bold text

Event Timeline

Matej Junk (MJunk) renamed this task from Regression: Converting a curve to the mesh does not take the use of a bevel object into account. to Regression: Converting a curve to mesh does not take the use of a bevel object into account..May 30 2019, 10:11 AM
Matej Junk (MJunk) created this task.

I tested it and it worked as expected. Here's a test file:


EDIT: When "Keep original" is selected it indeed converts to mesh ignoring the bevelling.

Matej Junk (MJunk) renamed this task from Regression: Converting a curve to mesh does not take the use of a bevel object into account. to Regression: Converting a curve to mesh does not take the use of a bevel object into account when you have Keep Original checked in the Redo Panel..May 30 2019, 11:11 AM
Matej Junk (MJunk) updated the task description. (Show Details)

I tested it and it worked as expected. Here's a test file:

You are right it works as expected unless you have Keep Original checked in the Redo Panel - I updated the description.

Thanks.

Bastien Montagne (mont29) lowered the priority of this task from Needs Triage by Developer to Confirmed, High.

Lost a lot of time in muddy waters here, think that first patch *should* be valid anyway (makes no sense without it really to take care of bevel/taper objects at all in curve_to_mesh_eval_ensure()?):

1diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
2index dd36da44b92..2d6924e436d 100644
3--- a/source/blender/blenkernel/intern/mesh_convert.c
4+++ b/source/blender/blenkernel/intern/mesh_convert.c
5@@ -981,16 +981,30 @@ static void curve_to_mesh_eval_ensure(Object *object)
6 Object bevel_object = {NULL};
7 if (remapped_curve.bevobj != NULL) {
8 bevel_object = *remapped_curve.bevobj;
9+ bevel_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
10 BLI_listbase_clear(&bevel_object.modifiers);
11 remapped_curve.bevobj = &bevel_object;
12+ BKE_displist_make_curveTypes_forRender(NULL,
13+ NULL,
14+ &bevel_object,
15+ &bevel_object.runtime.curve_cache->disp,
16+ &bevel_object.runtime.mesh_eval,
17+ false);
18 }
19
20 /* Same thing for taper. */
21 Object taper_object = {NULL};
22 if (remapped_curve.taperobj != NULL) {
23 taper_object = *remapped_curve.taperobj;
24+ taper_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
25 BLI_listbase_clear(&taper_object.modifiers);
26 remapped_curve.taperobj = &taper_object;
27+ BKE_displist_make_curveTypes_forRender(NULL,
28+ NULL,
29+ &taper_object,
30+ &taper_object.runtime.curve_cache->disp,
31+ &taper_object.runtime.mesh_eval,
32+ false);
33 }
34
35 /* NOTE: We don't have dependency graph or scene here, so we pass NULL. This is all fine since
36@@ -1017,6 +1031,10 @@ static void curve_to_mesh_eval_ensure(Object *object)
37
38 BKE_object_free_curve_cache(&bevel_object);
39 BKE_object_free_curve_cache(&taper_object);
40+
41+ /* We need to give back evaluated result to source object, otherwise whole function is useless.
42+ */
43+ object->runtime = remapped_object.runtime;
44 }
45
46 static Mesh *mesh_new_from_curve_type_object(Object *object)

However, even though the one above partially solves reported issue, there are other similar cases that it cannot address, especially when curve has some modifiers, those are totally lost, when you keep original.

The root of the issue is that convert operator expects to work on fully evaluated data, it even has a call at its start to ensure that. But when keeping original objects, we are actually working on (converting) copies of the objects, which have no runtime data at all! Following patch is a very brute force approach to solve it, it is working and presumably safe-ish, but very inefficient:

1diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
2index 2881163574b..b539ffd5e43 100644
3--- a/source/blender/editors/object/object_add.c
4+++ b/source/blender/editors/object/object_add.c
5@@ -2009,7 +2009,7 @@ static bool convert_poll(bContext *C)
6
7 /* Helper for convert_exec */
8 static Base *duplibase_for_convert(
9- Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
10+ Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
11 {
12 Object *obn;
13 Base *basen;
14@@ -2019,12 +2019,19 @@ static Base *duplibase_for_convert(
15 }
16
17 obn = BKE_object_copy(bmain, ob);
18- DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
19+ DEG_id_tag_update(&obn->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
20 BKE_collection_object_add_from(bmain, scene, ob, obn);
21
22 basen = BKE_view_layer_base_find(view_layer, obn);
23 ED_object_base_select(basen, BA_SELECT);
24 ED_object_base_select(base, BA_DESELECT);
25+
26+ DEG_graph_tag_relations_update(depsgraph);
27+ CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
28+ CustomData_MeshMasks_update(&scene->customdata_mask, &CD_MASK_MESH);
29+ BKE_scene_graph_update_tagged(depsgraph, bmain);
30+ scene->customdata_mask = customdata_mask_prev;
31+
32 return basen;
33 }
34
35@@ -2131,7 +2138,7 @@ static int convert_exec(bContext *C, wmOperator *op)
36 ob->flag |= OB_DONE;
37
38 if (keep_original) {
39- basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
40+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
41 newob = basen->object;
42
43 /* decrement original mesh's usage count */
44@@ -2156,7 +2163,7 @@ static int convert_exec(bContext *C, wmOperator *op)
45 ob->flag |= OB_DONE;
46
47 if (keep_original) {
48- basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
49+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
50 newob = basen->object;
51
52 /* decrement original mesh's usage count */
53@@ -2186,7 +2193,7 @@ static int convert_exec(bContext *C, wmOperator *op)
54 ob->flag |= OB_DONE;
55
56 if (keep_original) {
57- basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
58+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
59 newob = basen->object;
60
61 /* decrement original curve's usage count */
62@@ -2261,7 +2268,7 @@ static int convert_exec(bContext *C, wmOperator *op)
63
64 if (target == OB_MESH) {
65 if (keep_original) {
66- basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
67+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
68 newob = basen->object;
69
70 /* decrement original curve's usage count */
71@@ -2296,7 +2303,7 @@ static int convert_exec(bContext *C, wmOperator *op)
72 if (!(baseob->flag & OB_DONE)) {
73 baseob->flag |= OB_DONE;
74
75- basen = duplibase_for_convert(bmain, scene, view_layer, base, baseob);
76+ basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, baseob);
77 newob = basen->object;
78
79 mb = newob->data;

It is certainly possible to refactor the infamous convert_exec() to do a first loop and duplicate objects it needs to, then do a single deg update, then perform actual conversion, but, besides this being more risky (code there is not exactly straightforward), I’d rather first get agreement that this is the way to go…

@Sergey Sharybin (sergey) another nice can of worms for you to chime in. ;)

@Bastien Montagne (mont29), don't think i have much to add, unfortunately.

Don't do P1001, the indirect dependencies might not be ready yet. While this might not be a problem here, it will backfire sooner than later. This function is supposed to be called from a fully evaluated state, violation of that is on shoulders of a caller.

I like the idea of separating duplication and conversion, but indeed this could be tricky.
Think is all boiling down to how much overflowing your task list is. I can not think of a simpler fix here, or a fix which has less runtime penalty, and i can live with P1000 for the time being.

P.S. In the ideal world we also wouldn't modify scene's mask and only tag specific objects, to avoid too much re-evaluation, and heavy layers like vertex weights being permanently on all objects after Convert operator. But think your patch doesn't change this, this operator already leaves all the extra layers after its done?

@Sergey Sharybin (sergey) thanks, I’ll just go with P1000 then, yes. Besides time considerations, refactoring more convert to is not to be done now, we are too close to 2.80, and would rather solve issues rather than creating new ones! :P

Regarding leaving mesh in 'heavy' state, yes, that’s already the case, operator does not do any cleanup (it just restores scene's data layers mask to orig value, so I guess we'd need to re-run full depsgraph eval once more time to 'clean' things, anyway?).

I guess we'd need to re-run full depsgraph eval once more time to 'clean' things, anyway?).

Wouldn't work. Modifier stack evaluation does "inclusive" type of a check, not the equality. As in, it checks if there are any missing custom data layers. If all the layers are there nothing will happen.

The only way to force all custom data layers to be gone is to clear evaluated state of all objects and then re-run entire evaluation. This is very heavy.

With some support from dependency graph to do more grained masks adjustments this becomes less heavy, and i think we have all the bits internally. Just matter of exposing some APIs.