Fix #129: PSK can be imported into UT2 with incorrect weighting
Weights within the PSK are now sorted by point_index and have their weights normalized.
This commit is contained in:
@@ -421,6 +421,9 @@ def build_psk(context: Context, input_objects: PskInputObjects, options: PskBuil
|
|||||||
|
|
||||||
context.window_manager.progress_end()
|
context.window_manager.progress_end()
|
||||||
|
|
||||||
|
# https://github.com/DarklightGames/io_scene_psk_psa/issues/129.
|
||||||
|
psk.sort_and_normalize_weights()
|
||||||
|
|
||||||
result.psk = psk
|
result.psk = psk
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -113,6 +113,26 @@ class Psk(object):
|
|||||||
def has_morph_data(self):
|
def has_morph_data(self):
|
||||||
return len(self.morph_infos) > 0
|
return len(self.morph_infos) > 0
|
||||||
|
|
||||||
|
def sort_and_normalize_weights(self):
|
||||||
|
self.weights.sort(key=lambda x: x.point_index)
|
||||||
|
weight_index = 0
|
||||||
|
weight_total = len(self.weights)
|
||||||
|
while weight_index < weight_total:
|
||||||
|
point_weight_total = 1
|
||||||
|
point_index: int = self.weights[weight_index].point_index
|
||||||
|
weight_sum: float = self.weights[weight_index].weight
|
||||||
|
# Count the number of weights with contiguous point indices and sum the total weights.
|
||||||
|
for w in range(weight_index + 1, weight_total):
|
||||||
|
if point_index != self.weights[w].point_index:
|
||||||
|
break
|
||||||
|
point_weight_total += 1
|
||||||
|
weight_sum += self.weights[w].weight
|
||||||
|
# Now normalize the weights against the sum of all weights.
|
||||||
|
for weight in self.weights[weight_index:weight_index+point_weight_total]:
|
||||||
|
weight.weight /= weight_sum
|
||||||
|
# Increment
|
||||||
|
weight_index += point_weight_total
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.points: List[Vector3] = []
|
self.points: List[Vector3] = []
|
||||||
self.wedges: List[Psk.Wedge] = []
|
self.wedges: List[Psk.Wedge] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user