Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/drawmesh.c
| Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | typedef struct drawMeshFaceSelect_userData { | ||||
| Mesh *me; | Mesh *me; | ||||
| BLI_bitmap *edge_flags; /* pairs of edge options (visible, select) */ | BLI_bitmap *edge_flags; /* pairs of edge options (visible, select) */ | ||||
| } drawMeshFaceSelect_userData; | } drawMeshFaceSelect_userData; | ||||
| typedef struct drawEMTFMapped_userData { | typedef struct drawEMTFMapped_userData { | ||||
| BMEditMesh *em; | BMEditMesh *em; | ||||
| bool has_mcol; | bool has_mcol; | ||||
| int cd_poly_tex_offset; | int cd_poly_tex_offset; | ||||
| MFace *mf; | const MPoly *mpoly; | ||||
| MTFace *tf; | const MTexPoly *mtexpoly; | ||||
| } drawEMTFMapped_userData; | } drawEMTFMapped_userData; | ||||
| typedef struct drawTFace_userData { | typedef struct drawTFace_userData { | ||||
| Mesh *me; | const Mesh *me; | ||||
| MFace *mf; | const MPoly *mpoly; | ||||
| MTFace *tf; | const MTexPoly *mtexpoly; | ||||
| } drawTFace_userData; | } drawTFace_userData; | ||||
| /**************************** Face Select Mode *******************************/ | /**************************** Face Select Mode *******************************/ | ||||
| /* mainly to be less confusing */ | /* mainly to be less confusing */ | ||||
| BLI_INLINE int edge_vis_index(const int index) { return index * 2; } | BLI_INLINE int edge_vis_index(const int index) { return index * 2; } | ||||
| BLI_INLINE int edge_sel_index(const int index) { return index * 2 + 1; } | BLI_INLINE int edge_sel_index(const int index) { return index * 2 + 1; } | ||||
| ▲ Show 20 Lines • Show All 486 Lines • ▼ Show 20 Lines | if (mtexpoly || Gtexdraw.is_texpaint) | ||||
| set_draw_settings_cached(0, mtexpoly, ma, Gtexdraw); | set_draw_settings_cached(0, mtexpoly, ma, Gtexdraw); | ||||
| /* always use color from mcol, as set in update_tface_color_layer */ | /* always use color from mcol, as set in update_tface_color_layer */ | ||||
| return DM_DRAW_OPTION_NORMAL; | return DM_DRAW_OPTION_NORMAL; | ||||
| } | } | ||||
| static void update_tface_color_layer(DerivedMesh *dm, bool use_mcol) | static void update_tface_color_layer(DerivedMesh *dm, bool use_mcol) | ||||
| { | { | ||||
| const MPoly *mp = dm->getPolyArray(dm); | |||||
| const int mpoly_num = dm->getNumPolys(dm); | |||||
| MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY); | MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY); | ||||
| MFace *mface = dm->getTessFaceArray(dm); | MLoopCol *finalCol; | ||||
| MCol *finalCol; | |||||
| int i, j; | int i, j; | ||||
| MCol *mcol = NULL; | MLoopCol *mloopcol = NULL; | ||||
| /* cache material values to avoid a lot of lookups */ | /* cache material values to avoid a lot of lookups */ | ||||
| Material *ma = NULL; | Material *ma = NULL; | ||||
| short mat_nr_prev = -1; | short mat_nr_prev = -1; | ||||
| enum { | enum { | ||||
| COPY_CALC, | COPY_CALC, | ||||
| COPY_ORIG, | COPY_ORIG, | ||||
| COPY_PREV, | COPY_PREV, | ||||
| } copy_mode = COPY_CALC; | } copy_mode = COPY_CALC; | ||||
| if (use_mcol) { | if (use_mcol) { | ||||
| mcol = dm->getTessFaceDataArray(dm, CD_PREVIEW_MCOL); | mloopcol = dm->getLoopDataArray(dm, CD_PREVIEW_MLOOPCOL); | ||||
| if (!mcol) | if (!mloopcol) | ||||
| mcol = dm->getTessFaceDataArray(dm, CD_MCOL); | mloopcol = dm->getLoopDataArray(dm, CD_MLOOPCOL); | ||||
| } | } | ||||
| if (CustomData_has_layer(&dm->faceData, CD_TEXTURE_MCOL)) { | if (CustomData_has_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL)) { | ||||
| finalCol = CustomData_get_layer(&dm->faceData, CD_TEXTURE_MCOL); | finalCol = CustomData_get_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL); | ||||
| } | } | ||||
| else { | else { | ||||
| finalCol = MEM_mallocN(sizeof(MCol) * 4 * dm->getNumTessFaces(dm), "add_tface_color_layer"); | finalCol = MEM_mallocN(sizeof(MLoopCol) * dm->numLoopData, "add_tface_color_layer"); | ||||
| CustomData_add_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL, CD_ASSIGN, finalCol, dm->numLoopData); | |||||
| CustomData_add_layer(&dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numTessFaceData); | |||||
| } | } | ||||
| for (i = 0; i < dm->getNumTessFaces(dm); i++) { | for (i = mpoly_num; i--; mp++) { | ||||
| const short mat_nr = mface[i].mat_nr; | const short mat_nr = mp->mat_nr; | ||||
| if (UNLIKELY(mat_nr_prev != mat_nr)) { | if (UNLIKELY(mat_nr_prev != mat_nr)) { | ||||
| ma = give_current_material(Gtexdraw.ob, mface[i].mat_nr + 1); | ma = give_current_material(Gtexdraw.ob, mat_nr + 1); | ||||
| copy_mode = COPY_CALC; | copy_mode = COPY_CALC; | ||||
| mat_nr_prev = mat_nr; | mat_nr_prev = mat_nr; | ||||
| } | } | ||||
| /* avoid lookups */ | /* avoid lookups */ | ||||
| if (copy_mode == COPY_ORIG) { | if (copy_mode == COPY_ORIG) { | ||||
| memcpy(&finalCol[i * 4], &mcol[i * 4], sizeof(MCol) * 4); | memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop); | ||||
| } | } | ||||
| else if (copy_mode == COPY_PREV) { | else if (copy_mode == COPY_PREV) { | ||||
| memcpy(&finalCol[i * 4], &finalCol[(i - 1) * 4], sizeof(MCol) * 4); | int loop_index = mp->loopstart; | ||||
| const MLoopCol *lcol_prev = &finalCol[(mp - 1)->loopstart]; | |||||
| for (j = 0; j < mp->totloop; j++, loop_index++) { | |||||
| finalCol[loop_index] = *lcol_prev; | |||||
| } | |||||
| } | } | ||||
| /* (copy_mode == COPY_CALC) */ | /* (copy_mode == COPY_CALC) */ | ||||
| else if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { | else if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { | ||||
| if (mcol) { | if (mloopcol) { | ||||
| memcpy(&finalCol[i * 4], &mcol[i * 4], sizeof(MCol) * 4); | memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop); | ||||
| copy_mode = COPY_ORIG; | copy_mode = COPY_ORIG; | ||||
| } | } | ||||
| else { | else { | ||||
| for (j = 0; j < 4; j++) { | memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop); | ||||
| finalCol[i * 4 + j].b = 255; | |||||
| finalCol[i * 4 + j].g = 255; | |||||
| finalCol[i * 4 + j].r = 255; | |||||
| } | |||||
| copy_mode = COPY_PREV; | copy_mode = COPY_PREV; | ||||
| } | } | ||||
| } | } | ||||
| else if (mtexpoly && set_draw_settings_cached(0, mtexpoly, ma, Gtexdraw)) { | else if (mtexpoly && set_draw_settings_cached(0, mtexpoly, ma, Gtexdraw)) { | ||||
| for (j = 0; j < 4; j++) { | int loop_index = mp->loopstart; | ||||
| finalCol[i * 4 + j].b = 255; | for (j = 0; j < mp->totloop; j++, loop_index++) { | ||||
| finalCol[i * 4 + j].g = 0; | finalCol[loop_index].r = 255; | ||||
| finalCol[i * 4 + j].r = 255; | finalCol[loop_index].g = 0; | ||||
| finalCol[loop_index].b = 255; | |||||
| } | } | ||||
| copy_mode = COPY_PREV; | copy_mode = COPY_PREV; | ||||
| } | } | ||||
| else if (ma && (ma->shade_flag & MA_OBCOLOR)) { | else if (ma && (ma->shade_flag & MA_OBCOLOR)) { | ||||
| for (j = 0; j < 4; j++) { | int loop_index = mp->loopstart;; | ||||
| finalCol[i * 4 + j].b = Gtexdraw.obcol[0]; | for (j = 0; j < mp->totloop; j++, loop_index++) { | ||||
| finalCol[i * 4 + j].g = Gtexdraw.obcol[1]; | copy_v3_v3_char(&finalCol[loop_index].r, (char *)Gtexdraw.obcol); | ||||
| finalCol[i * 4 + j].r = Gtexdraw.obcol[2]; | |||||
| } | } | ||||
| copy_mode = COPY_PREV; | copy_mode = COPY_PREV; | ||||
| } | } | ||||
| else { | else { | ||||
| if (mcol) { | if (mloopcol) { | ||||
| memcpy(&finalCol[i * 4], &mcol[i * 4], sizeof(MCol) * 4); | memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop); | ||||
| copy_mode = COPY_ORIG; | copy_mode = COPY_ORIG; | ||||
| } | } | ||||
| else if (mtexpoly) { | else if (mtexpoly) { | ||||
| for (j = 0; j < 4; j++) { | memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop); | ||||
| finalCol[i * 4 + j].b = 255; | |||||
| finalCol[i * 4 + j].g = 255; | |||||
| finalCol[i * 4 + j].r = 255; | |||||
| } | |||||
| copy_mode = COPY_PREV; | copy_mode = COPY_PREV; | ||||
| } | } | ||||
| else { | else { | ||||
| if (ma) { | |||||
| float col[3]; | float col[3]; | ||||
| MCol tcol; | |||||
| if (Gtexdraw.color_profile) { | if (ma) { | ||||
| linearrgb_to_srgb_v3_v3(col, &ma->r); | int loop_index = mp->loopstart; | ||||
| } | MLoopCol lcol; | ||||
| else { | |||||
| copy_v3_v3(col, &ma->r); | |||||
| } | |||||
| tcol.b = FTOCHAR(col[0]); | if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r); | ||||
| tcol.g = FTOCHAR(col[1]); | else copy_v3_v3(col, &ma->r); | ||||
| tcol.r = FTOCHAR(col[2]); | rgb_float_to_uchar((unsigned char *)&lcol.r, col); | ||||
| tcol.a = 255; | lcol.a = 255; | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < mp->totloop; j++, loop_index++) { | ||||
| finalCol[i * 4 + j] = tcol; | finalCol[loop_index] = lcol; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (j = 0; j < 4; j++) { | memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop); | ||||
| finalCol[i * 4 + j].b = 255; | |||||
| finalCol[i * 4 + j].g = 255; | |||||
| finalCol[i * 4 + j].r = 255; | |||||
| } | |||||
| } | } | ||||
| copy_mode = COPY_PREV; | copy_mode = COPY_PREV; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static DMDrawOption draw_tface_mapped__set_draw(void *userData, int origindex, int UNUSED(mat_nr)) | static DMDrawOption draw_tface_mapped__set_draw(void *userData, int origindex, int UNUSED(mat_nr)) | ||||
| { | { | ||||
| Mesh *me = ((drawTFace_userData *)userData)->me; | const Mesh *me = ((drawTFace_userData *)userData)->me; | ||||
| /* array checked for NULL before calling */ | /* array checked for NULL before calling */ | ||||
| MPoly *mpoly = &me->mpoly[origindex]; | MPoly *mpoly = &me->mpoly[origindex]; | ||||
| BLI_assert(origindex >= 0 && origindex < me->totpoly); | BLI_assert(origindex >= 0 && origindex < me->totpoly); | ||||
| if (mpoly->flag & ME_HIDE) { | if (mpoly->flag & ME_HIDE) { | ||||
| return DM_DRAW_OPTION_SKIP; | return DM_DRAW_OPTION_SKIP; | ||||
| ▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | static void draw_mesh_text(Scene *scene, Object *ob, int glsl) | ||||
| ddm->release(ddm); | ddm->release(ddm); | ||||
| } | } | ||||
| static int compareDrawOptions(void *userData, int cur_index, int next_index) | static int compareDrawOptions(void *userData, int cur_index, int next_index) | ||||
| { | { | ||||
| drawTFace_userData *data = userData; | drawTFace_userData *data = userData; | ||||
| if (data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr) | if (data->mpoly && data->mpoly[cur_index].mat_nr != data->mpoly[next_index].mat_nr) | ||||
| return 0; | return 0; | ||||
| if (data->tf && data->tf[cur_index].tpage != data->tf[next_index].tpage) | if (data->mtexpoly && data->mtexpoly[cur_index].tpage != data->mtexpoly[next_index].tpage) | ||||
| return 0; | return 0; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) | static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) | ||||
| { | { | ||||
| drawEMTFMapped_userData *data = userData; | drawEMTFMapped_userData *data = userData; | ||||
| if (data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr) | if (data->mpoly && data->mpoly[cur_index].mat_nr != data->mpoly[next_index].mat_nr) | ||||
| return 0; | return 0; | ||||
| if (data->tf && data->tf[cur_index].tpage != data->tf[next_index].tpage) | if (data->mtexpoly && data->mtexpoly[cur_index].tpage != data->mtexpoly[next_index].tpage) { | ||||
| return 0; | return 0; | ||||
| } | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, | static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, | ||||
| Object *ob, DerivedMesh *dm, const int draw_flags) | Object *ob, DerivedMesh *dm, const int draw_flags) | ||||
| { | { | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| Show All 14 Lines | static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, | ||||
| if (ob->mode & OB_MODE_EDIT) { | if (ob->mode & OB_MODE_EDIT) { | ||||
| drawEMTFMapped_userData data; | drawEMTFMapped_userData data; | ||||
| data.em = me->edit_btmesh; | data.em = me->edit_btmesh; | ||||
| data.has_mcol = CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL); | data.has_mcol = CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL); | ||||
| data.cd_poly_tex_offset = CustomData_get_offset(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY); | data.cd_poly_tex_offset = CustomData_get_offset(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY); | ||||
| data.mf = DM_get_tessface_data_layer(dm, CD_MFACE); | data.mpoly = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| data.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | data.mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY); | ||||
| dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, compareDrawOptionsEm, &data, 0); | dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, compareDrawOptionsEm, &data, 0); | ||||
| } | } | ||||
| else if (draw_flags & DRAW_FACE_SELECT) { | else if (draw_flags & DRAW_FACE_SELECT) { | ||||
| if (ob->mode & OB_MODE_WEIGHT_PAINT) | if (ob->mode & OB_MODE_WEIGHT_PAINT) | ||||
| dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_facemask, GPU_enable_material, NULL, me, | dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_facemask, GPU_enable_material, NULL, me, | ||||
| DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH); | DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH); | ||||
| else { | else { | ||||
| drawTFace_userData userData; | drawTFace_userData userData; | ||||
| userData.mf = DM_get_tessface_data_layer(dm, CD_MFACE); | userData.mpoly = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| userData.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | userData.mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY); | ||||
| userData.me = me; | userData.me = me; | ||||
| dm->drawMappedFacesTex(dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, compareDrawOptions, &userData, uvflag); | dm->drawMappedFacesTex(dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, compareDrawOptions, &userData, uvflag); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| drawTFace_userData userData; | drawTFace_userData userData; | ||||
| update_tface_color_layer(dm, !(ob->mode & OB_MODE_TEXTURE_PAINT)); | update_tface_color_layer(dm, !(ob->mode & OB_MODE_TEXTURE_PAINT)); | ||||
| userData.mf = DM_get_tessface_data_layer(dm, CD_MFACE); | userData.mpoly = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| userData.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | userData.mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY); | ||||
| userData.me = NULL; | userData.me = NULL; | ||||
| dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, &userData, uvflag); | dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, &userData, uvflag); | ||||
| } | } | ||||
| /* draw game engine text hack */ | /* draw game engine text hack */ | ||||
| if (BKE_bproperty_object_get(ob, "Text")) | if (BKE_bproperty_object_get(ob, "Text")) | ||||
| draw_mesh_text(scene, ob, 0); | draw_mesh_text(scene, ob, 0); | ||||
| ▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | else if ((use_light == false) || (ob->dtx & OB_DRAWWIRE)) { | ||||
| draw_mesh_paint_weight_edges(rv3d, dm, use_depth, use_alpha, NULL, NULL); | draw_mesh_paint_weight_edges(rv3d, dm, use_depth, use_alpha, NULL, NULL); | ||||
| if (use_alpha == false) { | if (use_alpha == false) { | ||||
| set_inverted_drawing(0); | set_inverted_drawing(0); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||