/// <summary> /// コピー元のアバターのBlendShapeClipを基に、コピー先のアバターのBlendShapeClipを書き替えます。 /// </summary> /// <param name="sourceClip"></param> /// <param name="source"></param> /// <param name="destination"></param> private static void CopyBlendShapeClip(BlendShapeClip sourceClip, GameObject source, GameObject destination) { var destinationBlendShapeAvatar = destination.GetComponent <VRMBlendShapeProxy>().BlendShapeAvatar; var destinationClip = sourceClip.Preset != BlendShapePreset.Unknown ? destinationBlendShapeAvatar.GetClip(sourceClip.Preset) : destinationBlendShapeAvatar.GetClip(sourceClip.BlendShapeName); if (sourceClip == destinationClip) { return; } if (!destinationClip) { destinationClip = BlendShapeAvatar.CreateBlendShapeClip( UnityPath.FromAsset(destinationBlendShapeAvatar) .Parent.Child(Path.GetFileName(AssetDatabase.GetAssetPath(sourceClip))).Value ); destinationBlendShapeAvatar.Clips.Add(destinationClip); EditorUtility.SetDirty(destinationBlendShapeAvatar); } destinationClip.Values = sourceClip.Values .Select(binding => CopyVRMBlendShapes.CopyBlendShapeBinding(binding, source, destination)).ToArray(); destinationClip.MaterialValues = sourceClip.MaterialValues.ToArray(); EditorUtility.SetDirty(destinationClip); }
private bool InitializeSetNames() { var asset = _propBlendShapeAvatar.objectReferenceValue as BlendShapeAvatar; if (_asset != asset) { _clipNames = null != asset?asset.Clips.Select(c => c.name).ToArray() : null; _asset = asset; } return(_clipNames != null); }
private static BlendShapeClip GetExpression(BlendShapeAvatar blendShapeAvatar, ExpressionPreset preset) { switch (preset) { case ExpressionPreset.Aa: return(blendShapeAvatar.GetClip(BlendShapePreset.A)); case ExpressionPreset.Ih: return(blendShapeAvatar.GetClip(BlendShapePreset.I)); case ExpressionPreset.Ou: return(blendShapeAvatar.GetClip(BlendShapePreset.U)); case ExpressionPreset.Ee: return(blendShapeAvatar.GetClip(BlendShapePreset.E)); case ExpressionPreset.Oh: return(blendShapeAvatar.GetClip(BlendShapePreset.O)); case ExpressionPreset.Happy: return(blendShapeAvatar.GetClip(BlendShapePreset.Joy)); case ExpressionPreset.Angry: return(blendShapeAvatar.GetClip(BlendShapePreset.Angry)); case ExpressionPreset.Sad: return(blendShapeAvatar.GetClip(BlendShapePreset.Sorrow)); case ExpressionPreset.Relaxed: return(blendShapeAvatar.GetClip(BlendShapePreset.Fun)); case ExpressionPreset.Surprised: var blendShapeClip = ScriptableObject.CreateInstance <BlendShapeClip>(); blendShapeClip.BlendShapeName = "Surprised"; blendShapeAvatar.Clips.Add(blendShapeClip); return(blendShapeClip); case ExpressionPreset.Blink: return(blendShapeAvatar.GetClip(BlendShapePreset.Blink)); case ExpressionPreset.BlinkLeft: return(blendShapeAvatar.GetClip(BlendShapePreset.Blink_L)); case ExpressionPreset.BlinkRight: return(blendShapeAvatar.GetClip(BlendShapePreset.Blink_R)); } throw new ArgumentOutOfRangeException(); }
void OnGUI() { EditorGUILayout.PrefixLabel("アバター"); Avatar = EditorGUILayout.ObjectField(Avatar, typeof(GameObject), true) as GameObject; EditorGUILayout.PrefixLabel("VRMMetaObject"); VRMMetaObject = EditorGUILayout.ObjectField(VRMMetaObject, typeof(VRMMetaObject), true) as VRMMetaObject; EditorGUILayout.PrefixLabel("BlendShapeAvatar"); BlendShapeAvatar = EditorGUILayout.ObjectField(BlendShapeAvatar, typeof(BlendShapeAvatar), true) as BlendShapeAvatar; if (GUILayout.Button("VRM適用")) { Apply(); } if (GUILayout.Button("VRMはずす")) { Revert(); } }
void _Construction() { if (blendShapeAvatar == null) { blendShapeAvatar = GetComponent <VRM.VRMBlendShapeProxy> ().BlendShapeAvatar; } if (blendShapeAvatar != null) { var validatedBlendShapeAvatarClips = blendShapeAvatar.Clips.Where(t => t != null); // ここで NULL を排除しなとエラーが発生する。VRM.BlendShapeMerger のバグ? _merger = new BlendShapeMerger(validatedBlendShapeAvatarClips, this.transform); } List <BlendShapeKeyBinder> entities = new List <BlendShapeKeyBinder> (); foreach (var info in GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)) { Attribute[] attributes = Attribute.GetCustomAttributes( info, typeof(BlendShapeKeyAttribute)); foreach (Attribute attr in attributes) { var blendShapeEntityAttr = attr as BlendShapeKeyAttribute; if (blendShapeEntityAttr == null) { continue; } entities.Add( new BlendShapeKeyBinder( blendShapeEntityAttr.name, GetType().CreateGetDelegate(info.Name), GetType().CreateSetDelegate(info.Name) ) ); } } _binders = entities.ToArray(); }
/// <summary> /// VRMのブレンドシェイプを、シェイプキー名ベースで取得します。 /// </summary> /// <param name="avatar"></param> /// <returns></returns> public static IEnumerable <VRMBlendShapeClip> GetAllVRMBlendShapeClips(GameObject avatar) { var clips = new List <VRMBlendShapeClip>(); var blendShapeProxy = avatar.GetComponent <VRMBlendShapeProxy>(); if (!blendShapeProxy) { return(clips); } BlendShapeAvatar blendShapeAvatar = blendShapeProxy.BlendShapeAvatar; if (!blendShapeAvatar) { return(clips); } foreach (BlendShapeClip blendShapeClip in blendShapeAvatar.Clips) { if (!blendShapeClip) { continue; } var clip = ScriptableObject.CreateInstance <VRMBlendShapeClip>(); clip.BlendShapeName = blendShapeClip.BlendShapeName; clip.Preset = blendShapeClip.Preset; clip.Values = blendShapeClip.Values; clip.MaterialValues = blendShapeClip.MaterialValues; clip.IsBinary = blendShapeClip.IsBinary; foreach (BlendShapeBinding binding in clip.Values) { Transform transform = avatar.transform.Find(binding.RelativePath); if (!transform) { continue; } var renderer = transform.GetComponent <SkinnedMeshRenderer>(); if (!renderer) { continue; } Mesh mesh = renderer.sharedMesh; if (!mesh) { continue; } if (binding.Index >= mesh.blendShapeCount) { continue; } var shapeKeyName = mesh.GetBlendShapeName(binding.Index); if (clip.ShapeKeyValues.ContainsKey(shapeKeyName)) { if (binding.Weight > clip.ShapeKeyValues[shapeKeyName]) { clip.ShapeKeyValues[shapeKeyName] = binding.Weight; } } else { clip.ShapeKeyValues.Add(key: shapeKeyName, value: binding.Weight); } } if (clip.ShapeKeyValues.Count == 0) { continue; } clips.Add(clip); } return(clips); }
private void Reset() { blendShapeAvatar = GetComponent <VRM.VRMBlendShapeProxy> ().BlendShapeAvatar; _Construction(); }