Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-03-26 02:34:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-03-26 02:34:01 +0400
commitbd65fc176d39f8b083e0dbb7c6fda98de896257d (patch)
tree363e738ad1a47fb574451bd254c642af6cc9de9b /source/blender/editors/sculpt_paint/paint_vertex_proj.c
parent8703e2fe7e97ddad4f7f5bae8e5c801efbf9dddb (diff)
revert 0da3e97, fix for T39279
Following problems: - painting onto a cube asserts immediately (vpaint/wpaint) - crashes with valgrind (bad memory use) - the original intended behavior of vertex projection paint no longer works as I intended. (its constantly refreshing geometry even when no modifiers are applied). Best get code review for these kinds of changes.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_vertex_proj.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_proj.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.c b/source/blender/editors/sculpt_paint/paint_vertex_proj.c
index 1d98c39816e..a04e15d3729 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.c
@@ -52,10 +52,13 @@
/* stored while painting */
struct VertProjHandle {
- VertProjData *data;
+ DMCoNo *vcosnos;
bool use_update;
+ /* use for update */
+ float *dists_sq;
+
Object *ob;
Scene *scene;
};
@@ -77,7 +80,7 @@ static void vpaint_proj_dm_map_cosnos_init__map_cb(void *userData, int index, co
const float no_f[3], const short no_s[3])
{
struct VertProjHandle *vp_handle = userData;
- DMCoNo *co_no = &vp_handle->data->vcosnos[index];
+ DMCoNo *co_no = &vp_handle->vcosnos[index];
/* check if we've been here before (normal should not be 0) */
if (!is_zero_v3(co_no->no)) {
@@ -104,10 +107,11 @@ static void vpaint_proj_dm_map_cosnos_init(Scene *scene, Object *ob,
dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
if (dm->foreachMappedVert) {
+ memset(vp_handle->vcosnos, 0, sizeof(DMCoNo) * me->totvert);
dm->foreachMappedVert(dm, vpaint_proj_dm_map_cosnos_init__map_cb, vp_handle, DM_FOREACH_USE_NORMAL);
}
else {
- DMCoNo *v_co_no = vp_handle->data->vcosnos;
+ DMCoNo *v_co_no = vp_handle->vcosnos;
int a;
for (a = 0; a < me->totvert; a++, v_co_no++) {
dm->getVertCo(dm, a, v_co_no->co);
@@ -124,44 +128,45 @@ static void vpaint_proj_dm_map_cosnos_init(Scene *scene, Object *ob,
/* Same as init but take mouse location into account */
-static void vpaint_proj_dm_map_cosnos_update__map_cb(
- void *userData, int index, const float co[3],
- const float no_f[3], const short no_s[3])
+static void vpaint_proj_dm_map_cosnos_update__map_cb(void *userData, int index, const float co[3],
+ const float no_f[3], const short no_s[3])
{
struct VertProjUpdate *vp_update = userData;
+ struct VertProjHandle *vp_handle = vp_update->vp_handle;
- VertProjData *data = vp_update->vp_handle->data;
- DMCoNo *co_no = &data->vcosnos[index];
-
- /* first find distance to this vertex */
- float co_ss[2]; /* screenspace */
+ DMCoNo *co_no = &vp_handle->vcosnos[index];
- if (ED_view3d_project_float_object(vp_update->ar,
- co, co_ss,
- V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
+ /* find closest vertex */
{
- const float dist_sq = len_squared_v2v2(vp_update->mval_fl, co_ss);
- if (dist_sq > data->dists_sq[index]) {
- /* bail out! */
- return;
+ /* first find distance to this vertex */
+ float co_ss[2]; /* screenspace */
+
+ if (ED_view3d_project_float_object(vp_update->ar,
+ co, co_ss,
+ V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
+ {
+ const float dist_sq = len_squared_v2v2(vp_update->mval_fl, co_ss);
+ if (dist_sq > vp_handle->dists_sq[index]) {
+ /* bail out! */
+ return;
+ }
+
+ vp_handle->dists_sq[index] = dist_sq;
}
+ }
+ /* continue with regular functionality */
- data->dists_sq[index] = dist_sq;
- copy_v2_v2(data->ss_co[index], co_ss);
-
- copy_v3_v3(co_no->co, co);
- if (no_f) {
- copy_v3_v3(co_no->no, no_f);
- }
- else {
- normal_short_to_float_v3(co_no->no, no_s);
- }
+ copy_v3_v3(co_no->co, co);
+ if (no_f) {
+ copy_v3_v3(co_no->no, no_f);
+ }
+ else {
+ normal_short_to_float_v3(co_no->no, no_s);
}
}
-static void vpaint_proj_dm_map_cosnos_update(
- struct VertProjHandle *vp_handle,
- ARegion *ar, const float mval_fl[2])
+static void vpaint_proj_dm_map_cosnos_update(struct VertProjHandle *vp_handle,
+ ARegion *ar, const float mval_fl[2])
{
struct VertProjUpdate vp_update = {vp_handle, ar, mval_fl};
@@ -177,7 +182,7 @@ static void vpaint_proj_dm_map_cosnos_update(
/* highly unlikely this will become unavailable once painting starts (perhaps with animated modifiers) */
if (LIKELY(dm->foreachMappedVert)) {
- fill_vn_fl(vp_handle->data->dists_sq, me->totvert, FLT_MAX);
+ fill_vn_fl(vp_handle->dists_sq, me->totvert, FLT_MAX);
dm->foreachMappedVert(dm, vpaint_proj_dm_map_cosnos_update__map_cb, &vp_update, DM_FOREACH_USE_NORMAL);
}
@@ -189,38 +194,33 @@ static void vpaint_proj_dm_map_cosnos_update(
/* -------------------------------------------------------------------- */
/* Public Functions */
-struct VertProjHandle *ED_vpaint_proj_handle_create(
- Scene *scene, Object *ob,
- VertProjData **r_vcosnos)
+struct VertProjHandle *ED_vpaint_proj_handle_create(Scene *scene, Object *ob,
+ DMCoNo **r_vcosnos)
{
struct VertProjHandle *vp_handle = MEM_mallocN(sizeof(struct VertProjHandle), __func__);
Mesh *me = ob->data;
/* setup the handle */
- vp_handle->data = MEM_mallocN(sizeof(VertProjData), AT);
-
- vp_handle->data->vcosnos = MEM_mallocN(sizeof(DMCoNo) * me->totvert, "vertexcosnos map");
+ vp_handle->vcosnos = MEM_mallocN(sizeof(DMCoNo) * me->totvert, "vertexcosnos map");
vp_handle->use_update = false;
/* sets 'use_update' if needed */
vpaint_proj_dm_map_cosnos_init(scene, ob, vp_handle);
if (vp_handle->use_update) {
- vp_handle->data->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, AT);
- vp_handle->data->ss_co = MEM_mallocN(2 * sizeof(float) * me->totvert, AT);
+ vp_handle->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, __func__);
vp_handle->ob = ob;
vp_handle->scene = scene;
}
else {
- vp_handle->data->dists_sq = NULL;
- vp_handle->data->ss_co = NULL;
+ vp_handle->dists_sq = NULL;
vp_handle->ob = NULL;
vp_handle->scene = NULL;
}
- *r_vcosnos = vp_handle->data;
+ *r_vcosnos = vp_handle->vcosnos;
return vp_handle;
}
@@ -235,11 +235,9 @@ void ED_vpaint_proj_handle_update(struct VertProjHandle *vp_handle,
void ED_vpaint_proj_handle_free(struct VertProjHandle *vp_handle)
{
if (vp_handle->use_update) {
- MEM_freeN(vp_handle->data->dists_sq);
- MEM_freeN(vp_handle->data->ss_co);
+ MEM_freeN(vp_handle->dists_sq);
}
- MEM_freeN(vp_handle->data->vcosnos);
- MEM_freeN(vp_handle->data);
+ MEM_freeN(vp_handle->vcosnos);
MEM_freeN(vp_handle);
}