Commit: 82835bcaad3f1277a693d771b29fdf4a130ffd73
Author: witt
Date:   Fri Jun 30 19:40:07 2017 +0200
Branches: soc-2017-sculpting_improvements
https://developer.blender.org/rB82835bcaad3f1277a693d771b29fdf4a130ffd73

Progress on generated shape. Lots of smaller bugfixes parts are partially 
bridged.

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

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 ea0f027f8c3..b117d8c5725 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5167,6 +5167,12 @@ static void bl_debug_draw_BB_add(BB *bb,const unsigned 
int col)
 }
 #endif
 
+typedef enum {
+       SIL_INIT = 0,
+       SIL_DRAWING = 1,
+       SIL_OP = 2
+} SilhouetteState;
+
 typedef struct SilhouetteData {
        ARegion *ar;        /* region that Silhouette started drawn in */
        void *draw_handle;  /* for drawing preview loop */
@@ -5179,8 +5185,12 @@ typedef struct SilhouetteData {
        float add_col[3];
        float last_mouse_pos[2];
 
+       SilhouetteState state;
+
        float depth;
+       float smoothness;
        float anchor[3];
+       float z_vec[3];
 } SilhouetteData;
 
 typedef struct {
@@ -5233,14 +5243,14 @@ static SilhouetteStroke *silhouette_stroke_new(int 
max_verts)
 {
        SilhouetteStroke *stroke = MEM_callocN(sizeof(SilhouetteStroke), 
"SilhouetteStroke");
        stroke->points = 0;
-       stroke->points = 
MEM_callocN(sizeof(float)*2*max_verts,"SilhouetteStrokePoints");//TODO: Dynamic 
length
+       stroke->points = MEM_callocN(sizeof(float) * 3 * 
max_verts,"SilhouetteStrokePoints");//TODO: Dynamic length
        stroke->totvert = 0;
        stroke->max_verts = max_verts;
        printf("Init silhouette Data\n");
        return stroke;
 }
 
-static SilhouetteData *silhouette_data_new(bContext *C, wmOperator *UNUSED(op))
+static SilhouetteData *silhouette_data_new(bContext *C, wmOperator *op, bool 
rna_full)
 {
        SilhouetteData *sil = MEM_callocN(sizeof(SilhouetteData), 
"SilhouetteData");
        Object *obedit = CTX_data_edit_object(C);
@@ -5256,13 +5266,21 @@ static SilhouetteData *silhouette_data_new(bContext *C, 
wmOperator *UNUSED(op))
        sil->add_col[1] = 0.39;
        sil->add_col[2] = 0.39;
 
-       sil->depth = 1.5f;
+       sil->smoothness = RNA_float_get(op->ptr, "smoothness");
+       sil->depth = RNA_float_get(op->ptr, "depth");
+       if(rna_full){
+               RNA_float_get_array(op->ptr, "z_vec", sil->z_vec);
+               RNA_float_get_array(op->ptr, "anchor", sil->anchor);
+               RNA_float_get_array(op->ptr, "points", 
sil->current_stroke->points);
+               sil->current_stroke->totvert = RNA_int_get(op->ptr, "totvert");
+       }
 
 
        /* assign the drawing handle for drawing preview line... */
        sil->scene = scene;
        sil->ob = obedit;
 
+       sil->state = SIL_INIT;
        return sil;
 }
 
@@ -5277,14 +5295,29 @@ static void silhouette_data_free(struct wmOperator *op)
 }
 
 static void silhoute_stroke_point_to_3d(SilhouetteData *sil, int point, float 
r_v[3]){
-       ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, 
&sil->current_stroke->points[point], r_v);
+       copy_v3_v3(r_v,&sil->current_stroke->points[point]);
+       //ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, 
&sil->current_stroke->points[point], r_v);
 }
 
-static void silhouette_stroke_add_point(SilhouetteStroke *stroke, float 
point[2])
+static void silhouette_stroke_add_3Dpoint(SilhouetteStroke *stroke, float 
point[3])
 {
        if (stroke->totvert < stroke->max_verts) {
-               stroke->points[stroke->totvert*2] = point[0];
-               stroke->points[stroke->totvert*2+1] = point[1];
+               copy_v3_v3(&stroke->points[stroke->totvert * 3], point);
+               //ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, point, 
&sil->current_stroke->points[stroke->totvert * 3]);
+               /*stroke->points[stroke->totvert * 3] = point[0];
+                stroke->points[stroke->totvert*2+1] = point[1];*/
+               stroke->totvert ++;
+       } else {
+               printf("Stroke reached maximum vert count.\n");
+       }
+}
+
+static void silhouette_stroke_add_point(SilhouetteData *sil, SilhouetteStroke 
*stroke, float point[2])
+{
+       if (stroke->totvert < stroke->max_verts) {
+               ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, point, 
&sil->current_stroke->points[stroke->totvert * 3]);
+               /*stroke->points[stroke->totvert * 3] = point[0];
+               stroke->points[stroke->totvert*2+1] = point[1];*/
                stroke->totvert ++;
        } else {
                printf("Stroke reached maximum vert count.\n");
@@ -5297,6 +5330,7 @@ static void silhouette_set_ref_plane(const bContext *C, 
SilhouetteData *sil)
        View3D *v3d = CTX_wm_view3d(C);
        const float *fp = ED_view3d_cursor3d_get(scene, v3d);
 
+       ED_view3d_global_to_vector(sil->ar->regiondata, 
(float[3]){0.0f,0.0f,0.0f}, sil->z_vec);
        /* the reference point used depends on the owner... */
        copy_v3_v3(sil->anchor, fp);
 }
@@ -5306,13 +5340,11 @@ static void sculpt_silhouette_stroke_update(bContext 
*C, float mouse[2], Silhoue
        silhouette_set_ref_plane( C, sil);
        SilhouetteStroke *stroke = sil->current_stroke;
 
-       sil->last_mouse_pos[0] = mouse[0];//*(2.0f/(float)sil->ar->winx)-1.0f;
-       sil->last_mouse_pos[1] = mouse[1];//*(2.0f/(float)sil->ar->winy)-1.0f;
-       silhouette_stroke_add_point(stroke, sil->last_mouse_pos);
+       sil->last_mouse_pos[0] = mouse[0];
+       sil->last_mouse_pos[1] = mouse[1];
+       silhouette_stroke_add_point(sil, stroke, sil->last_mouse_pos);
        ED_region_tag_redraw(sil->ar);
        copy_v2_v2(sil->last_mouse_pos,mouse);
-       //printf("Mouse Pos: (%f,%f)",mouse[0],mouse[1]);
-       /* Update stroke*/
 }
 
 typedef enum {
@@ -5321,7 +5353,8 @@ typedef enum {
 
 typedef enum {
        BRANCH_INIT = 0,
-       BRANCH_VERT_GEN = 1
+       BRANCH_VERT_GEN = 1,
+       BRANCH_EDGE_GEN = 2
 } BranchState;
 
 typedef struct ShapePrimitive{
@@ -5340,6 +5373,7 @@ typedef struct SpineBranch{
        int *terminal_points;
        BranchState flag;
        int *gen_verts;
+       int *e_start_arr;
 }SpineBranch;
 
 typedef struct Spine{
@@ -5387,6 +5421,9 @@ static void free_spine_branch(SpineBranch *branch)
        if (branch->flag & BRANCH_VERT_GEN){
                MEM_freeN(branch->gen_verts);
        }
+       if (branch->flag & BRANCH_EDGE_GEN){
+               MEM_freeN(branch->e_start_arr);
+       }
        MEM_freeN(branch);
 }
 
@@ -5409,25 +5446,11 @@ static void detach_branch(SpineBranch *b, SpineBranch 
*db)
 
 static void dissolve_branch(Spine *spine, SpineBranch *branch, SpineBranch 
*t_branch)
 {
-       /*for(int i = 0; i < branch->totpoints-1; i++){
-               t_branch->points[t_branch->totpoints] = branch->points[i];
-               t_branch->totpoints ++;
-       }*/
-
        for(int i = 0; i < branch->tot_hull_points; i++){
                t_branch->hull_points[t_branch->tot_hull_points] = 
branch->hull_points[i];
                t_branch->tot_hull_points ++;
        }
 
-       /*for(int i = 0; i < branch->totforks; i++){
-               if(spine->branches[branch->terminal_points[i*4+2]] != t_branch){
-                       t_branch->terminal_points[t_branch->totforks*4  ] = 
branch->terminal_points[i*4];
-                       t_branch->terminal_points[t_branch->totforks*4+1] = 
branch->terminal_points[i*4+1];
-                       t_branch->terminal_points[t_branch->totforks*4+2] = 
branch->terminal_points[i*4+2];
-                       t_branch->terminal_points[t_branch->totforks*4+3] = 
branch->terminal_points[i*4+3];
-                       t_branch->totforks ++;
-               }
-       }*/
        for(int i = 0; i < branch->totforks; i++){
                if(branch->terminal_points[i * 2 + 1] != t_branch->idx){
                        detach_branch(spine->branches[branch->terminal_points[i 
* 2 + 1]], branch);
@@ -5630,7 +5653,7 @@ static Spine *silhouette_generate_spine(SilhouetteData 
*sil, SilhouetteStroke *s
                                                &bm_create_params);
 
        for (int i = 0; i < stroke->totvert; i++){
-               silhoute_stroke_point_to_3d(sil, i*2, v_co);
+               silhoute_stroke_point_to_3d(sil, i * 3, v_co);
                v = BM_vert_create( bm, v_co, NULL, BM_CREATE_NOP);
                BM_elem_index_set(v,i);
                vert_arr[i] = v;
@@ -5771,6 +5794,48 @@ static void generate_mesh_grid_f_e(Mesh *me, int 
u_steps, int v_steps, int v_sta
        }
 }
 
+static void bridge_loops(Mesh *me, int e_start_a, int e_start_b, int totvert, 
bool flip, int a_stride, int b_stride, bool n_flip)
+{
+       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;
+
+               if (i < totvert - 1) {
+                       me->medge[e_start + i].v1 = me->medge[e_start_a + i * 
a_stride].v1;
+                       me->medge[e_start + i].v2 = me->medge[e_start_b + (flip 
? -i : i) * b_stride].v1;
+
+                       me->mloop[l_start + i * 4 + 0].v = me->medge[e_start_a 
+ i * a_stride].v1;
+                       me->mloop[l_start + i * 4 + 0].e = e_start_a + i * 
a_stride;
+
+                       me->mloop[l_start + i * 4 + (n_flip? 3 : 1)].v = 
me->medge[e_start_a + i * a_stride].v2;
+                       me->mloop[l_start + i * 4 + (n_flip? 3 : 1)].e = 
e_start + i + 1;
+
+                       me->mloop[l_start + i * 4 + 2].v = me->medge[e_start_b 
+ (flip ? -i : i) * b_stride].v2;
+                       me->mloop[l_start + i * 4 + 2].e = e_start_b + (flip ? 
-i : i) * b_stride;
+
+                       me->mloop[l_start + i * 4 + (n_flip? 1 : 3)].v = 
me->medge[e_start_b + (flip ? -i : i) * b_stride].v1;
+                       me->mloop[l_start + i * 4 + (n_flip? 1 : 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;
+               } else {
+                       me->medge[e_start + i].v1 = me->medge[e_start_a + (i - 
1) * a_stride].v2;
+                       me->medge[e_start + i].v2 = me->medge[e_start_b + (flip 
? -(i - 1) : (i - 1)) * b_stride].v2;
+               }
+       }
+}
+
 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;
@@ -5814,15 +5879,160 @@ static int cmpfunc (const void * a, const void * b)/* 
TODO: is there a sort func
        return ( *(int*)a - *(int*)b );
 }
 
-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){
+static void fill_tube(Mesh *me, float *left, float *right, int totl, int totr, 
int u_steps, float z_vec[3], int ss_steps, int w_steps, float w_fact, int 
*e_start_sides)
+{
+       int v_steps = ss_steps;
+       int square_ss_steps = u_steps * v_steps;
+       float step_l = left[totl * 4 - 1] / (float)u_steps;
+       float step_r = right[totr * 4 - 1] / (float)u_steps;
+       float a, b, f;
+       float v1[3], v2[3], v3[3], v4[3], z_vec_b[3];
+       int l_u_pos_i = 1, r_u_pos_i = totr - 1;
+       int v_pos_w = 0;
+
+       const int v_start = me->totvert;
+       MVert ref_v;
+       ref_v.flag = 0; ref_v.bweight = 0;
+       ED_mesh_vertices_add(me, NULL, square_ss_steps * 2 + (w_steps - 1) * 
u_steps);
+
+       for(int u = 0; u < u_steps; u++){
+               while(left[l_

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to