Commit: 7465aa8965483802d8285930e55d48f01d8abf0a Author: Campbell Barton Date: Tue Dec 6 13:47:40 2022 +1100 Branches: master https://developer.blender.org/rB7465aa8965483802d8285930e55d48f01d8abf0a
Merge branch 'blender-v3.4-release' =================================================================== =================================================================== diff --cc source/blender/editors/sculpt_paint/sculpt.cc index 9d30aa512c8,00000000000..3c0dcf44c35 mode 100644,000000..100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@@ -1,6278 -1,0 +1,6278 @@@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2006 by Nicholas Bishop. All rights reserved. */ + +/** \file + * \ingroup edsculpt + * Implements the Sculpt Mode tools. + */ + +#include <cmath> +#include <cstdlib> +#include <cstring> + +#include "MEM_guardedalloc.h" + +#include "BLI_blenlib.h" +#include "BLI_dial_2d.h" +#include "BLI_ghash.h" +#include "BLI_gsqueue.h" +#include "BLI_math.h" +#include "BLI_task.h" +#include "BLI_task.hh" +#include "BLI_timeit.hh" +#include "BLI_utildefines.h" + +#include "DNA_brush_types.h" +#include "DNA_customdata_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BKE_attribute.h" +#include "BKE_brush.h" +#include "BKE_ccg.h" +#include "BKE_colortools.h" +#include "BKE_context.h" +#include "BKE_image.h" +#include "BKE_key.h" +#include "BKE_lib_id.h" +#include "BKE_main.h" +#include "BKE_mesh.h" +#include "BKE_mesh_mapping.h" +#include "BKE_modifier.h" +#include "BKE_multires.h" +#include "BKE_node_runtime.hh" +#include "BKE_object.h" +#include "BKE_paint.h" +#include "BKE_pbvh.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_subdiv_ccg.h" +#include "BKE_subsurf.h" + +#include "NOD_texture.h" + +#include "DEG_depsgraph.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_paint.h" +#include "ED_screen.h" +#include "ED_sculpt.h" +#include "ED_view3d.h" + +#include "paint_intern.h" +#include "sculpt_intern.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "bmesh.h" + +using blender::MutableSpan; + +/* -------------------------------------------------------------------- */ +/** \name Sculpt PBVH Abstraction API + * + * This is read-only, for writing use PBVH vertex iterators. There vd.index matches + * the indices used here. + * + * For multi-resolution, the same vertex in multiple grids is counted multiple times, with + * different index for each grid. + * \{ */ + +void SCULPT_vertex_random_access_ensure(SculptSession *ss) +{ + if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { + BM_mesh_elem_index_ensure(ss->bm, BM_VERT); + BM_mesh_elem_table_ensure(ss->bm, BM_VERT); + } +} + +int SCULPT_vertex_count_get(SculptSession *ss) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: + return ss->totvert; + case PBVH_BMESH: + return BM_mesh_elem_count(BKE_pbvh_get_bmesh(ss->pbvh), BM_VERT); + case PBVH_GRIDS: + return BKE_pbvh_get_grid_num_verts(ss->pbvh); + } + + return 0; +} + +const float *SCULPT_vertex_co_get(SculptSession *ss, PBVHVertRef vertex) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: { + if (ss->shapekey_active || ss->deform_modifiers_active) { + const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh); + return mverts[vertex.i].co; + } + return ss->mvert[vertex.i].co; + } + case PBVH_BMESH: + return ((BMVert *)vertex.i)->co; + case PBVH_GRIDS: { + const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); + const int grid_index = vertex.i / key->grid_area; + const int vertex_index = vertex.i - grid_index * key->grid_area; + CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index]; + return CCG_elem_co(key, CCG_elem_offset(key, elem, vertex_index)); + } + } + return nullptr; +} + +bool SCULPT_has_loop_colors(const Object *ob) +{ + Mesh *me = BKE_object_get_original_mesh(ob); + const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id); + + return layer && BKE_id_attribute_domain(&me->id, layer) == ATTR_DOMAIN_CORNER; +} + +bool SCULPT_has_colors(const SculptSession *ss) +{ + return ss->vcol || ss->mcol; +} + +void SCULPT_vertex_color_get(const SculptSession *ss, PBVHVertRef vertex, float r_color[4]) +{ + BKE_pbvh_vertex_color_get(ss->pbvh, vertex, r_color); +} + +void SCULPT_vertex_color_set(SculptSession *ss, PBVHVertRef vertex, const float color[4]) +{ + BKE_pbvh_vertex_color_set(ss->pbvh, vertex, color); +} + +void SCULPT_vertex_normal_get(SculptSession *ss, PBVHVertRef vertex, float no[3]) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: { + const float(*vert_normals)[3] = BKE_pbvh_get_vert_normals(ss->pbvh); + copy_v3_v3(no, vert_normals[vertex.i]); + break; + } + case PBVH_BMESH: { + BMVert *v = (BMVert *)vertex.i; + copy_v3_v3(no, v->no); + break; + } + case PBVH_GRIDS: { + const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); + const int grid_index = vertex.i / key->grid_area; + const int vertex_index = vertex.i - grid_index * key->grid_area; + CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index]; + copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, vertex_index))); + break; + } + } +} + +const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, PBVHVertRef vertex) +{ + if (ss->attrs.persistent_co) { + return (const float *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_co); + } + + return SCULPT_vertex_co_get(ss, vertex); +} + +const float *SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, PBVHVertRef vertex) +{ + if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) { + /* Always grab active shape key if the sculpt happens on shapekey. */ + if (ss->shapekey_active) { + const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh); + return mverts[vertex.i].co; + } + + /* Sculpting on the base mesh. */ + return ss->mvert[vertex.i].co; + } + + /* Everything else, such as sculpting on multires. */ + return SCULPT_vertex_co_get(ss, vertex); +} + +void SCULPT_vertex_limit_surface_get(SculptSession *ss, PBVHVertRef vertex, float r_co[3]) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: + case PBVH_BMESH: + copy_v3_v3(r_co, SCULPT_vertex_co_get(ss, vertex)); + break; + case PBVH_GRIDS: { + const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); + const int grid_index = vertex.i / key->grid_area; + const int vertex_index = vertex.i - grid_index * key->grid_area; + + SubdivCCGCoord coord{}; + coord.grid_index = grid_index; + coord.x = vertex_index % key->grid_size; + coord.y = vertex_index / key->grid_size; + BKE_subdiv_ccg_eval_limit_point(ss->subdiv_ccg, &coord, r_co); + break; + } + } +} + +void SCULPT_vertex_persistent_normal_get(SculptSession *ss, PBVHVertRef vertex, float no[3]) +{ + if (ss->attrs.persistent_no) { + copy_v3_v3(no, (float *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_no)); + return; + } + SCULPT_vertex_normal_get(ss, vertex, no); +} + +float SCULPT_vertex_mask_get(SculptSession *ss, PBVHVertRef vertex) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: + return ss->vmask ? ss->vmask[vertex.i] : 0.0f; + case PBVH_BMESH: { + BMVert *v; + int cd_mask = CustomData_get_offset(&ss->bm->vdata, CD_PAINT_MASK); + + v = (BMVert *)vertex.i; + return cd_mask != -1 ? BM_ELEM_CD_GET_FLOAT(v, cd_mask) : 0.0f; + } + case PBVH_GRIDS: { + const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); + const int grid_index = vertex.i / key->grid_area; + const int vertex_index = vertex.i - grid_index * key->grid_area; + CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index]; + return *CCG_elem_mask(key, CCG_elem_offset(key, elem, vertex_index)); + } + } + + return 0.0f; +} + +PBVHVertRef SCULPT_active_vertex_get(SculptSession *ss) +{ + if (ELEM(BKE_pbvh_type(ss->pbvh), PBVH_FACES, PBVH_BMESH, PBVH_GRIDS)) { + return ss->active_vertex; + } + + return BKE_pbvh_make_vref(PBVH_REF_NONE); +} + +const float *SCULPT_active_vertex_co_get(SculptSession *ss) +{ + return SCULPT_vertex_co_get(ss, SCULPT_active_vertex_get(ss)); +} + +void SCULPT_active_vertex_normal_get(SculptSession *ss, float normal[3]) +{ + SCULPT_vertex_normal_get(ss, SCULPT_active_vertex_get(ss), normal); +} + +MVert *SCULPT_mesh_deformed_mverts_get(SculptSession *ss) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: + if (ss->shapekey_active || ss->deform_modifiers_active) { + return BKE_pbvh_get_verts(ss->pbvh); + } + return ss->mvert; + case PBVH_BMESH: + case PBVH_GRIDS: + return nullptr; + } + return nullptr; +} + +float *SCULPT_brush_deform_target_vertex_co_get(SculptSession *ss, + const int deform_target, + PBVHVertexIter *iter) +{ + switch (deform_target) { + case BRUSH_DEFORM_TARGET_GEOMETRY: + return iter->co; + case BRUSH_DEFORM_TARGET_CLOTH_SIM: + return ss->cache->cloth_sim->deformation_pos[iter->index]; + } + return iter->co; +} + +char SCULPT_mesh_symmetry_xyz_get(Object *object) +{ + const Mesh *mesh = BKE_mesh_from_object(object); + return mesh->symmetry; +} + +/* Sculpt Face Sets and Visibility. */ + +int SCULPT_active_face_set_get(SculptSession *ss) +{ + switch (BKE_pbvh_type(ss->pbvh)) { + case PBVH_FACES: + if (!ss->face_sets) { + return SCULPT_FACE_SET_NONE; + } + return ss->face_sets[ss->active_face_index]; + case PBVH_GRIDS: { + if (!ss->face_sets) { + return SCULPT_FACE_SET_NONE; + } + const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, + ss->active_grid_index); + return ss->face_sets[face_index]; + } + case PBVH_BMESH: + return SCULPT_FACE_SET_NONE; + } + return SCULPT_FACE_SET_NONE; +} + +void SCULPT_vertex_visible_set(S @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs