[Bf-blender-cvs] [5254df3] strand_editmode: Filter affected hair vertices in edit mode based on the brush size and z depth.
Lukas Tönne
noreply at git.blender.org
Mon Apr 20 14:23:33 CEST 2015
Commit: 5254df30ba5af424f21dc49d79ef34f314171b34
Author: Lukas Tönne
Date: Tue Dec 2 18:24:39 2014 +0100
Branches: strand_editmode
https://developer.blender.org/rB5254df30ba5af424f21dc49d79ef34f314171b34
Filter affected hair vertices in edit mode based on the brush size and
z depth.
===================================================================
M source/blender/editors/hair/CMakeLists.txt
M source/blender/editors/hair/hair_edit.c
M source/blender/editors/hair/hair_intern.h
M source/blender/editors/hair/hair_stroke.c
===================================================================
diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index 41c2d42..e131dad 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -25,13 +25,16 @@ set(INC
../../blenkernel
../../blenlib
../../bmesh
+ ../../gpu
../../makesdna
../../makesrna
../../windowmanager
../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
)
set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
)
set(SRC
@@ -42,4 +45,6 @@ set(SRC
hair_intern.h
)
+add_definitions(${GL_DEFINITIONS})
+
blender_add_lib(bf_editor_hair "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index 6b3bff3..1c84d21 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -41,6 +41,7 @@
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
#include "BKE_brush.h"
#include "BKE_cdderivedmesh.h"
@@ -206,6 +207,32 @@ void HAIR_OT_hair_edit_toggle(wmOperatorType *ot)
/* ==== brush stroke ==== */
+static void hair_set_view3d_data(bContext *C, HairToolData *data)
+{
+ View3D *v3d;
+ bool has_zbuf;
+
+ view3d_set_viewcontext(C, &data->vc);
+
+ v3d = data->vc.v3d;
+ has_zbuf = (v3d->drawtype > OB_WIRE) && (v3d->flag & V3D_ZBUF_SELECT);
+
+ view3d_get_transformation(data->vc.ar, data->vc.rv3d, NULL, &data->mats);
+
+ if (has_zbuf) {
+ if (v3d->flag & V3D_INVALID_BACKBUF) {
+ /* needed or else the draw matrix can be incorrect */
+ view3d_operator_needs_opengl(C);
+
+ view3d_validate_backbuf(&data->vc);
+ /* we may need to force an update here by setting the rv3d as dirty
+ * for now it seems ok, but take care!:
+ * rv3d->depths->dirty = 1; */
+ ED_view3d_depth_update(data->vc.ar);
+ }
+ }
+}
+
static int hair_stroke_poll(bContext *C)
{
Object *obact;
@@ -296,6 +323,7 @@ static bool hair_stroke_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
totsteps = 1; // XXX TODO determine brush size for the above
mul_v2_fl(mdelta, 1.0f / (float)totsteps);
+ hair_set_view3d_data(C, &tool_data);
tool_data.scene = scene;
tool_data.ob = ob;
tool_data.edit = edit;
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 4dafd4f..1ade4e8 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -32,6 +32,11 @@
#ifndef __HAIR_INTERN_H__
#define __HAIR_INTERN_H__
+#include "BIF_glutil.h"
+
+#include "ED_view3d.h"
+
+struct ARegion;
struct bContext;
struct wmOperatorType;
@@ -46,6 +51,8 @@ void HAIR_OT_stroke(struct wmOperatorType *ot);
typedef struct HairToolData {
/* context */
+ ViewContext vc;
+ bglMats mats;
struct Scene *scene;
struct Object *ob;
struct BMEditStrands *edit;
diff --git a/source/blender/editors/hair/hair_stroke.c b/source/blender/editors/hair/hair_stroke.c
index 656adb2..9188703 100644
--- a/source/blender/editors/hair/hair_stroke.c
+++ b/source/blender/editors/hair/hair_stroke.c
@@ -37,21 +37,94 @@
#include "BLI_math.h"
#include "DNA_brush_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
#include "BKE_edithair.h"
#include "bmesh.h"
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_view3d.h"
+
#include "hair_intern.h"
-typedef void (*VertexToolCb)(HairToolData *data, BMVert *v, float factor);
+BLI_INLINE bool test_depth(HairToolData *data, const float co[3], const int screen_co[2])
+{
+ View3D *v3d = data->vc.v3d;
+ ViewDepths *vd = data->vc.rv3d->depths;
+ const bool has_zbuf = (v3d->drawtype > OB_WIRE) && (v3d->flag & V3D_ZBUF_SELECT);
+
+ double ux, uy, uz;
+ float depth;
+
+ /* nothing to do */
+ if (!has_zbuf)
+ return true;
+
+ gluProject(co[0], co[1], co[2],
+ data->mats.modelview, data->mats.projection, data->mats.viewport,
+ &ux, &uy, &uz);
+
+ /* check if screen_co is within bounds because brush_cut uses out of screen coords */
+ if (screen_co[0] >= 0 && screen_co[0] < vd->w && screen_co[1] >= 0 && screen_co[1] < vd->h) {
+ BLI_assert(vd && vd->depths);
+ /* we know its not clipped */
+ depth = vd->depths[screen_co[1] * vd->w + screen_co[0]];
+
+ return ((float)uz - 0.00001f <= depth);
+ }
+
+ return false;
+}
-BLI_INLINE float hair_tool_filter_vertex(HairToolData *data, BMVert *v)
+BLI_INLINE bool test_inside_circle(HairToolData *data, BMVert *v, float radsq, float *r_dist)
{
+ float co_world[3];
+ float dx, dy, distsq;
+ int screen_co[2];
+
+ mul_v3_m4v3(co_world, data->ob->obmat, v->co);
+
+ /* TODO, should this check V3D_PROJ_TEST_CLIP_BB too? */
+ if (ED_view3d_project_int_global(data->vc.ar, co_world, screen_co, V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_OK)
+ return false;
+
+ dx = data->mval[0] - (float)screen_co[0];
+ dy = data->mval[1] - (float)screen_co[1];
+ distsq = dx * dx + dy * dy;
+
+ if (distsq > radsq)
+ return false;
+
+ if (test_depth(data, v->co, screen_co)) {
+ *r_dist = sqrtf(distsq);
+ return true;
+ }
+ else
+ return false;
+}
+
+BLI_INLINE float factor_vertex(HairToolData *data, BMVert *v)
+{
+ const float rad = data->settings->brush->size * 0.5f;
+ const float radsq = rad*rad;
+
+ float dist;
+
+ if (!test_inside_circle(data, v, radsq, &dist))
+ return 0.0f;
+
return 1.0f; // TODO
}
+/* ------------------------------------------------------------------------- */
+
+typedef void (*VertexToolCb)(HairToolData *data, BMVert *v, float factor);
+
static int hair_tool_apply_vertex(HairToolData *data, VertexToolCb cb)
{
const float threshold = 0.0f; /* XXX could be useful, is it needed? */
@@ -61,7 +134,7 @@ static int hair_tool_apply_vertex(HairToolData *data, VertexToolCb cb)
int tot = 0;
BM_ITER_MESH(v, &iter, data->edit->bm, BM_VERTS_OF_MESH) {
- float factor = hair_tool_filter_vertex(data, v);
+ float factor = factor_vertex(data, v);
if (factor > threshold) {
cb(data, v, factor);
++tot;
More information about the Bf-blender-cvs
mailing list