From b39cd9a8490514e9fdcfb86b09f65b90200f6e97 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 7 Jul 2022 17:25:36 -0500 Subject: Test: Retrieve original mesh information from the editmesh --- .../nodes/node_geo_deform_curves_with_surface.cc | 39 +++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_with_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_with_surface.cc index 7557023aef7..353c93a53de 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_with_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_with_surface.cc @@ -2,6 +2,8 @@ #include "BKE_attribute_math.hh" #include "BKE_curves.hh" +#include "BKE_editmesh.h" +#include "BKE_lib_id.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" @@ -197,7 +199,15 @@ static void node_geo_exec(GeoNodeExecParams params) { GeometrySet curves_geometry = params.extract_input("Curves"); - auto pass_through_input = [&]() { params.set_output("Curves", std::move(curves_geometry)); }; + Mesh *surface_mesh_orig = nullptr; + bool free_suface_mesh_orig = false; + + auto pass_through_input = [&]() { + params.set_output("Curves", std::move(curves_geometry)); + if (free_suface_mesh_orig) { + BKE_id_free(nullptr, surface_mesh_orig); + } + }; const Object *self_ob_eval = params.self_object(); if (self_ob_eval == nullptr || self_ob_eval->type != OB_CURVES) { @@ -218,19 +228,28 @@ static void node_geo_exec(GeoNodeExecParams params) return; } Object *surface_ob_orig = DEG_get_original_object(surface_ob_eval); - Mesh &surface_mesh_orig = *static_cast(surface_ob_orig->data); + Mesh &surface_object_data = *static_cast(surface_ob_orig->data); + + if (BMEditMesh *em = surface_object_data.edit_mesh) { + surface_mesh_orig = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, NULL, &surface_object_data); + free_suface_mesh_orig = true; + } + else { + surface_mesh_orig = &surface_object_data; + } Mesh *surface_mesh_eval = BKE_modifier_get_evaluated_mesh_from_evaluated_object(surface_ob_eval, false); if (surface_mesh_eval == nullptr) { pass_through_input(); return; } + BKE_mesh_wrapper_ensure_mdata(surface_mesh_eval); MeshComponent mesh_eval; mesh_eval.replace(surface_mesh_eval, GeometryOwnershipType::ReadOnly); MeshComponent mesh_orig; - mesh_orig.replace(&surface_mesh_orig, GeometryOwnershipType::ReadOnly); + mesh_orig.replace(surface_mesh_orig, GeometryOwnershipType::ReadOnly); Curves &curves_id = *curves_geometry.get_curves_for_write(); CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry); @@ -259,8 +278,8 @@ static void node_geo_exec(GeoNodeExecParams params) rest_position_name, ATTR_DOMAIN_POINT, {0.0f, 0.0f, 0.0f}); const Span surface_uv_coords = curves.surface_uv_coords(); - const Span looptris_orig{BKE_mesh_runtime_looptri_ensure(&surface_mesh_orig), - BKE_mesh_runtime_looptri_len(&surface_mesh_orig)}; + const Span looptris_orig{BKE_mesh_runtime_looptri_ensure(surface_mesh_orig), + BKE_mesh_runtime_looptri_len(surface_mesh_orig)}; const Span looptris_eval{BKE_mesh_runtime_looptri_ensure(surface_mesh_eval), BKE_mesh_runtime_looptri_len(surface_mesh_eval)}; const ReverseUVSampler reverse_uv_sampler_orig{uv_map_orig, looptris_orig}; @@ -270,10 +289,10 @@ static void node_geo_exec(GeoNodeExecParams params) * because face normals or vertex normals may lose information (custom normals, auto smooth) in * some cases. It isn't yet possible to retrieve lazily calculated face corner normals from a * const mesh, so they are calculated here every time. */ - Array corner_normals_orig(surface_mesh_orig.totloop); + Array corner_normals_orig(surface_mesh_orig->totloop); Array corner_normals_eval(surface_mesh_eval->totloop); BKE_mesh_calc_normals_split_ex( - &surface_mesh_orig, nullptr, reinterpret_cast(corner_normals_orig.data())); + surface_mesh_orig, nullptr, reinterpret_cast(corner_normals_orig.data())); BKE_mesh_calc_normals_split_ex( surface_mesh_eval, nullptr, reinterpret_cast(corner_normals_eval.data())); @@ -282,7 +301,7 @@ static void node_geo_exec(GeoNodeExecParams params) const bke::CurvesSurfaceTransforms transforms{*self_ob_eval, surface_ob_eval}; deform_curves(curves, - surface_mesh_orig, + *surface_mesh_orig, *surface_mesh_eval, surface_uv_coords, reverse_uv_sampler_orig, @@ -303,6 +322,10 @@ static void node_geo_exec(GeoNodeExecParams params) MEM_freeN(error); } + if (free_suface_mesh_orig) { + BKE_id_free(nullptr, surface_mesh_orig); + } + params.set_output("Curves", curves_geometry); } -- cgit v1.2.3