From 08d93dd7970f063297436378e7a5e9a319e13dab Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 9 Jun 2017 16:07:09 -0400 Subject: [PATCH] Update GeoVertex UV touching for HSPlasma changes plGeometrySpan.TempVertex.uvs now returns an immutable tuple, so we have to convert that to a list. Furthermore, I took the liberty of changing to code to avoid spin-washing on the first encounter of a bumpmapped vertex. --- korman/exporter/mesh.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index 8c75398..98fb63c 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -285,21 +285,31 @@ class MeshConverter: geoVertex.normal = hsVector3(*tessface.normal) geoVertex.color = hsColor32(*vertex_color) - geoVertex.uvs = [hsVector3(uv[0], 1.0 - uv[1], 0.0) for uv in uvws] - - data.blender2gs[vertex][coluv] = len(data.vertices) + uvs = [hsVector3(uv[0], 1.0 - uv[1], 0.0) for uv in uvws] + if bumpmap is not None: + uvs.append(dPosDu) + uvs.append(dPosDv) + geoVertex.uvs = uvs + + idx = len(data.vertices) + data.blender2gs[vertex][coluv] = idx data.vertices.append(geoVertex) - - face_verts.append(data.blender2gs[vertex][coluv]) - - if bumpmap is not None: - idx = len(uvws) - geoVert = data.vertices[data.blender2gs[vertex][coluv]] - # We can't edit in place :\ - uvMaps = geoVert.uvs - uvMaps[idx] += dPosDu - uvMaps[idx + 1] += dPosDv - geoVert.uvs = uvMaps + face_verts.append(idx) + else: + # If we have a bump mapping layer, then we need to add the bump gradients for + # this face to the vertex's magic channels + if bumpmap is not None: + num_user_uvs = len(uvws) + geoVertex = data.vertices[data.blender2gs[vertex][coluv]] + + # Unfortunately, PyHSPlasma returns a copy of everything. Previously, editing + # in place would result in silent failures; however, as of python_refactor, + # PyHSPlasma now returns tuples to indicate this. + geoUVs = list(geoVertex.uvs) + geoUVs[num_user_uvs] += dPosDu + geoUVs[num_user_uvs+1] += dPosDv + geoVertex.uvs = geoUVs + face_verts.append(data.blender2gs[vertex][coluv]) # Convert to triangles, if need be... if len(face_verts) == 3: