I'm trying to access faces assigned to face maps groups. However, I couldn't find any relevant example of how to do it.
I need to get information about the face included in a certain face map. Is it possible to reach such information?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityI'm trying to access faces assigned to face maps groups. However, I couldn't find any relevant example of how to do it.
I need to get information about the face included in a certain face map. Is it possible to reach such information?
You can get an array of map indices with the following code.
>>> [m_face_map.value for m_face_map in obj.data.face_maps.active.data]
[0, 1, 0, 1, 0, 2, 1, 2, 0, 0, 0, 1, 0, 0, 0, 0, 2, 1, 1, 1, 0, 0, 0, 0]
However, it must be in object mode. In edit mode you get an empty array.
import bpy
# Important to run in object mode
bpy.ops.object.mode_set()
obj = bpy.context.object
# bpy_prop_collection of FaceMap
face_maps = obj.face_maps
# bpy_prop_collection of MeshFaceMap
mesh_face_maps = obj.data.face_maps.active.data
for i, mesh_face_map in enumerate(mesh_face_maps):
if i >= 8:
break
print(f"faces[{i}]: {face_maps[mesh_face_map.value].name}")
""" OUTPUT
faces[0]: FaceMap
faces[1]: FaceMap.001
faces[2]: FaceMap
faces[3]: FaceMap.001
faces[4]: FaceMap
faces[5]: FaceMap.002
faces[6]: FaceMap.001
faces[7]: FaceMap.002
"""