Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/BKE_curves.hh
| Show First 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | public: | ||||
| /** | /** | ||||
| * Which method to use for calculating the normals of evaluated points (#NormalMode). | * Which method to use for calculating the normals of evaluated points (#NormalMode). | ||||
| * Call #tag_normals_changed after changes. | * Call #tag_normals_changed after changes. | ||||
| */ | */ | ||||
| VArray<int8_t> normal_mode() const; | VArray<int8_t> normal_mode() const; | ||||
| MutableSpan<int8_t> normal_mode_for_write(); | MutableSpan<int8_t> normal_mode_for_write(); | ||||
| /** | /** | ||||
| * Used for normal mode curvature vector, specifying the weight as opposed to the minimal twist | |||||
| * normal. | |||||
| */ | |||||
| VArray<float> curvature_vector_weight() const; | |||||
| MutableSpan<float> curvature_vector_weight_for_write(); | |||||
| /** | |||||
| * Handle types for Bezier control points. Call #tag_topology_changed after changes. | * Handle types for Bezier control points. Call #tag_topology_changed after changes. | ||||
| */ | */ | ||||
| VArray<int8_t> handle_types_left() const; | VArray<int8_t> handle_types_left() const; | ||||
| MutableSpan<int8_t> handle_types_left_for_write(); | MutableSpan<int8_t> handle_types_left_for_write(); | ||||
| VArray<int8_t> handle_types_right() const; | VArray<int8_t> handle_types_right() const; | ||||
| MutableSpan<int8_t> handle_types_right_for_write(); | MutableSpan<int8_t> handle_types_right_for_write(); | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Calculate directions perpendicular to the tangent at every point by rotating an arbitrary | * Calculate directions perpendicular to the tangent at every point by rotating an arbitrary | ||||
| * starting vector by the same rotation of each tangent. If the curve is cyclic, propagate a | * starting vector by the same rotation of each tangent. If the curve is cyclic, propagate a | ||||
| * correction through the entire to make sure the first and last normal align. | * correction through the entire to make sure the first and last normal align. | ||||
| */ | */ | ||||
| void calculate_normals_minimum(Span<float3> tangents, bool cyclic, MutableSpan<float3> normals); | void calculate_normals_minimum(Span<float3> tangents, bool cyclic, MutableSpan<float3> normals); | ||||
| /** | /** | ||||
| * Calculate curvature vectors. TODO: more description. | |||||
| */ | |||||
| void calculate_curvature_vectors(Span<float3> positions, | |||||
| Span<float3> tangents, | |||||
| bool cyclic, | |||||
| MutableSpan<float3> normals); | |||||
| /** | |||||
| * Calculate a vector perpendicular to every tangent on the X-Y plane (unless the tangent is | * Calculate a vector perpendicular to every tangent on the X-Y plane (unless the tangent is | ||||
| * vertical, in that case use the X direction). | * vertical, in that case use the X direction). | ||||
| */ | */ | ||||
| void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> normals); | void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> normals); | ||||
| } // namespace poly | } // namespace poly | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Curve Catmull-Rom Methods | /** \name Curve Catmull-Rom Methods | ||||
| * \{ */ | * \{ */ | ||||
| namespace catmull_rom { | namespace catmull_rom { | ||||
| void calculate_tangents(Span<float3> positions, | |||||
| bool is_cyclic, | |||||
| int resolution, | |||||
| MutableSpan<float3> tangents); | |||||
| void calculate_normals(Span<float3> positions, | |||||
| bool is_cyclic, | |||||
| int resolution, | |||||
| float weight_bending, | |||||
| MutableSpan<float3> normals); | |||||
| /** | /** | ||||
| * Calculate the number of evaluated points that #interpolate_to_evaluated is expected to produce. | * Calculate the number of evaluated points that #interpolate_to_evaluated is expected to produce. | ||||
| * \param points_num: The number of points in the curve. | * \param points_num: The number of points in the curve. | ||||
| * \param resolution: The resolution for each segment. | * \param resolution: The resolution for each segment. | ||||
| */ | */ | ||||
| int calculate_evaluated_num(int points_num, bool cyclic, int resolution); | int calculate_evaluated_num(int points_num, bool cyclic, int resolution); | ||||
| /** | /** | ||||
| * Evaluate the Catmull Rom curve. The length of the #dst span should be calculated with | * Evaluate the Catmull Rom curve. The length of the #dst span should be calculated with | ||||
| * #calculate_evaluated_num and is expected to divide evenly by the #src span's segment size. | * #calculate_evaluated_num and is expected to divide evenly by the #src span's segment size. | ||||
| */ | */ | ||||
| void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, GMutableSpan dst); | void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, GMutableSpan dst); | ||||
| /** | /** | ||||
| * Evaluate the Catmull Rom curve. The size of each segment and its offset in the #dst span | * Evaluate the Catmull Rom curve. The size of each segment and its offset in the #dst span | ||||
| * is encoded in #evaluated_offsets, with the same method as #CurvesGeometry::offsets(). | * is encoded in #evaluated_offsets, with the same method as #CurvesGeometry::offsets(). | ||||
| */ | */ | ||||
| void interpolate_to_evaluated(const GSpan src, | void interpolate_to_evaluated(const GSpan src, | ||||
| const bool cyclic, | const bool cyclic, | ||||
| const Span<int> evaluated_offsets, | const Span<int> evaluated_offsets, | ||||
| GMutableSpan dst); | GMutableSpan dst); | ||||
| void calculate_basis(const float parameter, float4 &r_weights); | void calculate_basis(const float parameter, float4 &r_weights); | ||||
| void calculate_basis_derivative(const float parameter, float4 &r_weights); | |||||
| void calculate_basis_derivative2(const float parameter, float4 &r_weights); | |||||
| /** | /** | ||||
| * Interpolate the control point values for the given parameter on the piecewise segment. | * Interpolate the control point values for the given parameter on the piecewise segment. | ||||
| * \param a: Value associated with the first control point influencing the segment. | * \param a: Value associated with the first control point influencing the segment. | ||||
| * \param d: Value associated with the fourth control point. | * \param d: Value associated with the fourth control point. | ||||
| * \param parameter: Parameter in range [0, 1] to compute the interpolation for. | * \param parameter: Parameter in range [0, 1] to compute the interpolation for. | ||||
| */ | */ | ||||
| template<typename T> | template<typename T> | ||||
| T interpolate(const T &a, const T &b, const T &c, const T &d, const float parameter) | T interpolate( | ||||
| const int order, const T &a, const T &b, const T &c, const T &d, const float parameter) | |||||
| { | { | ||||
| BLI_assert(0.0f <= parameter && parameter <= 1.0f); | BLI_assert(0.0f <= parameter && parameter <= 1.0f); | ||||
| float4 n; | float4 n; | ||||
| switch (order) { | |||||
| case 1: | |||||
| calculate_basis_derivative(parameter, n); | |||||
| break; | |||||
| case 2: | |||||
| calculate_basis_derivative2(parameter, n); | |||||
| break; | |||||
| default: | |||||
| calculate_basis(parameter, n); | calculate_basis(parameter, n); | ||||
| break; | |||||
| } | |||||
| if constexpr (is_same_any_v<T, float, float2, float3>) { | if constexpr (is_same_any_v<T, float, float2, float3>) { | ||||
| /* Save multiplications by adjusting weights after mix. */ | /* Save multiplications by adjusting weights after mix. */ | ||||
| return 0.5f * attribute_math::mix4<T>(n, a, b, c, d); | return 0.5f * attribute_math::mix4<T>(n, a, b, c, d); | ||||
| } | } | ||||
| else { | else { | ||||
| return attribute_math::mix4<T>(n * 0.5f, a, b, c, d); | return attribute_math::mix4<T>(n * 0.5f, a, b, c, d); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines | |||||