bugfix [#19804] .MDD is not working?? // Also filetype issue?

- made all exporters default to the blend filename with the extension replaced
- MDD's poll function now checks for an active mesh
- multiline docstrings are written as multiline docs when generating epydocs
This commit is contained in:
Campbell Barton 2009-11-04 18:35:32 +00:00
parent fe82c2674e
commit 51943096a9
7 changed files with 160 additions and 136 deletions

@ -1109,7 +1109,7 @@ def save_3ds(filename, context):
# Blender.Draw.PupMenu("Error%t|This script requires a full python installation")
# # save_3ds('/test_b.3ds')
from bpy.props import *
class EXPORT_OT_autodesk_3ds(bpy.types.Operator):
class Export3DS(bpy.types.Operator):
'''Export to 3DS file format (.3ds).'''
bl_idname = "export.autodesk_3ds"
bl_label = 'Export 3DS'
@ -1135,9 +1135,13 @@ class EXPORT_OT_autodesk_3ds(bpy.types.Operator):
print("Poll")
return context.active_object != None
bpy.ops.add(EXPORT_OT_autodesk_3ds)
bpy.ops.add(Export3DS)
# Add to a menu
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.autodesk_3ds", text="Autodesk 3DS...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".3ds")
self.layout.item_stringO(Export3DS.bl_idname, "path", default_path, text="Autodesk 3DS...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)

@ -3351,7 +3351,7 @@ def write_ui():
# GLOBALS.clear()
from bpy.props import *
class EXPORT_OT_fbx(bpy.types.Operator):
class ExportFBX(bpy.types.Operator):
'''Selection to an ASCII Autodesk FBX'''
bl_idname = "export.fbx"
bl_label = "Export FBX"
@ -3433,7 +3433,7 @@ class EXPORT_OT_fbx(bpy.types.Operator):
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_fbx)
bpy.ops.add(ExportFBX)
# if __name__ == "__main__":
# bpy.ops.EXPORT_OT_ply(filename="/tmp/test.ply")
@ -3464,6 +3464,10 @@ bpy.ops.add(EXPORT_OT_fbx)
# Add to a menu
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.fbx", text="Autodesk FBX...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".fbx")
self.layout.item_stringO(ExportFBX.bl_idname, "path", default_path, text="Autodesk FBX...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)

@ -54,148 +54,148 @@ import os
#from Blender import *
#import BPyMessages
try:
from struct import pack
from struct import pack
except:
pack = None
pack = None
def zero_file(filepath):
'''
If a file fails, this replaces it with 1 char, better not remove it?
'''
file = open(filepath, 'w')
file.write('\n') # apparently macosx needs some data in a blank file?
file.close()
'''
If a file fails, this replaces it with 1 char, better not remove it?
'''
file = open(filepath, 'w')
file.write('\n') # apparently macosx needs some data in a blank file?
file.close()
def check_vertcount(mesh,vertcount):
'''
check and make sure the vertcount is consistent throughout the frame range
'''
if len(mesh.verts) != vertcount:
raise Exception('Error, number of verts has changed during animation, cannot export')
f.close()
zero_file(filepath)
return
'''
check and make sure the vertcount is consistent throughout the frame range
'''
if len(mesh.verts) != vertcount:
raise Exception('Error, number of verts has changed during animation, cannot export')
f.close()
zero_file(filepath)
return
def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS):
if not pack:
raise Exception('Error, this script requires the "pack" module')
if ob.type != 'MESH':
raise Exception('Error, active object is not a mesh')
"""
Window.EditMode(0)
Blender.Window.WaitCursor(1)
"""
Blender.Window.WaitCursor(1)
mesh_orig = Mesh.New()
mesh_orig.getFromObject(ob.name)
"""
orig_frame = sce.current_frame
sce.set_frame(PREF_STARTFRAME)
me = ob.create_mesh(True, 'PREVIEW')
mesh_orig = Mesh.New()
mesh_orig.getFromObject(ob.name)
"""
#Flip y and z
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],\
)
bpy.ops.object.mode_set(mode='OBJECT')
numverts = len(me.verts)
orig_frame = sce.current_frame
sce.set_frame(PREF_STARTFRAME)
me = ob.create_mesh(True, 'PREVIEW')
numframes = PREF_ENDFRAME-PREF_STARTFRAME+1
PREF_FPS= float(PREF_FPS)
f = open(filename, 'wb') #no Errors yet:Safe to create file
# Write the header
f.write(pack(">2i", numframes, numverts))
# Write the frame times (should we use the time IPO??)
f.write( pack(">%df" % (numframes), *[frame/PREF_FPS for frame in range(numframes)]) ) # seconds
#rest frame needed to keep frames in sync
"""
Blender.Set('curframe', PREF_STARTFRAME)
me_tmp.getFromObject(ob.name)
"""
#Flip y and z
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],\
)
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]))
for frame in range(PREF_STARTFRAME,PREF_ENDFRAME+1):#in order to start at desired frame
"""
Blender.Set('curframe', frame)
me_tmp.getFromObject(ob.name)
"""
numverts = len(me.verts)
sce.set_frame(frame)
me = ob.create_mesh(True, 'PREVIEW')
check_vertcount(me,numverts)
me.transform(mat_flip * ob.matrix)
# Write the vertex data
f.write(pack(">%df" % (numverts*3), *[axis for v in me.verts for axis in v.co]))
"""
me_tmp.verts= None
"""
f.close()
print ('MDD Exported: %s frames:%d\n'% (filename, numframes-1))
"""
Blender.Window.WaitCursor(0)
Blender.Set('curframe', orig_frame)
"""
sce.set_frame(orig_frame)
numframes = PREF_ENDFRAME-PREF_STARTFRAME+1
PREF_FPS= float(PREF_FPS)
f = open(filename, 'wb') #no Errors yet:Safe to create file
# Write the header
f.write(pack(">2i", numframes, numverts))
# Write the frame times (should we use the time IPO??)
f.write( pack(">%df" % (numframes), *[frame/PREF_FPS for frame in range(numframes)]) ) # seconds
#rest frame needed to keep frames in sync
"""
Blender.Set('curframe', PREF_STARTFRAME)
me_tmp.getFromObject(ob.name)
"""
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]))
for frame in range(PREF_STARTFRAME,PREF_ENDFRAME+1):#in order to start at desired frame
"""
Blender.Set('curframe', frame)
me_tmp.getFromObject(ob.name)
"""
sce.set_frame(frame)
me = ob.create_mesh(True, 'PREVIEW')
check_vertcount(me,numverts)
me.transform(mat_flip * ob.matrix)
# Write the vertex data
f.write(pack(">%df" % (numverts*3), *[axis for v in me.verts for axis in v.co]))
"""
me_tmp.verts= None
"""
f.close()
print ('MDD Exported: %s frames:%d\n'% (filename, numframes-1))
"""
Blender.Window.WaitCursor(0)
Blender.Set('curframe', orig_frame)
"""
sce.set_frame(orig_frame)
from bpy.props import *
class EXPORT_OT_mdd(bpy.types.Operator):
'''Animated mesh to MDD vertex keyframe file.'''
bl_idname = "export.mdd"
bl_label = "Export MDD"
class ExportMDD(bpy.types.Operator):
'''Animated mesh to MDD vertex keyframe file.'''
bl_idname = "export.mdd"
bl_label = "Export MDD"
# get first scene to get min and max properties for frames, fps
# get first scene to get min and max properties for frames, fps
sce = bpy.data.scenes[bpy.data.scenes.keys()[0]]
minframe = sce.rna_type.properties["current_frame"].soft_min
maxframe = sce.rna_type.properties["current_frame"].soft_max
minfps = sce.render_data.rna_type.properties["fps"].soft_min
maxfps = sce.render_data.rna_type.properties["fps"].soft_max
sce = bpy.data.scenes[bpy.data.scenes.keys()[0]]
minframe = sce.rna_type.properties["current_frame"].soft_min
maxframe = sce.rna_type.properties["current_frame"].soft_max
minfps = sce.render_data.rna_type.properties["fps"].soft_min
maxfps = sce.render_data.rna_type.properties["fps"].soft_max
# 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, default= "tmp.mdd")
fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25)
start_frame = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1)
end_frame = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250)
# 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, default= "tmp.mdd")
fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25)
start_frame = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1)
end_frame = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250)
def poll(self, context):
return context.active_object != None
def poll(self, context):
ob = context.active_object
return (ob and ob.type=='MESH')
def execute(self, context):
if not self.path:
raise Exception("filename not set")
write(self.path, context.scene, context.active_object,
self.start_frame, self.end_frame, self.fps )
return ('FINISHED',)
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
def execute(self, context):
if not self.path:
raise Exception("filename not set")
write(self.path, context.scene, context.active_object,
self.start_frame, self.end_frame, self.fps )
return ('FINISHED',)
def invoke(self, context, event):
wm = context.manager
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_mdd)
bpy.ops.add(ExportMDD)
# Add to a menu
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.mdd", text="Vertex Keyframe Animation (.mdd)...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".mdd")
self.layout.item_stringO(ExportMDD.bl_idname, "path", default_path, text="Vertex Keyframe Animation (.mdd)...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
if __name__=='__main__':
#if not pack:
# Draw.PupMenu('Error%t|This script requires a full python install')
#Blender.Window.FileSelector(mdd_export_ui, 'EXPORT MDD', sys.makename(ext='.mdd'))
bpy.ops.EXPORT_OT_mdd(path="/tmp/test.mdd")
#Blender.Window.FileSelector(mdd_export_ui, 'EXPORT MDD', sys.makename(ext='.mdd'))
bpy.ops.EXPORT_OT_mdd(path="/tmp/test.mdd")

@ -932,7 +932,7 @@ Currently the exporter lacks these features:
from bpy.props import *
class EXPORT_OT_obj(bpy.types.Operator):
class ExportOBJ(bpy.types.Operator):
'''Save a Wavefront OBJ File'''
bl_idname = "export.obj"
@ -1002,10 +1002,14 @@ class EXPORT_OT_obj(bpy.types.Operator):
print("Poll")
return context.active_object != None
bpy.ops.add(EXPORT_OT_obj)
bpy.ops.add(ExportOBJ)
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.obj", text="Wavefront (.obj)...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".obj")
self.layout.item_stringO(ExportOBJ.bl_idname, "path", default_path, text="Wavefront (.obj)...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
if __name__ == "__main__":

@ -252,7 +252,7 @@ def write(filename, scene, ob, \
from bpy.props import *
class EXPORT_OT_ply(bpy.types.Operator):
class ExportPLY(bpy.types.Operator):
'''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
bl_idname = "export.ply"
bl_label = "Export PLY"
@ -292,10 +292,14 @@ class EXPORT_OT_ply(bpy.types.Operator):
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_ply)
bpy.ops.add(ExportPLY)
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.ply", text="Stanford (.ply)...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".ply")
self.layout.item_stringO(ExportPLY.bl_idname, "path", default_path, text="Stanford (.ply)...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
if __name__ == "__main__":

@ -1215,7 +1215,7 @@ def x3d_export_ui(filename):
from bpy.props import *
class EXPORT_OT_x3d(bpy.types.Operator):
class ExportX3D(bpy.types.Operator):
'''Export selection to Extensible 3D file (.x3d)'''
bl_idname = "export.x3d"
bl_label = 'Export X3D'
@ -1238,10 +1238,14 @@ class EXPORT_OT_x3d(bpy.types.Operator):
wm.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(EXPORT_OT_x3d)
bpy.ops.add(ExportX3D)
import dynamic_menu
menu_func = lambda self, context: self.layout.itemO("export.x3d", text="X3D Extensible 3D (.x3d)...")
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".x3d")
self.layout.item_stringO(ExportX3D.bl_idname, "path", default_path, text="X3D Extensible 3D (.x3d)...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
# NOTES

@ -170,11 +170,11 @@ def write_func(rna, ident, out, func_type):
# Operators and functions work differently
if func_type=='OPERATOR':
rna_func_name = rna_struct.identifier.split("_OT_")[-1]
rna_func_desc = rna_struct.description.strip().replace('\n', ' ')
rna_func_desc = rna_struct.description.strip()
items = rna_struct.properties.items()
else:
rna_func_name = rna.identifier
rna_func_desc = rna.description.strip().replace('\n', ' ')
rna_func_desc = rna.description.strip()
items = rna.parameters.items()
@ -288,7 +288,11 @@ def write_func(rna, ident, out, func_type):
out.write(ident+'def %s(%s):\n' % (rna_func_name, ', '.join(kw_args)))
out.write(ident+'\t"""\n')
out.write(ident+'\t%s\n' % rna_func_desc)
# Descriptions could be multiline
for rna_func_desc_line in rna_func_desc.split('\n'):
out.write(ident+'\t%s\n' % rna_func_desc_line.strip())
for desc in kw_arg_attrs:
out.write(ident+'\t%s\n' % desc)