Fix a slew of whitespace issues.

This commit is contained in:
Bill Currie 2012-08-07 13:25:44 +09:00
parent a3c8209bdf
commit 971e689d3d
4 changed files with 54 additions and 53 deletions

View file

@ -70,7 +70,7 @@ def convert_image(image):
if i > 255: # should never happen
break
r = 0
for x in map (lambda a, b: (a - b) ** 2, rgb, p):
for x in map(lambda a, b: (a - b) ** 2, rgb, p):
r += x
if r < best[0]:
best = (r, i)
@ -115,7 +115,7 @@ def build_tris(mesh):
uv = uvfaces[face.loop_start:face.loop_start + face.loop_total]
uv = list(map(lambda a: a.uv, uv))
face_tris = []
for i in range (1, len(fv) - 1):
for i in range(1, len(fv) - 1):
# blender's and quake's vertex order are opposed
face_tris.append([(fv[0], tuple(uv[0])),
(fv[i + 1], tuple(uv[i + 1])),
@ -132,16 +132,16 @@ def build_tris(mesh):
return tris, stverts, vertmap
def convert_stverts(mdl, stverts):
for i, st in enumerate (stverts):
for i, st in enumerate(stverts):
s, t = st
# quake textures are top to bottom, but blender images
# are bottom to top
s = int (s * (mdl.skinwidth - 1) + 0.5)
t = int ((1 - t) * (mdl.skinheight - 1) + 0.5)
s = int(s * (mdl.skinwidth - 1) + 0.5)
t = int((1 - t) * (mdl.skinheight - 1) + 0.5)
# ensure st is within the skin
s = ((s % mdl.skinwidth) + mdl.skinwidth) % mdl.skinwidth
t = ((t % mdl.skinheight) + mdl.skinheight) % mdl.skinheight
stverts[i] = MDL.STVert ((s, t))
stverts[i] = MDL.STVert((s, t))
def make_frame(mesh, vertmap):
frame = MDL.Frame()
@ -177,7 +177,7 @@ def calc_average_area(mdl):
return totalarea / len(mdl.tris)
def get_properties(operator, mdl, obj):
mdl.eyeposition = tuple (obj.qfmdl.eyeposition)
mdl.eyeposition = tuple(obj.qfmdl.eyeposition)
mdl.synctype = MDL.SYNCTYPE[obj.qfmdl.synctype]
mdl.flags = ((obj.qfmdl.rotate and MDL.EF_ROTATE or 0)
| MDL.EFFECTS[obj.qfmdl.effects])
@ -215,7 +215,7 @@ def process_skin(mdl, skin, ingroup=False):
sk.times = intervals[1:len(skin['skins']) + 1]
sk.skins = []
for s in skin['skins']:
sk.skins.append(process_skin (mdl, s, True))
sk.skins.append(process_skin(mdl, s, True))
return sk
else:
#FIXME error handling
@ -225,7 +225,8 @@ def process_skin(mdl, skin, ingroup=False):
if (mdl.skinwidth != image.size[0]
or mdl.skinheight != image.size[1]):
raise ValueError("%s: different skin size (%d %d) (%d %d)"
% (name, mdl.skinwidth, mdl.skinheight, int(image.size[0]), int(image.size[1])))
% (name, mdl.skinwidth, mdl.skinheight,
int(image.size[0]), int(image.size[1])))
else:
mdl.skinwidth, mdl.skinheight = image.size
sk = convert_image(image)
@ -251,25 +252,25 @@ def process_frame(mdl, scene, frame, vertmap, ingroup = False,
intervals.append(intervals[-1] + 0.1)
fr = MDL.Frame()
for i, f in enumerate(frame['frames']):
fr.add_frame(process_frame (mdl, scene, f, vertmap, True,
frameno + i, name + str(i + 1)),
fr.add_frame(process_frame(mdl, scene, f, vertmap, True,
frameno + i, name + str(i + 1)),
intervals[i + 1])
if 'intervals' in frame:
return fr
mdl.frames += fr.frames[:-1]
return fr.frames[-1]
scene.frame_set (int(frameno), frameno - int(frameno))
mesh = mdl.obj.to_mesh (scene, True, 'PREVIEW') #wysiwyg?
scene.frame_set(int(frameno), frameno - int(frameno))
mesh = mdl.obj.to_mesh(scene, True, 'PREVIEW') #wysiwyg?
if mdl.obj.qfmdl.xform:
mesh.transform (mdl.obj.matrix_world)
mesh.transform(mdl.obj.matrix_world)
fr = make_frame(mesh, vertmap)
fr.name = name
return fr
def export_mdl(operator, context, filepath):
obj = context.active_object
mesh = obj.to_mesh (context.scene, True, 'PREVIEW') #wysiwyg?
#if not check_faces (mesh):
mesh = obj.to_mesh(context.scene, True, 'PREVIEW') #wysiwyg?
#if not check_faces(mesh):
# operator.report({'ERROR'},
# "Mesh has faces with more than 3 vertices.")
# return {'CANCELLED'}
@ -296,7 +297,7 @@ def export_mdl(operator, context, filepath):
if mdl.obj.qfmdl.xform:
mesh.transform(mdl.obj.matrix_world)
mdl.frames.append(make_frame(mesh, vertmap))
convert_stverts (mdl, mdl.stverts)
convert_stverts(mdl, mdl.stverts)
mdl.size = calc_average_area(mdl)
scale_verts(mdl)
mdl.write(filepath)

View file

@ -65,7 +65,7 @@ def make_faces(mdl):
if not tv[2]:
tv = [tv[2]] + tv[:2]
sts = [sts[2]] + sts[:2]
faces.append (tv)
faces.append(tv)
uvs.append(sts)
return faces, uvs
@ -94,12 +94,12 @@ def load_skins(mdl):
for i, skin in enumerate(mdl.skins):
if skin.type:
for j, subskin in enumerate(skin.skins):
load_skin (subskin, "%s_%d_%d" % (mdl.name, i, j))
load_skin(subskin, "%s_%d_%d" % (mdl.name, i, j))
else:
load_skin (skin, "%s_%d" % (mdl.name, i))
load_skin(skin, "%s_%d" % (mdl.name, i))
def setup_skins (mdl, uvs):
load_skins (mdl)
def setup_skins(mdl, uvs):
load_skins(mdl)
img = mdl.images[0] # use the first skin for now
uvlay = mdl.mesh.uv_textures.new(mdl.name)
uvloop = mdl.mesh.uv_layers[0]
@ -135,7 +135,7 @@ def make_shape_key(mdl, framenum, subframenum=0):
frame.name = name
frame.key = mdl.obj.shape_key_add(name)
frame.key.value = 0.0
mdl.keys.append (frame.key)
mdl.keys.append(frame.key)
s = Vector(mdl.scale)
o = Vector(mdl.scale_origin)
m = Matrix(((s.x, 0, 0,o.x),
@ -171,7 +171,7 @@ def set_keys(act, data):
def build_actions(mdl):
sk = mdl.mesh.shape_keys
ad = sk.animation_data_create()
track = ad.nla_tracks.new ();
track = ad.nla_tracks.new();
track.name = mdl.name
start_frame = 1.0
for frame in mdl.frames:
@ -183,14 +183,14 @@ def build_actions(mdl):
subframe.frameno = start_frame + j
co = []
if j > 1:
co.append ((1.0, 0.0))
co.append((1.0, 0.0))
if j > 0:
co.append ((j * 1.0, 0.0))
co.append (((j + 1) * 1.0, 1.0))
co.append((j * 1.0, 0.0))
co.append(((j + 1) * 1.0, 1.0))
if j < len(frame.frames) - 2:
co.append (((j + 2) * 1.0, 0.0))
co.append(((j + 2) * 1.0, 0.0))
if j < len(frame.frames) - 1:
co.append ((len(frame.frames) * 1.0, 0.0))
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)])
@ -205,8 +205,8 @@ def build_actions(mdl):
co = [(1.0, 0.0)]
for k in other_keys:
data.append((k, co))
set_keys (act, data)
track.strips.new (act.name, start_frame, act)
set_keys(act, data)
track.strips.new(act.name, start_frame, act)
start_frame += act.frame_range[1]
def merge_frames(mdl):
@ -349,15 +349,15 @@ def import_mdl(operator, context, filepath):
operator.report({'ERROR'},
"Unrecognized format: %s %d" % (mdl.ident, mdl.version))
return {'CANCELLED'}
faces, uvs = make_faces (mdl)
verts = make_verts (mdl, 0)
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)
setup_skins(mdl, uvs)
if len(mdl.frames) > 1 or mdl.frames[0].type:
build_shape_keys(mdl)
merge_frames(mdl)

View file

@ -346,7 +346,7 @@ class MDL:
#read in the st verts (uv map)
self.stverts = []
for i in range(numverts):
self.stverts.append (MDL.STVert().read(self))
self.stverts.append(MDL.STVert().read(self))
#read in the tris
self.tris = []
for i in range(numtris):
@ -357,23 +357,23 @@ class MDL:
self.frames.append(MDL.Frame().read(self, numverts))
return self
def write (self, filepath):
def write(self, filepath):
self.file = open(filepath, "wb")
self.write_string (self.ident, 4)
self.write_int (self.version)
self.write_float (self.scale)
self.write_float (self.scale_origin)
self.write_float (self.boundingradius)
self.write_float (self.eyeposition)
self.write_int (len(self.skins))
self.write_int ((self.skinwidth, self.skinheight))
self.write_int (len(self.stverts))
self.write_int (len(self.tris))
self.write_int (len(self.frames))
self.write_int (self.synctype)
self.write_string(self.ident, 4)
self.write_int(self.version)
self.write_float(self.scale)
self.write_float(self.scale_origin)
self.write_float(self.boundingradius)
self.write_float(self.eyeposition)
self.write_int(len(self.skins))
self.write_int((self.skinwidth, self.skinheight))
self.write_int(len(self.stverts))
self.write_int(len(self.tris))
self.write_int(len(self.frames))
self.write_int(self.synctype)
if self.version == 6:
self.write_int (self.flags)
self.write_float (self.size)
self.write_int(self.flags)
self.write_float(self.size)
# write out the skin data
for skin in self.skins:
skin.write(self)

View file

@ -31,7 +31,7 @@ class pldata:
def __init__(self, src = ''):
self.src = src
self.pos = 0;
self.end = len (self.src)
self.end = len(self.src)
self.line = 1
def skip_space(self):
while self.pos < self.end:
@ -226,7 +226,7 @@ class pldata:
self.data.append(';\n')
self.data.append('\t' * (level))
self.data.append("}")
elif type(item) in (list, tuple):
elif type(item) in(list, tuple):
self.data.append("(\n")
for n, i in enumerate(item):
self.data.append('\t' * (level + 1))
@ -243,7 +243,7 @@ class pldata:
elif type(item) == str:
self.write_string(item)
else:
raise PListError (0, "unsupported type")
raise PListError(0, "unsupported type")
def write(self, item):
self.data = []
self.write_item(item, 0)