OSDN Git Service

implement shape key
[meshio/pymeshio.git] / blender26-meshio / __init__.py
1 # coding: utf-8
2
3 bl_info={
4         'category': 'Import-Export',
5         'name': 'meshio. (.pmd)(.pmx)(.mqo)',
6         'author': 'ousttrue',
7         'blender': (2, 6, 0),
8         'location': 'File > Import-Export',
9         'description': 'Import-Export PMD/PMX/MQO meshes',
10         'warning': 'pmx importer/exporter is under development', 
11         'wiki_url': 'http://meshio.sourceforge.jp/',
12         'support': 'COMMUNITY',
13         }
14
15
16 # To support reload properly, try to access a package var, if it's there, reload everything
17 if 'bpy' in locals():
18     import imp
19     def reload_module(name):
20         if name in locals():
21             imp.reaload(locals()[name])
22     reload_module('import_pmx')
23     reload_module('export_pmx')
24     reload_module('import_pmd')
25     reload_module('export_pmd')
26     reload_module('import_mqo')
27     reload_module('export_mqo')
28    
29
30 import bpy
31 import bpy_extras.io_utils
32 from . import bl
33
34
35 class ImportPmd(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
36     '''Import from PMD file format (.pmd)'''
37     bl_idname = 'import_scene.mmd_pmd'
38     bl_label = 'Import PMD'
39     bl_options={'UNDO'}
40     filename_ext = '.pmd'
41     filter_glob = bpy.props.StringProperty(
42             default='*.pmd', options={'HIDDEN'})
43
44     def execute(self, context):
45         from . import import_pmd
46         bl.initialize('pmd_import', context.scene)
47         import_pmd._execute(**self.as_keywords(
48             ignore=('filter_glob',)))
49         bl.finalize()
50         return {'FINISHED'}
51
52     @classmethod
53     def menu_func(klass, self, context):
54         self.layout.operator(klass.bl_idname,
55                 text='MikuMikuDance model (.pmd)',
56                 icon='PLUGIN'
57                 )
58
59
60 class ImportPmx(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
61     '''Import from PMX Format(.pmx)'''
62     bl_idname='import_scene.mmd_pmx'
63     bl_label='Import PMX'
64     bl_options={'UNDO'}
65     filename_ext='.pmx'
66     filter_glob=bpy.props.StringProperty(
67             default='*.pmx', options={'HIDDEN'})
68
69     def execute(self, context):
70         from . import import_pmx
71         bl.initialize('pmd_import', context.scene)
72         import_pmx._execute(**self.as_keywords(
73             ignore=('filter_glob',)))
74         bl.finalize()
75         return  {'FINISHED'}
76
77     @classmethod
78     def menu_func(klass, self, context):
79         self.layout.operator(klass.bl_idname, 
80                 text='MikuMikuDance model (.pmx)',
81                 icon='PLUGIN'
82                 )
83
84
85 class ImportMqo(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
86     '''Import from MQO file format (.mqo)'''
87     bl_idname = 'import_scene.metasequioa_mqo'
88     bl_label = 'Import MQO'
89     bl_options={'UNDO'}
90     filename_ext = '.mqo'
91     filter_glob = bpy.props.StringProperty(
92             default='*.mqo', options={'HIDDEN'})
93
94     scale = bpy.props.FloatProperty(
95             name='Scale',
96             description='Scale the MQO by this value',
97             min=0.0001, max=1000000.0,
98             soft_min=0.001, soft_max=100.0, default=0.1)
99
100     def execute(self, context):
101         from . import import_mqo
102         bl.initialize('mqo_import', context.scene)
103         import_mqo._execute(**self.as_keywords(
104             ignore=('filter_glob',)))
105         bl.finalize()
106         return {'FINISHED'}
107
108     @classmethod
109     def menu_func(klass, self, context):
110         self.layout.operator(klass.bl_idname,
111                 text="Metasequoia (.mqo)",
112                 icon='PLUGIN'
113                 )
114
115
116 class ExportPmd(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
117     '''Export to PMD file format (.pmd)'''
118     bl_idname = 'export_scene.mmd_pmd'
119     bl_label = 'Export PMD'
120
121     filename_ext = '.pmd'
122     filter_glob = bpy.props.StringProperty(
123             default='*.pmd', options={'HIDDEN'})
124
125     use_selection = bpy.props.BoolProperty(
126             name='Selection Only', 
127             description='Export selected objects only', 
128             default=False)
129
130     def execute(self, context):
131         from . import export_pmd
132         bl.initialize('pmd_export', context.scene)
133         export_pmd._execute(**self.as_keywords(
134             ignore=('check_existing', 'filter_glob', 'use_selection')))
135         bl.finalize()
136         return {'FINISHED'}
137
138     @classmethod
139     def menu_func(klass, self, context):
140         default_path=bpy.data.filepath.replace('.blend', '.pmd')
141         self.layout.operator(klass.bl_idname,
142                 text='Miku Miku Dance Model(.pmd)',
143                 icon='PLUGIN'
144                 ).filepath=default_path
145
146
147 class ExportPmx(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
148     '''Export to PMX file format (.pmx)'''
149     bl_idname = 'export_scene.mmd_pmx'
150     bl_label = 'Export PMX'
151
152     filename_ext = '.pmx'
153     filter_glob = bpy.props.StringProperty(
154             default='*.pmx', options={'HIDDEN'})
155
156     use_selection = bpy.props.BoolProperty(
157             name='Selection Only', 
158             description='Export selected objects only', 
159             default=False)
160
161     def execute(self, context):
162         from . import export_pmx
163         bl.initialize('pmx_export', context.scene)
164         export_pmx._execute(**self.as_keywords(
165             ignore=('check_existing', 'filter_glob', 'use_selection')))
166         bl.finalize()
167         return {'FINISHED'}
168
169     @classmethod
170     def menu_func(klass, self, context):
171         default_path=bpy.data.filepath.replace('.blend', '.pmx')
172         self.layout.operator(klass.bl_idname,
173                 text='Miku Miku Dance Model(.pmx)',
174                 icon='PLUGIN'
175                 ).filepath=default_path
176
177
178 class ExportMqo(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
179     '''Save a Metasequoia MQO file.'''
180     bl_idname = 'export_scene.metasequioa_mqo'
181     bl_label = 'Export MQO'
182
183     filename_ext = '.mqo'
184     filter_glob = bpy.props.StringProperty(
185             default='*.mqo', options={'HIDDEN'})
186
187     use_selection = bpy.props.BoolProperty(
188             name='Selection Only', 
189             description='Export selected objects only', 
190             default=False)
191
192     scale = bpy.props.FloatProperty(
193             name='Scale',
194             description='Scale the MQO by this value',
195             min=0.0001, max=1000000.0,
196             soft_min=0.001, soft_max=100.0, default=10.0)
197
198     apply_modifier = bpy.props.BoolProperty(
199             name='ApplyModifier',
200             description='Would apply modifiers',
201             default=False)
202
203     def execute(self, context):
204         from . import export_mqo
205         bl.initialize('mqo_export', context.scene)
206         export_mqo._execute(**self.as_keywords(
207             ignore=('check_existing', 'filter_glob', 'use_selection')))
208         bl.finalize()
209         return {'FINISHED'}
210
211     @classmethod
212     def menu_func(klass, self, context):
213         default_path=bpy.data.filepath.replace('.blend', '.mqo')
214         self.layout.operator(klass.bl_idname,
215                 text='Metasequoia (.mqo)',
216                 icon='PLUGIN'
217                 ).filepath=default_path
218
219
220 def register():
221     bpy.utils.register_module(__name__)
222     bpy.types.INFO_MT_file_import.append(ImportPmd.menu_func)
223     bpy.types.INFO_MT_file_import.append(ImportPmx.menu_func)
224     bpy.types.INFO_MT_file_import.append(ImportMqo.menu_func)
225     bpy.types.INFO_MT_file_export.append(ExportPmd.menu_func)
226     bpy.types.INFO_MT_file_export.append(ExportPmx.menu_func)
227     bpy.types.INFO_MT_file_export.append(ExportMqo.menu_func)
228
229 def unregister():
230     bpy.utils.unregister_module(__name__)
231     bpy.types.INFO_MT_file_import.remove(ImportPmd.menu_func)
232     bpy.types.INFO_MT_file_import.remove(ImportPmx.menu_func)
233     bpy.types.INFO_MT_file_import.remove(ImportMqo.menu_func)
234     bpy.types.INFO_MT_file_export.remove(ExportPmd.menu_func)
235     bpy.types.INFO_MT_file_export.remove(ExportPmx.menu_func)
236     bpy.types.INFO_MT_file_export.remove(ExportMqo.menu_func)
237
238
239 if __name__=='__main__':
240     register()
241