Commit: 15d74e7e51ae36b4f6ed1fdcd639a934ad789342
Author: witt
Date:   Fri Jun 9 12:05:36 2017 +0200
Branches: soc-2017-sculpting_improvements
https://developer.blender.org/rB15d74e7e51ae36b4f6ed1fdcd639a934ad789342

Silhouette Operator basis setup.
First tests to generate Geometry, failed to integrate into the existing pbvh 
structure.
Experimental broken code.

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

M       source/blender/blenkernel/BKE_pbvh.h
M       source/blender/blenkernel/intern/pbvh.c
M       source/blender/blenkernel/intern/pbvh_bmesh.c
M       source/blender/editors/sculpt_paint/paint_ops.c
M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h 
b/source/blender/blenkernel/BKE_pbvh.h
index 927303f8b3c..23b67ff85de 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -29,6 +29,7 @@
 #include "BLI_bitmap.h"
 #include "BLI_ghash.h"
 #include "BLI_utildefines.h"
+#include "DNA_mesh_types.h"
 
 struct CCGElem;
 struct CCGKey;
@@ -61,6 +62,7 @@ typedef void (*BKE_pbvh_HitOccludedCallback)(PBVHNode *node, 
void *data, float *
 /* Building */
 
 PBVH *BKE_pbvh_new(void);
+void BKE_pbvh_attach_mesh(PBVH *pbvh, PBVHNode *node, Mesh *me, int totvert, 
float *max_bmin, float *max_bmax);
 void BKE_pbvh_build_mesh(
         PBVH *bvh,
         const struct MPoly *mpoly, const struct MLoop *mloop,
@@ -71,6 +73,7 @@ void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem 
**grid_elems,
                           struct CCGKey *key, void **gridfaces, struct 
DMFlagMat *flagmats,
                           unsigned int **grid_hidden);
 void BKE_pbvh_build_bmesh(PBVH *bvh, struct BMesh *bm, bool smooth_shading, 
struct BMLog *log, const int cd_vert_node_offset, const int 
cd_face_node_offset);
+void BKE_pbvh_build_tmp_bmesh(PBVH *bvh, struct BMesh *bm, bool 
smooth_shading);
 
 void BKE_pbvh_free(PBVH *bvh);
 void BKE_pbvh_free_layer_disp(PBVH *bvh);
@@ -172,6 +175,8 @@ typedef enum {
        PBVH_UpdateTopology = 256,
 } PBVHNodeFlags;
 
+bool BKE_pbvh_node_is_valid(PBVHNode *node);
+bool BKE_pbvh_node_is_leaf(PBVHNode *node);
 void BKE_pbvh_node_mark_update(PBVHNode *node);
 void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node);
 void BKE_pbvh_node_mark_redraw(PBVHNode *node);
@@ -190,9 +195,15 @@ void BKE_pbvh_node_get_verts(
         PBVH *bvh, PBVHNode *node,
         const int **r_vert_indices, struct MVert **r_verts);
 
+void BKE_pbvh_recalc_looptri_from_me(PBVH *pbvh, Mesh *me);
+PBVHNode *BKE_search_closest_pbvh_leaf_node(PBVH *pbvh, PBVHNode *p_node, 
float *target_bmin, float *target_bmax);
+
 void BKE_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 void BKE_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float 
bb_max[3]);
 
+void BKE_pbvh_node_get_children(PBVH *pbvh, PBVHNode *node, PBVHNode **left, 
PBVHNode **right);
+PBVHNode *BKE_pbvh_node_get_root(PBVH *pbvh);
+
 float BKE_pbvh_node_get_tmin(PBVHNode *node);
 
 /* test if AABB is at least partially inside the planes' volume */
diff --git a/source/blender/blenkernel/intern/pbvh.c 
b/source/blender/blenkernel/intern/pbvh.c
index dacaad8d703..c3d814c8109 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -38,6 +38,7 @@
 #include "BKE_global.h"
 #include "BKE_mesh.h" /* for BKE_mesh_calc_normals */
 #include "BKE_paint.h"
+#include "DNA_mesh_types.h"
 
 #include "GPU_buffers.h"
 
@@ -515,6 +516,25 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, 
int totprim)
 }
 
 /**
+ * Attach a new mesh to a node of the PBVH
+ * vertdata etc needs to be already in the basemesh
+ */
+void BKE_pbvh_attach_mesh(PBVH *pbvh, PBVHNode *node, Mesh *me, int totvert, 
float *max_bmin, float *max_bmax){
+       BB new_BB;
+       copy_v3_v3(new_BB.bmin, max_bmin);
+       copy_v3_v3(new_BB.bmax, max_bmax);
+
+       if(totvert <= pbvh->leaf_limit){
+               pbvh->totvert = me->totvert;
+               BB_expand_with_bb( &node->vb, &new_BB);
+
+               //build_mesh_leaf_node(pbvh, node);
+       }else{
+               //TODO: Attach to multiple nodes.
+       }
+}
+
+/**
  * Do a full rebuild with on Mesh data structure.
  *
  * \note Unlike mpoly/mloop/verts, looptri is **totally owned** by PBVH (which 
means it may rewrite it if needed,
@@ -1337,6 +1357,14 @@ BMesh *BKE_pbvh_get_bmesh(PBVH *bvh)
 
 /***************************** Node Access ***********************************/
 
+bool BKE_pbvh_node_is_valid(PBVHNode *node){
+       return node->flag; //TODO: check diffrent!
+}
+
+bool BKE_pbvh_node_is_leaf(PBVHNode *node){
+       return node->flag & PBVH_Leaf;
+}
+
 void BKE_pbvh_node_mark_update(PBVHNode *node)
 {
        node->flag |= PBVH_UpdateNormals | PBVH_UpdateBB | 
PBVH_UpdateOriginalBB | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
@@ -1428,6 +1456,64 @@ void BKE_pbvh_node_get_grids(
        }
 }
 
+float get_bb_distance_sqr(BB a, BB b){
+       float dist = 0.0f;
+       for(int i = 0; i < 3; i++){
+               if(a.bmin[i] >= b.bmax[i]){
+                       dist += (b.bmax[i] - a.bmin[i]) * (b.bmax[i] - 
a.bmin[i]);
+               }else if(a.bmax[i] < b.bmin[i]){
+                       dist += (b.bmin[i] - a.bmax[i]) * (b.bmin[i] - 
a.bmax[i]);
+               }
+       }
+       return dist;
+}
+
+void BKE_pbvh_recalc_looptri_from_me(PBVH *pbvh, Mesh *me){
+       MEM_freeN(pbvh->looptri);
+       MLoopTri *looptri;
+       int looptri_num = poly_to_tri_count(me->totpoly, me->totloop);
+       looptri = MEM_mallocN(sizeof(*looptri) * looptri_num, __func__);
+
+       BKE_mesh_recalc_looptri(
+                                                       me->mloop, me->mpoly,
+                                                       me->mvert,
+                                                       me->totloop, 
me->totpoly,
+                                                       looptri);
+       pbvh->looptri = looptri;
+}
+
+PBVHNode *BKE_search_closest_pbvh_leaf_node(PBVH *pbvh, PBVHNode *p_node, 
float *target_bmin, float *target_bmax){
+       BB new_BB;
+       copy_v3_v3(new_BB.bmin,target_bmin);
+       copy_v3_v3(new_BB.bmax,target_bmax);
+       BB_expand_with_bb(&p_node->vb,&new_BB);
+       if(BKE_pbvh_node_is_leaf(p_node)){
+               return p_node;
+       }
+       PBVHNode *left = NULL, *right = NULL;
+       BB bb_left, bb_right, bb_target;
+
+       copy_v3_v3(bb_target.bmin,target_bmin);
+       copy_v3_v3(bb_target.bmax,target_bmax);
+
+       BKE_pbvh_node_get_children(pbvh, p_node, &left, &right);
+       if((!left && !right)){
+               return p_node;
+       }else if(!left){
+               return BKE_search_closest_pbvh_leaf_node(pbvh, right, 
bb_target.bmin, bb_target.bmax);
+       }else if(!right){
+               return BKE_search_closest_pbvh_leaf_node(pbvh, left, 
bb_target.bmin, bb_target.bmax);
+       }
+       BKE_pbvh_node_get_BB(left,&bb_left.bmin,&bb_left.bmax);
+       BKE_pbvh_node_get_BB(right,&bb_right.bmin,&bb_right.bmax);
+       if(get_bb_distance_sqr(bb_target,bb_left) > 
get_bb_distance_sqr(bb_target,bb_right)){
+               return BKE_search_closest_pbvh_leaf_node(pbvh, right, 
bb_target.bmin, bb_target.bmax);
+       }else{
+               return BKE_search_closest_pbvh_leaf_node(pbvh, left, 
bb_target.bmin, bb_target.bmax);
+       }
+}
+
+
 void BKE_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
 {
        copy_v3_v3(bb_min, node->vb.bmin);
@@ -1440,6 +1526,15 @@ void BKE_pbvh_node_get_original_BB(PBVHNode *node, float 
bb_min[3], float bb_max
        copy_v3_v3(bb_max, node->orig_vb.bmax);
 }
 
+void BKE_pbvh_node_get_children(PBVH *pbvh, PBVHNode *node, PBVHNode **left, 
PBVHNode **right){
+       *left = pbvh->nodes+node->children_offset;
+       *right = pbvh->nodes+node->children_offset+1;
+}
+
+PBVHNode *BKE_pbvh_node_get_root(PBVH *pbvh){
+       return pbvh->nodes;
+}
+
 void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int 
*proxy_count)
 {
        if (node->proxy_count > 0) {
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c 
b/source/blender/blenkernel/intern/pbvh_bmesh.c
index c5e49883dc6..755bec549f4 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1850,6 +1850,71 @@ void BKE_pbvh_build_bmesh(
        MEM_freeN(nodeinfo);
 }
 
+/* Build a PBVH from a BMesh */
+void BKE_pbvh_build_tmp_bmesh(
+        PBVH *bvh, BMesh *bm, bool smooth_shading)
+{
+       bvh->cd_vert_node_offset = 0;
+       bvh->cd_face_node_offset = 0;
+       bvh->bm = bm;
+
+       bvh->type = PBVH_BMESH;
+
+       /* TODO: choose leaf limit better */
+       bvh->leaf_limit = 100;
+
+       if (smooth_shading)
+               bvh->flags |= PBVH_DYNTOPO_SMOOTH_SHADING;
+
+       /* bounding box array of all faces, no need to recalculate every time */
+       BBC *bbc_array = MEM_mallocN(sizeof(BBC) * bm->totface, "BBC");
+       BMFace **nodeinfo = MEM_mallocN(sizeof(*nodeinfo) * bm->totface, 
"nodeinfo");
+       MemArena *arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "fast PBVH 
node storage");
+
+       BMIter iter;
+       BMFace *f;
+       int i;
+       BM_ITER_MESH_INDEX(f, &iter, bm, BM_FACES_OF_MESH, i) {
+               BBC *bbc = &bbc_array[i];
+               BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
+               BMLoop *l_iter = l_first;
+
+               BB_reset((BB *)bbc);
+               do {
+                       BB_expand((BB *)bbc, l_iter->v->co);
+               } while ((l_iter = l_iter->next) != l_first);
+               BBC_update_centroid(bbc);
+
+               /* so we can do direct lookups on 'bbc_array' */
+               BM_elem_index_set(f, i);  /* set_dirty! */
+               nodeinfo[i] = f;
+       }
+
+       /* likely this is already dirty */
+       bm->elem_index_dirty |= BM_FACE;
+
+       /* setup root node */
+       struct FastNodeBuildInfo rootnode = {0};
+       rootnode.totface = bm->totface;
+
+       /* start recursion, assign faces to nodes accordingly */
+       pbvh_bmesh_node_limit_ensure_fast(bvh, nodeinfo, bbc_array, &rootnode, 
arena);
+
+       /* we now have all faces assigned to a node, next we need to assign 
those to the gsets of the nodes */
+
+       /* Start with all faces in the root node */
+       bvh->nodes = MEM_callocN(sizeof(PBVHNode), "PBVHNode");
+       bvh->totnode = 1;
+
+       /* take root node and visit and populate children recursively */
+       pbvh_bmesh_create_nodes_fast_recursive(bvh, nodeinfo, bbc_array, 
&rootnode, 0);
+
+       BLI_memarena_free(arena);
+       MEM_freeN(bbc_array);
+       MEM_freeN(nodeinfo);
+}
+
+
 /* Collapse short edges, subdivide long edges */
 bool BKE_pbvh_bmesh_update_topology(
         PBVH *bvh, PBVHTopologyUpdateMode mode,
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c 
b/source/blender/editors/sculpt_paint/paint_ops.c
index f88b64129e7..19672c940c7 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1566,6 +1566,9 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        /* Toggle dynamic topology */
        WM_keymap_add_item(keymap, "SCULPT_OT_dynamic_topology_toggle", DKEY, 
KM_PRESS, KM_CTRL, 0);
 
+       /* Draw Silhouette */
+       WM_keymap_add_item(keymap, "SCULPT_OT_silhouette_draw", LEFTMOUSE, 
KM_PRESS, KM_ALT, 0);
+
        /* Dynamic-topology detail size
         * 
         * This should be improved further, perhaps by showing a triangle
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index e59b144836e..ba5667fbb08 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -99,6 +99,36 @@
 #include <stdlib.h>
 #include <string.h>
 
+/*Maybe move silhouette GL Drawing into a seperate file*/
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+#include "ED_space_api.h"
+#include 

@@ 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