Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/editderivedmesh.c
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| #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); | ||||
| } | } | ||||
| static void emDM_drawMappedEdgesInterp(DerivedMesh *dm, | /** | ||||
| * 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_vertex_weight(BMesh *bm, BMVert *eve, int vgroup_index) | |||||
| { | |||||
| MDeformVert *dvert; | |||||
| MDeformWeight *dw; | |||||
| const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); | |||||
campbellbarton: This should be accessed once and used for every vertex. Then `cd_dvert_offset < 0` can be… | |||||
| if (cd_dvert_offset < 0) | |||||
| return -1.0f; // no weight groups | |||||
| dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); | |||||
| dw = defvert_find_index(dvert, vgroup_index); | |||||
| return dw ? dw->weight : -1.0f; | |||||
| } | |||||
| /** | |||||
| * the returned value can be -1.0 when the vertex is not weighted. | |||||
| */ | |||||
| static float get_weight_for_vert(BMesh *bm, int vert_index, int vgroup_index) | |||||
campbellbartonUnsubmitted 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… | |||||
| { | |||||
| BMVert *eve = BM_vert_at_index(bm, vert_index); | |||||
| return get_vertex_weight(bm, eve, vgroup_index); | |||||
| } | |||||
| static void get_rgb_from_weight(float col[3], const float weight, const char col0[3]) | |||||
campbellbartonUnsubmitted Not Done Inline ActionsNot sure why col0 is passed. campbellbarton: Not sure why `col0` is passed. | |||||
| { | |||||
| if (weight < 0) { | |||||
| col[0] = col0[0]; | |||||
| col[1] = col0[1]; | |||||
| col[2] = col0[2]; | |||||
| } | |||||
| else { | |||||
| weight_to_rgb(col, weight); | |||||
| col[0] *= 255; | |||||
| col[1] *= 255; | |||||
| col[2] *= 255; | |||||
| } | |||||
| } | |||||
| static void emDM_drawMappedEdgesInterp(Object *ob, | |||||
campbellbartonUnsubmitted 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. | |||||
| DerivedMesh *dm, | |||||
| DMSetDrawOptions setDrawOptions, | DMSetDrawOptions setDrawOptions, | ||||
| DMSetDrawInterpOptions setDrawInterpOptions, | DMSetDrawInterpOptions setDrawInterpOptions, | ||||
| void *userData) | void *userData, | ||||
| const char dt) | |||||
| { | { | ||||
| EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; | ||||
| BMesh *bm = bmdm->em->bm; | BMesh *bm = bmdm->em->bm; | ||||
| BMEdge *eed; | BMEdge *eed; | ||||
| BMIter iter; | BMIter iter; | ||||
| int i; | int i; | ||||
| unsigned char col_unweighted[3]={255,0,255}; | |||||
| float col[3]; | |||||
| float weight; | |||||
| Mesh *me = ob->data; | |||||
| glBegin(GL_LINES); | |||||
| if (me->drawflag & ME_DRAWEIGHT) | |||||
| glEnable(GL_BLEND); | |||||
| 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) { | ||||
| if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) { | ||||
| if (me->drawflag & ME_DRAWEIGHT && dt == OB_WIRE) { | |||||
| weight = get_weight_for_vert(bm, BM_elem_index_get(eed->v2), ob->actdef-1); | |||||
| get_rgb_from_weight(col, weight, col_unweighted); | |||||
| glColor4ub(col[0],col[1],col[2],0); | |||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]); | |||||
| weight = get_weight_for_vert(bm, BM_elem_index_get(eed->v2), ob->actdef-1); | |||||
| get_rgb_from_weight(col, weight, col_unweighted); | |||||
| glColor4ub(col[0],col[1],col[2],0); | |||||
| glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]); | |||||
| } | |||||
| else { | |||||
| 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) { | ||||
campbellbartonUnsubmitted 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 (me->drawflag & ME_DRAWEIGHT && dt == OB_WIRE) { | |||||
| weight = get_weight_for_vert(bm, BM_elem_index_get(eed->v1), ob->actdef-1); | |||||
| get_rgb_from_weight(col, weight, col_unweighted); | |||||
| glColor4ub(col[0],col[1],col[2],0); | |||||
campbellbartonUnsubmitted 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(bm, BM_elem_index_get(eed->v2), ob->actdef-1); | |||||
| get_rgb_from_weight(col, weight, col_unweighted); | |||||
| glColor4ub(col[0],col[1],col[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 (me->drawflag & ME_DRAWEIGHT) | |||||
| 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