Page MenuHome

Expose Face Sets to Python
AbandonedPublic

Authored by Toke Stuart Jepsen (tokejepsen) on Mar 30 2021, 11:52 PM.

Details

Reviewers
None
Group Reviewers
Sculpt, Paint & Texture
Summary

First time contributor and c coder, so let me know if I'm doing this wrong.

This revision exposes the face sets to python in the same way that face maps are exposed.

For testing the face sets in python:

import bpy
import bmesh

# Get the active mesh
me = bpy.context.object.data


# Get a BMesh representation
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me)   # fill it in from a Mesh

fs = bm.faces.layers.face_set.verify()

for face in bm.faces:
    face_idx = face.index
    set_idx = face[fs]

    print(f"face {face_idx}, set {set_idx}")

Diff Detail

Repository
rB Blender

Event Timeline

Toke Stuart Jepsen (tokejepsen) requested review of this revision.Mar 30 2021, 11:52 PM
Toke Stuart Jepsen (tokejepsen) created this revision.
Toke Stuart Jepsen (tokejepsen) edited the summary of this revision. (Show Details)
Toke Stuart Jepsen (tokejepsen) edited the summary of this revision. (Show Details)

Face sets, mask and visibility info from the sculpt can't be exposed directly to python (or to other areas of Blender) for editing operations. After editing that data, some internal updates need to happen to keep the state of all visibility flags on the mesh and PBVH in sync.

Face sets, mask and visibility info from the sculpt can't be exposed directly to python (or to other areas of Blender) for editing operations. After editing that data, some internal updates need to happen to keep the state of all visibility flags on the mesh and PBVH in sync.

Could we expose the data for reading only?
Think that is how it works atm with face maps, but not sure at all.

Yes, face sets for read only should be fine.
Better check with @Campbell Barton (campbellbarton) for the Python API changes.

I think it would be preferable to expose face sets as a builtin attribute (we have been talking recently about exposing the builtin attribute to python). I guess maybe that doesn't mean we wouldn't want to expose them here, but maybe it's redundant.

I think it would be preferable to expose face sets as a builtin attribute (we have been talking recently about exposing the builtin attribute to python). I guess maybe that doesn't mean we wouldn't want to expose them here, but maybe it's redundant.

Is there an issue for the builtin attributes?
Would like to add to that conversation about face sets and potentially close this.

@Hans Goudey (HooglyBoogly) @Campbell Barton (campbellbarton) I think this is definitely worth looking into again. A number of addon developers are looking forward to using face sets for their tools.

Face Sets have now been implemented as a generic attribute: D16045
For more info on how this can be used in python: https://wiki.blender.org/wiki/Reference/Release_Notes/3.4/Python_API#Internal_Mesh_Format