/// <summary> /// コピー元のアバターのBlendShapeBindingを基に、コピー先のアバターのBlendShapeBindingを生成します。 /// </summary> /// <param name="sourceBinding"></param> /// <param name="source"></param> /// <param name="destination"></param> /// <returns></returns> private static BlendShapeBinding CopyBlendShapeBinding( BlendShapeBinding binding, GameObject source, GameObject destination ) { var sourceMesh = CopyVRMBlendShapes.GetMesh(binding, source); if (!sourceMesh) { return(binding); } var shapeKeyName = sourceMesh.GetBlendShapeName(binding.Index); var destinationMesh = CopyVRMBlendShapes.GetMesh(binding.RelativePath, destination); if (destinationMesh) { var index = destinationMesh.GetBlendShapeIndex(shapeKeyName); if (index != -1) { binding.Index = index; return(binding); } } return(CopyVRMBlendShapes.FindShapeKey(binding, shapeKeyName, destination)); }
/// <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); }
/// <summary> /// BlendShapeBindingに対応するメッシュを返します。 /// </summary> /// <param name="binding"></param> /// <param name="avatar"></param> /// <returns></returns> private static Mesh GetMesh(BlendShapeBinding binding, GameObject avatar) { var mesh = CopyVRMBlendShapes.GetMesh(binding.RelativePath, avatar); if (!mesh || binding.Index > mesh.blendShapeCount) { return(null); } return(mesh); }
/// <summary> /// VRMBlendShapeをコピーします。 /// </summary> /// <param name="source"></param> /// <param name="destination"></param> internal static void Copy(GameObject source, GameObject destination) { var sourceBlendShapeAvatar = source.GetComponent <VRMBlendShapeProxy>().BlendShapeAvatar; var destinationBlendShapeAvatar = destination.GetComponent <VRMBlendShapeProxy>().BlendShapeAvatar; if (sourceBlendShapeAvatar == destinationBlendShapeAvatar) { return; } foreach (var sourceClip in sourceBlendShapeAvatar.Clips) { if (!sourceClip) { continue; } CopyVRMBlendShapes.CopyBlendShapeClip(sourceClip, source, destination); } }