Page MenuHome

"convert to mesh from curve" fail if the curve has a bevel.
Closed, ResolvedPublic

Description

System Information
Operating system: Windows-7-6.1.7601-SP1 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 425.31

Blender Version
Broken: version: 2.80 (sub 72), branch: blender2.7, commit date: 2019-05-23 20:37, hash: rBb3f96da2e605
Worked: blender-2.80.0-git.2a9214eaaf04-windows64

Short description of error
"convert to mesh from curve" operator doesn't work properly if the curve has a bevel object

Exact steps for others to reproduce the error
open the attached file and try to convert the curve to a mesh.

thankyou


Event Timeline

Broken: 2019-05-22 08:33, rB85322737baec

Bastien Montagne (mont29) triaged this task as Confirmed, High priority.

Confirmed, again with that missing evaluated cache data issue:

BLI_assert failed: /home/i74700deb64/blender/__work__/src/source/blender/blenkernel/intern/curve.c:1770, BKE_curve_bevel_make(), at 'cu->bevobj->runtime.curve_cache != ((void *)0)'

@Sergey Sharybin (sergey) that is probably a consequence of your recent changes in that area of code? Feel free to reassign to me otherwise.

Quite sure it's caused 91ce3087aa7.

The real solution is:

  • Make it so BKE_mesh_from_nurbs() doesn't do any in-place modifications and treats all inputs as const.
  • Make "Mesh from Curve" operator to pass evaluated object to the BKE_mesh_from_nurbs().
  • Use the result mesh, assign it to object data do all the other remapping.
  • Profit.

Perhaps we could use the code from D4940: Depsgraph API: Allow preserving custom data layers to ensure all data layers are preserved, instead of using the evaluated one directly.

That would indeed be a better way to go, and, arguably, easier. Here is a proof-of-concept:

1diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
2index cb152cb4e49..39753e9b51f 100644
3--- a/source/blender/editors/object/object_add.c
4+++ b/source/blender/editors/object/object_add.c
5@@ -1970,14 +1970,15 @@ static void convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Objec
6 }
7 }
8
9-static void curvetomesh(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
10+static void curvetomesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
11 {
12- convert_ensure_curve_cache(depsgraph, scene, ob);
13- BKE_mesh_from_nurbs(bmain, ob); /* also does users */
14-
15- if (ob->type == OB_MESH) {
16- BKE_object_free_modifiers(ob, 0);
17- }
18+ Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
19+ Curve *curve = ob->data;
20+ Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, object_eval);
21+ ob->data = mesh;
22+ ob->type = OB_MESH;
23+ id_us_min(&curve->id);
24+ id_us_plus(&mesh->id);
25 }
26
27 static bool convert_poll(bContext *C)
28@@ -2233,7 +2234,7 @@ static int convert_exec(bContext *C, wmOperator *op)
29 BKE_curve_curve_dimension_update(cu);
30
31 if (target == OB_MESH) {
32- curvetomesh(bmain, depsgraph, scene, newob);
33+ curvetomesh(bmain, depsgraph, newob);
34
35 /* meshes doesn't use displist */
36 BKE_object_free_curve_cache(newob);
37@@ -2257,7 +2258,7 @@ static int convert_exec(bContext *C, wmOperator *op)
38 newob = ob;
39 }
40
41- curvetomesh(bmain, depsgraph, scene, newob);
42+ curvetomesh(bmain, depsgraph, newob);
43
44 /* meshes doesn't use displist */
45 BKE_object_free_curve_cache(newob);

Still need to figure out proper remapping of IDs.