Exemple #1
0
static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
{
	Object *ob= CTX_data_active_object(C);
	paintface_deselect_all_visible(ob, SEL_INVERT, TRUE);
	ED_region_tag_redraw(CTX_wm_region(C));
	return OPERATOR_FINISHED;
}
Exemple #2
0
static int face_select_all_exec(bContext *C, wmOperator *op)
{
	Object *ob = CTX_data_active_object(C);
	paintface_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), true);
	ED_region_tag_redraw(CTX_wm_region(C));
	return OPERATOR_FINISHED;
}
Exemple #3
0
bool paintface_mouse_select(
    struct bContext *C, Object *ob, const int mval[2], bool extend, bool deselect, bool toggle)
{
  Mesh *me;
  MPoly *mpoly_sel;
  uint index;

  /* Get the face under the cursor */
  me = BKE_mesh_from_object(ob);

  if (!ED_mesh_pick_face(C, ob, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) {
    return false;
  }

  if (index >= me->totpoly) {
    return false;
  }

  mpoly_sel = me->mpoly + index;
  if (mpoly_sel->flag & ME_HIDE) {
    return false;
  }

  /* clear flags */
  if (!extend && !deselect && !toggle) {
    paintface_deselect_all_visible(C, ob, SEL_DESELECT, false);
  }

  me->act_face = (int)index;

  if (extend) {
    mpoly_sel->flag |= ME_FACE_SEL;
  }
  else if (deselect) {
    mpoly_sel->flag &= ~ME_FACE_SEL;
  }
  else if (toggle) {
    if (mpoly_sel->flag & ME_FACE_SEL) {
      mpoly_sel->flag &= ~ME_FACE_SEL;
    }
    else {
      mpoly_sel->flag |= ME_FACE_SEL;
    }
  }
  else {
    mpoly_sel->flag |= ME_FACE_SEL;
  }

  /* image window redraw */

  paintface_flush_flags(C, ob, SELECT);
  ED_region_tag_redraw(CTX_wm_region(C));  // XXX - should redraw all 3D views
  return true;
}
Exemple #4
0
int do_paintface_box_select(ViewContext *vc, rcti *rect, bool select, bool extend)
{
	Object *ob = vc->obact;
	Mesh *me;
	MPoly *mpoly;
	struct ImBuf *ibuf;
	unsigned int *rt;
	char *selar;
	int a, index;
	const int size[2] = {
	    BLI_rcti_size_x(rect) + 1,
	    BLI_rcti_size_y(rect) + 1};
	
	me = BKE_mesh_from_object(ob);

	if ((me == NULL) || (me->totpoly == 0) || (size[0] * size[1] <= 0)) {
		return OPERATOR_CANCELLED;
	}

	selar = MEM_callocN(me->totpoly + 1, "selar");

	if (extend == false && select) {
		paintface_deselect_all_visible(vc->obact, SEL_DESELECT, false);

		mpoly = me->mpoly;
		for (a = 1; a <= me->totpoly; a++, mpoly++) {
			if ((mpoly->flag & ME_HIDE) == 0)
				mpoly->flag &= ~ME_FACE_SEL;
		}
	}

	ED_view3d_backbuf_validate(vc);

	ibuf = IMB_allocImBuf(size[0], size[1], 32, IB_rect);
	rt = ibuf->rect;
	view3d_opengl_read_pixels(vc->ar, rect->xmin, rect->ymin, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE,  ibuf->rect);
	if (ENDIAN_ORDER == B_ENDIAN) {
		IMB_convert_rgba_to_abgr(ibuf);
	}
	GPU_select_to_index_array(ibuf->rect, size[0] * size[1]);

	a = size[0] * size[1];
	while (a--) {
		if (*rt) {
			index = *rt;
			if (index <= me->totpoly) {
				selar[index] = 1;
			}
		}
		rt++;
	}

	mpoly = me->mpoly;
	for (a = 1; a <= me->totpoly; a++, mpoly++) {
		if (selar[a]) {
			if (mpoly->flag & ME_HIDE) {
				/* pass */
			}
			else {
				if (select) mpoly->flag |= ME_FACE_SEL;
				else mpoly->flag &= ~ME_FACE_SEL;
			}
		}
	}

	IMB_freeImBuf(ibuf);
	MEM_freeN(selar);

#ifdef __APPLE__	
	glReadBuffer(GL_BACK);
#endif

	paintface_flush_flags(vc->obact, SELECT);

	return OPERATOR_FINISHED;
}