From 0b65eebc87a990eff02ccf48dc0790863c3e3ef7 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 31 Mar 2021 01:07:06 +0900 Subject: [PATCH] MaterialColorBind, TextureTransformBind --- .../VRM10/Runtime/IO/ExpressionExtensions.cs | 95 +++++++++---------- .../VRM10/Runtime/IO/RuntimeUnityBuilder.cs | 16 ++-- 2 files changed, 55 insertions(+), 56 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/ExpressionExtensions.cs b/Assets/VRM10/Runtime/IO/ExpressionExtensions.cs index 2ec227f5d..5d8f7c439 100644 --- a/Assets/VRM10/Runtime/IO/ExpressionExtensions.cs +++ b/Assets/VRM10/Runtime/IO/ExpressionExtensions.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UniGLTF.Extensions.VRMC_vrm; using UnityEngine; @@ -30,56 +31,54 @@ namespace UniVRM10 return new UniVRM10.MorphTargetBinding(relativePath, bind.Index.Value, bind.Weight.Value * 100.0f); } - // static UniVRM10.MaterialColorBinding? Build10(this MaterialColorBind bind, ModelMap loader) - // { - // var kv = bind.Property; - // var value = kv.Value.ToUnityVector4(); - // var material = loader.Materials[bind.Material]; + public static UniVRM10.MaterialColorBinding? Build10(this MaterialColorBind bind, IReadOnlyList materials) + { + var value = new Vector4(bind.TargetValue[0], bind.TargetValue[1], bind.TargetValue[2], bind.TargetValue[3]); + var material = materials[bind.Material.Value].Asset; - // var binding = default(UniVRM10.MaterialColorBinding?); - // if (material != null) - // { - // try - // { - // binding = new UniVRM10.MaterialColorBinding - // { - // MaterialName = bind.Material.Name, // UniVRM-0Xの実装は名前で持っている - // BindType = bind.BindType, - // TargetValue = value, - // // BaseValue = material.GetColor(kv.Key), - // }; - // } - // catch (Exception) - // { - // // do nothing - // } - // } - // return binding; - // } + var binding = default(UniVRM10.MaterialColorBinding?); + if (material != null) + { + try + { + binding = new UniVRM10.MaterialColorBinding + { + MaterialName = material.name, // 名前で持つべき? + BindType = bind.Type, + TargetValue = value, + // BaseValue = material.GetColor(kv.Key), + }; + } + catch (Exception) + { + // do nothing + } + } + return binding; + } - // static UniVRM10.MaterialUVBinding? Build10(this VrmLib.TextureTransformBind bind, ModelMap loader) - // { - // var material = loader.Materials[bind.Material]; - - // var binding = default(UniVRM10.MaterialUVBinding?); - // if (material != null) - // { - // try - // { - // binding = new UniVRM10.MaterialUVBinding - // { - // MaterialName = bind.Material.Name, // UniVRM-0Xの実装は名前で持っている - // Scaling = new Vector2(bind.Scale.X, bind.Scale.Y), - // Offset = new Vector2(bind.Offset.X, bind.Offset.Y), - // }; - // } - // catch (Exception) - // { - // // do nothing - // } - // } - // return binding; - // } + public static UniVRM10.MaterialUVBinding? Build10(this TextureTransformBind bind, IReadOnlyList materials) + { + var material = materials[bind.Material.Value].Asset; + var binding = default(UniVRM10.MaterialUVBinding?); + if (material != null) + { + try + { + binding = new UniVRM10.MaterialUVBinding + { + MaterialName = material.name, // 名前で持つべき + Scaling = new Vector2(bind.Scaling[0], bind.Scaling[1]), + Offset = new Vector2(bind.Offset[0], bind.Offset[1]), + }; + } + catch (Exception) + { + // do nothing + } + } + return binding; + } } } diff --git a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs index a36525152..bc7e83825 100644 --- a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs +++ b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs @@ -240,14 +240,14 @@ namespace UniVRM10 clip.MorphTargetBindings = expression.MorphTargetBinds.Select(x => x.Build10(Root, m_asset.Map, m_model)) .ToArray(); - // clip.MaterialColorBindings = expression.MaterialColorBinds.Select(x => x.Build10(asset.Map)) - // .Where(x => x.HasValue) - // .Select(x => x.Value) - // .ToArray(); - // clip.MaterialUVBindings = expression.TextureTransformBinds.Select(x => x.Build10(asset.Map)) - // .Where(x => x.HasValue) - // .Select(x => x.Value) - // .ToArray(); + clip.MaterialColorBindings = expression.MaterialColorBinds.Select(x => x.Build10(MaterialFactory.Materials)) + .Where(x => x.HasValue) + .Select(x => x.Value) + .ToArray(); + clip.MaterialUVBindings = expression.TextureTransformBinds.Select(x => x.Build10(MaterialFactory.Materials)) + .Where(x => x.HasValue) + .Select(x => x.Value) + .ToArray(); m_exressionAvatar.Clips.Add(clip); }