Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/editderivedmesh.c
| Show All 40 Lines | |||||
| * is likely to be a little slow. | * is likely to be a little slow. | ||||
| */ | */ | ||||
| #include "GL/glew.h" | #include "GL/glew.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_jitter.h" | #include "BLI_jitter.h" | ||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BKE_cdderivedmesh.h" | #include "BKE_cdderivedmesh.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_editmesh_bvh.h" | #include "BKE_editmesh_bvh.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "BKE_deform.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_extensions.h" | ||||
| extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */ | extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */ | ||||
| static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]); | static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]); | ||||
| typedef struct EditDerivedBMesh { | typedef struct EditDerivedBMesh { | ||||
| DerivedMesh dm; | DerivedMesh dm; | ||||
| BMEditMesh *em; | BMEditMesh *em; | ||||
| ▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void emDM_drawEdges(DerivedMesh *dm, | static void emDM_drawEdges(DerivedMesh *dm, | ||||
| int UNUSED(drawLooseEdges), | int UNUSED(drawLooseEdges), | ||||
| int UNUSED(drawAllEdges)) | int UNUSED(drawAllEdges)) | ||||
| { | { | ||||
| emDM_drawMappedEdges(dm, NULL, NULL); | emDM_drawMappedEdges(dm, NULL, NULL); | ||||
| } | } | ||||
| /** | |||||
| * This function returns -1.0 if no weight groups exist | |||||
| * or the active weight group has no weight defined for | |||||
| * the specified vertex. | |||||
| */ | |||||
| static float get_weight_for_vert(BMVert *eve, int vgroup_index, int cd_dvert_offset, char weight_user, const int defgroup_tot) | |||||
| { | |||||
| MDeformVert *dvert; | |||||
| MDeformWeight *dw; | |||||
| if (cd_dvert_offset == -1) | |||||
| return -1.0f; // unweighted | |||||
| dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); | |||||
| dw = defvert_find_index(dvert, vgroup_index); | |||||
| if (dw) | |||||
| return dw->weight; | |||||
| if(weight_user == 0) | |||||
| return 0.0f; | |||||
| if (weight_user == 1) | |||||
| return -1.0f; | |||||
| if (defvert_is_weight_zero(dvert, defgroup_tot)) | |||||
| return -1.0f; | |||||
| return 0.0f; | |||||
| } | |||||
| static const char *get_rgb_from_weight(char col[3], const float weight, const char alert_col[3]) | |||||
| { | |||||
| float fcol[3]; | |||||
| if (weight < 0) | |||||
| return alert_col; | |||||
| else | |||||
| weight_to_rgb(fcol, weight); | |||||
| col[0] = fcol[0]*255; | |||||
| col[1] = fcol[1]*255; | |||||
| col[2] = fcol[2]*255; | |||||
| return col; | |||||
| } | |||||
| extern struct DMWeightColorInfo G_dm_wcinfo; | |||||
| extern const char *get_weight_alert_color(); | |||||
| static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, | static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, | ||||
| DMSetDrawOptions setDrawOptions, | DMSetDrawOptions setDrawOptions, | ||||
| DMSetDrawInterpOptions setDrawInterpOptions, | DMSetDrawInterpOptions setDrawInterpOptions, | ||||
| void *userData) | void *userData, | ||||
| const bool draw_weights, | |||||
| const char weight_user) | |||||
| { | { | ||||
| EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | ||||
| BMesh *bm = bmdm->em->bm; | BMesh *bm = bmdm->em->bm; | ||||
| Object *ob = bmdm->em->ob; | |||||
campbellbarton: This should be accessed once and used for every vertex. Then `cd_dvert_offset < 0` can be… | |||||
| const int defgroup_tot = BLI_countlist(&ob->defbase); | |||||
| BMEdge *eed; | BMEdge *eed; | ||||
| BMIter iter; | BMIter iter; | ||||
| int i; | int i; | ||||
| float weight; | |||||
| const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); | |||||
| const char* alert_color = get_weight_alert_color(); | |||||
| char col[3]; | |||||
| glBegin(GL_LINES); | |||||
| if (draw_weights) | |||||
| glEnable(GL_BLEND); | |||||
Not Done Inline ActionsBM_vert_at_index isn't needed here, currently its getting the index from the vert, then the vert from the index, just pass the vert. eed->v1 / eed->v2 campbellbarton: `BM_vert_at_index` isn't needed here, currently its getting the index from the vert, then the… | |||||
| if (bmdm->vertexCos) { | if (bmdm->vertexCos) { | ||||
| BM_mesh_elem_index_ensure(bm, BM_VERT); | BM_mesh_elem_index_ensure(bm, BM_VERT); | ||||
| glBegin(GL_LINES); | |||||
| BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) { | BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) { | ||||
Not Done Inline ActionsNot sure why col0 is passed. campbellbarton: Not sure why `col0` is passed. | |||||
| if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | ||||
| if (draw_weights) { | |||||
| const char *vcol; | |||||
| weight = get_weight_for_vert(eed->v1, ob->actdef-1, cd_dvert_offset, weight_user, defgroup_tot); | |||||
| vcol = get_rgb_from_weight(col, weight, alert_color); | |||||
| glColor4ub(vcol[0],vcol[1],vcol[2],0); | |||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); | |||||
| weight = get_weight_for_vert(eed->v2, ob->actdef-1, cd_dvert_offset, weight_user, defgroup_tot); | |||||
| vcol = get_rgb_from_weight(col, weight, alert_color); | |||||
| glColor4ub(vcol[0], vcol[1], vcol[2], 0); | |||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); | |||||
| } | |||||
| else { | |||||
Not Done Inline ActionsNo need to add Object arg, use bmdm->em->ob instead. campbellbarton: No need to add `Object` arg, use `bmdm->em->ob` instead. | |||||
| setDrawInterpOptions(userData, i, 0.0); | setDrawInterpOptions(userData, i, 0.0); | ||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); | glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); | ||||
| setDrawInterpOptions(userData, i, 1.0); | setDrawInterpOptions(userData, i, 1.0); | ||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); | glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | } | ||||
| } | } | ||||
| else { | else { | ||||
| glBegin(GL_LINES); | |||||
| BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) { | BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) { | ||||
Not Done Inline Actionssuggest split this into 2 edge loops. same for loop above. campbellbarton: suggest split this into 2 edge loops. same for loop above. | |||||
| if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | ||||
| Mesh *me = ob->data; | |||||
| if (draw_weights) { | |||||
| const char *vcol; | |||||
| weight = get_weight_for_vert(eed->v1, ob->actdef-1, cd_dvert_offset, weight_user, defgroup_tot); | |||||
| vcol = get_rgb_from_weight(col, weight, alert_color); | |||||
| glColor4ub(vcol[0], vcol[1], vcol[2],0); | |||||
Not Done Inline Actionsbest call call color glColor3fv here. campbellbarton: best call call color `glColor3fv` here. | |||||
| glVertex3fv(eed->v1->co); | |||||
| weight = get_weight_for_vert(eed->v2, ob->actdef-1, cd_dvert_offset, weight_user, defgroup_tot); | |||||
| vcol = get_rgb_from_weight(col, weight, alert_color); | |||||
| glColor4ub(vcol[0], vcol[1], vcol[2],0); | |||||
| glVertex3fv(eed->v2->co); | |||||
| } | |||||
| else { | |||||
| setDrawInterpOptions(userData, i, 0.0); | setDrawInterpOptions(userData, i, 0.0); | ||||
| glVertex3fv(eed->v1->co); | glVertex3fv(eed->v1->co); | ||||
| setDrawInterpOptions(userData, i, 1.0); | setDrawInterpOptions(userData, i, 1.0); | ||||
| glVertex3fv(eed->v2->co); | glVertex3fv(eed->v2->co); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | |||||
| } | } | ||||
| } | } | ||||
| if (draw_weights) | |||||
| glDisable(GL_BLEND); | |||||
| glEnd(); | |||||
| } | |||||
| static void emDM_drawUVEdges(DerivedMesh *dm) | static void emDM_drawUVEdges(DerivedMesh *dm) | ||||
| { | { | ||||
| EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | ||||
| BMesh *bm = bmdm->em->bm; | BMesh *bm = bmdm->em->bm; | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMIter iter; | BMIter iter; | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | ||||
| ▲ Show 20 Lines • Show All 1,896 Lines • Show Last 20 Lines | |||||
This should be accessed once and used for every vertex. Then cd_dvert_offset < 0 can be avoided.
Also should check cd_dvert_offset == -1 since its only ever -1