简体   繁体   中英

Vertex animation exporter for Blender?

I really want to write an export script for Blender that exports vector animations (like md2) but I can't seem to grab the vertecies that are modiefied by bones... I've written static exporters, but getting tranformed vertex points is sort of beyond me...

Is there a way to easily grab the locations of a vertex that is being animated by bones at certain frames? Currently I'm making blender Animations, exporting each frame to *.obj, importing each frame into a new scene and exporting each new model with my static model script to export the new vector locations... There must be an easier (and faster) way!

Does anyone know of any tutorials or point out any commands/methods that might help?

I'm really not that good with python so my current exporter is a bit badly written... I was hoping to display the code here in a code box, but I can't figure out how to display python code in a codeblock here.... Sorry about that.

First, the source. It assumes that you skeletal animated object is called 'Cube'.

import bpy

o = bpy.data.objects['Cube']

frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end

for i in range(frame_start, frame_end):
    bpy.context.scene.frame_set(i)
    bpy.context.scene.update()

    m = o.to_mesh(bpy.context.scene, True, 'PREVIEW')

    print("Frame %d:" % i)

    for v in m.vertices:
        print("    (%f %f %f)" % (v.co.x, v.co.y, v.co.z))

    print("\n")

Then we'll go through each line. We start by importing the Blender Python module.

import bpy

We retrieve the object whose vertices we want to export.

o = bpy.data.objects['Cube']

We retrieve the start and end frame of the animation; these two values are those that show up at the bottom of the screen and that default to "Start: 1" and "End: 250".

frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end

Then we iterate over each frame between the first and the last one.

for i in range(frame_start, frame_end):

We set the current frame; note that the seemingly equivalent call (*bpy.ops.anim.change_frame(frame = i)* would not work properly. If anyone has an explanation for it I please feel free to share :-)).

    bpy.context.scene.frame_set(i)

The call to update doesn't seem to be necessary, but it's better to have it because it will force all updates dependent on frame position (that is, animations).

    bpy.context.scene.update()

We convert the object to a mesh, applying all modifiers (including Armature) according to their Preview settings.

    m = o.to_mesh(bpy.context.scene, True, 'PREVIEW')

We print current frame number.

    print("Frame %d:" % i)

We print all vertices for that frame, one per line.

    for v in m.vertices:
        print("    (%f %f %f)" % (v.co.x, v.co.y, v.co.z))

We separate vertices of different frames with a newline.

    print("\n")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM