From 4533a7f0bfed65249ad6012a87d65703d62af59c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 24 Nov 2021 21:52:47 +0900 Subject: [PATCH] const --- .../ReorderableMorphTargetBindingList.cs | 2 +- .../Expression/SerializedExpressionEditor.cs | 18 +++++++++--------- .../Expression/MorphTargetBinding.cs | 12 ++++++++++++ .../Expression/MorphTargetBindingMerger.cs | 7 ++++++- .../Expression/Preview/PreviewMeshItem.cs | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Assets/VRM10/Editor/Components/Expression/ReorderableMorphTargetBindingList.cs b/Assets/VRM10/Editor/Components/Expression/ReorderableMorphTargetBindingList.cs index ec0277a4e..98f962115 100644 --- a/Assets/VRM10/Editor/Components/Expression/ReorderableMorphTargetBindingList.cs +++ b/Assets/VRM10/Editor/Components/Expression/ReorderableMorphTargetBindingList.cs @@ -57,7 +57,7 @@ namespace UniVRM10 y += height; rect = new Rect(position.x, y, position.width, height); - if (ExpressionEditorHelper.FloatSlider(rect, property.FindPropertyRelative(nameof(MorphTargetBinding.Weight)), 1.0f)) + if (ExpressionEditorHelper.FloatSlider(rect, property.FindPropertyRelative(nameof(MorphTargetBinding.Weight)), MorphTargetBinding.MAX_WEIGHT)) { changed = true; } diff --git a/Assets/VRM10/Editor/Components/Expression/SerializedExpressionEditor.cs b/Assets/VRM10/Editor/Components/Expression/SerializedExpressionEditor.cs index aa3c9c9c0..782d355a3 100644 --- a/Assets/VRM10/Editor/Components/Expression/SerializedExpressionEditor.cs +++ b/Assets/VRM10/Editor/Components/Expression/SerializedExpressionEditor.cs @@ -192,11 +192,11 @@ namespace UniVRM10 //EditorGUI.indentLevel += 1; for (int i = 0; i < mesh.blendShapeCount; ++i) { - var src = renderer.GetBlendShapeWeight(i) * 0.01f; - var dst = EditorGUILayout.Slider(mesh.GetBlendShapeName(i), src, 0, 1.0f); + var src = renderer.GetBlendShapeWeight(i) * MorphTargetBinding.UNITY_TO_VRM; + var dst = EditorGUILayout.Slider(mesh.GetBlendShapeName(i), src, 0, MorphTargetBinding.MAX_WEIGHT); if (dst != src) { - renderer.SetBlendShapeWeight(i, dst * 100.0f); + renderer.SetBlendShapeWeight(i, dst * MorphTargetBinding.VRM_TO_UNITY); changed = true; } } @@ -210,7 +210,7 @@ namespace UniVRM10 MorphTargetBinding[] GetBindings(out string _maxWeightName) { - var maxWeight = 0.0f; + var maxUnityWeight = 0.0f; var maxWeightName = ""; // weightのついたblendShapeを集める var values = m_items @@ -225,18 +225,18 @@ namespace UniVRM10 { for (int i = 0; i < mesh.blendShapeCount; ++i) { - var weight = x.SkinnedMeshRenderer.GetBlendShapeWeight(i); - if (weight == 0) + var unityWeight = x.SkinnedMeshRenderer.GetBlendShapeWeight(i); + if (unityWeight == 0) { continue; } var name = mesh.GetBlendShapeName(i); - if (weight > maxWeight) + if (unityWeight > maxUnityWeight) { maxWeightName = name; - maxWeight = weight; + maxUnityWeight = unityWeight; } - list.Add(new MorphTargetBinding(relativePath, i, weight * 0.01f)); + list.Add(new MorphTargetBinding(relativePath, i, unityWeight * MorphTargetBinding.UNITY_TO_VRM)); } } return list; diff --git a/Assets/VRM10/Runtime/Components/Expression/MorphTargetBinding.cs b/Assets/VRM10/Runtime/Components/Expression/MorphTargetBinding.cs index 38326ba25..2195f51fa 100644 --- a/Assets/VRM10/Runtime/Components/Expression/MorphTargetBinding.cs +++ b/Assets/VRM10/Runtime/Components/Expression/MorphTargetBinding.cs @@ -6,6 +6,18 @@ namespace UniVRM10 [Serializable] public struct MorphTargetBinding : IEquatable { + /// + /// Unity の BlendShape の値域は 0-100 + /// + public const float VRM_TO_UNITY = 100.0f; + + /// + /// VRM-1.0 の MorphTargetBinding.Weight の値域は 0-1.0 + /// + public const float UNITY_TO_VRM = 0.01f; + + public const float MAX_WEIGHT = 1.0f; + /// /// SkinnedMeshRenderer.BlendShape[Index].Weight を 指し示す。 /// diff --git a/Assets/VRM10/Runtime/Components/Expression/MorphTargetBindingMerger.cs b/Assets/VRM10/Runtime/Components/Expression/MorphTargetBindingMerger.cs index b09a0e574..f9758414f 100644 --- a/Assets/VRM10/Runtime/Components/Expression/MorphTargetBindingMerger.cs +++ b/Assets/VRM10/Runtime/Components/Expression/MorphTargetBindingMerger.cs @@ -59,8 +59,13 @@ namespace UniVRM10 { m_morphTargetSetterMap.Add(binding, x => { + if (target == null) + { + // recompile in editor ? + return; + } // VRM-1.0 weight is 0-1 - target.SetBlendShapeWeight(binding.Index, x * 100.0f); + target.SetBlendShapeWeight(binding.Index, x * MorphTargetBinding.VRM_TO_UNITY); }); } else diff --git a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMeshItem.cs b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMeshItem.cs index 0961410c1..913f9cf53 100644 --- a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMeshItem.cs +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMeshItem.cs @@ -79,7 +79,7 @@ namespace UniVRM10 { if (x.Index >= 0 && x.Index < SkinnedMeshRenderer.sharedMesh.blendShapeCount) { - SkinnedMeshRenderer.SetBlendShapeWeight(x.Index, x.Weight * weight * 100.0f); + SkinnedMeshRenderer.SetBlendShapeWeight(x.Index, x.Weight * weight * MorphTargetBinding.VRM_TO_UNITY); } else {