-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.py
31 lines (24 loc) · 1.03 KB
/
path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import bpy
import random
def generate_curve(offset: tuple[float, float, float], scale: float, point_count: int, seed: int) -> bpy.types.Object:
random.seed(seed)
if point_count < 4:
raise ValueError("each curve must have at least 4 points")
curve_data = bpy.data.curves.new(name='MyCurve', type='CURVE')
curve_data.dimensions = '3D'
curve_data.resolution_u = 12
# Create a new spline in the curve
spline = curve_data.splines.new(type='BEZIER')
spline.bezier_points.add(point_count - 1)
# Set coordinates for the points
points = spline.bezier_points
for i, point in enumerate(points):
x = random.uniform(-scale, scale) + offset[0]
y = random.uniform(-scale, scale) + offset[1]
z = random.uniform(-scale, scale) + offset[2]
point.co = (x, y, z)
point.handle_left_type = 'AUTO'
point.handle_right_type = 'AUTO'
curve_obj = bpy.data.objects.new('MyCurveObject', curve_data)
bpy.context.scene.collection.objects.link(curve_obj)
return curve_obj