mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Load the skins into blender images.
Skin groups are not yet supported (skipped).
This commit is contained in:
parent
9d025e0058
commit
99ff91e341
2 changed files with 298 additions and 10 deletions
|
@ -26,8 +26,12 @@ 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:
|
||||
|
@ -42,6 +46,8 @@ def load_mdl(filepath):
|
|||
m = unpack("<4s i 3f 3f f 3f i i i i i i i i f", data[:84])
|
||||
data = data[84:]
|
||||
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])
|
||||
|
@ -61,22 +67,27 @@ def load_mdl(filepath):
|
|||
size = mdl.skinwidth * mdl.skinheight
|
||||
mdl.skins = []
|
||||
for i in range(mdl.numskins):
|
||||
skintype = unpack ("<i", data[:4])[0]
|
||||
s = skin()
|
||||
mdl.skins.append(s)
|
||||
s.type = unpack ("<i", data[:4])[0]
|
||||
data = data[4:]
|
||||
if skintype == 0:
|
||||
if s.type == 0:
|
||||
# single skin
|
||||
mdl.skins.append((0, data[:size]))
|
||||
s.pixels = data[:size]
|
||||
data = data[size:]
|
||||
else:
|
||||
# skin group
|
||||
n = unpack ("<i", data[:4])[0]
|
||||
s.numskins = unpack ("<i", data[:4])[0]
|
||||
data = data[4:]
|
||||
k = (n, unpack("<" + repr(n) + "f", data[:n * 4]), [])
|
||||
s.times = unpack("<" + repr(n) + "f", data[:n * 4])
|
||||
data = data[n * 4:]
|
||||
s.skins = []
|
||||
for j in range(n):
|
||||
k[2].append(data[:size])
|
||||
ss = skin()
|
||||
ss.type = 0
|
||||
ss.pixels = data[:size]
|
||||
data = data[size:]
|
||||
mdl.skins.append(k)
|
||||
s.skins.append[ss]
|
||||
#read in the st verts (uv map)
|
||||
mdl.stverts = []
|
||||
for i in range(mdl.numverts):
|
||||
|
@ -163,13 +174,32 @@ def make_mesh(mdl, framenum, subframenum=0):
|
|||
faces.append (t.verts)
|
||||
return verts, faces
|
||||
|
||||
def load_skins(mdl):
|
||||
for i in range(mdl.numskins):
|
||||
if mdl.skins[i].type:
|
||||
continue #skin groups not yet supported
|
||||
img = bpy.data.images.new("%s_%d" % (mdl.name, i),
|
||||
mdl.skinwidth, mdl.skinheight)
|
||||
p = [0.0] * mdl.skinwidth * mdl.skinheight * 4
|
||||
d = mdl.skins[i].pixels
|
||||
for j in range(mdl.skinheight):
|
||||
for k in range(mdl.skinwidth):
|
||||
c = quakepal.palette[d[j * mdl.skinwidth + k]]
|
||||
# quake textures are top to bottom, but blender images
|
||||
# are bottom to top
|
||||
l = ((mdl.skinheight - 1 - j) * mdl.skinwidth + k) * 4
|
||||
p[l + 0] = c[0] / 255.0
|
||||
p[l + 1] = c[1] / 255.0
|
||||
p[l + 2] = c[2] / 255.0
|
||||
p[l + 3] = 1.0
|
||||
img.pixels[:] = p[:]
|
||||
|
||||
def import_mdl(operator, context, filepath):
|
||||
mdl = load_mdl(filepath)
|
||||
verts, faces = make_mesh (mdl, 0)
|
||||
name = filepath.split('/')[-1]
|
||||
name = name.split('.')[0]
|
||||
bpy.context.user_preferences.edit.use_global_undo = False
|
||||
mesh = bpy.data.meshes.new(name)
|
||||
load_skins (mdl)
|
||||
mesh = bpy.data.meshes.new(mdl.name)
|
||||
mesh.from_pydata(verts, [], faces)
|
||||
mesh.update()
|
||||
object_data_add(context, mesh, operator=None)
|
||||
|
|
258
tools/qfmdl/quakepal.py
Normal file
258
tools/qfmdl/quakepal.py
Normal file
|
@ -0,0 +1,258 @@
|
|||
palette = (
|
||||
(0x00, 0x00, 0x00),
|
||||
(0x0f, 0x0f, 0x0f),
|
||||
(0x1f, 0x1f, 0x1f),
|
||||
(0x2f, 0x2f, 0x2f),
|
||||
(0x3f, 0x3f, 0x3f),
|
||||
(0x4b, 0x4b, 0x4b),
|
||||
(0x5b, 0x5b, 0x5b),
|
||||
(0x6b, 0x6b, 0x6b),
|
||||
(0x7b, 0x7b, 0x7b),
|
||||
(0x8b, 0x8b, 0x8b),
|
||||
(0x9b, 0x9b, 0x9b),
|
||||
(0xab, 0xab, 0xab),
|
||||
(0xbb, 0xbb, 0xbb),
|
||||
(0xcb, 0xcb, 0xcb),
|
||||
(0xdb, 0xdb, 0xdb),
|
||||
(0xeb, 0xeb, 0xeb),
|
||||
(0x0f, 0x0b, 0x07),
|
||||
(0x17, 0x0f, 0x0b),
|
||||
(0x1f, 0x17, 0x0b),
|
||||
(0x27, 0x1b, 0x0f),
|
||||
(0x2f, 0x23, 0x13),
|
||||
(0x37, 0x2b, 0x17),
|
||||
(0x3f, 0x2f, 0x17),
|
||||
(0x4b, 0x37, 0x1b),
|
||||
(0x53, 0x3b, 0x1b),
|
||||
(0x5b, 0x43, 0x1f),
|
||||
(0x63, 0x4b, 0x1f),
|
||||
(0x6b, 0x53, 0x1f),
|
||||
(0x73, 0x57, 0x1f),
|
||||
(0x7b, 0x5f, 0x23),
|
||||
(0x83, 0x67, 0x23),
|
||||
(0x8f, 0x6f, 0x23),
|
||||
(0x0b, 0x0b, 0x0f),
|
||||
(0x13, 0x13, 0x1b),
|
||||
(0x1b, 0x1b, 0x27),
|
||||
(0x27, 0x27, 0x33),
|
||||
(0x2f, 0x2f, 0x3f),
|
||||
(0x37, 0x37, 0x4b),
|
||||
(0x3f, 0x3f, 0x57),
|
||||
(0x47, 0x47, 0x67),
|
||||
(0x4f, 0x4f, 0x73),
|
||||
(0x5b, 0x5b, 0x7f),
|
||||
(0x63, 0x63, 0x8b),
|
||||
(0x6b, 0x6b, 0x97),
|
||||
(0x73, 0x73, 0xa3),
|
||||
(0x7b, 0x7b, 0xaf),
|
||||
(0x83, 0x83, 0xbb),
|
||||
(0x8b, 0x8b, 0xcb),
|
||||
(0x00, 0x00, 0x00),
|
||||
(0x07, 0x07, 0x00),
|
||||
(0x0b, 0x0b, 0x00),
|
||||
(0x13, 0x13, 0x00),
|
||||
(0x1b, 0x1b, 0x00),
|
||||
(0x23, 0x23, 0x00),
|
||||
(0x2b, 0x2b, 0x07),
|
||||
(0x2f, 0x2f, 0x07),
|
||||
(0x37, 0x37, 0x07),
|
||||
(0x3f, 0x3f, 0x07),
|
||||
(0x47, 0x47, 0x07),
|
||||
(0x4b, 0x4b, 0x0b),
|
||||
(0x53, 0x53, 0x0b),
|
||||
(0x5b, 0x5b, 0x0b),
|
||||
(0x63, 0x63, 0x0b),
|
||||
(0x6b, 0x6b, 0x0f),
|
||||
(0x07, 0x00, 0x00),
|
||||
(0x0f, 0x00, 0x00),
|
||||
(0x17, 0x00, 0x00),
|
||||
(0x1f, 0x00, 0x00),
|
||||
(0x27, 0x00, 0x00),
|
||||
(0x2f, 0x00, 0x00),
|
||||
(0x37, 0x00, 0x00),
|
||||
(0x3f, 0x00, 0x00),
|
||||
(0x47, 0x00, 0x00),
|
||||
(0x4f, 0x00, 0x00),
|
||||
(0x57, 0x00, 0x00),
|
||||
(0x5f, 0x00, 0x00),
|
||||
(0x67, 0x00, 0x00),
|
||||
(0x6f, 0x00, 0x00),
|
||||
(0x77, 0x00, 0x00),
|
||||
(0x7f, 0x00, 0x00),
|
||||
(0x13, 0x13, 0x00),
|
||||
(0x1b, 0x1b, 0x00),
|
||||
(0x23, 0x23, 0x00),
|
||||
(0x2f, 0x2b, 0x00),
|
||||
(0x37, 0x2f, 0x00),
|
||||
(0x43, 0x37, 0x00),
|
||||
(0x4b, 0x3b, 0x07),
|
||||
(0x57, 0x43, 0x07),
|
||||
(0x5f, 0x47, 0x07),
|
||||
(0x6b, 0x4b, 0x0b),
|
||||
(0x77, 0x53, 0x0f),
|
||||
(0x83, 0x57, 0x13),
|
||||
(0x8b, 0x5b, 0x13),
|
||||
(0x97, 0x5f, 0x1b),
|
||||
(0xa3, 0x63, 0x1f),
|
||||
(0xaf, 0x67, 0x23),
|
||||
(0x23, 0x13, 0x07),
|
||||
(0x2f, 0x17, 0x0b),
|
||||
(0x3b, 0x1f, 0x0f),
|
||||
(0x4b, 0x23, 0x13),
|
||||
(0x57, 0x2b, 0x17),
|
||||
(0x63, 0x2f, 0x1f),
|
||||
(0x73, 0x37, 0x23),
|
||||
(0x7f, 0x3b, 0x2b),
|
||||
(0x8f, 0x43, 0x33),
|
||||
(0x9f, 0x4f, 0x33),
|
||||
(0xaf, 0x63, 0x2f),
|
||||
(0xbf, 0x77, 0x2f),
|
||||
(0xcf, 0x8f, 0x2b),
|
||||
(0xdf, 0xab, 0x27),
|
||||
(0xef, 0xcb, 0x1f),
|
||||
(0xff, 0xf3, 0x1b),
|
||||
(0x0b, 0x07, 0x00),
|
||||
(0x1b, 0x13, 0x00),
|
||||
(0x2b, 0x23, 0x0f),
|
||||
(0x37, 0x2b, 0x13),
|
||||
(0x47, 0x33, 0x1b),
|
||||
(0x53, 0x37, 0x23),
|
||||
(0x63, 0x3f, 0x2b),
|
||||
(0x6f, 0x47, 0x33),
|
||||
(0x7f, 0x53, 0x3f),
|
||||
(0x8b, 0x5f, 0x47),
|
||||
(0x9b, 0x6b, 0x53),
|
||||
(0xa7, 0x7b, 0x5f),
|
||||
(0xb7, 0x87, 0x6b),
|
||||
(0xc3, 0x93, 0x7b),
|
||||
(0xd3, 0xa3, 0x8b),
|
||||
(0xe3, 0xb3, 0x97),
|
||||
(0xab, 0x8b, 0xa3),
|
||||
(0x9f, 0x7f, 0x97),
|
||||
(0x93, 0x73, 0x87),
|
||||
(0x8b, 0x67, 0x7b),
|
||||
(0x7f, 0x5b, 0x6f),
|
||||
(0x77, 0x53, 0x63),
|
||||
(0x6b, 0x4b, 0x57),
|
||||
(0x5f, 0x3f, 0x4b),
|
||||
(0x57, 0x37, 0x43),
|
||||
(0x4b, 0x2f, 0x37),
|
||||
(0x43, 0x27, 0x2f),
|
||||
(0x37, 0x1f, 0x23),
|
||||
(0x2b, 0x17, 0x1b),
|
||||
(0x23, 0x13, 0x13),
|
||||
(0x17, 0x0b, 0x0b),
|
||||
(0x0f, 0x07, 0x07),
|
||||
(0xbb, 0x73, 0x9f),
|
||||
(0xaf, 0x6b, 0x8f),
|
||||
(0xa3, 0x5f, 0x83),
|
||||
(0x97, 0x57, 0x77),
|
||||
(0x8b, 0x4f, 0x6b),
|
||||
(0x7f, 0x4b, 0x5f),
|
||||
(0x73, 0x43, 0x53),
|
||||
(0x6b, 0x3b, 0x4b),
|
||||
(0x5f, 0x33, 0x3f),
|
||||
(0x53, 0x2b, 0x37),
|
||||
(0x47, 0x23, 0x2b),
|
||||
(0x3b, 0x1f, 0x23),
|
||||
(0x2f, 0x17, 0x1b),
|
||||
(0x23, 0x13, 0x13),
|
||||
(0x17, 0x0b, 0x0b),
|
||||
(0x0f, 0x07, 0x07),
|
||||
(0xdb, 0xc3, 0xbb),
|
||||
(0xcb, 0xb3, 0xa7),
|
||||
(0xbf, 0xa3, 0x9b),
|
||||
(0xaf, 0x97, 0x8b),
|
||||
(0xa3, 0x87, 0x7b),
|
||||
(0x97, 0x7b, 0x6f),
|
||||
(0x87, 0x6f, 0x5f),
|
||||
(0x7b, 0x63, 0x53),
|
||||
(0x6b, 0x57, 0x47),
|
||||
(0x5f, 0x4b, 0x3b),
|
||||
(0x53, 0x3f, 0x33),
|
||||
(0x43, 0x33, 0x27),
|
||||
(0x37, 0x2b, 0x1f),
|
||||
(0x27, 0x1f, 0x17),
|
||||
(0x1b, 0x13, 0x0f),
|
||||
(0x0f, 0x0b, 0x07),
|
||||
(0x6f, 0x83, 0x7b),
|
||||
(0x67, 0x7b, 0x6f),
|
||||
(0x5f, 0x73, 0x67),
|
||||
(0x57, 0x6b, 0x5f),
|
||||
(0x4f, 0x63, 0x57),
|
||||
(0x47, 0x5b, 0x4f),
|
||||
(0x3f, 0x53, 0x47),
|
||||
(0x37, 0x4b, 0x3f),
|
||||
(0x2f, 0x43, 0x37),
|
||||
(0x2b, 0x3b, 0x2f),
|
||||
(0x23, 0x33, 0x27),
|
||||
(0x1f, 0x2b, 0x1f),
|
||||
(0x17, 0x23, 0x17),
|
||||
(0x0f, 0x1b, 0x13),
|
||||
(0x0b, 0x13, 0x0b),
|
||||
(0x07, 0x0b, 0x07),
|
||||
(0xff, 0xf3, 0x1b),
|
||||
(0xef, 0xdf, 0x17),
|
||||
(0xdb, 0xcb, 0x13),
|
||||
(0xcb, 0xb7, 0x0f),
|
||||
(0xbb, 0xa7, 0x0f),
|
||||
(0xab, 0x97, 0x0b),
|
||||
(0x9b, 0x83, 0x07),
|
||||
(0x8b, 0x73, 0x07),
|
||||
(0x7b, 0x63, 0x07),
|
||||
(0x6b, 0x53, 0x00),
|
||||
(0x5b, 0x47, 0x00),
|
||||
(0x4b, 0x37, 0x00),
|
||||
(0x3b, 0x2b, 0x00),
|
||||
(0x2b, 0x1f, 0x00),
|
||||
(0x1b, 0x0f, 0x00),
|
||||
(0x0b, 0x07, 0x00),
|
||||
(0x00, 0x00, 0xff),
|
||||
(0x0b, 0x0b, 0xef),
|
||||
(0x13, 0x13, 0xdf),
|
||||
(0x1b, 0x1b, 0xcf),
|
||||
(0x23, 0x23, 0xbf),
|
||||
(0x2b, 0x2b, 0xaf),
|
||||
(0x2f, 0x2f, 0x9f),
|
||||
(0x2f, 0x2f, 0x8f),
|
||||
(0x2f, 0x2f, 0x7f),
|
||||
(0x2f, 0x2f, 0x6f),
|
||||
(0x2f, 0x2f, 0x5f),
|
||||
(0x2b, 0x2b, 0x4f),
|
||||
(0x23, 0x23, 0x3f),
|
||||
(0x1b, 0x1b, 0x2f),
|
||||
(0x13, 0x13, 0x1f),
|
||||
(0x0b, 0x0b, 0x0f),
|
||||
(0x2b, 0x00, 0x00),
|
||||
(0x3b, 0x00, 0x00),
|
||||
(0x4b, 0x07, 0x00),
|
||||
(0x5f, 0x07, 0x00),
|
||||
(0x6f, 0x0f, 0x00),
|
||||
(0x7f, 0x17, 0x07),
|
||||
(0x93, 0x1f, 0x07),
|
||||
(0xa3, 0x27, 0x0b),
|
||||
(0xb7, 0x33, 0x0f),
|
||||
(0xc3, 0x4b, 0x1b),
|
||||
(0xcf, 0x63, 0x2b),
|
||||
(0xdb, 0x7f, 0x3b),
|
||||
(0xe3, 0x97, 0x4f),
|
||||
(0xe7, 0xab, 0x5f),
|
||||
(0xef, 0xbf, 0x77),
|
||||
(0xf7, 0xd3, 0x8b),
|
||||
(0xa7, 0x7b, 0x3b),
|
||||
(0xb7, 0x9b, 0x37),
|
||||
(0xc7, 0xc3, 0x37),
|
||||
(0xe7, 0xe3, 0x57),
|
||||
(0x7f, 0xbf, 0xff),
|
||||
(0xab, 0xe7, 0xff),
|
||||
(0xd7, 0xff, 0xff),
|
||||
(0x67, 0x00, 0x00),
|
||||
(0x8b, 0x00, 0x00),
|
||||
(0xb3, 0x00, 0x00),
|
||||
(0xd7, 0x00, 0x00),
|
||||
(0xff, 0x00, 0x00),
|
||||
(0xff, 0xf3, 0x93),
|
||||
(0xff, 0xf7, 0xc7),
|
||||
(0xff, 0xff, 0xff),
|
||||
(0x9f, 0x5b, 0x53),
|
||||
)
|
Loading…
Reference in a new issue