Skip to content
Snippets Groups Projects
Commit fabbd742 authored by Cory Perry's avatar Cory Perry
Browse files

Numerous changes, including pep8 conformence

commit e44929d0c9496c431cf892687e6515fd3134dfaa
Author: muraj <killogge@gmail.com>
Date:   Mon Jan 10 13:30:10 2011 -0500

    Updated meta information for blender tracker url

commit c699da0117693f8f3135b9e9013d7aefac29ae8b
Author: muraj <killogge@gmail.com>
Date:   Mon Jan 10 11:47:36 2011 -0500

    pep8 conformance

commit abdd2b41d06da2d82f6cb8207f55f65f149ec7e6
Author: Cory Perry <killogge@gmail.com>
Date:   Fri Dec 24 20:22:39 2010 -0500

    Fixed a dumb bug with vertex struct sizes not being properly calculated.  Thor now imports properly as a result.
parent ee6ece65
No related branches found
No related tags found
No related merge requests found
# ##### BEGIN GPL LICENSE BLOCK ##### # ##### BEGIN GPL LICENSE BLOCK #####
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
MAJOR_VERSION = 0
MINOR_VERSION = 2
BLENDER_VERSION = (2, 54, 0)
__version__ = "%d.%d.0" % (MAJOR_VERSION, MINOR_VERSION)
bl_addon_info = { bl_addon_info = {
"name": "M3 Import", 'name': 'Import: M3 (.m3)',
"author": "Cory Perry (muraj)", 'author': 'Cory Perry',
"version": (0, 0, 2), 'version': (0, 2, 0),
"blender": (2, 5, 4), 'blender': (2, 5, 4),
"api": 31878, "api": 31878,
"location": "File > Import-Export > M3 Import ", "location": "File > Import",
"description": "Import Blizzard M3 models (.m3 format)", "warning": "",
"warning": "Alpha version", "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/"\
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\ "Import-Export/M3_Import",
"Scripts/Import-Export/M3_Import",
"tracker_url": "http://projects.blender.org/tracker/index.php?"\ "tracker_url": "http://projects.blender.org/tracker/index.php?"\
"func=detail&aid=24017", "func=detail&aid=24017",
"category": "Import-Export"} "category": "Import/Export",
"description": "This script imports m3 format files to Blender."}
""" import bpy
This script imports m3 format files to Blender.
The m3 file format, used by Blizzard in several games, is based around the mdx and m2 file format. Thanks to the efforts of Volcore, madyavic and the people working on libm3, the file format has been reversed engineered enough to make this script possible (Thanks guys!).
This script currently imports the following:
- Geometry data (vertices, faces, submeshes [in vertex groups])
- Model Textures (currently only the first material is supported)
Blender supports the DDS file format and needs the image in the same
directory. This script will notify you of any missing textures.
TODO:
- Documentation & clean up
- Import *ALL* materials and bind accordingly
- Bind specular, normal, and emissive maps following new API
- Adjust vertices to bind pose (import IREF matrices)
- Import Armature data
- Get acquainted with 2.54 Armature API.
- Import Animation data
Known Bugs:
Thor isn't parsable for some reason, will look into.
Usage:
Execute this script from the "File->Import" menu and choose a m3 file to open.
Notes: try:
Generates the standard verts and faces lists. init_data
""" reload(import_m3)
#reload(export_m3)
except:
from io_mesh_m3 import import_m3
#from io_mesh_m3 import export_m3
if "bpy" in locals(): init_data = True
import imp
imp.reload(import_m3)
#imp.reload(export_m3)
else:
from . import import_m3
#from . import export_m3
import bpy
def menu_import(self, context): def menu_import(self, context):
from io_scene_pmd import import_pmd from io_mesh_m3 import import_m3
self.layout.operator( self.layout.operator(import_m3.M3Importer.bl_idname, \
import_m3.M3Importer.bl_idname, text="Blizzard M3 (.m3)").filepath = "*.m3"
text="Blizzard M3 (.m3)",
icon='PLUGIN'
)
#def menu_export(self, context): #def menu_export(self, context):
# from io_mesh_raw import export_raw # from io_mesh_raw import export_raw
# import os # import os
# default_path = os.path.splitext(bpy.data.filepath)[0] + ".raw" # 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 # self.layout.operator(export_raw.RawExporter.bl_idname, \
# text="Raw Faces (.raw)").filepath = default_path
def register(): def register():
bpy.types.INFO_MT_file_import.append(menu_import) bpy.types.INFO_MT_file_import.append(menu_import)
# bpy.types.INFO_MT_file_export.append(menu_export) # bpy.types.INFO_MT_file_export.append(menu_export)
def unregister(): def unregister():
bpy.types.INFO_MT_file_import.remove(menu_import) bpy.types.INFO_MT_file_import.remove(menu_import)
# bpy.types.INFO_MT_file_export.remove(menu_export) # bpy.types.INFO_MT_file_export.remove(menu_export)
if __name__ == "__main__": if __name__ == "__main__":
register() register()
...@@ -16,23 +16,76 @@ ...@@ -16,23 +16,76 @@
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
__author__ = "Cory Perry (muraj)"
import bpy, mathutils, time, struct, os.path __version__ = "0.0.2"
__bpydoc__ = """\
This script imports m3 format files to Blender.
The m3 file format, used by Blizzard in several games, is based around the
mdx and m2 file format. Thanks to the efforts of Volcore, madyavic and the
people working on libm3, the file format has been reversed engineered
enough to make this script possible (Thanks guys!).
This script currently imports the following:<br>
- Geometry data (vertices, faces, submeshes [in vertex groups])
- Model Textures (currently only the first material is supported)
Blender supports the DDS file format and needs the image in the same
directory. This script will notify you of any missing textures.
TODO:<br>
- Documentation & clean up
- Full MD34 and MD33 testing (possibly batch importing for a testing suite)
- Import *ALL* materials and bind accordingly (currently supports diffuse,
specular, and normal.
- Adjust vertices to bind pose (import IREF matrices)
- Import Bone data
- Import Animation data
Usage:<br>
Execute this script from the "File->Import" menu and choose a m3 file to
open.
Notes:<br>
Generates the standard verts and faces lists.
"""
import bpy
import mathutils
import time
import datetime
import struct
import os.path
from bpy.props import * from bpy.props import *
##################
#LOG = open('C:\m3_log.txt','w')
LOG = None
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 ## ## Struct setup ##
################## ##################
verFlag = False # Version flag (MD34 == True, MD33 == False)
verFlag = False #Version flag (MD34 == True, MD33 == False)
class ref: class ref:
fmt = 'LL' fmt = 'LL'
def __init__(self, file): def __init__(self, file):
global verFlag global verFlag
if verFlag: self.fmt += 'L' #Extra unknown... if verFlag:
_s=file.read(struct.calcsize(self.fmt)) self.fmt += 'L' # Extra unknown...
_s = file.read(struct.calcsize(self.fmt))
self.entries, self.refid = struct.unpack(self.fmt, _s)[:2] self.entries, self.refid = struct.unpack(self.fmt, _s)[:2]
@classmethod @classmethod
def size(cls): def size(cls):
global verFlag global verFlag
...@@ -41,107 +94,121 @@ class ref: ...@@ -41,107 +94,121 @@ class ref:
class animref: class animref:
fmt = 'HHL' fmt = 'HHL'
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.flags, self.animflags, self.animid = struct.unpack(self.fmt, _s) self.flags, self.animflags, self.animid = struct.unpack(self.fmt, _s)
class Tag: class Tag:
fmt = '4sLLL' fmt = '4sLLL'
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.name, self.ofs, self.nTag, self.version = struct.unpack(self.fmt, _s) self.name, self.ofs, self.nTag, self.version = \
struct.unpack(self.fmt, _s)
class matrix: class matrix:
fmt='f'*16 fmt = 'f' * 16
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.mat = struct.unpack(self.fmt, _s) self.mat = struct.unpack(self.fmt, _s)
class vect: class vect:
fmt='fff' fmt = 'fff'
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.v = struct.unpack(self.fmt, _s) self.v = struct.unpack(self.fmt, _s)
class vertex: class vertex:
fmt="4B4b4B%dH4B" fmt = "4B4b4B%dH4B"
ver = { 0x020000: 2, 0x060000: 4, 0x0A0000: 6, 0x120000: 8 } ver = {0x020000: 2, 0x060000: 4, 0x0A0000: 6, 0x120000: 8}
def __init__(self, file, flag): def __init__(self, file, flag):
self.pos = vect(file) self.pos = vect(file)
fmt = self.fmt % (self.ver[flag]) _fmt = self.fmt % (self.ver[flag])
_s=file.read(struct.calcsize(fmt)) _s = file.read(struct.calcsize(_fmt))
print(file.tell()) _s = struct.unpack(_fmt, _s)
_s = struct.unpack(fmt, _s)
self.boneWeight = _s[0:4] self.boneWeight = _s[0:4]
self.boneIndex = _s[4:8] self.boneIndex = _s[4:8]
self.normal = _s[8:12] self.normal = _s[8:12]
self.uv = _s[12:14] self.uv = _s[12:14]
self.tan = _s[-4:] #Skipping the middle ukn value if needed self.tan = _s[-4:] # Skipping the middle ukn value if needed
self.boneWeight = [b/255.0 for b in self.boneWeight] self.boneWeight = [b / 255.0 for b in self.boneWeight]
self.normal = [x*2.0/255.0-1.0 for x in self.normal] self.normal = [x * 2.0 / 255.0 - 1.0 for x in self.normal]
self.tan = [x*2.0/255.0-1.0 for x in self.tan] self.tan = [x * 2.0 / 255.0 - 1.0 for x in self.tan]
self.uv = [x/2046.0 for x in self.uv] self.uv = [x / 2046.0 for x in self.uv]
self.uv[1] = 1.0 - self.uv[1] self.uv[1] = 1.0 - self.uv[1]
@classmethod @classmethod
def size(cls, flag): def size(cls, flag=0x020000):
return struct.calcsize(cls.fmt % (cls.ver[flag])) return struct.calcsize('fff' + cls.fmt % (cls.ver[flag]))
class quat: class quat:
fmt='ffff' fmt = 'ffff'
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.v = struct.unpack(self.fmt, _s) self.v = struct.unpack(self.fmt, _s)
self.v = [self.v[-1], self.v[0], self.v[1], self.v[2]] #Quats are stored x,y,z,w - this fixes it #Quats are stored x,y,z,w - this fixes it
self.v = [self.v[-1], self.v[0], self.v[1], self.v[2]]
class bone: class bone:
def __init__(self, file): def __init__(self, file):
file.read(4) #ukn1 file.read(4) # ukn1
self.name = ref(file) self.name = ref(file)
self.flag, self.parent, _ = struct.unpack('LhH',file.read(8)) self.flag, self.parent, _ = struct.unpack('LhH', file.read(8))
self.posid = animref(file) self.posid = animref(file)
self.pos = vect(file) self.pos = vect(file)
file.read(4*4) #ukn file.read(4 * 4) # ukn
self.rotid = animref(file) self.rotid = animref(file)
self.rot = quat(file) self.rot = quat(file)
file.read(4*5) #ukn file.read(4 * 5) # ukn
self.scaleid = animref(file) self.scaleid = animref(file)
self.scale = vect(file) self.scale = vect(file)
vect(file) #ukn vect(file) # ukn
file.read(4*6) #ukn file.read(4 * 6) # ukn
class div: class div:
def __init__(self, file): def __init__(self, file):
self.faces = ref(file) self.faces = ref(file)
self.regn = ref(file) self.regn = ref(file)
self.bat = ref(file) self.bat = ref(file)
self.msec = ref(file) self.msec = ref(file)
file.read(4) #ukn file.read(4) # ukn
class regn: class regn:
fmt = 'LHHLL6H' fmt = 'L2H2L6H'
def __init__(self, file): def __init__(self, file):
_s=file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
_ukn1, self.ofsVert, self.nVerts, self.ofsIndex, self.nIndex, \ _ukn1, self.ofsVert, self.nVerts, self.ofsIndex, self.nIndex, \
self.boneCount, self.indBone, self.nBone = struct.unpack(self.fmt, _s)[:8] self.boneCount, self.indBone, self.nBone = \
struct.unpack(self.fmt, _s)[:8]
class mat: class mat:
def __init__(self, file): def __init__(self, file):
self.name = ref(file) self.name = ref(file)
file.read(4*10) #ukn file.read(4 * 10) # ukn
self.layers = [ref(file) for _ in range(13)] self.layers = [ref(file) for _ in range(13)]
file.read(4*15) #ukn file.read(4 * 15) # ukn
class layr: class layr:
def __init__(self, file): def __init__(self, file):
file.read(4) file.read(4)
self.name = ref(file) self.name = ref(file)
...@@ -150,6 +217,7 @@ class layr: ...@@ -150,6 +217,7 @@ class layr:
class hdr: class hdr:
fmt = '4sLL' fmt = '4sLL'
def __init__(self, file): def __init__(self, file):
_s = file.read(struct.calcsize(self.fmt)) _s = file.read(struct.calcsize(self.fmt))
self.magic, self.ofsTag, self.nTag = struct.unpack(self.fmt, _s) self.magic, self.ofsTag, self.nTag = struct.unpack(self.fmt, _s)
...@@ -157,152 +225,153 @@ class hdr: ...@@ -157,152 +225,153 @@ class hdr:
class MODL: class MODL:
def __init__(self, file, flag=20): def __init__(self, file, flag=20):
global verFlag global verFlag
self.name = ref(file) self.name = ref(file)
self.ver = struct.unpack('L',file.read(4))[0] self.ver = struct.unpack('L', file.read(4))[0]
self.seqHdr = ref(file) self.seqHdr = ref(file)
self.seqData = ref(file) self.seqData = ref(file)
self.seqLookup = ref(file) self.seqLookup = ref(file)
file.read(0x1C if verFlag else 0x14) #ukn1 file.read(0x1C if verFlag else 0x14) # ukn1
self.bones = ref(file) self.bones = ref(file)
file.read(4) #ukn2 file.read(4) # ukn2
self.flags = struct.unpack('L',file.read(4))[0] self.flags = struct.unpack('L', file.read(4))[0]
self.vert = ref(file) self.vert = ref(file)
self.views = ref(file) self.views = ref(file)
self.boneLookup = ref(file) self.boneLookup = ref(file)
self.extents = [vect(file), vect(file)] self.extents = [vect(file), vect(file)]
self.radius = struct.unpack('f',file.read(4))[0] self.radius = struct.unpack('f', file.read(4))[0]
if verFlag: file.read(4) #ukn MD34 addition if verFlag:
file.read(4) # ukn MD34 addition
if not verFlag: if not verFlag:
if flag == 20: file.read(0x2C) if flag == 20:
else: file.read(0x34) file.read(0x2C)
else:
file.read(0x34)
else: else:
if flag == 20: file.read(0x30) if flag == 20:
else: file.read(0x3C) file.read(0x30)
else:
file.read(0x3C)
self.attach = ref(file) self.attach = ref(file)
file.read(5*ref.size()) file.read(5 * ref.size())
self.materialsLookup = ref(file) self.materialsLookup = ref(file)
self.materials = ref(file) self.materials = ref(file)
file.read(ref.size()) file.read(ref.size())
if not verFlag: if not verFlag:
file.read(0x90) file.read(0x90)
else: file.read(0xD8) else:
file.read(0xD8)
self.iref = ref(file) self.iref = ref(file)
def read(file, context, op): def read(file, context, op):
'''Imports as an m3 file''' """Imports as an m3 file"""
global verFlag global verFlag
h=hdr(file) h = hdr(file)
if h.magic == b'43DM': if h.magic[::-1] == b'MD34':
print('m3_import: !WARNING! MD34 files not full tested...') debug('m3_import: !WARNING! MD34 files not full tested...')
verFlag = True verFlag = True
elif h.magic == b'33DM': elif h.magic[::-1] == b'MD33':
verFlag = False verFlag = False
else: else:
raise Exception('m3_import: !ERROR! Not a valid or supported m3 file') raise Exception('m3_import: !ERROR! Not a valid or supported m3 file')
file.seek(h.ofsTag) #Jump to the Tag table file.seek(h.ofsTag) # Jump to the Tag table
print('m3_import: !INFO! Reading TagTable...') debug('m3_import: !INFO! Reading TagTable...')
tagTable = [Tag(file) for _ in range(h.nTag)] tagTable = [Tag(file) for _ in range(h.nTag)]
file.seek(tagTable[h.MODLref.refid].ofs) file.seek(tagTable[h.MODLref.refid].ofs)
m = MODL(file, tagTable[h.MODLref.refid].version) m = MODL(file, tagTable[h.MODLref.refid].version)
if not m.flags & 0x20000: if not m.flags & 0x20000:
raise Exception('m3_import: !ERROR! Model doesn\'t contain any vertices') raise Exception('m3_import: !ERROR! Model doesn\'t have any vertices')
vert_flags = m.flags & 0x1E0000 #Mask out the vertex version debug('m3_import: !INFO! Reading Vertices...')
file.seek(tagTable[m.vert.refid].ofs) vert_flags = m.flags & 0x1E0000 # Mask out the vertex version
print('m3_import: !INFO! Reading Vertices...')
verts = [ vertex(file, vert_flags) for _ in range(int(tagTable[m.vert.refid].nTag / vertex.size(vert_flags))) ]
file.seek(tagTable[m.views.refid].ofs) file.seek(tagTable[m.views.refid].ofs)
d = div(file) d = div(file)
file.seek(tagTable[m.vert.refid].ofs)
verts = [vertex(file, vert_flags) \
for _ in range(tagTable[m.vert.refid].nTag // vertex.size(vert_flags))]
file.seek(tagTable[d.faces.refid].ofs) file.seek(tagTable[d.faces.refid].ofs)
print('m3_import: !INFO! Reading Faces...') debug('m3_import: !INFO! Reading Faces...')
rawfaceTable = struct.unpack('H'*(tagTable[d.faces.refid].nTag), file.read(tagTable[d.faces.refid].nTag*2)) rawfaceTable = struct.unpack('H' * (tagTable[d.faces.refid].nTag), \
file.read(tagTable[d.faces.refid].nTag * 2))
faceTable = [] faceTable = []
for i in range(1, len(rawfaceTable)+1): for i in range(1, len(rawfaceTable) + 1):
faceTable.append(rawfaceTable[i-1]) faceTable.append(rawfaceTable[i - 1])
if i % 3 == 0: faceTable.append(0) #Add a zero for the fourth index to the face. if i % 3 == 0: # Add a zero for the fourth index to the face.
print('m3_import: !INFO! Adding Geometry...') faceTable.append(0)
debug('m3_import: !INFO! Adding Geometry...')
mesh = bpy.data.meshes.new(os.path.basename(op.properties.filepath)) mesh = bpy.data.meshes.new(os.path.basename(op.properties.filepath))
mobj = bpy.data.objects.new(os.path.basename(op.properties.filepath), mesh) mobj = bpy.data.objects.new(os.path.basename(op.properties.filepath), mesh)
context.scene.objects.link(mobj) context.scene.objects.link(mobj)
v = [] v, n = [], []
for vert in verts: #"Flatten" the vertex array... for vert in verts: # "Flatten" the vertex array...
v.extend(vert.pos.v) v.extend(vert.pos.v)
n.extend(vert.normal)
mesh.vertices.add(len(verts)) mesh.vertices.add(len(verts))
mesh.faces.add(len(rawfaceTable)//3) mesh.faces.add(len(rawfaceTable) // 3)
mesh.vertices.foreach_set('co', v) mesh.vertices.foreach_set('co', v)
mesh.vertices.foreach_set('normal', n)
mesh.faces.foreach_set('vertices_raw', faceTable) mesh.faces.foreach_set('vertices_raw', faceTable)
uvtex = mesh.uv_textures.new() uvtex = mesh.uv_textures.new()
debug(len(verts), len(faceTable))
for i, face in enumerate(mesh.faces): for i, face in enumerate(mesh.faces):
uf = uvtex.data[i] uf = uvtex.data[i]
uf.uv1 = verts[faceTable[i*4+0]].uv uf.uv1 = verts[faceTable[i * 4 + 0]].uv
uf.uv2 = verts[faceTable[i*4+1]].uv uf.uv2 = verts[faceTable[i * 4 + 1]].uv
uf.uv3 = verts[faceTable[i*4+2]].uv uf.uv3 = verts[faceTable[i * 4 + 2]].uv
uf.uv4 = (0,0) uf.uv4 = (0, 0)
print('m3_import: !INFO! Importing materials...') debug('m3_import: !INFO! Importing materials...')
material = bpy.data.materials.new('Mat00') material = bpy.data.materials.new('Mat00')
mesh.materials.append(material) mesh.materials.append(material)
file.seek(tagTable[m.materials.refid].ofs) file.seek(tagTable[m.materials.refid].ofs)
mm = mat(file) mm = mat(file)
for map, i in [('use_map_diffuse', 0), ('use_map_specular', 2), ('use_map_normal', 9)]: tex_map = [('use_map_diffuse', 0), ('use_map_specular', 2),\
('use_map_normal', 9)]
for map, i in tex_map:
file.seek(tagTable[mm.layers[i].refid].ofs) file.seek(tagTable[mm.layers[i].refid].ofs)
nref = layr(file).name nref = layr(file).name
file.seek(tagTable[nref.refid].ofs) file.seek(tagTable[nref.refid].ofs)
name = bytes.decode(file.read(nref.entries-1)) name = bytes.decode(file.read(nref.entries - 1))
path = os.path.join(os.path.dirname(op.properties.filepath), os.path.basename(str(name))) 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') tex = bpy.data.textures.new(name=os.path.basename(path), type='IMAGE')
if os.path.exists(path): if os.path.exists(path):
tex.image = bpy.data.images.load(path) tex.image = bpy.data.images.load(path)
print("m3_import: !INFO! Loaded %s" % (path)) debug("m3_import: !INFO! Loaded %s" % (path))
else: else:
print("m3_import: !WARNING! Cannot find texture \"%s\"" % (path)) debug("m3_import: !WARNING! Cannot find texture \"%s\"" % (path))
mtex = material.texture_slots.add() mtex = material.texture_slots.add()
mtex.texture = tex mtex.texture = tex
mtex.texture_coords = 'UV' mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = (i == 0) mtex.use_map_color_diffuse = (i == 0)
setattr(mtex, map, True) # <- This is really dumb to have to do, just expose a bitmask or something. setattr(mtex, map, True)
class M3Importer(bpy.types.Operator): class M3Importer(bpy.types.Operator):
'''Import from M3 file format (.m3)''' '''Import from M3 file format (.m3)'''
bl_idname = "import_mesh.blizzard_m3" bl_idname = "import_mesh.blizzard_m3"
bl_label = 'Import M3' bl_label = 'Import M3'
# List of operator properties, the attributes will be assigned # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # to the class instance from the operator settings before calling.
filepath = StringProperty(name="File Path", description="Filepath used for importing the M3 file", maxlen= 1024, default= "") filepath = StringProperty(
name="File Path",\
description="Filepath used for importing the M3 file",\
maxlen=1024,\
default="")
def execute(self, context): def execute(self, context):
t = time.clock() t = time.mktime(datetime.datetime.now().timetuple())
with open(self.properties.filepath, 'rb') as file: with open(self.properties.filepath, 'rb') as file:
print('Importing file', self.properties.filepath) print('Importing file', self.properties.filepath)
read(file, context, self) read(file, context, self)
print('Finished importing in', time.clock() - t, 'seconds') t = time.mktime(datetime.datetime.now().timetuple()) - t
print('Finished importing in', t, 'seconds')
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
wm = context.window_manager wm = context.window_manager
wm.fileselect_add(self) wm.add_fileselect(self)
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(M3Importer.bl_idname, text="M3 (.m3)")
def register():
bpy.types.register(M3Importer)
bpy.types.INFO_MT_file_import.append(menu_func)
def unregister():
bpy.types.unregister(M3Importer)
bpy.types.INFO_MT_file_import.remove(menu_func)
if __name__ == "__main__":
register()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment