Browse Source

Update some bumpmap variables to obey The Zen

pull/50/head^2
Adam Johnson 7 years ago
parent
commit
64369b836d
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 8
      korman/exporter/material.py
  2. 20
      korman/exporter/mesh.py

8
korman/exporter/material.py

@ -109,7 +109,7 @@ class _Texture:
class MaterialConverter:
def __init__(self, exporter):
self._obj2mat = {}
self._bumpMats = {}
self._bump_mats = {}
self._exporter = weakref.ref(exporter)
self._pending = {}
self._alphatest = {}
@ -147,7 +147,7 @@ class MaterialConverter:
for idx, slot in slots:
# Prepend any BumpMapping magic layers
if slot.use_map_normal:
if bo in self._bumpMats:
if bo in self._bump_mats:
raise ExportError("Material '{}' has more than one bumpmap layer".format(bm.name))
du, dw, dv = self.export_bumpmap_slot(bo, bm, hsgmat, slot, idx)
hsgmat.addLayer(du.key) # Du
@ -163,7 +163,7 @@ class MaterialConverter:
restart_pass_next = False
hsgmat.addLayer(tex_layer.key)
if slot.use_map_normal:
self._bumpMats[bo] = (tex_layer.UVWSrc, tex_layer.transform)
self._bump_mats[bo] = (tex_layer.UVWSrc, tex_layer.transform)
# After a bumpmap layer(s), the next layer *must* be in a
# new pass, otherwise it gets added in non-intuitive ways
restart_pass_next = True
@ -682,7 +682,7 @@ class MaterialConverter:
return self._obj2mat.get(bo, [])
def get_bump_layer(self, bo):
return self._bumpMats.get(bo, None)
return self._bump_mats.get(bo, None)
def get_texture_animation_key(self, bo, bm, tex_name=None, tex_slot=None):
"""Finds or creates the appropriate key for sending messages to an animated Texture"""

20
korman/exporter/mesh.py

@ -193,7 +193,7 @@ class MeshConverter:
def _export_geometry(self, bo, mesh, materials, geospans):
geodata = [_GeoData(len(mesh.vertices)) for i in materials]
has_bumpmap = self.material.get_bump_layer(bo)
bumpmap = self.material.get_bump_layer(bo)
# Locate relevant vertex color layers now...
color, alpha = None, None
@ -236,7 +236,7 @@ class MeshConverter:
((src.color3[0] + src.color3[1] + src.color3[2]) / 3),
((src.color4[0] + src.color4[1] + src.color4[2]) / 3))
if has_bumpmap is not None:
if bumpmap is not None:
gradPass = []
gradUVWs = []
@ -256,8 +256,8 @@ class MeshConverter:
tuple((uvw[2] for uvw in tessface_uvws))))
for p, vids in enumerate(gradPass):
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)
dPosDu += self._get_bump_gradient(bumpmap[1], gradUVWs[p], mesh, vids, bumpmap[0], 0)
dPosDv += self._get_bump_gradient(bumpmap[1], gradUVWs[p], mesh, vids, bumpmap[0], 1)
dPosDv = -dPosDv
# Convert to per-material indices
@ -292,7 +292,7 @@ class MeshConverter:
face_verts.append(data.blender2gs[vertex][coluv])
if has_bumpmap is not None:
if bumpmap is not None:
idx = len(uvws)
geoVert = data.vertices[data.blender2gs[vertex][coluv]]
# We can't edit in place :\
@ -324,7 +324,7 @@ class MeshConverter:
raise explosions.TooManyVerticesError(bo.data.name, geospan.material.name, numVerts)
# If we're bump mapping, we need to normalize our magic UVW channels
if has_bumpmap is not None:
if bumpmap is not None:
for vtx in data.vertices:
uvMap = vtx.uvs
uvMap[numUVs - 2].normalize()
@ -346,18 +346,18 @@ class MeshConverter:
uv2 = (uvws[2][uvIdx][0], uvws[2][uvIdx][1], 0.0)
notUV = int(not iUV)
kRealSmall = 1.e-6
_REAL_SMALL = 0.000001
delta = uv0[notUV] - uv1[notUV]
if fabs(delta) < kRealSmall:
if fabs(delta) < _REAL_SMALL:
return v1 - v0 if uv0[iUV] - uv1[iUV] < 0 else v0 - v1
delta = uv2[notUV] - uv1[notUV]
if fabs(delta) < kRealSmall:
if fabs(delta) < _REAL_SMALL:
return v1 - v2 if uv2[iUV] - uv1[iUV] < 0 else v2 - v1
delta = uv2[notUV] - uv0[notUV]
if fabs(delta) < kRealSmall:
if fabs(delta) < _REAL_SMALL:
return v0 - v2 if uv2[iUV] - uv0[iUV] < 0 else v2 - v0
# On to the real fun...

Loading…
Cancel
Save