@@ -394,10 +394,12 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT):
394
394
continue
395
395
396
396
face_verts = []
397
- use_smooth = tessface .use_smooth
398
397
dPosDu = hsVector3 (0.0 , 0.0 , 0.0 )
399
398
dPosDv = hsVector3 (0.0 , 0.0 , 0.0 )
400
399
400
+ # Unpack normals
401
+ tessface_normals = tessface .split_normals
402
+
401
403
# Unpack the UV coordinates from each UV Texture layer
402
404
# NOTE: Blender has no third (W) coordinate
403
405
tessface_uvws = [uvtex .data [i ].uv for uvtex in mesh .tessface_uv_textures ]
@@ -446,6 +448,7 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT):
446
448
447
449
# Convert to per-material indices
448
450
for j , vertex in enumerate (tessface .vertices ):
451
+ vertex_normal = tuple (tessface_normals [j ])
449
452
uvws = tuple ([tuple (uvw [j ]) for uvw in tessface_uvws ])
450
453
451
454
# Calculate vertex colors.
@@ -462,18 +465,14 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT):
462
465
# Now, we'll index into the vertex dict using the per-face elements :(
463
466
# We're using tuples because lists are not hashable. The many mathutils and PyHSPlasma
464
467
# types are not either, and it's entirely too much work to fool with all that.
465
- coluv = (vertex_color , uvws )
466
- if coluv not in data .blender2gs [vertex ]:
468
+ normcoluv = (vertex_normal , vertex_color , uvws )
469
+ if normcoluv not in data .blender2gs [vertex ]:
467
470
source = mesh .vertices [vertex ]
468
471
geoVertex = plGeometrySpan .TempVertex ()
469
472
geoVertex .position = hsVector3 (* source .co )
470
473
471
- # If this face has smoothing, use the vertex normal
472
- # Otherwise, use the face normal
473
- normal = source .normal if use_smooth else tessface .normal
474
-
475
474
# MOUL/DX9 craps its pants if any element of the normal is exactly 0.0
476
- normal = map (lambda x : max (x , 0.01 ) if x >= 0.0 else min (x , - 0.01 ), normal )
475
+ normal = map (lambda x : max (x , 0.01 ) if x >= 0.0 else min (x , - 0.01 ), vertex_normal )
477
476
normal = hsVector3 (* normal )
478
477
normal .normalize ()
479
478
geoVertex .normal = normal
@@ -486,15 +485,15 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT):
486
485
geoVertex .uvs = uvs
487
486
488
487
idx = len (data .vertices )
489
- data .blender2gs [vertex ][coluv ] = idx
488
+ data .blender2gs [vertex ][normcoluv ] = idx
490
489
data .vertices .append (geoVertex )
491
490
face_verts .append (idx )
492
491
else :
493
492
# If we have a bump mapping layer, then we need to add the bump gradients for
494
493
# this face to the vertex's magic channels
495
494
if bumpmap is not None :
496
495
num_user_uvs = len (uvws )
497
- geoVertex = data .vertices [data .blender2gs [vertex ][coluv ]]
496
+ geoVertex = data .vertices [data .blender2gs [vertex ][normcoluv ]]
498
497
499
498
# Unfortunately, PyHSPlasma returns a copy of everything. Previously, editing
500
499
# in place would result in silent failures; however, as of python_refactor,
@@ -503,7 +502,7 @@ def _export_geometry(self, bo, mesh, materials, geospans, mat2span_LUT):
503
502
geoUVs [num_user_uvs ] += dPosDu
504
503
geoUVs [num_user_uvs + 1 ] += dPosDv
505
504
geoVertex .uvs = geoUVs
506
- face_verts .append (data .blender2gs [vertex ][coluv ])
505
+ face_verts .append (data .blender2gs [vertex ][normcoluv ])
507
506
508
507
# Convert to triangles, if need be...
509
508
num_faces = len (face_verts )
@@ -614,6 +613,7 @@ def _export_object(self, bo):
614
613
return self ._export_mesh (bo , mesh )
615
614
616
615
def _export_mesh (self , bo , mesh ):
616
+ mesh .calc_normals_split ()
617
617
mesh .calc_tessface ()
618
618
619
619
# Step 0.8: Determine materials needed for export... Three considerations here:
0 commit comments