From 1360834711a7e02af303650935d7459bd066b9de Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 30 Aug 2023 17:00:58 +0900 Subject: [PATCH] [VRM0.x] Fix wrong preview results in editor inspector when a material target is "*_ST_S" or "*_ST_T" --- .../Runtime/BlendShape/PreviewSceneManager.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs index bbe77dfb5..15875e7be 100644 --- a/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs +++ b/Assets/VRM/Runtime/BlendShape/PreviewSceneManager.cs @@ -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); } } }