设置几何体颜色属性渲染。
bpy.ops.geometry.color_attribute_render_set(location="", name="", value="")
以下示例演示如何使用此操作来设置颜色属性渲染。
import bpy
# 创建一个圆型的mesh
mesh = bpy.data.meshes.new("circle")
obj = bpy.data.objects.new("circle_obj", mesh)
bpy.context.scene.objects.link(obj)
verts = []
edges = []
faces = [(0, 1, 2)]
verts.append((0.0, 0.0, 0.0))
for i in range(10):
theta = i * (2 * 3.14) / 10
verts.append((0.5 * cos(theta), 0.5 * sin(theta), 0.0))
edges = [(i, i+1) for i in range(len(verts)-1)]
edges.append((len(verts)-1, 0))
mesh.from_pydata(verts, edges, faces)
mesh.validate(True)
# 设置随机的颜色属性
from random import uniform
for i in range(len(verts)):
mesh.vertex_colors.new()
mesh.vertex_colors.active.data[i].color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1)
# 渲染顶点颜色
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.context.scene.objects.active = obj
bpy.ops.object.vertex_color_paint_toggle()
bpy.ops.geometry.color_attribute_render_set(location="EDGES", name="Col", value=0.5)
输出:
对象模式下,可见圆组成的蓝色网格。顶点颜色绘画模式下,渲染了线条边缘的顶点颜色。