示例#1
0
static void partialvis_update_bmesh_verts(BMesh *bm,
                                          GSet *verts,
                                          PartialVisAction action,
                                          PartialVisArea area,
                                          float planes[4][4],
                                          bool *any_changed,
                                          bool *any_visible)
{
	GSetIterator gs_iter;

	GSET_ITER (gs_iter, verts) {
		BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
		float *vmask = CustomData_bmesh_get(&bm->vdata,
		                                    v->head.data,
		                                    CD_PAINT_MASK);

		/* hide vertex if in the hide volume */
		if (is_effected(area, planes, v->co, *vmask)) {
			if (action == PARTIALVIS_HIDE)
				BM_elem_flag_enable(v, BM_ELEM_HIDDEN);
			else
				BM_elem_flag_disable(v, BM_ELEM_HIDDEN);
			(*any_changed) = true;
		}

		if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN))
			(*any_visible) = true;
	}
示例#2
0
static void partialvis_update_mesh(Object *ob,
                                   PBVH *pbvh,
                                   PBVHNode *node,
                                   PartialVisAction action,
                                   PartialVisArea area,
                                   float planes[4][4])
{
	Mesh *me = ob->data;
	MVert *mvert;
	float *paint_mask;
	int *vert_indices;
	int totvert, i;
	bool any_changed = false, any_visible = false;
			
	BKE_pbvh_node_num_verts(pbvh, node, NULL, &totvert);
	BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
	paint_mask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);

	sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);

	for (i = 0; i < totvert; i++) {
		MVert *v = &mvert[vert_indices[i]];
		float vmask = paint_mask ? paint_mask[vert_indices[i]] : 0;

		/* hide vertex if in the hide volume */
		if (is_effected(area, planes, v->co, vmask)) {
			if (action == PARTIALVIS_HIDE)
				v->flag |= ME_HIDE;
			else
				v->flag &= ~ME_HIDE;
			any_changed = true;
		}

		if (!(v->flag & ME_HIDE))
			any_visible = true;
	}

	if (any_changed) {
		BKE_pbvh_node_mark_rebuild_draw(node);
		BKE_pbvh_node_fully_hidden_set(node, !any_visible);
	}
}
示例#3
0
static void partialvis_update_mesh(Object *ob,
                                   PBVH *pbvh,
                                   PBVHNode *node,
                                   PartialVisAction action,
                                   PartialVisArea area,
                                   float planes[4][4])
{
	MVert *mvert;
	int *vert_indices;
	int any_changed = 0, any_visible = 0, totvert, i;
			
	BLI_pbvh_node_num_verts(pbvh, node, NULL, &totvert);
	BLI_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);

	sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);

	for (i = 0; i < totvert; i++) {
		MVert *v = &mvert[vert_indices[i]];

		/* hide vertex if in the hide volume */
		if (is_effected(area, planes, v->co)) {
			if (action == PARTIALVIS_HIDE)
				v->flag |= ME_HIDE;
			else
				v->flag &= ~ME_HIDE;
			any_changed = 1;
		}

		if (!(v->flag & ME_HIDE))
			any_visible = 1;
	}

	if (any_changed) {
		BLI_pbvh_node_mark_rebuild_draw(node);
		BLI_pbvh_node_fully_hidden_set(node, !any_visible);
	}
}
示例#4
0
/* Hide or show elements in multires grids with a special GridFlags
 * customdata layer. */
static void partialvis_update_grids(Object *ob,
                                    PBVH *pbvh,
                                    PBVHNode *node,
                                    PartialVisAction action,
                                    PartialVisArea area,
                                    float planes[4][4])
{
	CCGElem **grids;
	CCGKey key;
	BLI_bitmap **grid_hidden;
	int *grid_indices, totgrid, i;
	bool any_changed = false, any_visible = false;


	/* get PBVH data */
	BKE_pbvh_node_get_grids(pbvh, node,
	                        &grid_indices, &totgrid, NULL, NULL,
	                        &grids, NULL);
	grid_hidden = BKE_pbvh_grid_hidden(pbvh);
	BKE_pbvh_get_grid_key(pbvh, &key);
	
	sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);

	for (i = 0; i < totgrid; i++) {
		int any_hidden = 0;
		int g = grid_indices[i], x, y;
		BLI_bitmap *gh = grid_hidden[g];

		if (!gh) {
			switch (action) {
				case PARTIALVIS_HIDE:
					/* create grid flags data */
					gh = grid_hidden[g] = BLI_BITMAP_NEW(key.grid_area,
					                                     "partialvis_update_grids");
					break;
				case PARTIALVIS_SHOW:
					/* entire grid is visible, nothing to show */
					continue;
			}
		}
		else if (action == PARTIALVIS_SHOW && area == PARTIALVIS_ALL) {
			/* special case if we're showing all, just free the
			 * grid */
			MEM_freeN(gh);
			grid_hidden[g] = NULL;
			any_changed = true;
			any_visible = true;
			continue;
		}

		for (y = 0; y < key.grid_size; y++) {
			for (x = 0; x < key.grid_size; x++) {
				CCGElem *elem = CCG_grid_elem(&key, grids[g], x, y);
				const float *co = CCG_elem_co(&key, elem);
				float mask = key.has_mask ? *CCG_elem_mask(&key, elem) : 0.0f;

				/* skip grid element if not in the effected area */
				if (is_effected(area, planes, co, mask)) {
					/* set or clear the hide flag */
					BLI_BITMAP_MODIFY(gh, y * key.grid_size + x,
					                  action == PARTIALVIS_HIDE);

					any_changed = true;
				}

				/* keep track of whether any elements are still hidden */
				if (BLI_BITMAP_GET(gh, y * key.grid_size + x))
					any_hidden = true;
				else
					any_visible = true;
			}
		}

		/* if everything in the grid is now visible, free the grid
		 * flags */
		if (!any_hidden) {
			MEM_freeN(gh);
			grid_hidden[g] = NULL;
		}
	}

	/* mark updates if anything was hidden/shown */
	if (any_changed) {
		BKE_pbvh_node_mark_rebuild_draw(node);
		BKE_pbvh_node_fully_hidden_set(node, !any_visible);
		multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED);
	}
}