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. #65295

Closed
opened 2019-05-30 10:11:41 +02:00 by Matej Junk · 14 comments

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: fee600f479
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

**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: `fee600f479` 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**
Author

Added subscriber: @mjunk

Added subscriber: @mjunk

#65658 was marked as duplicate of this issue

#65658 was marked as duplicate of this issue
Matej Junk changed title 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. 2019-05-30 10:13:37 +02:00

Added subscriber: @MarcinTwarowski

Added subscriber: @MarcinTwarowski

I tested it and it worked as expected. Here's a test file: curve_bevel_to_mesh.blend
EDIT: When "Keep original" is selected it indeed converts to mesh ignoring the bevelling.

I tested it and it worked as expected. Here's a test file: [curve_bevel_to_mesh.blend](https://archive.blender.org/developer/F7079658/curve_bevel_to_mesh.blend) EDIT: When "Keep original" is selected it indeed converts to mesh ignoring the bevelling.
Matej Junk changed title 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. 2019-05-30 11:11:21 +02:00
Author

In #65295#691259, @MarcinTwarowski wrote:
I tested it and it worked as expected. Here's a test file: curve_bevel_to_mesh.blend

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

Thanks.

> In #65295#691259, @MarcinTwarowski wrote: > I tested it and it worked as expected. Here's a test file: [curve_bevel_to_mesh.blend](https://archive.blender.org/developer/F7079658/curve_bevel_to_mesh.blend) You are right it works as expected unless you have Keep Original checked in the Redo Panel - I updated the description. Thanks.

I reported a related bug: #65301

I reported a related bug: #65301
Bastien Montagne self-assigned this 2019-06-09 21:03:48 +02:00

Added subscribers: @morphy76, @mont29, @tomjk

Added subscribers: @morphy76, @mont29, @tomjk

Added subscriber: @Sergey

Added subscriber: @Sergey

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()?):

P1001: (An Untitled Masterwork)

diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index dd36da44b92..2d6924e436d 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -981,16 +981,30 @@ static void curve_to_mesh_eval_ensure(Object *object)
   Object bevel_object = {NULL};
   if (remapped_curve.bevobj != NULL) {
     bevel_object = *remapped_curve.bevobj;
+    bevel_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
     BLI_listbase_clear(&bevel_object.modifiers);
     remapped_curve.bevobj = &bevel_object;
+    BKE_displist_make_curveTypes_forRender(NULL,
+                                           NULL,
+                                           &bevel_object,
+                                           &bevel_object.runtime.curve_cache->disp,
+                                           &bevel_object.runtime.mesh_eval,
+                                           false);
   }
 
   /* Same thing for taper. */
   Object taper_object = {NULL};
   if (remapped_curve.taperobj != NULL) {
     taper_object = *remapped_curve.taperobj;
+    taper_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
     BLI_listbase_clear(&taper_object.modifiers);
     remapped_curve.taperobj = &taper_object;
+    BKE_displist_make_curveTypes_forRender(NULL,
+                                           NULL,
+                                           &taper_object,
+                                           &taper_object.runtime.curve_cache->disp,
+                                           &taper_object.runtime.mesh_eval,
+                                           false);
   }
 
   /* NOTE: We don't have dependency graph or scene here, so we pass NULL. This is all fine since
@@ -1017,6 +1031,10 @@ static void curve_to_mesh_eval_ensure(Object *object)
 
   BKE_object_free_curve_cache(&bevel_object);
   BKE_object_free_curve_cache(&taper_object);
+
+  /* We need to give back evaluated result to source object, otherwise whole function is useless.
+   */
+  object->runtime = remapped_object.runtime;
 }
 
 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:

P1000: (An Untitled Masterwork)

diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 2881163574b..b539ffd5e43 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2009,7 +2009,7 @@ static bool convert_poll(bContext *C)
 
 /* Helper for convert_exec */
 static Base *duplibase_for_convert(
-    Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
+    Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
 {
   Object *obn;
   Base *basen;
@@ -2019,12 +2019,19 @@ static Base *duplibase_for_convert(
   }
 
   obn = BKE_object_copy(bmain, ob);
-  DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
+  DEG_id_tag_update(&obn->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
   BKE_collection_object_add_from(bmain, scene, ob, obn);
 
   basen = BKE_view_layer_base_find(view_layer, obn);
   ED_object_base_select(basen, BA_SELECT);
   ED_object_base_select(base, BA_DESELECT);
+
+  DEG_graph_tag_relations_update(depsgraph);
+  CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
+  CustomData_MeshMasks_update(&scene->customdata_mask, &CD_MASK_MESH);
+  BKE_scene_graph_update_tagged(depsgraph, bmain);
+  scene->customdata_mask = customdata_mask_prev;
+
   return basen;
 }
 
@@ -2131,7 +2138,7 @@ static int convert_exec(bContext *C, wmOperator *op)
       ob->flag |= OB_DONE;
 
       if (keep_original) {
-        basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
+        basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
         newob = basen->object;
 
         /* decrement original mesh's usage count  */
@@ -2156,7 +2163,7 @@ static int convert_exec(bContext *C, wmOperator *op)
       ob->flag |= OB_DONE;
 
       if (keep_original) {
-        basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
+        basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
         newob = basen->object;
 
         /* decrement original mesh's usage count  */
@@ -2186,7 +2193,7 @@ static int convert_exec(bContext *C, wmOperator *op)
       ob->flag |= OB_DONE;
 
       if (keep_original) {
-        basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
+        basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
         newob = basen->object;
 
         /* decrement original curve's usage count  */
@@ -2261,7 +2268,7 @@ static int convert_exec(bContext *C, wmOperator *op)
 
       if (target == OB_MESH) {
         if (keep_original) {
-          basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
+          basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
           newob = basen->object;
 
           /* decrement original curve's usage count  */
@@ -2296,7 +2303,7 @@ static int convert_exec(bContext *C, wmOperator *op)
       if (!(baseob->flag & OB_DONE)) {
         baseob->flag |= OB_DONE;
 
-        basen = duplibase_for_convert(bmain, scene, view_layer, base, baseob);
+        basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, baseob);
         newob = basen->object;
 
         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 another nice can of worms for you to chime in. ;)

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()`?): [P1001: (An Untitled Masterwork)](https://archive.blender.org/developer/P1001.txt) ``` diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index dd36da44b92..2d6924e436d 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -981,16 +981,30 @@ static void curve_to_mesh_eval_ensure(Object *object) Object bevel_object = {NULL}; if (remapped_curve.bevobj != NULL) { bevel_object = *remapped_curve.bevobj; + bevel_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); BLI_listbase_clear(&bevel_object.modifiers); remapped_curve.bevobj = &bevel_object; + BKE_displist_make_curveTypes_forRender(NULL, + NULL, + &bevel_object, + &bevel_object.runtime.curve_cache->disp, + &bevel_object.runtime.mesh_eval, + false); } /* Same thing for taper. */ Object taper_object = {NULL}; if (remapped_curve.taperobj != NULL) { taper_object = *remapped_curve.taperobj; + taper_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); BLI_listbase_clear(&taper_object.modifiers); remapped_curve.taperobj = &taper_object; + BKE_displist_make_curveTypes_forRender(NULL, + NULL, + &taper_object, + &taper_object.runtime.curve_cache->disp, + &taper_object.runtime.mesh_eval, + false); } /* NOTE: We don't have dependency graph or scene here, so we pass NULL. This is all fine since @@ -1017,6 +1031,10 @@ static void curve_to_mesh_eval_ensure(Object *object) BKE_object_free_curve_cache(&bevel_object); BKE_object_free_curve_cache(&taper_object); + + /* We need to give back evaluated result to source object, otherwise whole function is useless. + */ + object->runtime = remapped_object.runtime; } 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: [P1000: (An Untitled Masterwork)](https://archive.blender.org/developer/P1000.txt) ``` diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 2881163574b..b539ffd5e43 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -2009,7 +2009,7 @@ static bool convert_poll(bContext *C) /* Helper for convert_exec */ static Base *duplibase_for_convert( - Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob) + Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob) { Object *obn; Base *basen; @@ -2019,12 +2019,19 @@ static Base *duplibase_for_convert( } obn = BKE_object_copy(bmain, ob); - DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); + DEG_id_tag_update(&obn->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); BKE_collection_object_add_from(bmain, scene, ob, obn); basen = BKE_view_layer_base_find(view_layer, obn); ED_object_base_select(basen, BA_SELECT); ED_object_base_select(base, BA_DESELECT); + + DEG_graph_tag_relations_update(depsgraph); + CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask; + CustomData_MeshMasks_update(&scene->customdata_mask, &CD_MASK_MESH); + BKE_scene_graph_update_tagged(depsgraph, bmain); + scene->customdata_mask = customdata_mask_prev; + return basen; } @@ -2131,7 +2138,7 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL); + basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL); newob = basen->object; /* decrement original mesh's usage count */ @@ -2156,7 +2163,7 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL); + basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL); newob = basen->object; /* decrement original mesh's usage count */ @@ -2186,7 +2193,7 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL); + basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL); newob = basen->object; /* decrement original curve's usage count */ @@ -2261,7 +2268,7 @@ static int convert_exec(bContext *C, wmOperator *op) if (target == OB_MESH) { if (keep_original) { - basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL); + basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL); newob = basen->object; /* decrement original curve's usage count */ @@ -2296,7 +2303,7 @@ static int convert_exec(bContext *C, wmOperator *op) if (!(baseob->flag & OB_DONE)) { baseob->flag |= OB_DONE; - basen = duplibase_for_convert(bmain, scene, view_layer, base, baseob); + basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, baseob); newob = basen->object; 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 another nice can of worms for you to chime in. ;)

@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?

@mont29, don't think i have much to add, unfortunately. Don't do [P1001](https://archive.blender.org/developer/P1001.txt), 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](https://archive.blender.org/developer/P1000.txt) 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 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?).

@Sergey thanks, I’ll just go with [P1000](https://archive.blender.org/developer/P1000.txt) 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?).

This issue was referenced by 8aa87972ca

This issue was referenced by 8aa87972cac3c9c3c5439b68b62e25c3fd4c4919

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

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.

> 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.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#65295
No description provided.