LEFT | RIGHT |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 11 matching lines...) Expand all Loading... |
22 * | 22 * |
23 * Contributor(s): none yet. | 23 * Contributor(s): none yet. |
24 * | 24 * |
25 * ***** END GPL LICENSE BLOCK ***** | 25 * ***** END GPL LICENSE BLOCK ***** |
26 */ | 26 */ |
27 | 27 |
28 /** \file blender/blenkernel/intern/paint.c | 28 /** \file blender/blenkernel/intern/paint.c |
29 * \ingroup bke | 29 * \ingroup bke |
30 */ | 30 */ |
31 | 31 |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 | 32 |
35 #include "MEM_guardedalloc.h" | |
36 | 33 |
37 #include "DNA_object_types.h" | 34 #include "DNA_object_types.h" |
38 #include "DNA_mesh_types.h" | 35 #include "DNA_mesh_types.h" |
39 #include "DNA_meshdata_types.h" | |
40 #include "DNA_scene_types.h" | 36 #include "DNA_scene_types.h" |
41 #include "DNA_brush_types.h" | 37 #include "DNA_brush_types.h" |
42 #include "DNA_space_types.h" | |
43 | 38 |
44 #include "BLI_bitmap.h" | |
45 #include "BLI_utildefines.h" | 39 #include "BLI_utildefines.h" |
46 #include "BLI_math_vector.h" | 40 |
47 | 41 |
48 #include "BKE_brush.h" | 42 #include "BKE_brush.h" |
49 #include "BKE_context.h" | |
50 #include "BKE_depsgraph.h" | |
51 #include "BKE_global.h" | |
52 #include "BKE_image.h" | |
53 #include "BKE_library.h" | 43 #include "BKE_library.h" |
54 #include "BKE_object.h" | |
55 #include "BKE_paint.h" | 44 #include "BKE_paint.h" |
56 #include "BKE_pbvh.h" | |
57 #include "BKE_subsurf.h" | |
58 | 45 |
59 #include "bmesh.h" | 46 #include <stdlib.h> |
| 47 #include <string.h> |
60 | 48 |
61 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100}; | 49 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100}; |
62 const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255}; | 50 const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255}; |
63 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255}; | 51 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255}; |
64 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255}; | 52 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255}; |
65 | 53 |
| 54 Paint *paint_get_active(Scene *sce) |
| 55 { |
| 56 if(sce) { |
| 57 ToolSettings *ts = sce->toolsettings; |
| 58 ················ |
| 59 if(sce->basact && sce->basact->object) { |
| 60 switch(sce->basact->object->mode) { |
| 61 case OB_MODE_SCULPT: |
| 62 return &ts->sculpt->paint; |
| 63 case OB_MODE_VERTEX_PAINT: |
| 64 return &ts->vpaint->paint; |
| 65 case OB_MODE_WEIGHT_PAINT: |
66 return &ts->wpaint->paint; | 66 return &ts->wpaint->paint; |
67 case OB_MODE_TEXTURE_PAINT: | 67 case OB_MODE_TEXTURE_PAINT: |
68 return &ts->imapaint.paint; | 68 return &ts->imapaint.paint; |
| 69 case OB_MODE_EDIT: |
| 70 if(ts->use_uv_sculpt) |
| 71 return &ts->uvsculpt->paint; |
| 72 else |
| 73 return &ts->imapaint.paint; |
69 } | 74 } |
70 } | 75 } |
71 | 76 |
| 77 /* default to image paint */ |
| 78 return &ts->imapaint.paint; |
| 79 } |
| 80 |
| 81 return NULL; |
| 82 } |
| 83 |
| 84 Brush *paint_brush(Paint *p) |
| 85 { |
| 86 return p ? p->brush : NULL; |
| 87 } |
| 88 |
| 89 void paint_brush_set(Paint *p, Brush *br) |
| 90 { |
| 91 if(p) { |
| 92 id_us_min((ID *)p->brush); |
| 93 id_us_plus((ID *)br); |
| 94 p->brush= br; |
| 95 } |
| 96 } |
| 97 |
| 98 /* are we in vertex paint or weight pain face select mode? */ |
| 99 int paint_facesel_test(Object *ob) |
| 100 { |
| 101 return ( (ob != NULL) && |
| 102 (ob->type == OB_MESH) && |
| 103 (ob->data != NULL) && |
| 104 (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && |
| 105 (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_
TEXTURE_PAINT)) |
| 106 ); |
| 107 } |
| 108 |
| 109 /* are we in weight paint vertex select mode? */ |
| 110 int paint_vertsel_test(Object *ob) |
| 111 { |
| 112 return ( (ob != NULL) && |
| 113 (ob->type == OB_MESH) && |
| 114 (ob->data != NULL) && |
| 115 (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && |
| 116 (ob->mode & OB_MODE_WEIGHT_PAINT) |
| 117 ); |
| 118 } |
| 119 |
| 120 void paint_init(Paint *p, const char col[3]) |
| 121 { |
| 122 Brush *brush; |
| 123 |
| 124 /* If there's no brush, create one */ |
| 125 brush = paint_brush(p); |
| 126 if(brush == NULL) |
| 127 brush= add_brush("Brush"); |
| 128 paint_brush_set(p, brush); |
| 129 |
| 130 memcpy(p->paint_cursor_col, col, 3); |
| 131 p->paint_cursor_col[3] = 128; |
| 132 |
| 133 p->flags |= PAINT_SHOW_BRUSH; |
| 134 } |
| 135 |
| 136 void free_paint(Paint *paint) |
| 137 { |
| 138 id_us_min((ID *)paint->brush); |
| 139 } |
| 140 |
| 141 /* called when copying scene settings, so even if 'src' and 'tar' are the same |
| 142 * still do a id_us_plus(), rather then if we were copying betweem 2 existing |
| 143 * scenes where a matching value should decrease the existing user count as |
| 144 * with paint_brush_set() */ |
| 145 void copy_paint(Paint *src, Paint *tar) |
| 146 { |
| 147 tar->brush= src->brush; |
| 148 id_us_plus((ID *)tar->brush); |
| 149 } |
LEFT | RIGHT |