Browse Source

More cleanups

pull/50/head
Darryl Pogue 8 years ago
parent
commit
2a693a03c2
No known key found for this signature in database
GPG Key ID: CB824715C3E6FD41
  1. 12
      korman/exporter/manager.py
  2. 21
      korman/exporter/material.py
  3. 24
      korman/exporter/mesh.py
  4. 12
      korman/korlib/texture.py

12
korman/exporter/manager.py

@ -174,14 +174,16 @@ class ExportManager:
key = self.add_object(pl=pClass, name=name, bl=bl, so=so).key key = self.add_object(pl=pClass, name=name, bl=bl, so=so).key
return key return key
def find_key(self, pClass, bl=None, name=None, so=None): def find_key(self, pClass, bl=None, name=None, so=None, loc=None):
"""Given a blender Object and a Plasma class, find (or create) an exported plKey""" """Given a blender Object and a Plasma class, find (or create) an exported plKey"""
assert bl or so assert loc or bl or so
if so is None: if loc is not None:
location = self._pages[bl.plasma_object.page] location = loc
else: elif so is not None:
location = so.key.location location = so.key.location
else:
location = self._pages[bl.plasma_object.page]
if name is None: if name is None:
if bl is not None: if bl is not None:

21
korman/exporter/material.py

@ -110,7 +110,6 @@ class MaterialConverter:
def __init__(self, exporter): def __init__(self, exporter):
self._obj2mat = {} self._obj2mat = {}
self._bumpMats = {} self._bumpMats = {}
self._bumpLUT = None
self._exporter = weakref.ref(exporter) self._exporter = weakref.ref(exporter)
self._pending = {} self._pending = {}
self._alphatest = {} self._alphatest = {}
@ -240,16 +239,18 @@ class MaterialConverter:
dw_layer.UVWSrc = du_uv | plLayerInterface.kUVWNormal dw_layer.UVWSrc = du_uv | plLayerInterface.kUVWNormal
dv_layer.UVWSrc = du_uv + 1 dv_layer.UVWSrc = du_uv + 1
if self._bumpLUT is None:
self._bumpLUT = plMipmap("BumpLutTexture", 16, 16, 1, plBitmap.kUncompressed, plBitmap.kRGB8888)
GLTexture.create_bump_LUT(self._bumpLUT)
page = self._mgr.get_textures_page(du_layer.key) page = self._mgr.get_textures_page(du_layer.key)
self._mgr.AddObject(page, self._bumpLUT) LUT_key = self._mgr.find_key(plMipmap, loc=page, name="BumpLutTexture")
if LUT_key is None:
bumpLUT = plMipmap("BumpLutTexture", 16, 16, 1, plBitmap.kUncompressed, plBitmap.kRGB8888)
GLTexture.create_bump_LUT(bumpLUT)
self._mgr.AddObject(page, bumpLUT)
LUT_key = bumpLUT.key
du_layer.texture = self._bumpLUT.key du_layer.texture = LUT_key
dw_layer.texture = self._bumpLUT.key dw_layer.texture = LUT_key
dv_layer.texture = self._bumpLUT.key dv_layer.texture = LUT_key
return (du_layer, dw_layer, dv_layer) return (du_layer, dw_layer, dv_layer)
@ -673,7 +674,7 @@ class MaterialConverter:
def get_materials(self, bo): def get_materials(self, bo):
return self._obj2mat.get(bo, []) return self._obj2mat.get(bo, [])
def has_bump_layer(self, bo): def get_bump_layer(self, bo):
return self._bumpMats.get(bo, None) return self._bumpMats.get(bo, None)
def get_texture_animation_key(self, bo, bm, tex_name=None, tex_slot=None): def get_texture_animation_key(self, bo, bm, tex_name=None, tex_slot=None):

24
korman/exporter/mesh.py

@ -175,7 +175,7 @@ class MeshConverter:
def _export_geometry(self, bo, mesh, materials, geospans): def _export_geometry(self, bo, mesh, materials, geospans):
geodata = [_GeoData(len(mesh.vertices)) for i in materials] geodata = [_GeoData(len(mesh.vertices)) for i in materials]
has_bumpmap = self.material.has_bump_layer(bo) has_bumpmap = self.material.get_bump_layer(bo)
# Locate relevant vertex color layers now... # Locate relevant vertex color layers now...
color, alpha = None, None color, alpha = None, None
@ -225,13 +225,19 @@ class MeshConverter:
if len(tessface.vertices) != 3: if len(tessface.vertices) != 3:
gradPass.append([tessface.vertices[0], tessface.vertices[1], tessface.vertices[2]]) gradPass.append([tessface.vertices[0], tessface.vertices[1], tessface.vertices[2]])
gradPass.append([tessface.vertices[0], tessface.vertices[2], tessface.vertices[3]]) gradPass.append([tessface.vertices[0], tessface.vertices[2], tessface.vertices[3]])
gradUVWs.append([tuple([uvw[0] for uvw in tessface_uvws]), tuple([uvw[1] for uvw in tessface_uvws]), tuple([uvw[2] for uvw in tessface_uvws])]) gradUVWs.append((tuple((uvw[0] for uvw in tessface_uvws)),
gradUVWs.append([tuple([uvw[0] for uvw in tessface_uvws]), tuple([uvw[2] for uvw in tessface_uvws]), tuple([uvw[3] for uvw in tessface_uvws])]) tuple((uvw[1] for uvw in tessface_uvws)),
tuple((uvw[2] for uvw in tessface_uvws))))
gradUVWs.append((tuple((uvw[0] for uvw in tessface_uvws)),
tuple((uvw[2] for uvw in tessface_uvws)),
tuple((uvw[3] for uvw in tessface_uvws))))
else: else:
gradPass.append(tessface.vertices) gradPass.append(tessface.vertices)
gradUVWs.append([tuple([uvw[0] for uvw in tessface_uvws]), tuple([uvw[1] for uvw in tessface_uvws]), tuple([uvw[2] for uvw in tessface_uvws])]) gradUVWs.append((tuple((uvw[0] for uvw in tessface_uvws)),
tuple((uvw[1] for uvw in tessface_uvws)),
tuple((uvw[2] for uvw in tessface_uvws))))
for p,vids in enumerate(gradPass): for p, vids in enumerate(gradPass):
dPosDu += self._get_bump_gradient(has_bumpmap[1], gradUVWs[p], mesh, vids, has_bumpmap[0], 0) dPosDu += self._get_bump_gradient(has_bumpmap[1], gradUVWs[p], mesh, vids, has_bumpmap[0], 0)
dPosDv += self._get_bump_gradient(has_bumpmap[1], gradUVWs[p], mesh, vids, has_bumpmap[0], 1) dPosDv += self._get_bump_gradient(has_bumpmap[1], gradUVWs[p], mesh, vids, has_bumpmap[0], 1)
dPosDv = -dPosDv dPosDv = -dPosDv
@ -301,7 +307,7 @@ class MeshConverter:
# If we're bump mapping, we need to normalize our magic UVW channels # If we're bump mapping, we need to normalize our magic UVW channels
if has_bumpmap is not None: if has_bumpmap is not None:
geospan.format += 2 # We dded 2 special bumpmapping UV layers geospan.format += 2 # We dded 2 special bumpmapping UV layers
for v, vtx in enumerate(data.vertices): for vtx in data.vertices:
uvMap = vtx.uvs uvMap = vtx.uvs
uvMap[geospan.format - 2].normalize() uvMap[geospan.format - 2].normalize()
uvMap[geospan.format - 1].normalize() uvMap[geospan.format - 1].normalize()
@ -317,9 +323,9 @@ class MeshConverter:
v1 = hsVector3(*mesh.vertices[vIds[1]].co) v1 = hsVector3(*mesh.vertices[vIds[1]].co)
v2 = hsVector3(*mesh.vertices[vIds[2]].co) v2 = hsVector3(*mesh.vertices[vIds[2]].co)
uv0 = [(uv[0], uv[1], 0.0) for uv in uvws[0]][uvIdx] uv0 = (uvws[0][uvIdx][0], uvws[0][uvIdx][1], 0.0)
uv1 = [(uv[0], uv[1], 0.0) for uv in uvws[1]][uvIdx] uv1 = (uvws[1][uvIdx][0], uvws[1][uvIdx][1], 0.0)
uv2 = [(uv[0], uv[1], 0.0) for uv in uvws[2]][uvIdx] uv2 = (uvws[2][uvIdx][0], uvws[2][uvIdx][1], 0.0)
notUV = int(not iUV) notUV = int(not iUV)
kRealSmall = 1.e-6 kRealSmall = 1.e-6

12
korman/korlib/texture.py

@ -201,26 +201,26 @@ class GLTexture:
doneH = 0 doneH = 0
doneH = startH * kLUTWidth * 4 doneH = startH * kLUTWidth * 4
buf[0:doneH] = [b for x in range(kLUTWidth) for b in [0, 0, int((x / denom) * 255.9), 255]] * startH buf[0:doneH] = [b for x in range(kLUTWidth) for b in (0, 0, int((x / denom) * 255.9), 255)] * startH
startH = doneH startH = doneH
doneH += delH * kLUTWidth * 4 doneH += delH * kLUTWidth * 4
buf[startH:doneH] = [b for x in range(kLUTWidth) for b in [127, 127, int((x / denom) * 255.9), 255]] * delH buf[startH:doneH] = [b for x in range(kLUTWidth) for b in (127, 127, int((x / denom) * 255.9), 255)] * delH
startH = doneH startH = doneH
doneH += delH * kLUTWidth * 4 doneH += delH * kLUTWidth * 4
buf[startH:doneH] = [b for x in range(kLUTWidth) for b in [0, int((x / denom) * 255.9), 0, 255]] * delH buf[startH:doneH] = [b for x in range(kLUTWidth) for b in (0, int((x / denom) * 255.9), 0, 255)] * delH
startH = doneH startH = doneH
doneH += delH * kLUTWidth * 4 doneH += delH * kLUTWidth * 4
buf[startH:doneH] = [b for x in range(kLUTWidth) for b in [127, int((x / denom) * 255.9), 127, 255]] * delH buf[startH:doneH] = [b for x in range(kLUTWidth) for b in (127, int((x / denom) * 255.9), 127, 255)] * delH
startH = doneH startH = doneH
doneH += delH * kLUTWidth * 4 doneH += delH * kLUTWidth * 4
buf[startH:doneH] = [b for x in range(kLUTWidth) for b in [int((x / denom) * 255.9), 0, 0, 255]] * delH buf[startH:doneH] = [b for x in range(kLUTWidth) for b in (int((x / denom) * 255.9), 0, 0, 255)] * delH
startH = doneH startH = doneH
doneH += delH * kLUTWidth * 4 doneH += delH * kLUTWidth * 4
buf[startH:doneH] = [b for x in range(kLUTWidth) for b in [int((x / denom) * 255.9), 127, 127, 255]] * startH buf[startH:doneH] = [b for x in range(kLUTWidth) for b in (int((x / denom) * 255.9), 127, 127, 255)] * startH
mipmap.setRawImage(bytes(buf)) mipmap.setRawImage(bytes(buf))

Loading…
Cancel
Save