|
|
"And" <49341109@ntnu.edu.tw> wrote:
> "LanuHum" <Lan### [at] yandexru> wrote:
> > "And" <49341109@ntnu.edu.tw> wrote:
> > > "LanuHum" <Lan### [at] yandexru> wrote:
> > > > "And" <49341109@ntnu.edu.tw> wrote:
> > > >
> > > > > Parallel Bezier curve... sounds a challenge. I use Inkscape to do this
operation
> > > > > sometimes.(But only 2-D) Keep it up.
> > > >
> > > > The problem is solved.
> > > > Inkscape won't help. Parallel curves shall have number of control points equal
> > > > to number of control points of the original (sample).
> > > > I will use only the Blender tools.
> > > > Yesterday I already built a parallel bezier curve(3D) in Blender, using Python
> > > > and formulas. :)))))))
> > >
> > > Wow, that's great.
> >
> > It's a go. Parallel curves are constructed automatically.
> > Now control of a UV-mapping is necessary.
>
> Do you write them by yourself? I recall that you ever said your math was not
> good enough to deal with such a thing.
How many there is math?
import bpy
scene = bpy.context.scene
ob = bpy.context.object
cu = ob.parent
pd = cu.data.path_duration
frames = 4*[1]
frames[1] = pd/3
frames[2] = pd/3*2
frames[3] = pd
duplis = []
for i in range(4):
scene.frame_set(frames[i],0.0)
bpy.ops.object.duplicate()
du = bpy.context.object
duplis.append(du)
cu.select = True
scene.objects.active = cu
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
du.select = False
cu.select = False
ob.select = True
scene.objects.active = ob
ob.select = False
bpts = []
for i in range(4):
bpts.append(duplis[i].data.splines[0].bezier_points)
all_coords = []
for i, pt in enumerate(bpts[0]):
coords = []
for p in range(4):
co = duplis[p].matrix_world * bpts[p][i].handle_left
coords.append(co[:])
all_coords.append(coords)
coords = []
for p in range(4):
co = duplis[p].matrix_world * bpts[p][i].co
coords.append(co[:])
all_coords.append(coords)
all_coords.append(coords)
coords = []
for p in range(4):
co = duplis[p].matrix_world * bpts[p][i].handle_right
coords.append(co[:])
all_coords.append(coords)
all_coords.append(all_coords[0])
all_coords.pop(0)
all_coords.append(all_coords[0])
all_coords.pop(0)
cu = None
for i, coords in enumerate(all_coords):
if i % 4 == 0:
cu = bpy.data.curves.new('MyCurve', 'CURVE')
cu.dimensions = '3D'
obj = bpy.data.objects.new('MyCurveObject', cu)
bpy.context.scene.objects.link(obj)
x0 = coords[0][0]
y0 = coords[0][1]
z0 = coords[0][2]
x1 = coords[1][0]
y1 = coords[1][1]
z1 = coords[1][2]
x2 = coords[2][0]
y2 = coords[2][1]
z2 = coords[2][2]
x3 = coords[3][0]
y3 = coords[3][1]
z3 = coords[3][2]
p1x=(-5*x0+18*x1-9*x2+2*x3)/6
p1y=(-5*y0+18*y1-9*y2+2*y3)/6
p1z=(-5*z0+18*z1-9*z2+2*z3)/6
p2x=(2*x0-9*x1+18*x2-5*x3)/6
p2y=(2*y0-9*y1+18*y2-5*y3)/6
p2z=(2*z0-9*z1+18*z2-5*z3)/6
bezier = [((x0,y0,z0),(x0,y0,z0),(p1x,p1y,p1z)),
((x3,y3,z3),(p2x,p2y,p2z),(x3,y3,z3))]
spline = cu.splines.new('BEZIER')
spline.bezier_points.add(1)
for n in range(2):
bpt = spline.bezier_points[n]
bpt.co[:] = bezier[n][0]
bpt.handle_left[:] = bezier[n][1]
bpt.handle_right[:] = bezier[n][2]
Post a reply to this message
|
|