[Bf-blender-cvs] [3ca4ec3857c] temp-sculpt-roll-mapping: Merge branch 'master' into temp-sculpt-roll-mapping
Joseph Eagar
noreply at git.blender.org
Tue Jan 24 17:54:38 CET 2023
Commit: 3ca4ec3857c11b3ce700ad2013bbfe52ac2cb792
Author: Joseph Eagar
Date: Tue Jan 24 08:30:06 2023 -0800
Branches: temp-sculpt-roll-mapping
https://developer.blender.org/rB3ca4ec3857c11b3ce700ad2013bbfe52ac2cb792
Merge branch 'master' into temp-sculpt-roll-mapping
===================================================================
===================================================================
diff --cc release/datafiles/locale
index 7084c4ecd97,f1425d8a7fc..08b372721b9
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit 7084c4ecd97d93459d9d23fd90f81589b09be5df
-Subproject commit f1425d8a7fc38e8111c2a9e125f0e7877dcd0fdf
++Subproject commit 08b372721b9b33a16f380cab23b2e5ded738ea96
diff --cc release/scripts/addons
index a9d4443c244,c0a678d3686..d887a4ea6b2
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit a9d4443c244f89399ec4bcc427e05a07950528cc
-Subproject commit c0a678d3686a591eb3041cc72b60aec2857d389a
++Subproject commit d887a4ea6b2a9d64b926034d4e78ecf7a48ca979
diff --cc source/blender/blenlib/BLI_even_spline.hh
index dea44756ca4,00000000000..ae019808afe
mode 100644,000000..100644
--- a/source/blender/blenlib/BLI_even_spline.hh
+++ b/source/blender/blenlib/BLI_even_spline.hh
@@@ -1,777 -1,0 +1,777 @@@
+#pragma once
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_compiler_compat.h"
+
+#include "BLI_math.h"
- #include "BLI_math_vec_types.hh"
++#include "BLI_math_vector_types.hh"
+#include "BLI_vector.hh"
+
+#include <algorithm>
+#include <cstdio>
+#include <type_traits>
+#include <utility>
+
+//#define FINITE_DIFF
+
+/*
+ * Arc length parameterized spline library.
+ */
+namespace blender {
+/*
+ Abstract curve interface. Curves must be
+ arc length parameterized (evenly spaced,
+ length of first derivative vector is 1).
+
+ We get a nice set of properties by using
+ arc length parameterizion.
+
+ * Even spacing.
+ * Second derivative is the curve normal multiplied by the curvature
+ * Easy to calculate torsion for space curves (though this hasn't been
+ implemented yet).
+
+ Look up the Frenet-Serret formulas for more info.
+
+ Abstract class interface:
+
+ template<typename Float> class Curve {
- using Vector = vec_base<Float, 2>;
++ using Vector = VecBase<Float, 2>;
+
+ public:
+ Float length;
+
+ Vector evaluate(Float s);
+ Vector derivative(Float s);
+ Vector derivative2(Float s);
+
+ Float curvature(float s);
+ Float dcurvature(float s); // Derivative of curvature.
+
+ void update();
+ };
+
+*/
+
+/** Cubic curves */
+
+template<typename Float, int axes = 2, int table_size = 512> class CubicBezier {
- using Vector = vec_base<Float, axes>;
++ using Vector = VecBase<Float, axes>;
+
+ public:
+ Vector ps[4];
+
+ static const int TableSize = table_size;
+
+ CubicBezier(Vector a, Vector b, Vector c, Vector d)
+ {
+ ps[0] = a;
+ ps[1] = b;
+ ps[2] = c;
+ ps[3] = d;
+
+ deleted = false;
+ _arc_to_t = new Float[table_size];
+ }
+
+ ~CubicBezier()
+ {
+ deleted = true;
+
+ if (_arc_to_t) {
+ delete[] _arc_to_t;
+ _arc_to_t = nullptr;
+ }
+ }
+
+ CubicBezier()
+ {
+ deleted = false;
+ _arc_to_t = new Float[table_size];
+ }
+
+ CubicBezier(const CubicBezier &b)
+ {
+ _arc_to_t = new Float[table_size];
+ *this = b;
+ deleted = false;
+ }
+
+ CubicBezier &operator=(const CubicBezier &b)
+ {
+ ps[0] = b.ps[0];
+ ps[1] = b.ps[1];
+ ps[2] = b.ps[2];
+ ps[3] = b.ps[3];
+
+ length = b.length;
+
+ if (!_arc_to_t) {
+ _arc_to_t = new Float[table_size];
+ }
+
+ if (b._arc_to_t) {
+ for (int i = 0; i < table_size; i++) {
+ _arc_to_t[i] = b._arc_to_t[i];
+ }
+ }
+
+ return *this;
+ }
+
+ CubicBezier(CubicBezier &&b)
+ {
+ *this = b;
+ }
+
+ CubicBezier &operator=(CubicBezier &&b)
+ {
+ ps[0] = b.ps[0];
+ ps[1] = b.ps[1];
+ ps[2] = b.ps[2];
+ ps[3] = b.ps[3];
+
+ length = b.length;
+
+ if (b._arc_to_t) {
+ _arc_to_t = std::move(b._arc_to_t);
+ b._arc_to_t = nullptr;
+ }
+ else {
+ _arc_to_t = new Float[table_size];
+ }
+
+ return *this;
+ }
+
+ Float length;
+
+ /* Update arc length -> parameterization table. */
+ void update()
+ {
+ Float t = 0.0, dt = 1.0 / (Float)table_size;
+ Float s = 0.0;
+
+ if (!_arc_to_t) {
+ _arc_to_t = new Float[table_size];
+ }
+
+ for (int i = 0; i < table_size; i++) {
+ _arc_to_t[i] = -1.0;
+ }
+
+ length = 0.0;
+
+ for (int i = 0; i < table_size; i++, t += dt) {
+ Float dlen = 0.0;
+ for (int j = 0; j < axes; j++) {
+ float dv = dcubic(ps[0][j], ps[1][j], ps[2][j], ps[3][j], t);
+
+ dlen += dv * dv;
+ }
+
+ dlen = sqrt(dlen) * dt;
+
+ length += dlen;
+ }
+
+ const int samples = table_size;
+ dt = 1.0 / (Float)samples;
+
+ t = 0.0;
+ s = 0.0;
+
+ for (int i = 0; i < samples; i++, t += dt) {
+ Float dlen = 0.0;
+ for (int j = 0; j < axes; j++) {
+ float dv = dcubic(ps[0][j], ps[1][j], ps[2][j], ps[3][j], t);
+
+ dlen += dv * dv;
+ }
+
+ dlen = sqrt(dlen) * dt;
+
+ int j = (int)((s / length) * (Float)table_size * 0.999999);
+ j = min_ii(j, table_size - 1);
+
+ _arc_to_t[j] = t;
+
+ s += dlen;
+ }
+
+ _arc_to_t[0] = 0.0;
+ _arc_to_t[table_size - 1] = 1.0;
+
+ /* Interpolate gaps in table. */
+ for (int i = 0; i < table_size - 1; i++) {
+ if (_arc_to_t[i] == -1.0 || _arc_to_t[i + 1] != -1.0) {
+ continue;
+ }
+
+ int i1 = i;
+ int i2 = i + 1;
+
+ while (_arc_to_t[i2] == -1.0) {
+ i2++;
+ }
+
+ Float start = _arc_to_t[i1];
+ Float end = _arc_to_t[i2];
+ Float dt2 = 1.0 / (i2 - i1);
+
+ for (int j = i1 + 1; j < i2; j++) {
+ Float factor = (Float)(j - i1) * dt2;
+ _arc_to_t[j] = start + (end - start) * factor;
+ }
+
+ i = i2 - 1;
+ }
+ }
+
+ inline Vector evaluate(Float s)
+ {
+ Float t = arc_to_t(s);
+ Vector r;
+
+ for (int i = 0; i < axes; i++) {
+ r[i] = cubic(ps[0][i], ps[1][i], ps[2][i], ps[3][i], t);
+ }
+
+ return r;
+ }
+
+ Vector derivative(Float s, bool exact = true)
+ {
+ Float t = arc_to_t(s);
+ Vector r;
+
+ for (int i = 0; i < axes; i++) {
+ r[i] = dcubic(ps[0][i], ps[1][i], ps[2][i], ps[3][i], t) * length;
+ }
+
+ /* Real arc length parameterized tangent has unit length. */
+ if (exact) {
+ Float len = sqrt(_dot(r, r));
+
+ /* Use FLT_EPSILON here? */
+ if (len > 0.00001) {
+ r = r / len;
+ }
+ }
+
+ return r;
+ }
+
+ Vector derivative2(Float s)
+ {
+#ifdef FINITE_DIFF
+ const Float df = 0.0005;
+ Float s1, s2;
+
+ if (s >= 1.0 - df) {
+ s1 = s - df;
+ s2 = s;
+ }
+ else {
+ s1 = s;
+ s2 = s + df;
+ }
+
+ Vector a = derivative(s1);
+ Vector b = derivative(s2);
+
+ return (b - a) / df;
+#else
+ Float t = arc_to_t(s);
+ Vector r;
+
+ Float dx = dcubic(ps[0][0], ps[1][0], ps[2][0], ps[3][0], t);
+ Float d2x = d2cubic(ps[0][0], ps[1][0], ps[2][0], ps[3][0], t);
+ Float dy = dcubic(ps[0][1], ps[1][1], ps[2][1], ps[3][1], t);
+ Float d2y = d2cubic(ps[0][1], ps[1][1], ps[2][1], ps[3][1], t);
+
+ /* reduce algebra script
+ comment: arc length second derivative;
+
+ comment: build arc length from abstract derivative operators;
+
+ operator x, y, z, dx, dy, dz, d2x, d2y, d2z;
+
+ forall t let df(x(t), t) = dx(t);
+ forall t let df(y(t), t) = dy(t);
+ forall t let df(z(t), t) = dz(t);
+ forall t let df(dx(t), t) = d2x(t);
+ forall t let df(dy(t), t) = d2y(t);
+ forall t let df(dz(t), t) = d2z(t);
+
+ comment: arc length first derivative is just the normalized tangent;
+
+ comment: 2d case;
+ dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2);
+
+ comment: final derivatives;
+ df(df(x(t), t) / dlen, t);
+ df(df(y(t), t) / dlen, t);
+
+ comment: 3d case;
+ dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2 + df(z(t), t)**2);
+
+ comment: final derivatives;
+ df(df(x(t), t) / dlen, t);
+ df(df(y(t), t) / dlen, t);
+ df(df(z(t), t) / dlen, t);
+ */
+
+ if constexpr (axes == 2) {
+ /* Basically the 2d perpidicular normalized tangent multiplied by the curvature. */
+ Float div = sqrt(dx * dx + dy * dy) * (dx * dx + dy * dy);
+
+ r[0] = ((d2x * dy - d2y * dx) * dy) / div;
+ r[1] = (-(d2x * dy - d2y * dx) * dx) / div;
+ }
+ else if constexpr (axes == 3) {
+ Float dz = dcubic(ps[0][2], ps[1][2], ps[2][2], ps[3][2], t);
+ Float d2z = d2cubic(ps[0][2], ps[1][2], ps[2][2], ps[3][2], t);
+
+ Float div = sqrt(dx * dx + dy * dy + dz * dz) * (dy * dy + dz * dz + dx * dx);
+
+ r[0] = (d2x * dy * dy + d2x * dz * dz - d2y * dx * dy - d2z * dx * dz) / div;
+ r[1] = (-(d2x * dx * dy - d2y * dx * dx - d2y * dz * dz + d2z * dy * dz)) / div;
+ r[2] = (-(d2x * dx * dz + d2y * dy * dz - d2z * dx * dx - d2z * dy * dy)) / div;
+ }
+ else {
+ for (int i = 0; i < axes; i++) {
+ r[i] = d2cubic(ps[0][i], ps[1][i], ps[2][i], ps[3][i], t) * length;
+ }
+ }
+
+ return r;
+#endif
+ }
+
+ Float curvature(Float s)
+ {
+ Vector dv2 = derivative2(s);
+
+ if constexpr (axes == 2) {
+ Vector dv = derivative(s, true);
+
+ /* Calculate signed curvature. Remember that dv is normalized. */
+ return dv[0] * dv2[1] - dv[1] * dv2[0];
+ }
+
+ return sqrt(_dot(dv2, dv2));
+ }
+
+ /* First derivative of curvature. */
+ Float dcurvature(Float s)
+ {
+ const Float ds = 0.0001;
+ Float s1, s2;
+
+ if (s > 1.0 - ds) {
+ s1 = s - ds;
+ s2 = s;
+ }
+ else {
+ s1 = s;
+ s2 = s + ds;
+ }
+
+ Float a = curvature(s1);
+ Float b = curvature(s2);
+
+ return (b - a) / ds;
+ }
+
+ private:
+ Float *_arc_to_t;
+ bool deleted = false;
+
+ /* Bernstein/bezier polynomial.*/
+ Float cubic(Float k1, Float k2, Float k3, Float k4, Float t)
+ {
+ return -(((3.0 * (t - 1.0) * k3 - k4 * t) * t - 3.0 * (t - 1.0) * (t - 1.0) * k2) * t +
+ (
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list