Skip to content

Commit 7fd81d7

Browse files
committed
Reorganizing code
1 parent 9156b29 commit 7fd81d7

File tree

5 files changed

+111
-99
lines changed

5 files changed

+111
-99
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
__pycache__

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Can deal with animation (via the Shape Keys), textures and md3 tags (added as Em
77

88
More info on [BlenderWiki](http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3).
99

10-
I've used [this](http://www.icculus.org/homepages/phaethon/q3a/formats/md3format.html) format reference.
10+
Used [this](http://www.icculus.org/homepages/phaethon/q3a/formats/md3format.html) format reference.

io_scene_md3/__init__.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This program is free software: you can redistribute it and/or modify
2+
# it under the terms of the GNU General Public License as published by
3+
# the Free Software Foundation, either version 3 of the License, or
4+
# (at your option) any later version.
5+
#
6+
# This program is distributed in the hope that it will be useful,
7+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
# GNU General Public License for more details.
10+
#
11+
# You should have received a copy of the GNU General Public License
12+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
14+
15+
bl_info = {
16+
"name": "Quake 3 Model (.md3)",
17+
"author": "Vitaly Verhovodov",
18+
"version": (0, 1, 0),
19+
"blender": (2, 6, 9),
20+
"location": "File > Import-Export > Quake 3 Model",
21+
"description": "Quake 3 Model format (.md3)",
22+
"warning": "",
23+
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3",
24+
"tracker_url": "https://github.com/neumond/blender-md3/issues",
25+
"category": "Import-Export"}
26+
27+
28+
import bpy
29+
from bpy.props import StringProperty
30+
from bpy_extras.io_utils import ImportHelper, ExportHelper
31+
32+
33+
class ImportMD3(bpy.types.Operator, ImportHelper):
34+
'''Import a Quake 3 Model MD3 file'''
35+
bl_idname = "import_scene.md3"
36+
bl_label = 'Import MD3'
37+
filename_ext = ".md3"
38+
filter_glob = StringProperty(default="*.md3", options={'HIDDEN'})
39+
40+
def execute(self, context):
41+
from . import import_md3
42+
import_md3.importMD3(context, self.properties.filepath)
43+
return {'FINISHED'}
44+
45+
46+
class ExportMD3(bpy.types.Operator, ExportHelper):
47+
'''Export a Quake 3 Model MD3 file'''
48+
bl_idname = "export_scene.md3"
49+
bl_label = 'Export MD3'
50+
filename_ext = ".md3"
51+
filter_glob = StringProperty(default="*.md3", options={'HIDDEN'})
52+
53+
def execute(self, context):
54+
from . import export_md3
55+
export_md3.exportMD3(context, self.properties.filepath)
56+
return {'FINISHED'}
57+
58+
59+
def menu_func_import(self, context):
60+
self.layout.operator(ImportMD3.bl_idname, text="Quake 3 Model (.md3)")
61+
62+
def menu_func_export(self, context):
63+
self.layout.operator(ExportMD3.bl_idname, text="Quake 3 Model (.md3)")
64+
65+
66+
def register():
67+
bpy.utils.register_module(__name__)
68+
bpy.types.INFO_MT_file_import.append(menu_func_import)
69+
bpy.types.INFO_MT_file_export.append(menu_func_export)
70+
71+
def unregister():
72+
bpy.utils.unregister_module(__name__)
73+
bpy.types.INFO_MT_file_import.remove(menu_func_import)
74+
bpy.types.INFO_MT_file_export.remove(menu_func_export)
75+
76+
77+
if __name__ == "__main__":
78+
register()

md3_export.py renamed to io_scene_md3/export_md3.py

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# This script is licensed as public domain.
2-
3-
# grouping to surfaces must done by UV maps
1+
# This program is free software: you can redistribute it and/or modify
2+
# it under the terms of the GNU General Public License as published by
3+
# the Free Software Foundation, either version 3 of the License, or
4+
# (at your option) any later version.
5+
#
6+
# This program is distributed in the hope that it will be useful,
7+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
# GNU General Public License for more details.
10+
#
11+
# You should have received a copy of the GNU General Public License
12+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
14+
15+
# grouping to surfaces must done by UV maps also, not only normals
416
# TODO: merge surfaces with same uv maps and texture
5-
# TODO: add assertions on maxcounts (vertex, tris, etc)
6-
7-
bl_info = {
8-
"name": "Export Quake 3 Model (.md3)",
9-
"author": "Vitalik Verhovodov",
10-
"version": (0, 1, 0),
11-
"blender": (2, 6, 9),
12-
"location": "File > Export > Quake 3 Model",
13-
"description": "Export to the Quake 3 Model format (.md3)",
14-
"warning": "",
15-
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3",
16-
"tracker_url": "https://github.com/neumond/blender-md3/issues",
17-
"category": "Import-Export"}
17+
# TODO: check bounding sphere calculation
18+
1819

1920
import bpy
2021
import mathutils
2122
import struct
22-
from bpy_extras.io_utils import ExportHelper
2323
from math import atan2, acos, pi, sqrt
2424
import re
2525

@@ -366,36 +366,3 @@ def exportMD3(context, filename):
366366
raise Exception('Not all delayed write resolved: {}'.format(ctx['delayed']))
367367

368368
print('nFrames={} nSurfaces={}'.format(nFrames, len(ctx['surfNames'])))
369-
370-
371-
class ExportMD3(bpy.types.Operator, ExportHelper):
372-
'''Export a Quake 3 Model MD3 file'''
373-
bl_idname = "export.md3"
374-
bl_label = 'Export MD3'
375-
filename_ext = ".md3"
376-
377-
def execute(self, context):
378-
exportMD3(context, self.properties.filepath)
379-
return {'FINISHED'}
380-
381-
def check(self, context):
382-
filepath = bpy.path.ensure_ext(self.filepath, '.md3')
383-
if filepath != self.filepath:
384-
self.filepath = filepath
385-
return True
386-
return False
387-
388-
389-
def menu_func(self, context):
390-
self.layout.operator(ExportMD3.bl_idname, text="Quake 3 Model (.md3)")
391-
392-
def register():
393-
bpy.utils.register_module(__name__)
394-
bpy.types.INFO_MT_file_export.append(menu_func)
395-
396-
def unregister():
397-
bpy.utils.unregister_module(__name__)
398-
bpy.types.INFO_MT_file_export.remove(menu_func)
399-
400-
if __name__ == "__main__":
401-
register()

md3_import.py renamed to io_scene_md3/import_md3.py

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# This script is licensed as public domain.
1+
# This program is free software: you can redistribute it and/or modify
2+
# it under the terms of the GNU General Public License as published by
3+
# the Free Software Foundation, either version 3 of the License, or
4+
# (at your option) any later version.
5+
#
6+
# This program is distributed in the hope that it will be useful,
7+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
# GNU General Public License for more details.
10+
#
11+
# You should have received a copy of the GNU General Public License
12+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
214

315
# TODO: different normals for shape keys
416
# TODO: merge vertices near sharp edges (there is a disconnected surface now)
517
# TODO: use_smooth=False for flat faces (all vertex normal equal)
618

7-
bl_info = {
8-
"name": "Import Quake 3 Model (.md3)",
9-
"author": "Vitalik Verhovodov",
10-
"version": (0, 1, 0),
11-
"blender": (2, 6, 9),
12-
"location": "File > Import > Quake 3 Model",
13-
"description": "Import to the Quake 3 Model format (.md3)",
14-
"warning": "",
15-
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3",
16-
"tracker_url": "https://github.com/neumond/blender-md3/issues",
17-
"category": "Import-Export"}
1819

1920
import bpy
2021
import mathutils
2122
import struct
22-
from bpy_extras.io_utils import ImportHelper
2323
from math import pi, sin, cos
2424
import os.path
2525

@@ -231,38 +231,3 @@ def importMD3(context, filename):
231231
context.scene.game_settings.material_mode = 'GLSL'
232232

233233
bpy.ops.object.lamp_add(type='SUN')
234-
235-
236-
class ImportMD3(bpy.types.Operator, ImportHelper):
237-
'''Import a Quake 3 Model MD3 file'''
238-
bl_idname = "import.md3"
239-
bl_label = 'Import MD3'
240-
filename_ext = ".md3"
241-
242-
def execute(self, context):
243-
importMD3(context, self.properties.filepath)
244-
return {'FINISHED'}
245-
246-
def check(self, context):
247-
filepath = bpy.path.ensure_ext(self.filepath, '.md3')
248-
if filepath != self.filepath:
249-
self.filepath = filepath
250-
return True
251-
return False
252-
253-
254-
def menu_func(self, context):
255-
self.layout.operator(ImportMD3.bl_idname, text="Quake 3 Model (.md3)")
256-
257-
def register():
258-
bpy.utils.register_module(__name__)
259-
bpy.types.INFO_MT_file_import.append(menu_func)
260-
261-
def unregister():
262-
bpy.utils.unregister_module(__name__)
263-
bpy.types.INFO_MT_file_import.remove(menu_func)
264-
265-
if __name__ == "__main__":
266-
register()
267-
268-

0 commit comments

Comments
 (0)