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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-03-01 19:40:25 +0300
committerHans Goudey <h.goudey@me.com>2022-03-01 19:40:25 +0300
commitf98d74c80de7b1cae1e5a963f33c51c49f478ba1 (patch)
tree5144a2249410c0128d7e2780cb39e56aa5181ab2 /source/blender/editors
parent143bc9f8d4baf2a7312f3e836a464f74148c4a3b (diff)
Curves: Move curves primitive to object add code
Currently, any time a Curves data-block is created, the `curves_random` function runs, filling it with 500 random curves, also adding a radius attribute. This is just left over from the prototype in the initial commit that added the type. This commit moves the code that creates the random data to the curve editors module, like the other primitives are organized. Differential Revision: https://developer.blender.org/D14211
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/curves/CMakeLists.txt1
-rw-r--r--source/blender/editors/curves/intern/curves_add.cc57
-rw-r--r--source/blender/editors/include/ED_curves.h11
-rw-r--r--source/blender/editors/object/CMakeLists.txt1
-rw-r--r--source/blender/editors/object/object_add.cc6
5 files changed, 76 insertions, 0 deletions
diff --git a/source/blender/editors/curves/CMakeLists.txt b/source/blender/editors/curves/CMakeLists.txt
index 93b21a46916..1731d224b3e 100644
--- a/source/blender/editors/curves/CMakeLists.txt
+++ b/source/blender/editors/curves/CMakeLists.txt
@@ -14,6 +14,7 @@ set(INC
)
set(SRC
+ intern/curves_add.cc
intern/curves_ops.cc
)
diff --git a/source/blender/editors/curves/intern/curves_add.cc b/source/blender/editors/curves/intern/curves_add.cc
new file mode 100644
index 00000000000..9cde23451dc
--- /dev/null
+++ b/source/blender/editors/curves/intern/curves_add.cc
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup edcurves
+ */
+
+#include "BLI_rand.hh"
+
+#include "BKE_curves.hh"
+
+#include "ED_curves.h"
+
+namespace blender::ed::curves {
+
+bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int points_per_curve)
+{
+ bke::CurvesGeometry curves(points_per_curve * curves_size, curves_size);
+
+ MutableSpan<int> offsets = curves.offsets();
+ MutableSpan<float3> positions = curves.positions();
+
+ float *radius_data = (float *)CustomData_add_layer_named(
+ &curves.point_data, CD_PROP_FLOAT, CD_DEFAULT, nullptr, curves.point_size, "radius");
+ MutableSpan<float> radii{radius_data, curves.points_size()};
+
+ for (const int i : offsets.index_range()) {
+ offsets[i] = points_per_curve * i;
+ }
+
+ RandomNumberGenerator rng;
+
+ for (const int i : curves.curves_range()) {
+ const IndexRange curve_range = curves.range_for_curve(i);
+ MutableSpan<float3> curve_positions = positions.slice(curve_range);
+ MutableSpan<float> curve_radii = radii.slice(curve_range);
+
+ const float theta = 2.0f * M_PI * rng.get_float();
+ const float phi = saacosf(2.0f * rng.get_float() - 1.0f);
+
+ float3 no = {std::sin(theta) * std::sin(phi), std::cos(theta) * std::sin(phi), std::cos(phi)};
+ no = math::normalize(no);
+
+ float3 co = no;
+ for (int key = 0; key < points_per_curve; key++) {
+ float t = key / (float)(points_per_curve - 1);
+ curve_positions[key] = co;
+ curve_radii[key] = 0.02f * (1.0f - t);
+
+ float3 offset = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f;
+ co += (offset + no) / points_per_curve;
+ }
+ }
+
+ return curves;
+}
+
+} // namespace blender::ed::curves
diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h
index 7316b045646..706563061d4 100644
--- a/source/blender/editors/include/ED_curves.h
+++ b/source/blender/editors/include/ED_curves.h
@@ -15,3 +15,14 @@ void ED_operatortypes_curves(void);
#ifdef __cplusplus
}
#endif
+
+#ifdef __cplusplus
+
+# include "BKE_curves.hh"
+
+namespace blender::ed::curves {
+
+bke::CurvesGeometry primitive_random_sphere(int curves_size, int points_per_curve);
+
+}
+#endif \ No newline at end of file
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index a94387961ee..39ccadd1445 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -8,6 +8,7 @@ set(INC
../../blentranslation
../../bmesh
../../depsgraph
+ ../../functions
../../gpencil_modifiers
../../gpu
../../ikplugin
diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc
index 19db09961e8..7befad3b8d7 100644
--- a/source/blender/editors/object/object_add.cc
+++ b/source/blender/editors/object/object_add.cc
@@ -93,6 +93,7 @@
#include "ED_armature.h"
#include "ED_curve.h"
+#include "ED_curves.h"
#include "ED_gpencil.h"
#include "ED_mball.h"
#include "ED_mesh.h"
@@ -1899,6 +1900,8 @@ static bool object_hair_curves_add_poll(bContext *C)
static int object_hair_curves_add_exec(bContext *C, wmOperator *op)
{
+ using namespace blender;
+
ushort local_view_bits;
float loc[3], rot[3];
if (!ED_object_add_generic_get_opts(
@@ -1909,6 +1912,9 @@ static int object_hair_curves_add_exec(bContext *C, wmOperator *op)
Object *object = ED_object_add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits);
object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
+ Curves *curves_id = static_cast<Curves *>(object->data);
+ bke::CurvesGeometry::wrap(curves_id->geometry) = ed::curves::primitive_random_sphere(500, 8);
+
return OPERATOR_FINISHED;
}