i have a 2d bezier curve with 4 handles in blender which looks like this:
using this python code i’m trying to convert it into a shape path
import bpy
curve = bpy.data.curves['BezierCircle']
path_string = "const shape = new Shape()\n"
for spline in curve.splines:
if spline.type == 'BEZIER':
start_point = spline.bezier_points[0].co
path_string += ".moveTo(" + str(start_point[0]) + "," + str(start_point[1]) + ")\n"
for i, point in enumerate(spline.bezier_points):
x = point.co[0]
y = point.co[1]
handle_left_x=point.handle_left[0]
handle_left_y = point.handle_left[1]
handle_right_x = point.handle_right[0]
handle_right_y= point.handle_right[1]
path_string += ".bezierCurveTo(" + str(handle_left_x) + "," + str(handle_left_y) + "," + str(handle_right_x) + "," + str(handle_right_y) + "," + str(x) + "," + str(y) + ")\n"
print(path_string)
which prints
const shape = new Shape()
.moveTo(-0.5, 0.0)
.bezierCurveTo(-0.5, -0.2, -0.5, 0.2, -0.5, 0.0)
.bezierCurveTo(-0.2, 0.5, 0.2, 0.5, 0.0, 0.5)
.bezierCurveTo(0.5, 0.2, 0.5, -0.2, 0.5, 0.0)
.bezierCurveTo(0.2, -0.5, -0.2, -0.5, 0.0, -0.5)
on using this as a shapeGeomtery in three js
the shape looks broken
are there any mistakes here ?
the syntax i’m using is
bezierCurveTo( handle_x1 ,handle_y1 ,handle_x2 ,handle_y2, x ,y )