Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_utils.c
| Show First 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | if (findex == faceindex) { | ||||
| 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]->uv[0] * w[0] + tri_uv[1]->uv[0] * w[1] + tri_uv[2]->uv[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]->uv[1] * w[0] + tri_uv[1]->uv[1] * w[1] + tri_uv[2]->uv[1] * w[2]; | ||||
| minabsw = absw; | minabsw = absw; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* returns 0 if not found, otherwise 1 */ | /* returns false if not found, otherwise true */ | ||||
| static int imapaint_pick_face(ViewContext *vc, | static bool imapaint_pick_face(struct EDSelectID_Context *sel_id_ctx, | ||||
| const int mval[2], | const int mval[2], | ||||
| unsigned int *r_index, | uint *r_index) | ||||
| unsigned int totpoly) | |||||
| { | { | ||||
| if (totpoly == 0) { | |||||
| return 0; | |||||
| } | |||||
| /* sample only on the exact position */ | /* sample only on the exact position */ | ||||
| ED_view3d_select_id_validate(vc); | uint sel_id = ED_select_buffer_sample_point(mval); | ||||
| *r_index = ED_select_buffer_sample_point(mval); | if (sel_id != 0 && ED_view3d_select_id_elem_get(sel_id_ctx, sel_id, r_index, NULL, NULL)) { | ||||
| return true; | |||||
| if ((*r_index) == 0 || (*r_index) > (unsigned int)totpoly) { | |||||
| return 0; | |||||
| } | } | ||||
| (*r_index)--; | return false; | ||||
| return 1; | |||||
| } | } | ||||
| static Image *imapaint_face_image(Object *ob, Mesh *me, int face_index) | static Image *imapaint_face_image(Object *ob, Mesh *me, int face_index) | ||||
| { | { | ||||
| Image *ima; | Image *ima; | ||||
| MPoly *mp = me->mpoly + face_index; | MPoly *mp = me->mpoly + face_index; | ||||
| Material *ma = give_current_material(ob, mp->mat_nr + 1); | Material *ma = give_current_material(ob, mp->mat_nr + 1); | ||||
| ima = ma && ma->texpaintslot ? ma->texpaintslot[ma->paint_active_slot].ima : NULL; | ima = ma && ma->texpaintslot ? ma->texpaintslot[ma->paint_active_slot].ima : NULL; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (symm & PAINT_SYMM_Z) { | ||||
| axis[2] *= -1.0f; | axis[2] *= -1.0f; | ||||
| angle *= -1.0f; | angle *= -1.0f; | ||||
| } | } | ||||
| axis_angle_normalized_to_quat(out, axis, angle); | axis_angle_normalized_to_quat(out, axis, angle); | ||||
| } | } | ||||
| /* used for both 3d view and image window */ | /* used for both 3d view and image window */ | ||||
| void paint_sample_color( | void paint_sample_color(bContext *C, | ||||
| bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette) | ARegion *ar, | ||||
| struct EDSelectID_Context **sel_id_ctx, | |||||
| int x, | |||||
| int y, | |||||
| bool texpaint_proj, | |||||
| bool use_palette) | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| Paint *paint = BKE_paint_get_active_from_context(C); | Paint *paint = BKE_paint_get_active_from_context(C); | ||||
| Palette *palette = BKE_paint_palette(paint); | Palette *palette = BKE_paint_palette(paint); | ||||
| PaletteColor *color = NULL; | PaletteColor *color = NULL; | ||||
| Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | ||||
| unsigned int col; | unsigned int col; | ||||
| Show All 10 Lines | if (use_palette) { | ||||
| color = BKE_palette_color_add(palette); | color = BKE_palette_color_add(palette); | ||||
| palette->active_color = BLI_listbase_count(&palette->colors) - 1; | palette->active_color = BLI_listbase_count(&palette->colors) - 1; | ||||
| } | } | ||||
| if (CTX_wm_view3d(C) && texpaint_proj) { | if (CTX_wm_view3d(C) && texpaint_proj) { | ||||
| /* first try getting a color directly from the mesh faces if possible */ | /* first try getting a color directly from the mesh faces if possible */ | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Object *ob = OBACT(view_layer); | Base *base = BASACT(view_layer); | ||||
| Object *ob = base->object; | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| bool sample_success = false; | bool sample_success = false; | ||||
| ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | ||||
| bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); | bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); | ||||
| if (ob) { | if (ob) { | ||||
| CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; | CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; | ||||
| cddata_masks.pmask |= CD_MASK_ORIGINDEX; | cddata_masks.pmask |= CD_MASK_ORIGINDEX; | ||||
| Mesh *me = (Mesh *)ob->data; | |||||
| Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); | Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); | ||||
| ViewContext vc; | |||||
| const int mval[2] = {x, y}; | const int mval[2] = {x, y}; | ||||
| unsigned int faceindex; | unsigned int faceindex; | ||||
| unsigned int totpoly = me->totpoly; | |||||
| if (CustomData_has_layer(&me_eval->ldata, CD_MLOOPUV)) { | if (CustomData_has_layer(&me_eval->ldata, CD_MLOOPUV)) { | ||||
| ED_view3d_viewcontext_init(C, &vc); | |||||
| view3d_operator_needs_opengl(C); | view3d_operator_needs_opengl(C); | ||||
| if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { | if (*sel_id_ctx == NULL) { | ||||
| /* Lazy initialization. */ | |||||
| ViewContext vc; | |||||
| ED_view3d_viewcontext_init(C, &vc); | |||||
| *sel_id_ctx = ED_view3d_select_id_context_create(&vc, &base, 1, SCE_SELECT_FACE); | |||||
| } | |||||
| if (imapaint_pick_face(*sel_id_ctx, mval, &faceindex)) { | |||||
| Image *image; | Image *image; | ||||
| if (use_material) { | if (use_material) { | ||||
| image = imapaint_face_image(ob_eval, me_eval, faceindex); | image = imapaint_face_image(ob_eval, me_eval, faceindex); | ||||
| } | } | ||||
| else { | else { | ||||
| image = imapaint->canvas; | image = imapaint->canvas; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines | |||||