LEFT | RIGHT |
1 /* | 1 /* |
2 * $Id$ | |
3 * | |
4 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
5 * | 3 * |
6 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
8 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
9 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
10 * | 8 * |
11 * 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, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 23 matching lines...) Expand all Loading... |
37 | 35 |
38 #include "MEM_guardedalloc.h" | 36 #include "MEM_guardedalloc.h" |
39 | 37 |
40 #include "BLI_math.h" | 38 #include "BLI_math.h" |
41 #include "BLI_blenlib.h" | 39 #include "BLI_blenlib.h" |
42 #include "BLI_utildefines.h" | 40 #include "BLI_utildefines.h" |
43 #include "BLI_dynstr.h" | 41 #include "BLI_dynstr.h" |
44 #include "BLI_ghash.h" | 42 #include "BLI_ghash.h" |
45 #include "BLI_pbvh.h" | 43 #include "BLI_pbvh.h" |
46 #include "BLI_threads.h" | 44 #include "BLI_threads.h" |
47 #include "BLI_editVert.h" | |
48 #include "BLI_rand.h" | 45 #include "BLI_rand.h" |
49 | 46 |
| 47 #include "DNA_mesh_types.h" |
50 #include "DNA_meshdata_types.h" | 48 #include "DNA_meshdata_types.h" |
| 49 #include "DNA_node_types.h" |
51 #include "DNA_object_types.h" | 50 #include "DNA_object_types.h" |
52 #include "DNA_scene_types.h" | 51 #include "DNA_scene_types.h" |
53 #include "DNA_brush_types.h" | 52 #include "DNA_brush_types.h" |
54 | 53 |
55 #include "BKE_brush.h" | 54 #include "BKE_brush.h" |
| 55 #include "BKE_ccg.h" |
56 #include "BKE_cdderivedmesh.h" | 56 #include "BKE_cdderivedmesh.h" |
57 #include "BKE_context.h" | 57 #include "BKE_context.h" |
58 #include "BKE_depsgraph.h" | 58 #include "BKE_depsgraph.h" |
59 #include "BKE_key.h" | 59 #include "BKE_key.h" |
60 #include "BKE_library.h" | 60 #include "BKE_library.h" |
61 #include "BKE_mesh.h" | 61 #include "BKE_mesh.h" |
62 #include "BKE_modifier.h" | 62 #include "BKE_modifier.h" |
63 #include "BKE_multires.h" | 63 #include "BKE_multires.h" |
64 #include "BKE_paint.h" | 64 #include "BKE_paint.h" |
65 #include "BKE_report.h" | 65 #include "BKE_report.h" |
66 #include "BKE_lattice.h" /* for armature_deform_verts */ | 66 #include "BKE_lattice.h" /* for armature_deform_verts */ |
67 #include "BKE_node.h" | 67 #include "BKE_node.h" |
| 68 #include "BKE_subsurf.h" |
68 | 69 |
69 #include "BIF_glutil.h" | 70 #include "BIF_glutil.h" |
70 | 71 |
71 #include "WM_api.h" | 72 #include "WM_api.h" |
72 #include "WM_types.h" | 73 #include "WM_types.h" |
73 | 74 |
74 #include "ED_sculpt.h" | 75 #include "ED_sculpt.h" |
75 #include "ED_screen.h" | 76 #include "ED_screen.h" |
76 #include "ED_view3d.h" | 77 #include "ED_view3d.h" |
77 #include "ED_util.h" /* for crazyspace correction */ | 78 #include "ED_util.h" /* for crazyspace correction */ |
(...skipping 10 matching lines...) Expand all Loading... |
88 #include <math.h> | 89 #include <math.h> |
89 #include <stdlib.h> | 90 #include <stdlib.h> |
90 #include <string.h> | 91 #include <string.h> |
91 | 92 |
92 #ifdef _OPENMP | 93 #ifdef _OPENMP |
93 #include <omp.h> | 94 #include <omp.h> |
94 #endif | 95 #endif |
95 | 96 |
96 void ED_sculpt_force_update(bContext *C) | 97 void ED_sculpt_force_update(bContext *C) |
97 { | 98 { |
98 » Object *ob= CTX_data_active_object(C); | 99 » Object *ob = CTX_data_active_object(C); |
99 | 100 |
100 » if(ob && (ob->mode & OB_MODE_SCULPT)) | 101 » if (ob && (ob->mode & OB_MODE_SCULPT)) |
101 multires_force_update(ob); | 102 multires_force_update(ob); |
102 } | 103 } |
103 | 104 |
104 void ED_sculpt_modifiers_changed(Object *ob) | 105 float *ED_sculpt_get_last_stroke(struct Object *ob) |
105 { | 106 { |
106 » SculptSession *ss= ob->sculpt; | 107 » return (ob && ob->sculpt && ob->sculpt->last_stroke_valid) ? ob->sculpt-
>last_stroke : NULL; |
107 | 108 } |
108 » if(!ss->cache) { | 109 |
109 » » /* we free pbvh on changes, except during sculpt since it can't
deal with | 110 int ED_sculpt_minmax(bContext *C, float min[3], float max[3]) |
110 » » changing PVBH node organization, we hope topology does not ch
ange in | 111 { |
111 » » the meantime .. weak */ | 112 » Object *ob = CTX_data_active_object(C); |
112 » » if(ss->pbvh) { | 113 |
113 » » » » BLI_pbvh_free(ss->pbvh); | 114 » if (ob && ob->sculpt && ob->sculpt->last_stroke_valid) { |
114 » » » » ss->pbvh= NULL; | 115 » » copy_v3_v3(min, ob->sculpt->last_stroke); |
115 » » } | 116 » » copy_v3_v3(max, ob->sculpt->last_stroke); |
116 | 117 |
117 » » sculpt_free_deformMats(ob->sculpt); | 118 » » return 1; |
118 » } else { | 119 » } |
119 » » PBVHNode **nodes; | 120 » else { |
120 » » int n, totnode; | 121 » » return 0; |
121 | |
122 » » BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); | |
123 | |
124 » » for(n = 0; n < totnode; n++) | |
125 » » » BLI_pbvh_node_mark_update(nodes[n]); | |
126 | |
127 » » MEM_freeN(nodes); | |
128 } | 122 } |
129 } | 123 } |
130 | 124 |
131 /* Sculpt mode handles multires differently from regular meshes, but only if | 125 /* Sculpt mode handles multires differently from regular meshes, but only if |
132 it's the last modifier on the stack and it is not on the first level */ | 126 * it's the last modifier on the stack and it is not on the first level */ |
133 struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob) | 127 MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob) |
134 { | 128 { |
135 » Mesh *me= (Mesh*)ob->data; | 129 » Mesh *me = (Mesh *)ob->data; |
136 ModifierData *md; | 130 ModifierData *md; |
137 | 131 |
138 » if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) { | 132 » if (!CustomData_get_layer(&me->ldata, CD_MDISPS)) { |
139 /* multires can't work without displacement layer */ | 133 /* multires can't work without displacement layer */ |
140 return NULL; | 134 return NULL; |
141 } | 135 } |
142 | 136 |
143 » for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) { | 137 » for (md = modifiers_getVirtualModifierList(ob); md; md = md->next) { |
144 » » if(md->type == eModifierType_Multires) { | 138 » » if (md->type == eModifierType_Multires) { |
145 » » » MultiresModifierData *mmd= (MultiresModifierData*)md; | 139 » » » MultiresModifierData *mmd = (MultiresModifierData *)md; |
146 | 140 |
147 » » » if(!modifier_isEnabled(scene, md, eModifierMode_Realtime
)) | 141 » » » if (!modifier_isEnabled(scene, md, eModifierMode_Realtim
e)) |
148 continue; | 142 continue; |
149 | 143 |
150 » » » if(mmd->sculptlvl > 0) return mmd; | 144 » » » if (mmd->sculptlvl > 0) return mmd; |
151 else return NULL; | 145 else return NULL; |
152 } | 146 } |
153 } | 147 } |
154 | 148 |
155 return NULL; | 149 return NULL; |
156 } | 150 } |
157 | 151 |
158 /* Check if there are any active modifiers in stack (used for flushing updates a
t enter/exit sculpt mode) */ | 152 /* Check if there are any active modifiers in stack (used for flushing updates a
t enter/exit sculpt mode) */ |
159 static int sculpt_has_active_modifiers(Scene *scene, Object *ob) | 153 static int sculpt_has_active_modifiers(Scene *scene, Object *ob) |
160 { | 154 { |
161 ModifierData *md; | 155 ModifierData *md; |
162 | 156 |
163 » md= modifiers_getVirtualModifierList(ob); | 157 » md = modifiers_getVirtualModifierList(ob); |
164 | 158 |
165 /* exception for shape keys because we can edit those */ | 159 /* exception for shape keys because we can edit those */ |
166 » for(; md; md= md->next) { | 160 » for (; md; md = md->next) { |
167 » » if(modifier_isEnabled(scene, md, eModifierMode_Realtime)) | 161 » » if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) |
168 return 1; | 162 return 1; |
169 } | 163 } |
170 | 164 |
171 return 0; | 165 return 0; |
172 } | 166 } |
173 | 167 |
174 /* Checks if there are any supported deformation modifiers active */ | 168 /* Checks if there are any supported deformation modifiers active */ |
175 int sculpt_modifiers_active(Scene *scene, Object *ob) | 169 static int sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob) |
176 { | 170 { |
177 ModifierData *md; | 171 ModifierData *md; |
178 » MultiresModifierData *mmd= sculpt_multires_active(scene, ob); | 172 » Mesh *me = (Mesh *)ob->data; |
179 | 173 » MultiresModifierData *mmd = sculpt_multires_active(scene, ob); |
180 » if(mmd) return 0; | 174 |
181 | 175 » if (mmd) return 0; |
182 » md= modifiers_getVirtualModifierList(ob); | 176 |
| 177 » /* non-locked shape keys could be handled in the same way as deformed me
sh */ |
| 178 » if ((ob->shapeflag & OB_SHAPE_LOCK) == 0 && me->key && ob->shapenr) |
| 179 » » return 1; |
| 180 |
| 181 » md = modifiers_getVirtualModifierList(ob); |
183 | 182 |
184 /* exception for shape keys because we can edit those */ | 183 /* exception for shape keys because we can edit those */ |
185 » for(; md; md= md->next) { | 184 » for (; md; md = md->next) { |
186 ModifierTypeInfo *mti = modifierType_getInfo(md->type); | 185 ModifierTypeInfo *mti = modifierType_getInfo(md->type); |
187 | 186 » » if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) cont
inue; |
188 » » if(!modifier_isEnabled(scene, md, eModifierMode_Realtime)) conti
nue; | 187 » » if (md->type == eModifierType_ShapeKey) continue; |
189 » » if(md->type==eModifierType_ShapeKey) continue; | 188 |
190 | 189 » » if (mti->type == eModifierTypeType_OnlyDeform) return 1; |
191 » » if(mti->type==eModifierTypeType_OnlyDeform) | 190 » » else if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) return 1; |
192 » » » return 1; | |
193 } | 191 } |
194 | 192 |
195 return 0; | 193 return 0; |
196 } | 194 } |
197 | 195 |
198 typedef enum StrokeFlags { | 196 typedef enum StrokeFlags { |
199 CLIP_X = 1, | 197 CLIP_X = 1, |
200 CLIP_Y = 2, | 198 CLIP_Y = 2, |
201 CLIP_Z = 4 | 199 CLIP_Z = 4 |
202 } StrokeFlags; | 200 } StrokeFlags; |
203 | 201 |
204 /* Cache stroke properties. Used because | 202 /* Cache stroke properties. Used because |
205 RNA property lookup isn't particularly fast. | 203 * RNA property lookup isn't particularly fast. |
206 | 204 * |
207 For descriptions of these settings, check the operator properties. | 205 * For descriptions of these settings, check the operator properties. |
208 */ | 206 */ |
209 typedef struct StrokeCache { | 207 typedef struct StrokeCache { |
210 /* Invariants */ | 208 /* Invariants */ |
211 float initial_radius; | 209 float initial_radius; |
212 float scale[3]; | 210 float scale[3]; |
213 int flag; | 211 int flag; |
214 float clip_tolerance[3]; | 212 float clip_tolerance[3]; |
215 float initial_mouse[2]; | 213 float initial_mouse[2]; |
216 | 214 |
| 215 /* Pre-allocated temporary storage used during smoothing */ |
| 216 int num_threads; |
| 217 float (**tmpgrid_co)[3], (**tmprow_co)[3]; |
| 218 float **tmpgrid_mask, **tmprow_mask; |
| 219 |
217 /* Variants */ | 220 /* Variants */ |
218 float radius; | 221 float radius; |
219 float radius_squared; | 222 float radius_squared; |
220 //float traced_location[3]; | |
221 float true_location[3]; | 223 float true_location[3]; |
222 float location[3]; | 224 float location[3]; |
223 | 225 |
224 float pen_flip; | 226 float pen_flip; |
225 float invert; | 227 float invert; |
226 float pressure; | 228 float pressure; |
227 float mouse[2]; | 229 float mouse[2]; |
228 float bstrength; | 230 float bstrength; |
229 float tex_mouse[2]; | 231 float tex_mouse[2]; |
230 | 232 |
231 /* The rest is temporary storage that isn't saved as a property */ | 233 /* The rest is temporary storage that isn't saved as a property */ |
232 | 234 |
233 int first_time; /* Beginning of stroke may do some things special */ | 235 int first_time; /* Beginning of stroke may do some things special */ |
234 | 236 |
235 » bglMats *mats; | 237 » /* from ED_view3d_ob_project_mat_get() */ |
| 238 » float projection_mat[4][4]; |
236 | 239 |
237 /* Clean this up! */ | 240 /* Clean this up! */ |
238 ViewContext *vc; | 241 ViewContext *vc; |
239 Brush *brush; | 242 Brush *brush; |
240 | 243 |
241 float (*face_norms)[3]; /* Copy of the mesh faces' normals */ | 244 float (*face_norms)[3]; /* Copy of the mesh faces' normals */ |
242 float special_rotation; /* Texture rotation (radians) for anchored and r
ake modes */ | 245 float special_rotation; /* Texture rotation (radians) for anchored and r
ake modes */ |
243 int pixel_radius, previous_pixel_radius; | 246 int pixel_radius, previous_pixel_radius; |
244 float grab_delta[3], grab_delta_symmetry[3]; | 247 float grab_delta[3], grab_delta_symmetry[3]; |
245 float old_grab_location[3], orig_grab_location[3]; | 248 float old_grab_location[3], orig_grab_location[3]; |
246 | 249 |
247 int symmetry; /* Symmetry index between 0 and 7 bit combo 0 is Brush onl
y; | 250 int symmetry; /* Symmetry index between 0 and 7 bit combo 0 is Brush onl
y; |
248 » » 1 is X mirror; 2 is Y mirror; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ;
7 is XYZ */ | 251 » * 1 is X mirror; 2 is Y mirror; 3 is XY; 4 is Z; 5 is XZ;
6 is YZ; 7 is XYZ */ |
249 int mirror_symmetry_pass; /* the symmetry pass we are currently on betwe
en 0 and 7*/ | 252 int mirror_symmetry_pass; /* the symmetry pass we are currently on betwe
en 0 and 7*/ |
250 float true_view_normal[3]; | 253 float true_view_normal[3]; |
251 float view_normal[3]; | 254 float view_normal[3]; |
252 » float last_area_normal[3]; | 255 |
| 256 » /* sculpt_normal gets calculated by calc_sculpt_normal(), then the |
| 257 » * sculpt_normal_symm gets updated quickly with the usual symmetry |
| 258 » * transforms */ |
| 259 » float sculpt_normal[3]; |
| 260 » float sculpt_normal_symm[3]; |
| 261 |
| 262 » /* Used for wrap texture mode, local_mat gets calculated by |
| 263 » * calc_brush_local_mat() and used in tex_strength(). */ |
| 264 » float brush_local_mat[4][4]; |
| 265 »······· |
253 float last_center[3]; | 266 float last_center[3]; |
254 int radial_symmetry_pass; | 267 int radial_symmetry_pass; |
255 float symm_rot_mat[4][4]; | 268 float symm_rot_mat[4][4]; |
256 float symm_rot_mat_inv[4][4]; | 269 float symm_rot_mat_inv[4][4]; |
257 float last_rake[2]; /* Last location of updating rake rotation */ | 270 float last_rake[2]; /* Last location of updating rake rotation */ |
258 int original; | 271 int original; |
259 | 272 |
260 float vertex_rotation; | 273 float vertex_rotation; |
261 | 274 |
262 » char saved_active_brush_name[24]; | 275 » char saved_active_brush_name[MAX_ID_NAME]; |
| 276 » char saved_mask_brush_tool; |
263 int alt_smooth; | 277 int alt_smooth; |
264 | 278 |
265 float plane_trim_squared; | 279 float plane_trim_squared; |
| 280 |
| 281 rcti previous_r; /* previous redraw rectangle */ |
266 } StrokeCache; | 282 } StrokeCache; |
| 283 |
| 284 |
| 285 /*** paint mesh ***/ |
| 286 |
| 287 static void paint_mesh_restore_co(Sculpt *sd, SculptSession *ss) |
| 288 { |
| 289 StrokeCache *cache = ss->cache; |
| 290 int i; |
| 291 |
| 292 PBVHNode **nodes; |
| 293 int n, totnode; |
| 294 |
| 295 #ifndef _OPENMP |
| 296 (void)sd; /* quied unused warning */ |
| 297 #endif |
| 298 |
| 299 BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); |
| 300 |
| 301 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
| 302 for (n = 0; n < totnode; n++) { |
| 303 SculptUndoNode *unode; |
| 304 ················ |
| 305 unode = sculpt_undo_get_node(nodes[n]); |
| 306 if (unode) { |
| 307 PBVHVertexIter vd; |
| 308 |
| 309 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
| 310 { |
| 311 if (unode->type == SCULPT_UNDO_COORDS) { |
| 312 copy_v3_v3(vd.co, unode->co[vd.i]); |
| 313 if (vd.no) copy_v3_v3_short(vd.no, unode
->no[vd.i]); |
| 314 else normal_short_to_float_v3(vd.fno, un
ode->no[vd.i]); |
| 315 } |
| 316 else if (unode->type == SCULPT_UNDO_MASK) { |
| 317 *vd.mask = unode->mask[vd.i]; |
| 318 } |
| 319 if (vd.mvert) vd.mvert->flag |= ME_VERT_PBVH_UPD
ATE; |
| 320 } |
| 321 BLI_pbvh_vertex_iter_end; |
| 322 |
| 323 BLI_pbvh_node_mark_update(nodes[n]); |
| 324 } |
| 325 } |
| 326 |
| 327 if (ss->face_normals) { |
| 328 float *fn = ss->face_normals; |
| 329 for (i = 0; i < ss->totpoly; ++i, fn += 3) |
| 330 copy_v3_v3(fn, cache->face_norms[i]); |
| 331 } |
| 332 |
| 333 if (nodes) |
| 334 MEM_freeN(nodes); |
| 335 } |
267 | 336 |
268 /*** BVH Tree ***/ | 337 /*** BVH Tree ***/ |
269 | 338 |
270 /* Get a screen-space rectangle of the modified area */ | 339 /* Get a screen-space rectangle of the modified area */ |
271 static int sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, | 340 static int sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, |
272 » » » » Object *ob, rcti *rect) | 341 Object *ob, rcti *rect) |
273 { | 342 { |
274 » PBVH *pbvh= ob->sculpt->pbvh; | 343 » SculptSession *ss; |
275 » float bb_min[3], bb_max[3], pmat[4][4]; | 344 » PBVH *pbvh = ob->sculpt->pbvh; |
276 » int i, j, k; | 345 » float bb_min[3], bb_max[3]; |
277 | 346 |
278 » view3d_get_object_project_mat(rv3d, ob, pmat); | 347 » if (!pbvh) |
279 | |
280 » if(!pbvh) | |
281 return 0; | 348 return 0; |
282 | 349 |
283 BLI_pbvh_redraw_BB(pbvh, bb_min, bb_max); | 350 BLI_pbvh_redraw_BB(pbvh, bb_min, bb_max); |
284 | 351 |
285 » rect->xmin = rect->ymin = INT_MAX; | 352 » /* convert 3D bounding box to screen space */ |
286 » rect->xmax = rect->ymax = INT_MIN; | 353 » if (!paint_convert_bb_to_rect(rect, |
287 | 354 » bb_min, |
288 » if(bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[
2]) | 355 » bb_max, |
| 356 » ar, |
| 357 » rv3d, |
| 358 » ob)) |
| 359 » { |
289 return 0; | 360 return 0; |
290 | 361 » } |
291 » for(i = 0; i < 2; ++i) { | 362 |
292 » » for(j = 0; j < 2; ++j) { | 363 » /* expand redraw rect with redraw rect from previous step to |
293 » » » for(k = 0; k < 2; ++k) { | 364 » * prevent partial-redraw issues caused by fast strokes. This is |
294 » » » » float vec[3], proj[2]; | 365 » * needed here (not in sculpt_flush_update) as it was before |
295 » » » » vec[0] = i ? bb_min[0] : bb_max[0]; | 366 » * because redraw rectangle should be the same in both of |
296 » » » » vec[1] = j ? bb_min[1] : bb_max[1]; | 367 » * optimized PBVH draw function and 3d view redraw (if not -- some |
297 » » » » vec[2] = k ? bb_min[2] : bb_max[2]; | 368 » * mesh parts could disappear from screen (sergey) */ |
298 » » » » view3d_project_float(ar, vec, proj, pmat); | 369 » ss = ob->sculpt; |
299 » » » » rect->xmin = MIN2(rect->xmin, proj[0]); | 370 » if (ss->cache) { |
300 » » » » rect->xmax = MAX2(rect->xmax, proj[0]); | 371 » » if (!BLI_rcti_is_empty(&ss->cache->previous_r)) |
301 » » » » rect->ymin = MIN2(rect->ymin, proj[1]); | 372 » » » BLI_rcti_union(rect, &ss->cache->previous_r); |
302 » » » » rect->ymax = MAX2(rect->ymax, proj[1]); | 373 » } |
303 » » » } | 374 |
304 » » } | 375 » return 1; |
305 » } | |
306 »······· | |
307 » return rect->xmin < rect->xmax && rect->ymin < rect->ymax; | |
308 } | 376 } |
309 | 377 |
310 void sculpt_get_redraw_planes(float planes[4][4], ARegion *ar, | 378 void sculpt_get_redraw_planes(float planes[4][4], ARegion *ar, |
311 » » » » RegionView3D *rv3d, Object *ob) | 379 RegionView3D *rv3d, Object *ob) |
312 { | 380 { |
313 » PBVH *pbvh= ob->sculpt->pbvh; | 381 » PBVH *pbvh = ob->sculpt->pbvh; |
314 » BoundBox bb; | |
315 » bglMats mats; | |
316 rcti rect; | 382 rcti rect; |
317 | 383 |
318 » memset(&bb, 0, sizeof(BoundBox)); | 384 » sculpt_get_redraw_rect(ar, rv3d, ob, &rect); |
319 | 385 |
320 » view3d_get_transformation(ar, rv3d, ob, &mats); | 386 » paint_calc_redraw_planes(planes, ar, rv3d, ob, &rect); |
321 » sculpt_get_redraw_rect(ar, rv3d,ob, &rect); | |
322 | |
323 #if 1 | |
324 » /* use some extra space just in case */ | |
325 » rect.xmin -= 2; | |
326 » rect.xmax += 2; | |
327 » rect.ymin -= 2; | |
328 » rect.ymax += 2; | |
329 #else | |
330 » /* it was doing this before, allows to redraw a smaller | |
331 » part of the screen but also gives artifaces .. */ | |
332 » rect.xmin += 2; | |
333 » rect.xmax -= 2; | |
334 » rect.ymin += 2; | |
335 » rect.ymax -= 2; | |
336 #endif | |
337 | |
338 » view3d_calculate_clipping(&bb, planes, &mats, &rect); | |
339 » mul_m4_fl(planes, -1.0f); | |
340 | 387 |
341 /* clear redraw flag from nodes */ | 388 /* clear redraw flag from nodes */ |
342 » if(pbvh) | 389 » if (pbvh) |
343 BLI_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL); | 390 BLI_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL); |
344 } | 391 } |
345 | 392 |
346 /************************ Brush Testing *******************/ | 393 /************************ Brush Testing *******************/ |
347 | 394 |
348 typedef struct SculptBrushTest { | 395 typedef struct SculptBrushTest { |
349 float radius_squared; | 396 float radius_squared; |
350 float location[3]; | 397 float location[3]; |
351 float dist; | 398 float dist; |
352 } SculptBrushTest; | 399 } SculptBrushTest; |
353 | 400 |
354 static void sculpt_brush_test_init(SculptSession *ss, SculptBrushTest *test) | 401 static void sculpt_brush_test_init(SculptSession *ss, SculptBrushTest *test) |
355 { | 402 { |
356 » test->radius_squared= ss->cache->radius_squared; | 403 » test->radius_squared = ss->cache->radius_squared; |
357 copy_v3_v3(test->location, ss->cache->location); | 404 copy_v3_v3(test->location, ss->cache->location); |
358 » test->dist= 0.0f;» /* just for initialize */ | 405 » test->dist = 0.0f; /* just for initialize */ |
359 } | 406 } |
360 | 407 |
361 static int sculpt_brush_test(SculptBrushTest *test, float co[3]) | 408 static int sculpt_brush_test(SculptBrushTest *test, float co[3]) |
362 { | 409 { |
363 float distsq = len_squared_v3v3(co, test->location); | 410 float distsq = len_squared_v3v3(co, test->location); |
364 | 411 |
365 » if(distsq <= test->radius_squared) { | 412 » if (distsq <= test->radius_squared) { |
366 test->dist = sqrt(distsq); | 413 test->dist = sqrt(distsq); |
367 return 1; | 414 return 1; |
368 } | 415 } |
369 else { | 416 else { |
370 return 0; | 417 return 0; |
371 } | 418 } |
372 } | 419 } |
373 | 420 |
374 static int sculpt_brush_test_sq(SculptBrushTest *test, float co[3]) | 421 static int sculpt_brush_test_sq(SculptBrushTest *test, float co[3]) |
375 { | 422 { |
376 float distsq = len_squared_v3v3(co, test->location); | 423 float distsq = len_squared_v3v3(co, test->location); |
377 | 424 |
378 » if(distsq <= test->radius_squared) { | 425 » if (distsq <= test->radius_squared) { |
379 test->dist = distsq; | 426 test->dist = distsq; |
380 return 1; | 427 return 1; |
381 } | 428 } |
382 else { | 429 else { |
383 return 0; | 430 return 0; |
384 } | 431 } |
385 } | 432 } |
386 | 433 |
387 static int sculpt_brush_test_fast(SculptBrushTest *test, float co[3]) | 434 static int sculpt_brush_test_fast(SculptBrushTest *test, float co[3]) |
388 { | 435 { |
389 return len_squared_v3v3(co, test->location) <= test->radius_squared; | 436 return len_squared_v3v3(co, test->location) <= test->radius_squared; |
390 } | 437 } |
391 | 438 |
392 static int sculpt_brush_test_cube(SculptBrushTest *test, float co[3], float loca
l[4][4]) | 439 static int sculpt_brush_test_cube(SculptBrushTest *test, float co[3], float loca
l[4][4]) |
393 { | 440 { |
394 » static const float side = 0.70710678118654752440084436210485; // sqrt(.5
); | 441 » float side = M_SQRT1_2; |
395 | |
396 float local_co[3]; | 442 float local_co[3]; |
397 | 443 |
398 mul_v3_m4v3(local_co, local, co); | 444 mul_v3_m4v3(local_co, local, co); |
399 | 445 |
400 local_co[0] = fabs(local_co[0]); | 446 local_co[0] = fabs(local_co[0]); |
401 local_co[1] = fabs(local_co[1]); | 447 local_co[1] = fabs(local_co[1]); |
402 local_co[2] = fabs(local_co[2]); | 448 local_co[2] = fabs(local_co[2]); |
403 | 449 |
404 if (local_co[0] <= side && local_co[1] <= side && local_co[2] <= side) { | 450 if (local_co[0] <= side && local_co[1] <= side && local_co[2] <= side) { |
405 » » test->dist = MAX3(local_co[0], local_co[1], local_co[2]) / side; | 451 » » float p = 4.0f; |
| 452 » »······· |
| 453 » » test->dist = ((powf(local_co[0], p) + |
| 454 » » powf(local_co[1], p) + |
| 455 » » powf(local_co[2], p)) / powf(side, p)); |
406 | 456 |
407 return 1; | 457 return 1; |
408 } | 458 } |
409 else { | 459 else { |
410 return 0; | 460 return 0; |
411 } | 461 } |
412 } | 462 } |
413 | 463 |
414 static float frontface(Brush *brush, float sculpt_normal[3], short no[3], float
fno[3]) | 464 static float frontface(Brush *brush, const float sculpt_normal[3], |
| 465 const short no[3], const float fno[3]) |
415 { | 466 { |
416 if (brush->flag & BRUSH_FRONTFACE) { | 467 if (brush->flag & BRUSH_FRONTFACE) { |
417 float dot; | 468 float dot; |
418 | 469 |
419 if (no) { | 470 if (no) { |
420 float tmp[3]; | 471 float tmp[3]; |
421 | 472 |
422 normal_short_to_float_v3(tmp, no); | 473 normal_short_to_float_v3(tmp, no); |
423 » » » dot= dot_v3v3(tmp, sculpt_normal); | 474 » » » dot = dot_v3v3(tmp, sculpt_normal); |
424 } | 475 } |
425 else { | 476 else { |
426 » » » dot= dot_v3v3(fno, sculpt_normal); | 477 » » » dot = dot_v3v3(fno, sculpt_normal); |
427 } | 478 } |
428 return dot > 0 ? dot : 0; | 479 return dot > 0 ? dot : 0; |
429 } | 480 } |
430 else { | 481 else { |
431 return 1; | 482 return 1; |
432 } | 483 } |
433 } | 484 } |
434 | 485 |
435 #if 0 | 486 #if 0 |
436 | 487 |
437 static int sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float locat
ion[3], float an[3]) | 488 static int sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float locat
ion[3], float an[3]) |
438 { | 489 { |
439 if (sculpt_brush_test_fast(test, co)) { | 490 if (sculpt_brush_test_fast(test, co)) { |
440 float t1[3], t2[3], t3[3], dist; | 491 float t1[3], t2[3], t3[3], dist; |
441 | 492 |
442 sub_v3_v3v3(t1, location, co); | 493 sub_v3_v3v3(t1, location, co); |
443 sub_v3_v3v3(t2, x2, location); | 494 sub_v3_v3v3(t2, x2, location); |
444 | 495 |
445 cross_v3_v3v3(t3, an, t1); | 496 cross_v3_v3v3(t3, an, t1); |
446 | 497 |
447 » » dist = len_v3(t3)/len_v3(t2); | 498 » » dist = len_v3(t3) / len_v3(t2); |
448 | 499 |
449 test->dist = dist; | 500 test->dist = dist; |
450 | 501 |
451 return 1; | 502 return 1; |
452 } | 503 } |
453 | 504 |
454 return 0; | 505 return 0; |
455 } | 506 } |
456 | 507 |
457 #endif | 508 #endif |
458 | 509 |
459 /* ===== Sculpting ===== | 510 /* ===== Sculpting ===== |
460 * | 511 * |
461 */ | 512 */ |
462 ·· | 513 ·· |
463 | 514 |
464 static float overlapped_curve(Brush* br, float x) | 515 static float overlapped_curve(Brush *br, float x) |
465 { | 516 { |
466 int i; | 517 int i; |
467 const int n = 100 / br->spacing; | 518 const int n = 100 / br->spacing; |
468 const float h = br->spacing / 50.0f; | 519 const float h = br->spacing / 50.0f; |
469 » const float x0 = x-1; | 520 » const float x0 = x - 1; |
470 | 521 |
471 float sum; | 522 float sum; |
472 | 523 |
473 sum = 0; | 524 sum = 0; |
474 » for (i= 0; i < n; i++) { | 525 » for (i = 0; i < n; i++) { |
475 float xx; | 526 float xx; |
476 | 527 |
477 » » xx = fabs(x0 + i*h); | 528 » » xx = fabs(x0 + i * h); |
478 | 529 |
479 if (xx < 1.0f) | 530 if (xx < 1.0f) |
480 » » » sum += brush_curve_strength(br, xx, 1); | 531 » » » sum += BKE_brush_curve_strength(br, xx, 1); |
481 } | 532 } |
482 | 533 |
483 return sum; | 534 return sum; |
484 } | 535 } |
485 | 536 |
486 static float integrate_overlap(Brush* br) | 537 static float integrate_overlap(Brush *br) |
487 { | 538 { |
488 int i; | 539 int i; |
489 » int m= 10; | 540 » int m = 10; |
490 » float g = 1.0f/m; | 541 » float g = 1.0f / m; |
491 » float overlap; | |
492 float max; | 542 float max; |
493 | 543 |
494 » overlap= 0; | 544 » max = 0; |
495 » max= 0; | 545 » for (i = 0; i < m; i++) { |
496 » for(i= 0; i < m; i++) { | 546 » » float overlap = overlapped_curve(br, i * g); |
497 » » overlap = overlapped_curve(br, i*g); | |
498 | 547 |
499 if (overlap > max) | 548 if (overlap > max) |
500 max = overlap; | 549 max = overlap; |
501 } | 550 } |
502 | 551 |
503 return max; | 552 return max; |
504 } | 553 } |
505 | 554 |
506 /* Uses symm to selectively flip any axis of a coordinate. */ | 555 /* Uses symm to selectively flip any axis of a coordinate. */ |
507 static void flip_coord(float out[3], float in[3], const char symm) | 556 static void flip_v3_v3(float out[3], const float in[3], const char symm) |
508 { | 557 { |
509 » if(symm & SCULPT_SYMM_X) | 558 » if (symm & SCULPT_SYMM_X) |
510 » » out[0]= -in[0]; | 559 » » out[0] = -in[0]; |
511 else | 560 else |
512 » » out[0]= in[0]; | 561 » » out[0] = in[0]; |
513 » if(symm & SCULPT_SYMM_Y) | 562 » if (symm & SCULPT_SYMM_Y) |
514 » » out[1]= -in[1]; | 563 » » out[1] = -in[1]; |
515 else | 564 else |
516 » » out[1]= in[1]; | 565 » » out[1] = in[1]; |
517 » if(symm & SCULPT_SYMM_Z) | 566 » if (symm & SCULPT_SYMM_Z) |
518 » » out[2]= -in[2]; | 567 » » out[2] = -in[2]; |
519 else | 568 else |
520 » » out[2]= in[2]; | 569 » » out[2] = in[2]; |
| 570 } |
| 571 |
| 572 static void flip_v3(float v[3], const char symm) |
| 573 { |
| 574 » flip_v3_v3(v, v, symm); |
521 } | 575 } |
522 | 576 |
523 static float calc_overlap(StrokeCache *cache, const char symm, const char axis,
const float angle) | 577 static float calc_overlap(StrokeCache *cache, const char symm, const char axis,
const float angle) |
524 { | 578 { |
525 float mirror[3]; | 579 float mirror[3]; |
526 float distsq; | 580 float distsq; |
527 ········ | 581 ········ |
528 » //flip_coord(mirror, cache->traced_location, symm); | 582 » /* flip_v3_v3(mirror, cache->traced_location, symm); */ |
529 » flip_coord(mirror, cache->true_location, symm); | 583 » flip_v3_v3(mirror, cache->true_location, symm); |
530 | 584 |
531 » if(axis != 0) { | 585 » if (axis != 0) { |
532 » » float mat[4][4]= MAT4_UNITY; | 586 » » float mat[4][4] = MAT4_UNITY; |
533 rotate_m4(mat, axis, angle); | 587 rotate_m4(mat, axis, angle); |
534 mul_m4_v3(mat, mirror); | 588 mul_m4_v3(mat, mirror); |
535 } | 589 } |
536 | 590 |
537 » //distsq = len_squared_v3v3(mirror, cache->traced_location); | 591 » /* distsq = len_squared_v3v3(mirror, cache->traced_location); */ |
538 distsq = len_squared_v3v3(mirror, cache->true_location); | 592 distsq = len_squared_v3v3(mirror, cache->true_location); |
539 | 593 |
540 » if (distsq <= 4.0f*(cache->radius_squared)) | 594 » if (distsq <= 4.0f * (cache->radius_squared)) |
541 » » return (2.0f*(cache->radius) - sqrtf(distsq)) / (2.0f*(cache->
radius)); | 595 » » return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache
->radius)); |
542 else | 596 else |
543 return 0; | 597 return 0; |
544 } | 598 } |
545 | 599 |
546 static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const
char symm, const char axis) | 600 static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const
char symm, const char axis) |
547 { | 601 { |
548 int i; | 602 int i; |
549 float overlap; | 603 float overlap; |
550 | 604 |
551 overlap = 0; | 605 overlap = 0; |
552 » for(i = 1; i < sd->radial_symm[axis-'X']; ++i) { | 606 » for (i = 1; i < sd->radial_symm[axis - 'X']; ++i) { |
553 » » const float angle = 2*M_PI*i/sd->radial_symm[axis-'X']; | 607 » » const float angle = 2 * M_PI * i / sd->radial_symm[axis - 'X']; |
554 overlap += calc_overlap(cache, symm, axis, angle); | 608 overlap += calc_overlap(cache, symm, axis, angle); |
555 } | 609 } |
556 | 610 |
557 return overlap; | 611 return overlap; |
558 } | 612 } |
559 | 613 |
560 static float calc_symmetry_feather(Sculpt *sd, StrokeCache* cache) | 614 static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache) |
561 { | 615 { |
562 if (sd->flags & SCULPT_SYMMETRY_FEATHER) { | 616 if (sd->flags & SCULPT_SYMMETRY_FEATHER) { |
563 float overlap; | 617 float overlap; |
564 int symm = cache->symmetry; | 618 int symm = cache->symmetry; |
565 int i; | 619 int i; |
566 | 620 |
567 overlap = 0; | 621 overlap = 0; |
568 for (i = 0; i <= symm; i++) { | 622 for (i = 0; i <= symm; i++) { |
569 » » » if(i == 0 || (symm & i && (symm != 5 || i != 3) && (symm
!= 6 || (i != 3 && i != 5)))) { | 623 » » » if (i == 0 || (symm & i && (symm != 5 || i != 3) && (sym
m != 6 || (i != 3 && i != 5)))) { |
570 | 624 |
571 overlap += calc_overlap(cache, i, 0, 0); | 625 overlap += calc_overlap(cache, i, 0, 0); |
572 | 626 |
573 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'X'); | 627 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'X'); |
574 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'Y'); | 628 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'Y'); |
575 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'Z'); | 629 overlap += calc_radial_symmetry_feather(sd, cach
e, i, 'Z'); |
576 } | 630 } |
577 } | 631 } |
578 | 632 |
579 » » return 1/overlap; | 633 » » return 1 / overlap; |
580 } | 634 } |
581 else { | 635 else { |
582 return 1; | 636 return 1; |
583 } | 637 } |
584 } | 638 } |
585 | 639 |
586 /* Return modified brush strength. Includes the direction of the brush, positive | 640 /* Return modified brush strength. Includes the direction of the brush, positive |
587 values pull vertices, negative values push. Uses tablet pressure and a | 641 * values pull vertices, negative values push. Uses tablet pressure and a |
588 special multiplier found experimentally to scale the strength factor. */ | 642 * special multiplier found experimentally to scale the strength factor. */ |
589 static float brush_strength(Sculpt *sd, StrokeCache *cache, float feather) | 643 static float brush_strength(Sculpt *sd, StrokeCache *cache, float feather) |
590 { | 644 { |
| 645 const Scene *scene = cache->vc->scene; |
591 Brush *brush = paint_brush(&sd->paint); | 646 Brush *brush = paint_brush(&sd->paint); |
592 | 647 |
593 /* Primary strength input; square it to make lower values more sensitive
*/ | 648 /* Primary strength input; square it to make lower values more sensitive
*/ |
594 » const float root_alpha = brush_alpha(brush); | 649 » const float root_alpha = BKE_brush_alpha_get(scene, brush); |
595 » float alpha = root_alpha*root_alpha; | 650 » float alpha = root_alpha * root_alpha; |
596 float dir = brush->flag & BRUSH_DIR_IN ? -1 : 1; | 651 float dir = brush->flag & BRUSH_DIR_IN ? -1 : 1; |
597 » float pressure = brush_use_alpha_pressure(brush) ? cache->pressure :
1; | 652 » float pressure = BKE_brush_use_alpha_pressure(scene, brush) ? cache-
>pressure : 1; |
598 float pen_flip = cache->pen_flip ? -1 : 1; | 653 float pen_flip = cache->pen_flip ? -1 : 1; |
599 float invert = cache->invert ? -1 : 1; | 654 float invert = cache->invert ? -1 : 1; |
600 float accum = integrate_overlap(brush); | 655 float accum = integrate_overlap(brush); |
601 » float overlap = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & B
RUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? 1.0f/
accum : 1; // spacing is integer percentage of radius, divide by 50 to get norma
lized diameter | 656 » /* spacing is integer percentage of radius, divide by 50 to get |
| 657 » * normalized diameter */ |
| 658 » float overlap = (brush->flag & BRUSH_SPACE_ATTEN && |
| 659 » brush->flag & BRUSH_SPACE && |
| 660 » !(brush->flag & BRUSH_ANCHORED) && |
| 661 » (brush->spacing < 100)) ? 1.0f / accum : 1; |
602 float flip = dir * invert * pen_flip; | 662 float flip = dir * invert * pen_flip; |
603 | 663 |
604 » switch(brush->sculpt_tool){ | 664 » switch (brush->sculpt_tool) { |
605 case SCULPT_TOOL_CLAY: | 665 case SCULPT_TOOL_CLAY: |
606 » » case SCULPT_TOOL_CLAY_TUBES: | 666 » » case SCULPT_TOOL_CLAY_STRIPS: |
607 case SCULPT_TOOL_DRAW: | 667 case SCULPT_TOOL_DRAW: |
608 case SCULPT_TOOL_LAYER: | 668 case SCULPT_TOOL_LAYER: |
609 return alpha * flip * pressure * overlap * feather; | 669 return alpha * flip * pressure * overlap * feather; |
| 670 ························ |
| 671 case SCULPT_TOOL_MASK: |
| 672 overlap = (1 + overlap) / 2; |
| 673 switch ((BrushMaskTool)brush->mask_tool) { |
| 674 case BRUSH_MASK_DRAW: |
| 675 return alpha * flip * pressure * overlap
* feather; |
| 676 case BRUSH_MASK_SMOOTH: |
| 677 return alpha * pressure * feather; |
| 678 } |
610 | 679 |
611 case SCULPT_TOOL_CREASE: | 680 case SCULPT_TOOL_CREASE: |
612 case SCULPT_TOOL_BLOB: | 681 case SCULPT_TOOL_BLOB: |
613 return alpha * flip * pressure * overlap * feather; | 682 return alpha * flip * pressure * overlap * feather; |
614 | 683 |
615 case SCULPT_TOOL_INFLATE: | 684 case SCULPT_TOOL_INFLATE: |
616 if (flip > 0) { | 685 if (flip > 0) { |
617 return 0.250f * alpha * flip * pressure * overla
p * feather; | 686 return 0.250f * alpha * flip * pressure * overla
p * feather; |
618 } | 687 } |
619 else { | 688 else { |
620 return 0.125f * alpha * flip * pressure * overla
p * feather; | 689 return 0.125f * alpha * flip * pressure * overla
p * feather; |
621 } | 690 } |
622 | 691 |
623 case SCULPT_TOOL_FILL: | 692 case SCULPT_TOOL_FILL: |
624 case SCULPT_TOOL_SCRAPE: | 693 case SCULPT_TOOL_SCRAPE: |
625 case SCULPT_TOOL_FLATTEN: | 694 case SCULPT_TOOL_FLATTEN: |
626 if (flip > 0) { | 695 if (flip > 0) { |
627 » » » » overlap = (1+overlap) / 2; | 696 » » » » overlap = (1 + overlap) / 2; |
628 return alpha * flip * pressure * overlap * feath
er; | 697 return alpha * flip * pressure * overlap * feath
er; |
629 } | 698 } |
630 else { | 699 else { |
631 /* reduce strength for DEEPEN, PEAKS, and CONTRA
ST */ | 700 /* reduce strength for DEEPEN, PEAKS, and CONTRA
ST */ |
632 return 0.5f * alpha * flip * pressure * overlap
* feather;· | 701 return 0.5f * alpha * flip * pressure * overlap
* feather;· |
633 } | 702 } |
634 | 703 |
635 case SCULPT_TOOL_SMOOTH: | 704 case SCULPT_TOOL_SMOOTH: |
636 return alpha * pressure * feather; | 705 return alpha * pressure * feather; |
637 | 706 |
638 case SCULPT_TOOL_PINCH: | 707 case SCULPT_TOOL_PINCH: |
639 if (flip > 0) { | 708 if (flip > 0) { |
640 return alpha * flip * pressure * overlap * feath
er; | 709 return alpha * flip * pressure * overlap * feath
er; |
641 } | 710 } |
642 else { | 711 else { |
643 return 0.25f * alpha * flip * pressure * overlap
* feather; | 712 return 0.25f * alpha * flip * pressure * overlap
* feather; |
644 } | 713 } |
645 | 714 |
646 case SCULPT_TOOL_NUDGE: | 715 case SCULPT_TOOL_NUDGE: |
647 » » » overlap = (1+overlap) / 2; | 716 » » » overlap = (1 + overlap) / 2; |
648 return alpha * pressure * overlap * feather; | 717 return alpha * pressure * overlap * feather; |
649 | 718 |
650 case SCULPT_TOOL_THUMB: | 719 case SCULPT_TOOL_THUMB: |
651 » » » return alpha*pressure*feather; | 720 » » » return alpha * pressure * feather; |
652 | 721 |
653 case SCULPT_TOOL_SNAKE_HOOK: | 722 case SCULPT_TOOL_SNAKE_HOOK: |
654 return feather; | 723 return feather; |
655 | 724 |
656 case SCULPT_TOOL_GRAB: | 725 case SCULPT_TOOL_GRAB: |
| 726 return feather; |
| 727 |
657 case SCULPT_TOOL_ROTATE: | 728 case SCULPT_TOOL_ROTATE: |
658 » » » return feather; | 729 » » » return alpha * pressure * feather; |
659 | 730 |
660 default: | 731 default: |
661 return 0; | 732 return 0; |
662 } | 733 } |
663 } | 734 } |
664 | 735 |
665 /* Return a multiplier for brush strength on a particular vertex. */ | 736 /* Return a multiplier for brush strength on a particular vertex. */ |
666 static float tex_strength(SculptSession *ss, Brush *br, float *point, const floa
t len) | 737 static float tex_strength(SculptSession *ss, Brush *br, float point[3], |
| 738 const float len, |
| 739 const float sculpt_normal[3], |
| 740 const short vno[3], |
| 741 const float fno[3], |
| 742 const float mask) |
667 { | 743 { |
668 MTex *mtex = &br->mtex; | 744 MTex *mtex = &br->mtex; |
669 » float avg= 1; | 745 » float avg = 1; |
670 | 746 |
671 » if(!mtex->tex) { | 747 » if (!mtex->tex) { |
672 » » avg= 1; | 748 » » avg = 1; |
673 » } | 749 » } |
674 » else if(mtex->brush_map_mode == MTEX_MAP_MODE_3D) { | 750 » else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) { |
675 float jnk; | 751 float jnk; |
676 | 752 |
677 /* Get strength by feeding the vertex· | 753 /* Get strength by feeding the vertex· |
678 » » location directly into a texture */ | 754 » » * location directly into a texture */ |
679 externtex(mtex, point, &avg, | 755 externtex(mtex, point, &avg, |
680 » » » &jnk, &jnk, &jnk, &jnk, 0); | 756 » » &jnk, &jnk, &jnk, &jnk, 0); |
681 » } | 757 » } |
682 » else if(ss->texcache) { | 758 » else if (ss->texcache) { |
683 float rotation = -mtex->rot; | 759 float rotation = -mtex->rot; |
684 » » float x, y, point_2d[3]; | 760 » » float symm_point[3], point_2d[2]; |
685 » » float radius; | 761 » » float x = 0.0f, y = 0.0f; /* Quite warnings */ |
| 762 » » float radius = 1.0f; /* Quite warnings */ |
686 | 763 |
687 /* if the active area is being applied for symmetry, flip it | 764 /* if the active area is being applied for symmetry, flip it |
688 » » across the symmetry axis and rotate it back to the orignal | 765 » » * across the symmetry axis and rotate it back to the original |
689 » » position in order to project it. This insures that the· | 766 » » * position in order to project it. This insures that the· |
690 » » brush texture will be oriented correctly. */ | 767 » » * brush texture will be oriented correctly. */ |
691 | 768 |
692 » » flip_coord(point_2d, point, ss->cache->mirror_symmetry_pass); | 769 » » flip_v3_v3(symm_point, point, ss->cache->mirror_symmetry_pass); |
693 | 770 |
694 if (ss->cache->radial_symmetry_pass) | 771 if (ss->cache->radial_symmetry_pass) |
695 » » » mul_m4_v3(ss->cache->symm_rot_mat_inv, point_2d); | 772 » » » mul_m4_v3(ss->cache->symm_rot_mat_inv, symm_point); |
696 | 773 |
697 » » projectf(ss->cache->mats, point_2d, point_2d); | 774 » » ED_view3d_project_float_v2(ss->cache->vc->ar, symm_point, point_
2d, ss->cache->projection_mat); |
698 | 775 |
699 » » /* if fixed mode, keep coordinates relative to mouse */ | 776 » » if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { |
700 » » if(mtex->brush_map_mode == MTEX_MAP_MODE_FIXED) { | 777 » » » /* keep coordinates relative to mouse */ |
| 778 |
701 rotation += ss->cache->special_rotation; | 779 rotation += ss->cache->special_rotation; |
702 | 780 |
703 point_2d[0] -= ss->cache->tex_mouse[0]; | 781 point_2d[0] -= ss->cache->tex_mouse[0]; |
704 point_2d[1] -= ss->cache->tex_mouse[1]; | 782 point_2d[1] -= ss->cache->tex_mouse[1]; |
705 | 783 |
706 » » » radius = ss->cache->pixel_radius; // use pressure adjust
ed size for fixed mode | 784 » » » /* use pressure adjusted size for fixed mode */ |
707 | 785 » » » radius = ss->cache->pixel_radius; |
| 786 |
| 787 » » » x = point_2d[0] + ss->cache->vc->ar->winrct.xmin; |
| 788 » » » y = point_2d[1] + ss->cache->vc->ar->winrct.ymin; |
| 789 » » } |
| 790 » » else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { |
| 791 » » » /* leave the coordinates relative to the screen */ |
| 792 |
| 793 » » » /* use unadjusted size for tiled mode */ |
| 794 » » » radius = BKE_brush_size_get(ss->cache->vc->scene, br); |
| 795 » »······· |
708 x = point_2d[0]; | 796 x = point_2d[0]; |
709 y = point_2d[1]; | 797 y = point_2d[1]; |
710 } | 798 } |
711 » » else /* else (mtex->brush_map_mode == MTEX_MAP_MODE_TILED), | 799 » » else if (mtex->brush_map_mode == MTEX_MAP_MODE_AREA) { |
712 » » leave the coordinates relative to the screen */ | 800 » » » /* Similar to fixed mode, but projects from brush angle |
713 » » { | 801 » » » * rather than view direction */ |
714 » » » radius = brush_size(br); // use unadjusted size for tile
d mode | 802 |
| 803 » » » /* Rotation is handled by the brush_local_mat */ |
| 804 » » » rotation = 0; |
| 805 |
| 806 » » » mul_m4_v3(ss->cache->brush_local_mat, symm_point); |
| 807 |
| 808 » » » x = symm_point[0]; |
| 809 » » » y = symm_point[1]; |
| 810 » » } |
| 811 |
| 812 » » if (mtex->brush_map_mode != MTEX_MAP_MODE_AREA) { |
| 813 » » » x /= ss->cache->vc->ar->winx; |
| 814 » » » y /= ss->cache->vc->ar->winy; |
| 815 |
| 816 » » » if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { |
| 817 » » » » x -= 0.5f; |
| 818 » » » » y -= 0.5f; |
| 819 » » » } |
715 ················ | 820 ················ |
716 » » » x = point_2d[0] - ss->cache->vc->ar->winrct.xmin; | 821 » » » x *= ss->cache->vc->ar->winx / radius; |
717 » » » y = point_2d[1] - ss->cache->vc->ar->winrct.ymin; | 822 » » » y *= ss->cache->vc->ar->winy / radius; |
718 » » } | 823 » » } |
719 | |
720 » » x /= ss->cache->vc->ar->winx; | |
721 » » y /= ss->cache->vc->ar->winy; | |
722 | |
723 » » if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { | |
724 » » » x -= 0.5f; | |
725 » » » y -= 0.5f; | |
726 » » } | |
727 » »······· | |
728 » » x *= ss->cache->vc->ar->winx / radius; | |
729 » » y *= ss->cache->vc->ar->winy / radius; | |
730 | 824 |
731 /* it is probably worth optimizing for those cases where· | 825 /* it is probably worth optimizing for those cases where· |
732 » » the texture is not rotated by skipping the calls to | 826 » » * the texture is not rotated by skipping the calls to |
733 » » atan2, sqrtf, sin, and cos. */ | 827 » » * atan2, sqrtf, sin, and cos. */ |
734 if (rotation > 0.001f || rotation < -0.001f) { | 828 if (rotation > 0.001f || rotation < -0.001f) { |
735 const float angle = atan2f(y, x) + rotation; | 829 const float angle = atan2f(y, x) + rotation; |
736 » » » const float flen = sqrtf(x*x + y*y); | 830 » » » const float flen = sqrtf(x * x + y * y); |
737 | 831 |
738 x = flen * cosf(angle); | 832 x = flen * cosf(angle); |
739 y = flen * sinf(angle); | 833 y = flen * sinf(angle); |
740 } | 834 } |
741 | 835 |
742 x *= br->mtex.size[0]; | 836 x *= br->mtex.size[0]; |
743 y *= br->mtex.size[1]; | 837 y *= br->mtex.size[1]; |
744 | 838 |
745 x += br->mtex.ofs[0]; | 839 x += br->mtex.ofs[0]; |
746 y += br->mtex.ofs[1]; | 840 y += br->mtex.ofs[1]; |
747 | 841 |
748 avg = paint_get_tex_pixel(br, x, y); | 842 avg = paint_get_tex_pixel(br, x, y); |
749 } | 843 } |
750 | 844 |
751 avg += br->texture_sample_bias; | 845 avg += br->texture_sample_bias; |
752 | 846 |
753 » avg *= brush_curve_strength(br, len, ss->cache->radius); /* Falloff curv
e */ | 847 » /* Falloff curve */ |
| 848 » avg *= BKE_brush_curve_strength(br, len, ss->cache->radius); |
| 849 |
| 850 » avg *= frontface(br, sculpt_normal, vno, fno); |
| 851 |
| 852 » /* Paint mask */ |
| 853 » avg *= 1.0f - mask; |
754 | 854 |
755 return avg; | 855 return avg; |
756 } | 856 } |
757 | 857 |
758 typedef struct { | 858 typedef struct { |
759 Sculpt *sd; | 859 Sculpt *sd; |
760 SculptSession *ss; | 860 SculptSession *ss; |
761 float radius_squared; | 861 float radius_squared; |
762 int original; | 862 int original; |
763 } SculptSearchSphereData; | 863 } SculptSearchSphereData; |
764 | 864 |
765 /* Test AABB against sphere */ | 865 /* Test AABB against sphere */ |
766 static int sculpt_search_sphere_cb(PBVHNode *node, void *data_v) | 866 static int sculpt_search_sphere_cb(PBVHNode *node, void *data_v) |
767 { | 867 { |
768 SculptSearchSphereData *data = data_v; | 868 SculptSearchSphereData *data = data_v; |
769 float *center = data->ss->cache->location, nearest[3]; | 869 float *center = data->ss->cache->location, nearest[3]; |
770 float t[3], bb_min[3], bb_max[3]; | 870 float t[3], bb_min[3], bb_max[3]; |
771 int i; | 871 int i; |
772 | 872 |
773 » if(data->original) | 873 » if (data->original) |
774 BLI_pbvh_node_get_original_BB(node, bb_min, bb_max); | 874 BLI_pbvh_node_get_original_BB(node, bb_min, bb_max); |
775 else | 875 else |
776 BLI_pbvh_node_get_BB(node, bb_min, bb_max); | 876 BLI_pbvh_node_get_BB(node, bb_min, bb_max); |
777 ········ | 877 ········ |
778 » for(i = 0; i < 3; ++i) { | 878 » for (i = 0; i < 3; ++i) { |
779 » » if(bb_min[i] > center[i]) | 879 » » if (bb_min[i] > center[i]) |
780 nearest[i] = bb_min[i]; | 880 nearest[i] = bb_min[i]; |
781 » » else if(bb_max[i] < center[i]) | 881 » » else if (bb_max[i] < center[i]) |
782 nearest[i] = bb_max[i]; | 882 nearest[i] = bb_max[i]; |
783 else | 883 else |
784 nearest[i] = center[i];· | 884 nearest[i] = center[i];· |
785 } | 885 } |
786 ········ | 886 ········ |
787 sub_v3_v3v3(t, center, nearest); | 887 sub_v3_v3v3(t, center, nearest); |
788 | 888 |
789 return dot_v3v3(t, t) < data->radius_squared; | 889 return dot_v3v3(t, t) < data->radius_squared; |
790 } | 890 } |
791 | 891 |
792 /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */ | 892 /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */ |
793 static void sculpt_clip(Sculpt *sd, SculptSession *ss, float *co, const float va
l[3]) | 893 static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float
val[3]) |
794 { | 894 { |
795 int i; | 895 int i; |
796 | 896 |
797 » for(i=0; i<3; ++i) { | 897 » for (i = 0; i < 3; ++i) { |
798 » » if(sd->flags & (SCULPT_LOCK_X << i)) | 898 » » if (sd->flags & (SCULPT_LOCK_X << i)) |
799 continue; | 899 continue; |
800 | 900 |
801 » » if((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cac
he->clip_tolerance[i])) | 901 » » if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->ca
che->clip_tolerance[i])) |
802 » » » co[i]= 0.0f; | 902 » » » co[i] = 0.0f; |
803 else | 903 else |
804 » » » co[i]= val[i]; | 904 » » » co[i] = val[i]; |
805 } | 905 } |
806 } | 906 } |
807 | 907 |
808 static void add_norm_if(float view_vec[3], float out[3], float out_flip[3], floa
t fno[3]) | 908 static void add_norm_if(float view_vec[3], float out[3], float out_flip[3], floa
t fno[3]) |
809 { | 909 { |
810 » if((dot_v3v3(view_vec, fno)) > 0) { | 910 » if ((dot_v3v3(view_vec, fno)) > 0) { |
811 add_v3_v3(out, fno); | 911 add_v3_v3(out, fno); |
812 » } else { | 912 » } |
| 913 » else { |
813 add_v3_v3(out_flip, fno); /* out_flip is used when out is {0,0,0
} */ | 914 add_v3_v3(out_flip, fno); /* out_flip is used when out is {0,0,0
} */ |
814 } | 915 } |
815 } | 916 } |
816 | 917 |
817 static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nod
es, int totnode) | 918 static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nod
es, int totnode) |
818 { | 919 { |
819 SculptSession *ss = ob->sculpt; | 920 SculptSession *ss = ob->sculpt; |
820 int n; | |
821 | |
822 float out_flip[3] = {0.0f, 0.0f, 0.0f}; | 921 float out_flip[3] = {0.0f, 0.0f, 0.0f}; |
| 922 int n, original; |
| 923 |
| 924 /* Grab brush requires to test on original data (see r33888 and |
| 925 * bug #25371) */ |
| 926 original = (paint_brush(&sd->paint)->sculpt_tool == SCULPT_TOOL_GRAB ? |
| 927 TRUE : ss->cache->original); |
823 | 928 |
824 (void)sd; /* unused w/o openmp */ | 929 (void)sd; /* unused w/o openmp */ |
825 ········ | 930 ········ |
826 zero_v3(an); | 931 zero_v3(an); |
827 | 932 |
828 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 933 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
829 » for(n=0; n<totnode; n++) { | 934 » for (n = 0; n < totnode; n++) { |
830 PBVHVertexIter vd; | 935 PBVHVertexIter vd; |
831 SculptBrushTest test; | 936 SculptBrushTest test; |
832 SculptUndoNode *unode; | 937 SculptUndoNode *unode; |
833 float private_an[3] = {0.0f, 0.0f, 0.0f}; | 938 float private_an[3] = {0.0f, 0.0f, 0.0f}; |
834 float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; | 939 float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; |
835 | 940 |
836 » » unode = sculpt_undo_push_node(ob, nodes[n]); | 941 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS); |
837 sculpt_brush_test_init(ss, &test); | 942 sculpt_brush_test_init(ss, &test); |
838 | 943 |
839 » » if(ss->cache->original) { | 944 » » if (original) { |
840 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 945 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
841 » » » » if(sculpt_brush_test_fast(&test, unode->co[vd.i]
)) { | 946 » » » { |
| 947 » » » » if (sculpt_brush_test_fast(&test, unode->co[vd.i
])) { |
842 float fno[3]; | 948 float fno[3]; |
843 | 949 |
844 normal_short_to_float_v3(fno, unode->no[
vd.i]); | 950 normal_short_to_float_v3(fno, unode->no[
vd.i]); |
845 add_norm_if(ss->cache->view_normal, priv
ate_an, private_out_flip, fno); | 951 add_norm_if(ss->cache->view_normal, priv
ate_an, private_out_flip, fno); |
846 } | 952 } |
847 } | 953 } |
848 BLI_pbvh_vertex_iter_end; | 954 BLI_pbvh_vertex_iter_end; |
849 } | 955 } |
850 else { | 956 else { |
851 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 957 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
852 » » » » if(sculpt_brush_test_fast(&test, vd.co)) { | 958 » » » { |
853 » » » » » if(vd.no) { | 959 » » » » if (sculpt_brush_test_fast(&test, vd.co)) { |
| 960 » » » » » if (vd.no) { |
854 float fno[3]; | 961 float fno[3]; |
855 | 962 |
856 normal_short_to_float_v3(fno, vd
.no); | 963 normal_short_to_float_v3(fno, vd
.no); |
857 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, fno); | 964 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, fno); |
858 } | 965 } |
859 else { | 966 else { |
860 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, vd.fno); | 967 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, vd.fno); |
861 } | 968 } |
862 } | 969 } |
863 } | 970 } |
864 BLI_pbvh_vertex_iter_end; | 971 BLI_pbvh_vertex_iter_end; |
865 } | 972 } |
866 | 973 |
867 #pragma omp critical | 974 #pragma omp critical |
868 { | 975 { |
869 add_v3_v3(an, private_an); | 976 add_v3_v3(an, private_an); |
870 add_v3_v3(out_flip, private_out_flip); | 977 add_v3_v3(out_flip, private_out_flip); |
871 } | 978 } |
872 } | 979 } |
873 | 980 |
874 if (is_zero_v3(an)) | 981 if (is_zero_v3(an)) |
875 copy_v3_v3(an, out_flip); | 982 copy_v3_v3(an, out_flip); |
876 | 983 |
877 normalize_v3(an); | 984 normalize_v3(an); |
878 } | 985 } |
879 | 986 |
880 /* This initializes the faces to be moved for this sculpt for draw/layer/flatten
; then it | 987 /* Calculate primary direction of movement for many brushes */ |
881 finds average normal for all active vertices - note that this is called once fo
r each mirroring direction */ | 988 static void calc_sculpt_normal(Sculpt *sd, Object *ob, |
882 static void calc_sculpt_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **n
odes, int totnode) | 989 PBVHNode **nodes, int totnode, |
883 { | 990 float an[3]) |
884 » SculptSession *ss = ob->sculpt; | 991 { |
885 » Brush *brush = paint_brush(&sd->paint); | 992 » const Brush *brush = paint_brush(&sd->paint); |
886 | 993 » const SculptSession *ss = ob->sculpt; |
887 » if (ss->cache->mirror_symmetry_pass == 0 && | 994 |
888 » ss->cache->radial_symmetry_pass == 0 && | 995 » switch (brush->sculpt_plane) { |
889 » (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) | 996 » » case SCULPT_DISP_DIR_VIEW: |
| 997 » » » ED_view3d_global_to_vector(ss->cache->vc->rv3d, |
| 998 » » » ss->cache->vc->rv3d->twmat[3]
, |
| 999 » » » an); |
| 1000 » » » break; |
| 1001 |
| 1002 » » case SCULPT_DISP_DIR_X: |
| 1003 » » » an[1] = 0.0; |
| 1004 » » » an[2] = 0.0; |
| 1005 » » » an[0] = 1.0; |
| 1006 » » » break; |
| 1007 |
| 1008 » » case SCULPT_DISP_DIR_Y: |
| 1009 » » » an[0] = 0.0; |
| 1010 » » » an[2] = 0.0; |
| 1011 » » » an[1] = 1.0; |
| 1012 » » » break; |
| 1013 |
| 1014 » » case SCULPT_DISP_DIR_Z: |
| 1015 » » » an[0] = 0.0; |
| 1016 » » » an[1] = 0.0; |
| 1017 » » » an[2] = 1.0; |
| 1018 » » » break; |
| 1019 |
| 1020 » » case SCULPT_DISP_DIR_AREA: |
| 1021 » » » calc_area_normal(sd, ob, an, nodes, totnode); |
| 1022 |
| 1023 » » default: |
| 1024 » » » break; |
| 1025 » } |
| 1026 } |
| 1027 |
| 1028 static void update_sculpt_normal(Sculpt *sd, Object *ob, |
| 1029 PBVHNode **nodes, int totnode) |
| 1030 { |
| 1031 » const Brush *brush = paint_brush(&sd->paint); |
| 1032 » StrokeCache *cache = ob->sculpt->cache; |
| 1033 »······· |
| 1034 » if (cache->mirror_symmetry_pass == 0 && |
| 1035 » cache->radial_symmetry_pass == 0 && |
| 1036 » (cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) |
890 { | 1037 { |
891 » » switch (brush->sculpt_plane) { | 1038 » » calc_sculpt_normal(sd, ob, nodes, totnode, cache->sculpt_normal)
; |
892 » » » case SCULPT_DISP_DIR_VIEW: | 1039 » » copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); |
893 » » » » viewvector(ss->cache->vc->rv3d, ss->cache->vc->r
v3d->twmat[3], an); | |
894 » » » » break; | |
895 | |
896 » » » case SCULPT_DISP_DIR_X: | |
897 » » » » an[1] = 0.0; | |
898 » » » » an[2] = 0.0; | |
899 » » » » an[0] = 1.0; | |
900 » » » » break; | |
901 | |
902 » » » case SCULPT_DISP_DIR_Y: | |
903 » » » » an[0] = 0.0; | |
904 » » » » an[2] = 0.0; | |
905 » » » » an[1] = 1.0; | |
906 » » » » break; | |
907 | |
908 » » » case SCULPT_DISP_DIR_Z: | |
909 » » » » an[0] = 0.0; | |
910 » » » » an[1] = 0.0; | |
911 » » » » an[2] = 1.0; | |
912 » » » » break; | |
913 | |
914 » » » case SCULPT_DISP_DIR_AREA: | |
915 » » » » calc_area_normal(sd, ob, an, nodes, totnode); | |
916 | |
917 » » » default: | |
918 » » » » break; | |
919 » » } | |
920 | |
921 » » copy_v3_v3(ss->cache->last_area_normal, an); | |
922 } | 1040 } |
923 else { | 1041 else { |
924 » » copy_v3_v3(an, ss->cache->last_area_normal); | 1042 » » copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); |
925 » » flip_coord(an, an, ss->cache->mirror_symmetry_pass); | 1043 » » flip_v3(cache->sculpt_normal_symm, cache->mirror_symmetry_pass); |
926 » » mul_m4_v3(ss->cache->symm_rot_mat, an); | 1044 » » mul_m4_v3(cache->symm_rot_mat, cache->sculpt_normal_symm); |
927 » } | 1045 » } |
| 1046 } |
| 1047 |
| 1048 static void calc_local_y(ViewContext *vc, const float center[3], float y[3]) |
| 1049 { |
| 1050 » Object *ob = vc->obact; |
| 1051 » float loc[3], mval_f[2] = {0.0f, 1.0f}; |
| 1052 |
| 1053 » mul_v3_m4v3(loc, ob->imat, center); |
| 1054 » initgrabz(vc->rv3d, loc[0], loc[1], loc[2]); |
| 1055 |
| 1056 » ED_view3d_win_to_delta(vc->ar, mval_f, y); |
| 1057 » normalize_v3(y); |
| 1058 |
| 1059 » add_v3_v3(y, ob->loc); |
| 1060 » mul_m4_v3(ob->imat, y); |
| 1061 } |
| 1062 |
| 1063 static void calc_brush_local_mat(const Brush *brush, Object *ob, |
| 1064 float local_mat[4][4]) |
| 1065 { |
| 1066 » const StrokeCache *cache = ob->sculpt->cache; |
| 1067 » float tmat[4][4]; |
| 1068 » float mat[4][4]; |
| 1069 » float scale[4][4]; |
| 1070 » float angle, v[3]; |
| 1071 » float up[3]; |
| 1072 |
| 1073 » /* Ensure ob->imat is up to date */ |
| 1074 » invert_m4_m4(ob->imat, ob->obmat); |
| 1075 |
| 1076 » /* Initialize last column of matrix */ |
| 1077 » mat[0][3] = 0; |
| 1078 » mat[1][3] = 0; |
| 1079 » mat[2][3] = 0; |
| 1080 » mat[3][3] = 1; |
| 1081 |
| 1082 » /* Get view's up vector in object-space */ |
| 1083 » calc_local_y(cache->vc, cache->location, up); |
| 1084 |
| 1085 » /* Calculate the X axis of the local matrix */ |
| 1086 » cross_v3_v3v3(v, up, cache->sculpt_normal); |
| 1087 » /* Apply rotation (user angle, rake, etc.) to X axis */ |
| 1088 » angle = brush->mtex.rot - cache->special_rotation; |
| 1089 » rotate_v3_v3v3fl(mat[0], v, cache->sculpt_normal, angle); |
| 1090 |
| 1091 » /* Get other axes */ |
| 1092 » cross_v3_v3v3(mat[1], cache->sculpt_normal, mat[0]); |
| 1093 » copy_v3_v3(mat[2], cache->sculpt_normal); |
| 1094 |
| 1095 » /* Set location */ |
| 1096 » copy_v3_v3(mat[3], cache->location); |
| 1097 |
| 1098 » /* Scale by brush radius */ |
| 1099 » normalize_m4(mat); |
| 1100 » scale_m4_fl(scale, cache->radius); |
| 1101 » mult_m4_m4m4(tmat, mat, scale); |
| 1102 |
| 1103 » /* Return inverse (for converting from modelspace coords to local |
| 1104 » * area coords) */ |
| 1105 » invert_m4_m4(local_mat, tmat); |
| 1106 } |
| 1107 |
| 1108 static void update_brush_local_mat(Sculpt *sd, Object *ob) |
| 1109 { |
| 1110 » StrokeCache *cache = ob->sculpt->cache; |
| 1111 |
| 1112 » if (cache->mirror_symmetry_pass == 0 && |
| 1113 » cache->radial_symmetry_pass == 0) |
| 1114 » { |
| 1115 » » calc_brush_local_mat(paint_brush(&sd->paint), ob, |
| 1116 » » cache->brush_local_mat); |
| 1117 » } |
| 1118 } |
| 1119 |
| 1120 /* Test whether the StrokeCache.sculpt_normal needs update in |
| 1121 * do_brush_action() */ |
| 1122 static int brush_needs_sculpt_normal(const Brush *brush) |
| 1123 { |
| 1124 » return ((ELEM(brush->sculpt_tool, |
| 1125 » SCULPT_TOOL_GRAB, |
| 1126 » SCULPT_TOOL_SNAKE_HOOK) && |
| 1127 » ((brush->normal_weight > 0) || |
| 1128 » (brush->flag & BRUSH_FRONTFACE))) || |
| 1129 |
| 1130 » ELEM7(brush->sculpt_tool, |
| 1131 » SCULPT_TOOL_BLOB, |
| 1132 » SCULPT_TOOL_CREASE, |
| 1133 » SCULPT_TOOL_DRAW, |
| 1134 » SCULPT_TOOL_LAYER, |
| 1135 » SCULPT_TOOL_NUDGE, |
| 1136 » SCULPT_TOOL_ROTATE, |
| 1137 » SCULPT_TOOL_THUMB) || |
| 1138 |
| 1139 » (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)); |
928 } | 1140 } |
929 | 1141 |
930 /* For the smooth brush, uses the neighboring vertices around vert to calculate | 1142 /* For the smooth brush, uses the neighboring vertices around vert to calculate |
931 a smoothed location for vert. Skips corner vertices (used by only one | 1143 * a smoothed location for vert. Skips corner vertices (used by only one |
932 polygon.) */ | 1144 * polygon.) */ |
933 static void neighbor_average(SculptSession *ss, float avg[3], const unsigned ver
t) | 1145 static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert) |
934 { | 1146 { |
935 » int i, skip= -1, total=0; | 1147 » const MeshElemMap *vert_map = &ss->pmap[vert]; |
936 » IndexNode *node= ss->fmap[vert].first; | 1148 » const MVert *mvert = ss->mvert; |
937 » char ncount= BLI_countlist(&ss->fmap[vert]); | 1149 » float (*deform_co)[3] = ss->deform_cos; |
938 » MFace *f; | 1150 |
939 | 1151 » zero_v3(avg); |
940 » avg[0] = avg[1] = avg[2] = 0; | |
941 ················ | 1152 ················ |
942 /* Don't modify corner vertices */ | 1153 /* Don't modify corner vertices */ |
943 » if(ncount==1) { | 1154 » if (vert_map->count > 1) { |
944 » » if(ss->deform_cos) copy_v3_v3(avg, ss->deform_cos[vert]); | 1155 » » int i, total = 0; |
945 » » else copy_v3_v3(avg, ss->mvert[vert].co); | 1156 |
946 | 1157 » » for (i = 0; i < vert_map->count; i++) { |
947 » » return; | 1158 » » » const MPoly *p = &ss->mpoly[vert_map->indices[i]]; |
948 » } | 1159 » » » unsigned f_adj_v[3]; |
949 | 1160 |
950 » while(node){ | 1161 » » » if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop,
vert) != -1) { |
951 » » f= &ss->mface[node->index]; | 1162 » » » » int j; |
952 » »······· | 1163 » » »······· |
953 » » if(f->v4) { | 1164 » » » » for (j = 0; j < 3; j++) { |
954 » » » skip= (f->v1==vert?2: | 1165 » » » » » if (vert_map->count != 2 || ss->pmap[f_a
dj_v[j]].count <= 2) { |
955 » » » » f->v2==vert?3: | 1166 » » » » » » add_v3_v3(avg, deform_co ? defor
m_co[f_adj_v[j]] : |
956 » » » » f->v3==vert?0: | 1167 » » » » » » mvert[f_adj_v[j]].co); |
957 » » » » f->v4==vert?1:-1); | 1168 |
958 » » } | 1169 » » » » » » total++; |
959 | 1170 » » » » » } |
960 » » for(i=0; i<(f->v4?4:3); ++i) { | 1171 » » » » } |
961 » » » if(i != skip && (ncount!=2 || BLI_countlist(&ss->fmap[(&
f->v1)[i]]) <= 2)) { | 1172 » » » } |
962 » » » » if(ss->deform_cos) add_v3_v3(avg, ss->deform_cos
[(&f->v1)[i]]); | 1173 » » } |
963 » » » » else add_v3_v3(avg, ss->mvert[(&f->v1)[i]].co); | 1174 |
964 » » » » ++total; | 1175 » » if (total > 0) { |
965 » » » } | 1176 » » » mul_v3_fl(avg, 1.0f / total); |
966 » » } | 1177 » » » return; |
967 | 1178 » » } |
968 » » node= node->next; | 1179 » } |
969 » } | 1180 |
970 | 1181 » copy_v3_v3(avg, deform_co ? deform_co[vert] : mvert[vert].co); |
971 » if(total>0) | 1182 } |
972 » » mul_v3_fl(avg, 1.0f / total); | 1183 |
973 » else { | 1184 /* Similar to neighbor_average(), but returns an averaged mask value |
974 » » if(ss->deform_cos) copy_v3_v3(avg, ss->deform_cos[vert]); | 1185 * instead of coordinate. Also does not restrict based on border or |
975 » » else copy_v3_v3(avg, ss->mvert[vert].co); | 1186 * corner vertices. */ |
976 » } | 1187 static float neighbor_average_mask(SculptSession *ss, unsigned vert) |
977 } | 1188 { |
978 | 1189 » const float *vmask = ss->vmask; |
979 static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node,
float bstrength) | 1190 » float avg = 0; |
| 1191 » int i, total = 0; |
| 1192 |
| 1193 » for (i = 0; i < ss->pmap[vert].count; i++) { |
| 1194 » » const MPoly *p = &ss->mpoly[ss->pmap[vert].indices[i]]; |
| 1195 » » unsigned f_adj_v[3]; |
| 1196 |
| 1197 » » if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop, vert) !=
-1) { |
| 1198 » » » int j; |
| 1199 » » »······· |
| 1200 » » » for (j = 0; j < 3; j++) { |
| 1201 » » » » avg += vmask[f_adj_v[j]]; |
| 1202 » » » » total++; |
| 1203 » » » } |
| 1204 » » } |
| 1205 » } |
| 1206 |
| 1207 » if (total > 0) |
| 1208 » » return avg / (float)total; |
| 1209 » else |
| 1210 » » return vmask[vert]; |
| 1211 } |
| 1212 |
| 1213 static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node,
float bstrength, int smooth_mask) |
980 { | 1214 { |
981 Brush *brush = paint_brush(&sd->paint); | 1215 Brush *brush = paint_brush(&sd->paint); |
982 PBVHVertexIter vd; | 1216 PBVHVertexIter vd; |
983 SculptBrushTest test; | 1217 SculptBrushTest test; |
984 ········ | 1218 ········ |
985 CLAMP(bstrength, 0.0f, 1.0f); | 1219 CLAMP(bstrength, 0.0f, 1.0f); |
986 | 1220 |
987 sculpt_brush_test_init(ss, &test); | 1221 sculpt_brush_test_init(ss, &test); |
988 | 1222 |
989 » BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { | 1223 » BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE) |
990 » » if(sculpt_brush_test(&test, vd.co)) { | 1224 » { |
991 » » » const float fade = bstrength*tex_strength(ss, brush, vd.
co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); | 1225 » » if (sculpt_brush_test(&test, vd.co)) { |
992 » » » float avg[3], val[3]; | 1226 » » » const float fade = bstrength * tex_strength(ss, brush, v
d.co, test.dist, |
993 | 1227 » » » ss->cache->v
iew_normal, vd.no, vd.fno, |
994 » » » neighbor_average(ss, avg, vd.vert_indices[vd.i]); | 1228 » » » smooth_mask
? 0 : *vd.mask); |
995 » » » sub_v3_v3v3(val, avg, vd.co); | 1229 » » » if (smooth_mask) { |
996 » » » mul_v3_fl(val, fade); | 1230 » » » » float val = neighbor_average_mask(ss, vd.vert_in
dices[vd.i]) - *vd.mask; |
997 | 1231 » » » » val *= fade * bstrength; |
998 » » » add_v3_v3(val, vd.co); | 1232 » » » » *vd.mask += val; |
999 | 1233 » » » » CLAMP(*vd.mask, 0, 1); |
1000 » » » sculpt_clip(sd, ss, vd.co, val); | 1234 » » » } |
1001 | 1235 » » » else { |
1002 » » » if(vd.mvert) | 1236 » » » » float avg[3], val[3]; |
1003 » » » » » vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1237 |
| 1238 » » » » neighbor_average(ss, avg, vd.vert_indices[vd.i])
; |
| 1239 » » » » sub_v3_v3v3(val, avg, vd.co); |
| 1240 » » » » mul_v3_fl(val, fade); |
| 1241 |
| 1242 » » » » add_v3_v3(val, vd.co); |
| 1243 |
| 1244 » » » » sculpt_clip(sd, ss, vd.co, val); |
| 1245 » » » } |
| 1246 |
| 1247 » » » if (vd.mvert) |
| 1248 » » » » vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1004 } | 1249 } |
1005 } | 1250 } |
1006 BLI_pbvh_vertex_iter_end; | 1251 BLI_pbvh_vertex_iter_end; |
1007 } | 1252 } |
1008 | 1253 |
1009 static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
de, float bstrength) | 1254 static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
de, |
| 1255 float bstrength, int smooth_mask) |
1010 { | 1256 { |
1011 Brush *brush = paint_brush(&sd->paint); | 1257 Brush *brush = paint_brush(&sd->paint); |
1012 SculptBrushTest test; | 1258 SculptBrushTest test; |
1013 » DMGridData **griddata, *data; | 1259 » CCGElem **griddata, *data; |
| 1260 » CCGKey key; |
1014 DMGridAdjacency *gridadj, *adj; | 1261 DMGridAdjacency *gridadj, *adj; |
1015 » float (*tmpgrid)[3], (*tmprow)[3]; | 1262 » float (*tmpgrid_co)[3], (*tmprow_co)[3]; |
| 1263 » float *tmpgrid_mask, *tmprow_mask; |
1016 int v1, v2, v3, v4; | 1264 int v1, v2, v3, v4; |
| 1265 int thread_num; |
1017 int *grid_indices, totgrid, gridsize, i, x, y; | 1266 int *grid_indices, totgrid, gridsize, i, x, y; |
1018 | 1267 |
1019 sculpt_brush_test_init(ss, &test); | 1268 sculpt_brush_test_init(ss, &test); |
1020 | 1269 |
1021 CLAMP(bstrength, 0.0f, 1.0f); | 1270 CLAMP(bstrength, 0.0f, 1.0f); |
1022 | 1271 |
1023 BLI_pbvh_node_get_grids(ss->pbvh, node, &grid_indices, &totgrid, | 1272 BLI_pbvh_node_get_grids(ss->pbvh, node, &grid_indices, &totgrid, |
1024 » » NULL, &gridsize, &griddata, &gridadj); | 1273 » NULL, &gridsize, &griddata, &gridadj); |
1025 | 1274 » BLI_pbvh_get_grid_key(ss->pbvh, &key); |
1026 » #pragma omp critical | 1275 |
1027 » { | 1276 » thread_num = 0; |
1028 » » tmpgrid= MEM_mallocN(sizeof(float)*3*gridsize*gridsize, "tmpgrid
"); | 1277 #ifdef _OPENMP |
1029 » » tmprow= MEM_mallocN(sizeof(float)*3*gridsize, "tmprow"); | 1278 » if (sd->flags & SCULPT_USE_OPENMP) |
1030 » } | 1279 » » thread_num = omp_get_thread_num(); |
1031 | 1280 #endif |
1032 » for(i = 0; i < totgrid; ++i) { | 1281 » tmpgrid_co = ss->cache->tmpgrid_co[thread_num]; |
| 1282 » tmprow_co = ss->cache->tmprow_co[thread_num]; |
| 1283 » tmpgrid_mask = ss->cache->tmpgrid_mask[thread_num]; |
| 1284 » tmprow_mask = ss->cache->tmprow_mask[thread_num]; |
| 1285 |
| 1286 » for (i = 0; i < totgrid; ++i) { |
1033 data = griddata[grid_indices[i]]; | 1287 data = griddata[grid_indices[i]]; |
1034 adj = &gridadj[grid_indices[i]]; | 1288 adj = &gridadj[grid_indices[i]]; |
1035 | 1289 |
1036 » » memset(tmpgrid, 0, sizeof(float)*3*gridsize*gridsize); | 1290 » » if (smooth_mask) |
1037 | 1291 » » » memset(tmpgrid_mask, 0, sizeof(float) * gridsize * grids
ize); |
1038 » » for (y= 0; y < gridsize-1; y++) { | 1292 » » else |
1039 » » » float tmp[3]; | 1293 » » » memset(tmpgrid_co, 0, sizeof(float) * 3 * gridsize * gri
dsize); |
1040 | 1294 |
1041 » » » v1 = y*gridsize; | 1295 » » for (y = 0; y < gridsize - 1; y++) { |
1042 » » » add_v3_v3v3(tmprow[0], data[v1].co, data[v1+gridsize].co
); | 1296 » » » v1 = y * gridsize; |
1043 | 1297 » » » if (smooth_mask) { |
1044 » » » for (x= 0; x < gridsize-1; x++) { | 1298 » » » » tmprow_mask[0] = (*CCG_elem_offset_mask(&key, da
ta, v1) + |
1045 » » » » v1 = x + y*gridsize; | 1299 » » » » *CCG_elem_offset_mask(&key, da
ta, v1 + gridsize)); |
| 1300 » » » } |
| 1301 » » » else { |
| 1302 » » » » add_v3_v3v3(tmprow_co[0], |
| 1303 » » » » CCG_elem_offset_co(&key, data, v1), |
| 1304 » » » » CCG_elem_offset_co(&key, data, v1 +
gridsize)); |
| 1305 » » » } |
| 1306 |
| 1307 » » » for (x = 0; x < gridsize - 1; x++) { |
| 1308 » » » » v1 = x + y * gridsize; |
1046 v2 = v1 + 1; | 1309 v2 = v1 + 1; |
1047 v3 = v1 + gridsize; | 1310 v3 = v1 + gridsize; |
1048 v4 = v3 + 1; | 1311 v4 = v3 + 1; |
1049 | 1312 |
1050 » » » » add_v3_v3v3(tmprow[x+1], data[v2].co, data[v4].c
o); | 1313 » » » » if (smooth_mask) { |
1051 » » » » add_v3_v3v3(tmp, tmprow[x+1], tmprow[x]); | 1314 » » » » » float tmp; |
1052 | 1315 |
1053 » » » » add_v3_v3(tmpgrid[v1], tmp); | 1316 » » » » » tmprow_mask[x + 1] = (*CCG_elem_offset_m
ask(&key, data, v2) + |
1054 » » » » add_v3_v3(tmpgrid[v2], tmp); | 1317 » » » » » *CCG_elem_offset_m
ask(&key, data, v4)); |
1055 » » » » add_v3_v3(tmpgrid[v3], tmp); | 1318 » » » » » tmp = tmprow_mask[x + 1] + tmprow_mask[x
]; |
1056 » » » » add_v3_v3(tmpgrid[v4], tmp); | 1319 |
| 1320 » » » » » tmpgrid_mask[v1] += tmp; |
| 1321 » » » » » tmpgrid_mask[v2] += tmp; |
| 1322 » » » » » tmpgrid_mask[v3] += tmp; |
| 1323 » » » » » tmpgrid_mask[v4] += tmp; |
| 1324 » » » » } |
| 1325 » » » » else { |
| 1326 » » » » » float tmp[3]; |
| 1327 |
| 1328 » » » » » add_v3_v3v3(tmprow_co[x + 1], |
| 1329 » » » » » CCG_elem_offset_co(&key, dat
a, v2), |
| 1330 » » » » » CCG_elem_offset_co(&key, dat
a, v4)); |
| 1331 » » » » » add_v3_v3v3(tmp, tmprow_co[x + 1], tmpro
w_co[x]); |
| 1332 |
| 1333 » » » » » add_v3_v3(tmpgrid_co[v1], tmp); |
| 1334 » » » » » add_v3_v3(tmpgrid_co[v2], tmp); |
| 1335 » » » » » add_v3_v3(tmpgrid_co[v3], tmp); |
| 1336 » » » » » add_v3_v3(tmpgrid_co[v4], tmp); |
| 1337 » » » » } |
1057 } | 1338 } |
1058 } | 1339 } |
1059 | 1340 |
1060 /* blend with existing coordinates */ | 1341 /* blend with existing coordinates */ |
1061 » » for(y = 0; y < gridsize; ++y) { | 1342 » » for (y = 0; y < gridsize; ++y) { |
1062 » » » for(x = 0; x < gridsize; ++x) { | 1343 » » » for (x = 0; x < gridsize; ++x) { |
1063 float *co; | 1344 float *co; |
1064 float *fno; | 1345 float *fno; |
| 1346 float *mask; |
1065 int index; | 1347 int index; |
1066 | 1348 |
1067 » » » » if(x == 0 && adj->index[0] == -1) | 1349 » » » » if (x == 0 && adj->index[0] == -1) |
1068 continue; | 1350 continue; |
1069 | 1351 |
1070 » » » » if(x == gridsize - 1 && adj->index[2] == -1) | 1352 » » » » if (x == gridsize - 1 && adj->index[2] == -1) |
1071 continue; | 1353 continue; |
1072 | 1354 |
1073 » » » » if(y == 0 && adj->index[3] == -1) | 1355 » » » » if (y == 0 && adj->index[3] == -1) |
1074 continue; | 1356 continue; |
1075 | 1357 |
1076 » » » » if(y == gridsize - 1 && adj->index[1] == -1) | 1358 » » » » if (y == gridsize - 1 && adj->index[1] == -1) |
1077 continue; | 1359 continue; |
1078 | 1360 |
1079 » » » » index = x + y*gridsize; | 1361 » » » » index = x + y * gridsize; |
1080 » » » » co= data[index].co; | 1362 » » » » co = CCG_elem_offset_co(&key, data, index); |
1081 » » » » fno= data[index].no; | 1363 » » » » fno = CCG_elem_offset_no(&key, data, index); |
1082 | 1364 » » » » mask = CCG_elem_offset_mask(&key, data, index); |
1083 » » » » if(sculpt_brush_test(&test, co)) { | 1365 |
1084 » » » » » const float fade = bstrength*tex_strengt
h(ss, brush, co, test.dist)*frontface(brush, ss->cache->view_normal, NULL, fno); | 1366 » » » » if (sculpt_brush_test(&test, co)) { |
1085 » » » » » float *avg, val[3]; | 1367 » » » » » const float strength_mask = (smooth_mask
? 0 : *mask); |
1086 » » » » » float n; | 1368 » » » » » const float fade = bstrength * tex_stren
gth(ss, brush, co, test.dist, |
1087 | 1369 » » » » »
ss->cache->view_normal, |
1088 » » » » » avg = tmpgrid[x + y*gridsize]; | 1370 » » » » »
NULL, fno, strength_mask); |
1089 | 1371 » » » » » float n = 1.0f / 16.0f; |
1090 » » » » » n = 1/16.0f; | 1372 » » » » »······· |
1091 | 1373 » » » » » if (x == 0 || x == gridsize - 1) |
1092 » » » » » if(x == 0 || x == gridsize - 1) | |
1093 n *= 2; | 1374 n *= 2; |
1094 | 1375 » » » » » |
1095 » » » » » if(y == 0 || y == gridsize - 1) | 1376 » » » » » if (y == 0 || y == gridsize - 1) |
1096 n *= 2; | 1377 n *= 2; |
1097 | 1378 » » » » »······· |
1098 » » » » » mul_v3_fl(avg, n); | 1379 » » » » » if (smooth_mask) { |
1099 | 1380 » » » » » » *mask += ((tmpgrid_mask[x + y *
gridsize] * n) - *mask) * fade; |
1100 » » » » » sub_v3_v3v3(val, avg, co); | 1381 » » » » » } |
1101 » » » » » mul_v3_fl(val, fade); | 1382 » » » » » else { |
1102 | 1383 » » » » » » float *avg, val[3]; |
1103 » » » » » add_v3_v3(val, co); | 1384 |
1104 | 1385 » » » » » » avg = tmpgrid_co[x + y * gridsiz
e]; |
1105 » » » » » sculpt_clip(sd, ss, co, val); | 1386 |
| 1387 » » » » » » mul_v3_fl(avg, n); |
| 1388 |
| 1389 » » » » » » sub_v3_v3v3(val, avg, co); |
| 1390 » » » » » » mul_v3_fl(val, fade); |
| 1391 |
| 1392 » » » » » » add_v3_v3(val, co); |
| 1393 |
| 1394 » » » » » » sculpt_clip(sd, ss, co, val); |
| 1395 » » » » » } |
1106 } | 1396 } |
1107 } | 1397 } |
1108 } | 1398 } |
1109 } | 1399 } |
1110 | 1400 } |
1111 » #pragma omp critical | 1401 |
1112 » { | 1402 static void smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, |
1113 » » MEM_freeN(tmpgrid); | 1403 float bstrength, int smooth_mask) |
1114 » » MEM_freeN(tmprow); | |
1115 » } | |
1116 } | |
1117 | |
1118 static void smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float
bstrength) | |
1119 { | 1404 { |
1120 SculptSession *ss = ob->sculpt; | 1405 SculptSession *ss = ob->sculpt; |
1121 const int max_iterations = 4; | 1406 const int max_iterations = 4; |
1122 » const float fract = 1.0f/max_iterations; | 1407 » const float fract = 1.0f / max_iterations; |
| 1408 » PBVHType type = BLI_pbvh_type(ss->pbvh); |
1123 int iteration, n, count; | 1409 int iteration, n, count; |
1124 float last; | 1410 float last; |
1125 | 1411 |
1126 CLAMP(bstrength, 0, 1); | 1412 CLAMP(bstrength, 0, 1); |
1127 | 1413 |
1128 » count = (int)(bstrength*max_iterations); | 1414 » count = (int)(bstrength * max_iterations); |
1129 » last = max_iterations*(bstrength - count*fract); | 1415 » last = max_iterations * (bstrength - count * fract); |
1130 | 1416 |
1131 » for(iteration = 0; iteration <= count; ++iteration) { | 1417 » if (type == PBVH_FACES && !ss->pmap) { |
| 1418 » » BLI_assert(!"sculpt smooth: pmap missing"); |
| 1419 » » return; |
| 1420 » } |
| 1421 |
| 1422 » for (iteration = 0; iteration <= count; ++iteration) { |
| 1423 » » float strength = (iteration != count) ? 1.0f : last; |
| 1424 |
1132 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) | 1425 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) |
1133 » » for(n=0; n<totnode; n++) { | 1426 » » for (n = 0; n < totnode; n++) { |
1134 » » » if(ss->multires) { | 1427 » » » switch (type) { |
1135 » » » » do_multires_smooth_brush(sd, ss, nodes[n], itera
tion != count ? 1.0f : last); | 1428 » » » » case PBVH_GRIDS: |
1136 » » » } | 1429 » » » » » do_multires_smooth_brush(sd, ss, nodes[n
], strength, |
1137 » » » else if(ss->fmap) | 1430 » » » » » smooth_mask); |
1138 » » » » do_mesh_smooth_brush(sd, ss, nodes[n], iteration
!= count ? 1.0f : last); | 1431 » » » » » break; |
1139 » » } | 1432 » » » » case PBVH_FACES: |
1140 | 1433 » » » » » do_mesh_smooth_brush(sd, ss, nodes[n], s
trength, |
1141 » » if(ss->multires) | 1434 » » » » » smooth_mask); |
| 1435 » » » » » break; |
| 1436 » » » } |
| 1437 » » } |
| 1438 |
| 1439 » » if (ss->multires) |
1142 multires_stitch_grids(ob); | 1440 multires_stitch_grids(ob); |
1143 } | 1441 } |
1144 } | 1442 } |
1145 | 1443 |
1146 static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) | 1444 static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) |
1147 { | 1445 { |
1148 SculptSession *ss = ob->sculpt; | 1446 SculptSession *ss = ob->sculpt; |
1149 » smooth(sd, ob, nodes, totnode, ss->cache->bstrength); | 1447 » smooth(sd, ob, nodes, totnode, ss->cache->bstrength, FALSE); |
1150 } | 1448 } |
1151 | 1449 |
1152 static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | 1450 static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int tot
node) |
1153 { | 1451 { |
1154 SculptSession *ss = ob->sculpt; | 1452 SculptSession *ss = ob->sculpt; |
1155 Brush *brush = paint_brush(&sd->paint); | 1453 Brush *brush = paint_brush(&sd->paint); |
1156 » float offset[3], area_normal[3]; | 1454 » float bstrength = ss->cache->bstrength; |
1157 » float bstrength= ss->cache->bstrength; | |
1158 int n; | 1455 int n; |
1159 | 1456 |
1160 » calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); | 1457 » /* threaded loop over nodes */ |
| 1458 » #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
| 1459 » for (n = 0; n < totnode; n++) { |
| 1460 » » PBVHVertexIter vd; |
| 1461 » » SculptBrushTest test; |
| 1462 |
| 1463 » » sculpt_brush_test_init(ss, &test); |
| 1464 |
| 1465 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 1466 » » { |
| 1467 » » » if (sculpt_brush_test(&test, vd.co)) { |
| 1468 » » » » float fade = tex_strength(ss, brush, vd.co, test
.dist, |
| 1469 » » » » ss->cache->view_normal
, vd.no, vd.fno, 0); |
| 1470 |
| 1471 » » » » (*vd.mask) += fade * bstrength; |
| 1472 » » » » CLAMP(*vd.mask, 0, 1); |
| 1473 |
| 1474 » » » » if (vd.mvert) |
| 1475 » » » » » vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
| 1476 » » » } |
| 1477 » » » BLI_pbvh_vertex_iter_end; |
| 1478 » » } |
| 1479 » } |
| 1480 } |
| 1481 |
| 1482 static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) |
| 1483 { |
| 1484 » SculptSession *ss = ob->sculpt; |
| 1485 » Brush *brush = paint_brush(&sd->paint); |
1161 ········ | 1486 ········ |
| 1487 switch ((BrushMaskTool)brush->mask_tool) { |
| 1488 case BRUSH_MASK_DRAW: |
| 1489 do_mask_brush_draw(sd, ob, nodes, totnode); |
| 1490 break; |
| 1491 case BRUSH_MASK_SMOOTH: |
| 1492 smooth(sd, ob, nodes, totnode, ss->cache->bstrength, TRU
E); |
| 1493 break; |
| 1494 } |
| 1495 } |
| 1496 |
| 1497 static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) |
| 1498 { |
| 1499 SculptSession *ss = ob->sculpt; |
| 1500 Brush *brush = paint_brush(&sd->paint); |
| 1501 float offset[3]; |
| 1502 float bstrength = ss->cache->bstrength; |
| 1503 int n; |
| 1504 |
1162 /* offset with as much as possible factored in already */ | 1505 /* offset with as much as possible factored in already */ |
1163 » mul_v3_v3fl(offset, area_normal, ss->cache->radius); | 1506 » mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); |
1164 mul_v3_v3(offset, ss->cache->scale); | 1507 mul_v3_v3(offset, ss->cache->scale); |
1165 mul_v3_fl(offset, bstrength); | 1508 mul_v3_fl(offset, bstrength); |
1166 | 1509 |
1167 /* threaded loop over nodes */ | 1510 /* threaded loop over nodes */ |
1168 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1511 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1169 » for(n=0; n<totnode; n++) { | 1512 » for (n = 0; n < totnode; n++) { |
1170 PBVHVertexIter vd; | 1513 PBVHVertexIter vd; |
1171 SculptBrushTest test; | 1514 SculptBrushTest test; |
1172 float (*proxy)[3]; | 1515 float (*proxy)[3]; |
1173 | 1516 |
1174 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1517 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1175 | 1518 |
1176 sculpt_brush_test_init(ss, &test); | 1519 sculpt_brush_test_init(ss, &test); |
1177 | 1520 |
1178 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1521 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 1522 » » { |
1179 if (sculpt_brush_test(&test, vd.co)) { | 1523 if (sculpt_brush_test(&test, vd.co)) { |
1180 //if(sculpt_brush_test_cyl(&test, vd.co, ss->cache->loca
tion, area_normal)) { | |
1181 /* offset vertex */ | 1524 /* offset vertex */ |
1182 » » » » float fade = tex_strength(ss, brush, vd.co, test
.dist)*frontface(brush, area_normal, vd.no, vd.fno); | 1525 » » » » float fade = tex_strength(ss, brush, vd.co, test
.dist, |
| 1526 » » » » ss->cache->sculpt_norm
al_symm, vd.no, |
| 1527 » » » » vd.fno, *vd.mask); |
1183 | 1528 |
1184 mul_v3_v3fl(proxy[vd.i], offset, fade); | 1529 mul_v3_v3fl(proxy[vd.i], offset, fade); |
1185 | 1530 |
1186 » » » » if(vd.mvert) | 1531 » » » » if (vd.mvert) |
1187 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1532 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1188 } | 1533 } |
1189 } | 1534 } |
1190 BLI_pbvh_vertex_iter_end; | 1535 BLI_pbvh_vertex_iter_end; |
1191 } | 1536 } |
1192 } | 1537 } |
1193 | 1538 |
1194 static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) | 1539 static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) |
1195 { | 1540 { |
1196 SculptSession *ss = ob->sculpt; | 1541 SculptSession *ss = ob->sculpt; |
| 1542 const Scene *scene = ss->cache->vc->scene; |
1197 Brush *brush = paint_brush(&sd->paint); | 1543 Brush *brush = paint_brush(&sd->paint); |
1198 » float offset[3], area_normal[3]; | 1544 » float offset[3]; |
1199 » float bstrength= ss->cache->bstrength; | 1545 » float bstrength = ss->cache->bstrength; |
1200 float flippedbstrength, crease_correction; | 1546 float flippedbstrength, crease_correction; |
| 1547 float brush_alpha; |
1201 int n; | 1548 int n; |
1202 | 1549 |
1203 calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); | |
1204 ········ | |
1205 /* offset with as much as possible factored in already */ | 1550 /* offset with as much as possible factored in already */ |
1206 » mul_v3_v3fl(offset, area_normal, ss->cache->radius); | 1551 » mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); |
1207 mul_v3_v3(offset, ss->cache->scale); | 1552 mul_v3_v3(offset, ss->cache->scale); |
1208 mul_v3_fl(offset, bstrength); | 1553 mul_v3_fl(offset, bstrength); |
1209 ········ | 1554 ········ |
1210 /* we divide out the squared alpha and multiply by the squared crease to
give us the pinch strength */ | 1555 /* we divide out the squared alpha and multiply by the squared crease to
give us the pinch strength */ |
1211 »······· | 1556 » crease_correction = brush->crease_pinch_factor * brush->crease_pinch_fac
tor; |
1212 » if(brush_alpha(brush) > 0.0f) | 1557 » brush_alpha = BKE_brush_alpha_get(scene, brush); |
1213 » » crease_correction = brush->crease_pinch_factor*brush->crease_pin
ch_factor/(brush_alpha(brush)*brush_alpha(brush)); | 1558 » if (brush_alpha > 0.0f) |
1214 » else | 1559 » » crease_correction /= brush_alpha * brush_alpha; |
1215 » » crease_correction = brush->crease_pinch_factor*brush->crease_pin
ch_factor; | |
1216 | 1560 |
1217 /* we always want crease to pinch or blob to relax even when draw is neg
ative */ | 1561 /* we always want crease to pinch or blob to relax even when draw is neg
ative */ |
1218 » flippedbstrength = (bstrength < 0) ? -crease_correction*bstrength : crea
se_correction*bstrength; | 1562 » flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : cr
ease_correction * bstrength; |
1219 | 1563 |
1220 » if(brush->sculpt_tool == SCULPT_TOOL_BLOB) flippedbstrength *= -1.0f; | 1564 » if (brush->sculpt_tool == SCULPT_TOOL_BLOB) flippedbstrength *= -1.0f; |
1221 | 1565 |
1222 /* threaded loop over nodes */ | 1566 /* threaded loop over nodes */ |
1223 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1567 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1224 » for(n=0; n<totnode; n++) { | 1568 » for (n = 0; n < totnode; n++) { |
1225 PBVHVertexIter vd; | 1569 PBVHVertexIter vd; |
1226 SculptBrushTest test; | 1570 SculptBrushTest test; |
1227 float (*proxy)[3]; | 1571 float (*proxy)[3]; |
1228 | 1572 |
1229 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1573 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1230 | 1574 |
1231 sculpt_brush_test_init(ss, &test); | 1575 sculpt_brush_test_init(ss, &test); |
1232 | 1576 |
1233 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1577 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1234 » » » if(sculpt_brush_test(&test, vd.co)) { | 1578 » » { |
| 1579 » » » if (sculpt_brush_test(&test, vd.co)) { |
1235 /* offset vertex */ | 1580 /* offset vertex */ |
1236 » » » » const float fade = tex_strength(ss, brush, vd.co
, test.dist)*frontface(brush, area_normal, vd.no, vd.fno); | 1581 » » » » const float fade = tex_strength(ss, brush, vd.co
, test.dist, |
| 1582 » » » » ss->cache->sculp
t_normal_symm, |
| 1583 » » » » vd.no, vd.fno, *
vd.mask); |
1237 float val1[3]; | 1584 float val1[3]; |
1238 float val2[3]; | 1585 float val2[3]; |
1239 | 1586 |
1240 /* first we pinch */ | 1587 /* first we pinch */ |
1241 sub_v3_v3v3(val1, test.location, vd.co); | 1588 sub_v3_v3v3(val1, test.location, vd.co); |
1242 » » » » //mul_v3_v3(val1, ss->cache->scale); | 1589 » » » » mul_v3_fl(val1, fade * flippedbstrength); |
1243 » » » » mul_v3_fl(val1, fade*flippedbstrength); | |
1244 | 1590 |
1245 /* then we draw */ | 1591 /* then we draw */ |
1246 mul_v3_v3fl(val2, offset, fade); | 1592 mul_v3_v3fl(val2, offset, fade); |
1247 | 1593 |
1248 add_v3_v3v3(proxy[vd.i], val1, val2); | 1594 add_v3_v3v3(proxy[vd.i], val1, val2); |
1249 | 1595 |
1250 » » » » if(vd.mvert) | 1596 » » » » if (vd.mvert) |
1251 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1597 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1252 } | 1598 } |
1253 } | 1599 } |
1254 BLI_pbvh_vertex_iter_end; | 1600 BLI_pbvh_vertex_iter_end; |
1255 } | 1601 } |
1256 } | 1602 } |
1257 | 1603 |
1258 static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) | 1604 static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) |
1259 { | 1605 { |
1260 SculptSession *ss = ob->sculpt; | 1606 SculptSession *ss = ob->sculpt; |
1261 Brush *brush = paint_brush(&sd->paint); | 1607 Brush *brush = paint_brush(&sd->paint); |
1262 » float bstrength= ss->cache->bstrength; | 1608 » float bstrength = ss->cache->bstrength; |
1263 int n; | 1609 int n; |
1264 | 1610 |
1265 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1611 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1266 » for(n=0; n<totnode; n++) { | 1612 » for (n = 0; n < totnode; n++) { |
1267 PBVHVertexIter vd; | 1613 PBVHVertexIter vd; |
1268 SculptBrushTest test; | 1614 SculptBrushTest test; |
1269 float (*proxy)[3]; | 1615 float (*proxy)[3]; |
1270 | 1616 |
1271 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1617 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1272 | 1618 |
1273 sculpt_brush_test_init(ss, &test); | 1619 sculpt_brush_test_init(ss, &test); |
1274 | 1620 |
1275 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1621 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1276 » » » if(sculpt_brush_test(&test, vd.co)) { | 1622 » » { |
1277 » » » » float fade = bstrength*tex_strength(ss, brush, v
d.co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); | 1623 » » » if (sculpt_brush_test(&test, vd.co)) { |
| 1624 » » » » float fade = bstrength * tex_strength(ss, brush,
vd.co, test.dist, |
| 1625 » » » » ss->cache-
>view_normal, vd.no, |
| 1626 » » » » vd.fno, *v
d.mask); |
1278 float val[3]; | 1627 float val[3]; |
1279 | 1628 |
1280 sub_v3_v3v3(val, test.location, vd.co); | 1629 sub_v3_v3v3(val, test.location, vd.co); |
1281 mul_v3_v3fl(proxy[vd.i], val, fade); | 1630 mul_v3_v3fl(proxy[vd.i], val, fade); |
1282 | 1631 |
1283 » » » » if(vd.mvert) | 1632 » » » » if (vd.mvert) |
1284 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1633 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1285 } | 1634 } |
1286 } | 1635 } |
1287 BLI_pbvh_vertex_iter_end; | 1636 BLI_pbvh_vertex_iter_end; |
1288 } | 1637 } |
1289 } | 1638 } |
1290 | 1639 |
1291 static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | 1640 static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) |
1292 { | |
1293 SculptSession *ss = ob->sculpt; | |
1294 Brush *brush= paint_brush(&sd->paint); | |
1295 float bstrength= ss->cache->bstrength; | |
1296 float grab_delta[3], an[3]; | |
1297 int n; | |
1298 float len; | |
1299 | |
1300 if (brush->normal_weight > 0 || brush->flag & BRUSH_FRONTFACE) { | |
1301 int cache= 1; | |
1302 /* grab brush requires to test on original data */ | |
1303 SWAP(int, ss->cache->original, cache); | |
1304 calc_sculpt_normal(sd, ob, an, nodes, totnode); | |
1305 SWAP(int, ss->cache->original, cache); | |
1306 } | |
1307 ········ | |
1308 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); | |
1309 | |
1310 len = len_v3(grab_delta); | |
1311 | |
1312 if (brush->normal_weight > 0) { | |
1313 mul_v3_fl(an, len*brush->normal_weight); | |
1314 mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); | |
1315 add_v3_v3(grab_delta, an); | |
1316 } | |
1317 | |
1318 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | |
1319 for(n=0; n<totnode; n++) { | |
1320 PBVHVertexIter vd; | |
1321 SculptUndoNode* unode; | |
1322 SculptBrushTest test; | |
1323 float (*origco)[3]; | |
1324 short (*origno)[3]; | |
1325 float (*proxy)[3]; | |
1326 | |
1327 unode= sculpt_undo_push_node(ob, nodes[n]); | |
1328 origco= unode->co; | |
1329 origno= unode->no; | |
1330 | |
1331 proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | |
1332 | |
1333 sculpt_brush_test_init(ss, &test); | |
1334 | |
1335 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | |
1336 if(sculpt_brush_test(&test, origco[vd.i])) { | |
1337 const float fade = bstrength*tex_strength(ss, br
ush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); | |
1338 | |
1339 mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | |
1340 | |
1341 if(vd.mvert) | |
1342 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | |
1343 } | |
1344 } | |
1345 BLI_pbvh_vertex_iter_end; | |
1346 } | |
1347 } | |
1348 | |
1349 static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) | |
1350 { | 1641 { |
1351 SculptSession *ss = ob->sculpt; | 1642 SculptSession *ss = ob->sculpt; |
1352 Brush *brush = paint_brush(&sd->paint); | 1643 Brush *brush = paint_brush(&sd->paint); |
1353 float bstrength = ss->cache->bstrength; | 1644 float bstrength = ss->cache->bstrength; |
1354 float grab_delta[3]; | 1645 float grab_delta[3]; |
1355 int n; | 1646 int n; |
1356 » float an[3]; | 1647 » float len; |
| 1648 |
| 1649 » copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); |
| 1650 |
| 1651 » len = len_v3(grab_delta); |
| 1652 |
| 1653 » if (brush->normal_weight > 0) { |
| 1654 » » mul_v3_fl(ss->cache->sculpt_normal_symm, len * brush->normal_wei
ght); |
| 1655 » » mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); |
| 1656 » » add_v3_v3(grab_delta, ss->cache->sculpt_normal_symm); |
| 1657 » } |
| 1658 |
| 1659 » #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
| 1660 » for (n = 0; n < totnode; n++) { |
| 1661 » » PBVHVertexIter vd; |
| 1662 » » SculptUndoNode *unode; |
| 1663 » » SculptBrushTest test; |
| 1664 » » float (*origco)[3]; |
| 1665 » » short (*origno)[3]; |
| 1666 » » float (*proxy)[3]; |
| 1667 |
| 1668 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS)
; |
| 1669 » » origco = unode->co; |
| 1670 » » origno = unode->no; |
| 1671 |
| 1672 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
| 1673 |
| 1674 » » sculpt_brush_test_init(ss, &test); |
| 1675 |
| 1676 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 1677 » » { |
| 1678 » » » if (sculpt_brush_test(&test, origco[vd.i])) { |
| 1679 » » » » const float fade = bstrength * tex_strength(ss,
brush, origco[vd.i], test.dist, |
| 1680 » » » » ss->
cache->sculpt_normal_symm, origno[vd.i], NULL, *vd.mask); |
| 1681 |
| 1682 » » » » mul_v3_v3fl(proxy[vd.i], grab_delta, fade); |
| 1683 |
| 1684 » » » » if (vd.mvert) |
| 1685 » » » » » vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
| 1686 » » » } |
| 1687 » » } |
| 1688 » » BLI_pbvh_vertex_iter_end; |
| 1689 » } |
| 1690 } |
| 1691 |
| 1692 static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) |
| 1693 { |
| 1694 » SculptSession *ss = ob->sculpt; |
| 1695 » Brush *brush = paint_brush(&sd->paint); |
| 1696 » float bstrength = ss->cache->bstrength; |
| 1697 » float grab_delta[3]; |
1357 float tmp[3], cono[3]; | 1698 float tmp[3], cono[3]; |
| 1699 int n; |
1358 | 1700 |
1359 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); | 1701 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); |
1360 | 1702 |
1361 » calc_sculpt_normal(sd, ob, an, nodes, totnode); | 1703 » cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); |
1362 | 1704 » cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); |
1363 » cross_v3_v3v3(tmp, an, grab_delta); | |
1364 » cross_v3_v3v3(cono, tmp, an); | |
1365 | 1705 |
1366 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1706 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1367 » for(n = 0; n < totnode; n++) { | 1707 » for (n = 0; n < totnode; n++) { |
1368 PBVHVertexIter vd; | 1708 PBVHVertexIter vd; |
1369 SculptBrushTest test; | 1709 SculptBrushTest test; |
1370 float (*proxy)[3]; | 1710 float (*proxy)[3]; |
1371 | 1711 |
1372 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1712 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1373 | 1713 |
1374 sculpt_brush_test_init(ss, &test); | 1714 sculpt_brush_test_init(ss, &test); |
1375 | 1715 |
1376 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1716 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1377 » » » if(sculpt_brush_test(&test, vd.co)) { | 1717 » » { |
1378 » » » » const float fade = bstrength*tex_strength(ss, br
ush, vd.co, test.dist)*frontface(brush, an, vd.no, vd.fno); | 1718 » » » if (sculpt_brush_test(&test, vd.co)) { |
| 1719 » » » » const float fade = bstrength * tex_strength(ss,
brush, vd.co, test.dist, |
| 1720 » » » » ss->
cache->sculpt_normal_symm, |
| 1721 » » » » vd.n
o, vd.fno, *vd.mask); |
1379 | 1722 |
1380 mul_v3_v3fl(proxy[vd.i], cono, fade); | 1723 mul_v3_v3fl(proxy[vd.i], cono, fade); |
1381 | 1724 |
1382 » » » » if(vd.mvert) | 1725 » » » » if (vd.mvert) |
1383 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1726 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1384 } | 1727 } |
1385 } | 1728 } |
1386 BLI_pbvh_vertex_iter_end; | 1729 BLI_pbvh_vertex_iter_end; |
1387 } | 1730 } |
1388 } | 1731 } |
1389 | 1732 |
1390 static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
tnode) | 1733 static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
tnode) |
1391 { | |
1392 SculptSession *ss = ob->sculpt; | |
1393 Brush *brush = paint_brush(&sd->paint); | |
1394 float bstrength = ss->cache->bstrength; | |
1395 float grab_delta[3], an[3]; | |
1396 int n; | |
1397 float len; | |
1398 | |
1399 if (brush->normal_weight > 0 || brush->flag & BRUSH_FRONTFACE) | |
1400 calc_sculpt_normal(sd, ob, an, nodes, totnode); | |
1401 | |
1402 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); | |
1403 | |
1404 len = len_v3(grab_delta); | |
1405 | |
1406 if (bstrength < 0) | |
1407 negate_v3(grab_delta); | |
1408 | |
1409 if (brush->normal_weight > 0) { | |
1410 mul_v3_fl(an, len*brush->normal_weight); | |
1411 mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); | |
1412 add_v3_v3(grab_delta, an); | |
1413 } | |
1414 | |
1415 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | |
1416 for(n = 0; n < totnode; n++) { | |
1417 PBVHVertexIter vd; | |
1418 SculptBrushTest test; | |
1419 float (*proxy)[3]; | |
1420 | |
1421 proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | |
1422 | |
1423 sculpt_brush_test_init(ss, &test); | |
1424 | |
1425 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | |
1426 if(sculpt_brush_test(&test, vd.co)) { | |
1427 const float fade = bstrength*tex_strength(ss, br
ush, vd.co, test.dist)*frontface(brush, an, vd.no, vd.fno); | |
1428 | |
1429 mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | |
1430 | |
1431 if(vd.mvert) | |
1432 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | |
1433 } | |
1434 } | |
1435 BLI_pbvh_vertex_iter_end; | |
1436 } | |
1437 } | |
1438 | |
1439 static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) | |
1440 { | 1734 { |
1441 SculptSession *ss = ob->sculpt; | 1735 SculptSession *ss = ob->sculpt; |
1442 Brush *brush = paint_brush(&sd->paint); | 1736 Brush *brush = paint_brush(&sd->paint); |
1443 float bstrength = ss->cache->bstrength; | 1737 float bstrength = ss->cache->bstrength; |
1444 float grab_delta[3]; | 1738 float grab_delta[3]; |
1445 int n; | 1739 int n; |
1446 » float an[3]; | 1740 » float len; |
| 1741 |
| 1742 » copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); |
| 1743 |
| 1744 » len = len_v3(grab_delta); |
| 1745 |
| 1746 » if (bstrength < 0) |
| 1747 » » negate_v3(grab_delta); |
| 1748 |
| 1749 » if (brush->normal_weight > 0) { |
| 1750 » » mul_v3_fl(ss->cache->sculpt_normal_symm, len * brush->normal_wei
ght); |
| 1751 » » mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); |
| 1752 » » add_v3_v3(grab_delta, ss->cache->sculpt_normal_symm); |
| 1753 » } |
| 1754 |
| 1755 » #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
| 1756 » for (n = 0; n < totnode; n++) { |
| 1757 » » PBVHVertexIter vd; |
| 1758 » » SculptBrushTest test; |
| 1759 » » float (*proxy)[3]; |
| 1760 |
| 1761 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
| 1762 |
| 1763 » » sculpt_brush_test_init(ss, &test); |
| 1764 |
| 1765 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 1766 » » { |
| 1767 » » » if (sculpt_brush_test(&test, vd.co)) { |
| 1768 » » » » const float fade = bstrength * tex_strength(ss,
brush, vd.co, test.dist, |
| 1769 » » » » ss->
cache->sculpt_normal_symm, |
| 1770 » » » » vd.n
o, vd.fno, *vd.mask); |
| 1771 |
| 1772 » » » » mul_v3_v3fl(proxy[vd.i], grab_delta, fade); |
| 1773 |
| 1774 » » » » if (vd.mvert) |
| 1775 » » » » » vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
| 1776 » » » } |
| 1777 » » } |
| 1778 » » BLI_pbvh_vertex_iter_end; |
| 1779 » } |
| 1780 } |
| 1781 |
| 1782 static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) |
| 1783 { |
| 1784 » SculptSession *ss = ob->sculpt; |
| 1785 » Brush *brush = paint_brush(&sd->paint); |
| 1786 » float bstrength = ss->cache->bstrength; |
| 1787 » float grab_delta[3]; |
1447 float tmp[3], cono[3]; | 1788 float tmp[3], cono[3]; |
| 1789 int n; |
1448 | 1790 |
1449 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); | 1791 copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); |
1450 | 1792 |
1451 » calc_sculpt_normal(sd, ob, an, nodes, totnode); | 1793 » cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); |
1452 | 1794 » cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); |
1453 » cross_v3_v3v3(tmp, an, grab_delta); | |
1454 » cross_v3_v3v3(cono, tmp, an); | |
1455 | 1795 |
1456 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1796 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1457 » for(n = 0; n < totnode; n++) { | 1797 » for (n = 0; n < totnode; n++) { |
1458 PBVHVertexIter vd; | 1798 PBVHVertexIter vd; |
1459 » » SculptUndoNode* unode; | 1799 » » SculptUndoNode *unode; |
1460 SculptBrushTest test; | 1800 SculptBrushTest test; |
1461 float (*origco)[3]; | 1801 float (*origco)[3]; |
1462 short (*origno)[3]; | 1802 short (*origno)[3]; |
1463 float (*proxy)[3]; | 1803 float (*proxy)[3]; |
1464 | 1804 |
1465 » » unode= sculpt_undo_push_node(ob, nodes[n]); | 1805 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS)
; |
1466 » » origco= unode->co; | 1806 » » origco = unode->co; |
1467 » » origno= unode->no; | 1807 » » origno = unode->no; |
1468 | 1808 |
1469 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1809 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1470 | 1810 |
1471 sculpt_brush_test_init(ss, &test); | 1811 sculpt_brush_test_init(ss, &test); |
1472 | 1812 |
1473 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1813 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1474 » » » if(sculpt_brush_test(&test, origco[vd.i])) { | 1814 » » { |
1475 » » » » const float fade = bstrength*tex_strength(ss, br
ush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); | 1815 » » » if (sculpt_brush_test(&test, origco[vd.i])) { |
| 1816 » » » » const float fade = bstrength * tex_strength(ss,
brush, origco[vd.i], test.dist, |
| 1817 » » » » ss->
cache->sculpt_normal_symm, |
| 1818 » » » » orig
no[vd.i], NULL, *vd.mask); |
1476 | 1819 |
1477 mul_v3_v3fl(proxy[vd.i], cono, fade); | 1820 mul_v3_v3fl(proxy[vd.i], cono, fade); |
1478 | 1821 |
1479 » » » » if(vd.mvert) | 1822 » » » » if (vd.mvert) |
1480 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1823 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1481 } | 1824 } |
1482 } | 1825 } |
1483 BLI_pbvh_vertex_iter_end; | 1826 BLI_pbvh_vertex_iter_end; |
1484 } | 1827 } |
1485 } | 1828 } |
1486 | 1829 |
1487 static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) | 1830 static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) |
1488 { | 1831 { |
1489 SculptSession *ss = ob->sculpt; | 1832 SculptSession *ss = ob->sculpt; |
1490 » Brush *brush= paint_brush(&sd->paint); | 1833 » Brush *brush = paint_brush(&sd->paint); |
1491 » float bstrength= ss->cache->bstrength; | 1834 » float bstrength = ss->cache->bstrength; |
1492 » float an[3]; | |
1493 int n; | 1835 int n; |
1494 » float m[3][3]; | 1836 » float m[4][4], rot[4][4], lmat[4][4], ilmat[4][4]; |
1495 static const int flip[8] = { 1, -1, -1, 1, -1, 1, 1, -1 }; | 1837 static const int flip[8] = { 1, -1, -1, 1, -1, 1, 1, -1 }; |
1496 float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmet
ry_pass]; | 1838 float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmet
ry_pass]; |
1497 | 1839 |
1498 » calc_sculpt_normal(sd, ob, an, nodes, totnode); | 1840 » unit_m4(m); |
1499 | 1841 » unit_m4(lmat); |
1500 » axis_angle_to_mat3(m, an, angle); | 1842 |
| 1843 » copy_v3_v3(lmat[3], ss->cache->location); |
| 1844 » invert_m4_m4(ilmat, lmat); |
| 1845 » axis_angle_to_mat4(rot, ss->cache->sculpt_normal_symm, angle); |
| 1846 |
| 1847 » mul_serie_m4(m, lmat, rot, ilmat, NULL, NULL, NULL, NULL, NULL); |
1501 | 1848 |
1502 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1849 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1503 » for(n=0; n<totnode; n++) { | 1850 » for (n = 0; n < totnode; n++) { |
1504 PBVHVertexIter vd; | 1851 PBVHVertexIter vd; |
1505 » » SculptUndoNode* unode; | 1852 » » SculptUndoNode *unode; |
1506 SculptBrushTest test; | 1853 SculptBrushTest test; |
1507 float (*origco)[3]; | 1854 float (*origco)[3]; |
1508 short (*origno)[3]; | 1855 short (*origno)[3]; |
1509 float (*proxy)[3]; | 1856 float (*proxy)[3]; |
1510 | 1857 |
1511 » » unode= sculpt_undo_push_node(ob, nodes[n]); | 1858 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS)
; |
1512 » » origco= unode->co; | 1859 » » origco = unode->co; |
1513 » » origno= unode->no; | 1860 » » origno = unode->no; |
1514 | 1861 |
1515 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1862 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1516 | 1863 |
1517 sculpt_brush_test_init(ss, &test); | 1864 sculpt_brush_test_init(ss, &test); |
1518 | 1865 |
1519 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1866 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1520 » » » if(sculpt_brush_test(&test, origco[vd.i])) { | 1867 » » { |
1521 » » » » const float fade = bstrength*tex_strength(ss, br
ush, origco[vd.i], test.dist)*frontface(brush, an, origno[vd.i], NULL); | 1868 » » » if (sculpt_brush_test(&test, origco[vd.i])) { |
1522 | 1869 » » » » const float fade = bstrength * tex_strength(ss,
brush, origco[vd.i], test.dist, |
1523 » » » » mul_v3_m3v3(proxy[vd.i], m, origco[vd.i]); | 1870 » » » » ss->
cache->sculpt_normal_symm, |
| 1871 » » » » orig
no[vd.i], NULL, *vd.mask); |
| 1872 |
| 1873 » » » » mul_v3_m4v3(proxy[vd.i], m, origco[vd.i]); |
1524 sub_v3_v3(proxy[vd.i], origco[vd.i]); | 1874 sub_v3_v3(proxy[vd.i], origco[vd.i]); |
1525 mul_v3_fl(proxy[vd.i], fade); | 1875 mul_v3_fl(proxy[vd.i], fade); |
1526 | 1876 |
1527 » » » » if(vd.mvert) | 1877 » » » » if (vd.mvert) |
1528 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1878 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1529 } | 1879 } |
1530 } | 1880 } |
1531 BLI_pbvh_vertex_iter_end; | 1881 BLI_pbvh_vertex_iter_end; |
1532 } | 1882 } |
1533 } | 1883 } |
1534 | 1884 |
1535 static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) | 1885 static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
) |
1536 { | 1886 { |
1537 SculptSession *ss = ob->sculpt; | 1887 SculptSession *ss = ob->sculpt; |
1538 Brush *brush = paint_brush(&sd->paint); | 1888 Brush *brush = paint_brush(&sd->paint); |
1539 » float bstrength= ss->cache->bstrength; | 1889 » float bstrength = ss->cache->bstrength; |
1540 » float area_normal[3], offset[3]; | 1890 » float offset[3]; |
1541 » float lim= brush->height; | 1891 » float lim = brush->height; |
1542 int n; | 1892 int n; |
1543 | 1893 |
1544 » if(bstrength < 0) | 1894 » if (bstrength < 0) |
1545 lim = -lim; | 1895 lim = -lim; |
1546 | 1896 |
1547 » calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); | 1897 » mul_v3_v3v3(offset, ss->cache->scale, ss->cache->sculpt_normal_symm); |
1548 | |
1549 » mul_v3_v3v3(offset, ss->cache->scale, area_normal); | |
1550 | 1898 |
1551 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1899 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1552 » for(n=0; n<totnode; n++) { | 1900 » for (n = 0; n < totnode; n++) { |
1553 PBVHVertexIter vd; | 1901 PBVHVertexIter vd; |
1554 SculptBrushTest test; | 1902 SculptBrushTest test; |
1555 SculptUndoNode *unode; | 1903 SculptUndoNode *unode; |
1556 float (*origco)[3], *layer_disp; | 1904 float (*origco)[3], *layer_disp; |
1557 » » //float (*proxy)[3]; // XXX layer brush needs conversion to prox
y but its more complicated | 1905 » » /* XXX: layer brush needs conversion to proxy but its more compl
icated */ |
1558 | 1906 » » /* proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; */ |
1559 » » //proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | |
1560 ················ | 1907 ················ |
1561 » » unode= sculpt_undo_push_node(ob, nodes[n]); | 1908 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS); |
1562 » » origco=unode->co; | 1909 » » origco = unode->co; |
1563 » » if(!unode->layer_disp) | 1910 » » if (!unode->layer_disp) { |
1564 » » » { | 1911 » » » #pragma omp critical· |
1565 » » » » #pragma omp critical· | 1912 » » » unode->layer_disp = MEM_callocN(sizeof(float) * unode->t
otvert, "layer disp"); |
1566 » » » » unode->layer_disp= MEM_callocN(sizeof(float)*uno
de->totvert, "layer disp"); | 1913 » » } |
1567 » » » } | 1914 |
1568 | 1915 » » layer_disp = unode->layer_disp; |
1569 » » layer_disp= unode->layer_disp; | |
1570 | 1916 |
1571 sculpt_brush_test_init(ss, &test); | 1917 sculpt_brush_test_init(ss, &test); |
1572 | 1918 |
1573 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1919 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1574 » » » if(sculpt_brush_test(&test, origco[vd.i])) { | 1920 » » { |
1575 » » » » const float fade = bstrength*tex_strength(ss, br
ush, vd.co, test.dist)*frontface(brush, area_normal, vd.no, vd.fno); | 1921 » » » if (sculpt_brush_test(&test, origco[vd.i])) { |
1576 » » » » float *disp= &layer_disp[vd.i]; | 1922 » » » » const float fade = bstrength * tex_strength(ss,
brush, vd.co, test.dist, |
| 1923 » » » » ss->
cache->sculpt_normal_symm, |
| 1924 » » » » vd.n
o, vd.fno, *vd.mask); |
| 1925 » » » » float *disp = &layer_disp[vd.i]; |
1577 float val[3]; | 1926 float val[3]; |
1578 | 1927 |
1579 » » » » *disp+= fade; | 1928 » » » » *disp += fade; |
1580 | 1929 |
1581 /* Don't let the displacement go past the limit
*/ | 1930 /* Don't let the displacement go past the limit
*/ |
1582 » » » » if((lim < 0 && *disp < lim) || (lim >= 0 && *dis
p > lim)) | 1931 » » » » if ((lim < 0 && *disp < lim) || (lim >= 0 && *di
sp > lim)) |
1583 *disp = lim; | 1932 *disp = lim; |
1584 | 1933 |
1585 mul_v3_v3fl(val, offset, *disp); | 1934 mul_v3_v3fl(val, offset, *disp); |
1586 | 1935 |
1587 » » » » if(ss->layer_co && (brush->flag & BRUSH_PERSISTE
NT)) { | 1936 » » » » if (ss->layer_co && (brush->flag & BRUSH_PERSIST
ENT)) { |
1588 » » » » » int index= vd.vert_indices[vd.i]; | 1937 » » » » » int index = vd.vert_indices[vd.i]; |
1589 | 1938 |
1590 /* persistent base */ | 1939 /* persistent base */ |
1591 add_v3_v3(val, ss->layer_co[index]); | 1940 add_v3_v3(val, ss->layer_co[index]); |
1592 } | 1941 } |
1593 else { | 1942 else { |
1594 add_v3_v3(val, origco[vd.i]); | 1943 add_v3_v3(val, origco[vd.i]); |
1595 } | 1944 } |
1596 | 1945 |
1597 sculpt_clip(sd, ss, vd.co, val); | 1946 sculpt_clip(sd, ss, vd.co, val); |
1598 | 1947 |
1599 » » » » if(vd.mvert) | 1948 » » » » if (vd.mvert) |
1600 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1949 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1601 } | 1950 } |
1602 } | 1951 } |
1603 BLI_pbvh_vertex_iter_end; | 1952 BLI_pbvh_vertex_iter_end; |
1604 } | 1953 } |
1605 } | 1954 } |
1606 | 1955 |
1607 static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
de) | 1956 static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
de) |
1608 { | 1957 { |
1609 SculptSession *ss = ob->sculpt; | 1958 SculptSession *ss = ob->sculpt; |
1610 Brush *brush = paint_brush(&sd->paint); | 1959 Brush *brush = paint_brush(&sd->paint); |
1611 » float bstrength= ss->cache->bstrength; | 1960 » float bstrength = ss->cache->bstrength; |
1612 int n; | 1961 int n; |
1613 | 1962 |
1614 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 1963 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1615 » for(n=0; n<totnode; n++) { | 1964 » for (n = 0; n < totnode; n++) { |
1616 PBVHVertexIter vd; | 1965 PBVHVertexIter vd; |
1617 SculptBrushTest test; | 1966 SculptBrushTest test; |
1618 float (*proxy)[3]; | 1967 float (*proxy)[3]; |
1619 | 1968 |
1620 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 1969 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1621 | 1970 |
1622 sculpt_brush_test_init(ss, &test); | 1971 sculpt_brush_test_init(ss, &test); |
1623 | 1972 |
1624 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 1973 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
1625 » » » if(sculpt_brush_test(&test, vd.co)) { | 1974 » » { |
1626 » » » » const float fade = bstrength*tex_strength(ss, br
ush, vd.co, test.dist)*frontface(brush, ss->cache->view_normal, vd.no, vd.fno); | 1975 » » » if (sculpt_brush_test(&test, vd.co)) { |
| 1976 » » » » const float fade = bstrength * tex_strength(ss,
brush, vd.co, test.dist, |
| 1977 » » » » ss->
cache->view_normal, vd.no, vd.fno, *vd.mask); |
1627 float val[3]; | 1978 float val[3]; |
1628 | 1979 |
1629 » » » » if(vd.fno) copy_v3_v3(val, vd.fno); | 1980 » » » » if (vd.fno) copy_v3_v3(val, vd.fno); |
1630 else normal_short_to_float_v3(val, vd.no); | 1981 else normal_short_to_float_v3(val, vd.no); |
1631 ································ | 1982 ································ |
1632 mul_v3_fl(val, fade * ss->cache->radius); | 1983 mul_v3_fl(val, fade * ss->cache->radius); |
1633 mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale); | 1984 mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale); |
1634 | 1985 |
1635 » » » » if(vd.mvert) | 1986 » » » » if (vd.mvert) |
1636 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | 1987 vd.mvert->flag |= ME_VERT_PBVH_UPDATE; |
1637 } | 1988 } |
1638 } | 1989 } |
1639 BLI_pbvh_vertex_iter_end; | 1990 BLI_pbvh_vertex_iter_end; |
1640 } | 1991 } |
1641 } | 1992 } |
1642 | 1993 |
1643 static void calc_flatten_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
tnode, float fc[3]) | 1994 static void calc_flatten_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
tnode, float fc[3]) |
1644 { | 1995 { |
1645 SculptSession *ss = ob->sculpt; | 1996 SculptSession *ss = ob->sculpt; |
1646 int n; | 1997 int n; |
1647 | 1998 |
1648 float count = 0; | 1999 float count = 0; |
1649 | 2000 |
1650 (void)sd; /* unused w/o openmp */ | 2001 (void)sd; /* unused w/o openmp */ |
1651 | 2002 |
1652 zero_v3(fc); | 2003 zero_v3(fc); |
1653 | 2004 |
1654 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2005 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1655 » for(n=0; n<totnode; n++) { | 2006 » for (n = 0; n < totnode; n++) { |
1656 PBVHVertexIter vd; | 2007 PBVHVertexIter vd; |
1657 SculptBrushTest test; | 2008 SculptBrushTest test; |
1658 SculptUndoNode *unode; | 2009 SculptUndoNode *unode; |
1659 float private_fc[3] = {0.0f, 0.0f, 0.0f}; | 2010 float private_fc[3] = {0.0f, 0.0f, 0.0f}; |
1660 int private_count = 0; | 2011 int private_count = 0; |
1661 | 2012 |
1662 » » unode = sculpt_undo_push_node(ob, nodes[n]); | 2013 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS); |
1663 sculpt_brush_test_init(ss, &test); | 2014 sculpt_brush_test_init(ss, &test); |
1664 | 2015 |
1665 » » if(ss->cache->original) { | 2016 » » if (ss->cache->original) { |
1666 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 2017 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
1667 » » » » if(sculpt_brush_test_fast(&test, unode->co[vd.i]
)) { | 2018 » » » { |
1668 » » » » » add_v3_v3(private_fc, vd.co); | 2019 » » » » if (sculpt_brush_test_fast(&test, unode->co[vd.i
])) { |
| 2020 » » » » » add_v3_v3(private_fc, unode->co[vd.i]); |
1669 private_count++; | 2021 private_count++; |
1670 } | 2022 } |
1671 } | 2023 } |
1672 BLI_pbvh_vertex_iter_end; | 2024 BLI_pbvh_vertex_iter_end; |
1673 } | 2025 } |
1674 else { | 2026 else { |
1675 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 2027 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
1676 » » » » if(sculpt_brush_test_fast(&test, vd.co)) { | 2028 » » » { |
| 2029 » » » » if (sculpt_brush_test_fast(&test, vd.co)) { |
1677 add_v3_v3(private_fc, vd.co); | 2030 add_v3_v3(private_fc, vd.co); |
1678 private_count++; | 2031 private_count++; |
1679 } | 2032 } |
1680 } | 2033 } |
1681 BLI_pbvh_vertex_iter_end; | 2034 BLI_pbvh_vertex_iter_end; |
1682 } | 2035 } |
1683 | 2036 |
1684 #pragma omp critical | 2037 #pragma omp critical |
1685 { | 2038 { |
1686 add_v3_v3(fc, private_fc); | 2039 add_v3_v3(fc, private_fc); |
1687 count += private_count; | 2040 count += private_count; |
1688 } | 2041 } |
1689 } | 2042 } |
1690 | 2043 |
1691 mul_v3_fl(fc, 1.0f / count); | 2044 mul_v3_fl(fc, 1.0f / count); |
1692 } | 2045 } |
1693 | 2046 |
1694 /* this calculates flatten center and area normal together,· | 2047 /* this calculates flatten center and area normal together,· |
1695 amortizing the memory bandwidth and loop overhead to calculate both at the same
time */ | 2048 * amortizing the memory bandwidth and loop overhead to calculate both at the sa
me time */ |
1696 static void calc_area_normal_and_flatten_center(Sculpt *sd, Object *ob, PBVHNode
**nodes, int totnode, float an[3], float fc[3]) | 2049 static void calc_area_normal_and_flatten_center(Sculpt *sd, Object *ob, |
| 2050 PBVHNode **nodes, int totnode, |
| 2051 float an[3], float fc[3]) |
1697 { | 2052 { |
1698 SculptSession *ss = ob->sculpt; | 2053 SculptSession *ss = ob->sculpt; |
1699 int n; | 2054 int n; |
1700 | 2055 |
1701 » // an | 2056 » /* for area normal */ |
1702 float out_flip[3] = {0.0f, 0.0f, 0.0f}; | 2057 float out_flip[3] = {0.0f, 0.0f, 0.0f}; |
1703 | 2058 |
1704 » // fc | 2059 » /* for flatten center */ |
1705 float count = 0; | 2060 float count = 0; |
1706 | 2061 |
1707 (void)sd; /* unused w/o openmp */ | 2062 (void)sd; /* unused w/o openmp */ |
1708 ········ | 2063 ········ |
1709 » // an | 2064 » /* for area normal */ |
1710 zero_v3(an); | 2065 zero_v3(an); |
1711 | 2066 |
1712 » // fc | 2067 » /* for flatten center */ |
1713 zero_v3(fc); | 2068 zero_v3(fc); |
1714 | 2069 |
1715 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2070 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1716 » for(n=0; n<totnode; n++) { | 2071 » for (n = 0; n < totnode; n++) { |
1717 PBVHVertexIter vd; | 2072 PBVHVertexIter vd; |
1718 SculptBrushTest test; | 2073 SculptBrushTest test; |
1719 SculptUndoNode *unode; | 2074 SculptUndoNode *unode; |
1720 float private_an[3] = {0.0f, 0.0f, 0.0f}; | 2075 float private_an[3] = {0.0f, 0.0f, 0.0f}; |
1721 float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; | 2076 float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; |
1722 float private_fc[3] = {0.0f, 0.0f, 0.0f}; | 2077 float private_fc[3] = {0.0f, 0.0f, 0.0f}; |
1723 int private_count = 0; | 2078 int private_count = 0; |
1724 | 2079 |
1725 » » unode = sculpt_undo_push_node(ob, nodes[n]); | 2080 » » unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS); |
1726 sculpt_brush_test_init(ss, &test); | 2081 sculpt_brush_test_init(ss, &test); |
1727 | 2082 |
1728 » » if(ss->cache->original) { | 2083 » » if (ss->cache->original) { |
1729 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 2084 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
1730 » » » » if(sculpt_brush_test_fast(&test, unode->co[vd.i]
)) { | 2085 » » » { |
1731 » » » » » // an | 2086 » » » » if (sculpt_brush_test_fast(&test, unode->co[vd.i
])) { |
| 2087 » » » » » /* for area normal */ |
1732 float fno[3]; | 2088 float fno[3]; |
1733 | 2089 |
1734 normal_short_to_float_v3(fno, unode->no[
vd.i]); | 2090 normal_short_to_float_v3(fno, unode->no[
vd.i]); |
1735 add_norm_if(ss->cache->view_normal, priv
ate_an, private_out_flip, fno); | 2091 add_norm_if(ss->cache->view_normal, priv
ate_an, private_out_flip, fno); |
1736 | 2092 |
1737 » » » » » // fc | 2093 » » » » » /* for flatten center */ |
1738 » » » » » add_v3_v3(private_fc, vd.co); | 2094 » » » » » add_v3_v3(private_fc, unode->co[vd.i]); |
1739 private_count++; | 2095 private_count++; |
1740 } | 2096 } |
1741 } | 2097 } |
1742 BLI_pbvh_vertex_iter_end; | 2098 BLI_pbvh_vertex_iter_end; |
1743 } | 2099 } |
1744 else { | 2100 else { |
1745 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 2101 » » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) |
1746 » » » » if(sculpt_brush_test_fast(&test, vd.co)) { | 2102 » » » { |
1747 » » » » » // an | 2103 » » » » if (sculpt_brush_test_fast(&test, vd.co)) { |
1748 » » » » » if(vd.no) { | 2104 » » » » » /* for area normal */ |
| 2105 » » » » » if (vd.no) { |
1749 float fno[3]; | 2106 float fno[3]; |
1750 | 2107 |
1751 normal_short_to_float_v3(fno, vd
.no); | 2108 normal_short_to_float_v3(fno, vd
.no); |
1752 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, fno); | 2109 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, fno); |
1753 } | 2110 } |
1754 else { | 2111 else { |
1755 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, vd.fno); | 2112 add_norm_if(ss->cache->view_norm
al, private_an, private_out_flip, vd.fno); |
1756 } | 2113 } |
1757 | 2114 |
1758 » » » » » // fc | 2115 » » » » » /* for flatten center */ |
1759 add_v3_v3(private_fc, vd.co); | 2116 add_v3_v3(private_fc, vd.co); |
1760 private_count++; | 2117 private_count++; |
1761 } | 2118 } |
1762 } | 2119 } |
1763 BLI_pbvh_vertex_iter_end; | 2120 BLI_pbvh_vertex_iter_end; |
1764 } | 2121 } |
1765 | 2122 |
1766 #pragma omp critical | 2123 #pragma omp critical |
1767 { | 2124 { |
1768 » » » // an | 2125 » » » /* for area normal */ |
1769 add_v3_v3(an, private_an); | 2126 add_v3_v3(an, private_an); |
1770 add_v3_v3(out_flip, private_out_flip); | 2127 add_v3_v3(out_flip, private_out_flip); |
1771 | 2128 |
1772 » » » // fc | 2129 » » » /* for flatten center */ |
1773 add_v3_v3(fc, private_fc); | 2130 add_v3_v3(fc, private_fc); |
1774 count += private_count; | 2131 count += private_count; |
1775 } | 2132 } |
1776 } | 2133 } |
1777 | 2134 |
1778 » // an | 2135 » /* for area normal */ |
1779 if (is_zero_v3(an)) | 2136 if (is_zero_v3(an)) |
1780 copy_v3_v3(an, out_flip); | 2137 copy_v3_v3(an, out_flip); |
1781 | 2138 |
1782 normalize_v3(an); | 2139 normalize_v3(an); |
1783 | 2140 |
1784 » // fc | 2141 » /* for flatten center */ |
1785 if (count != 0) { | 2142 if (count != 0) { |
1786 mul_v3_fl(fc, 1.0f / count); | 2143 mul_v3_fl(fc, 1.0f / count); |
1787 } | 2144 } |
1788 else { | 2145 else { |
1789 zero_v3(fc); | 2146 zero_v3(fc); |
1790 } | 2147 } |
1791 } | 2148 } |
1792 | 2149 |
1793 static void calc_sculpt_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totn
ode, float an[3], float fc[3]) | 2150 static void calc_sculpt_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totn
ode, float an[3], float fc[3]) |
1794 { | 2151 { |
1795 SculptSession *ss = ob->sculpt; | 2152 SculptSession *ss = ob->sculpt; |
1796 Brush *brush = paint_brush(&sd->paint); | 2153 Brush *brush = paint_brush(&sd->paint); |
1797 | 2154 |
1798 if (ss->cache->mirror_symmetry_pass == 0 && | 2155 if (ss->cache->mirror_symmetry_pass == 0 && |
1799 ss->cache->radial_symmetry_pass == 0 && | 2156 ss->cache->radial_symmetry_pass == 0 && |
1800 » (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) | 2157 » (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) |
1801 { | 2158 { |
1802 switch (brush->sculpt_plane) { | 2159 switch (brush->sculpt_plane) { |
1803 case SCULPT_DISP_DIR_VIEW: | 2160 case SCULPT_DISP_DIR_VIEW: |
1804 » » » » viewvector(ss->cache->vc->rv3d, ss->cache->vc->r
v3d->twmat[3], an); | 2161 » » » » ED_view3d_global_to_vector(ss->cache->vc->rv3d,
ss->cache->vc->rv3d->twmat[3], an); |
1805 break; | 2162 break; |
1806 | 2163 |
1807 case SCULPT_DISP_DIR_X: | 2164 case SCULPT_DISP_DIR_X: |
1808 an[1] = 0.0; | 2165 an[1] = 0.0; |
1809 an[2] = 0.0; | 2166 an[2] = 0.0; |
1810 an[0] = 1.0; | 2167 an[0] = 1.0; |
1811 break; | 2168 break; |
1812 | 2169 |
1813 case SCULPT_DISP_DIR_Y: | 2170 case SCULPT_DISP_DIR_Y: |
1814 an[0] = 0.0; | 2171 an[0] = 0.0; |
1815 an[2] = 0.0; | 2172 an[2] = 0.0; |
1816 an[1] = 1.0; | 2173 an[1] = 1.0; |
1817 break; | 2174 break; |
1818 | 2175 |
1819 case SCULPT_DISP_DIR_Z: | 2176 case SCULPT_DISP_DIR_Z: |
1820 an[0] = 0.0; | 2177 an[0] = 0.0; |
1821 an[1] = 0.0; | 2178 an[1] = 0.0; |
1822 an[2] = 1.0; | 2179 an[2] = 1.0; |
1823 break; | 2180 break; |
1824 | 2181 |
1825 case SCULPT_DISP_DIR_AREA: | 2182 case SCULPT_DISP_DIR_AREA: |
1826 calc_area_normal_and_flatten_center(sd, ob, node
s, totnode, an, fc); | 2183 calc_area_normal_and_flatten_center(sd, ob, node
s, totnode, an, fc); |
1827 | 2184 |
1828 default: | 2185 default: |
1829 break; | 2186 break; |
1830 } | 2187 } |
1831 | 2188 |
1832 » » // fc | 2189 » » /* for flatten center */ |
1833 /* flatten center has not been calculated yet if we are not usin
g the area normal */ | 2190 /* flatten center has not been calculated yet if we are not usin
g the area normal */ |
1834 if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) | 2191 if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) |
1835 calc_flatten_center(sd, ob, nodes, totnode, fc); | 2192 calc_flatten_center(sd, ob, nodes, totnode, fc); |
1836 | 2193 |
1837 » » // an | 2194 » » /* for area normal */ |
1838 » » copy_v3_v3(ss->cache->last_area_normal, an); | 2195 » » copy_v3_v3(ss->cache->sculpt_normal, an); |
1839 | 2196 |
1840 » » // fc | 2197 » » /* for flatten center */ |
1841 copy_v3_v3(ss->cache->last_center, fc); | 2198 copy_v3_v3(ss->cache->last_center, fc); |
1842 } | 2199 } |
1843 else { | 2200 else { |
1844 » » // an | 2201 » » /* for area normal */ |
1845 » » copy_v3_v3(an, ss->cache->last_area_normal); | 2202 » » copy_v3_v3(an, ss->cache->sculpt_normal); |
1846 | 2203 |
1847 » » // fc | 2204 » » /* for flatten center */ |
1848 copy_v3_v3(fc, ss->cache->last_center); | 2205 copy_v3_v3(fc, ss->cache->last_center); |
1849 | 2206 |
1850 » » // an | 2207 » » /* for area normal */ |
1851 » » flip_coord(an, an, ss->cache->mirror_symmetry_pass); | 2208 » » flip_v3(an, ss->cache->mirror_symmetry_pass); |
1852 | 2209 |
1853 » » // fc | 2210 » » /* for flatten center */ |
1854 » » flip_coord(fc, fc, ss->cache->mirror_symmetry_pass); | 2211 » » flip_v3(fc, ss->cache->mirror_symmetry_pass); |
1855 | 2212 |
1856 » » // an | 2213 » » /* for area normal */ |
1857 mul_m4_v3(ss->cache->symm_rot_mat, an); | 2214 mul_m4_v3(ss->cache->symm_rot_mat, an); |
1858 | 2215 |
1859 » » // fc | 2216 » » /* for flatten center */ |
1860 mul_m4_v3(ss->cache->symm_rot_mat, fc); | 2217 mul_m4_v3(ss->cache->symm_rot_mat, fc); |
1861 } | 2218 } |
1862 } | 2219 } |
1863 | 2220 |
1864 /* Projects a point onto a plane along the plane's normal */ | 2221 /* Projects a point onto a plane along the plane's normal */ |
1865 static void point_plane_project(float intr[3], float co[3], float plane_normal[3
], float plane_center[3]) | 2222 static void point_plane_project(float intr[3], float co[3], float plane_normal[3
], float plane_center[3]) |
1866 { | 2223 { |
1867 sub_v3_v3v3(intr, co, plane_center); | 2224 » sub_v3_v3v3(intr, co, plane_center); |
1868 mul_v3_v3fl(intr, plane_normal, dot_v3v3(plane_normal, intr)); | 2225 » mul_v3_v3fl(intr, plane_normal, dot_v3v3(plane_normal, intr)); |
1869 sub_v3_v3v3(intr, co, intr); | 2226 » sub_v3_v3v3(intr, co, intr); |
1870 } | 2227 } |
1871 | 2228 |
1872 static int plane_trim(StrokeCache *cache, Brush *brush, float val[3]) | 2229 static int plane_trim(StrokeCache *cache, Brush *brush, float val[3]) |
1873 { | 2230 { |
1874 » return !(brush->flag & BRUSH_PLANE_TRIM) || (dot_v3v3(val, val) <= cache
->radius_squared*cache->plane_trim_squared); | 2231 » return (!(brush->flag & BRUSH_PLANE_TRIM) || |
| 2232 » ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_tri
m_squared))); |
1875 } | 2233 } |
1876 | 2234 |
1877 static int plane_point_side_flip(float co[3], float plane_normal[3], float plane
_center[3], int flip) | 2235 static int plane_point_side_flip(float co[3], float plane_normal[3], float plane
_center[3], int flip) |
1878 { | 2236 { |
1879 float delta[3]; | 2237 » float delta[3]; |
1880 float d; | 2238 » float d; |
1881 | 2239 |
1882 sub_v3_v3v3(delta, co, plane_center); | 2240 » sub_v3_v3v3(delta, co, plane_center); |
1883 d = dot_v3v3(plane_normal, delta); | 2241 » d = dot_v3v3(plane_normal, delta); |
1884 | 2242 |
1885 if (flip) d = -d; | 2243 » if (flip) d = -d; |
1886 | 2244 |
1887 return d <= 0.0f; | 2245 » return d <= 0.0f; |
1888 } | 2246 } |
1889 | 2247 |
1890 static int plane_point_side(float co[3], float plane_normal[3], float plane_cent
er[3]) | 2248 static int plane_point_side(float co[3], float plane_normal[3], float plane_cent
er[3]) |
1891 { | 2249 { |
1892 float delta[3]; | 2250 » float delta[3]; |
1893 | 2251 |
1894 sub_v3_v3v3(delta, co, plane_center); | 2252 » sub_v3_v3v3(delta, co, plane_center); |
1895 return dot_v3v3(plane_normal, delta) <= 0.0f; | 2253 » return dot_v3v3(plane_normal, delta) <= 0.0f; |
1896 } | 2254 } |
1897 | 2255 |
1898 static float get_offset(Sculpt *sd, SculptSession *ss) | 2256 static float get_offset(Sculpt *sd, SculptSession *ss) |
1899 { | 2257 { |
1900 » Brush* brush = paint_brush(&sd->paint); | 2258 » Brush *brush = paint_brush(&sd->paint); |
1901 | 2259 |
1902 float rv = brush->plane_offset; | 2260 float rv = brush->plane_offset; |
1903 | 2261 |
1904 if (brush->flag & BRUSH_OFFSET_PRESSURE) { | 2262 if (brush->flag & BRUSH_OFFSET_PRESSURE) { |
1905 rv *= ss->cache->pressure; | 2263 rv *= ss->cache->pressure; |
1906 } | 2264 } |
1907 | 2265 |
1908 return rv; | 2266 return rv; |
1909 } | 2267 } |
1910 | 2268 |
(...skipping 11 matching lines...) Expand all Loading... |
1922 float offset = get_offset(sd, ss); | 2280 float offset = get_offset(sd, ss); |
1923 | 2281 |
1924 float displace; | 2282 float displace; |
1925 | 2283 |
1926 int n; | 2284 int n; |
1927 | 2285 |
1928 float temp[3]; | 2286 float temp[3]; |
1929 | 2287 |
1930 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); | 2288 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); |
1931 | 2289 |
1932 » displace = radius*offset; | 2290 » displace = radius * offset; |
1933 | 2291 |
1934 mul_v3_v3v3(temp, an, ss->cache->scale); | 2292 mul_v3_v3v3(temp, an, ss->cache->scale); |
1935 mul_v3_fl(temp, displace); | 2293 mul_v3_fl(temp, displace); |
1936 add_v3_v3(fc, temp); | 2294 add_v3_v3(fc, temp); |
1937 | 2295 |
1938 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2296 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
1939 » for(n = 0; n < totnode; n++) { | 2297 » for (n = 0; n < totnode; n++) { |
1940 » » PBVHVertexIter vd; | 2298 » » PBVHVertexIter vd; |
1941 SculptBrushTest test; | 2299 SculptBrushTest test; |
1942 float (*proxy)[3]; | 2300 float (*proxy)[3]; |
1943 | 2301 |
1944 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 2302 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
1945 | 2303 |
1946 sculpt_brush_test_init(ss, &test); | 2304 sculpt_brush_test_init(ss, &test); |
1947 | 2305 |
1948 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 2306 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 2307 » » { |
1949 if (sculpt_brush_test_sq(&test, vd.co)) { | 2308 if (sculpt_brush_test_sq(&test, vd.co)) { |
1950 float intr[3]; | 2309 float intr[3]; |
1951 float val[3]; | 2310 float val[3]; |
1952 | 2311 |
1953 point_plane_project(intr, vd.co, an, fc); | 2312 point_plane_project(intr, vd.co, an, fc); |
1954 | 2313 |
1955 sub_v3_v3v3(val, intr, vd.co); | 2314 sub_v3_v3v3(val, intr, vd.co); |
1956 | 2315 |
1957 if (plane_trim(ss->cache, brush, val)) { | 2316 if (plane_trim(ss->cache, brush, val)) { |
1958 » » » » » const float fade = bstrength*tex_strengt
h(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno); | 2317 » » » » » const float fade = bstrength * tex_stren
gth(ss, brush, vd.co, sqrt(test.dist), |
| 2318 » » » » »
an, vd.no, vd.fno, *vd.mask); |
1959 | 2319 |
1960 mul_v3_v3fl(proxy[vd.i], val, fade); | 2320 mul_v3_v3fl(proxy[vd.i], val, fade); |
1961 | 2321 |
1962 » » » » » if(vd.mvert) | 2322 » » » » » if (vd.mvert) |
1963 vd.mvert->flag |= ME_VERT_PBVH_U
PDATE; | 2323 vd.mvert->flag |= ME_VERT_PBVH_U
PDATE; |
1964 } | 2324 } |
1965 } | 2325 } |
1966 } | 2326 } |
1967 BLI_pbvh_vertex_iter_end; | 2327 BLI_pbvh_vertex_iter_end; |
1968 } | 2328 } |
1969 } | 2329 } |
1970 | 2330 |
1971 static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | 2331 static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) |
1972 { | 2332 { |
1973 SculptSession *ss = ob->sculpt; | 2333 SculptSession *ss = ob->sculpt; |
1974 Brush *brush = paint_brush(&sd->paint); | 2334 Brush *brush = paint_brush(&sd->paint); |
1975 | 2335 |
1976 float bstrength = ss->cache->bstrength; | 2336 float bstrength = ss->cache->bstrength; |
1977 float radius = ss->cache->radius; | 2337 float radius = ss->cache->radius; |
1978 float offset = get_offset(sd, ss); | 2338 float offset = get_offset(sd, ss); |
1979 ········ | 2339 ········ |
1980 float displace; | 2340 float displace; |
1981 | 2341 |
1982 » float an[3]; // area normal | 2342 » float an[3]; |
1983 » float fc[3]; // flatten center | 2343 » float fc[3]; |
1984 | 2344 |
1985 int n; | 2345 int n; |
1986 | 2346 |
1987 float temp[3]; | 2347 float temp[3]; |
1988 //float p[3]; | |
1989 | 2348 |
1990 int flip; | 2349 int flip; |
1991 | 2350 |
1992 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); | 2351 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); |
1993 | 2352 |
1994 flip = bstrength < 0; | 2353 flip = bstrength < 0; |
1995 | 2354 |
1996 if (flip) { | 2355 if (flip) { |
1997 bstrength = -bstrength; | 2356 bstrength = -bstrength; |
1998 radius = -radius; | 2357 radius = -radius; |
1999 } | 2358 } |
2000 | 2359 |
2001 » displace = radius * (0.25f+offset); | 2360 » displace = radius * (0.25f + offset); |
2002 | 2361 |
2003 mul_v3_v3v3(temp, an, ss->cache->scale); | 2362 mul_v3_v3v3(temp, an, ss->cache->scale); |
2004 mul_v3_fl(temp, displace); | 2363 mul_v3_fl(temp, displace); |
2005 add_v3_v3(fc, temp); | 2364 add_v3_v3(fc, temp); |
2006 | 2365 |
2007 » //add_v3_v3v3(p, ss->cache->location, an); | 2366 » /* add_v3_v3v3(p, ss->cache->location, an); */ |
2008 | 2367 |
2009 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2368 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
2010 for (n = 0; n < totnode; n++) { | 2369 for (n = 0; n < totnode; n++) { |
2011 PBVHVertexIter vd; | 2370 PBVHVertexIter vd; |
2012 SculptBrushTest test; | 2371 SculptBrushTest test; |
2013 float (*proxy)[3]; | 2372 float (*proxy)[3]; |
2014 | 2373 |
2015 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 2374 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
2016 | 2375 |
2017 sculpt_brush_test_init(ss, &test); | 2376 sculpt_brush_test_init(ss, &test); |
2018 | 2377 |
2019 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 2378 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 2379 » » { |
2020 if (sculpt_brush_test_sq(&test, vd.co)) { | 2380 if (sculpt_brush_test_sq(&test, vd.co)) { |
2021 if (plane_point_side_flip(vd.co, an, fc, flip))
{ | 2381 if (plane_point_side_flip(vd.co, an, fc, flip))
{ |
2022 //if (sculpt_brush_test_cyl(&test, vd.co, ss->ca
che->location, p)) { | |
2023 float intr[3]; | 2382 float intr[3]; |
2024 float val[3]; | 2383 float val[3]; |
2025 | 2384 |
2026 point_plane_project(intr, vd.co, an, fc)
; | 2385 point_plane_project(intr, vd.co, an, fc)
; |
2027 | 2386 |
2028 sub_v3_v3v3(val, intr, vd.co); | 2387 sub_v3_v3v3(val, intr, vd.co); |
2029 | 2388 |
2030 if (plane_trim(ss->cache, brush, val)) { | 2389 if (plane_trim(ss->cache, brush, val)) { |
2031 » » » » » » const float fade = bstrength*tex
_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno)
; | 2390 » » » » » » const float fade = bstrength * t
ex_strength(ss, brush, vd.co, |
| 2391 » » » » » »
sqrt(test.dist), |
| 2392 » » » » » »
an, vd.no, vd.fno, *vd.mask); |
2032 | 2393 |
2033 mul_v3_v3fl(proxy[vd.i], val, fa
de); | 2394 mul_v3_v3fl(proxy[vd.i], val, fa
de); |
2034 | 2395 |
2035 » » » » » » if(vd.mvert) | 2396 » » » » » » if (vd.mvert) |
2036 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; | 2397 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; |
2037 } | 2398 } |
2038 } | 2399 } |
2039 } | 2400 } |
2040 } | 2401 } |
2041 BLI_pbvh_vertex_iter_end; | 2402 BLI_pbvh_vertex_iter_end; |
2042 } | 2403 } |
2043 } | 2404 } |
2044 | 2405 |
2045 static void do_clay_tubes_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
tnode) | 2406 static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
otnode) |
2046 { | 2407 { |
2047 SculptSession *ss = ob->sculpt; | 2408 SculptSession *ss = ob->sculpt; |
2048 Brush *brush = paint_brush(&sd->paint); | 2409 Brush *brush = paint_brush(&sd->paint); |
2049 | 2410 |
2050 float bstrength = ss->cache->bstrength; | 2411 float bstrength = ss->cache->bstrength; |
2051 float radius = ss->cache->radius; | 2412 float radius = ss->cache->radius; |
2052 float offset = get_offset(sd, ss); | 2413 float offset = get_offset(sd, ss); |
2053 ········ | 2414 ········ |
2054 float displace; | 2415 float displace; |
2055 | 2416 |
2056 » float sn[3]; // sculpt normal | 2417 » float sn[3]; |
2057 » float an[3]; // area normal | 2418 » float an[3]; |
2058 » float fc[3]; // flatten center | 2419 » float fc[3]; |
2059 | 2420 |
2060 int n; | 2421 int n; |
2061 | 2422 |
2062 float temp[3]; | 2423 float temp[3]; |
2063 float mat[4][4]; | 2424 float mat[4][4]; |
2064 float scale[4][4]; | 2425 float scale[4][4]; |
2065 float tmat[4][4]; | 2426 float tmat[4][4]; |
2066 | 2427 |
2067 int flip; | 2428 int flip; |
2068 | 2429 |
2069 calc_sculpt_plane(sd, ob, nodes, totnode, sn, fc); | 2430 calc_sculpt_plane(sd, ob, nodes, totnode, sn, fc); |
2070 | 2431 |
2071 if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_
ORIGINAL_NORMAL)) | 2432 if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_
ORIGINAL_NORMAL)) |
2072 calc_area_normal(sd, ob, an, nodes, totnode); | 2433 calc_area_normal(sd, ob, an, nodes, totnode); |
2073 else | 2434 else |
2074 copy_v3_v3(an, sn); | 2435 copy_v3_v3(an, sn); |
2075 | 2436 |
| 2437 /* delay the first daub because grab delta is not setup */ |
2076 if (ss->cache->first_time) | 2438 if (ss->cache->first_time) |
2077 » » return; // delay the first daub because grab delta is not setup | 2439 » » return; |
2078 | 2440 |
2079 flip = bstrength < 0; | 2441 flip = bstrength < 0; |
2080 | 2442 |
2081 if (flip) { | 2443 if (flip) { |
2082 bstrength = -bstrength; | 2444 bstrength = -bstrength; |
2083 radius = -radius; | 2445 radius = -radius; |
2084 } | 2446 } |
2085 | 2447 |
2086 » displace = radius * (0.25f+offset); | 2448 » displace = radius * (0.25f + offset); |
2087 | 2449 |
2088 mul_v3_v3v3(temp, sn, ss->cache->scale); | 2450 mul_v3_v3v3(temp, sn, ss->cache->scale); |
2089 mul_v3_fl(temp, displace); | 2451 mul_v3_fl(temp, displace); |
2090 add_v3_v3(fc, temp); | 2452 add_v3_v3(fc, temp); |
2091 | 2453 |
2092 » cross_v3_v3v3(mat[0], an, ss->cache->grab_delta_symmetry); mat[0][3] = 0
; | 2454 » /* init mat */ |
2093 » cross_v3_v3v3(mat[1], an, mat[0]); mat[1][3] = 0; | 2455 » cross_v3_v3v3(mat[0], an, ss->cache->grab_delta_symmetry); |
2094 » copy_v3_v3(mat[2], an); mat[2][3] = 0; | 2456 » mat[0][3] = 0; |
2095 » copy_v3_v3(mat[3], ss->cache->location); mat[3][3] = 1; | 2457 » cross_v3_v3v3(mat[1], an, mat[0]); |
| 2458 » mat[1][3] = 0; |
| 2459 » copy_v3_v3(mat[2], an); |
| 2460 » mat[2][3] = 0; |
| 2461 » copy_v3_v3(mat[3], ss->cache->location); |
| 2462 » mat[3][3] = 1; |
2096 normalize_m4(mat); | 2463 normalize_m4(mat); |
| 2464 |
| 2465 /* scale mat */ |
2097 scale_m4_fl(scale, ss->cache->radius); | 2466 scale_m4_fl(scale, ss->cache->radius); |
2098 » mul_m4_m4m4(tmat, scale, mat); | 2467 » mult_m4_m4m4(tmat, mat, scale); |
2099 invert_m4_m4(mat, tmat); | 2468 invert_m4_m4(mat, tmat); |
2100 | 2469 |
2101 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2470 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
2102 for (n = 0; n < totnode; n++) { | 2471 for (n = 0; n < totnode; n++) { |
2103 PBVHVertexIter vd; | 2472 PBVHVertexIter vd; |
2104 SculptBrushTest test; | 2473 SculptBrushTest test; |
2105 float (*proxy)[3]; | 2474 float (*proxy)[3]; |
2106 | 2475 |
2107 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 2476 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
2108 | 2477 |
2109 sculpt_brush_test_init(ss, &test); | 2478 sculpt_brush_test_init(ss, &test); |
2110 | 2479 |
2111 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 2480 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 2481 » » { |
2112 if (sculpt_brush_test_cube(&test, vd.co, mat)) { | 2482 if (sculpt_brush_test_cube(&test, vd.co, mat)) { |
2113 if (plane_point_side_flip(vd.co, sn, fc, flip))
{ | 2483 if (plane_point_side_flip(vd.co, sn, fc, flip))
{ |
2114 float intr[3]; | 2484 float intr[3]; |
2115 float val[3]; | 2485 float val[3]; |
2116 | 2486 |
2117 point_plane_project(intr, vd.co, sn, fc)
; | 2487 point_plane_project(intr, vd.co, sn, fc)
; |
2118 | 2488 |
2119 sub_v3_v3v3(val, intr, vd.co); | 2489 sub_v3_v3v3(val, intr, vd.co); |
2120 | 2490 |
2121 if (plane_trim(ss->cache, brush, val)) { | 2491 if (plane_trim(ss->cache, brush, val)) { |
2122 » » » » » » const float fade = bstrength*tex
_strength(ss, brush, vd.co, ss->cache->radius*test.dist)*frontface(brush, an, vd
.no, vd.fno); | 2492 » » » » » » const float fade = bstrength * t
ex_strength(ss, brush, vd.co, |
| 2493 » » » » » »
ss->cache->radius * test.dist, |
| 2494 » » » » » »
an, vd.no, vd.fno, *vd.mask); |
2123 | 2495 |
2124 mul_v3_v3fl(proxy[vd.i], val, fa
de); | 2496 mul_v3_v3fl(proxy[vd.i], val, fa
de); |
2125 | 2497 |
2126 » » » » » » if(vd.mvert) | 2498 » » » » » » if (vd.mvert) |
2127 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; | 2499 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; |
2128 } | 2500 } |
2129 } | 2501 } |
2130 } | 2502 } |
2131 } | 2503 } |
2132 BLI_pbvh_vertex_iter_end; | 2504 BLI_pbvh_vertex_iter_end; |
2133 } | 2505 } |
2134 } | 2506 } |
2135 | 2507 |
2136 static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | 2508 static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) |
2137 { | 2509 { |
2138 SculptSession *ss = ob->sculpt; | 2510 SculptSession *ss = ob->sculpt; |
2139 Brush *brush = paint_brush(&sd->paint); | 2511 Brush *brush = paint_brush(&sd->paint); |
2140 | 2512 |
2141 float bstrength = ss->cache->bstrength; | 2513 float bstrength = ss->cache->bstrength; |
2142 const float radius = ss->cache->radius; | 2514 const float radius = ss->cache->radius; |
2143 | 2515 |
2144 float an[3]; | 2516 float an[3]; |
2145 float fc[3]; | 2517 float fc[3]; |
2146 float offset = get_offset(sd, ss); | 2518 float offset = get_offset(sd, ss); |
2147 | 2519 |
2148 float displace; | 2520 float displace; |
2149 | 2521 |
2150 int n; | 2522 int n; |
2151 | 2523 |
2152 float temp[3]; | 2524 float temp[3]; |
2153 | 2525 |
2154 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); | 2526 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); |
2155 | 2527 |
2156 » displace = radius*offset; | 2528 » displace = radius * offset; |
2157 | 2529 |
2158 mul_v3_v3v3(temp, an, ss->cache->scale); | 2530 mul_v3_v3v3(temp, an, ss->cache->scale); |
2159 mul_v3_fl(temp, displace); | 2531 mul_v3_fl(temp, displace); |
2160 add_v3_v3(fc, temp); | 2532 add_v3_v3(fc, temp); |
2161 | 2533 |
2162 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2534 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
2163 for (n = 0; n < totnode; n++) { | 2535 for (n = 0; n < totnode; n++) { |
2164 PBVHVertexIter vd; | 2536 PBVHVertexIter vd; |
2165 SculptBrushTest test; | 2537 SculptBrushTest test; |
2166 float (*proxy)[3]; | 2538 float (*proxy)[3]; |
2167 | 2539 |
2168 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 2540 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
2169 | 2541 |
2170 sculpt_brush_test_init(ss, &test); | 2542 sculpt_brush_test_init(ss, &test); |
2171 | 2543 |
2172 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 2544 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 2545 » » { |
2173 if (sculpt_brush_test_sq(&test, vd.co)) { | 2546 if (sculpt_brush_test_sq(&test, vd.co)) { |
2174 if (plane_point_side(vd.co, an, fc)) { | 2547 if (plane_point_side(vd.co, an, fc)) { |
2175 float intr[3]; | 2548 float intr[3]; |
2176 float val[3]; | 2549 float val[3]; |
2177 | 2550 |
2178 point_plane_project(intr, vd.co, an, fc)
; | 2551 point_plane_project(intr, vd.co, an, fc)
; |
2179 | 2552 |
2180 sub_v3_v3v3(val, intr, vd.co); | 2553 sub_v3_v3v3(val, intr, vd.co); |
2181 | 2554 |
2182 if (plane_trim(ss->cache, brush, val)) { | 2555 if (plane_trim(ss->cache, brush, val)) { |
2183 » » » » » » const float fade = bstrength*tex
_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno)
; | 2556 » » » » » » const float fade = bstrength * t
ex_strength(ss, brush, vd.co, |
| 2557 » » » » » »
sqrt(test.dist), |
| 2558 » » » » » »
an, vd.no, vd.fno, *vd.mask); |
2184 | 2559 |
2185 mul_v3_v3fl(proxy[vd.i], val, fa
de); | 2560 mul_v3_v3fl(proxy[vd.i], val, fa
de); |
2186 | 2561 |
2187 » » » » » » if(vd.mvert) | 2562 » » » » » » if (vd.mvert) |
2188 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; | 2563 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; |
2189 } | 2564 } |
2190 } | 2565 } |
2191 } | 2566 } |
2192 } | 2567 } |
2193 BLI_pbvh_vertex_iter_end; | 2568 BLI_pbvh_vertex_iter_end; |
2194 } | 2569 } |
2195 } | 2570 } |
2196 | 2571 |
2197 static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) | 2572 static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
e) |
2198 { | 2573 { |
2199 SculptSession *ss = ob->sculpt; | 2574 SculptSession *ss = ob->sculpt; |
2200 Brush *brush = paint_brush(&sd->paint); | 2575 Brush *brush = paint_brush(&sd->paint); |
2201 | 2576 |
2202 float bstrength = ss->cache->bstrength; | 2577 float bstrength = ss->cache->bstrength; |
2203 const float radius = ss->cache->radius; | 2578 const float radius = ss->cache->radius; |
2204 | 2579 |
2205 float an[3]; | 2580 float an[3]; |
2206 float fc[3]; | 2581 float fc[3]; |
2207 float offset = get_offset(sd, ss); | 2582 float offset = get_offset(sd, ss); |
2208 | 2583 |
2209 float displace; | 2584 float displace; |
2210 | 2585 |
2211 int n; | 2586 int n; |
2212 | 2587 |
2213 float temp[3]; | 2588 float temp[3]; |
2214 | 2589 |
2215 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); | 2590 calc_sculpt_plane(sd, ob, nodes, totnode, an, fc); |
2216 | 2591 |
2217 » displace = -radius*offset; | 2592 » displace = -radius * offset; |
2218 | 2593 |
2219 mul_v3_v3v3(temp, an, ss->cache->scale); | 2594 mul_v3_v3v3(temp, an, ss->cache->scale); |
2220 mul_v3_fl(temp, displace); | 2595 mul_v3_fl(temp, displace); |
2221 add_v3_v3(fc, temp); | 2596 add_v3_v3(fc, temp); |
2222 | 2597 |
2223 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) | 2598 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPE
NMP) |
2224 for (n = 0; n < totnode; n++) { | 2599 for (n = 0; n < totnode; n++) { |
2225 PBVHVertexIter vd; | 2600 PBVHVertexIter vd; |
2226 SculptBrushTest test; | 2601 SculptBrushTest test; |
2227 float (*proxy)[3]; | 2602 float (*proxy)[3]; |
2228 | 2603 |
2229 » » proxy= BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; | 2604 » » proxy = BLI_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; |
2230 | 2605 |
2231 sculpt_brush_test_init(ss, &test); | 2606 sculpt_brush_test_init(ss, &test); |
2232 | 2607 |
2233 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) { | 2608 » » BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNI
QUE) |
| 2609 » » { |
2234 if (sculpt_brush_test_sq(&test, vd.co)) { | 2610 if (sculpt_brush_test_sq(&test, vd.co)) { |
2235 if (!plane_point_side(vd.co, an, fc)) { | 2611 if (!plane_point_side(vd.co, an, fc)) { |
2236 float intr[3]; | 2612 float intr[3]; |
2237 float val[3]; | 2613 float val[3]; |
2238 | 2614 |
2239 point_plane_project(intr, vd.co, an, fc)
; | 2615 point_plane_project(intr, vd.co, an, fc)
; |
2240 | 2616 |
2241 sub_v3_v3v3(val, intr, vd.co); | 2617 sub_v3_v3v3(val, intr, vd.co); |
2242 | 2618 |
2243 if (plane_trim(ss->cache, brush, val)) { | 2619 if (plane_trim(ss->cache, brush, val)) { |
2244 » » » » » » const float fade = bstrength*tex
_strength(ss, brush, vd.co, sqrt(test.dist))*frontface(brush, an, vd.no, vd.fno)
; | 2620 » » » » » » const float fade = bstrength * t
ex_strength(ss, brush, vd.co, |
| 2621 » » » » » »
sqrt(test.dist), |
| 2622 » » » » » »
an, vd.no, vd.fno, *vd.mask); |
2245 | 2623 |
2246 mul_v3_v3fl(proxy[vd.i], val, fa
de); | 2624 mul_v3_v3fl(proxy[vd.i], val, fa
de); |
2247 | 2625 |
2248 » » » » » » if(vd.mvert) | 2626 » » » » » » if (vd.mvert) |
2249 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; | 2627 vd.mvert->flag |= ME_VER
T_PBVH_UPDATE; |
2250 } | 2628 } |
2251 } | 2629 } |
2252 } | 2630 } |
2253 } | 2631 } |
2254 BLI_pbvh_vertex_iter_end; | 2632 BLI_pbvh_vertex_iter_end; |
2255 } | 2633 } |
2256 } | 2634 } |
2257 | 2635 |
2258 void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) | 2636 void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) |
2259 { | 2637 { |
2260 » Mesh *me= (Mesh*)ob->data; | 2638 » Mesh *me = (Mesh *)ob->data; |
2261 » float (*ofs)[3]= NULL; | 2639 » float (*ofs)[3] = NULL; |
2262 » int a, is_basis= 0; | 2640 » int a, is_basis = 0; |
2263 KeyBlock *currkey; | 2641 KeyBlock *currkey; |
2264 | 2642 |
2265 /* for relative keys editing of base should update other keys */ | 2643 /* for relative keys editing of base should update other keys */ |
2266 if (me->key->type == KEY_RELATIVE) | 2644 if (me->key->type == KEY_RELATIVE) |
2267 » » for (currkey = me->key->block.first; currkey; currkey= currkey->
next) | 2645 » » for (currkey = me->key->block.first; currkey; currkey = currkey-
>next) |
2268 » » » if(ob->shapenr-1 == currkey->relative) { | 2646 » » » if (ob->shapenr - 1 == currkey->relative) { |
2269 » » » » is_basis= 1; | 2647 » » » » is_basis = 1; |
2270 break; | 2648 break; |
2271 } | 2649 } |
2272 | 2650 |
2273 if (is_basis) { | 2651 if (is_basis) { |
2274 » » ofs= key_to_vertcos(ob, kb); | 2652 » » ofs = key_to_vertcos(ob, kb); |
2275 | 2653 |
2276 /* calculate key coord offsets (from previous location) */ | 2654 /* calculate key coord offsets (from previous location) */ |
2277 » » for (a= 0; a < me->totvert; a++) | 2655 » » for (a = 0; a < me->totvert; a++) { |
2278 » » » VECSUB(ofs[a], vertCos[a], ofs[a]); | 2656 » » » sub_v3_v3v3(ofs[a], vertCos[a], ofs[a]); |
| 2657 » » } |
2279 | 2658 |
2280 /* apply offsets on other keys */ | 2659 /* apply offsets on other keys */ |
2281 currkey = me->key->block.first; | 2660 currkey = me->key->block.first; |
2282 while (currkey) { | 2661 while (currkey) { |
2283 » » » int apply_offset = ((currkey != kb) && (ob->shapenr-1 ==
currkey->relative)); | 2662 » » » int apply_offset = ((currkey != kb) && (ob->shapenr - 1
== currkey->relative)); |
2284 | 2663 |
2285 if (apply_offset) | 2664 if (apply_offset) |
2286 offset_to_key(ob, currkey, ofs); | 2665 offset_to_key(ob, currkey, ofs); |
2287 | 2666 |
2288 » » » currkey= currkey->next; | 2667 » » » currkey = currkey->next; |
2289 } | 2668 } |
2290 | 2669 |
2291 MEM_freeN(ofs); | 2670 MEM_freeN(ofs); |
2292 } | 2671 } |
2293 | 2672 |
2294 /* modifying of basis key should update mesh */ | 2673 /* modifying of basis key should update mesh */ |
2295 if (kb == me->key->refkey) { | 2674 if (kb == me->key->refkey) { |
2296 » » MVert *mvert= me->mvert; | 2675 » » MVert *mvert = me->mvert; |
2297 | 2676 |
2298 » » for (a= 0; a < me->totvert; a++, mvert++) | 2677 » » for (a = 0; a < me->totvert; a++, mvert++) |
2299 » » » VECCOPY(mvert->co, vertCos[a]); | 2678 » » » copy_v3_v3(mvert->co, vertCos[a]); |
2300 | 2679 |
2301 » » mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface
, NULL); | 2680 » » BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, |
| 2681 » » me->mpoly, me->totloop, me->totpol
y, |
| 2682 » » NULL, NULL, 0, NULL, NULL); |
2302 } | 2683 } |
2303 | 2684 |
2304 /* apply new coords on active key block */ | 2685 /* apply new coords on active key block */ |
2305 vertcos_to_key(ob, kb, vertCos); | 2686 vertcos_to_key(ob, kb, vertCos); |
2306 } | 2687 } |
2307 | 2688 |
2308 static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush) | 2689 static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush) |
2309 { | 2690 { |
2310 SculptSession *ss = ob->sculpt; | 2691 SculptSession *ss = ob->sculpt; |
2311 SculptSearchSphereData data; | 2692 SculptSearchSphereData data; |
2312 PBVHNode **nodes = NULL; | 2693 PBVHNode **nodes = NULL; |
2313 int n, totnode; | 2694 int n, totnode; |
2314 | 2695 |
2315 /* Build a list of all nodes that are potentially within the brush's are
a of influence */ | 2696 /* Build a list of all nodes that are potentially within the brush's are
a of influence */ |
2316 data.ss = ss; | 2697 data.ss = ss; |
2317 data.sd = sd; | 2698 data.sd = sd; |
2318 data.radius_squared = ss->cache->radius_squared; | 2699 data.radius_squared = ss->cache->radius_squared; |
2319 » data.original = ELEM4(brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_
ROTATE, SCULPT_TOOL_THUMB, SCULPT_TOOL_LAYER); | 2700 » data.original = ELEM4(brush->sculpt_tool, |
| 2701 » SCULPT_TOOL_GRAB, |
| 2702 » SCULPT_TOOL_ROTATE, |
| 2703 » SCULPT_TOOL_THUMB, |
| 2704 » SCULPT_TOOL_LAYER); |
2320 BLI_pbvh_search_gather(ss->pbvh, sculpt_search_sphere_cb, &data, &nodes,
&totnode); | 2705 BLI_pbvh_search_gather(ss->pbvh, sculpt_search_sphere_cb, &data, &nodes,
&totnode); |
2321 | 2706 |
2322 /* Only act if some verts are inside the brush area */ | 2707 /* Only act if some verts are inside the brush area */ |
2323 if (totnode) { | 2708 if (totnode) { |
2324 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) | 2709 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) |
2325 » » for (n= 0; n < totnode; n++) { | 2710 » » for (n = 0; n < totnode; n++) { |
2326 » » » sculpt_undo_push_node(ob, nodes[n]); | 2711 » » » sculpt_undo_push_node(ob, nodes[n], |
| 2712 » » » brush->sculpt_tool == SCULPT_TOOL_
MASK ? |
| 2713 » » » SCULPT_UNDO_MASK : SCULPT_UNDO_COO
RDS); |
2327 BLI_pbvh_node_mark_update(nodes[n]); | 2714 BLI_pbvh_node_mark_update(nodes[n]); |
2328 } | 2715 } |
2329 | 2716 |
| 2717 if (brush_needs_sculpt_normal(brush)) |
| 2718 update_sculpt_normal(sd, ob, nodes, totnode); |
| 2719 |
| 2720 if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) |
| 2721 update_brush_local_mat(sd, ob); |
| 2722 |
2330 /* Apply one type of brush action */ | 2723 /* Apply one type of brush action */ |
2331 switch(brush->sculpt_tool){ | 2724 switch (brush->sculpt_tool) { |
2332 case SCULPT_TOOL_DRAW: | 2725 case SCULPT_TOOL_DRAW: |
2333 do_draw_brush(sd, ob, nodes, totnode); | 2726 do_draw_brush(sd, ob, nodes, totnode); |
2334 break; | 2727 break; |
2335 case SCULPT_TOOL_SMOOTH: | 2728 case SCULPT_TOOL_SMOOTH: |
2336 do_smooth_brush(sd, ob, nodes, totnode); | 2729 do_smooth_brush(sd, ob, nodes, totnode); |
2337 break; | 2730 break; |
2338 case SCULPT_TOOL_CREASE: | 2731 case SCULPT_TOOL_CREASE: |
2339 do_crease_brush(sd, ob, nodes, totnode); | 2732 do_crease_brush(sd, ob, nodes, totnode); |
2340 break; | 2733 break; |
2341 case SCULPT_TOOL_BLOB: | 2734 case SCULPT_TOOL_BLOB: |
2342 do_crease_brush(sd, ob, nodes, totnode); | 2735 do_crease_brush(sd, ob, nodes, totnode); |
2343 break; | 2736 break; |
2344 case SCULPT_TOOL_PINCH: | 2737 case SCULPT_TOOL_PINCH: |
2345 do_pinch_brush(sd, ob, nodes, totnode); | 2738 do_pinch_brush(sd, ob, nodes, totnode); |
2346 break; | 2739 break; |
2347 case SCULPT_TOOL_INFLATE: | 2740 case SCULPT_TOOL_INFLATE: |
2348 do_inflate_brush(sd, ob, nodes, totnode); | 2741 do_inflate_brush(sd, ob, nodes, totnode); |
2349 break; | 2742 break; |
2350 case SCULPT_TOOL_GRAB: | 2743 case SCULPT_TOOL_GRAB: |
2351 do_grab_brush(sd, ob, nodes, totnode); | 2744 do_grab_brush(sd, ob, nodes, totnode); |
2352 break; | 2745 break; |
2353 case SCULPT_TOOL_ROTATE: | 2746 case SCULPT_TOOL_ROTATE: |
2354 do_rotate_brush(sd, ob, nodes, totnode); | 2747 do_rotate_brush(sd, ob, nodes, totnode); |
2355 break; | 2748 break; |
2356 case SCULPT_TOOL_SNAKE_HOOK: | 2749 case SCULPT_TOOL_SNAKE_HOOK: |
2357 do_snake_hook_brush(sd, ob, nodes, totnode); | 2750 do_snake_hook_brush(sd, ob, nodes, totnode); |
2358 break; | 2751 break; |
2359 case SCULPT_TOOL_NUDGE: | 2752 case SCULPT_TOOL_NUDGE: |
2360 do_nudge_brush(sd, ob, nodes, totnode); | 2753 do_nudge_brush(sd, ob, nodes, totnode); |
2361 break; | 2754 break; |
2362 case SCULPT_TOOL_THUMB: | 2755 case SCULPT_TOOL_THUMB: |
2363 do_thumb_brush(sd, ob, nodes, totnode); | 2756 do_thumb_brush(sd, ob, nodes, totnode); |
2364 break; | 2757 break; |
2365 case SCULPT_TOOL_LAYER: | 2758 case SCULPT_TOOL_LAYER: |
2366 do_layer_brush(sd, ob, nodes, totnode); | 2759 do_layer_brush(sd, ob, nodes, totnode); |
2367 break; | 2760 break; |
2368 case SCULPT_TOOL_FLATTEN: | 2761 case SCULPT_TOOL_FLATTEN: |
2369 do_flatten_brush(sd, ob, nodes, totnode); | 2762 do_flatten_brush(sd, ob, nodes, totnode); |
2370 break; | 2763 break; |
2371 case SCULPT_TOOL_CLAY: | 2764 case SCULPT_TOOL_CLAY: |
2372 do_clay_brush(sd, ob, nodes, totnode); | 2765 do_clay_brush(sd, ob, nodes, totnode); |
2373 break; | 2766 break; |
2374 case SCULPT_TOOL_CLAY_TUBES: | 2767 case SCULPT_TOOL_CLAY_STRIPS: |
2375 do_clay_tubes_brush(sd, ob, nodes, totnode); | 2768 do_clay_strips_brush(sd, ob, nodes, totnode); |
2376 break; | 2769 break; |
2377 case SCULPT_TOOL_FILL: | 2770 case SCULPT_TOOL_FILL: |
2378 do_fill_brush(sd, ob, nodes, totnode); | 2771 do_fill_brush(sd, ob, nodes, totnode); |
2379 break; | 2772 break; |
2380 case SCULPT_TOOL_SCRAPE: | 2773 case SCULPT_TOOL_SCRAPE: |
2381 do_scrape_brush(sd, ob, nodes, totnode); | 2774 do_scrape_brush(sd, ob, nodes, totnode); |
2382 break; | 2775 break; |
2383 } | 2776 case SCULPT_TOOL_MASK: |
2384 | 2777 do_mask_brush(sd, ob, nodes, totnode); |
2385 if (brush->sculpt_tool != SCULPT_TOOL_SMOOTH && brush->autosmoot
h_factor > 0) { | 2778 break; |
2386 if (brush->flag & BRUSH_INVERSE_SMOOTH_PRESSURE) { | 2779 } |
2387 smooth(sd, ob, nodes, totnode, brush->autosmooth
_factor*(1-ss->cache->pressure)); | 2780 |
2388 } | 2781 if (!ELEM(brush->sculpt_tool, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_MA
SK) && |
2389 else { | 2782 } |
2390 smooth(sd, ob, nodes, totnode, brush->autosmooth
_factor); | 2783 } |
2391 } | 2784 |
2392 } | 2785 /**** Radial control ****/ |
2393 | 2786 static int sculpt_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *ev
ent) |
2394 MEM_freeN(nodes); | 2787 { |
2395 } | 2788 Paint *p = paint_get_active(CTX_data_scene(C)); |
2396 } | 2789 Brush *brush = paint_brush(p); |
2397 | 2790 float col[4], tex_col[4]; |
2398 /* flush displacement from deformed PBVH vertex to original mesh */ | 2791 |
2399 static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd) | 2792 WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor); |
2400 { | 2793 p->paint_cursor = NULL; |
2401 SculptSession *ss = ob->sculpt; | 2794 brush_radial_control_invoke(op, brush, 1); |
2402 Mesh *me= ob->data; | 2795 |
2403 float disp[3], newco[3]; | 2796 if((brush->flag & BRUSH_DIR_IN) && ELEM4(brush->sculpt_tool, SCULPT_TOOL
_DRAW, SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY, SCULPT_TOOL_PINCH)) |
2404 int index= vd->vert_indices[vd->i]; | 2797 copy_v3_v3(col, brush->sub_col); |
2405 | 2798 else |
2406 sub_v3_v3v3(disp, vd->co, ss->deform_cos[index]); | 2799 copy_v3_v3(col, brush->add_col); |
2407 mul_m3_v3(ss->deform_imats[index], disp); | 2800 col[3]= 0.5f; |
2408 add_v3_v3v3(newco, disp, ss->orig_cos[index]); | 2801 ············································································ |
2409 | 2802 copy_v3_v3(tex_col, U.sculpt_paint_overlay_col); |
2410 copy_v3_v3(ss->deform_cos[index], vd->co); | 2803 tex_col[3]= (brush->texture_overlay_alpha / 100.0f); |
2411 copy_v3_v3(ss->orig_cos[index], newco); | 2804 |
2412 | 2805 RNA_float_set_array(op->ptr, "color", col); |
2413 if(!ss->kb) | 2806 RNA_float_set_array(op->ptr, "texture_color", tex_col); |
2414 copy_v3_v3(me->mvert[index].co, newco); | 2807 |
2415 } | 2808 return WM_radial_control_invoke(C, op, event); |
2416 | 2809 } |
2417 static void sculpt_combine_proxies(Sculpt *sd, Object *ob) | 2810 |
2418 { | 2811 static int sculpt_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve
nt) |
2419 SculptSession *ss = ob->sculpt; | 2812 { |
2420 Brush *brush= paint_brush(&sd->paint); | 2813 int ret = WM_radial_control_modal(C, op, event); |
2421 PBVHNode** nodes; | 2814 if(ret != OPERATOR_RUNNING_MODAL) |
2422 int totnode, n; | 2815 paint_cursor_start(C, sculpt_poll); |
2423 | 2816 return ret; |
2424 BLI_pbvh_gather_proxies(ss->pbvh, &nodes, &totnode); | 2817 } |
2425 | 2818 |
2426 if(!ELEM(brush->sculpt_tool, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_LAYER)) { | 2819 static int sculpt_radial_control_exec(bContext *C, wmOperator *op) |
2427 /* these brushes start from original coordinates */ | 2820 { |
2428 const int use_orco = (ELEM3(brush->sculpt_tool, SCULPT_TOOL_GRAB
, | 2821 Brush *brush = paint_brush(&CTX_data_tool_settings(C)->sculpt->paint); |
2429 SCULPT_TOOL_ROTATE, SCULPT_TOOL_THUMB)); | 2822 int ret = brush_radial_control_exec(op, brush, 1); |
2430 | 2823 |
2431 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) | 2824 WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush); |
2432 for (n= 0; n < totnode; n++) { | 2825 |
2433 PBVHVertexIter vd; | 2826 return ret; |
2434 PBVHProxyNode* proxies; | 2827 } |
2435 int proxy_count; | 2828 |
2436 float (*orco)[3]; | 2829 static void SCULPT_OT_radial_control(wmOperatorType *ot) |
2437 | 2830 { |
2438 if(use_orco) | 2831 WM_OT_radial_control_partial(ot); |
2439 orco= sculpt_undo_push_node(ob, nodes[n])->co; | 2832 |
2440 | 2833 ot->name= "Sculpt Radial Control"; |
2441 BLI_pbvh_node_get_proxies(nodes[n], &proxies, &proxy_cou
nt); | 2834 ot->idname= "SCULPT_OT_radial_control"; |
2442 | 2835 |
2443 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_
ITER_UNIQUE) { | 2836 ot->invoke= sculpt_radial_control_invoke; |
2444 float val[3]; | 2837 ot->modal= sculpt_radial_control_modal; |
2445 int p; | 2838 ot->exec= sculpt_radial_control_exec; |
2446 | 2839 ot->poll= sculpt_poll; |
2447 if(use_orco) | 2840 |
2448 copy_v3_v3(val, orco[vd.i]); | 2841 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; |
2449 else | |
2450 copy_v3_v3(val, vd.co); | |
2451 | |
2452 for (p= 0; p < proxy_count; p++) | |
2453 add_v3_v3(val, proxies[p].co[vd.i]); | |
2454 | |
2455 sculpt_clip(sd, ss, vd.co, val); | |
2456 | |
2457 if(ss->modifiers_active) | |
2458 sculpt_flush_pbvhvert_deform(ob, &vd); | |
2459 } | |
2460 BLI_pbvh_vertex_iter_end; | |
2461 | |
2462 BLI_pbvh_node_free_proxies(nodes[n]); | |
2463 } | |
2464 } | |
2465 | |
2466 if (nodes) | |
2467 MEM_freeN(nodes); | |
2468 } | |
2469 | |
2470 /* copy the modified vertices from bvh to the active key */ | |
2471 static void sculpt_update_keyblock(Object *ob) | |
2472 { | |
2473 SculptSession *ss = ob->sculpt; | |
2474 float (*vertCos)[3]; | |
2475 | |
2476 /* Keyblock update happens after hadning deformation caused by modifiers
, | |
2477 so ss->orig_cos would be updated with new stroke */ | |
2478 if(ss->orig_cos) vertCos = ss->orig_cos; | |
2479 else vertCos = BLI_pbvh_get_vertCos(ss->pbvh); | |
2480 | |
2481 if (vertCos) { | |
2482 sculpt_vertcos_to_key(ob, ss->kb, vertCos); | |
2483 | |
2484 if(vertCos != ss->orig_cos) | |
2485 MEM_freeN(vertCos); | |
2486 } | |
2487 } | |
2488 | |
2489 /* flush displacement from deformed PBVH to original layer */ | |
2490 static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob) | |
2491 { | |
2492 SculptSession *ss = ob->sculpt; | |
2493 ········ | |
2494 if(!ss->kb) { | |
2495 Mesh *me= (Mesh*)ob->data; | |
2496 Brush *brush= paint_brush(&sd->paint); | |
2497 | |
2498 if(ELEM(brush->sculpt_tool, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_LAYE
R)) { | |
2499 /* this brushes aren't using proxies, so sculpt_combine_
proxies() wouldn't | |
2500 propagate needed deformation to original base */ | |
2501 | |
2502 int n, totnode; | |
2503 PBVHNode** nodes; | |
2504 | |
2505 BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &to
tnode); | |
2506 | |
2507 #pragma omp parallel for schedule(guided) if (sd->flags
& SCULPT_USE_OPENMP) | |
2508 for (n= 0; n < totnode; n++) { | |
2509 PBVHVertexIter vd; | |
2510 | |
2511 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], v
d, PBVH_ITER_UNIQUE) { | |
2512 sculpt_flush_pbvhvert_deform(ob, &vd); | |
2513 } | |
2514 BLI_pbvh_vertex_iter_end; | |
2515 } | |
2516 | |
2517 MEM_freeN(nodes); | |
2518 } | |
2519 | |
2520 /* Modifiers could depend on mesh normals, so we should update t
hem/ | |
2521 Note, then if sculpting happens on locked key, normals should
be re-calculated | |
2522 after applying coords from keyblock on base mesh */ | |
2523 mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface
, NULL); | |
2524 } else sculpt_update_keyblock(ob); | |
2525 } | |
2526 | |
2527 //static int max_overlap_count(Sculpt *sd) | |
2528 //{ | |
2529 // int count[3]; | |
2530 // int i, j; | |
2531 // | |
2532 // for (i= 0; i < 3; i++) { | |
2533 // count[i] = sd->radial_symm[i]; | |
2534 // | |
2535 // for (j= 0; j < 3; j++) { | |
2536 // if (i != j && sd->flags & (SCULPT_SYMM_X<<i)) | |
2537 // count[i] *= 2; | |
2538 // } | |
2539 // } | |
2540 // | |
2541 // return MAX3(count[0], count[1], count[2]); | |
2542 //} | |
2543 | |
2544 /* Flip all the editdata across the axis/axes specified by symm. Used to | |
2545 calculate multiple modifications to the mesh when symmetry is enabled. */ | |
2546 static void calc_brushdata_symm(Sculpt *sd, StrokeCache *cache, const char symm,
const char axis, const float angle, const float UNUSED(feather)) | |
2547 { | |
2548 (void)sd; /* unused */ | |
2549 | |
2550 flip_coord(cache->location, cache->true_location, symm); | |
2551 flip_coord(cache->grab_delta_symmetry, cache->grab_delta, symm); | |
2552 flip_coord(cache->view_normal, cache->true_view_normal, symm); | |
2553 | |
2554 // XXX This reduces the length of the grab delta if it approaches the li
ne of symmetry | |
2555 // XXX However, a different approach appears to be needed | |
2556 //if (sd->flags & SCULPT_SYMMETRY_FEATHER) { | |
2557 // float frac = 1.0f/max_overlap_count(sd); | |
2558 // float reduce = (feather-frac)/(1-frac); | |
2559 | |
2560 // printf("feather: %f frac: %f reduce: %f\n", feather, frac, reduc
e); | |
2561 | |
2562 // if (frac < 1) | |
2563 // mul_v3_fl(cache->grab_delta_symmetry, reduce); | |
2564 //} | |
2565 | |
2566 unit_m4(cache->symm_rot_mat); | |
2567 unit_m4(cache->symm_rot_mat_inv); | |
2568 | |
2569 if(axis) { /* expects XYZ */ | |
2570 rotate_m4(cache->symm_rot_mat, axis, angle); | |
2571 rotate_m4(cache->symm_rot_mat_inv, axis, -angle); | |
2572 } | |
2573 | |
2574 mul_m4_v3(cache->symm_rot_mat, cache->location); | |
2575 mul_m4_v3(cache->symm_rot_mat, cache->grab_delta_symmetry); | |
2576 } | |
2577 | |
2578 static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, const char
symm, const int axis, const float feather) | |
2579 { | |
2580 SculptSession *ss = ob->sculpt; | |
2581 int i; | |
2582 | |
2583 for(i = 1; i < sd->radial_symm[axis-'X']; ++i) { | |
2584 const float angle = 2*M_PI*i/sd->radial_symm[axis-'X']; | |
2585 ss->cache->radial_symmetry_pass= i; | |
2586 calc_brushdata_symm(sd, ss->cache, symm, axis, angle, feather); | |
2587 do_brush_action(sd, ob, brush); | |
2588 } | |
2589 } | |
2590 | |
2591 /* noise texture gives different values for the same input coord; this | |
2592 can tear a multires mesh during sculpting so do a stitch in this | |
2593 case */ | |
2594 static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob) | |
2595 { | |
2596 SculptSession *ss = ob->sculpt; | |
2597 Brush *brush = paint_brush(&sd->paint); | |
2598 MTex *mtex = &brush->mtex; | |
2599 | |
2600 if(ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) | |
2601 multires_stitch_grids(ob); | |
2602 } | |
2603 | |
2604 static void do_symmetrical_brush_actions(Sculpt *sd, Object *ob) | |
2605 { | |
2606 Brush *brush = paint_brush(&sd->paint); | |
2607 SculptSession *ss = ob->sculpt; | |
2608 StrokeCache *cache = ss->cache; | |
2609 const char symm = sd->flags & 7; | |
2610 int i; | |
2611 | |
2612 float feather = calc_symmetry_feather(sd, ss->cache); | |
2613 | |
2614 cache->bstrength= brush_strength(sd, cache, feather); | |
2615 | |
2616 cache->symmetry= symm; | |
2617 | |
2618 /* symm is a bit combination of XYZ - 1 is mirror X; 2 is Y; 3 is XY; 4
is Z; 5 is XZ; 6 is YZ; 7 is XYZ */· | |
2619 for(i = 0; i <= symm; ++i) { | |
2620 if(i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 ||
(i != 3 && i != 5)))) { | |
2621 cache->mirror_symmetry_pass= i; | |
2622 cache->radial_symmetry_pass= 0; | |
2623 | |
2624 calc_brushdata_symm(sd, cache, i, 0, 0, feather); | |
2625 do_brush_action(sd, ob, brush); | |
2626 | |
2627 do_radial_symmetry(sd, ob, brush, i, 'X', feather); | |
2628 do_radial_symmetry(sd, ob, brush, i, 'Y', feather); | |
2629 do_radial_symmetry(sd, ob, brush, i, 'Z', feather); | |
2630 } | |
2631 } | |
2632 | |
2633 sculpt_combine_proxies(sd, ob); | |
2634 | |
2635 /* hack to fix noise texture tearing mesh */ | |
2636 sculpt_fix_noise_tear(sd, ob); | |
2637 | |
2638 if (ss->modifiers_active) | |
2639 sculpt_flush_stroke_deform(sd, ob); | |
2640 | |
2641 cache->first_time= 0; | |
2642 } | |
2643 | |
2644 static void sculpt_update_tex(Sculpt *sd, SculptSession *ss) | |
2645 { | |
2646 Brush *brush = paint_brush(&sd->paint); | |
2647 const int radius= brush_size(brush); | |
2648 | |
2649 if(ss->texcache) { | |
2650 MEM_freeN(ss->texcache); | |
2651 ss->texcache= NULL; | |
2652 } | |
2653 | |
2654 /* Need to allocate a bigger buffer for bigger brush size */ | |
2655 ss->texcache_side = 2*radius; | |
2656 if(!ss->texcache || ss->texcache_side > ss->texcache_actual) { | |
2657 ss->texcache = brush_gen_texture_cache(brush, radius); | |
2658 ss->texcache_actual = ss->texcache_side; | |
2659 } | |
2660 } | |
2661 | |
2662 void sculpt_free_deformMats(SculptSession *ss) | |
2663 { | |
2664 if(ss->orig_cos) MEM_freeN(ss->orig_cos); | |
2665 if(ss->deform_cos) MEM_freeN(ss->deform_cos); | |
2666 if(ss->deform_imats) MEM_freeN(ss->deform_imats); | |
2667 | |
2668 ss->orig_cos = NULL; | |
2669 ss->deform_cos = NULL; | |
2670 ss->deform_imats = NULL; | |
2671 } | |
2672 | |
2673 void sculpt_update_mesh_elements(Scene *scene, Object *ob, int need_fmap) | |
2674 { | |
2675 DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); | |
2676 SculptSession *ss = ob->sculpt; | |
2677 MultiresModifierData *mmd= sculpt_multires_active(scene, ob); | |
2678 | |
2679 ss->modifiers_active= sculpt_modifiers_active(scene, ob); | |
2680 | |
2681 if((ob->shapeflag & OB_SHAPE_LOCK) && !mmd) ss->kb= ob_get_keyblock(ob); | |
2682 else ss->kb= NULL; | |
2683 | |
2684 if(mmd) { | |
2685 ss->multires = mmd; | |
2686 ss->totvert = dm->getNumVerts(dm); | |
2687 ss->totface = dm->getNumFaces(dm); | |
2688 ss->mvert= NULL; | |
2689 ss->mface= NULL; | |
2690 ss->face_normals= NULL; | |
2691 } | |
2692 else { | |
2693 Mesh *me = get_mesh(ob); | |
2694 ss->totvert = me->totvert; | |
2695 ss->totface = me->totface; | |
2696 ss->mvert = me->mvert; | |
2697 ss->mface = me->mface; | |
2698 ss->face_normals = NULL; | |
2699 ss->multires = NULL; | |
2700 } | |
2701 | |
2702 ss->pbvh = dm->getPBVH(ob, dm); | |
2703 ss->fmap = (need_fmap && dm->getFaceMap)? dm->getFaceMap(ob, dm): NULL; | |
2704 | |
2705 if(ss->modifiers_active) { | |
2706 if(!ss->orig_cos) { | |
2707 int a; | |
2708 | |
2709 sculpt_free_deformMats(ss); | |
2710 | |
2711 if(ss->kb) ss->orig_cos = key_to_vertcos(ob, ss->kb); | |
2712 else ss->orig_cos = mesh_getVertexCos(ob->data, NULL); | |
2713 | |
2714 crazyspace_build_sculpt(scene, ob, &ss->deform_imats, &s
s->deform_cos); | |
2715 BLI_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos); | |
2716 | |
2717 for(a = 0; a < ((Mesh*)ob->data)->totvert; ++a) | |
2718 invert_m3(ss->deform_imats[a]); | |
2719 } | |
2720 } else sculpt_free_deformMats(ss); | |
2721 | |
2722 /* if pbvh is deformed, key block is already applied to it */ | |
2723 if (ss->kb && !BLI_pbvh_isDeformed(ss->pbvh)) { | |
2724 float (*vertCos)[3]= key_to_vertcos(ob, ss->kb); | |
2725 | |
2726 if (vertCos) { | |
2727 /* apply shape keys coordinates to PBVH */ | |
2728 BLI_pbvh_apply_vertCos(ss->pbvh, vertCos); | |
2729 MEM_freeN(vertCos); | |
2730 } | |
2731 } | |
2732 } | |
2733 | |
2734 static int sculpt_mode_poll(bContext *C) | |
2735 { | |
2736 Object *ob = CTX_data_active_object(C); | |
2737 return ob && ob->mode & OB_MODE_SCULPT; | |
2738 } | |
2739 | |
2740 int sculpt_poll(bContext *C) | |
2741 { | |
2742 return sculpt_mode_poll(C) && paint_poll(C); | |
2743 } | |
2744 | |
2745 static const char *sculpt_tool_name(Sculpt *sd) | |
2746 { | |
2747 Brush *brush = paint_brush(&sd->paint); | |
2748 | |
2749 switch(brush->sculpt_tool) { | |
2750 case SCULPT_TOOL_DRAW: | |
2751 return "Draw Brush"; break; | |
2752 case SCULPT_TOOL_SMOOTH: | |
2753 return "Smooth Brush"; break; | |
2754 case SCULPT_TOOL_CREASE: | |
2755 return "Crease Brush"; break; | |
2756 case SCULPT_TOOL_BLOB: | |
2757 return "Blob Brush"; break; | |
2758 case SCULPT_TOOL_PINCH: | |
2759 return "Pinch Brush"; break; | |
2760 case SCULPT_TOOL_INFLATE: | |
2761 return "Inflate Brush"; break; | |
2762 case SCULPT_TOOL_GRAB: | |
2763 return "Grab Brush"; break; | |
2764 case SCULPT_TOOL_NUDGE: | |
2765 return "Nudge Brush"; break; | |
2766 case SCULPT_TOOL_THUMB: | |
2767 return "Thumb Brush"; break; | |
2768 case SCULPT_TOOL_LAYER: | |
2769 return "Layer Brush"; break; | |
2770 case SCULPT_TOOL_FLATTEN: | |
2771 return "Flatten Brush"; break; | |
2772 case SCULPT_TOOL_CLAY: | |
2773 return "Clay Brush"; break; | |
2774 case SCULPT_TOOL_CLAY_TUBES: | |
2775 return "Clay Tubes Brush"; break; | |
2776 case SCULPT_TOOL_FILL: | |
2777 return "Fill Brush"; break; | |
2778 case SCULPT_TOOL_SCRAPE: | |
2779 return "Scrape Brush"; break; | |
2780 default: | |
2781 return "Sculpting"; break; | |
2782 } | |
2783 } | 2842 } |
2784 | 2843 |
2785 /**** Operator for applying a stroke (various attributes including mouse path) | 2844 /**** Operator for applying a stroke (various attributes including mouse path) |
2786 using the current brush. ****/ | 2845 using the current brush. ****/ |
2787 | 2846 |
2788 static void sculpt_cache_free(StrokeCache *cache) | |
2789 { | |
2790 if(cache->face_norms) | |
2791 MEM_freeN(cache->face_norms); | |
2792 if(cache->mats) | |
2793 MEM_freeN(cache->mats); | |
2794 MEM_freeN(cache); | |
2795 } | |
2796 | |
2797 /* Initialize mirror modifier clipping */ | |
2798 static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss) | |
2799 { | |
2800 ModifierData *md; | |
2801 int i; | |
2802 | |
2803 for(md= ob->modifiers.first; md; md= md->next) { | |
2804 if(md->type==eModifierType_Mirror && | |
2805 (md->mode & eModifierMode_Realtime)) { | |
2806 MirrorModifierData *mmd = (MirrorModifierData*)md; | |
2807 ························ | |
2808 if(mmd->flag & MOD_MIR_CLIPPING) { | |
2809 /* check each axis for mirroring */ | |
2810 for(i = 0; i < 3; ++i) { | |
2811 if(mmd->flag & (MOD_MIR_AXIS_X << i)) { | |
2812 /* enable sculpt clipping */ | |
2813 ss->cache->flag |= CLIP_X << i; | |
2814 ················································ | |
2815 /* update the clip tolerance */ | |
2816 if(mmd->tolerance > | |
2817 ss->cache->clip_tolerance[i]) | |
2818 ss->cache->clip_toleranc
e[i] = | |
2819 mmd->tolerance; | |
2820 } | |
2821 } | |
2822 } | |
2823 } | |
2824 } | |
2825 } | |
2826 | |
2827 /* Initialize the stroke cache invariants from operator properties */ | |
2828 static void sculpt_update_cache_invariants(bContext* C, Sculpt *sd, SculptSessio
n *ss, wmOperator *op, wmEvent *event) | |
2829 { | |
2830 StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache"); | |
2831 Brush *brush = paint_brush(&sd->paint); | |
2832 ViewContext *vc = paint_stroke_view_context(op->customdata); | |
2833 Object *ob= CTX_data_active_object(C); | |
2834 int i; | |
2835 int mode; | |
2836 | |
2837 ss->cache = cache; | |
2838 | |
2839 /* Set scaling adjustment */ | |
2840 ss->cache->scale[0] = 1.0f / ob->size[0]; | |
2841 ss->cache->scale[1] = 1.0f / ob->size[1]; | |
2842 ss->cache->scale[2] = 1.0f / ob->size[2]; | |
2843 | |
2844 ss->cache->plane_trim_squared = brush->plane_trim * brush->plane_trim; | |
2845 | |
2846 ss->cache->flag = 0; | |
2847 | |
2848 sculpt_init_mirror_clipping(ob, ss); | |
2849 | |
2850 /* Initial mouse location */ | |
2851 if (event) { | |
2852 ss->cache->initial_mouse[0] = event->x; | |
2853 ss->cache->initial_mouse[1] = event->y; | |
2854 } | |
2855 else { | |
2856 ss->cache->initial_mouse[0] = 0; | |
2857 ss->cache->initial_mouse[1] = 0; | |
2858 } | |
2859 | |
2860 mode = RNA_enum_get(op->ptr, "mode"); | |
2861 cache->invert = mode == BRUSH_STROKE_INVERT; | |
2862 cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH; | |
2863 | |
2864 /* not very nice, but with current events system implementation | |
2865 we can't handle brush appearance inversion hotkey separately (sergey)
*/ | |
2866 if(cache->invert) brush->flag |= BRUSH_INVERTED; | |
2867 else brush->flag &= ~BRUSH_INVERTED; | |
2868 | |
2869 /* Alt-Smooth */ | |
2870 if (ss->cache->alt_smooth) { | |
2871 Paint *p= &sd->paint; | |
2872 Brush *br; | |
2873 ················ | |
2874 BLI_strncpy(cache->saved_active_brush_name, brush->id.name+2, si
zeof(cache->saved_active_brush_name)); | |
2875 | |
2876 br= (Brush *)find_id("BR", "Smooth"); | |
2877 if(br) { | |
2878 paint_brush_set(p, br); | |
2879 brush = br; | |
2880 } | |
2881 } | |
2882 | |
2883 copy_v2_v2(cache->mouse, cache->initial_mouse); | |
2884 copy_v2_v2(cache->tex_mouse, cache->initial_mouse); | |
2885 | |
2886 /* Truly temporary data that isn't stored in properties */ | |
2887 | |
2888 cache->vc = vc; | |
2889 | |
2890 cache->brush = brush; | |
2891 | |
2892 cache->mats = MEM_callocN(sizeof(bglMats), "sculpt bglMats"); | |
2893 view3d_get_transformation(vc->ar, vc->rv3d, vc->obact, cache->mats); | |
2894 | |
2895 viewvector(cache->vc->rv3d, cache->vc->rv3d->twmat[3], cache->true_view_
normal); | |
2896 /* Initialize layer brush displacements and persistent coords */ | |
2897 if(brush->sculpt_tool == SCULPT_TOOL_LAYER) { | |
2898 /* not supported yet for multires */ | |
2899 if(!ss->multires && !ss->layer_co && (brush->flag & BRUSH_PERSIS
TENT)) { | |
2900 if(!ss->layer_co) | |
2901 ss->layer_co= MEM_mallocN(sizeof(float) * 3 * ss
->totvert, | |
2902 "scul
pt mesh vertices copy"); | |
2903 | |
2904 if(ss->deform_cos) memcpy(ss->layer_co, ss->deform_cos,
ss->totvert); | |
2905 else { | |
2906 for(i = 0; i < ss->totvert; ++i) { | |
2907 copy_v3_v3(ss->layer_co[i], ss->mvert[i]
.co); | |
2908 } | |
2909 } | |
2910 } | |
2911 } | |
2912 | |
2913 /* Make copies of the mesh vertex locations and normals for some tools *
/ | |
2914 if(brush->flag & BRUSH_ANCHORED) { | |
2915 if(ss->face_normals) { | |
2916 float *fn = ss->face_normals; | |
2917 cache->face_norms= MEM_mallocN(sizeof(float) * 3 * ss->t
otface, "Sculpt face norms"); | |
2918 for(i = 0; i < ss->totface; ++i, fn += 3) | |
2919 copy_v3_v3(cache->face_norms[i], fn); | |
2920 } | |
2921 | |
2922 cache->original = 1; | |
2923 } | |
2924 | |
2925 if(ELEM8(brush->sculpt_tool, SCULPT_TOOL_DRAW, SCULPT_TOOL_CREASE, SCUL
PT_TOOL_BLOB, SCULPT_TOOL_LAYER, SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY, SCULPT_T
OOL_CLAY_TUBES, SCULPT_TOOL_ROTATE)) | |
2926 if(!(brush->flag & BRUSH_ACCUMULATE)) | |
2927 cache->original = 1; | |
2928 | |
2929 cache->special_rotation = (brush->flag & BRUSH_RAKE) ? sd->last_angle :
0; | |
2930 //cache->last_rake[0] = sd->last_x; | |
2931 //cache->last_rake[1] = sd->last_y; | |
2932 | |
2933 cache->first_time= 1; | |
2934 | |
2935 cache->vertex_rotation= 0; | |
2936 } | |
2937 | |
2938 static void sculpt_update_brush_delta(Sculpt *sd, Object *ob, Brush *brush) | |
2939 { | |
2940 SculptSession *ss = ob->sculpt; | |
2941 StrokeCache *cache = ss->cache; | |
2942 int tool = brush->sculpt_tool; | |
2943 | |
2944 if(ELEM5(tool, | |
2945 SCULPT_TOOL_GRAB, SCULPT_TOOL_NUDGE, | |
2946 SCULPT_TOOL_CLAY_TUBES, SCULPT_TOOL_SNAKE_HOOK, | |
2947 SCULPT_TOOL_THUMB)) { | |
2948 float grab_location[3], imat[4][4], delta[3]; | |
2949 | |
2950 if(cache->first_time) { | |
2951 copy_v3_v3(cache->orig_grab_location, | |
2952 cache->true_location); | |
2953 } | |
2954 else if(tool == SCULPT_TOOL_SNAKE_HOOK) | |
2955 add_v3_v3(cache->true_location, cache->grab_delta); | |
2956 | |
2957 /* compute 3d coordinate at same z from original location + mous
e */ | |
2958 initgrabz(cache->vc->rv3d, | |
2959 cache->orig_grab_location[0], | |
2960 cache->orig_grab_location[1], | |
2961 cache->orig_grab_location[2]); | |
2962 | |
2963 window_to_3d_delta(cache->vc->ar, grab_location, | |
2964 cache->mouse[0], cache->mouse[1]); | |
2965 | |
2966 /* compute delta to move verts by */ | |
2967 if(!cache->first_time) { | |
2968 switch(tool) { | |
2969 case SCULPT_TOOL_GRAB: | |
2970 case SCULPT_TOOL_THUMB: | |
2971 sub_v3_v3v3(delta, grab_location, cache->old_gra
b_location); | |
2972 invert_m4_m4(imat, ob->obmat); | |
2973 mul_mat3_m4_v3(imat, delta); | |
2974 add_v3_v3(cache->grab_delta, delta); | |
2975 break; | |
2976 case SCULPT_TOOL_CLAY_TUBES: | |
2977 case SCULPT_TOOL_NUDGE: | |
2978 sub_v3_v3v3(cache->grab_delta, grab_location, ca
che->old_grab_location); | |
2979 invert_m4_m4(imat, ob->obmat); | |
2980 mul_mat3_m4_v3(imat, cache->grab_delta); | |
2981 break; | |
2982 case SCULPT_TOOL_SNAKE_HOOK: | |
2983 sub_v3_v3v3(cache->grab_delta, grab_location, ca
che->old_grab_location); | |
2984 invert_m4_m4(imat, ob->obmat); | |
2985 mul_mat3_m4_v3(imat, cache->grab_delta); | |
2986 break; | |
2987 } | |
2988 } | |
2989 else { | |
2990 zero_v3(cache->grab_delta); | |
2991 } | |
2992 | |
2993 copy_v3_v3(cache->old_grab_location, grab_location); | |
2994 | |
2995 if(tool == SCULPT_TOOL_GRAB) | |
2996 copy_v3_v3(sd->anchored_location, cache->true_location); | |
2997 else if(tool == SCULPT_TOOL_THUMB) | |
2998 copy_v3_v3(sd->anchored_location, cache->orig_grab_locat
ion);··················· | |
2999 | |
3000 if(ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) { | |
3001 /* location stays the same for finding vertices in brush
radius */ | |
3002 copy_v3_v3(cache->true_location, cache->orig_grab_locati
on); | |
3003 | |
3004 sd->draw_anchored = 1; | |
3005 copy_v3_v3(sd->anchored_initial_mouse, cache->initial_mo
use); | |
3006 sd->anchored_size = cache->pixel_radius; | |
3007 } | |
3008 } | |
3009 } | |
3010 | |
3011 /* Initialize the stroke cache variants from operator properties */ | |
3012 static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, st
ruct PaintStroke *stroke, PointerRNA *ptr) | |
3013 { | |
3014 SculptSession *ss = ob->sculpt; | |
3015 StrokeCache *cache = ss->cache; | |
3016 Brush *brush = paint_brush(&sd->paint); | |
3017 | |
3018 int dx, dy; | |
3019 | |
3020 //RNA_float_get_array(ptr, "location", cache->traced_location); | |
3021 | |
3022 if (cache->first_time || | |
3023 !((brush->flag & BRUSH_ANCHORED)|| | |
3024 (brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK)|| | |
3025 (brush->sculpt_tool == SCULPT_TOOL_ROTATE)) | |
3026 ) | |
3027 { | |
3028 RNA_float_get_array(ptr, "location", cache->true_location); | |
3029 } | |
3030 | |
3031 cache->pen_flip = RNA_boolean_get(ptr, "pen_flip"); | |
3032 RNA_float_get_array(ptr, "mouse", cache->mouse); | |
3033 | |
3034 /* XXX: Use preassure value from first brush step for brushes which don'
t | |
3035 support strokes (grab, thumb). They depends on initial state and | |
3036 brush coord/pressure/etc. | |
3037 It's more an events design issue, which doesn't split coordinate
/pressure/angle | |
3038 changing events. We should avoid this after events system re-des
ign */ | |
3039 if(paint_space_stroke_enabled(brush) || cache->first_time) | |
3040 cache->pressure = RNA_float_get(ptr, "pressure"); | |
3041 | |
3042 /* Truly temporary data that isn't stored in properties */ | |
3043 | |
3044 sd->draw_pressure= 1; | |
3045 sd->pressure_value= cache->pressure; | |
3046 | |
3047 cache->previous_pixel_radius = cache->pixel_radius; | |
3048 cache->pixel_radius = brush_size(brush); | |
3049 | |
3050 if(cache->first_time) { | |
3051 if (!brush_use_locked_size(brush)) { | |
3052 cache->initial_radius= paint_calc_object_space_radius(ca
che->vc, cache->true_location, brush_size(brush)); | |
3053 brush_set_unprojected_radius(brush, cache->initial_radiu
s); | |
3054 } | |
3055 else { | |
3056 cache->initial_radius= brush_unprojected_radius(brush); | |
3057 } | |
3058 | |
3059 if (ELEM(brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE
_HOOK)) | |
3060 cache->initial_radius *= 2.0f; | |
3061 } | |
3062 | |
3063 if(brush_use_size_pressure(brush)) { | |
3064 cache->pixel_radius *= cache->pressure; | |
3065 cache->radius= cache->initial_radius * cache->pressure; | |
3066 } | |
3067 else | |
3068 cache->radius= cache->initial_radius; | |
3069 | |
3070 cache->radius_squared = cache->radius*cache->radius; | |
3071 | |
3072 if(!(brush->flag & BRUSH_ANCHORED || ELEM4(brush->sculpt_tool, SCULPT_TO
OL_GRAB, SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB, SCULPT_TOOL_ROTATE))) { | |
3073 copy_v2_v2(cache->tex_mouse, cache->mouse); | |
3074 | |
3075 if ( (brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) && | |
3076 (brush->flag & BRUSH_RANDOM_ROTATION) && | |
3077 !(brush->flag & BRUSH_RAKE)) | |
3078 { | |
3079 cache->special_rotation = 2.0f*(float)M_PI*BLI_frand(); | |
3080 } | |
3081 } | |
3082 | |
3083 if(brush->flag & BRUSH_ANCHORED) { | |
3084 int hit = 0; | |
3085 | |
3086 dx = cache->mouse[0] - cache->initial_mouse[0]; | |
3087 dy = cache->mouse[1] - cache->initial_mouse[1]; | |
3088 | |
3089 sd->anchored_size = cache->pixel_radius = sqrt(dx*dx + dy*dy); | |
3090 | |
3091 cache->special_rotation = atan2(dx, dy) + M_PI; | |
3092 | |
3093 if (brush->flag & BRUSH_EDGE_TO_EDGE) { | |
3094 float halfway[2]; | |
3095 float out[3]; | |
3096 | |
3097 halfway[0] = (float)dx * 0.5f + cache->initial_mouse[0]; | |
3098 halfway[1] = (float)dy * 0.5f + cache->initial_mouse[1]; | |
3099 | |
3100 if (sculpt_stroke_get_location(C, stroke, out, halfway))
{ | |
3101 copy_v3_v3(sd->anchored_location, out); | |
3102 copy_v2_v2(sd->anchored_initial_mouse, halfway); | |
3103 copy_v2_v2(cache->tex_mouse, halfway); | |
3104 copy_v3_v3(cache->true_location, sd->anchored_lo
cation); | |
3105 sd->anchored_size /= 2.0f; | |
3106 cache->pixel_radius /= 2.0f; | |
3107 hit = 1; | |
3108 } | |
3109 } | |
3110 | |
3111 if (!hit) | |
3112 copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mo
use); | |
3113 | |
3114 cache->radius= paint_calc_object_space_radius(paint_stroke_view_
context(stroke), cache->true_location, cache->pixel_radius); | |
3115 cache->radius_squared = cache->radius*cache->radius; | |
3116 | |
3117 copy_v3_v3(sd->anchored_location, cache->true_location); | |
3118 | |
3119 sd->draw_anchored = 1; | |
3120 } | |
3121 else if(brush->flag & BRUSH_RAKE) { | |
3122 const float u = 0.5f; | |
3123 const float v = 1 - u; | |
3124 const float r = 20; | |
3125 | |
3126 const float dx = cache->last_rake[0] - cache->mouse[0]; | |
3127 const float dy = cache->last_rake[1] - cache->mouse[1]; | |
3128 | |
3129 if (cache->first_time) { | |
3130 copy_v2_v2(cache->last_rake, cache->mouse); | |
3131 } | |
3132 else if (dx*dx + dy*dy >= r*r) { | |
3133 cache->special_rotation = atan2(dx, dy); | |
3134 | |
3135 cache->last_rake[0] = u*cache->last_rake[0] + v*cache->m
ouse[0]; | |
3136 cache->last_rake[1] = u*cache->last_rake[1] + v*cache->m
ouse[1]; | |
3137 } | |
3138 } | |
3139 | |
3140 sculpt_update_brush_delta(sd, ob, brush); | |
3141 | |
3142 if(brush->sculpt_tool == SCULPT_TOOL_ROTATE) { | |
3143 dx = cache->mouse[0] - cache->initial_mouse[0]; | |
3144 dy = cache->mouse[1] - cache->initial_mouse[1]; | |
3145 | |
3146 cache->vertex_rotation = -atan2(dx, dy); | |
3147 | |
3148 sd->draw_anchored = 1; | |
3149 copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse); | |
3150 copy_v3_v3(sd->anchored_location, cache->true_location); | |
3151 sd->anchored_size = cache->pixel_radius; | |
3152 } | |
3153 | |
3154 sd->special_rotation = cache->special_rotation; | |
3155 } | |
3156 | |
3157 static void sculpt_stroke_modifiers_check(bContext *C, Object *ob) | |
3158 { | |
3159 SculptSession *ss = ob->sculpt; | |
3160 | |
3161 if(ss->modifiers_active) { | |
3162 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3163 Brush *brush = paint_brush(&sd->paint); | |
3164 | |
3165 sculpt_update_mesh_elements(CTX_data_scene(C), ob, brush->sculpt
_tool == SCULPT_TOOL_SMOOTH); | |
3166 } | |
3167 } | |
3168 | |
3169 typedef struct { | |
3170 SculptSession *ss; | |
3171 float *ray_start, *ray_normal; | |
3172 int hit; | |
3173 float dist; | |
3174 int original; | |
3175 } SculptRaycastData; | |
3176 | |
3177 static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float* tmin) | |
3178 { | |
3179 if (BLI_pbvh_node_get_tmin(node) < *tmin) { | |
3180 SculptRaycastData *srd = data_v; | |
3181 float (*origco)[3]= NULL; | |
3182 | |
3183 if(srd->original && srd->ss->cache) { | |
3184 /* intersect with coordinates from before we started str
oke */ | |
3185 SculptUndoNode *unode= sculpt_undo_get_node(node); | |
3186 origco= (unode)? unode->co: NULL; | |
3187 } | |
3188 | |
3189 if (BLI_pbvh_node_raycast(srd->ss->pbvh, node, origco, srd->ray_
start, srd->ray_normal, &srd->dist)) { | |
3190 srd->hit = 1; | |
3191 *tmin = srd->dist; | |
3192 } | |
3193 } | |
3194 } | |
3195 | |
3196 /* Do a raycast in the tree to find the 3d brush location | |
3197 (This allows us to ignore the GL depth buffer) | |
3198 Returns 0 if the ray doesn't hit the mesh, non-zero otherwise | |
3199 */ | |
3200 int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
t[3], float mouse[2]) | |
3201 { | |
3202 ViewContext *vc = paint_stroke_view_context(stroke); | |
3203 Object *ob = vc->obact; | |
3204 SculptSession *ss= ob->sculpt; | |
3205 StrokeCache *cache= ss->cache; | |
3206 float ray_start[3], ray_end[3], ray_normal[3], dist; | |
3207 float obimat[4][4]; | |
3208 float mval[2]; | |
3209 SculptRaycastData srd; | |
3210 | |
3211 mval[0] = mouse[0] - vc->ar->winrct.xmin; | |
3212 mval[1] = mouse[1] - vc->ar->winrct.ymin; | |
3213 | |
3214 sculpt_stroke_modifiers_check(C, ob); | |
3215 | |
3216 viewline(vc->ar, vc->v3d, mval, ray_start, ray_end); | |
3217 | |
3218 invert_m4_m4(obimat, ob->obmat); | |
3219 mul_m4_v3(obimat, ray_start); | |
3220 mul_m4_v3(obimat, ray_end); | |
3221 | |
3222 sub_v3_v3v3(ray_normal, ray_end, ray_start); | |
3223 dist= normalize_v3(ray_normal); | |
3224 | |
3225 srd.ss = vc->obact->sculpt; | |
3226 srd.ray_start = ray_start; | |
3227 srd.ray_normal = ray_normal; | |
3228 srd.dist = dist; | |
3229 srd.hit = 0; | |
3230 srd.original = (cache)? cache->original: 0; | |
3231 BLI_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, | |
3232 ray_start, ray_normal, srd.original); | |
3233 ········ | |
3234 copy_v3_v3(out, ray_normal); | |
3235 mul_v3_fl(out, srd.dist); | |
3236 add_v3_v3(out, ray_start); | |
3237 | |
3238 return srd.hit; | |
3239 } | |
3240 | |
3241 static void sculpt_brush_init_tex(Sculpt *sd, SculptSession *ss) | |
3242 { | |
3243 Brush *brush = paint_brush(&sd->paint); | |
3244 MTex *mtex= &brush->mtex; | |
3245 | |
3246 /* init mtex nodes */ | |
3247 if(mtex->tex && mtex->tex->nodetree) | |
3248 ntreeBeginExecTree(mtex->tex->nodetree); /* has internal flag to
detect it only does it once */ | |
3249 | |
3250 /* TODO: Shouldn't really have to do this at the start of every | |
3251 stroke, but sculpt would need some sort of notification when | |
3252 changes are made to the texture. */ | |
3253 sculpt_update_tex(sd, ss); | |
3254 } | |
3255 | |
3256 static int sculpt_brush_stroke_init(bContext *C, ReportList *reports) | |
3257 { | |
3258 Scene *scene= CTX_data_scene(C); | |
3259 Object *ob= CTX_data_active_object(C); | |
3260 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3261 SculptSession *ss = CTX_data_active_object(C)->sculpt; | |
3262 Brush *brush = paint_brush(&sd->paint); | |
3263 | |
3264 if(ob_get_key(ob) && !(ob->shapeflag & OB_SHAPE_LOCK)) { | |
3265 BKE_report(reports, RPT_ERROR, "Shape key sculpting requires a l
ocked shape."); | |
3266 return 0; | |
3267 } | |
3268 | |
3269 view3d_operator_needs_opengl(C); | |
3270 sculpt_brush_init_tex(sd, ss); | |
3271 | |
3272 sculpt_update_mesh_elements(scene, ob, brush->sculpt_tool == SCULPT_TOOL
_SMOOTH); | |
3273 | |
3274 return 1; | |
3275 } | |
3276 | |
3277 static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss) | |
3278 { | |
3279 Brush *brush = paint_brush(&sd->paint); | |
3280 | |
3281 /* Restore the mesh before continuing with anchored stroke */ | |
3282 if((brush->flag & BRUSH_ANCHORED) || | |
3283 (brush->sculpt_tool == SCULPT_TOOL_GRAB && brush_use_size_pressure(br
ush)) || | |
3284 (brush->flag & BRUSH_RESTORE_MESH)) | |
3285 { | |
3286 StrokeCache *cache = ss->cache; | |
3287 int i; | |
3288 | |
3289 PBVHNode **nodes; | |
3290 int n, totnode; | |
3291 | |
3292 BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); | |
3293 | |
3294 #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT
_USE_OPENMP) | |
3295 for(n=0; n<totnode; n++) { | |
3296 SculptUndoNode *unode; | |
3297 ························ | |
3298 unode= sculpt_undo_get_node(nodes[n]); | |
3299 if(unode) { | |
3300 PBVHVertexIter vd; | |
3301 | |
3302 BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], v
d, PBVH_ITER_UNIQUE) { | |
3303 copy_v3_v3(vd.co, unode->co[vd.i]); | |
3304 if(vd.no) VECCOPY(vd.no, unode->no[vd.i]
) | |
3305 else normal_short_to_float_v3(vd.fno, un
ode->no[vd.i]); | |
3306 | |
3307 if(vd.mvert) vd.mvert->flag |= ME_VERT_P
BVH_UPDATE; | |
3308 } | |
3309 BLI_pbvh_vertex_iter_end; | |
3310 | |
3311 BLI_pbvh_node_mark_update(nodes[n]); | |
3312 } | |
3313 } | |
3314 | |
3315 if(ss->face_normals) { | |
3316 float *fn = ss->face_normals; | |
3317 for(i = 0; i < ss->totface; ++i, fn += 3) | |
3318 copy_v3_v3(fn, cache->face_norms[i]); | |
3319 } | |
3320 | |
3321 if(nodes) | |
3322 MEM_freeN(nodes); | |
3323 } | |
3324 } | |
3325 | |
3326 static void sculpt_flush_update(bContext *C) | |
3327 { | |
3328 Object *ob = CTX_data_active_object(C); | |
3329 SculptSession *ss = ob->sculpt; | |
3330 ARegion *ar = CTX_wm_region(C); | |
3331 MultiresModifierData *mmd = ss->multires; | |
3332 | |
3333 if(mmd) | |
3334 multires_mark_as_modified(ob); | |
3335 if(ob->derivedFinal) /* VBO no longer valid */ | |
3336 GPU_drawobject_free(ob->derivedFinal); | |
3337 | |
3338 if(ss->modifiers_active) { | |
3339 DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | |
3340 ED_region_tag_redraw(ar); | |
3341 } | |
3342 else { | |
3343 rcti r; | |
3344 | |
3345 BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB, NULL); | |
3346 if (sculpt_get_redraw_rect(ar, CTX_wm_region_view3d(C), ob, &r))
{ | |
3347 //rcti tmp; | |
3348 | |
3349 r.xmin += ar->winrct.xmin + 1; | |
3350 r.xmax += ar->winrct.xmin - 1; | |
3351 r.ymin += ar->winrct.ymin + 1; | |
3352 r.ymax += ar->winrct.ymin - 1; | |
3353 | |
3354 //tmp = r; | |
3355 | |
3356 //if (!BLI_rcti_is_empty(&ss->previous_r)) | |
3357 // BLI_union_rcti(&r, &ss->previous_r); | |
3358 | |
3359 //ss->previous_r= tmp; | |
3360 | |
3361 ss->partial_redraw = 1; | |
3362 ED_region_tag_redraw_partial(ar, &r); | |
3363 } | |
3364 } | |
3365 } | |
3366 | |
3367 /* Returns whether the mouse/stylus is over the mesh (1) | |
3368 or over the background (0) */ | |
3369 static int over_mesh(bContext *C, struct wmOperator *op, float x, float y) | |
3370 { | |
3371 float mouse[2], co[3]; | |
3372 | |
3373 mouse[0] = x; | |
3374 mouse[1] = y; | |
3375 | |
3376 return sculpt_stroke_get_location(C, op->customdata, co, mouse); | |
3377 } | |
3378 | |
3379 static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op, | |
3380 wmEvent *event) | |
3381 { | |
3382 /* Don't start the stroke until mouse goes over the mesh */ | |
3383 if(over_mesh(C, op, event->x, event->y)) { | |
3384 Object *ob = CTX_data_active_object(C); | |
3385 SculptSession *ss = ob->sculpt; | |
3386 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3387 | |
3388 ED_view3d_init_mats_rv3d(ob, CTX_wm_region_view3d(C)); | |
3389 | |
3390 sculpt_update_cache_invariants(C, sd, ss, op, event); | |
3391 | |
3392 sculpt_undo_push_begin(sculpt_tool_name(sd)); | |
3393 | |
3394 #ifdef _OPENMP | |
3395 /* If using OpenMP then create a number of threads two times the | |
3396 number of processor cores. | |
3397 Justification: Empirically I've found that two threads per | |
3398 processor gives higher throughput. */ | |
3399 if (sd->flags & SCULPT_USE_OPENMP) { | |
3400 int num_procs; | |
3401 | |
3402 num_procs = omp_get_num_procs(); | |
3403 omp_set_num_threads(2*num_procs); | |
3404 } | |
3405 #endif | |
3406 | |
3407 return 1; | |
3408 } | |
3409 else | |
3410 return 0; | |
3411 } | |
3412 | |
3413 static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
ointerRNA *itemptr) | |
3414 { | |
3415 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3416 Object *ob = CTX_data_active_object(C); | |
3417 SculptSession *ss = ob->sculpt; | |
3418 ········ | |
3419 sculpt_stroke_modifiers_check(C, ob); | |
3420 sculpt_update_cache_variants(C, sd, ob, stroke, itemptr); | |
3421 sculpt_restore_mesh(sd, ss); | |
3422 do_symmetrical_brush_actions(sd, ob); | |
3423 | |
3424 /* Cleanup */ | |
3425 sculpt_flush_update(C); | |
3426 } | |
3427 | |
3428 static void sculpt_brush_exit_tex(Sculpt *sd) | |
3429 { | |
3430 Brush *brush= paint_brush(&sd->paint); | |
3431 MTex *mtex= &brush->mtex; | |
3432 | |
3433 if(mtex->tex && mtex->tex->nodetree) | |
3434 ntreeEndExecTree(mtex->tex->nodetree); | |
3435 } | |
3436 | |
3437 static void sculpt_stroke_done(bContext *C, struct PaintStroke *unused) | |
3438 { | |
3439 Object *ob= CTX_data_active_object(C); | |
3440 SculptSession *ss = ob->sculpt; | |
3441 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3442 | |
3443 (void)unused; | |
3444 | |
3445 // reset values used to draw brush after completing the stroke | |
3446 sd->draw_anchored= 0; | |
3447 sd->draw_pressure= 0; | |
3448 sd->special_rotation= 0; | |
3449 | |
3450 /* Finished */ | |
3451 if(ss->cache) { | |
3452 Brush *brush= paint_brush(&sd->paint); | |
3453 brush->flag &= ~BRUSH_INVERTED; | |
3454 | |
3455 sculpt_stroke_modifiers_check(C, ob); | |
3456 | |
3457 /* Alt-Smooth */ | |
3458 if (ss->cache->alt_smooth) { | |
3459 Paint *p= &sd->paint; | |
3460 brush= (Brush *)find_id("BR", ss->cache->saved_active_br
ush_name); | |
3461 if(brush) { | |
3462 paint_brush_set(p, brush); | |
3463 } | |
3464 } | |
3465 | |
3466 sculpt_cache_free(ss->cache); | |
3467 ss->cache = NULL; | |
3468 | |
3469 sculpt_undo_push_end(); | |
3470 | |
3471 BLI_pbvh_update(ss->pbvh, PBVH_UpdateOriginalBB, NULL); | |
3472 | |
3473 /* optimization: if there is locked key and active modifiers pre
sent in */ | |
3474 /* the stack, keyblock is updating at each step. otherwise we co
uld update */ | |
3475 /* keyblock only when stroke is finished */ | |
3476 if(ss->kb && !ss->modifiers_active) sculpt_update_keyblock(ob); | |
3477 | |
3478 ss->partial_redraw = 0; | |
3479 | |
3480 /* try to avoid calling this, only for e.g. linked duplicates no
w */ | |
3481 if(((Mesh*)ob->data)->id.us > 1) | |
3482 DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | |
3483 | |
3484 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); | |
3485 } | |
3486 | |
3487 sculpt_brush_exit_tex(sd); | |
3488 } | |
3489 | |
3490 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even
t) | |
3491 { | |
3492 struct PaintStroke *stroke; | |
3493 int ignore_background_click; | |
3494 | |
3495 if(!sculpt_brush_stroke_init(C, op->reports)) | |
3496 return OPERATOR_CANCELLED; | |
3497 | |
3498 stroke = paint_stroke_new(C, sculpt_stroke_get_location, | |
3499 sculpt_stroke_test_start, | |
3500 sculpt_stroke_update_step, | |
3501 sculpt_stroke_done, event->type); | |
3502 | |
3503 op->customdata = stroke; | |
3504 | |
3505 /* For tablet rotation */ | |
3506 ignore_background_click = RNA_boolean_get(op->ptr, | |
3507 "ignore_background_click");· | |
3508 | |
3509 if(ignore_background_click && !over_mesh(C, op, event->x, event->y)) { | |
3510 paint_stroke_free(stroke); | |
3511 return OPERATOR_PASS_THROUGH; | |
3512 } | |
3513 ········ | |
3514 /* add modal handler */ | |
3515 WM_event_add_modal_handler(C, op); | |
3516 | |
3517 op->type->modal(C, op, event); | |
3518 ········ | |
3519 return OPERATOR_RUNNING_MODAL; | |
3520 } | |
3521 | |
3522 static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) | |
3523 { | |
3524 Sculpt *sd = CTX_data_tool_settings(C)->sculpt; | |
3525 SculptSession *ss = CTX_data_active_object(C)->sculpt; | |
3526 | |
3527 if(!sculpt_brush_stroke_init(C, op->reports)) | |
3528 return OPERATOR_CANCELLED; | |
3529 | |
3530 op->customdata = paint_stroke_new(C, sculpt_stroke_get_location, sculpt_
stroke_test_start, | |
3531 sculpt_stroke_update_step, sculpt_stro
ke_done, 0); | |
3532 | |
3533 sculpt_update_cache_invariants(C, sd, ss, op, NULL); | |
3534 | |
3535 paint_stroke_exec(C, op); | |
3536 | |
3537 sculpt_flush_update(C); | |
3538 sculpt_cache_free(ss->cache); | |
3539 | |
3540 return OPERATOR_FINISHED; | |
3541 } | |
3542 | |
3543 static void SCULPT_OT_brush_stroke(wmOperatorType *ot) | |
3544 { | |
3545 static EnumPropertyItem stroke_mode_items[] = { | |
3546 {BRUSH_STROKE_NORMAL, "NORMAL", 0, "Normal", "Apply brush normal
ly"}, | |
3547 {BRUSH_STROKE_INVERT, "INVERT", 0, "Invert", "Invert action of b
rush for duration of stroke"}, | |
3548 {BRUSH_STROKE_SMOOTH, "SMOOTH", 0, "Smooth", "Switch brush to sm
ooth mode for duration of stroke"}, | |
3549 {0} | |
3550 }; | |
3551 | |
3552 /* identifiers */ | |
3553 ot->name= "Sculpt Mode"; | |
3554 ot->idname= "SCULPT_OT_brush_stroke"; | |
3555 ········ | |
3556 /* api callbacks */ | |
3557 ot->invoke= sculpt_brush_stroke_invoke; | |
3558 ot->modal= paint_stroke_modal; | |
3559 ot->exec= sculpt_brush_stroke_exec; | |
3560 ot->poll= sculpt_poll; | |
3561 | |
3562 /* flags (sculpt does own undo? (ton) */ | |
3563 ot->flag= OPTYPE_BLOCKING; | |
3564 | |
3565 /* properties */ | |
3566 | |
3567 RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElemen
t, | |
3568 "Stroke", ""); | |
3569 | |
3570 RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL,· | |
3571 "Sculpt Stroke Mode", | |
3572 "Action taken when a sculpt stroke is made"); | |
3573 | |
3574 RNA_def_boolean(ot->srna, "ignore_background_click", 0, | |
3575 "Ignore Background Click", | |
3576 "Clicks on the background do not start the stroke"); | |
3577 } | |
3578 | |
3579 /**** Reset the copy of the mesh that is being sculpted on (currently just for t
he layer brush) ****/ | |
3580 | |
3581 static int sculpt_set_persistent_base(bContext *C, wmOperator *unused) | |
3582 { | |
3583 SculptSession *ss = CTX_data_active_object(C)->sculpt; | |
3584 | |
3585 (void)unused; | |
3586 | |
3587 if(ss) { | |
3588 if(ss->layer_co) | |
3589 MEM_freeN(ss->layer_co); | |
3590 ss->layer_co = NULL; | |
3591 } | |
3592 | |
3593 return OPERATOR_FINISHED; | |
3594 } | |
3595 | |
3596 static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) | |
3597 { | |
3598 /* identifiers */ | |
3599 ot->name= "Set Persistent Base"; | |
3600 ot->idname= "SCULPT_OT_set_persistent_base"; | |
3601 ········ | |
3602 /* api callbacks */ | |
3603 ot->exec= sculpt_set_persistent_base; | |
3604 ot->poll= sculpt_mode_poll; | |
3605 ········ | |
3606 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | |
3607 } | |
3608 | |
3609 /**** Toggle operator for turning sculpt mode on or off ****/ | |
3610 | |
3611 static void sculpt_init_session(Scene *scene, Object *ob) | |
3612 { | |
3613 ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); | |
3614 | |
3615 sculpt_update_mesh_elements(scene, ob, 0); | |
3616 } | |
3617 | |
3618 static int sculpt_toggle_mode(bContext *C, wmOperator *unused) | |
3619 { | |
3620 Scene *scene = CTX_data_scene(C); | |
3621 ToolSettings *ts = CTX_data_tool_settings(C); | |
3622 Object *ob = CTX_data_active_object(C); | |
3623 MultiresModifierData *mmd= sculpt_multires_active(scene, ob); | |
3624 int flush_recalc= 0; | |
3625 | |
3626 (void)unused; | |
3627 | |
3628 /* multires in sculpt mode could have different from object mode subdivi
sion level */ | |
3629 flush_recalc |= mmd && mmd->sculptlvl != mmd->lvl; | |
3630 /* if object has got active modifiers, it's dm could be different in scu
lpt mode */ | |
3631 flush_recalc |= sculpt_has_active_modifiers(scene, ob); | |
3632 | |
3633 if(ob->mode & OB_MODE_SCULPT) { | |
3634 if(mmd) | |
3635 multires_force_update(ob); | |
3636 | |
3637 if(flush_recalc) | |
3638 DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | |
3639 | |
3640 /* Leave sculptmode */ | |
3641 ob->mode &= ~OB_MODE_SCULPT; | |
3642 | |
3643 free_sculptsession(ob); | |
3644 } | |
3645 else { | |
3646 /* Enter sculptmode */ | |
3647 ob->mode |= OB_MODE_SCULPT; | |
3648 | |
3649 if(flush_recalc) | |
3650 DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | |
3651 ················ | |
3652 /* Create persistent sculpt mode data */ | |
3653 if(!ts->sculpt) { | |
3654 ts->sculpt = MEM_callocN(sizeof(Sculpt), "sculpt mode da
ta"); | |
3655 | |
3656 /* Turn on X plane mirror symmetry by default */ | |
3657 ts->sculpt->flags |= SCULPT_SYMM_X; | |
3658 } | |
3659 | |
3660 /* Create sculpt mode session data */ | |
3661 if(ob->sculpt) | |
3662 free_sculptsession(ob); | |
3663 | |
3664 sculpt_init_session(scene, ob); | |
3665 | |
3666 paint_init(&ts->sculpt->paint, PAINT_CURSOR_SCULPT); | |
3667 ················ | |
3668 paint_cursor_start(C, sculpt_poll); | |
3669 } | |
3670 | |
3671 WM_event_add_notifier(C, NC_SCENE|ND_MODE, CTX_data_scene(C)); | |
3672 | |
3673 return OPERATOR_FINISHED; | |
3674 } | |
3675 | |
3676 static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot) | |
3677 { | |
3678 /* identifiers */ | |
3679 ot->name= "Sculpt Mode"; | |
3680 ot->idname= "SCULPT_OT_sculptmode_toggle"; | |
3681 ········ | |
3682 /* api callbacks */ | |
3683 ot->exec= sculpt_toggle_mode; | |
3684 ot->poll= ED_operator_object_active_editable_mesh; | |
3685 ········ | |
3686 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | |
3687 } | |
3688 | |
3689 void ED_operatortypes_sculpt(void) | |
3690 { | |
3691 WM_operatortype_append(SCULPT_OT_brush_stroke); | |
3692 WM_operatortype_append(SCULPT_OT_sculptmode_toggle); | |
3693 WM_operatortype_append(SCULPT_OT_set_persistent_base); | |
3694 } | |
LEFT | RIGHT |