[varLib.models] Add getMasterScalars
This commit is contained in:
parent
3ecbc94dcf
commit
85883f09bc
@ -472,6 +472,22 @@ class VariationModel(object):
|
||||
for support in self.supports
|
||||
]
|
||||
|
||||
def _getMasterScalarsRecurse(self, out, j, weights, scalar=1):
|
||||
for i, weight in weights.items():
|
||||
influence = -weight * scalar
|
||||
out[i] += influence
|
||||
self._getMasterScalarsRecurse(out, i, self.deltaWeights[i], influence)
|
||||
|
||||
def getMasterScalars(self, targetLocation):
|
||||
out = []
|
||||
for i, (weights, support) in enumerate(zip(self.deltaWeights, self.supports)):
|
||||
scalar = supportScalar(targetLocation, support)
|
||||
out.append(scalar)
|
||||
self._getMasterScalarsRecurse(out, i, weights, scalar)
|
||||
|
||||
out = [out[self.mapping[i]] for i in range(len(out))]
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def interpolateFromDeltasAndScalars(deltas, scalars):
|
||||
v = None
|
||||
|
@ -397,7 +397,7 @@ class VariationModelTest(object):
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"locations, axisOrder, masterValues, instanceLocation, expectedValue",
|
||||
"locations, axisOrder, masterValues, instanceLocation, expectedValue, masterScalars",
|
||||
[
|
||||
(
|
||||
[
|
||||
@ -422,6 +422,7 @@ class VariationModelTest(object):
|
||||
"axis_B": 0.5,
|
||||
},
|
||||
37.5,
|
||||
[0.25, 0.0, 0.0, -0.25, 0.5, 0.5],
|
||||
),
|
||||
],
|
||||
)
|
||||
@ -432,8 +433,11 @@ class VariationModelTest(object):
|
||||
masterValues,
|
||||
instanceLocation,
|
||||
expectedValue,
|
||||
masterScalars,
|
||||
):
|
||||
model = VariationModel(locations, axisOrder=axisOrder)
|
||||
interpolatedValue = model.interpolateFromMasters(instanceLocation, masterValues)
|
||||
|
||||
interpolatedValue = model.interpolateFromMasters(instanceLocation, masterValues)
|
||||
assert interpolatedValue == expectedValue
|
||||
|
||||
assert masterScalars == model.getMasterScalars(instanceLocation)
|
||||
|
Loading…
x
Reference in New Issue
Block a user