diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
commit | 90b464d3728d9ed8ec26fdf59058d236b99dbcd9 (patch) | |
tree | e88cab4fb1358e962b19f658064ca8c9f8d29f5b /release/scripts/io/export_mdd.py | |
parent | 08d02dd04d836976b25793bb1d4c6a86b3f924c7 (diff) | |
parent | b0b787ef38f9947b3176642556f5282eb3518f69 (diff) |
COLLADA branch: merge from trunk -r 28015:31610.soc-2009-chingachgook
Diffstat (limited to 'release/scripts/io/export_mdd.py')
-rw-r--r-- | release/scripts/io/export_mdd.py | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/release/scripts/io/export_mdd.py b/release/scripts/io/export_mdd.py index be3ddbc73bd..b2eda13fc8f 100644 --- a/release/scripts/io/export_mdd.py +++ b/release/scripts/io/export_mdd.py @@ -48,7 +48,7 @@ Be sure not to use modifiers that change the number or order of verts in the mes # ***** END GPL LICENCE BLOCK ***** import bpy -import Mathutils +import mathutils from struct import pack @@ -65,7 +65,7 @@ def check_vertcount(mesh, vertcount): ''' check and make sure the vertcount is consistent throughout the frame range ''' - if len(mesh.verts) != vertcount: + if len(mesh.vertices) != vertcount: raise Exception('Error, number of verts has changed during animation, cannot export') f.close() zero_file(filepath) @@ -84,17 +84,17 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS): orig_frame = sce.frame_current sce.set_frame(PREF_STARTFRAME) - me = ob.create_mesh(True, 'PREVIEW') + me = ob.create_mesh(sce, True, 'PREVIEW') #Flip y and z - mat_flip = Mathutils.Matrix(\ + mat_flip = mathutils.Matrix(\ [1.0, 0.0, 0.0, 0.0],\ [0.0, 0.0, 1.0, 0.0],\ [0.0, 1.0, 0.0, 0.0],\ [0.0, 0.0, 0.0, 1.0],\ ) - numverts = len(me.verts) + numverts = len(me.vertices) numframes = PREF_ENDFRAME - PREF_STARTFRAME + 1 PREF_FPS = float(PREF_FPS) @@ -113,8 +113,8 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS): """ check_vertcount(me, numverts) - me.transform(mat_flip * ob.matrix) - f.write(pack(">%df" % (numverts * 3), *[axis for v in me.verts for axis in v.co])) + me.transform(mat_flip * ob.matrix_world) + f.write(pack(">%df" % (numverts * 3), *[axis for v in me.vertices for axis in v.co])) for frame in range(PREF_STARTFRAME, PREF_ENDFRAME + 1):#in order to start at desired frame """ @@ -123,15 +123,15 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS): """ sce.set_frame(frame) - me = ob.create_mesh(True, 'PREVIEW') + me = ob.create_mesh(sce, True, 'PREVIEW') check_vertcount(me, numverts) - me.transform(mat_flip * ob.matrix) + me.transform(mat_flip * ob.matrix_world) # Write the vertex data - f.write(pack(">%df" % (numverts * 3), *[axis for v in me.verts for axis in v.co])) + f.write(pack(">%df" % (numverts * 3), *[axis for v in me.vertices for axis in v.co])) """ - me_tmp.verts= None + me_tmp.vertices= None """ f.close() @@ -159,41 +159,49 @@ class ExportMDD(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen=1024) + filepath = StringProperty(name="File Path", description="Filepath used for exporting the MDD file", maxlen=1024) check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default=25) frame_start = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe, max=maxframe, default=1) frame_end = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default=250) - def poll(self, context): + @classmethod + def poll(cls, context): ob = context.active_object return (ob and ob.type == 'MESH') def execute(self, context): - if not self.properties.path: - raise Exception("filename not set") - write(self.properties.path, context.scene, context.active_object, - self.properties.frame_start, self.properties.frame_end, self.properties.fps) + filepath = self.properties.filepath + filepath = bpy.path.ensure_ext(filepath, ".mdd") + + write(filepath, + context.scene, + context.active_object, + self.properties.frame_start, + self.properties.frame_end, + self.properties.fps, + ) + return {'FINISHED'} def invoke(self, context, event): - wm = context.manager - wm.add_fileselect(self) + import os + if not self.properties.is_property_set("filepath"): + self.properties.filepath = os.path.splitext(bpy.data.filepath)[0] + ".mdd" + + context.manager.add_fileselect(self) return {'RUNNING_MODAL'} def menu_func(self, context): - default_path = bpy.data.filename.replace(".blend", ".mdd") - self.layout.operator(ExportMDD.bl_idname, text="Lightwave Point Cache (.mdd)").path = default_path + self.layout.operator(ExportMDD.bl_idname, text="Lightwave Point Cache (.mdd)") def register(): - bpy.types.register(ExportMDD) bpy.types.INFO_MT_file_export.append(menu_func) def unregister(): - bpy.types.unregister(ExportMDD) bpy.types.INFO_MT_file_export.remove(menu_func) if __name__ == "__main__": |