# vim:ts=4:et # ##### BEGIN GPL LICENSE BLOCK ##### # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### # from struct import unpack from pprint import pprint import bpy from bpy_extras.object_utils import object_data_add 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 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: 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)] for k in other_keys: data.append((k, co)) else: data.append((frame.key, [(1.0, 1.0)])) if frame.key in other_keys: del(other_keys[other_keys.index(frame.key)]) co = [(1.0, 0.0)] for k in other_keys: data.append((k, co)) set_keys (act, data) def get_base(name): i = 0 while i < len(name) and name[i] not in "0123456789": i += 1 return name[:i] def merge_frames(mdl): i = 0 while i < mdl.numframes: if mdl.frames[i].type: i += 1 continue base = get_base(mdl.frames[i].name) j = i + 1 while j < mdl.numframes: if mdl.frames[j].type: break if get_base(mdl.frames[j].name) != base: break j += 1 f = 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): bpy.context.user_preferences.edit.use_global_undo = False for obj in bpy.context.scene.objects: obj.select = False mdl = load_mdl(filepath) faces, uvs = make_faces (mdl) verts = make_verts (mdl, 0) mdl.mesh = bpy.data.meshes.new(mdl.name) mdl.mesh.from_pydata(verts, [], faces) mdl.obj = bpy.data.objects.new(mdl.name, mdl.mesh) bpy.context.scene.objects.link(mdl.obj) bpy.context.scene.objects.active = mdl.obj mdl.obj.select = True setup_skins (mdl, uvs) if mdl.numframes > 1 or mdl.frames[0].type: build_shape_keys(mdl) merge_frames(mdl) build_actions(mdl) mdl.mesh.update() bpy.context.user_preferences.edit.use_global_undo = True return 'FINISHED'