public void CleanupUVScaleOffset() { // ST_S, ST_T を統合する var count = TextureTransformBinds.Count; var map = new Dictionary <Material, TextureTransformBind>(); foreach (var uv in TextureTransformBinds.OrderBy(uv => uv.Material.Name).Distinct()) { if (!map.TryGetValue(uv.Material, out TextureTransformBind value)) { value = new TextureTransformBind(uv.Material, Vector2.One, Vector2.Zero); } map[uv.Material] = value.Merge(uv); } TextureTransformBinds.Clear(); foreach (var kv in map) { TextureTransformBinds.Add(new TextureTransformBind(kv.Key, kv.Value.Scale, kv.Value.Offset)); } // Console.WriteLine($"MergeUVScaleOffset: {count} => {UVScaleOffsetValues.Count}"); }
/// <summary> /// VRM-0.X の MaterialBindValue を VRM-1.0 仕様に変換する /// /// * Property名 => enum MaterialBindType /// * 特に _MainTex_ST の場合、MaterialBindType.UvScale + MaterialBindType.UvScale 2つになりうる /// /// </summary> VrmLib.Expression ToVrmLib(VRM10Expression clip, GameObject root) { var expression = new VrmLib.Expression(clip.Preset, clip.ExpressionName, clip.IsBinary); expression.OverrideBlink = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideBlink); expression.OverrideLookAt = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideLookAt); expression.OverrideMouth = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideMouth); foreach (var binding in clip.MorphTargetBindings) { var transform = GetTransformFromRelativePath(root.transform, binding.RelativePath); if (transform == null) { continue; } var renderer = transform.gameObject.GetComponent <SkinnedMeshRenderer>(); if (renderer == null) { continue; } var mesh = renderer.sharedMesh; if (mesh == null) { continue; } var names = new List <string>(); for (int i = 0; i < mesh.blendShapeCount; ++i) { names.Add(mesh.GetBlendShapeName(i)); } var node = Nodes[transform.gameObject]; var blendShapeValue = new VrmLib.MorphTargetBind( node, names[binding.Index], // Unity Range [0-100] to VRM-1.0 Range [0-1.0] binding.Weight * 0.01f ); expression.MorphTargetBinds.Add(blendShapeValue); } foreach (var binding in clip.MaterialColorBindings) { var materialPair = Materials.FirstOrDefault(x => x.Key.name == binding.MaterialName); if (materialPair.Value != null) { var bind = new VrmLib.MaterialColorBind( materialPair.Value, binding.BindType, binding.TargetValue.ToNumericsVector4() ); expression.MaterialColorBinds.Add(bind); } } foreach (var binding in clip.MaterialUVBindings) { var materialPair = Materials.FirstOrDefault(x => x.Key.name == binding.MaterialName); if (materialPair.Value != null) { var bind = new VrmLib.TextureTransformBind( materialPair.Value, binding.Scaling.ToNumericsVector2(), binding.Offset.ToNumericsVector2() ); expression.TextureTransformBinds.Add(bind); } } return(expression); }