Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include "FN_generic_virtual_array.hh"
|
|
|
|
|
|
|
|
#include "BLI_float3.hh"
|
|
|
|
#include "BLI_float4x4.hh"
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
2021-05-19 19:22:09 +02:00
|
|
|
#include "BKE_attribute_access.hh"
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
#include "BKE_attribute_math.hh"
|
|
|
|
|
|
|
|
struct Curve;
|
2021-06-28 21:28:52 +02:00
|
|
|
struct ListBase;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
class Spline;
|
|
|
|
using SplinePtr = std::unique_ptr<Spline>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A spline is an abstraction of a single branch-less curve section, its evaluation methods,
|
|
|
|
* and data. The spline data itself is just control points and a set of attributes by the set
|
|
|
|
* of "evaluated" data is often used instead.
|
|
|
|
*
|
|
|
|
* Any derived class of Spline has to manage two things:
|
|
|
|
* 1. Interpolating arbitrary attribute data from the control points to evaluated points.
|
|
|
|
* 2. Evaluating the positions based on the stored control point data.
|
|
|
|
*
|
|
|
|
* Beyond that, everything is the base class's responsibility, with minor exceptions. Further
|
|
|
|
* evaluation happens in a layer on top of the evaluated points generated by the derived types.
|
|
|
|
*
|
|
|
|
* There are a few methods to evaluate a spline:
|
2021-06-21 05:05:57 +02:00
|
|
|
* 1. #evaluated_positions and #interpolate_to_evaluated give data for the initial
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
* evaluated points, depending on the resolution.
|
|
|
|
* 2. #lookup_evaluated_factor and #lookup_evaluated_factor are meant for one-off lookups
|
|
|
|
* along the length of a curve.
|
2021-05-14 23:37:05 +02:00
|
|
|
* 3. #sample_uniform_index_factors returns an array that stores uniform-length samples
|
|
|
|
* along the spline which can be used to interpolate data from method 1.
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
*
|
|
|
|
* Commonly used evaluated data is stored in caches on the spline itself so that operations on
|
|
|
|
* splines don't need to worry about taking ownership of evaluated data when they don't need to.
|
|
|
|
*/
|
|
|
|
class Spline {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Bezier,
|
|
|
|
NURBS,
|
|
|
|
Poly,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum NormalCalculationMode {
|
|
|
|
ZUp,
|
|
|
|
Minimum,
|
|
|
|
Tangent,
|
|
|
|
};
|
2021-06-20 20:07:49 +02:00
|
|
|
NormalCalculationMode normal_mode = Minimum;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2021-05-19 19:22:09 +02:00
|
|
|
blender::bke::CustomDataAttributes attributes;
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
protected:
|
2021-05-12 18:50:35 +02:00
|
|
|
Type type_;
|
|
|
|
bool is_cyclic_ = false;
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
/** Direction of the spline at each evaluated point. */
|
|
|
|
mutable blender::Vector<blender::float3> evaluated_tangents_cache_;
|
|
|
|
mutable std::mutex tangent_cache_mutex_;
|
|
|
|
mutable bool tangent_cache_dirty_ = true;
|
|
|
|
|
|
|
|
/** Normal direction vectors for each evaluated point. */
|
|
|
|
mutable blender::Vector<blender::float3> evaluated_normals_cache_;
|
|
|
|
mutable std::mutex normal_cache_mutex_;
|
|
|
|
mutable bool normal_cache_dirty_ = true;
|
|
|
|
|
|
|
|
/** Accumulated lengths along the evaluated points. */
|
|
|
|
mutable blender::Vector<float> evaluated_lengths_cache_;
|
|
|
|
mutable std::mutex length_cache_mutex_;
|
|
|
|
mutable bool length_cache_dirty_ = true;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Spline() = default;
|
|
|
|
Spline(const Type type) : type_(type)
|
|
|
|
{
|
|
|
|
}
|
2021-06-02 15:11:35 +02:00
|
|
|
Spline(Spline &other) : attributes(other.attributes), type_(other.type_)
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
{
|
2021-06-02 15:11:35 +02:00
|
|
|
copy_base_settings(other, *this);
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
}
|
|
|
|
|
2021-06-22 18:32:50 +02:00
|
|
|
SplinePtr copy() const;
|
|
|
|
SplinePtr copy_only_settings() const;
|
|
|
|
SplinePtr copy_without_attributes() const;
|
2021-08-02 20:21:19 +02:00
|
|
|
static void copy_base_settings(const Spline &src, Spline &dst);
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
Spline::Type type() const;
|
|
|
|
|
|
|
|
/** Return the number of control points. */
|
|
|
|
virtual int size() const = 0;
|
|
|
|
int segments_size() const;
|
|
|
|
bool is_cyclic() const;
|
|
|
|
void set_cyclic(const bool value);
|
|
|
|
|
2021-05-07 22:37:06 +02:00
|
|
|
virtual void resize(const int size) = 0;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
virtual blender::MutableSpan<blender::float3> positions() = 0;
|
|
|
|
virtual blender::Span<blender::float3> positions() const = 0;
|
|
|
|
virtual blender::MutableSpan<float> radii() = 0;
|
|
|
|
virtual blender::Span<float> radii() const = 0;
|
|
|
|
virtual blender::MutableSpan<float> tilts() = 0;
|
|
|
|
virtual blender::Span<float> tilts() const = 0;
|
|
|
|
|
|
|
|
virtual void translate(const blender::float3 &translation);
|
|
|
|
virtual void transform(const blender::float4x4 &matrix);
|
|
|
|
|
2021-09-15 20:57:01 +02:00
|
|
|
/**
|
|
|
|
* Change the direction of the spline (switch the start and end) without changing its shape.
|
|
|
|
*/
|
|
|
|
void reverse();
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
/**
|
|
|
|
* Mark all caches for re-computation. This must be called after any operation that would
|
|
|
|
* change the generated positions, tangents, normals, mapping, etc. of the evaluated points.
|
|
|
|
*/
|
|
|
|
virtual void mark_cache_invalid() = 0;
|
|
|
|
virtual int evaluated_points_size() const = 0;
|
|
|
|
int evaluated_edges_size() const;
|
|
|
|
|
|
|
|
float length() const;
|
|
|
|
|
|
|
|
virtual blender::Span<blender::float3> evaluated_positions() const = 0;
|
|
|
|
|
|
|
|
blender::Span<float> evaluated_lengths() const;
|
|
|
|
blender::Span<blender::float3> evaluated_tangents() const;
|
|
|
|
blender::Span<blender::float3> evaluated_normals() const;
|
|
|
|
|
|
|
|
void bounds_min_max(blender::float3 &min, blender::float3 &max, const bool use_evaluated) const;
|
|
|
|
|
|
|
|
struct LookupResult {
|
|
|
|
/**
|
|
|
|
* The index of the evaluated point before the result location. In other words, the index of
|
|
|
|
* the edge that the result lies on. If the sampled factor/length is the very end of the
|
|
|
|
* spline, this will be the second to last index, if it's the very beginning, this will be 0.
|
|
|
|
*/
|
|
|
|
int evaluated_index;
|
|
|
|
/**
|
|
|
|
* The index of the evaluated point after the result location, accounting for wrapping when
|
|
|
|
* the spline is cyclic. If the sampled factor/length is the very end of the spline, this will
|
|
|
|
* be the last index (#evaluated_points_size - 1).
|
|
|
|
*/
|
|
|
|
int next_evaluated_index;
|
|
|
|
/**
|
|
|
|
* The portion of the way from the evaluated point at #evaluated_index to the next point.
|
|
|
|
* If the sampled factor/length is the very end of the spline, this will be the 1.0f
|
|
|
|
*/
|
|
|
|
float factor;
|
|
|
|
};
|
|
|
|
LookupResult lookup_evaluated_factor(const float factor) const;
|
|
|
|
LookupResult lookup_evaluated_length(const float length) const;
|
|
|
|
|
2021-05-07 22:37:06 +02:00
|
|
|
blender::Array<float> sample_uniform_index_factors(const int samples_size) const;
|
|
|
|
LookupResult lookup_data_from_index_factor(const float index_factor) const;
|
|
|
|
|
2021-06-21 05:05:57 +02:00
|
|
|
void sample_with_index_factors(const blender::fn::GVArray &src,
|
|
|
|
blender::Span<float> index_factors,
|
|
|
|
blender::fn::GMutableSpan dst) const;
|
2021-06-09 21:53:39 +02:00
|
|
|
template<typename T>
|
2021-06-21 05:05:57 +02:00
|
|
|
void sample_with_index_factors(const blender::VArray<T> &src,
|
|
|
|
blender::Span<float> index_factors,
|
|
|
|
blender::MutableSpan<T> dst) const
|
2021-06-09 21:53:39 +02:00
|
|
|
{
|
2021-06-21 05:05:57 +02:00
|
|
|
this->sample_with_index_factors(
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
blender::fn::GVArray(src), index_factors, blender::fn::GMutableSpan(dst));
|
2021-06-09 21:53:39 +02:00
|
|
|
}
|
|
|
|
template<typename T>
|
2021-06-21 05:05:57 +02:00
|
|
|
void sample_with_index_factors(blender::Span<T> src,
|
|
|
|
blender::Span<float> index_factors,
|
|
|
|
blender::MutableSpan<T> dst) const
|
2021-06-09 21:53:39 +02:00
|
|
|
{
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
this->sample_with_index_factors(blender::VArray<T>::ForSpan(src), index_factors, dst);
|
2021-06-09 21:53:39 +02:00
|
|
|
}
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
/**
|
|
|
|
* Interpolate a virtual array of data with the size of the number of control points to the
|
|
|
|
* evaluated points. For poly splines, the lifetime of the returned virtual array must not
|
|
|
|
* exceed the lifetime of the input data.
|
|
|
|
*/
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
virtual blender::fn::GVArray interpolate_to_evaluated(const blender::fn::GVArray &src) const = 0;
|
|
|
|
blender::fn::GVArray interpolate_to_evaluated(blender::fn::GSpan data) const;
|
|
|
|
template<typename T> blender::VArray<T> interpolate_to_evaluated(blender::Span<T> data) const
|
2021-06-09 21:53:39 +02:00
|
|
|
{
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
return this->interpolate_to_evaluated(blender::fn::GSpan(data)).typed<T>();
|
2021-06-09 21:53:39 +02:00
|
|
|
}
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void correct_end_tangents() const = 0;
|
2021-06-22 18:32:50 +02:00
|
|
|
virtual void copy_settings(Spline &dst) const = 0;
|
|
|
|
virtual void copy_data(Spline &dst) const = 0;
|
2021-09-15 20:57:01 +02:00
|
|
|
virtual void reverse_impl() = 0;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Bézier spline is made up of a many curve segments, possibly achieving continuity of curvature
|
|
|
|
* by constraining the alignment of curve handles. Evaluation stores the positions and a map of
|
|
|
|
* factors and indices in a list of floats, which is then used to interpolate any other data.
|
|
|
|
*/
|
|
|
|
class BezierSpline final : public Spline {
|
|
|
|
public:
|
|
|
|
enum class HandleType {
|
|
|
|
/** The handle can be moved anywhere, and doesn't influence the point's other handle. */
|
|
|
|
Free,
|
|
|
|
/** The location is automatically calculated to be smooth. */
|
|
|
|
Auto,
|
|
|
|
/** The location is calculated to point to the next/previous control point. */
|
|
|
|
Vector,
|
|
|
|
/** The location is constrained to point in the opposite direction as the other handle. */
|
|
|
|
Align,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
blender::Vector<blender::float3> positions_;
|
|
|
|
blender::Vector<float> radii_;
|
|
|
|
blender::Vector<float> tilts_;
|
|
|
|
int resolution_;
|
|
|
|
|
2021-05-11 02:33:12 +02:00
|
|
|
blender::Vector<HandleType> handle_types_left_;
|
|
|
|
blender::Vector<HandleType> handle_types_right_;
|
|
|
|
|
2021-05-12 17:21:12 +02:00
|
|
|
/* These are mutable to allow lazy recalculation of #Auto and #Vector handle positions. */
|
|
|
|
mutable blender::Vector<blender::float3> handle_positions_left_;
|
|
|
|
mutable blender::Vector<blender::float3> handle_positions_right_;
|
|
|
|
|
|
|
|
mutable std::mutex auto_handle_mutex_;
|
|
|
|
mutable bool auto_handles_dirty_ = true;
|
2021-05-11 02:33:12 +02:00
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
/** Start index in evaluated points array for every control point. */
|
|
|
|
mutable blender::Vector<int> offset_cache_;
|
|
|
|
mutable std::mutex offset_cache_mutex_;
|
|
|
|
mutable bool offset_cache_dirty_ = true;
|
|
|
|
|
|
|
|
/** Cache of evaluated positions. */
|
|
|
|
mutable blender::Vector<blender::float3> evaluated_position_cache_;
|
|
|
|
mutable std::mutex position_cache_mutex_;
|
|
|
|
mutable bool position_cache_dirty_ = true;
|
|
|
|
|
|
|
|
/** Cache of "index factors" based calculated from the evaluated positions. */
|
|
|
|
mutable blender::Vector<float> evaluated_mapping_cache_;
|
|
|
|
mutable std::mutex mapping_cache_mutex_;
|
|
|
|
mutable bool mapping_cache_dirty_ = true;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BezierSpline() : Spline(Type::Bezier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
BezierSpline(const BezierSpline &other)
|
|
|
|
: Spline((Spline &)other),
|
|
|
|
positions_(other.positions_),
|
|
|
|
radii_(other.radii_),
|
|
|
|
tilts_(other.tilts_),
|
2021-05-11 02:33:12 +02:00
|
|
|
resolution_(other.resolution_),
|
|
|
|
handle_types_left_(other.handle_types_left_),
|
|
|
|
handle_types_right_(other.handle_types_right_),
|
|
|
|
handle_positions_left_(other.handle_positions_left_),
|
|
|
|
handle_positions_right_(other.handle_positions_right_)
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int size() const final;
|
|
|
|
int resolution() const;
|
|
|
|
void set_resolution(const int value);
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \warning Call #reallocate on the spline's attributes after adding all points.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
void add_point(const blender::float3 position,
|
2021-05-27 15:27:08 +02:00
|
|
|
const HandleType handle_type_left,
|
|
|
|
const blender::float3 handle_position_left,
|
|
|
|
const HandleType handle_type_right,
|
|
|
|
const blender::float3 handle_position_right,
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
const float radius,
|
|
|
|
const float tilt);
|
|
|
|
|
2021-05-07 22:37:06 +02:00
|
|
|
void resize(const int size) final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::MutableSpan<blender::float3> positions() final;
|
|
|
|
blender::Span<blender::float3> positions() const final;
|
|
|
|
blender::MutableSpan<float> radii() final;
|
|
|
|
blender::Span<float> radii() const final;
|
|
|
|
blender::MutableSpan<float> tilts() final;
|
|
|
|
blender::Span<float> tilts() const final;
|
|
|
|
blender::Span<HandleType> handle_types_left() const;
|
|
|
|
blender::MutableSpan<HandleType> handle_types_left();
|
|
|
|
blender::Span<blender::float3> handle_positions_left() const;
|
2021-11-11 16:25:10 +01:00
|
|
|
/**
|
2021-11-13 03:07:13 +01:00
|
|
|
* Get writable access to the handle position.
|
2021-11-11 16:25:10 +01:00
|
|
|
*
|
|
|
|
* \param write_only: pass true for an uninitialized spline, this prevents accessing
|
2021-11-13 03:07:13 +01:00
|
|
|
* uninitialized memory while auto-generating handles.
|
2021-11-11 16:25:10 +01:00
|
|
|
*/
|
|
|
|
blender::MutableSpan<blender::float3> handle_positions_left(bool write_only = false);
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::Span<HandleType> handle_types_right() const;
|
|
|
|
blender::MutableSpan<HandleType> handle_types_right();
|
|
|
|
blender::Span<blender::float3> handle_positions_right() const;
|
2021-11-11 16:25:10 +01:00
|
|
|
/**
|
2021-11-13 03:07:13 +01:00
|
|
|
* Get writable access to the handle position.
|
2021-11-11 16:25:10 +01:00
|
|
|
*
|
|
|
|
* \param write_only: pass true for an uninitialized spline, this prevents accessing
|
2021-11-13 03:07:13 +01:00
|
|
|
* uninitialized memory while auto-generating handles.
|
2021-11-11 16:25:10 +01:00
|
|
|
*/
|
|
|
|
blender::MutableSpan<blender::float3> handle_positions_right(bool write_only = false);
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Recalculate all #Auto and #Vector handles with positions automatically
|
|
|
|
* derived from the neighboring control points.
|
|
|
|
*/
|
2021-07-22 23:11:26 +02:00
|
|
|
void ensure_auto_handles() const;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
void translate(const blender::float3 &translation) override;
|
|
|
|
void transform(const blender::float4x4 &matrix) override;
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Set positions for the right handle of the control point, ensuring that
|
|
|
|
* aligned handles stay aligned. Has no effect for auto and vector type handles.
|
|
|
|
*/
|
2021-09-29 22:29:29 +02:00
|
|
|
void set_handle_position_right(const int index, const blender::float3 &value);
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Set positions for the left handle of the control point, ensuring that
|
|
|
|
* aligned handles stay aligned. Has no effect for auto and vector type handles.
|
|
|
|
*/
|
2021-09-29 22:29:29 +02:00
|
|
|
void set_handle_position_left(const int index, const blender::float3 &value);
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
bool point_is_sharp(const int index) const;
|
|
|
|
|
|
|
|
void mark_cache_invalid() final;
|
|
|
|
int evaluated_points_size() const final;
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Returns access to a cache of offsets into the evaluated point array for each control point.
|
|
|
|
* While most control point edges generate the number of edges specified by the resolution,
|
|
|
|
* vector segments only generate one edge.
|
|
|
|
*
|
|
|
|
* \note The length of the result is one greater than the number of points, so that the last item
|
|
|
|
* is the total number of evaluated points. This is useful to avoid recalculating the size of the
|
|
|
|
* last segment everywhere.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::Span<int> control_point_offsets() const;
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Returns non-owning access to an array of values containing the information necessary to
|
|
|
|
* interpolate values from the original control points to evaluated points. The control point
|
|
|
|
* index is the integer part of each value, and the factor used for interpolating to the next
|
|
|
|
* control point is the remaining factional part.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::Span<float> evaluated_mappings() const;
|
|
|
|
blender::Span<blender::float3> evaluated_positions() const final;
|
|
|
|
struct InterpolationData {
|
|
|
|
int control_point_index;
|
|
|
|
int next_control_point_index;
|
|
|
|
/**
|
|
|
|
* Linear interpolation weight between the two indices, from 0 to 1.
|
2021-05-14 23:37:05 +02:00
|
|
|
* Higher means closer to next control point.
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
*/
|
|
|
|
float factor;
|
|
|
|
};
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Convert the data encoded in #evaulated_mappings into its parts-- the information necessary
|
|
|
|
* to interpolate data from control points to evaluated points between them. The next control
|
|
|
|
* point index result will not overflow the size of the control point vectors.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
InterpolationData interpolation_data_from_index_factor(const float index_factor) const;
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
virtual blender::fn::GVArray interpolate_to_evaluated(
|
2021-06-24 19:17:51 +02:00
|
|
|
const blender::fn::GVArray &src) const override;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2021-06-15 23:31:08 +02:00
|
|
|
void evaluate_segment(const int index,
|
|
|
|
const int next_index,
|
|
|
|
blender::MutableSpan<blender::float3> positions) const;
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \warning This functional assumes that the spline has more than one point.
|
|
|
|
*/
|
2021-06-15 23:31:08 +02:00
|
|
|
bool segment_is_vector(const int start_index) const;
|
|
|
|
|
2021-07-14 21:13:17 +02:00
|
|
|
/** See comment and diagram for #calculate_segment_insertion. */
|
|
|
|
struct InsertResult {
|
|
|
|
blender::float3 handle_prev;
|
|
|
|
blender::float3 left_handle;
|
|
|
|
blender::float3 position;
|
|
|
|
blender::float3 right_handle;
|
|
|
|
blender::float3 handle_next;
|
|
|
|
};
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* De Casteljau Bezier subdivision.
|
|
|
|
* \param index: The index of the segment's start control point.
|
|
|
|
* \param next_index: The index of the control point at the end of the segment. Could be 0,
|
|
|
|
* if the spline is cyclic.
|
|
|
|
* \param parameter: The factor along the segment, between 0 and 1. Note that this is used
|
|
|
|
* directly by the calculation, it doesn't correspond to a portion of the evaluated length.
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* handle_prev handle_next
|
|
|
|
* x----------------x
|
|
|
|
* / \
|
|
|
|
* / x---O---x \
|
|
|
|
* / result \
|
|
|
|
* / \
|
|
|
|
* O O
|
|
|
|
* point_prev point_next
|
|
|
|
* </pre>
|
|
|
|
*/
|
2021-07-14 21:13:17 +02:00
|
|
|
InsertResult calculate_segment_insertion(const int index,
|
|
|
|
const int next_index,
|
|
|
|
const float parameter);
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
private:
|
|
|
|
void correct_end_tangents() const final;
|
2021-06-22 18:32:50 +02:00
|
|
|
void copy_settings(Spline &dst) const final;
|
|
|
|
void copy_data(Spline &dst) const final;
|
2021-09-15 20:57:01 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void reverse_impl() override;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data for Non-Uniform Rational B-Splines. The mapping from control points to evaluated points is
|
|
|
|
* influenced by a vector of knots, weights for each point, and the order of the spline. Every
|
|
|
|
* mapping of data to evaluated points is handled the same way, but the positions are cached in
|
|
|
|
* the spline.
|
|
|
|
*/
|
|
|
|
class NURBSpline final : public Spline {
|
|
|
|
public:
|
|
|
|
enum class KnotsMode {
|
|
|
|
Normal,
|
|
|
|
EndPoint,
|
|
|
|
Bezier,
|
|
|
|
};
|
2021-05-14 23:37:05 +02:00
|
|
|
|
|
|
|
/** Method used to recalculate the knots vector when points are added or removed. */
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
KnotsMode knots_mode;
|
|
|
|
|
|
|
|
struct BasisCache {
|
|
|
|
/** The influence at each control point `i + #start_index`. */
|
|
|
|
blender::Vector<float> weights;
|
|
|
|
/**
|
|
|
|
* An offset for the start of #weights: the first control point index with a non-zero weight.
|
|
|
|
*/
|
|
|
|
int start_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
blender::Vector<blender::float3> positions_;
|
|
|
|
blender::Vector<float> radii_;
|
|
|
|
blender::Vector<float> tilts_;
|
|
|
|
blender::Vector<float> weights_;
|
|
|
|
int resolution_;
|
|
|
|
/**
|
|
|
|
* Defines the number of nearby control points that influence a given evaluated point. Higher
|
|
|
|
* orders give smoother results. The number of control points must be greater than or equal to
|
|
|
|
* this value.
|
|
|
|
*/
|
|
|
|
uint8_t order_;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines where and how the control points affect the evaluated points. The length should
|
|
|
|
* always be the value returned by #knots_size(), and each value should be greater than or equal
|
|
|
|
* to the previous. Only invalidated when a point is added or removed.
|
|
|
|
*/
|
|
|
|
mutable blender::Vector<float> knots_;
|
|
|
|
mutable std::mutex knots_mutex_;
|
|
|
|
mutable bool knots_dirty_ = true;
|
|
|
|
|
|
|
|
/** Cache of control point influences on each evaluated point. */
|
|
|
|
mutable blender::Vector<BasisCache> basis_cache_;
|
|
|
|
mutable std::mutex basis_cache_mutex_;
|
|
|
|
mutable bool basis_cache_dirty_ = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache of position data calculated from the basis cache. Though it is interpolated
|
|
|
|
* in the same way as any other attribute, it is stored to save unnecessary recalculation.
|
|
|
|
*/
|
|
|
|
mutable blender::Vector<blender::float3> evaluated_position_cache_;
|
|
|
|
mutable std::mutex position_cache_mutex_;
|
|
|
|
mutable bool position_cache_dirty_ = true;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NURBSpline() : Spline(Type::NURBS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
NURBSpline(const NURBSpline &other)
|
|
|
|
: Spline((Spline &)other),
|
|
|
|
knots_mode(other.knots_mode),
|
|
|
|
positions_(other.positions_),
|
|
|
|
radii_(other.radii_),
|
|
|
|
tilts_(other.tilts_),
|
|
|
|
weights_(other.weights_),
|
|
|
|
resolution_(other.resolution_),
|
|
|
|
order_(other.order_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int size() const final;
|
|
|
|
int resolution() const;
|
|
|
|
void set_resolution(const int value);
|
|
|
|
uint8_t order() const;
|
|
|
|
void set_order(const uint8_t value);
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \warning Call #reallocate on the spline's attributes after adding all points.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
void add_point(const blender::float3 position,
|
|
|
|
const float radius,
|
|
|
|
const float tilt,
|
|
|
|
const float weight);
|
|
|
|
|
|
|
|
bool check_valid_size_and_order() const;
|
|
|
|
int knots_size() const;
|
|
|
|
|
2021-05-07 22:37:06 +02:00
|
|
|
void resize(const int size) final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::MutableSpan<blender::float3> positions() final;
|
|
|
|
blender::Span<blender::float3> positions() const final;
|
|
|
|
blender::MutableSpan<float> radii() final;
|
|
|
|
blender::Span<float> radii() const final;
|
|
|
|
blender::MutableSpan<float> tilts() final;
|
|
|
|
blender::Span<float> tilts() const final;
|
|
|
|
blender::Span<float> knots() const;
|
|
|
|
|
|
|
|
blender::MutableSpan<float> weights();
|
|
|
|
blender::Span<float> weights() const;
|
|
|
|
|
|
|
|
void mark_cache_invalid() final;
|
|
|
|
int evaluated_points_size() const final;
|
|
|
|
|
|
|
|
blender::Span<blender::float3> evaluated_positions() const final;
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
blender::fn::GVArray interpolate_to_evaluated(const blender::fn::GVArray &src) const final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void correct_end_tangents() const final;
|
2021-06-22 18:32:50 +02:00
|
|
|
void copy_settings(Spline &dst) const final;
|
|
|
|
void copy_data(Spline &dst) const final;
|
2021-09-15 20:57:01 +02:00
|
|
|
void reverse_impl() override;
|
2021-06-22 18:32:50 +02:00
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
void calculate_knots() const;
|
2021-06-22 06:02:00 +02:00
|
|
|
blender::Span<BasisCache> calculate_basis_cache() const;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Poly spline is like a bezier spline with a resolution of one. The main reason to distinguish
|
|
|
|
* the two is for reduced complexity and increased performance, since interpolating data to control
|
|
|
|
* points does not change it.
|
|
|
|
*/
|
|
|
|
class PolySpline final : public Spline {
|
|
|
|
blender::Vector<blender::float3> positions_;
|
|
|
|
blender::Vector<float> radii_;
|
|
|
|
blender::Vector<float> tilts_;
|
|
|
|
|
|
|
|
public:
|
2021-05-04 21:34:16 +02:00
|
|
|
PolySpline() : Spline(Type::Poly)
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
PolySpline(const PolySpline &other)
|
|
|
|
: Spline((Spline &)other),
|
|
|
|
positions_(other.positions_),
|
|
|
|
radii_(other.radii_),
|
|
|
|
tilts_(other.tilts_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int size() const final;
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \warning Call #reallocate on the spline's attributes after adding all points.
|
|
|
|
*/
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
void add_point(const blender::float3 position, const float radius, const float tilt);
|
|
|
|
|
2021-05-07 22:37:06 +02:00
|
|
|
void resize(const int size) final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
blender::MutableSpan<blender::float3> positions() final;
|
|
|
|
blender::Span<blender::float3> positions() const final;
|
|
|
|
blender::MutableSpan<float> radii() final;
|
|
|
|
blender::Span<float> radii() const final;
|
|
|
|
blender::MutableSpan<float> tilts() final;
|
|
|
|
blender::Span<float> tilts() const final;
|
|
|
|
|
|
|
|
void mark_cache_invalid() final;
|
|
|
|
int evaluated_points_size() const final;
|
|
|
|
|
|
|
|
blender::Span<blender::float3> evaluated_positions() const final;
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
blender::fn::GVArray interpolate_to_evaluated(const blender::fn::GVArray &src) const final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void correct_end_tangents() const final;
|
2021-06-22 18:32:50 +02:00
|
|
|
void copy_settings(Spline &dst) const final;
|
|
|
|
void copy_data(Spline &dst) const final;
|
2021-09-15 20:57:01 +02:00
|
|
|
void reverse_impl() override;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-12-02 15:24:21 +01:00
|
|
|
* A collection of #Spline objects with the same attribute types and names. Most data and
|
|
|
|
* functionality is in splines, but this contains some helpers for working with them as a group.
|
|
|
|
*
|
|
|
|
* \note A #CurveEval corresponds to the #Curve object data. The name is different for clarity,
|
|
|
|
* since more of the data is stored in the splines, but also just to be different than the name in
|
|
|
|
* DNA.
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
*/
|
2021-05-27 16:50:43 +02:00
|
|
|
struct CurveEval {
|
2021-05-12 18:46:13 +02:00
|
|
|
private:
|
|
|
|
blender::Vector<SplinePtr> splines_;
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
public:
|
2021-05-19 19:22:09 +02:00
|
|
|
blender::bke::CustomDataAttributes attributes;
|
|
|
|
|
2021-05-19 19:02:53 +02:00
|
|
|
CurveEval() = default;
|
2021-05-19 19:22:09 +02:00
|
|
|
CurveEval(const CurveEval &other) : attributes(other.attributes)
|
2021-05-19 19:02:53 +02:00
|
|
|
{
|
|
|
|
for (const SplinePtr &spline : other.splines()) {
|
|
|
|
this->add_spline(spline->copy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 18:46:13 +02:00
|
|
|
blender::Span<SplinePtr> splines() const;
|
|
|
|
blender::MutableSpan<SplinePtr> splines();
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \return True if the curve contains a spline with the given type.
|
|
|
|
*
|
|
|
|
* \note If you are looping over all of the splines in the same scope anyway,
|
|
|
|
* it's better to avoid calling this function, in case there are many splines.
|
|
|
|
*/
|
2021-07-22 23:20:04 +02:00
|
|
|
bool has_spline_with_type(const Spline::Type type) const;
|
2021-05-12 18:46:13 +02:00
|
|
|
|
2021-06-15 23:24:11 +02:00
|
|
|
void resize(const int size);
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* \warning Call #reallocate on the spline's attributes after adding all splines.
|
|
|
|
*/
|
2021-05-12 18:46:13 +02:00
|
|
|
void add_spline(SplinePtr spline);
|
|
|
|
void remove_splines(blender::IndexMask mask);
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
void translate(const blender::float3 &translation);
|
|
|
|
void transform(const blender::float4x4 &matrix);
|
|
|
|
void bounds_min_max(blender::float3 &min, blender::float3 &max, const bool use_evaluated) const;
|
2021-05-16 00:44:33 +02:00
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Return the start indices for each of the curve spline's control points, if they were part
|
|
|
|
* of a flattened array. This can be used to facilitate parallelism by avoiding the need to
|
|
|
|
* accumulate an offset while doing more complex calculations.
|
|
|
|
*
|
|
|
|
* \note The result is one longer than the spline count; the last element is the total size.
|
|
|
|
*/
|
2021-05-16 00:44:33 +02:00
|
|
|
blender::Array<int> control_point_offsets() const;
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Exactly like #control_point_offsets, but uses the number of evaluated points instead.
|
|
|
|
*/
|
2021-05-16 00:44:33 +02:00
|
|
|
blender::Array<int> evaluated_point_offsets() const;
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Return the accumulated length at the start of every spline in the curve.
|
|
|
|
* \note The result is one longer than the spline count; the last element is the total length.
|
|
|
|
*/
|
2021-09-21 03:23:26 +02:00
|
|
|
blender::Array<float> accumulated_spline_lengths() const;
|
2021-05-19 19:22:09 +02:00
|
|
|
|
2021-11-22 19:07:59 +01:00
|
|
|
float total_length() const;
|
|
|
|
int total_control_point_size() const;
|
|
|
|
|
2021-10-29 09:28:31 +02:00
|
|
|
void mark_cache_invalid();
|
|
|
|
|
2021-12-02 15:24:21 +01:00
|
|
|
/**
|
|
|
|
* Check the invariants that curve control point attributes should always uphold, necessary
|
|
|
|
* because attributes are stored on splines rather than in a flat array on the curve:
|
|
|
|
* - The same set of attributes exists on every spline.
|
|
|
|
* - Attributes with the same name have the same type on every spline.
|
|
|
|
* - Attributes are in the same order on every spline.
|
|
|
|
*/
|
2021-05-19 19:22:09 +02:00
|
|
|
void assert_valid_point_attributes() const;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
2021-06-28 21:28:52 +02:00
|
|
|
std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &curve,
|
|
|
|
const ListBase &nurbs_list);
|
|
|
|
std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve);
|