Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
            }
        }