0
$\begingroup$

Is it possible to transfer the vertex colours in a mesh from the rbg channels to the alpha channel after they have been desaturated? thanks.

I tried using chatGPT to create a script to do it but instead of transferring to the alpha channel of the vertex it created a new color attribute later called 'alpha' and copied the data to that instead.

    import bpy
import bmesh

# Get the active object and its mesh data
obj = bpy.context.active_object
mesh = obj.data

# Get the active vertex color layer
color_layer = mesh.vertex_colors.active

if color_layer is None:
    raise ValueError("No active vertex color layer found")

# Create a new vertex color layer for the alpha channel
alpha_layer = mesh.vertex_colors.new(name="Alpha")

# Get the mesh's bmesh data
bm = bmesh.new()
bm.from_mesh(mesh)

# Iterate through each vertex and transfer the RGB channels to the alpha channel
for vertex in bm.verts:
    color = color_layer.data[vertex.index].color
    alpha = sum(color) / 3.0  # Take the average of the RGB channels to calculate the alpha
    alpha_layer.data[vertex.index].color = (0.0, 0.0, 0.0, alpha)

# Update the bmesh data and mesh data
bm.to_mesh(mesh)
bm.free()
mesh.update()
$\endgroup$

1 Answer 1

2
$\begingroup$

You can convert using Geometry Nodes:

The setup to draw on one monkey and see the alpha on another is based on the monkey having the ⎇ AltD linked-duplicate (and the geonodes modifier is on the duplicate), as well as a shader:

If you wanted to keep the color, you could do something like this:

$\endgroup$
1
  • $\begingroup$ Thanks very much for this detailed reply, I will try it out as soon as possible and let you know how I got on. $\endgroup$ May 3 at 9:10

You must log in to answer this question.

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