Merge pull request #2148 from Santarh/vrm0xBlendshapePreview

[VRM0.x] Fix wrong preview results in editor inspector when a vrm blendshape material target is "*_ST_S" or "*_ST_T"
This commit is contained in:
ousttrue 2023-10-11 20:03:45 +09:00 committed by GitHub
commit ebb7ef67c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,24 +245,29 @@ namespace VRM
foreach (var x in bake.MaterialValueBindings)
{
MaterialItem item;
if (m_materialMap.TryGetValue(x.MaterialName, out item))
if (m_materialMap.TryGetValue(x.MaterialName, out var item))
{
//Debug.Log("set material");
PropItem prop;
if (item.PropMap.TryGetValue(x.ValueName, out prop))
if (item.PropMap.TryGetValue(x.ValueName, out _))
{
var valueName = x.ValueName;
if (valueName.EndsWith("_ST_S")
|| valueName.EndsWith("_ST_T"))
var offsetValue = x.TargetValue - x.BaseValue;
var targetPropName = x.ValueName;
if (x.ValueName.EndsWith("_ST_S"))
{
valueName = valueName.Substring(0, valueName.Length - 2);
offsetValue.y = 0;
offsetValue.w = 0;
targetPropName = targetPropName.Substring(0, targetPropName.Length - 2);
}
else if (x.ValueName.EndsWith("_ST_T"))
{
offsetValue.x = 0;
offsetValue.z = 0;
targetPropName = targetPropName.Substring(0, targetPropName.Length - 2);
}
var value = item.Material.GetVector(valueName);
//Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
value += ((x.TargetValue - x.BaseValue) * bake.Weight);
item.Material.SetColor(valueName, value);
var value = item.Material.GetVector(targetPropName);
value += offsetValue * bake.Weight;
item.Material.SetColor(targetPropName, value);
}
}
}