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 *mp; | ||||
| MTFace *tf; | const MTexPoly *tf; | ||||
| } drawEMTFMapped_userData; | } drawEMTFMapped_userData; | ||||
| typedef struct drawTFace_userData { | typedef struct drawTFace_userData { | ||||
| Mesh *me; | const Mesh *me; | ||||
| MFace *mf; | const MPoly *mp; | ||||
| MTFace *tf; | const MTexPoly *tf; | ||||
| } 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 487 Lines • ▼ Show 20 Lines | static DMDrawOption draw_tface__set_draw(MTexPoly *mtexpoly, const bool UNUSED(has_mcol), int matnr) | ||||
| /* 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) | ||||
| { | { | ||||
| 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); | const MPoly *mpoly = dm->getPolyArray(dm); | ||||
| MCol *finalCol; | const MLoopTri *lt = dm->looptris.array; | ||||
| MLoopCol *finalCol; | |||||
| int i, j; | int i, j; | ||||
| MCol *mcol = NULL; | MLoopCol *mloopcol = NULL; | ||||
| 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 = 0; i < dm->looptris.num; i++) { | ||||
| Material *ma = give_current_material(Gtexdraw.ob, mface[i].mat_nr + 1); | const MPoly *mp = &mpoly[lt->poly]; | ||||
| const unsigned int *ltri = lt->tri; | |||||
| Material *ma = give_current_material(Gtexdraw.ob, mp->mat_nr + 1); | |||||
| if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { | if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { | ||||
| if (mcol) | if (mloopcol) { | ||||
| memcpy(&finalCol[i * 4], &mcol[i * 4], sizeof(MCol) * 4); | for (j = 0; j < 3; j++) { | ||||
| finalCol[ltri[j]] = mloopcol[ltri[j]]; | |||||
| } | |||||
| } | |||||
| else | else | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = 255; | finalCol[ltri[j]].b = 255; | ||||
| finalCol[i * 4 + j].g = 255; | finalCol[ltri[j]].g = 255; | ||||
| finalCol[i * 4 + j].r = 255; | finalCol[ltri[j]].r = 255; | ||||
| } | } | ||||
| } | } | ||||
| 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++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = 255; | finalCol[ltri[j]].b = 255; | ||||
| finalCol[i * 4 + j].g = 0; | finalCol[ltri[j]].g = 0; | ||||
| finalCol[i * 4 + j].r = 255; | finalCol[ltri[j]].r = 255; | ||||
| } | } | ||||
| } | } | ||||
| else if (ma && (ma->shade_flag & MA_OBCOLOR)) { | else if (ma && (ma->shade_flag & MA_OBCOLOR)) { | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = Gtexdraw.obcol[0]; | finalCol[ltri[j]].b = Gtexdraw.obcol[0]; | ||||
| finalCol[i * 4 + j].g = Gtexdraw.obcol[1]; | finalCol[ltri[j]].g = Gtexdraw.obcol[1]; | ||||
| finalCol[i * 4 + j].r = Gtexdraw.obcol[2]; | finalCol[ltri[j]].r = Gtexdraw.obcol[2]; | ||||
| } | } | ||||
| } | } | ||||
| else if (!mcol) { | else if (!mloopcol) { | ||||
| if (mtexpoly) { | if (mtexpoly) { | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = 255; | finalCol[ltri[j]].b = 255; | ||||
| finalCol[i * 4 + j].g = 255; | finalCol[ltri[j]].g = 255; | ||||
| finalCol[i * 4 + j].r = 255; | finalCol[ltri[j]].r = 255; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| float col[3]; | float col[3]; | ||||
| if (ma) { | if (ma) { | ||||
| if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r); | if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r); | ||||
| else copy_v3_v3(col, &ma->r); | else copy_v3_v3(col, &ma->r); | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = FTOCHAR(col[0]); | finalCol[ltri[j]].b = FTOCHAR(col[0]); | ||||
| finalCol[i * 4 + j].g = FTOCHAR(col[1]); | finalCol[ltri[j]].g = FTOCHAR(col[1]); | ||||
| finalCol[i * 4 + j].r = FTOCHAR(col[2]); | finalCol[ltri[j]].r = FTOCHAR(col[2]); | ||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].b = 255; | finalCol[ltri[j]].b = 255; | ||||
| finalCol[i * 4 + j].g = 255; | finalCol[ltri[j]].g = 255; | ||||
| finalCol[i * 4 + j].r = 255; | finalCol[ltri[j]].r = 255; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (j = 0; j < 4; j++) { | for (j = 0; j < 3; j++) { | ||||
| finalCol[i * 4 + j].r = mcol[i * 4 + j].r; | finalCol[ltri[j]] = mloopcol[ltri[j]]; | ||||
| finalCol[i * 4 + j].g = mcol[i * 4 + j].g; | |||||
| finalCol[i * 4 + j].b = mcol[i * 4 + j].b; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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->mp && data->mp[cur_index].mat_nr != data->mp[next_index].mat_nr) | ||||
| return 0; | return 0; | ||||
| if (data->tf && data->tf[cur_index].tpage != data->tf[next_index].tpage) | if (data->tf && data->tf[cur_index].tpage != data->tf[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->mp && data->mp[cur_index].mat_nr != data->mp[next_index].mat_nr) | ||||
| return 0; | return 0; | ||||
| if (data->tf && data->tf[cur_index].tpage != data->tf[next_index].tpage) | if (data->tf && data->tf[cur_index].tpage != data->tf[next_index].tpage) | ||||
| return 0; | return 0; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| Show All 18 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.mp = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| data.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | data.tf = 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.mp = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| userData.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | userData.tf = 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.mp = DM_get_poly_data_layer(dm, CD_MPOLY); | ||||
| userData.tf = DM_get_tessface_data_layer(dm, CD_MTFACE); | userData.tf = 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 349 Lines • Show Last 20 Lines | |||||