Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCory Perry <killogge@gmail.com>2011-02-16 12:13:17 +0300
committerCory Perry <killogge@gmail.com>2011-02-16 12:13:17 +0300
commit99c456626f0496a3e6b40c1f3ebbe9154d464e47 (patch)
treec714f67764da98207426e5396e06d402027de93b /io_scene_m3
parentf61def92ef317d34c7f463c2875e8382e6e21314 (diff)
commit 53dd5d4cdded47233bcd9ebf42e44c6fd4886c8f
Author: Cory Perry <killogge@gmail.com> Date: Wed Feb 16 03:51:42 2011 -0500 Updated to latest svn branch of blender (r34892). * Lowered influence of normal map for better looking results. * Modifed code to utilize io_utils module * Minor updates to blender info structs
Diffstat (limited to 'io_scene_m3')
-rw-r--r--io_scene_m3/__init__.py95
-rw-r--r--io_scene_m3/import_m3.py50
2 files changed, 78 insertions, 67 deletions
diff --git a/io_scene_m3/__init__.py b/io_scene_m3/__init__.py
index c43ee686..088fd5a0 100644
--- a/io_scene_m3/__init__.py
+++ b/io_scene_m3/__init__.py
@@ -16,61 +16,82 @@
#
# ##### END GPL LICENSE BLOCK #####
-MAJOR_VERSION = 0
-MINOR_VERSION = 2
-BLENDER_VERSION = (2, 54, 0)
-__version__ = "%d.%d.0" % (MAJOR_VERSION, MINOR_VERSION)
+# <pep8 compliant>
+
bl_info = {
- 'name': 'Import: M3 (.m3)',
+ 'name': 'Blizzard M3 format',
'author': 'Cory Perry',
- 'version': (0, 2, 0),
- 'blender': (2, 5, 4),
- "api": 31878,
- "location": "File > Import",
- "warning": "",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/"\
- "Import-Export/M3_Import",
- "tracker_url": "http://projects.blender.org/tracker/index.php?"\
- "func=detail&aid=24017",
- "category": "Import-Export",
- "description": "This script imports m3 format files to Blender."}
+ 'version': (0, 2, 1),
+ 'blender': (2, 5, 6),
+ 'api': 34893,
+ 'location': 'File > Import-Export',
+ 'description': 'This script imports the Blizzard M3 format (.m3)',
+ 'warning': '',
+ 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/'\
+ 'Import-Export/M3_Import',
+ 'tracker_url': 'http://projects.blender.org/tracker/index.php?'\
+ 'func=detail&aid=24017',
+ 'category': 'Import-Export'}
+
+# To support reload properly, try to access a package var, if it's there,
+# reload everything
if "bpy" in locals():
import imp
- imp.reload(import_m3)
- #imp.reload(export_m3)
-else:
- pass
- #from . import import_m3
- #from . import export_m3
+ if 'import_m3' in locals():
+ imp.reload(import_m3)
+# if 'export_m3' in locals():
+# imp.reload(export_m3)
+import time
+import datetime
import bpy
+from bpy.props import *
+from io_utils import ImportHelper, ExportHelper
+
+
+class ImportM3(bpy.types.Operator, ImportHelper):
+ '''Import from M3 file format (.m3)'''
+ bl_idname = 'import_scene.blizzard_m3'
+ bl_label = 'Import M3'
+
+ filename_ext = '.m3'
+ filter_glob = StringProperty(default='*.m3', options={'HIDDEN'})
-def menu_import(self, context):
- self.layout.operator(import_m3.M3Importer.bl_idname, \
- text="Blizzard M3 (.m3)").filepath = "*.m3"
+ use_image_search = BoolProperty(name='Image Search',
+ description='Search subdirectories for any associated'\
+ 'images', default=True)
+ def execute(self, context):
+ from . import import_m3
+ print('Importing file', self.filepath)
+ t = time.mktime(datetime.datetime.now().timetuple())
+ with open(self.filepath, 'rb') as file:
+ import_m3.read(file, context, self)
+ t = time.mktime(datetime.datetime.now().timetuple()) - t
+ print('Finished importing in', t, 'seconds')
+ return {'FINISHED'}
+
+
+def menu_func_import(self, context):
+ self.layout.operator(ImportM3.bl_idname, text='Blizzard M3 (.m3)')
+
+
+#def menu_func_export(self, context):
+# self.layout.operator(ExportM3.bl_idname, text='Blizzard M3 (.m3)')
-#def menu_export(self, context):
-# from io_mesh_raw import export_raw
-# import os
-# default_path = os.path.splitext(bpy.data.filepath)[0] + ".raw"
-# self.layout.operator(export_raw.RawExporter.bl_idname, \
-# text="Raw Faces (.raw)").filepath = default_path
def register():
- from . import import_m3
bpy.utils.register_module(__name__)
-
- bpy.types.INFO_MT_file_import.append(menu_import)
-# bpy.types.INFO_MT_file_export.append(menu_export)
+ bpy.types.INFO_MT_file_import.append(menu_func_import)
+# bpy.types.INFO_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_module(__name__)
+ bpy.types.INFO_MT_file_import.remove(menu_func_import)
+# bpy.types.INFO_MT_file_export.remove(menu_func_export)
- bpy.types.INFO_MT_file_import.remove(menu_import)
-# bpy.types.INFO_MT_file_export.remove(menu_export)
if __name__ == "__main__":
register()
diff --git a/io_scene_m3/import_m3.py b/io_scene_m3/import_m3.py
index 3208b0ac..ec0a635f 100644
--- a/io_scene_m3/import_m3.py
+++ b/io_scene_m3/import_m3.py
@@ -17,7 +17,7 @@
# ##### END GPL LICENSE BLOCK #####
__author__ = "Cory Perry (muraj)"
-__version__ = "0.0.2"
+__version__ = "0.2.1"
__bpydoc__ = """\
This script imports m3 format files to Blender.
@@ -47,29 +47,17 @@ Usage:<br>
open.
Notes:<br>
+ Known issue with Thor.m3, seems to add a lot of unecessary verts.
Generates the standard verts and faces lists.
"""
import bpy
import mathutils
-import time
-import datetime
import struct
import os.path
from bpy.props import *
-##################
-#LOG = open('C:\m3_log.txt','w')
-LOG = None
-
+from io_utils import load_image
-def debug(*args): # TODO: make a little more robust, right now just a hack
- if LOG == None:
- print(*args)
- else:
- for i in args:
- LOG.write(str(i) + ' ')
- LOG.write('\n')
- LOG.flush()
##################
## Struct setup ##
##################
@@ -271,20 +259,20 @@ def read(file, context, op):
global verFlag
h = hdr(file)
if h.magic[::-1] == b'MD34':
- debug('m3_import: !WARNING! MD34 files not full tested...')
+ print('m3_import: !WARNING! MD34 files not full tested...')
verFlag = True
elif h.magic[::-1] == b'MD33':
verFlag = False
else:
raise Exception('m3_import: !ERROR! Not a valid or supported m3 file')
file.seek(h.ofsTag) # Jump to the Tag table
- debug('m3_import: !INFO! Reading TagTable...')
+ print('m3_import: !INFO! Reading TagTable...')
tagTable = [Tag(file) for _ in range(h.nTag)]
file.seek(tagTable[h.MODLref.refid].ofs)
m = MODL(file, tagTable[h.MODLref.refid].version)
if not m.flags & 0x20000:
raise Exception('m3_import: !ERROR! Model doesn\'t have any vertices')
- debug('m3_import: !INFO! Reading Vertices...')
+ print('m3_import: !INFO! Reading Vertices...')
vert_flags = m.flags & 0x1E0000 # Mask out the vertex version
file.seek(tagTable[m.views.refid].ofs)
d = div(file)
@@ -292,7 +280,7 @@ def read(file, context, op):
verts = [vertex(file, vert_flags) \
for _ in range(tagTable[m.vert.refid].nTag // vertex.size(vert_flags))]
file.seek(tagTable[d.faces.refid].ofs)
- debug('m3_import: !INFO! Reading Faces...')
+ print('m3_import: !INFO! Reading Faces...')
rawfaceTable = struct.unpack('H' * (tagTable[d.faces.refid].nTag), \
file.read(tagTable[d.faces.refid].nTag * 2))
faceTable = []
@@ -300,7 +288,9 @@ def read(file, context, op):
faceTable.append(rawfaceTable[i - 1])
if i % 3 == 0: # Add a zero for the fourth index to the face.
faceTable.append(0)
- debug('m3_import: !INFO! Adding Geometry...')
+ print("m3_import: !INFO! Read %d vertices and %d faces" \
+ % (len(verts), len(faceTable)))
+ print('m3_import: !INFO! Adding Geometry...')
mesh = bpy.data.meshes.new(os.path.basename(op.properties.filepath))
mobj = bpy.data.objects.new(os.path.basename(op.properties.filepath), mesh)
context.scene.objects.link(mobj)
@@ -314,36 +304,36 @@ def read(file, context, op):
mesh.vertices.foreach_set('normal', n)
mesh.faces.foreach_set('vertices_raw', faceTable)
uvtex = mesh.uv_textures.new()
- debug(len(verts), len(faceTable))
for i, face in enumerate(mesh.faces):
uf = uvtex.data[i]
uf.uv1 = verts[faceTable[i * 4 + 0]].uv
uf.uv2 = verts[faceTable[i * 4 + 1]].uv
uf.uv3 = verts[faceTable[i * 4 + 2]].uv
uf.uv4 = (0, 0)
- debug('m3_import: !INFO! Importing materials...')
+ print('m3_import: !INFO! Importing materials...')
material = bpy.data.materials.new('Mat00')
mesh.materials.append(material)
file.seek(tagTable[m.materials.refid].ofs)
mm = mat(file)
- tex_map = [('use_map_diffuse', 0), ('use_map_specular', 2),\
+ tex_map = [('use_map_color_diffuse', 0), ('use_map_specular', 2),\
('use_map_normal', 9)]
for map, i in tex_map:
file.seek(tagTable[mm.layers[i].refid].ofs)
nref = layr(file).name
file.seek(tagTable[nref.refid].ofs)
name = bytes.decode(file.read(nref.entries - 1))
- path = os.path.join(os.path.dirname(op.properties.filepath),\
- os.path.basename(str(name)))
- tex = bpy.data.textures.new(name=os.path.basename(path), type='IMAGE')
- if os.path.exists(path):
- tex.image = bpy.data.images.load(path)
- debug("m3_import: !INFO! Loaded %s" % (path))
+ name = os.path.basename(str(name))
+ tex = bpy.data.textures.new(name=name, type='IMAGE')
+ tex.image = load_image(name, os.path.dirname(op.filepath))
+ if tex.image != None:
+ print("m3_import: !INFO! Loaded %s" % (name))
else:
- debug("m3_import: !WARNING! Cannot find texture \"%s\"" % (path))
+ print("m3_import: !WARNING! Cannot find texture \"%s\"" % (name))
mtex = material.texture_slots.add()
mtex.texture = tex
mtex.texture_coords = 'UV'
+ if i == 9:
+ mtex.normal_factor = 0.1 # Just a guess, seems to look nice
mtex.use_map_color_diffuse = (i == 0)
setattr(mtex, map, True)