Metaball: Evaluate metaball objects as mesh components

With the ultimate goal of simplifying drawing and evaluation,
this patch makes the following changes and removes code:
- Use `Mesh` instead of `DispList` for evaluated basis metaballs.
- Remove all `DispList` drawing code, which is now unused.
- Simplify code that converts evaluated metaballs to meshes.
- Store the evaluated mesh in the evaluated geometry set.

This has the following indirect benefits:
- Evaluated meshes from metaball objects can be used in geometry nodes.
- Renderers can ignore evaluated metaball objects completely
- Cycles rendering no longer has to convert to mesh from `DispList`.
- We get closer to removing `DispList` completely.
- Optimizations to mesh rendering will also apply to metaball objects.

The vertex normals on the evaluated mesh are technically invalid;
the regular calculation wouldn't reproduce them. Metaball objects
don't support modifiers though, so it shouldn't be a problem.
Eventually we can support per-vertex custom normals (T93551).

Differential Revision: https://developer.blender.org/D14593
This commit is contained in:
2022-08-17 10:20:25 -04:00
parent 71f091a631
commit eaa87101cd
35 changed files with 210 additions and 1193 deletions

View File

@@ -2771,25 +2771,6 @@ static const EnumPropertyItem convert_target_items[] = {
{0, nullptr, 0, nullptr, nullptr},
};
static void object_data_convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
if (ob->runtime.curve_cache == nullptr) {
/* Force creation. This is normally not needed but on operator
* redo we might end up with an object which isn't evaluated yet.
* Also happens in case we are working on a copy of the object
* (all its caches have been nuked then).
*/
if (ELEM(ob->type, OB_SURF, OB_CURVES_LEGACY, OB_FONT)) {
/* We need 'for render' ON here, to enable computing bevel #DispList if needed.
* Also makes sense anyway, we would not want e.g. to lose hidden parts etc. */
BKE_displist_make_curveTypes(depsgraph, scene, ob, true);
}
else if (ob->type == OB_MBALL) {
BKE_displist_make_mball(depsgraph, scene, ob);
}
}
}
static void object_data_convert_curve_to_mesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
{
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
@@ -2908,7 +2889,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
const bool use_faces = RNA_boolean_get(op->ptr, "faces");
const float offset = RNA_float_get(op->ptr, "offset");
int a, mballConverted = 0;
int mballConverted = 0;
bool gpencilConverted = false;
bool gpencilCurveConverted = false;
@@ -3332,22 +3313,14 @@ static int object_convert_exec(bContext *C, wmOperator *op)
MetaBall *mb = static_cast<MetaBall *>(newob->data);
id_us_min(&mb->id);
newob->data = BKE_mesh_add(bmain, "Mesh");
/* Find the evaluated mesh of the basis metaball object. */
Object *object_eval = DEG_get_evaluated_object(depsgraph, baseob);
Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, depsgraph, object_eval, true);
id_us_plus(&mesh->id);
newob->data = mesh;
newob->type = OB_MESH;
Mesh *me = static_cast<Mesh *>(newob->data);
me->totcol = mb->totcol;
if (newob->totcol) {
me->mat = static_cast<Material **>(MEM_dupallocN(mb->mat));
for (a = 0; a < newob->totcol; a++) {
id_us_plus((ID *)me->mat[a]);
}
}
object_data_convert_ensure_curve_cache(depsgraph, scene, baseob);
BKE_mesh_from_metaball(&baseob->runtime.curve_cache->disp,
static_cast<Mesh *>(newob->data));
if (obact->type == OB_MBALL) {
basact = basen;
}