Skip to content

Commit

Permalink
Add Support for Normalizing Bone Weights
Browse files Browse the repository at this point in the history
  • Loading branch information
SE2Dev committed Apr 3, 2017
1 parent 4cfc0ca commit bbd23db
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from itertools import repeat
from time import strftime
from math import sqrt


def __clamp_float__(value, range=(-1.0, 1.0)):
Expand All @@ -10,6 +11,11 @@ def __clamp_multi__(value, range=(-1.0, 1.0)):
return tuple([max(min(v, range[1]), range[0]) for v in value])


def __normalized__(iterable):
d = 1.0 / sqrt(sum([v * v for v in iterable]))
return [v * d for v in iterable]


def deserialize_image_string(ref_string):
if len(ref_string) == 0:
return {"color": "$none.tga"}
Expand Down Expand Up @@ -600,6 +606,14 @@ def __load_materials__(self, file, version):

return lines_read

def normalize_weights(self):
"""
Normalize the bone weights for all verts (in all meshes)
"""
for mesh in self.meshes:
for vert in mesh.verts:
vert.weights = __normalized__(vert.weights)

def LoadFile(self, path, split_meshes=True):
file = open(path, "r")
# file automatically keeps track of what line its on across calls
Expand Down

0 comments on commit bbd23db

Please sign in to comment.