Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-02-16 20:32:37 +0300
committerHans Goudey <h.goudey@me.com>2022-02-16 20:32:37 +0300
commitc324cf153924ae2ec5b7c59eabff71652847aeae (patch)
treef12f07ed61b018481e4bc45a7687567c48c952aa /source/blender/blenkernel/BKE_curves.hh
parent5b73017ddb679bb050fe13e4d9e3e5b04ea559b9 (diff)
Curves: Further implementation of new curves data structure
The general idea here is to wrap the `CurvesGeometry` DNA struct with a C++ class that can do most of the heavy lifting for the curve geometry. Using a C++ class allows easier ways to group methods, easier const correctness, and code that's more readable and faster to write. This way, it works much more like a version of `CurveEval` that uses more efficient attribute storage. This commit adds the structure of some yet-to-be-implemented code, the largest thing being mutexes and vectors meant to hold lazily calculated evaluated positions, tangents, and normals. That part might change slightly, but it's helpful to be able to see the direction this commit is aiming in. In particular, the inherently single-threaded accumulated lengths and Bezier evaluated point offsets might be cached. Ref T95355 Differential Revision: https://developer.blender.org/D14054
Diffstat (limited to 'source/blender/blenkernel/BKE_curves.hh')
-rw-r--r--source/blender/blenkernel/BKE_curves.hh156
1 files changed, 156 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
new file mode 100644
index 00000000000..6bcbb0f6e66
--- /dev/null
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -0,0 +1,156 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+#include "BKE_curves.h"
+
+/** \file
+ * \ingroup bke
+ * \brief Low-level operations for curves.
+ */
+
+#include <mutex>
+
+#include "BLI_float4x4.hh"
+#include "BLI_index_mask.hh"
+#include "BLI_math_vec_types.hh"
+#include "BLI_span.hh"
+#include "BLI_task.hh"
+#include "BLI_vector.hh"
+#include "BLI_virtual_array.hh"
+
+#include "BKE_attribute_access.hh"
+
+#include "FN_generic_virtual_array.hh"
+
+namespace blender::bke {
+
+/**
+ * Contains derived data, caches, and other information not saved in files, besides a few pointers
+ * to arrays that are kept in the non-runtime struct to avoid dereferencing this whenever they are
+ * accessed.
+ */
+class CurvesGeometryRuntime {
+ public:
+ /** Cache of evaluated positions. */
+ mutable Vector<float3> evaluated_position_cache;
+ mutable std::mutex position_cache_mutex;
+ mutable bool position_cache_dirty = true;
+
+ /** Direction of the spline at each evaluated point. */
+ mutable Vector<float3> evaluated_tangents_cache;
+ mutable std::mutex tangent_cache_mutex;
+ mutable bool tangent_cache_dirty = true;
+
+ /** Normal direction vectors for each evaluated point. */
+ mutable Vector<float3> evaluated_normals_cache;
+ mutable std::mutex normal_cache_mutex;
+ mutable bool normal_cache_dirty = true;
+};
+
+/**
+ * A C++ class that wraps the DNA struct for better encapsulation and ease of use. It inherits
+ * directly from the struct rather than storing a pointer to avoid more complcated ownership
+ * handling.
+ */
+class CurvesGeometry : public ::CurvesGeometry {
+ public:
+ CurvesGeometry();
+ /**
+ * Create curves with the given size. Only the position attribute is created, along with the
+ * offsets.
+ */
+ CurvesGeometry(int point_size, int curve_size);
+ CurvesGeometry(const CurvesGeometry &other);
+ CurvesGeometry &operator=(const CurvesGeometry &other);
+ ~CurvesGeometry();
+
+ static CurvesGeometry &wrap(::CurvesGeometry &dna_struct)
+ {
+ CurvesGeometry *geometry = reinterpret_cast<CurvesGeometry *>(&dna_struct);
+ return *geometry;
+ }
+ static const CurvesGeometry &wrap(const ::CurvesGeometry &dna_struct)
+ {
+ const CurvesGeometry *geometry = reinterpret_cast<const CurvesGeometry *>(&dna_struct);
+ return *geometry;
+ }
+
+ /* --------------------------------------------------------------------
+ * Accessors.
+ */
+
+ int points_size() const;
+ int curves_size() const;
+
+ /**
+ * The total number of points in the evaluated poly curve.
+ * This can depend on the resolution attribute if it exists.
+ */
+ int evaluated_points_size() const;
+
+ /**
+ * Access a range of indices of point data for a specific curve.
+ */
+ IndexRange range_for_curve(int index) const;
+
+ /** The type (#CurveType) of each curve, or potentially a single if all are the same type. */
+ VArray<int8_t> curve_types() const;
+ /** Mutable access to curve types. Call #tag_topology_changed after changing any type. */
+ MutableSpan<int8_t> curve_types();
+
+ MutableSpan<float3> positions();
+ Span<float3> positions() const;
+
+ /**
+ * Calculate the largest and smallest position values, only including control points
+ * (rather than evaluated points). The existing values of `min` and `max` are taken into account.
+ *
+ * \return Whether there are any points. If the curve is empty, the inputs will be unaffected.
+ */
+ bool bounds_min_max(float3 &min, float3 &max) const;
+
+ /**
+ * The index of the first point in every curve. The size of this span is one larger than the
+ * number of curves. Consider using #range_for_curve rather than using the offsets directly.
+ */
+ Span<int> offsets() const;
+ MutableSpan<int> offsets();
+
+ /* --------------------------------------------------------------------
+ * Operations.
+ */
+
+ /**
+ * Change the number of elements. New values for existing attributes should be properly
+ * initialized afterwards.
+ */
+ void resize(int point_size, int curve_size);
+
+ /** Call after deforming the position attribute. */
+ void tag_positions_changed();
+ /**
+ * Call after any operation that changes the topology
+ * (number of points, evaluated points, or the total count).
+ */
+ void tag_topology_changed();
+ /** Call after changing the "tilt" or "up" attributes. */
+ void tag_normals_changed();
+
+ void translate(const float3 &translation);
+ void transform(const float4x4 &matrix);
+
+ void update_customdata_pointers();
+
+ /* --------------------------------------------------------------------
+ * Attributes.
+ */
+
+ fn::GVArray adapt_domain(const fn::GVArray &varray,
+ AttributeDomain from,
+ AttributeDomain to) const;
+};
+
+Curves *curves_new_nomain(int point_size, int curves_size);
+
+} // namespace blender::bke