Cleanup: Simplify replacing component data in geometry set
This commit is contained in:
parent
f37fa6d0b1
commit
ec29d96d11
|
@ -543,12 +543,10 @@ static Mesh *modifier_modify_mesh_and_geometry_set(ModifierData *md,
|
|||
* some point. */
|
||||
BKE_mesh_wrapper_ensure_mdata(input_mesh);
|
||||
|
||||
/* Adds a new mesh component to the geometry set based on the #input_mesh. */
|
||||
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
|
||||
/* Replace only the mesh rather than the whole component, because the entire #MeshComponent
|
||||
* might have been replaced by data from a different object in the node tree, which means the
|
||||
* component contains vertex group name data for that object that should not be removed. */
|
||||
mesh_component.replace(input_mesh, GeometryOwnershipType::Editable);
|
||||
geometry_set.replace_mesh(input_mesh, GeometryOwnershipType::Editable);
|
||||
|
||||
/* Let the modifier change the geometry set. */
|
||||
mti->modifyGeometrySet(md, &mectx, &geometry_set);
|
||||
|
|
|
@ -390,20 +390,14 @@ bool GeometrySet::is_empty() const
|
|||
GeometrySet GeometrySet::create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership)
|
||||
{
|
||||
GeometrySet geometry_set;
|
||||
if (mesh != nullptr) {
|
||||
MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>();
|
||||
component.replace(mesh, ownership);
|
||||
}
|
||||
geometry_set.replace_mesh(mesh, ownership);
|
||||
return geometry_set;
|
||||
}
|
||||
|
||||
GeometrySet GeometrySet::create_with_volume(Volume *volume, GeometryOwnershipType ownership)
|
||||
{
|
||||
GeometrySet geometry_set;
|
||||
if (volume != nullptr) {
|
||||
VolumeComponent &component = geometry_set.get_component_for_write<VolumeComponent>();
|
||||
component.replace(volume, ownership);
|
||||
}
|
||||
geometry_set.replace_volume(volume, ownership);
|
||||
return geometry_set;
|
||||
}
|
||||
|
||||
|
@ -411,20 +405,14 @@ GeometrySet GeometrySet::create_with_pointcloud(PointCloud *pointcloud,
|
|||
GeometryOwnershipType ownership)
|
||||
{
|
||||
GeometrySet geometry_set;
|
||||
if (pointcloud != nullptr) {
|
||||
PointCloudComponent &component = geometry_set.get_component_for_write<PointCloudComponent>();
|
||||
component.replace(pointcloud, ownership);
|
||||
}
|
||||
geometry_set.replace_pointcloud(pointcloud, ownership);
|
||||
return geometry_set;
|
||||
}
|
||||
|
||||
GeometrySet GeometrySet::create_with_curves(Curves *curves, GeometryOwnershipType ownership)
|
||||
{
|
||||
GeometrySet geometry_set;
|
||||
if (curves != nullptr) {
|
||||
CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>();
|
||||
component.replace(curves, ownership);
|
||||
}
|
||||
geometry_set.replace_curves(curves, ownership);
|
||||
return geometry_set;
|
||||
}
|
||||
|
||||
|
|
|
@ -1066,9 +1066,7 @@ static bool modifier_apply_obdata(
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Create a temporary geometry set and component. */
|
||||
bke::GeometrySet geometry_set;
|
||||
geometry_set.get_component_for_write<bke::CurveComponent>().replace(
|
||||
bke::GeometrySet geometry_set = bke::GeometrySet::create_with_curves(
|
||||
&curves, bke::GeometryOwnershipType::ReadOnly);
|
||||
|
||||
ModifierEvalContext mectx = {depsgraph, ob, ModifierApplyFlag(0)};
|
||||
|
@ -1079,10 +1077,9 @@ static bool modifier_apply_obdata(
|
|||
}
|
||||
Curves &curves_eval = *geometry_set.get_curves_for_write();
|
||||
|
||||
/* Anonymous attributes shouldn't be available on the applied geometry. */
|
||||
/* Anonymous attributes shouldn't be available on original geometry. */
|
||||
curves_eval.geometry.wrap().attributes_for_write().remove_anonymous();
|
||||
|
||||
/* Copy the relevant information to the original. */
|
||||
curves.geometry.wrap() = std::move(curves_eval.geometry.wrap());
|
||||
Main *bmain = DEG_get_bmain(depsgraph);
|
||||
BKE_object_material_from_eval_data(bmain, ob, &curves_eval.id);
|
||||
|
@ -1094,9 +1091,7 @@ static bool modifier_apply_obdata(
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Create a temporary geometry set and component. */
|
||||
bke::GeometrySet geometry_set;
|
||||
geometry_set.get_component_for_write<bke::PointCloudComponent>().replace(
|
||||
bke::GeometrySet geometry_set = bke::GeometrySet::create_with_pointcloud(
|
||||
&points, bke::GeometryOwnershipType::ReadOnly);
|
||||
|
||||
ModifierEvalContext mectx = {depsgraph, ob, ModifierApplyFlag(0)};
|
||||
|
@ -1109,10 +1104,9 @@ static bool modifier_apply_obdata(
|
|||
PointCloud *pointcloud_eval =
|
||||
geometry_set.get_component_for_write<bke::PointCloudComponent>().release();
|
||||
|
||||
/* Anonymous attributes shouldn't be available on the applied geometry. */
|
||||
/* Anonymous attributes shouldn't be available on original geometry. */
|
||||
pointcloud_eval->attributes_for_write().remove_anonymous();
|
||||
|
||||
/* Copy the relevant information to the original. */
|
||||
Main *bmain = DEG_get_bmain(depsgraph);
|
||||
BKE_object_material_from_eval_data(bmain, ob, &pointcloud_eval->id);
|
||||
BKE_pointcloud_nomain_to_pointcloud(pointcloud_eval, &points);
|
||||
|
|
|
@ -495,39 +495,32 @@ bke::GeometrySet spreadsheet_get_display_geometry_set(const SpaceSpreadsheet *ss
|
|||
{
|
||||
bke::GeometrySet geometry_set;
|
||||
if (sspreadsheet->object_eval_state == SPREADSHEET_OBJECT_EVAL_STATE_ORIGINAL) {
|
||||
Object *object_orig = DEG_get_original_object(object_eval);
|
||||
const Object *object_orig = DEG_get_original_object(object_eval);
|
||||
if (object_orig->type == OB_MESH) {
|
||||
bke::MeshComponent &mesh_component =
|
||||
geometry_set.get_component_for_write<bke::MeshComponent>();
|
||||
const Mesh *mesh = static_cast<const Mesh *>(object_orig->data);
|
||||
if (object_orig->mode == OB_MODE_EDIT) {
|
||||
Mesh *mesh = (Mesh *)object_orig->data;
|
||||
BMEditMesh *em = mesh->edit_mesh;
|
||||
if (em != nullptr) {
|
||||
if (const BMEditMesh *em = mesh->edit_mesh) {
|
||||
Mesh *new_mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
|
||||
/* This is a potentially heavy operation to do on every redraw. The best solution here is
|
||||
* to display the data directly from the bmesh without a conversion, which can be
|
||||
* implemented a bit later. */
|
||||
BM_mesh_bm_to_me_for_eval(em->bm, new_mesh, nullptr);
|
||||
mesh_component.replace(new_mesh, bke::GeometryOwnershipType::Owned);
|
||||
geometry_set.replace_mesh(new_mesh, bke::GeometryOwnershipType::Owned);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Mesh *mesh = (Mesh *)object_orig->data;
|
||||
mesh_component.replace(mesh, bke::GeometryOwnershipType::ReadOnly);
|
||||
geometry_set.replace_mesh(const_cast<Mesh *>(mesh), bke::GeometryOwnershipType::ReadOnly);
|
||||
}
|
||||
}
|
||||
else if (object_orig->type == OB_POINTCLOUD) {
|
||||
PointCloud *pointcloud = (PointCloud *)object_orig->data;
|
||||
bke::PointCloudComponent &pointcloud_component =
|
||||
geometry_set.get_component_for_write<bke::PointCloudComponent>();
|
||||
pointcloud_component.replace(pointcloud, bke::GeometryOwnershipType::ReadOnly);
|
||||
const PointCloud *pointcloud = static_cast<const PointCloud *>(object_orig->data);
|
||||
geometry_set.replace_pointcloud(const_cast<PointCloud *>(pointcloud),
|
||||
bke::GeometryOwnershipType::ReadOnly);
|
||||
}
|
||||
else if (object_orig->type == OB_CURVES) {
|
||||
const Curves &curves_id = *(const Curves *)object_orig->data;
|
||||
bke::CurveComponent &curve_component =
|
||||
geometry_set.get_component_for_write<bke::CurveComponent>();
|
||||
curve_component.replace(&const_cast<Curves &>(curves_id),
|
||||
bke::GeometryOwnershipType::ReadOnly);
|
||||
const Curves &curves_id = *static_cast<const Curves *>(object_orig->data);
|
||||
geometry_set.replace_curves(&const_cast<Curves &>(curves_id),
|
||||
bke::GeometryOwnershipType::ReadOnly);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -776,9 +776,7 @@ static void execute_realize_pointcloud_tasks(const RealizeInstancesOptions &opti
|
|||
|
||||
/* Allocate new point cloud. */
|
||||
PointCloud *dst_pointcloud = BKE_pointcloud_new_nomain(tot_points);
|
||||
bke::PointCloudComponent &dst_component =
|
||||
r_realized_geometry.get_component_for_write<bke::PointCloudComponent>();
|
||||
dst_component.replace(dst_pointcloud);
|
||||
r_realized_geometry.replace_pointcloud(dst_pointcloud);
|
||||
bke::MutableAttributeAccessor dst_attributes = dst_pointcloud->attributes_for_write();
|
||||
|
||||
const RealizePointCloudTask &first_task = tasks.first();
|
||||
|
@ -1095,9 +1093,7 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
|
|||
const int tot_poly = last_task.start_indices.poly + last_mesh.totpoly;
|
||||
|
||||
Mesh *dst_mesh = BKE_mesh_new_nomain(tot_vertices, tot_edges, tot_poly, tot_loops);
|
||||
bke::MeshComponent &dst_component =
|
||||
r_realized_geometry.get_component_for_write<bke::MeshComponent>();
|
||||
dst_component.replace(dst_mesh);
|
||||
r_realized_geometry.replace_mesh(dst_mesh);
|
||||
bke::MutableAttributeAccessor dst_attributes = dst_mesh->attributes_for_write();
|
||||
MutableSpan<float3> dst_positions = dst_mesh->vert_positions_for_write();
|
||||
MutableSpan<int2> dst_edges = dst_mesh->edges_for_write();
|
||||
|
|
Loading…
Reference in New Issue