Geometry Nodes: add simulation support #104924

Closed
Hans Goudey wants to merge 211 commits from geometry-nodes-simulation into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 22 additions and 21 deletions
Showing only changes of commit 20cab8f8f2 - Show all commits

View File

@ -694,7 +694,8 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
Object *ob_eval,
ModifierData *md_eval,
const bool use_virtual_modifiers,
const bool build_shapekey_layers)
const bool build_shapekey_layers,
ReportList *reports)
{
Mesh *me = ob_eval->runtime.data_orig ? reinterpret_cast<Mesh *>(ob_eval->runtime.data_orig) :
reinterpret_cast<Mesh *>(ob_eval->data);
@ -766,9 +767,21 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
add_shapekey_layers(*mesh_temp, *me);
}
result = mti->modifyMesh(md_eval, &mectx, mesh_temp);
if (mesh_temp != result) {
BKE_id_free(nullptr, mesh_temp);
if (mti->modifyGeometrySet) {
GeometrySet geometry_set = GeometrySet::create_with_mesh(mesh_temp,
GeometryOwnershipType::Owned);
mti->modifyGeometrySet(md_eval, &mectx, &geometry_set);
if (!geometry_set.has_mesh()) {
BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain a mesh");
return nullptr;
}
result = geometry_set.get_component_for_write<MeshComponent>().release();
}
else {
result = mti->modifyMesh(md_eval, &mectx, mesh_temp);
if (mesh_temp != result) {
BKE_id_free(nullptr, mesh_temp);
}
}
}
@ -817,7 +830,8 @@ static bool modifier_apply_shape(Main *bmain,
DEG_get_evaluated_object(depsgraph, ob),
md_eval,
true,
false);
false,
reports);
if (!mesh_applied) {
BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
return false;
@ -883,9 +897,9 @@ static bool modifier_apply_obdata(
/* It's important not to apply virtual modifiers (e.g. shape-keys) because they're kept,
* causing them to be applied twice, see: T97758. */
false,
true);
true,
reports);
if (!mesh_applied) {
BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply");
return false;
}

View File

@ -1365,19 +1365,6 @@ static void modifyGeometry(ModifierData *md,
}
}
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
GeometrySet geometry_set = GeometrySet::create_with_mesh(mesh, GeometryOwnershipType::Editable);
modifyGeometry(md, ctx, geometry_set);
Mesh *new_mesh = geometry_set.get_component_for_write<MeshComponent>().release();
if (new_mesh == nullptr) {
return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
}
return new_mesh;
}
static void modifyGeometrySet(ModifierData *md,
const ModifierEvalContext *ctx,
GeometrySet *geometry_set)
@ -1948,7 +1935,7 @@ ModifierTypeInfo modifierType_Nodes = {
/* deformMatrices */ nullptr,
/* deformVertsEM */ nullptr,
/* deformMatricesEM */ nullptr,
/* modifyMesh */ modifyMesh,
/* modifyMesh */ nullptr,
/* modifyGeometrySet */ modifyGeometrySet,
/* initData */ initData,