From my tests, it tends to whiff on the prompts completely. For example, asking for a dead simple vertex shader example with the following prompt:
In Blender, using Python and the gpu module to draw custom GL to the viewport, how would you make a rectangle with rounded corners?
The CSM result is a script that tries to create a beveled plane using bmesh, which- incidentally fails to run due to various exceptions:
import bmesh
import bpy
from mathutils import Matrix
dim = (2, 1)
cnr = 0.2
bm = bmesh.new()
bmesh.ops.create_grid(
bm,
size=0.5,
matrix=Matrix.Diagonal((dim[0], dim[1], 1, 1)) @
Matrix.Translation((0.5, 0.5, 0)),
)
bmesh.ops.bevel(
bm,
geom=bm.verts,
#loop_slide=True,
affect='VERTICES',
profile=0.5, # round
offset=cnr,
segments=5,
)
bmesh.ops.triangulate(
bm,
faces=bm.faces,
)
# scale by 100
bm.transform(
Matrix.Diagonal([100] * 4)
)
# translate by 100, 100
bm.transform(
Matrix.Translation((100, 100, 0))
)
print("vertices = (")
for v in bm.verts:
print(f"\t{v.co.xy[:]},")
print(")")
print("faces = (")
for f in bm.faces:
print(f"\t{[v.index for v in f.verts]},")
bm.to_mesh(bpy.context.object.data)
print(")")
# Set outline width
bpy.data.objects['Mesh'].data.bevel_depth = 0.1
# Hide edge lines
bpy.data.objects['Mesh'].data.show_edge_crease = False
Asking the same thing in ChatGPT gives you a script that also fails to run due to numerous exceptions, but it does at least give a result that is in the ballpark:
import bpy
import gpu
import bgl
from gpu_extras.batch import batch_for_shader
from mathutils import Vector
# Define the shader program
shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'TRI_STRIP', {"pos": [(0, 0), (0, 0), (0, 0), (0, 0)], "radius": 0.1})
# Define the size and position of the rectangle
x, y = 100, 100
width, height = 200, 100
radius = 20
# Calculate the corner vertices
corners = [(x+radius, y+radius), (x+width-radius, y+radius), (x+width-radius, y+height-radius), (x+radius, y+height-radius)]
# Define the vertices of the rectangle
vertices = []
for corner in corners:
vertices.append(corner)
vertices.append((corner[0]+radius, corner[1]))
for i in range(1, 7):
angle = i * (3.14159/4)
vertex = Vector((corner[0]+radius+radius*math.cos(angle), corner[1]+radius+radius*math.sin(angle)))
vertices.append(vertex)
# Set the vertices and radius data for the batch
batch.vertices["pos"] = vertices
batch.vertices["radius"] = [radius] * len(vertices)
# Draw the rectangle to the viewport
bgl.glEnable(bgl.GL_BLEND)
shader.bind()
shader.uniform_float("color", (1.0, 1.0, 1.0, 1.0))
batch.draw(shader)
shader.unbind()
I wouldn’t even call that a nitpick- the double spacing is ROUGH.