[Bf-blender-cvs] [cd79bf179d1] soc-2021-curve-fillet: Cleanup: Commenting and minor refactoring
dilithjay
noreply at git.blender.org
Tue Jul 20 04:45:16 CEST 2021
Commit: cd79bf179d17ea64b6d13d48bb1dd15fdaf4d5c8
Author: dilithjay
Date: Tue Jul 20 08:13:16 2021 +0530
Branches: soc-2021-curve-fillet
https://developer.blender.org/rBcd79bf179d17ea64b6d13d48bb1dd15fdaf4d5c8
Cleanup: Commenting and minor refactoring
===================================================================
M release/datafiles/locale
M release/scripts/addons
M source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
===================================================================
diff --git a/release/datafiles/locale b/release/datafiles/locale
index 1ab25ca4f20..f3791fbfdb8 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 1ab25ca4f208edc8fb6c3551b3050ce3ad50ad7c
+Subproject commit f3791fbfdb839860035241ba477bf8872966af93
diff --git a/release/scripts/addons b/release/scripts/addons
index e1f331e0af4..9791dfef7f7 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit e1f331e0af4461dbf80e03e76d9576fa748a0460
+Subproject commit 9791dfef7f73f20a1b8d4bbeac638accc71ce8e1
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
index 8a66c1d4b61..15c066ba5a6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
@@ -74,12 +74,13 @@ struct FilletModeParam {
/* The radius of the formed circle */
std::optional<float> radius;
- /* Distribution of radii on the curve. */
+ /* Distribution of radii on the spline. */
std::optional<std::string> radii_dist;
GVArray_Typed<float> *radii{};
};
+/* A data structure used to store fillet data about a vertex in the source spline. */
struct FilletData {
float3 prev_dir, pos, next_dir, axis;
float radius;
@@ -109,11 +110,7 @@ static void geo_node_curve_fillet_update(bNodeTree *UNUSED(ntree), bNode *node)
radius_mode == GEO_NODE_CURVE_FILLET_RADIUS_ATTRIBUTE);
}
-static int get_point_count(float3 prev_pos, float3 pos, float3 next_pos, float arc_angle)
-{
- return 1;
-}
-
+/* Function to get the center of a fillet. */
static float3 get_center(const float3 vec_pos2prev,
const float3 pos,
const float3 axis,
@@ -126,6 +123,7 @@ static float3 get_center(const float3 vec_pos2prev,
return vec_pos2center + pos;
}
+/* Function to get the center of the fillet using fillet data */
static float3 get_center(const float3 vec_pos2prev, const FilletData &fd)
{
float angle = fd.angle;
@@ -135,6 +133,7 @@ static float3 get_center(const float3 vec_pos2prev, const FilletData &fd)
return get_center(vec_pos2prev, pos, axis, angle);
}
+/* Function to calculate fillet data for each vertex. */
static FilletData calculate_fillet_data_per_vertex(const float3 prev_pos,
const float3 pos,
const float3 next_pos,
@@ -156,6 +155,7 @@ static FilletData calculate_fillet_data_per_vertex(const float3 prev_pos,
return fd;
}
+/* Function to calculate and obtain the fillet data for the entire spline. */
static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
const FilletModeParam &mode_param,
int &added_count,
@@ -164,6 +164,7 @@ static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
Span<float3> positions = spline->positions();
int fillet_count, start = 0, size = spline->size();
+ /* Determine the number of vertices that can be filleted. */
bool cyclic = spline->is_cyclic();
if (!cyclic) {
fillet_count = size - 2;
@@ -176,6 +177,7 @@ static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
Array<FilletData> fds(fillet_count);
for (const int i : IndexRange(fillet_count)) {
+ /* Find the positions of the adjacent vertices. */
float3 prev_pos, pos, next_pos;
if (cyclic) {
prev_pos = positions[i == 0 ? positions.size() - 1 : i - 1];
@@ -188,6 +190,7 @@ static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
next_pos = positions[i + 2];
}
+ /* Define the radius. */
float radius = 0.0f;
if (mode_param.radius_mode == GEO_NODE_CURVE_FILLET_RADIUS_FLOAT) {
radius = mode_param.radius.value();
@@ -201,16 +204,18 @@ static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
}
}
+ /* Calculate fillet data for the vertex. */
fds[i] = calculate_fillet_data_per_vertex(
prev_pos, pos, next_pos, mode_param.angle, mode_param.count, radius);
+ /* Exit from here if the radius is zero */
if (!radius) {
continue;
}
+ /* Calculate number of points to be added for the vertex. */
int count = 0;
if (mode_param.mode == GEO_NODE_CURVE_FILLET_ADAPTIVE) {
- // temp
count = ceil(fds[i].angle / mode_param.angle.value());
}
else if (mode_param.mode == GEO_NODE_CURVE_FILLET_USER_DEFINED) {
@@ -224,6 +229,8 @@ static Array<FilletData> calculate_fillet_data(const SplinePtr &spline,
return fds;
}
+/* Create a mapping from each vertex in the resulting spline to that of the source spline.
+Used for copying the data from the source spline.*/
static Array<int> create_dst_to_src_map(const Array<int> point_counts, const int total_points)
{
Array<int> map(total_points);
@@ -241,6 +248,7 @@ static Array<int> create_dst_to_src_map(const Array<int> point_counts, const int
return map;
}
+/* Copy attribute data from source spline's Span to destination spline's Span. */
template<typename T>
static void copy_attribute_by_mapping(const Span<T> src, MutableSpan<T> dst, Array<int> mapping)
{
@@ -249,6 +257,7 @@ static void copy_attribute_by_mapping(const Span<T> src, MutableSpan<T> dst, Arr
}
}
+/* Copy all attributes in Bezier curves. */
static void copy_bezier_attributes_by_mapping(const BezierSpline &src,
BezierSpline &dst,
Array<int> mapping)
@@ -262,6 +271,7 @@ static void copy_bezier_attributes_by_mapping(const BezierSpline &src,
copy_attribute_by_mapping(src.handle_positions_right(), dst.handle_positions_right(), mapping);
}
+/* Copy all attributes in Poly curves. */
static void copy_poly_attributes_by_mapping(const PolySpline &src,
PolySpline &dst,
Array<int> mapping)
@@ -271,49 +281,60 @@ static void copy_poly_attributes_by_mapping(const PolySpline &src,
copy_attribute_by_mapping(src.tilts(), dst.tilts(), mapping);
}
+/* Update the positions and handle positions of a Bezier spline based on fillet data. */
static void update_bezier_positions(Array<FilletData> &fds,
Array<int> &point_counts,
BezierSpline &dst_spline,
int start,
int fillet_count)
{
- int next_i = start;
+ int cur_i = start;
for (const int i : IndexRange(start, fillet_count)) {
FilletData fd = fds[i - start];
int count = point_counts[i];
+
+ /* Skip if the point count for the vertex is 1. */
if (count == 1) {
- next_i++;
+ cur_i++;
continue;
}
+ /* Calculate the angle to be formed between any 2 adjacent vertices within the fillet. */
float segment_angle = fd.angle / (count - 1);
+ /* Calculate the handle length for each added vertex. Equation: L = 4R/3 * tan(A/4) */
float handle_length = 4.0f * fd.radius / 3 * tanf(segment_angle / 4);
+ /* Calculate the distance by which each vertex should be displaced from their initial position.
+ */
float displacement = fd.radius * tanf(fd.angle / 2);
- /* Position the end points of the arc. */
- int end_i = next_i + count - 1;
- dst_spline.positions()[next_i] = fd.pos + displacement * fd.prev_dir;
+ /* Position the end points of the arc and their handles. */
+ int end_i = cur_i + count - 1;
+ dst_spline.positions()[cur_i] = fd.pos + displacement * fd.prev_dir;
dst_spline.positions()[end_i] = fd.pos + displacement * fd.next_dir;
- dst_spline.handle_positions_right()[next_i] = dst_spline.positions()[next_i] -
- handle_length * fd.prev_dir;
+ dst_spline.handle_positions_right()[cur_i] = dst_spline.positions()[cur_i] -
+ handle_length * fd.prev_dir;
dst_spline.handle_positions_left()[end_i] = dst_spline.positions()[end_i] -
handle_length * fd.next_dir;
-
- dst_spline.handle_types_right()[next_i] = dst_spline.handle_types_left()[end_i] =
+ dst_spline.handle_types_right()[cur_i] = dst_spline.handle_types_left()[end_i] =
BezierSpline::HandleType::Align;
- float3 center = get_center(dst_spline.positions()[next_i] - fd.pos, fd);
- float3 radius_vec = dst_spline.positions()[next_i] - center;
+ /* Calculate the center of the radius to be formed. */
+ float3 center = get_center(dst_spline.positions()[cur_i] - fd.pos, fd);
+ /* Calculate the vector of the radius formed by the first vertex. */
+ float3 radius_vec = dst_spline.positions()[cur_i] - center;
+ /* For each of the vertices in between the end points. */
for (int j = 1; j < count - 1; j++) {
- int index = next_i + j;
+ int index = cur_i + j;
+ /* Rotate the radius by the segment angle and determine its tangent (used for getting handle
+ * directions). */
float3 new_radius_vec, tangent_vec;
rotate_v3_v3v3fl(new_radius_vec, radius_vec, -fd.axis, segment_angle);
rotate_v3_v3v3fl(tangent_vec, new_radius_vec, fd.axis, M_PI_2);
radius_vec = new_radius_vec;
-
normalize_v3_length(tangent_vec, handle_length);
+ /* Adjust the positions of the respective vertex and its handles. */
dst_spline.positions()[index] = center + new_radius_vec;
dst_spline.handle_types_right()[index] = dst_spline.handle_types_right()[index] =
BezierSpline::HandleType::Align;
@@ -321,22 +342,25 @@ static void update_bezier_positions(Array<FilletData> &fds,
dst_spline.handle_positions_right()[index] = dst_spline.positions()[index] - tangent_vec;
}
- next_i += count;
+ cur_i += count;
}
}
+/* Update the positions of a Poly spline based on fillet data. */
static void upd
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list