3
$\begingroup$

I am working on multiple objects all required to preserve some details, which can be done using masking in sculpting.

Can any one help me with a script which can mask first/single faceset on one click.

Or any other way where I dont have to hide/show the faceset again and again.

$\endgroup$
2
  • 1
    $\begingroup$ Why not just use the Automask option for Face Sets in the Tool settings (1)? It will limit the effect of the brush to the face set under the mouse pointer when you start painting (2) => i.sstatic.net/BlUmA.jpg $\endgroup$
    – Blunder
    Commented Sep 18, 2022 at 11:19
  • $\begingroup$ I need to mask that face set, remove the face sets then smooth the whole mask so the sculpting effect looks even $\endgroup$
    – Sam316911
    Commented Sep 19, 2022 at 18:24

2 Answers 2

3
$\begingroup$

You can mask a face set by pressing Shift+A to create a mask that starts on the face set, and then hold Ctrl to make it fill one (or more) face sets.

Blender sculpt mode mask creation while holding CTRL to snap to multiple face sets

$\endgroup$
2
$\begingroup$

Here is an add-on script that creates a mask from the face set under the mouse pointer on a single key press. Shortcut key is Y. The menu entry is located under View3D > Mask > Mask From Face Set in Sculpt mode.

The operator is only four lines but for the shortcut key, a few more lines are required.

bl_info = {
    "name": "Mask From Face Set",
    "description": "Creates a mask from the face set under the mouse.",
    "author": "Blunder",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Mask > Mask From Face Set",
    "support": "COMMUNITY",
    "category": "Sculpt",
}

import bpy

class MaskFromFaceSetOperator(bpy.types.Operator):
    bl_idname = "wm.mask_from_face_set"
    bl_label = "Mask From Face Set Operator"

    def execute(self, context):
        bpy.ops.paint.mask_flood_fill(mode='VALUE', value=0)
        bpy.ops.sculpt.face_set_change_visibility(mode='TOGGLE')
        bpy.ops.paint.mask_flood_fill(mode='INVERT')
        bpy.ops.sculpt.face_set_change_visibility(mode='SHOW_ALL')
        return {'FINISHED'}

# Only needed if you want to add into a dynamic menu.
def menu_func(self, context):
    self.layout.operator(MaskFromFaceSetOperator.bl_idname, text="Mask From Face Set")

# store keymaps here to access after registration
addon_keymaps = []

# Register and add to the mask menu (required to also use F3 search "Mask From Face Set Operator" for quick access).
def register():
    bpy.utils.register_class(MaskFromFaceSetOperator)
    bpy.types.VIEW3D_MT_mask.append(menu_func)
    
    # handle the keymap
    wm = bpy.context.window_manager
    # Note that in background mode (no GUI available), keyconfigs are not available either,
    # so we have to check this to avoid nasty errors in background case.
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='Sculpt', space_type='EMPTY')
        kmi = km.keymap_items.new(MaskFromFaceSetOperator.bl_idname, 'Y', 'PRESS', ctrl=False, shift=False)
        addon_keymaps.append((km, kmi))

def unregister():
    # handle the keymap
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    
    bpy.utils.unregister_class(MaskFromFaceSetOperator)
    bpy.types.VIEW3D_MT_mask.remove(menu_func)

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ Thank you for sharing! As of 3.6.1, this line needs to be changed: bpy.ops.sculpt.face_set_change_visibility(mode='SHOW_ALL') to bpy.ops.sculpt.reveal_all() $\endgroup$ Commented Jul 31, 2023 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .