Generate a python script that works in Blender 3.4.1 that creates 200 curves that…
- User
Generate a python script that works in Blender 3.4.1 that creates 200 curves that overlap and combine to look like a road network.
- Assistant
Here's a Python script that works in Blender 3.4.1 to create 200 curves that overlap and combine to look like a road network:
import bpy import random # Set the number of curves to create num_curves = 200 # Create a new collection to hold the curves collection = bpy.data.collections.new("Road Network") bpy.context.scene.collection.children.link(collection) # Loop through and create the curves for i in range(num_curves): # Create a new curve object curve = bpy.data.curves.new("Curve", "CURVE") curve.dimensions = '3D' curve.resolution_u = 2 # Create a new spline and set the control points spline = curve.splines.new('NURBS') spline.points.add(3) spline.points[0].co = (0, 0, 0, 1) spline.points[1].co = (random.uniform(-5, 5), random.uniform(-5, 5), random.uniform(0, 5), 1) spline.points[2].co = (random.uniform(-10, 10), random.uniform(-10, 10), random.uniform(5, 10), 1) spline.points[3].co = (random.uniform(-20, 20), random.uniform(-20, 20), random.uniform(10, 20), 1) # Set the curve object's data and add it to the collection curve_obj = bpy.data.objects.new("Curve_" + str(i), curve) collection.objects.link(curve_obj) # Combine the curves into one object using the Boolean modifier bool_mod = collection.objects[0].modifiers.new(type="BOOLEAN", name="Combine") bool_mod.operation = 'UNION' for i in range(1, num_curves): bool_mod.object = collection.objects[i] bpy.context.view_layer.objects.active = collection.objects[i-1] bpy.ops.object.modifier_apply(modifier="Combine") # Remove the original curve objects for obj in collection.objects: if obj.type == 'CURVE': bpy.data.objects.remove(obj, do_unlink=True) - User
Is it possible to have the curves generated be Bezier curves? How would the above code change, if at all?
- Assistant
Yes, it's possible to generate Bezier curves instead of NURBS curves. Here's the modified code:
import bpy import random # Set the number of curves to create num_curves = 200 # Create a new collection to hold the curves collection = bpy.data.collections.new("Road Network") bpy.context.scene.collection.children.link(collection) # Loop through and create the curves for i in range(num_curves): # Create a new curve object curve = bpy.data.curves.new("Curve", "CURVE") curve.dimensions = '3D' curve.resolution_u = 2 # Create a new spline and set the control points spline = curve.splines.new('BEZIER') spline.bezier_points.add(3) spline.bezier_points[0].co = (0, 0, 0) spline.bezier_points[1].co = (random.uniform(-5, 5), random.uniform(-5, 5), random.uniform(0, 5)) spline.bezier_points[2].co = (random.uniform(-10, 10), random.uniform(-10, 10), random.uniform(5, 10)) spline.bezier_points[3].co = (random.uniform(-20, 20), random.uniform(-20, 20), random.uniform(10, 20)) # Set the curve object's data and add it to the collection curve_obj = bpy.data.objects.new("Curve_" + str(i), curve) collection.objects.link(curve_obj) # Combine the curves into one object using the Boolean modifier bool_mod = collection.objects[0].modifiers.new(type="BOOLEAN", name="Combine") bool_mod.operation = 'UNION' for i in range(1, num_curves): bool_mod.object = collection.objects[i] bpy.context.view_layer.objects.active = collection.objects[i-1] bpy.ops.object.modifier_apply(modifier="Combine") # Remove the original curve objects for obj in collection.objects: if obj.type == 'CURVE': bpy.data.objects.remove(obj, do_unlink=True)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →