help me with export script (armature)


(Blacky_) #1

This is my export script. I am saving whole animation in text file. It works when I rotate object, but every frame is same when I use armature. Why? Somebody suggested Blender.NMesh.GetRawFromObject so I used it, but it changes nothing.


import Blender

def SaveMeshFaces(mesh):
        tempfaces = [];
        for f in mesh.faces:
                if (len(f.v)==3):
                        tempfaces.append(f);

        file.write("faces %i
" % len(tempfaces))
        for f in tempfaces:
                for i in range(len(f.v)):
                        file.write("%i " %  f.v[i].index)
                        file.write("
")
       
def SaveMeshVerts(mesh):
        file.write("vertices %i
" % len(mesh.verts))
        for v in mesh.verts:
                file.write("%f %f %f
" % (v.co.x, v.co.y, v.co.z))
                file.write("%f %f %f
" % (v.no.x, v.no.y, v.no.z))
                file.write("%f %f
"    % (v.uvco.x, v.uvco.y))

def SaveLocRotSize(object):
        file.write("Loc %f %f %f
" % (object.LocX,object.LocY,object.LocZ))
        file.write("Rot %f %f %f
" % (object.RotX,object.RotY,object.RotZ))
        file.write("Size %f %f %f
" % (object.SizeX,object.SizeY,object.SizeZ))

def SaveObjectHeader(object_name):
        mesh = Blender.NMesh.GetRawFromObject(object_name)
        file.write("object %s
" % object_name)
        file.write("mesh %s
" % mesh.name)
        SaveMeshFaces(mesh)

def SaveObject(frame,object_name):
        Blender.Set('curframe',frame)
        object = Blender.Object.Get(object_name)
        mesh = Blender.NMesh.GetRawFromObject(object.name)
        file.write("
frame %i
" % Blender.Get('curframe'))
        SaveLocRotSize(object)
        SaveMeshVerts(mesh)

file = open("scene","w")
file.write("DecopterMetaMesh
")
file.write("frames: %i
" % Blender.Get('endframe'))
file.write("meshes %i
" % len(Blender.Object.getSelected()))
for object in Blender.Object.getSelected():
        SaveObjectHeader(object.name)
        for frame in range(Blender.Get('staframe'),Blender.Get('endframe')+1):
                SaveObject(frame,object.name)
file.write("EndOfMeshes
");
file.close();

Check this script with any animated object. Then check created “scene” textfile. You will notice vertex coordinates in every frame are same.
If you see bug in that code please point me to one, so I could move my game development forward.


(eeshlo) #2

The problem is probably the blender version you use. It works with 2.23 (with the exception of getSelected(), which should be GetSelected()), but doesn’t work in the official 2.25, which doesn’t have a Set() function anymore. So I guess you are using some kind of ‘custom’ Blender version? I tried it with nikolatesla’s version, and although the script does work without change, the mesh is exported without deformation as you said. The various ‘new’ versions of Blender out there have quite a mixed up implementation of the blender python API, so it probably is best to stick with 2.23 for this.