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:
Diffstat (limited to 'source/blender/modifiers/intern/MOD_screw.c')
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 9588b9acd3b..d8b11c0e89e 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -52,13 +52,18 @@ static void initData(ModifierData *md)
#include "BLI_strict_flags.h"
-/* used for gathering edge connectivity */
+/** Used for gathering edge connectivity. */
typedef struct ScrewVertConnect {
- float dist; /* distance from the center axis */
- float co[3]; /* location relative to the transformed axis */
- float no[3]; /* calc normal of the vertex */
- uint v[2]; /* 2 verts on either side of this one */
- MEdge *e[2]; /* edges on either side, a bit of a waste since each edge ref's 2 edges */
+ /** Distance from the center axis. */
+ float dist_sq;
+ /** Location relative to the transformed axis. */
+ float co[3];
+ /** Calc normal of the vertex. */
+ float no[3];
+ /** 2 verts on either side of this one. */
+ uint v[2];
+ /** Edges on either side, a bit of a waste since each edge ref's 2 edges. */
+ MEdge *e[2];
char flag;
} ScrewVertConnect;
@@ -270,18 +275,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
axis_vec[ltmd->axis] = 1.0f;
if (ob_axis != NULL) {
- /* calc the matrix relative to the axis object */
+ /* Calculate the matrix relative to the axis object. */
invert_m4_m4(mtx_tmp_a, ctx->object->obmat);
copy_m4_m4(mtx_tx_inv, ob_axis->obmat);
mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv);
- /* calc the axis vec */
+ /* Calculate the axis vector. */
mul_mat3_m4_v3(mtx_tx, axis_vec); /* only rotation component */
normalize_v3(axis_vec);
/* screw */
if (ltmd->flag & MOD_SCREW_OBJECT_OFFSET) {
- /* find the offset along this axis relative to this objects matrix */
+ /* Find the offset along this axis relative to this objects matrix. */
float totlen = len_v3(mtx_tx[3]);
if (totlen != 0.0f) {
@@ -330,7 +335,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
else {
axis_char = (char)(axis_char + ltmd->axis); /* 'X' + axis */
- /* useful to be able to use the axis vec in some cases still */
+ /* Useful to be able to use the axis vector in some cases still. */
zero_v3(axis_vec);
axis_vec[ltmd->axis] = 1.0f;
}
@@ -393,7 +398,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
medge_new = result->medge;
if (!CustomData_has_layer(&result->pdata, CD_ORIGINDEX)) {
- CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, (int)maxPolys);
+ CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_SET_DEFAULT, NULL, (int)maxPolys);
}
int *origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
@@ -441,7 +446,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->crease = med_orig->crease;
med_new->flag = med_orig->flag & ~ME_LOOSEEDGE;
- /* Tag mvert as not loose. */
+ /* Tag #MVert as not loose. */
BLI_BITMAP_ENABLE(vert_tag, med_orig->v1);
BLI_BITMAP_ENABLE(vert_tag, med_orig->v2);
}
@@ -481,8 +486,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
if (ltmd->flag & MOD_SCREW_NORMAL_CALC) {
- /*
- * Normal Calculation (for face flipping)
+ /* Normal Calculation (for face flipping)
* Sort edge verts for correct face flipping
* NOT REALLY NEEDED but face flipping is nice. */
@@ -490,19 +494,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
*
* Since we are only ordering the edges here it can avoid mallocing the
* extra space by abusing the vert array before its filled with new verts.
- * The new array for vert_connect must be at least sizeof(ScrewVertConnect) * totvert
- * and the size of our resulting meshes array is sizeof(MVert) * totvert * 3
- * so its safe to use the second 2 thirds of MVert the array for vert_connect,
- * just make sure ScrewVertConnect struct is no more than twice as big as MVert,
+ * The new array for vert_connect must be at least `sizeof(ScrewVertConnect) * totvert`
+ * and the size of our resulting meshes array is `sizeof(MVert) * totvert * 3`
+ * so its safe to use the second 2 thirds of #MVert the array for vert_connect,
+ * just make sure #ScrewVertConnect struct is no more than twice as big as #MVert,
* at the moment there is no chance of that being a problem,
- * unless MVert becomes half its current size.
+ * unless #MVert becomes half its current size.
*
* once the edges are ordered, vert_connect is not needed and it can be used for verts
*
- * This makes the modifier faster with one less alloc.
+ * This makes the modifier faster with one less allocate.
*/
- vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), "ScrewVertConnect");
+ vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), __func__);
/* skip the first slice of verts. */
// vert_connect = (ScrewVertConnect *) &medge_new[totvert];
vc = vert_connect;
@@ -512,7 +516,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
if (!totedge) {
for (i = 0; i < totvert; i++, mv_orig++, mv_new++) {
copy_v3_v3(mv_new->co, mv_orig->co);
- normalize_v3_v3(vc->no, mv_new->co); /* no edges- this is really a dummy normal */
+ /* No edges: this is really a dummy normal. */
+ normalize_v3_v3(vc->no, mv_new->co);
}
}
else {
@@ -533,11 +538,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
vc->v[0] = vc->v[1] = SV_UNUSED;
mul_m4_v3(mtx_tx, vc->co);
- /* length in 2d, don't sqrt because this is only for comparison */
- vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] +
- vc->co[other_axis_2] * vc->co[other_axis_2];
+ /* Length in 2D, don't `sqrt` because this is only for comparison. */
+ vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] +
+ vc->co[other_axis_2] * vc->co[other_axis_2];
- // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist);
+ // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq);
}
}
else {
@@ -550,11 +555,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
vc->e[0] = vc->e[1] = NULL;
vc->v[0] = vc->v[1] = SV_UNUSED;
- /* length in 2d, don't sqrt because this is only for comparison */
- vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] +
- vc->co[other_axis_2] * vc->co[other_axis_2];
+ /* Length in 2D, don't sqrt because this is only for comparison. */
+ vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] +
+ vc->co[other_axis_2] * vc->co[other_axis_2];
- // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist);
+ // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq);
}
}
@@ -622,9 +627,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
lt_iter.v_poin->flag = 1;
vc_tot_linked++;
- // printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist);
- if (fl <= lt_iter.v_poin->dist) {
- fl = lt_iter.v_poin->dist;
+ // printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist_sq);
+ if (fl <= lt_iter.v_poin->dist_sq) {
+ fl = lt_iter.v_poin->dist_sq;
v_best = lt_iter.v;
// printf("\t\t\tVERT BEST: %i\n", v_best);
}
@@ -942,6 +947,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* more of an offset in this case */
edge_offset = totedge + (totvert * (step_tot - (close ? 0 : 1)));
+ const int *src_material_index = BKE_mesh_material_indices(mesh);
+ int *dst_material_index = BKE_mesh_material_indices_for_write(result);
+
for (i = 0; i < totedge; i++, med_new_firstloop++) {
const uint step_last = step_tot - (close ? 1 : 2);
const uint mpoly_index_orig = totpoly ? edge_poly_map[i] : UINT_MAX;
@@ -954,14 +962,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
};
const bool has_mloop_orig = mloop_index_orig[0] != UINT_MAX;
- short mat_nr;
+ int mat_nr;
/* for each edge, make a cylinder of quads */
i1 = med_new_firstloop->v1;
i2 = med_new_firstloop->v2;
if (has_mpoly_orig) {
- mat_nr = mpoly_orig[mpoly_index_orig].mat_nr;
+ mat_nr = src_material_index == NULL ? 0 : src_material_index[mpoly_index_orig];
}
else {
mat_nr = 0;
@@ -987,8 +995,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
else {
origindex[mpoly_index] = ORIGINDEX_NONE;
+ dst_material_index[mpoly_index] = mat_nr;
mp_new->flag = mpoly_flag;
- mp_new->mat_nr = mat_nr;
}
mp_new->loopstart = mpoly_index * 4;
mp_new->totloop = 4;
@@ -1148,7 +1156,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
ScrewModifierData *ltmd = (ScrewModifierData *)md;
if (ltmd->ob_axis != NULL) {
DEG_add_object_relation(ctx->node, ltmd->ob_axis, DEG_OB_COMP_TRANSFORM, "Screw Modifier");
- DEG_add_modifier_to_transform_relation(ctx->node, "Screw Modifier");
+ DEG_add_depends_on_transform_relation(ctx->node, "Screw Modifier");
}
}