Commit: e9a6e62d1949eb07f0dc44a0c3a75bd397648cce
Author: witt
Date:   Fri Jun 23 19:50:08 2017 +0200
Branches: soc-2017-sculpting_improvements
https://developer.blender.org/rBe9a6e62d1949eb07f0dc44a0c3a75bd397648cce

Added t-intersections and caps. Next step: bridging the gaps.

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

M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index e2c34c43240..ea0f027f8c3 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5319,6 +5319,11 @@ typedef enum {
        SHAPE_RING = 1
 } ShapeTypes;
 
+typedef enum {
+       BRANCH_INIT = 0,
+       BRANCH_VERT_GEN = 1
+} BranchState;
+
 typedef struct ShapePrimitive{
        ShapeTypes type;
        float z_pos;
@@ -5333,6 +5338,8 @@ typedef struct SpineBranch{
        int idx;
        /*Per fork one terminal: |point fork_idx| = Terminal*/
        int *terminal_points;
+       BranchState flag;
+       int *gen_verts;
 }SpineBranch;
 
 typedef struct Spine{
@@ -5377,6 +5384,9 @@ static void free_spine_branch(SpineBranch *branch)
        if (branch->terminal_points) {
                MEM_freeN(branch->terminal_points);
        }
+       if (branch->flag & BRANCH_VERT_GEN){
+               MEM_freeN(branch->gen_verts);
+       }
        MEM_freeN(branch);
 }
 
@@ -5455,11 +5465,11 @@ static Spine *new_spine(int max_alloc, int hull_max)
 }
 
 #ifdef DEBUG_DRAW
-static void debug_branch(SpineBranch *sb, Spine *spine, SilhouetteData *sil, 
char color){
+static void debug_branch(SpineBranch *sb, Spine *spine, SilhouetteData *sil, 
unsigned int color){
        float v1[3], v2[3];
 
        if(sb->totpoints > 1){
-               bl_debug_color_set(0x0000FF);
+               bl_debug_color_set(color);
                for(int j = 1; j < sb->totpoints; j++){
                        copy_v3_v3(v1,&sb->points[j*3-3]);
                        copy_v3_v3(v2,&sb->points[j*3  ]);
@@ -5474,7 +5484,7 @@ static void debug_branch(SpineBranch *sb, Spine *spine, 
SilhouetteData *sil, cha
        }*/
 
        /*SpineBranch *rsb;*/
-       unsigned int forkcol = 0xFFFF00;
+       /*unsigned int forkcol = 0xFFFF00;
        for(int j = 1; j < sb->totforks; j++){
                printf("Branch fork %i, stroke ids: %i, %i\n", j, 
sb->terminal_points[j*4], sb->terminal_points[j*4+3]);
                if (spine->branches[sb->terminal_points[j*4+2]] && 
spine->branches[sb->terminal_points[j*4+2]]->totforks > 0) {
@@ -5485,7 +5495,7 @@ static void debug_branch(SpineBranch *sb, Spine *spine, 
SilhouetteData *sil, cha
                        bl_debug_draw_point(v1, 0.2f);
                        bl_debug_color_set(color);
                }
-       }
+       }*/
 }
 
 static void debug_spine(Spine *spine, SilhouetteData *sil)
@@ -5590,14 +5600,14 @@ static int calc_mid_spine_rec(BMFace *f, Spine *spine, 
SpineBranch *active_branc
 
                new_branch = spine_branchoff(spine, active_branch, f, 
max_alloc, hull_max);
                sub_added_points = calc_mid_spine_rec(ad_f[0], spine, 
new_branch, f, max_alloc, hull_max);
-               if(sub_added_points < 5 && new_branch->totforks < 2){
+               if(sub_added_points < 6 && new_branch->totforks < 2){
                        dissolve_branch(spine, new_branch, active_branch);
                }
                added_points += sub_added_points;
 
                new_branch = spine_branchoff(spine, active_branch, f, 
max_alloc, hull_max);
                sub_added_points = calc_mid_spine_rec(ad_f[1], spine, 
new_branch, f, max_alloc, hull_max);
-               if(sub_added_points < 3 && new_branch->totforks < 3){
+               if(sub_added_points < 6 && new_branch->totforks < 2){
                        dissolve_branch(spine, new_branch, active_branch);
                }
                added_points += sub_added_points;
@@ -5674,68 +5684,435 @@ static Spine *silhouette_generate_spine(SilhouetteData 
*sil, SilhouetteStroke *s
        return spine;
 }
 
+/* Create standardised Mesh (Edges, Loops, Polys):*/
+static void generate_mesh_grid_f_e(Mesh *me, int u_steps, int v_steps, int 
v_start, bool n_flip)
+{
+       int face_count = (u_steps - 1) * (v_steps - 1);
+       int e_start = me->totedge;
+       int l_start = me->totloop;
+       int p_start = me->totpoly;
+       int p_pos = 0, l_pos = 0, e_pos = 0, v_pos = 0;
+       int edges_per_side = face_count * 2 + u_steps + v_steps - 2;
+       /*TODO: drag out of branch loop*/
+       ED_mesh_edges_add(me, NULL, edges_per_side);
+       ED_mesh_loops_add(me, NULL, face_count * 4);
+       ED_mesh_polys_add(me, NULL, face_count);
+
+       for(int u = 0; u < u_steps; u++){
+               for(int v = 0; v < v_steps; v++){
+                       /* add edges */
+                       if (v < v_steps - 1 && u < u_steps - 1) {
+                               e_pos = e_start + u * (v_steps * 2 - 1) + v * 2;
+                               me->medge[e_pos].crease = 0;
+                               me->medge[e_pos].bweight = 0;
+                               me->medge[e_pos].flag = 0;
+                               me->medge[e_pos].v1 = v_start + u * v_steps + v;
+                               me->medge[e_pos].v2 = v_start + u * v_steps + v 
+ 1;
+
+                               me->medge[e_pos + 1].crease = 0;
+                               me->medge[e_pos + 1].bweight = 0;
+                               me->medge[e_pos + 1].flag = 0;
+                               me->medge[e_pos + 1].v1 = v_start + u * v_steps 
+ v;
+                               me->medge[e_pos + 1].v2 = v_start + (u + 1) * 
v_steps + v;
+
+                               /* add loops */
+                               l_pos = l_start + u * 4 * (v_steps - 1) + v * 4;
+                               v_pos = v_start + u * v_steps + v;
+                               me->mloop[l_pos].v = v_pos;
+                               me->mloop[l_pos].e = e_pos;
+
+                               if (n_flip) {
+                                       /* clockwise */
+                                       me->mloop[l_pos + 1].v = v_pos + 1;
+                                       me->mloop[l_pos + 1].e = e_pos + 3;
+
+                                       me->mloop[l_pos + 2].v = v_pos + 
v_steps + 1;
+                                       me->mloop[l_pos + 2].e = e_pos + 
v_steps * 2 - 1;
+
+                                       me->mloop[l_pos + 3].v = v_pos + 
v_steps;
+                                       me->mloop[l_pos + 3].e = e_pos + 1;
+                               } else {
+                                       /* anti clockwise */
+                                       me->mloop[l_pos + 1].v = v_pos + 
v_steps;
+                                       me->mloop[l_pos + 1].e = e_pos + 1;
+
+                                       me->mloop[l_pos + 2].v = v_pos + 
v_steps + 1;
+                                       me->mloop[l_pos + 2].e = e_pos + 
v_steps * 2 - 1;
+
+                                       me->mloop[l_pos + 3].v = v_pos + 1;
+                                       me->mloop[l_pos + 3].e = e_pos + 3;
+                               }
+
+                               /* add Polys */
+                               p_pos = p_start + u * (v_steps - 1) + v;
+                               me->mpoly[p_pos].totloop = 4;
+                               me->mpoly[p_pos].loopstart = l_pos;
+                               me->mpoly[p_pos].mat_nr = 0;
+                               me->mpoly[p_pos].flag = 0;
+                               me->mpoly[p_pos].pad = 0;
+
+
+                       } else if (v == v_steps - 1 && u != u_steps - 1){
+                               e_pos = e_start + u * (v_steps * 2 - 1) + v * 2;
+                               me->medge[e_pos].crease = 0;
+                               me->medge[e_pos].bweight = 0;
+                               me->medge[e_pos].flag = 0;
+                               me->medge[e_pos].v1 = v_start + u * v_steps + v;
+                               me->medge[e_pos].v2 = v_start + (u + 1) * 
v_steps + v;
+                       } else if (u == u_steps - 1 && v != v_steps - 1) {
+                               e_pos = e_start + u * (v_steps * 2 - 1) + v;
+                               me->medge[e_pos].crease = 0;
+                               me->medge[e_pos].bweight = 0;
+                               me->medge[e_pos].flag = 0;
+                               me->medge[e_pos].v1 = v_start + u * v_steps + v;
+                               me->medge[e_pos].v2 = v_start + u * v_steps + v 
+ 1;
+                       }
+               }
+       }
+}
+
+static void bridge_loop(Mesh *me, int v_start_a, int v_start_b, int totvert, 
bool flip, int l_start_a, int l_start_b, int l_stride)
+{
+       int e_start = me->totedge;
+       int l_start = me->totloop;
+       int p_start = me->totpoly;
+       ED_mesh_edges_add(me, NULL, totvert);
+       ED_mesh_loops_add(me, NULL, 4 * totvert - 4);
+       ED_mesh_polys_add(me, NULL, totvert - 1);
+
+       for (int i = 0; i < totvert; i++) {
+               me->medge[e_start + i].crease = 0;
+               me->medge[e_start + i].bweight = 0;
+               me->medge[e_start + i].flag = 0;
+               me->medge[e_start + i].v1 = v_start_a + i;
+               me->medge[e_start + i].v2 = v_start_b + (flip ? -i : i);
+
+               if (i < totvert - 1) {
+                       me->mloop[l_start + i * 4 + 0].v = v_start_a + i;
+                       me->mloop[l_start + i * 4 + 0].e = l_start_a + i * 
l_stride;
+
+                       me->mloop[l_start + i * 4 + 1].v = v_start_a + i + 1;
+                       me->mloop[l_start + i * 4 + 1].e = e_start + i + 1;
+
+                       me->mloop[l_start + i * 4 + 2].v = v_start_b + (flip ? 
-i - 1 : i + 1);
+                       me->mloop[l_start + i * 4 + 2].e = l_start_b + (flip ? 
-i : i) * l_stride;
+
+                       me->mloop[l_start + i * 4 + 3].v = v_start_b + (flip ? 
-i : i);
+                       me->mloop[l_start + i * 4 + 3].e = e_start + i;
+
+                       me->mpoly[p_start + i].loopstart = l_start + i * 4;
+                       me->mpoly[p_start + i].totloop = 4;
+                       me->mpoly[p_start + i].mat_nr = 0;
+                       me->mpoly[p_start + i].flag = 0;
+                       me->mpoly[p_start + i].pad = 0;
+               }
+       }
+}
+
 static int cmpfunc (const void * a, const void * b)/* TODO: is there a sort 
func already?*/
 {
        return ( *(int*)a - *(int*)b );
 }
 
-static void add_ss_tube(SilhouetteData *sil, SpineBranch *branch, Mesh *me, 
float z_vec[3], int ss_steps)
+static void add_ss_cap(SilhouetteData *sil, SpineBranch *branch, int 
*gen_verts, Mesh *me, float z_vec[3], float depth, int ss_steps, int w_steps){
+       float cap_p[branch->tot_hull_points * 4];
+       float v1[3], v2[3], v3[3], z_vec_b[3];
+       float totlength = 0.0f;
+       float step_size = depth / (float)w_steps;
+       qsort (branch->hull_points, branch->tot_hull_points, sizeof(int), 
cmpfunc);
+
+       for(int i = 0; i < branch->tot_hull_points; i++){
+               silhoute_stroke_point_to_3d(sil, branch->hull_points[i] * 2, 
&cap_p[i * 4]);
+               if (i > 0) {
+                       cap_p[i * 4 + 3] = len_v3v3(&cap_p[i * 4], v1) + 
cap_p[i * 4 - 1];
+               } else {
+                       cap_p[i * 4 + 3] = 0.0f;
+               }
+               copy_v3_v3(v1, &cap_p[i * 4]);
+       }
+
+       totlength = cap_p[branch->tot_hull_points * 4 - 1];
+
+       float cap_length = fmin(totlength, (w_steps * step_size));
+       step_size = cap_length / (float)w_steps;
+       float cap_pos = (totlength - cap_length) * 0.5f;
+       float a, b, f;
+       int u_pos_i = 1;
+       int v_start = me->totvert;
+
+       if (totlength > step_size * w_steps && false){
+               /*TODO: tubeish ends*/
+       }
+
+       ED_mesh_vertices_add(me, NULL, w_steps * ss_steps);
+
+       for(int u = 0; u < w_steps; u++){
+               while(cap_p[u_pos_i * 4 + 3] < cap_pos){
+                       u_pos_i ++;
+               }
+
+               a = cap_p[u_pos_i * 4 - 1];
+               b = cap_p[u_pos_i * 4 + 3];
+               f = (cap_pos - a) / (b - a);
+               interp_v3_v3v3(v1, &cap_p[u_pos_i * 4 - 4], &cap_p[u_pos_i * 
4], f);
+               copy_v3_v3(z_vec_b, z_vec);
+
+               for(int v = 0; v < ss_steps; v++){
+                       add_v3_v3(v1, z_vec_b);
+                       f = (float)v / (float)(ss_steps * 2);
+                       f = sin(M_PI * f - M_PI * 0.5f) + 1.0f;
+                       interp_v3_v3v3(v3, v1, me->mvert[gen_verts[ss_steps + 
u]].co, f);
+                       me->mvert[v_start + u * ss_steps + v].flag = 0;
+                       me->mvert[v_start + u * ss_steps + v].bweight = 0;
+                       copy_v3_v3(me->mvert[v_start + u * ss_steps + v].co,v3);
+                       mul_v3_fl(z_vec_b, cos(0.5f * M_PI * ((float)v / 
(float)ss_steps)));
+               }
+               cap_pos += step_size;
+       }
+
+       generate_mesh_grid_f_e(me, w_steps, ss_steps, v_start, false);
+}
+
+static void calc_fork_arc(float v1[3], float v2[3], float *out, int offloop, 
const float z_vec[3], int ss_steps, int w_steps, float w_fact){
+       float v3[3], v4[3], z_vec_b[3];
+       float f;
+       copy_v3_v3(z_vec_b, z_vec);
+       for(int v = 0; v < ss_steps; v++){
+               add_v3_v3(v1, z_vec_b);
+               add_v3_v3(v2, z_vec_b);
+               f = (float)v/(float)(ss_steps * 2);
+               f = (sin(M_PI * f - M_PI * 0.5f) * 0.5f + 0.5f) * w_fact;
+               interp_v3_v3v3(v3, v1, v2, f);
+               copy_v3_v3(&out[offloop + v * 3], v3);
+               int

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to