diff --git a/tools/qfmdl/import_mdl.py b/tools/qfmdl/import_mdl.py index 81bc7ca30..39d7adcc6 100644 --- a/tools/qfmdl/import_mdl.py +++ b/tools/qfmdl/import_mdl.py @@ -29,152 +29,160 @@ from mathutils import Vector,Matrix from . import quakepal class MDL: - pass -class skin: - pass -class stvert: - pass -class tri: - pass -class frame: - pass -class vert: - pass + class Skin: + def __init__(self): + pass + def read(self, mdl, sub=0): + self.width, self.height = mdl.skinwidth, mdl.skinheight + if sub: + self.type = 0 + self.read_pixels(mdl) + return self + self.type = mdl.read_int() + if self.type: + # skin group + num = mdl.read_int() + self.times = mdl.read_float(num) + self.skins = [] + for i in range(num): + self.skins.append(MDL.Skin().read(mdl, 1)) + num -= 1 + return self + self.read_pixels(mdl) + return self -def load_mdl(filepath): - data = open(filepath, "rb").read() - m = unpack("<4s i 3f 3f f 3f i i i i i i i", data[:76]) - data = data[76:] - mdl = MDL() - mdl.name = filepath.split('/')[-1] - mdl.name = mdl.name.split('.')[0] - mdl.ident = m[0] - mdl.version = m[1] - mdl.scale = Vector(m[2:5]) - mdl.scale_origin = Vector(m[5:8]) - mdl.boundingradius = m[8] - mdl.eyeposition = Vector(m[9:12]) - mdl.numskins = m[12] - mdl.skinwidth = m[13] - mdl.skinheight = m[14] - mdl.numverts = m[15] - mdl.numtris = m[16] - mdl.numframes = m[17] - mdl.synctype = m[18] - mdl.flags = 0 - mdl.size = 1.0 # random number ;) - if mdl.version == 6: - m = (" 1: co.append ((1.0, 0.0)) if j > 0: co.append ((j * 1.0, 0.0)) co.append (((j + 1) * 1.0, 1.0)) - if j < frame.numframes - 2: + if j < len(frame.frames) - 2: co.append (((j + 2) * 1.0, 0.0)) - if j < frame.numframes - 1: - co.append ((frame.numframes * 1.0, 0.0)) - data.append((frame.frames[j].key, co)) - if frame.frames[j].key in other_keys: - del(other_keys[other_keys.index(frame.frames[j].key)]) - co = [(1.0, 0.0), (frame.numframes * 1.0, 0.0)] + if j < len(frame.frames) - 1: + co.append ((len(frame.frames) * 1.0, 0.0)) + data.append((subframe.key, co)) + if subframe.key in other_keys: + del(other_keys[other_keys.index(subframe.key)]) + co = [(1.0, 0.0), (len(frame.frames) * 1.0, 0.0)] for k in other_keys: data.append((k, co)) else: @@ -349,25 +358,23 @@ def get_base(name): def merge_frames(mdl): i = 0 - while i < mdl.numframes: + while i < len(mdl.frames): if mdl.frames[i].type: i += 1 continue base = get_base(mdl.frames[i].name) j = i + 1 - while j < mdl.numframes: + while j < len(mdl.frames): if mdl.frames[j].type: break if get_base(mdl.frames[j].name) != base: break j += 1 - f = frame() + f = MDL.Frame() f.name = base - f.numframes = j - i f.type = 1 f.frames = mdl.frames[i:j] mdl.frames[i:j] = [f] - mdl.numframes -= f.numframes - 1 i += 1 def import_mdl(operator, context, filepath): @@ -376,7 +383,10 @@ def import_mdl(operator, context, filepath): for obj in bpy.context.scene.objects: obj.select = False - mdl = load_mdl(filepath) + mdl = MDL() + if not mdl.read(filepath): + #FIXME report? + return {'CANCELED'} faces, uvs = make_faces (mdl) verts = make_verts (mdl, 0) mdl.mesh = bpy.data.meshes.new(mdl.name) @@ -386,7 +396,7 @@ def import_mdl(operator, context, filepath): bpy.context.scene.objects.active = mdl.obj mdl.obj.select = True setup_skins (mdl, uvs) - if mdl.numframes > 1 or mdl.frames[0].type: + if len(mdl.frames) > 1 or mdl.frames[0].type: build_shape_keys(mdl) merge_frames(mdl) build_actions(mdl)