This makes custom mesh attributes available in Cycles. Typically, these attributes are generated by geometry nodes, but they can also be created with a Python script.
Possible todos:
- Support subdivision. Still have to investigate what that actually means exactly and how to test it. Not sure if it is acceptible to merge this without support for it.
- Investigate potential conflicts with sculpt vertex colors (which are a subset of custom attributes). Problem is I don't really know how to use sculpt vertex colors, also they are still an experimental feature, so maybe sculpt vertex colors should check how to interact with generic attributes instead of the other way around.
- (can be improved later) Potentially use different types for integer and bool attributes, currently they just become floats in cycles. This wastes memory in some cases, but I'm not sure how Cycles handles other geometry types internally, or if everything should just be floats.
This script can be used for testing. It simply adds a new attribute that can then be accessed using the Attribute node in Cycles.
import bpy import random attribute_name = "a" mesh = bpy.context.active_object.data try: mesh.attributes.remove(mesh.attributes.get(attribute_name)) except: pass attribute = mesh.attributes.new(attribute_name, "FLOAT_VECTOR", "POLYGON") for value in attribute.data: value.vector = (random.random(), random.random(), random.random())