Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_utils.c
| Show First 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | const int *material_indices = (const int *)CustomData_get_layer_named( | ||||
| &me_eval->pdata, CD_PROP_INT32, "material_index"); | &me_eval->pdata, CD_PROP_INT32, "material_index"); | ||||
| /* test all faces in the derivedmesh with the original index of the picked face */ | /* test all faces in the derivedmesh with the original index of the picked face */ | ||||
| /* face means poly here, not triangle, indeed */ | /* face means poly here, not triangle, indeed */ | ||||
| for (i = 0; i < tottri; i++, lt++) { | for (i = 0; i < tottri; i++, lt++) { | ||||
| findex = index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly; | findex = index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly; | ||||
| if (findex == faceindex) { | if (findex == faceindex) { | ||||
| const MLoopUV *mloopuv; | const float(*mloopuv)[2]; | ||||
| const MLoopUV *tri_uv[3]; | const float *tri_uv[3]; | ||||
| float tri_co[3][3]; | float tri_co[3][3]; | ||||
| for (int j = 3; j--;) { | for (int j = 3; j--;) { | ||||
| copy_v3_v3(tri_co[j], positions[mloop[lt->tri[j]].v]); | copy_v3_v3(tri_co[j], positions[mloop[lt->tri[j]].v]); | ||||
| } | } | ||||
| if (mode == PAINT_CANVAS_SOURCE_MATERIAL) { | if (mode == PAINT_CANVAS_SOURCE_MATERIAL) { | ||||
| const Material *ma; | const Material *ma; | ||||
| const TexPaintSlot *slot; | const TexPaintSlot *slot; | ||||
| ma = BKE_object_material_get( | ma = BKE_object_material_get( | ||||
| ob_eval, material_indices == NULL ? 1 : material_indices[lt->poly] + 1); | ob_eval, material_indices == NULL ? 1 : material_indices[lt->poly] + 1); | ||||
| slot = &ma->texpaintslot[ma->paint_active_slot]; | slot = &ma->texpaintslot[ma->paint_active_slot]; | ||||
| if (!(slot && slot->uvname && | if (!(slot && slot->uvname && | ||||
| (mloopuv = CustomData_get_layer_named(&me_eval->ldata, CD_MLOOPUV, slot->uvname)))) { | (mloopuv = CustomData_get_layer_named( | ||||
| mloopuv = CustomData_get_layer(&me_eval->ldata, CD_MLOOPUV); | &me_eval->ldata, CD_PROP_FLOAT2, slot->uvname)))) { | ||||
| mloopuv = CustomData_get_layer(&me_eval->ldata, CD_PROP_FLOAT2); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| mloopuv = CustomData_get_layer(&me_eval->ldata, CD_MLOOPUV); | mloopuv = CustomData_get_layer(&me_eval->ldata, CD_PROP_FLOAT2); | ||||
| } | } | ||||
| tri_uv[0] = &mloopuv[lt->tri[0]]; | tri_uv[0] = mloopuv[lt->tri[0]]; | ||||
| tri_uv[1] = &mloopuv[lt->tri[1]]; | tri_uv[1] = mloopuv[lt->tri[1]]; | ||||
| tri_uv[2] = &mloopuv[lt->tri[2]]; | tri_uv[2] = mloopuv[lt->tri[2]]; | ||||
| p[0] = xy[0]; | p[0] = xy[0]; | ||||
| p[1] = xy[1]; | p[1] = xy[1]; | ||||
| imapaint_tri_weights(matrix, view, UNPACK3(tri_co), p, w); | imapaint_tri_weights(matrix, view, UNPACK3(tri_co), p, w); | ||||
| absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); | absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); | ||||
| if (absw < minabsw) { | if (absw < minabsw) { | ||||
| uv[0] = tri_uv[0]->uv[0] * w[0] + tri_uv[1]->uv[0] * w[1] + tri_uv[2]->uv[0] * w[2]; | uv[0] = tri_uv[0][0] * w[0] + tri_uv[1][0] * w[1] + tri_uv[2][0] * w[2]; | ||||
| uv[1] = tri_uv[0]->uv[1] * w[0] + tri_uv[1]->uv[1] * w[1] + tri_uv[2]->uv[1] * w[2]; | uv[1] = tri_uv[0][1] * w[0] + tri_uv[1][1] * w[1] + tri_uv[2][1] * w[2]; | ||||
| minabsw = absw; | minabsw = absw; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* returns 0 if not found, otherwise 1 */ | /* returns 0 if not found, otherwise 1 */ | ||||
| static int imapaint_pick_face(ViewContext *vc, const int mval[2], uint *r_index, uint totpoly) | static int imapaint_pick_face(ViewContext *vc, const int mval[2], uint *r_index, uint totpoly) | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (ob) { | ||||
| const int *material_indices = (const int *)CustomData_get_layer_named( | const int *material_indices = (const int *)CustomData_get_layer_named( | ||||
| &me_eval->pdata, CD_PROP_INT32, "material_index"); | &me_eval->pdata, CD_PROP_INT32, "material_index"); | ||||
| ViewContext vc; | ViewContext vc; | ||||
| const int mval[2] = {x, y}; | const int mval[2] = {x, y}; | ||||
| uint faceindex; | uint faceindex; | ||||
| uint totpoly = me->totpoly; | uint totpoly = me->totpoly; | ||||
| if (CustomData_has_layer(&me_eval->ldata, CD_MLOOPUV)) { | if (CustomData_has_layer(&me_eval->ldata, CD_PROP_FLOAT2)) { | ||||
| ED_view3d_viewcontext_init(C, &vc, depsgraph); | ED_view3d_viewcontext_init(C, &vc, depsgraph); | ||||
| view3d_operator_needs_opengl(C); | view3d_operator_needs_opengl(C); | ||||
| if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { | if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { | ||||
| Image *image = NULL; | Image *image = NULL; | ||||
| int interp = SHD_INTERP_LINEAR; | int interp = SHD_INTERP_LINEAR; | ||||
| ▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines | |||||