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:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2022-03-02 17:22:19 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2022-03-02 17:22:19 +0300
commit3a0df7d37bcf55b2b0f9a070d5c80f908e46ebc4 (patch)
tree01e256d9f853dbed48217c0ce95b8cc2946a3031 /source/blender/blenkernel
parent47396ea81edba585cc69c5760703cde727bc08a6 (diff)
parent6883c47bb5930be5a95d1c2e8e06fce2d3b68681 (diff)
Merge remote-tracking branch 'origin/blender-v3.1-release'
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_subdiv_mesh.h9
-rw-r--r--source/blender/blenkernel/intern/subdiv_mesh.c48
2 files changed, 37 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_subdiv_mesh.h b/source/blender/blenkernel/BKE_subdiv_mesh.h
index ede7ae60dc9..b24db517143 100644
--- a/source/blender/blenkernel/BKE_subdiv_mesh.h
+++ b/source/blender/blenkernel/BKE_subdiv_mesh.h
@@ -14,6 +14,7 @@ extern "C" {
#endif
struct Mesh;
+struct MEdge;
struct Subdiv;
typedef struct SubdivToMeshSettings {
@@ -33,6 +34,14 @@ struct Mesh *BKE_subdiv_to_mesh(struct Subdiv *subdiv,
const SubdivToMeshSettings *settings,
const struct Mesh *coarse_mesh);
+/* Interpolate a position along the `coarse_edge` at the relative `u` coordinate. If `is_simple` is
+ * false, this will perform a B-Spline interpolation using the edge neighbors, otherwise a linear
+ * interpolation will be done base on the edge vertices. */
+void BKE_subdiv_mesh_interpolate_position_on_edge(const struct Mesh *coarse_mesh,
+ const struct MEdge *coarse_edge,
+ bool is_simple,
+ float u,
+ float pos_r[3]);
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/subdiv_mesh.c b/source/blender/blenkernel/intern/subdiv_mesh.c
index 50135110a64..953f040fa0d 100644
--- a/source/blender/blenkernel/intern/subdiv_mesh.c
+++ b/source/blender/blenkernel/intern/subdiv_mesh.c
@@ -930,11 +930,10 @@ static void subdiv_mesh_vertex_loose(const SubdivForeachContext *foreach_context
/* Get neighbor edges of the given one.
* - neighbors[0] is an edge adjacent to edge->v1.
* - neighbors[1] is an edge adjacent to edge->v2. */
-static void find_edge_neighbors(const SubdivMeshContext *ctx,
+static void find_edge_neighbors(const Mesh *coarse_mesh,
const MEdge *edge,
const MEdge *neighbors[2])
{
- const Mesh *coarse_mesh = ctx->coarse_mesh;
const MEdge *coarse_medge = coarse_mesh->medge;
neighbors[0] = NULL;
neighbors[1] = NULL;
@@ -964,12 +963,11 @@ static void find_edge_neighbors(const SubdivMeshContext *ctx,
}
}
-static void points_for_loose_edges_interpolation_get(SubdivMeshContext *ctx,
+static void points_for_loose_edges_interpolation_get(const Mesh *coarse_mesh,
const MEdge *coarse_edge,
const MEdge *neighbors[2],
float points_r[4][3])
{
- const Mesh *coarse_mesh = ctx->coarse_mesh;
const MVert *coarse_mvert = coarse_mesh->mvert;
/* Middle points corresponds to the edge. */
copy_v3_v3(points_r[1], coarse_mvert[coarse_edge->v1].co);
@@ -1002,6 +1000,30 @@ static void points_for_loose_edges_interpolation_get(SubdivMeshContext *ctx,
}
}
+void BKE_subdiv_mesh_interpolate_position_on_edge(const Mesh *coarse_mesh,
+ const MEdge *coarse_edge,
+ const bool is_simple,
+ const float u,
+ float pos_r[3])
+{
+ if (is_simple) {
+ const MVert *coarse_mvert = coarse_mesh->mvert;
+ const MVert *vert_1 = &coarse_mvert[coarse_edge->v1];
+ const MVert *vert_2 = &coarse_mvert[coarse_edge->v2];
+ interp_v3_v3v3(pos_r, vert_1->co, vert_2->co, u);
+ }
+ else {
+ /* Find neighbors of the coarse edge. */
+ const MEdge *neighbors[2];
+ find_edge_neighbors(coarse_mesh, coarse_edge, neighbors);
+ float points[4][3];
+ points_for_loose_edges_interpolation_get(coarse_mesh, coarse_edge, neighbors, points);
+ float weights[4];
+ key_curve_position_weights(u, weights, KEY_BSPLINE);
+ interp_v3_v3v3v3v3(pos_r, points[0], points[1], points[2], points[3], weights);
+ }
+}
+
static void subdiv_mesh_vertex_of_loose_edge_interpolate(SubdivMeshContext *ctx,
const MEdge *coarse_edge,
const float u,
@@ -1038,9 +1060,6 @@ static void subdiv_mesh_vertex_of_loose_edge(const struct SubdivForeachContext *
Mesh *subdiv_mesh = ctx->subdiv_mesh;
MVert *subdiv_mvert = subdiv_mesh->mvert;
const bool is_simple = ctx->subdiv->settings.is_simple;
- /* Find neighbors of the current loose edge. */
- const MEdge *neighbors[2];
- find_edge_neighbors(ctx, coarse_edge, neighbors);
/* Interpolate custom data when not an end point.
* This data has already been copied from the original vertex by #subdiv_mesh_vertex_loose. */
if (!ELEM(u, 0.0, 1.0)) {
@@ -1048,19 +1067,8 @@ static void subdiv_mesh_vertex_of_loose_edge(const struct SubdivForeachContext *
}
/* Interpolate coordinate. */
MVert *subdiv_vertex = &subdiv_mvert[subdiv_vertex_index];
- if (is_simple) {
- const MVert *coarse_mvert = coarse_mesh->mvert;
- const MVert *vert_1 = &coarse_mvert[coarse_edge->v1];
- const MVert *vert_2 = &coarse_mvert[coarse_edge->v2];
- interp_v3_v3v3(subdiv_vertex->co, vert_1->co, vert_2->co, u);
- }
- else {
- float points[4][3];
- points_for_loose_edges_interpolation_get(ctx, coarse_edge, neighbors, points);
- float weights[4];
- key_curve_position_weights(u, weights, KEY_BSPLINE);
- interp_v3_v3v3v3v3(subdiv_vertex->co, points[0], points[1], points[2], points[3], weights);
- }
+ BKE_subdiv_mesh_interpolate_position_on_edge(
+ coarse_mesh, coarse_edge, is_simple, u, subdiv_vertex->co);
/* Reset flags and such. */
subdiv_vertex->flag = 0;
/* TODO(sergey): This matches old behavior, but we can as well interpolate