# Generate geometry using geometry shader

I have some points which represent polylines. I want to convert this polylines into geometry for which I am creating a curve and an object containing this object.

    curveData = bpy.data.curves.new('myCurve', type='CURVE')
curveData.dimensions = '3D'
curveData.bevel_resolution = 0
curveData.bevel_depth = 1

polyline = curveData.splines.new(type='POLY')
for point, node in zip(polyline.points, yarn):
point.co = positions[node]

# create Object
obj = bpy.data.objects.new('yarn', curveData)
obj.active_material = mat


This code normally works fine, but for some data sets that I have it takes ages to generate all the geometry I need (~ 15 minutes).

I want to know if there is any way to send the points in my data set to the GPU and use a geometry shader to create the geoemtry I want to render. I would like to render it using the Principled BSDF shader, so the geometry shader should produce data for this shader.

• How many spline points do you have in this context? – lemon Sep 25 '19 at 14:52
• I have around 20K splines. The number of control points for each spline may vary, but around 500 – jjcasmar Sep 25 '19 at 14:53
• I think you should generate all the splines in the same object. That will accelerate the generation. Though, that will be around 40 millions of vertices as result (so may be slow for several things) – lemon Sep 25 '19 at 15:36
• How can I generate all the splines in the same object? Im not sure how can I say where a spline end and where the next one begins. – jjcasmar Sep 25 '19 at 15:46

A workaround can be generating all the splines in the same object.

Should be around 1 minute or less from the given information (20K splines of 500 vertices). Of course here, I've used generated coordinates.

import bpy

n_curves = 20000
n_points = 500

curveData = bpy.data.curves.new('myCurve', type='CURVE')
curveData.dimensions = '3D'
curveData.bevel_resolution = 0
curveData.bevel_depth = 1

for i in range( n_curves ):

# splines.new adds a new spline inside the data (in the same object)
polyline = curveData.splines.new(type='POLY')

for n, point in zip( range( n_points ), polyline.points ):
point.co = (n, 2*i, 0, 1)

# create Object
obj = bpy.data.objects.new('yarn', curveData)
#obj.active_material = mat