Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_ccg.h" | #include "BKE_ccg.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_deform.h" | |||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_mapping.h" | #include "BKE_mesh_mapping.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_multires.h" | #include "BKE_multires.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_object_deform.h" | |||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_pbvh.h" | #include "BKE_pbvh.h" | ||||
| #include "BKE_pointcache.h" | #include "BKE_pointcache.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_subsurf.h" | #include "BKE_subsurf.h" | ||||
| ▲ Show 20 Lines • Show All 9,733 Lines • ▼ Show 20 Lines | static void SCULPT_OT_set_pivot_position(wmOperatorType *ot) | ||||
| RNA_def_enum(ot->srna, | RNA_def_enum(ot->srna, | ||||
| "mode", | "mode", | ||||
| prop_sculpt_pivot_position_types, | prop_sculpt_pivot_position_types, | ||||
| SCULPT_PIVOT_POSITION_UNMASKED, | SCULPT_PIVOT_POSITION_UNMASKED, | ||||
| "Mode", | "Mode", | ||||
| ""); | ""); | ||||
| } | } | ||||
| static int sculpt_mask_to_vertex_group_exec(bContext *C, wmOperator *UNUSED(op)) | |||||
| { | |||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| Mesh *mesh = ob->data; | |||||
| SculptSession *ss = ob->sculpt; | |||||
| PBVH *pbvh = ob->sculpt->pbvh; | |||||
| const int def_nr = ob->actdef - 1; | |||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false); | |||||
| if (BKE_pbvh_type(pbvh) != PBVH_FACES) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| if (!mesh->dvert) { | |||||
| BKE_object_defgroup_data_create(&mesh->id); | |||||
| } | |||||
| MDeformVert *dv = mesh->dvert; | |||||
| if (!dv || def_nr < 0) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| if (!ss->vmask) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| int totvert = sculpt_vertex_count_get(ss); | |||||
| for (int i = 0; i < totvert; i++, dv++) { | |||||
| MDeformWeight *dw; | |||||
| dw = defvert_verify_index(dv, def_nr); | |||||
| if (dw) { | |||||
| dw->weight = sculpt_vertex_mask_get(ss, i); | |||||
| } | |||||
| } | |||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | |||||
| WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void SCULPT_OT_mask_to_vertex_group(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Mask to vertex group"; | |||||
| ot->idname = "SCULPT_OT_mask_to_vertex_group"; | |||||
| ot->description = "Stores the masks values into a vertex group"; | |||||
| /* api callbacks */ | |||||
| ot->exec = sculpt_mask_to_vertex_group_exec; | |||||
| ot->poll = sculpt_mode_poll; | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| } | |||||
| static int sculpt_vertex_group_to_mask_exec(bContext *C, wmOperator *UNUSED(op)) | |||||
| { | |||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| Mesh *mesh = ob->data; | |||||
| SculptSession *ss = ob->sculpt; | |||||
| PBVH *pbvh = ob->sculpt->pbvh; | |||||
| PBVHNode **nodes; | |||||
| int totnode; | |||||
| const int def_nr = ob->actdef - 1; | |||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, false, true); | |||||
| if (BKE_pbvh_type(pbvh) != PBVH_FACES) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| if (!mesh->dvert) { | |||||
| BKE_object_defgroup_data_create(&mesh->id); | |||||
| } | |||||
| MDeformVert *dv = mesh->dvert; | |||||
| if (!dv || def_nr < 0) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| if (!ss->vmask) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); | |||||
| sculpt_undo_push_begin("vertex group to mask"); | |||||
| for (int i = 0; i < totnode; i++) { | |||||
| sculpt_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK); | |||||
| } | |||||
| int totvert = sculpt_vertex_count_get(ss); | |||||
| for (int i = 0; i < totvert; i++, dv++) { | |||||
| MDeformWeight *dw; | |||||
| dw = defvert_verify_index(dv, def_nr); | |||||
| if (dw) { | |||||
| ss->vmask[i] = dw->weight; | |||||
| } | |||||
| } | |||||
| for (int i = 0; i < totnode; i++) { | |||||
| BKE_pbvh_node_mark_update_mask(nodes[i]); | |||||
| } | |||||
| MEM_SAFE_FREE(nodes); | |||||
| sculpt_flush_update_done(C, ob, SCULPT_UPDATE_MASK); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void SCULPT_OT_vertex_group_to_mask(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Vertex Group to Mask"; | |||||
| ot->idname = "SCULPT_OT_vertex_group_to_mask"; | |||||
| ot->description = "Stores the masks values into a vertex group"; | |||||
| /* api callbacks */ | |||||
| ot->exec = sculpt_vertex_group_to_mask_exec; | |||||
| ot->poll = sculpt_mode_poll; | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| } | |||||
| void ED_operatortypes_sculpt(void) | void ED_operatortypes_sculpt(void) | ||||
| { | { | ||||
| WM_operatortype_append(SCULPT_OT_brush_stroke); | WM_operatortype_append(SCULPT_OT_brush_stroke); | ||||
| WM_operatortype_append(SCULPT_OT_sculptmode_toggle); | WM_operatortype_append(SCULPT_OT_sculptmode_toggle); | ||||
| WM_operatortype_append(SCULPT_OT_set_persistent_base); | WM_operatortype_append(SCULPT_OT_set_persistent_base); | ||||
| WM_operatortype_append(SCULPT_OT_dynamic_topology_toggle); | WM_operatortype_append(SCULPT_OT_dynamic_topology_toggle); | ||||
| WM_operatortype_append(SCULPT_OT_optimize); | WM_operatortype_append(SCULPT_OT_optimize); | ||||
| WM_operatortype_append(SCULPT_OT_symmetrize); | WM_operatortype_append(SCULPT_OT_symmetrize); | ||||
| WM_operatortype_append(SCULPT_OT_detail_flood_fill); | WM_operatortype_append(SCULPT_OT_detail_flood_fill); | ||||
| WM_operatortype_append(SCULPT_OT_sample_detail_size); | WM_operatortype_append(SCULPT_OT_sample_detail_size); | ||||
| WM_operatortype_append(SCULPT_OT_set_detail_size); | WM_operatortype_append(SCULPT_OT_set_detail_size); | ||||
| WM_operatortype_append(SCULPT_OT_mesh_filter); | WM_operatortype_append(SCULPT_OT_mesh_filter); | ||||
| WM_operatortype_append(SCULPT_OT_mask_filter); | WM_operatortype_append(SCULPT_OT_mask_filter); | ||||
| WM_operatortype_append(SCULPT_OT_dirty_mask); | WM_operatortype_append(SCULPT_OT_dirty_mask); | ||||
| WM_operatortype_append(SCULPT_OT_mask_expand); | WM_operatortype_append(SCULPT_OT_mask_expand); | ||||
| WM_operatortype_append(SCULPT_OT_set_pivot_position); | WM_operatortype_append(SCULPT_OT_set_pivot_position); | ||||
| WM_operatortype_append(SCULPT_OT_mask_to_vertex_group); | |||||
| WM_operatortype_append(SCULPT_OT_vertex_group_to_mask); | |||||
| } | } | ||||