Revision: 30096 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30096 Author: nicholasbishop Date: 2010-07-08 00:55:57 +0200 (Thu, 08 Jul 2010)
Log Message: ----------- Some more changes for improving non-sculpt paint modes: ?\226?\128?\162 Add face customdata to the pbvh ?\226?\128?\162 Return more data from BLI_pbvh_node_get_faces ?\226?\128?\162 Add some drawing flags for the pbvh/VBO drawing code ?\226?\128?\162 Some initial support for drawing mesh colors (not used yet) ?\226?\128?\162 Abstracted sculpt's get_location a bit so it can be used for other types of paint strokes ?\226?\128?\162 Moved and renamed unproject_brush_radius so other paint modes can use it ?\226?\128?\162 There should be no visible changes from this commit Modified Paths: -------------- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c branches/soc-2010-nicolasbishop/source/blender/editors/space_view3d/drawobject.c branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c =================================================================== --- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c 2010-07-07 21:57:57 UTC (rev 30095) +++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c 2010-07-07 22:55:57 UTC (rev 30096) @@ -2186,7 +2186,7 @@ changing PVBH node organization, we hope topology does not change in the meantime .. weak */ if(ob->paint && ob->paint->pbvh) { - if(!ob->paint->sculpt->cache) { + if(!ob->paint->sculpt || !ob->paint->sculpt->cache) { BLI_pbvh_free(ob->paint->pbvh); ob->paint->pbvh= NULL; } Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c =================================================================== --- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c 2010-07-07 21:57:57 UTC (rev 30095) +++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c 2010-07-07 22:55:57 UTC (rev 30096) @@ -223,7 +223,8 @@ cddm->pbvh = BLI_pbvh_new(); cddm->pbvh_draw = can_pbvh_draw(ob, dm); BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert, - &me->vdata, me->totface, me->totvert, + &me->vdata, &me->fdata, me->totface, + me->totvert, ss ? &ss->hidden_areas : NULL); } @@ -439,15 +440,16 @@ if(cddm->pbvh && cddm->pbvh_draw) { if(dm->numFaceData) { + GPUDrawFlags drawflags = 0; float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL); /* should be per face */ if(!setMaterial(mface->mat_nr+1, NULL)) return; + if(mface->flag & ME_SMOOTH) + drawflags |= GPU_DRAW_SMOOTH; - glShadeModel((mface->flag & ME_SMOOTH)? GL_SMOOTH: GL_FLAT); - BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, (mface->flag & ME_SMOOTH)); - glShadeModel(GL_FLAT); + BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, drawflags); } return; Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c =================================================================== --- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c 2010-07-07 21:57:57 UTC (rev 30095) +++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c 2010-07-07 22:55:57 UTC (rev 30096) @@ -60,6 +60,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "gpu_buffers.h" #include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_material.h" @@ -1303,13 +1304,15 @@ if(ccgdm->pbvh && ccgdm->multires.mmd && !fast) { if(dm->numFaceData) { + GPUDrawFlags drawflags = 0; + /* should be per face */ if(!setMaterial(faceFlags[1]+1, NULL)) return; + if(faceFlags[0] & ME_SMOOTH) + drawflags |= GPU_DRAW_SMOOTH; - glShadeModel((faceFlags[0] & ME_SMOOTH)? GL_SMOOTH: GL_FLAT); - BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL, (faceFlags[0] & ME_SMOOTH)); - glShadeModel(GL_FLAT); + BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL, drawflags); } return; @@ -2349,7 +2352,7 @@ ob->paint->pbvh= ccgdm->pbvh = BLI_pbvh_new(); BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert, - &me->vdata, me->totface, me->totvert, + &me->vdata, &me->fdata, me->totface, me->totvert, ss ? &ss->hidden_areas : NULL); ccgdm->pbvh_draw = 0; } Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h =================================================================== --- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h 2010-07-07 21:57:57 UTC (rev 30095) +++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h 2010-07-07 22:55:57 UTC (rev 30096) @@ -54,12 +54,20 @@ typedef void (*BLI_pbvh_HitCallback)(PBVHNode *node, void *data); +/* test AABB against sphere */ +typedef struct { + float *center; + float radius_squared; + int original; +} PBVHSearchSphereData; +int BLI_pbvh_search_sphere_cb(PBVHNode *node, void *data); + /* Building */ PBVH *BLI_pbvh_new(void); void BLI_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts, - struct CustomData *vdata, int totface, int totvert, - ListBase *hidden_areas); + struct CustomData *vdata, struct CustomData *fdata, + int totface, int totvert, ListBase *hidden_areas); void BLI_pbvh_build_grids(PBVH *bvh, struct DMGridData **grids, struct DMGridAdjacency *gridadj, int totgrid, int gridsize, struct GridKey *gridkey, void **gridfaces, @@ -92,7 +100,7 @@ void BLI_pbvh_node_draw(PBVHNode *node, void *data); int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data); -void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smooth); +void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int flags); /* Node Access */ @@ -123,7 +131,9 @@ void BLI_pbvh_node_set_flags(PBVHNode *node, void *data); void BLI_pbvh_node_get_faces(PBVH *bvh, PBVHNode *node, - int **face_indices, int *totnode); + struct MFace **faces, struct CustomData **fdata, + int **face_indices, int **face_vert_indices, + int *totface); void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, struct DMGridData ***griddata, struct DMGridAdjacency **gridadj, struct GridKey **gridkey); Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c =================================================================== --- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-07-07 21:57:57 UTC (rev 30095) +++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-07-07 22:55:57 UTC (rev 30096) @@ -33,6 +33,7 @@ #include "BKE_global.h" /* for mesh_calc_normals */ #include "gpu_buffers.h" +#include "GL/glew.h" static void pbvh_free_nodes(PBVH *bvh); @@ -121,6 +122,9 @@ /* Used by both mesh and grid type */ CustomData *vdata; + /* For vertex paint */ + CustomData *fdata; + /* Only used during BVH build and update, don't need to remain valid after */ BLI_bitmap vert_bitmap; @@ -152,8 +156,33 @@ int stackspace; } PBVHIter; +/* Test AABB against sphere */ +int BLI_pbvh_search_sphere_cb(PBVHNode *node, void *data_v) +{ + PBVHSearchSphereData *data = data_v; + float nearest[3]; + float t[3], bb_min[3], bb_max[3]; + int i; + if(data->original) + BLI_pbvh_node_get_original_BB(node, bb_min, bb_max); + else + BLI_pbvh_node_get_BB(node, bb_min, bb_max); + + for(i = 0; i < 3; ++i) { + if(bb_min[i] > data->center[i]) + nearest[i] = bb_min[i]; + else if(bb_max[i] < data->center[i]) + nearest[i] = bb_max[i]; + else + nearest[i] = data->center[i]; + } + + sub_v3_v3v3(t, data->center, nearest); + return t[0] * t[0] + t[1] * t[1] + t[2] * t[2] < data->radius_squared; +} + /* Adapted from: http://www.gamedev.net/community/forums/topic.asp?topic_id=512123 Returns true if the AABB is at least partially within the frustum @@ -392,6 +421,7 @@ node->draw_buffers = GPU_build_mesh_buffers(map, bvh->verts, bvh->faces, bvh->vdata, + bvh->fdata, node->prim_indices, node->totprim, node->vert_indices, node->uniq_verts, @@ -614,12 +644,14 @@ /* Do a full rebuild with on Mesh data structure */ void BLI_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, - CustomData *vdata, int totface, int totvert, + CustomData *vdata, CustomData *fdata, + int totface, int totvert, ListBase *hidden_areas) { bvh->faces = faces; bvh->verts = verts; bvh->vdata = vdata; + bvh->fdata = fdata; bvh->totvert = totvert; bvh->leaf_limit = LEAF_LIMIT; @@ -969,7 +1001,7 @@ } } -static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, int smooth) +static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, GPUDrawFlags flags) { PBVHNode *node; int n; @@ -986,7 +1018,7 @@ node->totprim, bvh->gridsize, bvh->gridkey, - smooth); + flags & GPU_DRAW_SMOOTH); } else { GPU_update_mesh_vert_buffers(node->draw_buffers, @@ -1011,10 +1043,7 @@ } else { GPU_update_mesh_color_buffers(node->draw_buffers, - bvh->vdata, - node->vert_indices, - node->uniq_verts + - node->face_verts); + bvh, node, flags); } node->flag &= ~PBVH_UpdateColorBuffers; @@ -1176,14 +1205,22 @@ } void BLI_pbvh_node_get_faces(PBVH *bvh, PBVHNode *node, - int **face_indices, int *totnode) + struct MFace **mface, struct CustomData **fdata, + int **face_indices, int **face_vert_indices, + int *totnode) { if(bvh->grids) { + if(mface) *mface= NULL; + if(fdata) *fdata= NULL; if(face_indices) *face_indices= NULL; + if(face_vert_indices) *face_vert_indices= NULL; if(totnode) *totnode= 0; } else { + if(mface) *mface= bvh->faces; + if(fdata) *fdata= bvh->fdata; if(face_indices) *face_indices= node->prim_indices; + if(face_vert_indices) *face_vert_indices= node->face_vert_indices; if(totnode) *totnode= node->totprim; } } @@ -1431,7 +1468,7 @@ return pbvh_planes_contain_AABB(bb_min, bb_max, data); } -void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smooth) +void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int flags) { PBVHNode **nodes; int totnode; @@ -1441,10 +1478,12 @@ &nodes, &totnode); pbvh_update_normals(bvh, nodes, totnode, face_nors); - pbvh_update_draw_buffers(bvh, nodes, totnode, smooth); + pbvh_update_draw_buffers(bvh, nodes, totnode, flags); if(nodes) MEM_freeN(nodes); + glShadeModel((flags & GPU_DRAW_SMOOTH) ? GL_SMOOTH: GL_FLAT); + if(planes) { BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB, planes, BLI_pbvh_node_draw, NULL); @@ -1452,6 +1491,8 @@ else { BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, NULL); } + + glShadeModel(GL_FLAT); } void BLI_pbvh_grids_update(PBVH *bvh, DMGridData **grids, Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h =================================================================== @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs