[Bf-blender-cvs] [e1cef1b85db] geometry-nodes-curve-support: A bit of progress

Hans Goudey noreply at git.blender.org
Thu Apr 1 00:49:57 CEST 2021


Commit: e1cef1b85db089e4ba1e969a593605581251254c
Author: Hans Goudey
Date:   Tue Mar 30 06:54:33 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBe1cef1b85db089e4ba1e969a593605581251254c

A bit of progress

===================================================================

M	release/scripts/startup/nodeitems_builtins.py
A	source/blender/blenkernel/BKE_derived_curve.hh
M	source/blender/blenkernel/BKE_geometry_set.h
M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/attribute_access.cc
A	source/blender/blenkernel/intern/derived_curve.cc
A	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
M	source/blender/nodes/geometry/nodes/node_geo_transform.cc

===================================================================

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 7e887caf3f2..7f8a5f6de02 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -504,6 +504,9 @@ geometry_node_categories = [
         NodeItem("ShaderNodeSeparateRGB"),
         NodeItem("ShaderNodeCombineRGB"),
     ]),
+    GeometryNodeCategory("GEO_CURVE", "Curve", items=[
+        NodeItem("GeometryNodeCurveToMesh"),
+    ]),
     GeometryNodeCategory("GEO_GEOMETRY", "Geometry", items=[
         NodeItem("GeometryNodeTransform"),
         NodeItem("GeometryNodeJoinGeometry"),
diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
new file mode 100644
index 00000000000..35f9a6417c8
--- /dev/null
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -0,0 +1,121 @@
+/*
+ * 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 "BLI_float3.hh"
+#include "BLI_vector.hh"
+
+#include "BKE_curve.h"
+
+struct Curve;
+
+enum class BezierHandleType {
+  Free,
+  Auto,
+  Vector,
+  Align,
+};
+
+struct ControlPoint {
+  blender::float3 position;
+  float radius;
+  /* User defined tilt in radians, added on top of the auto-calculated tilt. */
+  float tilt;
+};
+
+struct ControlPointBezier : ControlPoint {
+  blender::float3 handle_position_a;
+  blender::float3 handle_position_b;
+  BezierHandleType handle_type_a;
+  BezierHandleType handle_type_b;
+};
+
+struct ControlPointNURBS : ControlPoint {
+  blender::float3 position;
+  float radius;
+  float weight;
+};
+
+enum class SplineType {
+  Bezier,
+  Poly,
+  NURBS,
+};
+
+struct Spline {
+  SplineType type;
+
+  virtual int size() const = 0;
+};
+
+struct SplineBezier : Spline {
+  blender::Vector<ControlPointBezier> control_points;
+
+  blender::Vector<blender::float3> handle_positions_a;
+  blender::Vector<blender::float3> positions;
+  blender::Vector<blender::float3> handle_positions_b;
+
+  blender::Vector<BezierHandleType> handle_type_a;
+  blender::Vector<BezierHandleType> handle_type_b;
+
+  int32_t flag; /* Cyclic, smooth. */
+  int32_t resolution_u;
+  int32_t resolution_v;
+
+  int size() const final
+  {
+    return control_points.size();
+  }
+};
+
+struct SplineNURBS : Spline {
+  blender::Vector<ControlPointNURBS> control_points;
+  int32_t flag; /* Cyclic, smooth. */
+  int32_t resolution_u;
+  int32_t resolution_v;
+  uint8_t order;
+
+  int size() const final
+  {
+    return control_points.size();
+  }
+};
+
+/* Proposed name to be different from DNA type. */
+struct DCurve {
+  blender::Vector<Spline *> splines;
+  //   AttributeStorage attributes;
+  int32_t flag; /* 2D. */
+
+  /* Attributes. */
+  //   CustomData *control_point_data;
+  //   CustomData *spline_data;
+
+  /* Then maybe whatever caches are necessary, etc. */
+  //   std::mutex cache_mutex;
+  blender::Vector<blender::float3> evaluated_spline_cache;
+
+  void ensure_evaluation_cache();
+
+  DCurve from_dna_curve(const Curve &curve);
+};
diff --git a/source/blender/blenkernel/BKE_geometry_set.h b/source/blender/blenkernel/BKE_geometry_set.h
index 08b4a25d946..9dcbca4e09f 100644
--- a/source/blender/blenkernel/BKE_geometry_set.h
+++ b/source/blender/blenkernel/BKE_geometry_set.h
@@ -36,6 +36,7 @@ typedef enum GeometryComponentType {
   GEO_COMPONENT_TYPE_POINT_CLOUD = 1,
   GEO_COMPONENT_TYPE_INSTANCES = 2,
   GEO_COMPONENT_TYPE_VOLUME = 3,
+  GEO_COMPONENT_TYPE_CURVE = 4,
 } GeometryComponentType;
 
 void BKE_geometry_set_free(struct GeometrySet *geometry_set);
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 8cc37a3e711..db43e6e300d 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -39,6 +39,7 @@ struct Mesh;
 struct Object;
 struct PointCloud;
 struct Volume;
+struct DCurve;
 
 enum class GeometryOwnershipType {
   /* The geometry is owned. This implies that it can be changed. */
@@ -324,17 +325,23 @@ struct GeometrySet {
   bool has_pointcloud() const;
   bool has_instances() const;
   bool has_volume() const;
+  bool has_curve() const;
+
   const Mesh *get_mesh_for_read() const;
   const PointCloud *get_pointcloud_for_read() const;
   const Volume *get_volume_for_read() const;
+  const DCurve *get_curve_for_read() const;
+
   Mesh *get_mesh_for_write();
   PointCloud *get_pointcloud_for_write();
   Volume *get_volume_for_write();
+  DCurve *get_curve_for_write();
 
   /* Utility methods for replacement. */
   void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
   void replace_pointcloud(PointCloud *pointcloud,
                           GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
+  void replace_curve(DCurve *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
 };
 
 /** A geometry component that can store a mesh. */
@@ -408,6 +415,34 @@ class PointCloudComponent : public GeometryComponent {
   const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
 };
 
+class CurveComponent : public GeometryComponent {
+ private:
+  DCurve *curve_ = nullptr;
+  GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
+
+ public:
+  CurveComponent();
+  ~CurveComponent();
+  GeometryComponent *copy() const override;
+
+  void clear();
+  bool has_curve() const;
+  void replace(DCurve *pointcloud, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
+  DCurve *release();
+
+  const DCurve *get_for_read() const;
+  DCurve *get_for_write();
+
+  int attribute_domain_size(const AttributeDomain domain) const final;
+
+  bool is_empty() const final;
+
+  static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_CURVE;
+
+ private:
+  const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
+};
+
 /** A geometry component that stores instances. */
 class InstancesComponent : public GeometryComponent {
  private:
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 42ed026cb01..c5984b6cdd0 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1399,6 +1399,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_MESH_PRIMITIVE_GRID 1039
 #define GEO_NODE_ATTRIBUTE_MAP_RANGE 1040
 #define GEO_NODE_ATTRIBUTE_CLAMP 1041
+#define GEO_NODE_CURVE_TO_MESH 1042
 
 /** \} */
 
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8fbf49b31d4..7396b1fe269 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -117,6 +117,7 @@ set(SRC
   intern/customdata_file.c
   intern/data_transfer.c
   intern/deform.c
+  intern/derived_curve.cc
   intern/displist.c
   intern/displist_tangent.c
   intern/dynamicpaint.c
@@ -133,6 +134,7 @@ set(SRC
   intern/fmodifier.c
   intern/font.c
   intern/freestyle.c
+  intern/geometry_component_curve.cc
   intern/geometry_component_instances.cc
   intern/geometry_component_mesh.cc
   intern/geometry_component_pointcloud.cc
@@ -321,6 +323,7 @@ set(SRC
   BKE_customdata_file.h
   BKE_data_transfer.h
   BKE_deform.h
+  BKE_derived_curve.hh
   BKE_displist.h
   BKE_displist_tangent.h
   BKE_duplilist.h
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 52f89ca302b..bbbd832fc9a 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -327,10 +327,8 @@ CustomDataType attribute_data_type_highest_complexity(Span<CustomDataType> data_
 static int attribute_domain_priority(const AttributeDomain domain)
 {
   switch (domain) {
-#if 0
     case ATTR_DOMAIN_CURVE:
       return 0;
-#endif
     case ATTR_DOMAIN_FACE:
       return 1;
     case ATTR_DOMAIN_EDGE:
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
new file mode 100644
index 00000000000..7e888ba7dc0
--- /dev/null
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+#include "BLI_array.hh"
+#include "BLI_listbase.h"
+#include "BLI_span.hh"
+
+#include "DNA_curve_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_derived_curve.hh"
+
+using blender::Array;
+using blender::float3;
+using blender::Span;
+
+static BezierHandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
+{
+  switch (dna_handle_type) {
+    case HD_FREE:
+      return BezierHandleType::Free;
+    case HD_AUTO:
+      return BezierHandleType::Auto;
+    ca

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list