0
$\begingroup$

I am trying to export a Bezier curve I have animated. This is what I have so far:

def getBezierPathNode(doc, frames, obj):
    node = doc.createElement("vertices")    

    for i in range(len(bpy.data.objects[obj].data.splines[0].bezier_points)):
        vertex = doc.createElement("vertex")
        vertex.setAttribute("id", str(i+1))
        attenuation = doc.createElement("attenuation")
        attenuation.appendChild(doc.createTextNode(str(0.5)))
        vertex.appendChild(attenuation)

        for fn, f in enumerate(frames):
            bpy.context.scene.frame_set(f)
            o = bpy.data.objects[obj]
            points = o.data.splines[0].bezier_points
            point = points[i]
            print((f,point.co))
            frame = doc.createElement("frame")
            frame.setAttribute("num", str(fn))
            setPoint(o, frame, "", point.co)
            setPoint(o, frame, "a", point.handle_right)
            if i < len(points)-1:
                setPoint(o, frame, "b", points[i+1].handle_left)
            else:
                setPoint(o, frame, "b", point.co)
            vertex.appendChild(frame)

            node.appendChild(vertex)

    node.setAttribute("num", str(len(points)))
    node.setAttribute("frames", str(len(frames)))
    return node

def getFrames():
    frames = []

    for action in bpy.data.actions:
        for fcurve in action.fcurves:
            for k in fcurve.keyframe_points:
                fr = k.co[0]
                frames.append(fr)

    frames = list(set(frames))
    frames.sort()
    return frames

frames = getFrames()
doc = Document()
for obj in bpy.data.objects:
    if obj.type == 'CURVE':
        node.appendChild(getBezierPathNode(doc, frames, obj.name))

This outputs the following data (in the print statement):

(0.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(10.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(20.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(30.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(40.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(100.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(0.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(10.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(20.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(30.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(40.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(100.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(0.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(10.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(20.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(30.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(40.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(100.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(0.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(10.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(20.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(30.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(40.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(100.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(0.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(10.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(20.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(30.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(40.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(100.0, Vector((-2.7375922203063965, 1.0250422954559326, 0.0)))
(0.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(10.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(20.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(30.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(40.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(100.0, Vector((-2.364258289337158, 0.9919000864028931, 0.0)))
(0.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(10.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(20.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(30.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(40.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(100.0, Vector((-2.0551865100860596, 4.03302001953125, 0.0)))
(0.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(10.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(20.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(30.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(40.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))
(100.0, Vector((-1.7511816024780273, 4.02277135848999, 0.0)))

No animations has taken place! Does anyone know how to make this work correctly? The Bezier curves are animated in the 3D view when I change the keyframe with frame_set

$\endgroup$
  • $\begingroup$ The main problem seems to be that the curve positions and handles are not updated when changing the animation frame, even though they are updated 3D view $\endgroup$ – nulvinge May 21 '14 at 14:32
  • $\begingroup$ How are you animating the curve? $\endgroup$ – ideasman42 May 21 '14 at 15:13
  • $\begingroup$ I create a couple of animation shapes in the curves panel. Then I made keyframes with them by pressing "I" over they animation key $\endgroup$ – nulvinge May 21 '14 at 17:47
  • $\begingroup$ To clarify: I created a Bezier curve, then modified it with some shape keys. I then created keyframes with these shape keys. $\endgroup$ – nulvinge May 22 '14 at 5:56
1
$\begingroup$

The issue is that the shape keys aren't changing the original data. (they are non-distructive which is intentional).

But in this case you want the curve after deformation.

You can get the curve as a mesh, however this will have the bezier splines bakes into vertices.

Posting this as an answer since nobody else stepped in, but Ill have to check if the API has some way to accessed the deformed curve.

$\endgroup$
  • $\begingroup$ I found a way to access the shape keys, but that is a hacky solution. Why are shape keys intentionally non-destructive? $\endgroup$ – nulvinge May 26 '14 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.