Files
test/source/blender/blenkernel/intern/geometry_component_edit_data.cc
Hans Goudey f4124ee02d Cleanup: Move GeometrySet and components to proper namespace
Move `GeometrySet` and `GeometryComponent` and subclasses
to the `blender::bke` namespace. This wasn't done earlier since
these were one of the first C++ classes used throughout Blender,
but now it is common.

Also remove the now-unnecessary C-header, since all users of
the geometry set header are now in C++.

Pull Request: https://projects.blender.org/blender/blender/pulls/109020
2023-06-15 22:18:28 +02:00

66 lines
1.9 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_curves.hh"
#include "BKE_geometry_set.hh"
namespace blender::bke {
GeometryComponentEditData::GeometryComponentEditData() : GeometryComponent(Type::Edit) {}
GeometryComponent *GeometryComponentEditData::copy() const
{
GeometryComponentEditData *new_component = new GeometryComponentEditData();
if (curves_edit_hints_) {
new_component->curves_edit_hints_ = std::make_unique<CurvesEditHints>(*curves_edit_hints_);
}
return new_component;
}
bool GeometryComponentEditData::owns_direct_data() const
{
return true;
}
void GeometryComponentEditData::ensure_owns_direct_data()
{
/* Nothing to do. */
}
void GeometryComponentEditData::clear()
{
BLI_assert(this->is_mutable() || this->is_expired());
curves_edit_hints_.reset();
}
void GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(
GeometrySet &geometry)
{
/* This component should be created at the start of object evaluation if it's necessary. */
if (!geometry.has<GeometryComponentEditData>()) {
return;
}
GeometryComponentEditData &edit_component =
geometry.get_component_for_write<GeometryComponentEditData>();
if (!edit_component.curves_edit_hints_) {
return;
}
if (edit_component.curves_edit_hints_->positions.has_value()) {
return;
}
const Curves *curves_id = geometry.get_curves_for_read();
if (curves_id == nullptr) {
return;
}
const CurvesGeometry &curves = curves_id->geometry.wrap();
const int points_num = curves.points_num();
if (points_num != edit_component.curves_edit_hints_->curves_id_orig.geometry.point_num) {
return;
}
edit_component.curves_edit_hints_->positions.emplace(points_num);
edit_component.curves_edit_hints_->positions->as_mutable_span().copy_from(curves.positions());
}
} // namespace blender::bke