Fairly new to blender python, though have some experience with python outside of blender, I'm trying to work out why this bit of code is only ever working on the first color attribute and not the currently selected one.
def paint_map(self, mesh, map, color):
i = 0
for poly in mesh.polygons:
for _ in poly.loop_indices:
map[i].color = color
i += 1
def paint_mesh(self, mesh, color):
if len(mesh.vertex_colors) == 0:
mesh.vertex_colors.new()
self.paint_map(mesh, mesh.vertex_colors.active.data, color)
def run(self, context):
objs = context.selected_objects
if len(objs) > 0:
for obj in objs:
if obj.sollum_type == SollumType.DRAWABLE_GEOMETRY:
self.paint_mesh(obj.data, self.color)
self.messages.append(
f"{obj.name} was successfully painted.")
else:
self.messages.append(
f"{obj.name} will be skipped because it is not a {SOLLUMZ_UI_NAMES[SollumType.DRAWABLE_GEOMETRY]} type.")
else:
self.message("No objects selected to paint.")
return False
return True
how this code currently behaves https://i.stack.imgur.com/oEix4.jpg
Whilst researching the online documentation I noticed that mesh.vertex_colors is depreciated and its best to use color_attributes moving forward. I've played around with it a bit and can't wrap my head around it.
I did notice if I do the following
print(bpy.data.meshes["Mesh.001"].attributes.active_color)
within the python console it does indeed return the selected color attribute, I can't however work out how to rework the current codebase to use it however.
Python console tests https://i.stack.imgur.com/G9f1q.jpg
If someone could help me work out how to get and use the currently selected color attribute of the selected meshes I'd be very grateful! Thanks in advance! CuppaT