Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/paint.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| ss->totvert = me_eval->totvert; | ss->totvert = me_eval->totvert; | ||||
| ss->totpoly = me_eval->totpoly; | ss->totpoly = me_eval->totpoly; | ||||
| ss->totfaces = me->totpoly; | ss->totfaces = me->totpoly; | ||||
| /* These are assigned to the base mesh in Multires. This is needed because Face Sets operators | /* These are assigned to the base mesh in Multires. This is needed because Face Sets operators | ||||
| * and tools use the Face Sets data from the base mesh when Multires is active. */ | * and tools use the Face Sets data from the base mesh when Multires is active. */ | ||||
| ss->vert_positions = BKE_mesh_vert_positions_for_write(me); | ss->vert_positions = BKE_mesh_vert_positions_for_write(me); | ||||
| ss->mpoly = BKE_mesh_polys(me); | ss->mpoly = BKE_mesh_polys(me); | ||||
| ss->mloop = BKE_mesh_loops(me); | ss->corner_verts = me->corner_verts().data(); | ||||
| } | } | ||||
| else { | else { | ||||
| ss->totvert = me->totvert; | ss->totvert = me->totvert; | ||||
| ss->totpoly = me->totpoly; | ss->totpoly = me->totpoly; | ||||
| ss->totfaces = me->totpoly; | ss->totfaces = me->totpoly; | ||||
| ss->vert_positions = BKE_mesh_vert_positions_for_write(me); | ss->vert_positions = BKE_mesh_vert_positions_for_write(me); | ||||
| ss->mpoly = BKE_mesh_polys(me); | ss->mpoly = BKE_mesh_polys(me); | ||||
| ss->mloop = BKE_mesh_loops(me); | ss->corner_verts = me->corner_verts().data(); | ||||
| ss->multires.active = false; | ss->multires.active = false; | ||||
| ss->multires.modifier = nullptr; | ss->multires.modifier = nullptr; | ||||
| ss->multires.level = 0; | ss->multires.level = 0; | ||||
| ss->vmask = static_cast<float *>( | ss->vmask = static_cast<float *>( | ||||
| CustomData_get_layer_for_write(&me->vdata, CD_PAINT_MASK, me->totvert)); | CustomData_get_layer_for_write(&me->vdata, CD_PAINT_MASK, me->totvert)); | ||||
| CustomDataLayer *layer; | CustomDataLayer *layer; | ||||
| eAttrDomain domain; | eAttrDomain domain; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| sculpt_attribute_update_refs(ob); | sculpt_attribute_update_refs(ob); | ||||
| sculpt_update_persistent_base(ob); | sculpt_update_persistent_base(ob); | ||||
| if (need_pmap && ob->type == OB_MESH && !ss->pmap) { | if (need_pmap && ob->type == OB_MESH && !ss->pmap) { | ||||
| BKE_mesh_vert_poly_map_create(&ss->pmap, | BKE_mesh_vert_poly_map_create(&ss->pmap, | ||||
| &ss->pmap_mem, | &ss->pmap_mem, | ||||
| BKE_mesh_polys(me), | BKE_mesh_polys(me), | ||||
| BKE_mesh_loops(me), | me->corner_verts().data(), | ||||
| me->totvert, | me->totvert, | ||||
| me->totpoly, | me->totpoly, | ||||
| me->totloop); | me->totloop); | ||||
| if (ss->pbvh) { | if (ss->pbvh) { | ||||
| BKE_pbvh_pmap_set(ss->pbvh, ss->pmap); | BKE_pbvh_pmap_set(ss->pbvh, ss->pmap); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| int BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, | int BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, | ||||
| Main *bmain, | Main *bmain, | ||||
| Object *ob, | Object *ob, | ||||
| MultiresModifierData *mmd) | MultiresModifierData *mmd) | ||||
| { | { | ||||
| Mesh *me = static_cast<Mesh *>(ob->data); | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| const Span<MPoly> polys = me->polys(); | const Span<MPoly> polys = me->polys(); | ||||
| const Span<MLoop> loops = me->loops(); | const Span<int> corner_verts = me->corner_verts(); | ||||
| int ret = 0; | int ret = 0; | ||||
| const float *paint_mask = static_cast<const float *>( | const float *paint_mask = static_cast<const float *>( | ||||
| CustomData_get_layer(&me->vdata, CD_PAINT_MASK)); | CustomData_get_layer(&me->vdata, CD_PAINT_MASK)); | ||||
| /* if multires is active, create a grid paint mask layer if there | /* if multires is active, create a grid paint mask layer if there | ||||
| * isn't one already */ | * isn't one already */ | ||||
| if (mmd && !CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) { | if (mmd && !CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) { | ||||
| Show All 17 Lines | |||||
| /* if vertices already have mask, copy into multires data */ | /* if vertices already have mask, copy into multires data */ | ||||
| if (paint_mask) { | if (paint_mask) { | ||||
| for (i = 0; i < me->totpoly; i++) { | for (i = 0; i < me->totpoly; i++) { | ||||
| const MPoly *p = &polys[i]; | const MPoly *p = &polys[i]; | ||||
| float avg = 0; | float avg = 0; | ||||
| /* mask center */ | /* mask center */ | ||||
| for (j = 0; j < p->totloop; j++) { | for (j = 0; j < p->totloop; j++) { | ||||
| const MLoop *l = &loops[p->loopstart + j]; | const int vert_i = corner_verts[p->loopstart + j]; | ||||
| avg += paint_mask[l->v]; | avg += paint_mask[vert_i]; | ||||
| } | } | ||||
| avg /= float(p->totloop); | avg /= float(p->totloop); | ||||
| /* fill in multires mask corner */ | /* fill in multires mask corner */ | ||||
| for (j = 0; j < p->totloop; j++) { | for (j = 0; j < p->totloop; j++) { | ||||
| GridPaintMask *gpm = &gmask[p->loopstart + j]; | GridPaintMask *gpm = &gmask[p->loopstart + j]; | ||||
| const MLoop *l = &loops[p->loopstart + j]; | const int vert_i = corner_verts[p->loopstart + j]; | ||||
| const MLoop *prev = ME_POLY_LOOP_PREV(loops, p, j); | const int prev = ME_POLY_LOOP_PREV(p, j); | ||||
| const MLoop *next = ME_POLY_LOOP_NEXT(loops, p, j); | const int next = ME_POLY_LOOP_NEXT(p, j); | ||||
| gpm->data[0] = avg; | gpm->data[0] = avg; | ||||
| gpm->data[1] = (paint_mask[l->v] + paint_mask[next->v]) * 0.5f; | gpm->data[1] = (paint_mask[vert_i] + paint_mask[corner_verts[next]]) * 0.5f; | ||||
| gpm->data[2] = (paint_mask[l->v] + paint_mask[prev->v]) * 0.5f; | gpm->data[2] = (paint_mask[vert_i] + paint_mask[corner_verts[prev]]) * 0.5f; | ||||
| gpm->data[3] = paint_mask[l->v]; | gpm->data[3] = paint_mask[vert_i]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* The evaluated multires CCG must be updated to contain the new data. */ | /* The evaluated multires CCG must be updated to contain the new data. */ | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| if (depsgraph) { | if (depsgraph) { | ||||
| BKE_scene_graph_evaluated_ensure(depsgraph, bmain); | BKE_scene_graph_evaluated_ensure(depsgraph, bmain); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| Mesh *me = BKE_object_get_original_mesh(ob); | Mesh *me = BKE_object_get_original_mesh(ob); | ||||
| const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); | const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); | ||||
| PBVH *pbvh = BKE_pbvh_new(PBVH_FACES); | PBVH *pbvh = BKE_pbvh_new(PBVH_FACES); | ||||
| BKE_pbvh_respect_hide_set(pbvh, respect_hide); | BKE_pbvh_respect_hide_set(pbvh, respect_hide); | ||||
| MutableSpan<float3> positions = me->vert_positions_for_write(); | MutableSpan<float3> positions = me->vert_positions_for_write(); | ||||
| const Span<MPoly> polys = me->polys(); | const Span<MPoly> polys = me->polys(); | ||||
| const Span<MLoop> loops = me->loops(); | const Span<int> corner_verts = me->corner_verts(); | ||||
| MLoopTri *looptri = static_cast<MLoopTri *>( | MLoopTri *looptri = static_cast<MLoopTri *>( | ||||
| MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__)); | MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__)); | ||||
| BKE_mesh_recalc_looptri(loops.data(), | BKE_mesh_recalc_looptri(corner_verts.data(), | ||||
| polys.data(), | polys.data(), | ||||
| reinterpret_cast<const float(*)[3]>(positions.data()), | reinterpret_cast<const float(*)[3]>(positions.data()), | ||||
| me->totloop, | me->totloop, | ||||
| me->totpoly, | me->totpoly, | ||||
| looptri); | looptri); | ||||
| BKE_pbvh_build_mesh(pbvh, | BKE_pbvh_build_mesh(pbvh, | ||||
| me, | me, | ||||
| polys.data(), | polys.data(), | ||||
| loops.data(), | corner_verts.data(), | ||||
| reinterpret_cast<float(*)[3]>(positions.data()), | reinterpret_cast<float(*)[3]>(positions.data()), | ||||
| me->totvert, | me->totvert, | ||||
| &me->vdata, | &me->vdata, | ||||
| &me->ldata, | &me->ldata, | ||||
| &me->pdata, | &me->pdata, | ||||
| looptri, | looptri, | ||||
| looptris_num); | looptris_num); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||