2011-09-18 12:16:03 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2012-08-05 15:04:10 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-09-18 12:16:03 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/sculpt_paint/paint_utils.c
|
|
|
|
* \ingroup edsculpt
|
|
|
|
*/
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2009-08-14 04:45:29 +00:00
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_brush_types.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2012-07-12 08:31:23 +00:00
|
|
|
#include "BLI_rect.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2009-03-11 00:43:08 +00:00
|
|
|
#include "BKE_brush.h"
|
2009-08-14 04:45:29 +00:00
|
|
|
#include "BKE_context.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2009-08-16 19:50:00 +00:00
|
|
|
#include "BKE_paint.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
2011-01-08 01:45:02 +00:00
|
|
|
/* TODO: remove once projectf goes away */
|
|
|
|
#include "BIF_glutil.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2011-01-07 22:03:16 +00:00
|
|
|
#include "RE_shader_ext.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include "ED_view3d.h"
|
2009-11-01 00:06:53 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "BLO_sys_types.h"
|
|
|
|
#include "ED_mesh.h" /* for face mask functions */
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2009-08-14 04:45:29 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "paint_intern.h"
|
|
|
|
|
2011-12-26 20:19:55 +00:00
|
|
|
/* Convert the object-space axis-aligned bounding box (expressed as
|
2012-03-03 16:31:46 +00:00
|
|
|
* its minimum and maximum corners) into a screen-space rectangle,
|
|
|
|
* returns zero if the result is empty */
|
2011-12-26 20:19:55 +00:00
|
|
|
int paint_convert_bb_to_rect(rcti *rect,
|
2012-03-28 03:47:33 +00:00
|
|
|
const float bb_min[3],
|
|
|
|
const float bb_max[3],
|
|
|
|
const ARegion *ar,
|
|
|
|
RegionView3D *rv3d,
|
|
|
|
Object *ob)
|
2011-12-26 20:19:55 +00:00
|
|
|
{
|
|
|
|
float projection_mat[4][4];
|
|
|
|
int i, j, k;
|
|
|
|
|
2012-07-12 08:31:23 +00:00
|
|
|
BLI_rcti_init_minmax(rect);
|
2011-12-26 20:19:55 +00:00
|
|
|
|
|
|
|
/* return zero if the bounding box has non-positive volume */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2])
|
2011-12-26 20:19:55 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
for (j = 0; j < 2; ++j) {
|
|
|
|
for (k = 0; k < 2; ++k) {
|
2011-12-26 20:19:55 +00:00
|
|
|
float vec[3], proj[2];
|
2012-07-12 09:24:17 +00:00
|
|
|
int proj_i[2];
|
2011-12-26 20:19:55 +00:00
|
|
|
vec[0] = i ? bb_min[0] : bb_max[0];
|
|
|
|
vec[1] = j ? bb_min[1] : bb_max[1];
|
|
|
|
vec[2] = k ? bb_min[2] : bb_max[2];
|
|
|
|
/* convert corner to screen space */
|
2012-03-07 01:06:18 +00:00
|
|
|
ED_view3d_project_float_v2(ar, vec, proj, projection_mat);
|
2011-12-26 20:19:55 +00:00
|
|
|
/* expand 2D rectangle */
|
2012-07-12 09:24:17 +00:00
|
|
|
|
|
|
|
/* we could project directly to int? */
|
|
|
|
proj_i[0] = proj[0];
|
|
|
|
proj_i[1] = proj[1];
|
|
|
|
|
|
|
|
BLI_rcti_do_minmax_v(rect, proj_i);
|
2011-12-26 20:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return false if the rectangle has non-positive area */
|
|
|
|
return rect->xmin < rect->xmax && rect->ymin < rect->ymax;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get four planes in object-space that describe the projection of
|
2012-03-03 16:31:46 +00:00
|
|
|
* screen_rect from screen into object-space (essentially converting a
|
|
|
|
* 2D screens-space bounding box into four 3D planes) */
|
2011-12-26 20:19:55 +00:00
|
|
|
void paint_calc_redraw_planes(float planes[4][4],
|
2012-03-28 03:47:33 +00:00
|
|
|
const ARegion *ar,
|
|
|
|
RegionView3D *rv3d,
|
|
|
|
Object *ob,
|
|
|
|
const rcti *screen_rect)
|
2011-12-26 20:19:55 +00:00
|
|
|
{
|
|
|
|
BoundBox bb;
|
|
|
|
bglMats mats;
|
|
|
|
rcti rect;
|
|
|
|
|
|
|
|
memset(&bb, 0, sizeof(BoundBox));
|
|
|
|
view3d_get_transformation(ar, rv3d, ob, &mats);
|
|
|
|
|
|
|
|
/* use some extra space just in case */
|
2011-12-26 23:36:44 +00:00
|
|
|
rect = *screen_rect;
|
2011-12-26 20:19:55 +00:00
|
|
|
rect.xmin -= 2;
|
|
|
|
rect.xmax += 2;
|
|
|
|
rect.ymin -= 2;
|
|
|
|
rect.ymax += 2;
|
|
|
|
|
2011-12-26 23:36:44 +00:00
|
|
|
ED_view3d_calc_clipping(&bb, planes, &mats, &rect);
|
2011-12-26 20:19:55 +00:00
|
|
|
mul_m4_fl(planes, -1.0f);
|
|
|
|
}
|
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* convert a point in model coordinates to 2D screen coordinates */
|
|
|
|
/* TODO: can be deleted once all calls are replaced with
|
2012-03-03 16:31:46 +00:00
|
|
|
* view3d_project_float() */
|
2011-01-08 01:45:02 +00:00
|
|
|
void projectf(bglMats *mats, const float v[3], float p[2])
|
|
|
|
{
|
|
|
|
double ux, uy, uz;
|
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
gluProject(v[0], v[1], v[2], mats->modelview, mats->projection,
|
|
|
|
(GLint *)mats->viewport, &ux, &uy, &uz);
|
|
|
|
p[0] = ux;
|
|
|
|
p[1] = uy;
|
2011-01-08 01:45:02 +00:00
|
|
|
}
|
|
|
|
|
2012-01-15 23:43:54 +00:00
|
|
|
float paint_calc_object_space_radius(ViewContext *vc, const float center[3],
|
2012-03-28 03:47:33 +00:00
|
|
|
float pixel_radius)
|
2011-01-07 22:46:52 +00:00
|
|
|
{
|
|
|
|
Object *ob = vc->obact;
|
|
|
|
float delta[3], scale, loc[3];
|
2012-09-06 23:41:03 +00:00
|
|
|
const float mval_f[2] = {pixel_radius, 0.0f};
|
2011-01-07 22:46:52 +00:00
|
|
|
|
|
|
|
mul_v3_m4v3(loc, ob->obmat, center);
|
|
|
|
|
|
|
|
initgrabz(vc->rv3d, loc[0], loc[1], loc[2]);
|
2011-05-20 13:50:41 +00:00
|
|
|
|
|
|
|
ED_view3d_win_to_delta(vc->ar, mval_f, delta);
|
2011-01-07 22:46:52 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
scale = fabsf(mat4_to_scale(ob->obmat));
|
|
|
|
scale = (scale == 0.0f) ? 1.0f : scale;
|
2011-01-07 22:46:52 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
return len_v3(delta) / scale;
|
2011-01-07 22:46:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
float paint_get_tex_pixel(Brush *br, float u, float v)
|
2011-01-07 22:03:16 +00:00
|
|
|
{
|
2012-08-05 15:04:10 +00:00
|
|
|
TexResult texres = {0};
|
|
|
|
float co[3] = {u, v, 0.0f};
|
2011-01-07 22:03:16 +00:00
|
|
|
int hasrgb;
|
|
|
|
|
2011-01-09 18:43:47 +00:00
|
|
|
hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 0, &texres);
|
2011-01-07 22:03:16 +00:00
|
|
|
|
|
|
|
if (hasrgb & TEX_RGB)
|
2012-05-09 10:48:24 +00:00
|
|
|
texres.tin = rgb_to_grayscale(&texres.tr) * texres.ta;
|
2011-01-07 22:03:16 +00:00
|
|
|
|
|
|
|
return texres.tin;
|
|
|
|
}
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
/* 3D Paint */
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void imapaint_project(Object *ob, float model[][4], float proj[][4], const float co[3], float pco[4])
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v3_v3(pco, co);
|
2012-03-28 03:47:33 +00:00
|
|
|
pco[3] = 1.0f;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(ob->obmat, pco);
|
2012-02-28 14:05:00 +00:00
|
|
|
mul_m4_v3(model, pco);
|
|
|
|
mul_m4_v4(proj, pco);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void imapaint_tri_weights(Object *ob,
|
|
|
|
const float v1[3], const float v2[3], const float v3[3],
|
|
|
|
const float co[3], float w[3])
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
|
|
|
float pv1[4], pv2[4], pv3[4], h[3], divw;
|
2012-02-28 14:05:00 +00:00
|
|
|
float model[4][4], proj[4][4], wmat[3][3], invwmat[3][3];
|
2009-02-19 23:53:40 +00:00
|
|
|
GLint view[4];
|
|
|
|
|
|
|
|
/* compute barycentric coordinates */
|
|
|
|
|
|
|
|
/* get the needed opengl matrices */
|
|
|
|
glGetIntegerv(GL_VIEWPORT, view);
|
2012-02-28 14:05:00 +00:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (float *)model);
|
|
|
|
glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj);
|
2009-02-19 23:53:40 +00:00
|
|
|
view[0] = view[1] = 0;
|
|
|
|
|
|
|
|
/* project the verts */
|
|
|
|
imapaint_project(ob, model, proj, v1, pv1);
|
|
|
|
imapaint_project(ob, model, proj, v2, pv2);
|
|
|
|
imapaint_project(ob, model, proj, v3, pv3);
|
|
|
|
|
|
|
|
/* do inverse view mapping, see gluProject man page */
|
2012-03-28 03:47:33 +00:00
|
|
|
h[0] = (co[0] - view[0]) * 2.0f / view[2] - 1;
|
|
|
|
h[1] = (co[1] - view[1]) * 2.0f / view[3] - 1;
|
|
|
|
h[2] = 1.0f;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
/* solve for (w1,w2,w3)/perspdiv in:
|
2012-03-03 16:31:46 +00:00
|
|
|
* h * perspdiv = Project * Model * (w1 * v1 + w2 * v2 + w3 * v3) */
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
wmat[0][0] = pv1[0]; wmat[1][0] = pv2[0]; wmat[2][0] = pv3[0];
|
|
|
|
wmat[0][1] = pv1[1]; wmat[1][1] = pv2[1]; wmat[2][1] = pv3[1];
|
|
|
|
wmat[0][2] = pv1[3]; wmat[1][2] = pv2[3]; wmat[2][2] = pv3[3];
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m3_m3(invwmat, wmat);
|
|
|
|
mul_m3_v3(invwmat, h);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v3_v3(w, h);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
/* w is still divided by perspdiv, make it sum to one */
|
2012-03-28 03:47:33 +00:00
|
|
|
divw = w[0] + w[1] + w[2];
|
2012-03-24 06:38:07 +00:00
|
|
|
if (divw != 0.0f) {
|
2012-03-28 03:47:33 +00:00
|
|
|
mul_v3_fl(w, 1.0f / divw);
|
2012-02-28 14:05:00 +00:00
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compute uv coordinates of mouse in face */
|
2011-05-20 14:11:05 +00:00
|
|
|
void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2])
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
|
2011-04-15 01:19:13 +00:00
|
|
|
const int *index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
MTFace *tface = dm->getTessFaceDataArray(dm, CD_MTFACE), *tf;
|
2010-01-05 22:33:41 +00:00
|
|
|
int numfaces = dm->getNumTessFaces(dm), a, findex;
|
2009-02-19 23:53:40 +00:00
|
|
|
float p[2], w[3], absw, minabsw;
|
|
|
|
MFace mf;
|
|
|
|
MVert mv[4];
|
|
|
|
|
|
|
|
minabsw = 1e10;
|
|
|
|
uv[0] = uv[1] = 0.0;
|
|
|
|
|
|
|
|
/* test all faces in the derivedmesh with the original index of the picked face */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (a = 0; a < numfaces; a++) {
|
2012-03-28 03:47:33 +00:00
|
|
|
findex = index ? index[a] : a;
|
2009-11-04 20:23:48 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (findex == faceindex) {
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
dm->getTessFace(dm, a, &mf);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
dm->getVert(dm, mf.v1, &mv[0]);
|
|
|
|
dm->getVert(dm, mf.v2, &mv[1]);
|
|
|
|
dm->getVert(dm, mf.v3, &mv[2]);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mf.v4)
|
2009-02-19 23:53:40 +00:00
|
|
|
dm->getVert(dm, mf.v4, &mv[3]);
|
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
tf = &tface[a];
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
p[0] = xy[0];
|
|
|
|
p[1] = xy[1];
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mf.v4) {
|
2009-02-19 23:53:40 +00:00
|
|
|
/* the triangle with the largest absolute values is the one
|
2012-03-03 16:31:46 +00:00
|
|
|
* with the most negative weights */
|
2009-02-19 23:53:40 +00:00
|
|
|
imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w);
|
2012-07-21 15:27:40 +00:00
|
|
|
absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (absw < minabsw) {
|
2012-03-28 03:47:33 +00:00
|
|
|
uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[3][0] * w[2];
|
|
|
|
uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[3][1] * w[2];
|
2009-02-19 23:53:40 +00:00
|
|
|
minabsw = absw;
|
|
|
|
}
|
|
|
|
|
|
|
|
imapaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w);
|
2012-07-21 15:27:40 +00:00
|
|
|
absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (absw < minabsw) {
|
2012-03-28 03:47:33 +00:00
|
|
|
uv[0] = tf->uv[1][0] * w[0] + tf->uv[2][0] * w[1] + tf->uv[3][0] * w[2];
|
|
|
|
uv[1] = tf->uv[1][1] * w[0] + tf->uv[2][1] * w[1] + tf->uv[3][1] * w[2];
|
2009-02-19 23:53:40 +00:00
|
|
|
minabsw = absw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w);
|
2012-07-21 15:27:40 +00:00
|
|
|
absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (absw < minabsw) {
|
2012-03-28 03:47:33 +00:00
|
|
|
uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[2][0] * w[2];
|
|
|
|
uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[2][1] * w[2];
|
2009-02-19 23:53:40 +00:00
|
|
|
minabsw = absw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dm->release(dm);
|
|
|
|
}
|
|
|
|
|
2012-03-28 00:42:38 +00:00
|
|
|
/* returns 0 if not found, otherwise 1 */
|
|
|
|
int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *index, unsigned int totface)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2012-03-28 00:42:38 +00:00
|
|
|
if (totface == 0)
|
2009-02-19 23:53:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* sample only on the exact position */
|
|
|
|
*index = view3d_sample_backbuf(vc, mval[0], mval[1]);
|
|
|
|
|
2012-03-28 00:42:38 +00:00
|
|
|
if ((*index) <= 0 || (*index) > (unsigned int)totface) {
|
2009-02-19 23:53:40 +00:00
|
|
|
return 0;
|
2012-03-28 00:42:38 +00:00
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
(*index)--;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* used for both 3d view and image window */
|
2012-06-04 07:29:45 +00:00
|
|
|
void paint_sample_color(const bContext *C, ARegion *ar, int x, int y) /* frontbuf */
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2012-06-04 07:29:45 +00:00
|
|
|
Brush *br = paint_brush(paint_get_active_from_context(C));
|
2009-02-19 23:53:40 +00:00
|
|
|
unsigned int col;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
CLAMP(x, 0, ar->winx);
|
|
|
|
CLAMP(y, 0, ar->winy);
|
|
|
|
|
|
|
|
glReadBuffer(GL_FRONT);
|
2012-03-28 03:47:33 +00:00
|
|
|
glReadPixels(x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
|
2009-02-19 23:53:40 +00:00
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
|
|
|
|
cp = (char *)&col;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (br) {
|
2012-03-28 03:47:33 +00:00
|
|
|
br->rgb[0] = cp[0] / 255.0f;
|
|
|
|
br->rgb[1] = cp[1] / 255.0f;
|
|
|
|
br->rgb[2] = cp[2] / 255.0f;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-14 04:45:29 +00:00
|
|
|
static int brush_curve_preset_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-04 07:29:45 +00:00
|
|
|
Brush *br = paint_brush(paint_get_active_from_context(C));
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape"));
|
2009-08-14 04:45:29 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int brush_curve_preset_poll(bContext *C)
|
|
|
|
{
|
2012-06-04 07:29:45 +00:00
|
|
|
Brush *br = paint_brush(paint_get_active_from_context(C));
|
2009-08-14 04:45:29 +00:00
|
|
|
|
2009-08-16 19:50:00 +00:00
|
|
|
return br && br->curve;
|
2009-08-14 04:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BRUSH_OT_curve_preset(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
static EnumPropertyItem prop_shape_items[] = {
|
2010-01-04 17:28:37 +00:00
|
|
|
{CURVE_PRESET_SHARP, "SHARP", 0, "Sharp", ""},
|
|
|
|
{CURVE_PRESET_SMOOTH, "SMOOTH", 0, "Smooth", ""},
|
|
|
|
{CURVE_PRESET_MAX, "MAX", 0, "Max", ""},
|
2010-07-14 14:11:03 +00:00
|
|
|
{CURVE_PRESET_LINE, "LINE", 0, "Line", ""},
|
|
|
|
{CURVE_PRESET_ROUND, "ROUND", 0, "Round", ""},
|
|
|
|
{CURVE_PRESET_ROOT, "ROOT", 0, "Root", ""},
|
2009-08-14 04:45:29 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Preset";
|
|
|
|
ot->description = "Set brush shape";
|
|
|
|
ot->idname = "BRUSH_OT_curve_preset";
|
2009-08-14 04:45:29 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = brush_curve_preset_exec;
|
|
|
|
ot->poll = brush_curve_preset_poll;
|
2009-08-14 04:45:29 +00:00
|
|
|
|
2010-01-04 17:28:37 +00:00
|
|
|
RNA_def_enum(ot->srna, "shape", prop_shape_items, CURVE_PRESET_SMOOTH, "Mode", "");
|
2009-08-14 04:45:29 +00:00
|
|
|
}
|
2009-11-01 00:06:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* face-select ops */
|
2010-10-15 01:36:14 +00:00
|
|
|
static int paint_select_linked_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-11-01 00:06:53 +00:00
|
|
|
{
|
2010-11-03 01:56:02 +00:00
|
|
|
paintface_select_linked(C, CTX_data_active_object(C), NULL, 2);
|
2009-11-01 00:06:53 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_face_select_linked(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Select Linked";
|
|
|
|
ot->description = "Select linked faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_linked";
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = paint_select_linked_exec;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int paint_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
int mode = RNA_boolean_get(op->ptr, "extend") ? 1 : 0;
|
2010-11-03 01:56:02 +00:00
|
|
|
paintface_select_linked(C, CTX_data_active_object(C), event->mval, mode);
|
2009-11-01 00:06:53 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_face_select_linked_pick(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Select Linked Pick";
|
|
|
|
ot->description = "Select linked faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_linked_pick";
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = paint_select_linked_pick_invoke;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-01 00:06:53 +00:00
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
static int face_select_all_exec(bContext *C, wmOperator *op)
|
2009-11-01 00:06:53 +00:00
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2010-11-03 01:56:02 +00:00
|
|
|
paintface_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE);
|
2009-11-01 00:06:53 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-29 22:16:29 +00:00
|
|
|
void PAINT_OT_face_select_all(wmOperatorType *ot)
|
2009-11-01 00:06:53 +00:00
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Face Selection";
|
|
|
|
ot->description = "Change selection for all faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_all";
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = face_select_all_exec;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-29 22:16:29 +00:00
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2011-09-18 17:10:28 +00:00
|
|
|
|
2011-07-12 19:06:06 +00:00
|
|
|
static int vert_select_all_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2011-07-12 19:06:06 +00:00
|
|
|
paintvert_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2011-09-18 17:10:28 +00:00
|
|
|
|
2011-07-12 19:06:06 +00:00
|
|
|
void PAINT_OT_vert_select_all(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Vertex Selection";
|
|
|
|
ot->description = "Change selection for all vertices";
|
|
|
|
ot->idname = "PAINT_OT_vert_select_all";
|
2011-07-12 19:06:06 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = vert_select_all_exec;
|
|
|
|
ot->poll = vert_paint_poll;
|
2011-07-12 19:06:06 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-07-12 19:06:06 +00:00
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
|
|
|
}
|
2011-09-18 17:10:28 +00:00
|
|
|
|
2011-09-18 01:09:18 +00:00
|
|
|
static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2011-09-18 01:09:18 +00:00
|
|
|
paintvert_deselect_all_visible(ob, SEL_INVERT, TRUE);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2011-09-18 17:10:28 +00:00
|
|
|
|
2011-09-18 01:09:18 +00:00
|
|
|
void PAINT_OT_vert_select_inverse(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Vertex Select Invert";
|
|
|
|
ot->description = "Invert selection of vertices";
|
|
|
|
ot->idname = "PAINT_OT_vert_select_inverse";
|
2011-09-18 01:09:18 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = vert_select_inverse_exec;
|
|
|
|
ot->poll = vert_paint_poll;
|
2011-07-12 19:06:06 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-18 01:09:18 +00:00
|
|
|
}
|
2011-02-24 16:04:36 +00:00
|
|
|
static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2011-02-24 16:04:36 +00:00
|
|
|
paintface_deselect_all_visible(ob, SEL_INVERT, TRUE);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PAINT_OT_face_select_inverse(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Face Select Invert";
|
|
|
|
ot->description = "Invert selection of faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_inverse";
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = face_select_inverse_exec;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-24 16:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int face_select_hide_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
const int unselected = RNA_boolean_get(op->ptr, "unselected");
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2011-02-24 16:04:36 +00:00
|
|
|
paintface_hide(ob, unselected);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_face_select_hide(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Face Select Hide";
|
|
|
|
ot->description = "Hide selected faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_hide";
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = face_select_hide_exec;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2011-09-19 12:26:20 +00:00
|
|
|
RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
|
2011-02-24 16:04:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 17:57:35 +00:00
|
|
|
static int face_select_reveal_exec(bContext *C, wmOperator *UNUSED(op))
|
2011-02-24 16:04:36 +00:00
|
|
|
{
|
2012-03-28 03:47:33 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2011-02-24 16:04:36 +00:00
|
|
|
paintface_reveal(ob);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_face_select_reveal(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Face Select Reveal";
|
|
|
|
ot->description = "Reveal hidden faces";
|
|
|
|
ot->idname = "PAINT_OT_face_select_reveal";
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = face_select_reveal_exec;
|
|
|
|
ot->poll = facemask_paint_poll;
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-24 16:04:36 +00:00
|
|
|
|
2011-09-19 12:26:20 +00:00
|
|
|
RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
|
2011-02-24 16:04:36 +00:00
|
|
|
}
|