Example #1
0
 public GroupMorphData(MorphData data)
 {
     foreach (MorphOffsetBase morphOffsetBase in data.MorphOffsetes)
     {
         this.MorphOffsets.Add((GroupMorphOffset)morphOffsetBase);
     }
 }
Example #2
0
 public BoneMorphData(MorphData morphData)
 {
     foreach (MorphOffsetBase morphOffsetBase in morphData.MorphOffsetes)
     {
         BoneMorphs.Add((BoneMorphOffset)morphOffsetBase);
     }
 }
Example #3
0
 public MaterialMorphData(MorphData morph)
 {
     foreach (MorphOffsetBase morphOffsetBase in morph.MorphOffsetes)
     {
         Morphoffsets.Add((MaterialMorphOffset)morphOffsetBase);
     }
 }
 public PmxMaterialMorph(int index, MorphData d, OpType op)
     : this()
 {
     Index = index;
     Data  = d;
     Op    = op;
 }
Example #5
0
 public UVMorphData(MorphData morphData)
 {
     foreach (MorphOffsetBase morphOffsetBase in morphData.MorphOffsetes)
     {
         this.MorphOffsets.Add((UVMorphOffset)morphOffsetBase);
     }
 }
Example #6
0
 public VertexMorphData(MorphData morphData)
 {
     foreach (MorphOffsetBase morphOffsetBase in morphData.MorphOffsetes)
     {
         MorphOffsets.Add((VertexMorphOffset)morphOffsetBase);
     }
 }
 public void Mul(MorphData d)
 {
     Diffuse   = mul_v4(Diffuse, d.Diffuse);
     Specular  = mul_v4(Specular, d.Specular);
     Ambient   = mul_v3(Ambient, d.Ambient);
     EdgeSize *= d.EdgeSize;
     EdgeColor = mul_v4(EdgeColor, d.EdgeColor);
     Tex       = mul_v4(Tex, d.Tex);
     Sphere    = mul_v4(Sphere, d.Sphere);
     Toon      = mul_v4(Toon, d.Toon);
 }
Example #8
0
    public override void OnInspectorGUI()
    {
        MCSMorphFileWrapper wrapper = (MCSMorphFileWrapper)target;

        GUILayout.Label("File: " + wrapper.fileName);

        try
        {
            byte[]    bytes     = System.IO.File.ReadAllBytes(wrapper.fileName);
            MorphData morphData = MorphData.ConvertBytesToMorphData(bytes);
            GUILayout.Label("Morph: " + morphData.name);
            GUILayout.Label("Mesh: " + morphData.meshName);

            int i = 0;
            GUILayout.Label("Delta Vertices: " + (morphData.blendshapeData.deltaVertices != null ? morphData.blendshapeData.deltaVertices.Length.ToString() : "null"));
            if (morphData.blendshapeData.deltaVertices != null)
            {
                scrollDeltaVertsPos = EditorGUILayout.BeginScrollView(scrollDeltaVertsPos, GUILayout.Height(400));
                foreach (Vector3 v in morphData.blendshapeData.deltaVertices)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(50));
                    EditorGUILayout.Vector3Field("", v);//, GUILayout.Width(300));
                    EditorGUILayout.EndHorizontal();

                    i++;
                }
                EditorGUILayout.EndScrollView();
            }


            GUILayout.Label("Delta Normals: " + (morphData.blendshapeData.deltaNormals != null ? morphData.blendshapeData.deltaNormals.Length.ToString() : "null"));
            if (morphData.blendshapeData.deltaNormals != null)
            {
                scrollDeltaNormalsPos = EditorGUILayout.BeginScrollView(scrollDeltaNormalsPos, GUILayout.Height(400));
                i = 0;
                foreach (Vector3 v in morphData.blendshapeData.deltaNormals)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Vector3Field(i.ToString(), v);//, GUILayout.Width(300));
                    EditorGUILayout.EndHorizontal();

                    i++;
                }
                EditorGUILayout.EndScrollView();
            }
        }
        catch
        {
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;
            GUILayout.Label("Can't parse morph file, it appears corrupted.");
        }
    }
 public void Add(MorphData d)
 {
     Diffuse   += d.Diffuse;
     Specular  += d.Specular;
     Ambient   += d.Ambient;
     EdgeSize  += d.EdgeSize;
     EdgeColor += d.EdgeColor;
     Tex       += d.Tex;
     Sphere    += d.Sphere;
     Toon      += d.Toon;
 }
Example #10
0
        static MorphData RemapMorphData(SkinnedMeshRenderer skinnedMeshRenderer, MorphData morphData, Dictionary <int, int> targetToSourceMap)
        {
            // This is taken from MCS StreamingMorphs's built-in ConvertMorphDataFromMap, but without requiring a projectionmap.

            Mesh mesh = skinnedMeshRenderer.sharedMesh;

            Vector3[] targetVertices = mesh.vertices;

            MorphData morphDataNew = new MorphData();

            morphDataNew.name                      = morphData.name;
            morphDataNew.jctData                   = morphData.jctData;
            morphDataNew.blendshapeData            = new BlendshapeData();
            morphDataNew.blendshapeData.frameIndex = morphData.blendshapeData.frameIndex;
            morphDataNew.blendshapeData.shapeIndex = morphData.blendshapeData.shapeIndex;

            morphDataNew.blendshapeData.deltaVertices = new Vector3[targetVertices.Length];
            morphDataNew.blendshapeData.deltaNormals  = new Vector3[targetVertices.Length];
            morphDataNew.blendshapeData.deltaTangents = new Vector3[targetVertices.Length];

            foreach (var ts in targetToSourceMap)
            {
                if (morphData.blendshapeData.deltaNormals != null)
                {
                    morphDataNew.blendshapeData.deltaNormals[ts.Key] = morphData.blendshapeData.deltaNormals[ts.Value];
                }
                if (morphData.blendshapeData.deltaVertices != null)
                {
                    if (ts.Key >= morphDataNew.blendshapeData.deltaVertices.Length)
                    {
                        throw new System.Exception("ts.key in: " + skinnedMeshRenderer.name + " is too large for deltas: " + ts.Key + " => " + ts.Value + " | " + morphDataNew.blendshapeData.deltaVertices.Length);
                    }
                    if (ts.Value >= morphData.blendshapeData.deltaVertices.Length)
                    {
                        throw new System.Exception("ts.value in: " + skinnedMeshRenderer.name + " is too large for deltas: " + ts.Key + " => " + ts.Value + " | " + morphData.blendshapeData.deltaVertices.Length);
                    }
                    morphDataNew.blendshapeData.deltaVertices[ts.Key] = morphData.blendshapeData.deltaVertices[ts.Value];
                }
                if (morphData.blendshapeData.deltaTangents != null)
                {
                    morphDataNew.blendshapeData.deltaTangents[ts.Key] = morphData.blendshapeData.deltaTangents[ts.Value];
                }
            }
            return(morphDataNew);
        }
            public static MorphData Inter(MorphData a, MorphData b, float val)
            {
                if (val == 0f)
                {
                    return(a);
                }
                if (val == 1f)
                {
                    return(b);
                }
                MorphData result = a;

                result.Mul(1f - val);
                MorphData d = b;

                d.Mul(val);
                result.Add(d);
                return(result);
            }
Example #12
0
    void _AddMorphData(List <MorphData> morphDataList, string morphScript)
    {
        if (morphDataList != null && morphScript != null)
        {
            MorphData morphData = new MorphData();
            for (int i = 0; i < morphScript.Length; ++i)
            {
                //Debug.Log( "Char:" + morphScript[i] );
                morphData.morphChar = morphScript[i];
                morphData.morphName = "";
                switch (morphData.morphChar)
                {
                case 'a': morphData.morphName = hiraMorphNameList[0]; break;

                case 'i': morphData.morphName = hiraMorphNameList[1]; break;

                case 'u': morphData.morphName = hiraMorphNameList[2]; break;

                case 'e': morphData.morphName = hiraMorphNameList[3]; break;

                case 'o': morphData.morphName = hiraMorphNameList[4]; break;

                case 'n': morphData.morphName = hiraMorphNameList[2]; break; // u

                case '^': morphData.morphName = hiraMorphNameList[2]; break; // u

                case '`': morphData.morphName = ""; break;                   // n

                case '/':
                case '-':
                case '~':
                    if (morphDataList.Count > 0)
                    {
                        morphData.morphName = morphDataList[morphDataList.Count - 1].morphName;
                    }
                    break;
                }
                morphDataList.Add(morphData);
            }
        }
    }
Example #13
0
        /// <summary>
        /// Removes morphs from selected assets. Useful in cases like hair moving unnaturally with eye blinks.
        /// </summary>
        public static void RemoveMorphsFromSelected(List <string> morphNamesToBeRemoved)
        {
            List <GameObject> content = GetContent(true);

            if (content.Count == 0 || morphNamesToBeRemoved == null || morphNamesToBeRemoved.Count == 0)
            {
                return;
            }

            if (!EditorUtility.DisplayDialog("Warning", "This process is nonreversible.\nAre you sure?", "Yes", "Cancel"))
            {
                return;
            }

            // Load common conversion tools and data
            _conversionData = new ConversionData();

            _activeProcess         = new ContentProcessor("Edit", content, true);
            _activeProcess.Process = delegate() {
                GameObject obj = _activeProcess.GetObject();
                if (obj == null)
                {
                    return;
                }

                CoreMesh[] meshes = obj.GetComponentsInChildren <CoreMesh>();
                foreach (CoreMesh mesh in meshes)
                {
                    //_activeProcess.status = mesh.name + " : Checking...";

                    // Check smr
                    SkinnedMeshRenderer smr = mesh.GetComponent <SkinnedMeshRenderer>();
                    if (smr == null)
                    {
                        continue;
                    }

                    // Create temp directory for generated .morph files
                    string morphPath = Path.Combine(Application.streamingAssetsPath, mesh.runtimeMorphPath);
                    Directory.CreateDirectory(morphPath);

                    try {
                        // Get manifest
                        var manifest = _conversionData.GetManifestForCoreMesh(mesh, _manifestSelectionMethod);

                        // Process morphs
                        List <string> morphNames = new List <string>(manifest.names);
                        morphNames.Add("base"); // Add "base" morph that's not in the manifest but is required for clothing and hair

                        foreach (string morph in morphNames)
                        {
                            MorphData data = _conversionData.GetMorphData(morphPath, morph);
                            if (data != null)
                            {
                                if (morphNamesToBeRemoved.Contains(morph))
                                {
                                    _activeProcess.status = mesh.name + " : Removed Morph " + morph;
                                }
                                else
                                {
                                    // Save .morph file for keeping
                                    MCS_Utilities.MorphExtraction.MorphExtraction.WriteMorphDataToFile(data, morphPath + "/" + data.name + ".morph", false, false);
                                }
                            }
                        }

                        // Repack morphs into .morph.mr file
                        //_activeProcess.status = mesh.name + " : Rebuilding MR...";
                        RepackMorphs(morphPath);

                        //_activeProcess.status = mesh.name + " : Success!";
                    } catch {
                        _activeProcess.status = mesh.name + " : FAILED";
                    } finally {
                        MCS_Utilities.Paths.TryDirectoryDelete(morphPath);
                    }
                }
            };
        }
Example #14
0
 public static CharacterMorph make_char_morph(MorphData morph)
 {
     // TODO
     return(null);
 }
Example #15
0
        public static DictRadix<MorphData> LoadDictionaryFromHSpellFolder(string path, bool bLoadMorphData)
        {
            if (path[path.Length - 1] != Path.DirectorySeparatorChar)
                path += Path.DirectorySeparatorChar;

            if (bLoadMorphData)
            {
                // Load the count of morphological data slots required
                string sizesFile = File.ReadAllText(path + HSpell.Constants.SizesFile);
                int lookupLen = sizesFile.IndexOf(' ', sizesFile.IndexOf('\n'));
                lookupLen = Convert.ToInt32(sizesFile.Substring(lookupLen + 1));
                string[] lookup = new string[lookupLen + 1];

                using (GZipStream fdict = new GZipStream(File.OpenRead(path + HSpell.Constants.DictionaryFile), CompressionMode.Decompress))
                {
                    char[] sbuf = new char[HSpell.Constants.MaxWordLength];
                    int c = 0, n, slen = 0, i = 0;
                    while ((c = fdict.ReadByte()) > -1)
                    {
                        if (c >= '0' && c <= '9') // No conversion required for chars < 0xBE
                        {
                            /* new word - finalize and save old word */
                            lookup[i++] = new string(sbuf, 0, slen);

                            /* and read how much to go back */
                            n = 0;
                            do
                            {
                                /* base 10... */
                                n *= 10;
                                n += (c - '0');
                            } while ((c = fdict.ReadByte()) > -1 && c >= '0' && c <= '9');
                            slen -= n;
                        }
                        sbuf[slen++] = ISO8859_To_Unicode(c);
                    }
                }

                using (MorphDataLoader dataLoader = new MorphDataLoader(path + HSpell.Constants.DescFile,
                        path + HSpell.Constants.StemsFile))
                {
                    using (GZipStream fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
                    {
                        DictRadix<MorphData> ret = new DictRadix<MorphData>();

                        for (int i = 0; lookup[i] != null; i++)
                        {
                            MorphData data = new MorphData();
                            data.Prefixes = Convert.ToByte(fprefixes.ReadByte()); // Read prefix hint byte
                            data.DescFlags = dataLoader.ReadDescFile();

                            List<int> stemReferences = dataLoader.ReadStemFile();
                            data.Lemmas = new string[stemReferences.Count];
                            int stemPosition = 0;
                            foreach (int r in stemReferences)
                            {
                                // This is a bypass for the psuedo-stem "שונות", as defined by hspell
                                // TODO: Try looking into changing this in hspell itself
                                if (lookup[r].Equals("שונות") && !lookup[r].Equals(lookup[i]))
                                {
                                    data.Lemmas[stemPosition++] = null;
                                }
                                else
                                {
                                    data.Lemmas[stemPosition++] = lookup[r];
                                }
                            }
                            ret.AddNode(lookup[i], data);
                        }

                        return ret;
                    }
                }
            }
            else // Use optimized version for loading HSpell's dictionary files
            {
                using (GZipStream fdict = new GZipStream(File.OpenRead(path + HSpell.Constants.DictionaryFile), CompressionMode.Decompress))
                {
                    using (GZipStream fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
                    {
                        DictRadix<MorphData> ret = new DictRadix<MorphData>();

                        char[] sbuf = new char[HSpell.Constants.MaxWordLength];
                        int c = 0, n, slen = 0;
                        while ((c = fdict.ReadByte()) > -1)
                        {
                            if (c >= '0' && c <= '9') // No conversion required for chars < 0xBE
                            {
                                /* new word - finalize old word first (set value) */
                                sbuf[slen] = '\0';

                                // TODO: Avoid creating new MorphData object, and enhance DictRadix to store
                                // the prefixes mask in the node itself
                                MorphData data = new MorphData();
                                data.Prefixes = Convert.ToByte(fprefixes.ReadByte()); // Read prefix hint byte
                                ret.AddNode(sbuf, data);

                                /* and read how much to go back */
                                n = 0;
                                do
                                {
                                    /* base 10... */
                                    n *= 10;
                                    n += (c - '0');
                                } while ((c = fdict.ReadByte()) > -1 && c >= '0' && c <= '9');
                                slen -= n;
                            }
                            sbuf[slen++] = ISO8859_To_Unicode(c);
                        }

                        return ret;
                    }
                }
            }
        }
Example #16
0
 public static void free_morph(MorphData morph)
 {
     // TODO
 }
Example #17
0
        public static DictRadix <MorphData> LoadDictionaryFromHSpellFolder(string path, bool bLoadMorphData)
        {
            if (path[path.Length - 1] != Path.DirectorySeparatorChar)
            {
                path += Path.DirectorySeparatorChar;
            }

            if (bLoadMorphData)
            {
                // Load the count of morphological data slots required
                int lookupLen = GetWordCountInHSpellFolder(path);
                var lookup    = new string[lookupLen + 1];

                using (GZipStream fdict = new GZipStream(File.OpenRead(path + Constants.DictionaryFile), CompressionMode.Decompress))
                {
                    var sbuf = new char[Constants.MaxWordLength];
                    int c = 0, n, slen = 0, i = 0;
                    while ((c = fdict.ReadByte()) > -1)
                    {
                        if (c >= '0' && c <= '9')                         // No conversion required for chars < 0xBE
                        {
                            /* new word - finalize and save old word */
                            lookup[i++] = new string(sbuf, 0, slen);

                            /* and read how much to go back */
                            n = 0;
                            do
                            {
                                /* base 10... */
                                n *= 10;
                                n += (c - '0');
                            } while ((c = fdict.ReadByte()) > -1 && c >= '0' && c <= '9');
                            slen -= n;
                        }
                        sbuf[slen++] = ISO8859_To_Unicode(c);
                    }
                }

                using (var dataLoader = new MorphDataLoader(path + HSpell.Constants.DescFile, path + Constants.StemsFile))
                    using (var fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
                    {
                        DictRadix <MorphData> ret = new DictRadix <MorphData>();

                        for (int i = 0; lookup[i] != null; i++)
                        {
                            MorphData data = new MorphData();
                            data.Prefixes  = Convert.ToByte(fprefixes.ReadByte());                    // Read prefix hint byte
                            data.DescFlags = dataLoader.ReadDescFile();

                            var stemReferences = dataLoader.ReadStemFile();
                            data.Lemmas = new string[stemReferences.Count];
                            int stemPosition = 0;
                            foreach (int r in stemReferences)
                            {
                                // This is a bypass for the psuedo-stem "שונות", as defined by hspell
                                // TODO: Try looking into changing this in hspell itself
                                if (lookup[r].Equals("שונות") && !lookup[r].Equals(lookup[i]))
                                {
                                    data.Lemmas[stemPosition++] = null;
                                }
                                else
                                {
                                    data.Lemmas[stemPosition++] = lookup[r];
                                }
                            }
                            ret.AddNode(lookup[i], data);
                        }

                        return(ret);
                    }
            }
            else             // Use optimized version for loading HSpell's dictionary files
            {
                using (var fdict = new GZipStream(File.OpenRead(path + HSpell.Constants.DictionaryFile), CompressionMode.Decompress))
                    using (var fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
                    {
                        var ret = new DictRadix <MorphData>();

                        var sbuf = new char[HSpell.Constants.MaxWordLength];
                        int c = 0, n, slen = 0;
                        while ((c = fdict.ReadByte()) > -1)
                        {
                            if (c >= '0' && c <= '9')                     // No conversion required for chars < 0xBE
                            {
                                /* new word - finalize old word first (set value) */
                                sbuf[slen] = '\0';

                                // TODO: Avoid creating new MorphData object, and enhance DictRadix to store
                                // the prefixes mask in the node itself
                                MorphData data = new MorphData();
                                data.Prefixes = Convert.ToByte(fprefixes.ReadByte());                         // Read prefix hint byte
                                ret.AddNode(sbuf, data);

                                /* and read how much to go back */
                                n = 0;
                                do
                                {
                                    /* base 10... */
                                    n *= 10;
                                    n += (c - '0');
                                } while ((c = fdict.ReadByte()) > -1 && c >= '0' && c <= '9');
                                slen -= n;
                            }
                            sbuf[slen++] = ISO8859_To_Unicode(c);
                        }

                        return(ret);
                    }
            }
        }
Example #18
0
 public static void morph_defaults(MorphData morph)
 {
     // TODO
 }
Example #19
0
 public static void copy_morph(MorphData morph, MorphData temp)
 {
     // TODO
 }
 public void FromPmxMaterialMorph(PmxMaterialMorph sv)
 {
     FromPmxBaseMorph(sv);
     Op   = sv.Op;
     Data = sv.Data;
 }
Example #21
0
 public static void unmorph_all(MorphData morph)
 {
     // TODO
 }
 public PmxMaterialMorph(int index, MorphData d)
     : this()
 {
     Index = index;
     Data  = d;
 }
Example #23
0
 public static void send_morph_message(CharacterInstance ch, MorphData morph, bool is_morph)
 {
 }
Example #24
0
 public static void fwrite_morph(FileStream fs, MorphData morph)
 {
     // TODO
 }
Example #25
0
    List <MorphData> _ParseMorphText(string morphText)
    {
        if (string.IsNullOrEmpty(morphText))
        {
            return(null);
        }

        //Debug.Log( "_ParseMorphText:" + morphText ); // for Debug.

        System.Text.StringBuilder alphabets = new System.Text.StringBuilder();

        List <MorphData> morphDataList = new List <MorphData>();

        bool isBeforeAlphabet = false;
        bool isBeforeMorph    = false;

        int textPos = 0;

        for (;;)
        {
            if (textPos >= morphText.Length)
            {
                break;
            }

            string japanesePronun = null;
            char   ch             = morphText[textPos];

            if (ch == '[')
            {
                int beginPos = (++textPos);
                for ( ; textPos < morphText.Length; ++textPos)
                {
                    if (morphText[textPos] == ']')
                    {
                        int milliSeconds = MMD4MecanimCommon.ToInt(morphText, beginPos, textPos - beginPos);
                        if (isBeforeMorph && morphDataList.Count > 0)
                        {
                            MorphData morphData = morphDataList[morphDataList.Count - 1];
                            morphData.morphLength = (float)milliSeconds * 0.001f;
                            morphDataList[morphDataList.Count - 1] = morphData;
                        }
                        else
                        {
                            MorphData morphData = new MorphData();
                            morphData.morphChar   = ' ';
                            morphData.morphName   = "";
                            morphData.morphLength = (float)milliSeconds * 0.001f;
                            morphDataList.Add(morphData);
                        }
                        ++textPos;
                        break;
                    }
                }
                isBeforeMorph = false;
            }
            else if (_IsEscape(ch))
            {
                // ^ ... alveolar
                // ` ... bilabial
                // / ... staccato
                // - ... -
                // ~ ... -
                MorphData morphData = new MorphData();
                morphData.morphChar = ch;
                morphData.morphName = "";
                switch (ch)
                {
                case '^':
                    morphData.morphName = hiraMorphNameList[2];                     // u
                    break;

                case '`':
                    morphData.morphName = "";                     // n
                    break;

                case '/':
                case '-':
                case '~':
                    if (morphDataList.Count > 0)
                    {
                        morphData.morphName = morphDataList[morphDataList.Count - 1].morphName;
                    }
                    break;
                }
                isBeforeMorph = true;
                morphDataList.Add(morphData);
                ++textPos;
            }
            else if (MMD4MecanimCommon.IsAlphabet(ch))
            {
                // for English.
                string tempString        = null;
                bool   processedAnything = false;
                ch = MMD4MecanimCommon.ToHalfLower(ch);
                if (textPos + 1 < morphText.Length && MMD4MecanimCommon.IsAlphabet(morphText[textPos + 1]))
                {
                    char ch2 = MMD4MecanimCommon.ToHalfLower(morphText[textPos + 1]);
                    if (textPos + 2 < morphText.Length && MMD4MecanimCommon.IsAlphabet(morphText[textPos + 2]))
                    {
                        char ch3 = MMD4MecanimCommon.ToHalfLower(morphText[textPos + 2]);
                        alphabets.Remove(0, alphabets.Length);
                        alphabets.Append(ch);
                        alphabets.Append(ch2);
                        alphabets.Append(ch3);
                        if (englishPhraseDictionary.TryGetValue(alphabets.ToString(), out tempString))
                        {
                            _AddMorphData(morphDataList, tempString);
                            processedAnything = true;
                            textPos          += 3;
                        }
                    }
                    if (!processedAnything)
                    {
                        alphabets.Remove(0, alphabets.Length);
                        alphabets.Append(ch);
                        alphabets.Append(ch2);
                        if (englishPhraseDictionary.TryGetValue(alphabets.ToString(), out tempString))
                        {
                            _AddMorphData(morphDataList, tempString);
                            processedAnything = true;
                            textPos          += 2;
                        }
                    }
                }
                if (!processedAnything)
                {
                    if (!isBeforeAlphabet && (morphText[textPos] == 'I' || morphText[textPos] == '\uFF29'))
                    {
                        _AddMorphData(morphDataList, "ai");
                    }
                    else
                    {
                        if (textPos > 0 && MMD4MecanimCommon.ToHalfLower(morphText[textPos - 1]) == 'e' && ch == 'e')                              // lee, bee, ...
                        {
                            _AddMorphData(morphDataList, "-");
                        }
                        else
                        {
                            if (englishPronunDictionary.TryGetValue(ch, out tempString))
                            {
                                _AddMorphData(morphDataList, tempString);
                            }
                            else
                            {
                                _AddMorphData(morphDataList, " ");
                            }
                        }
                    }
                    processedAnything = true;
                    ++textPos;
                }
                isBeforeAlphabet = true;
                isBeforeMorph    = true;
            }
            else if (japanesePronunDictionary.TryGetValue(ch, out japanesePronun))
            {
                string postPhaseText = null;
                if (textPos + 1 < morphText.Length && japanesePostPhraseDictionary.TryGetValue(morphText[textPos + 1], out postPhaseText))
                {
                    string phaseText = null;
                    if (japanesePhraseDictionary.TryGetValue(morphText.Substring(textPos, 2), out phaseText))
                    {
                        _AddMorphData(morphDataList, phaseText);
                    }
                    else
                    {
                        _AddMorphData(morphDataList, japanesePronun);
                        _AddMorphData(morphDataList, postPhaseText);
                    }
                    textPos += 2;
                }
                else
                {
                    _AddMorphData(morphDataList, japanesePronun);
                    ++textPos;
                }
                isBeforeAlphabet = false;
                isBeforeMorph    = true;
            }
            else
            {
                if (textPos + 1 < morphText.Length)                    // Simulate VOICEROID
                {
                    string tempString = null;
                    if (punctuatDictionary.TryGetValue(ch, out tempString))
                    {
                        _AddMorphData(morphDataList, "   ");                           // Simulate VOICEROID
                    }
                    else
                    {
                        // Nothing
                    }
                }
                isBeforeAlphabet = false;
                isBeforeMorph    = false;
                ++textPos;
            }
        }

        return(morphDataList);
    }
Example #26
0
    PlayingData _ParsePlayingData(AudioClip audioClip, string morphText)
    {
        PlayingData playingData = new PlayingData();

        playingData.audioClip     = audioClip;
        playingData.playingLength = 0.0f;
        playingData.playingTime   = 0.0f;
        playingData.morphPos      = -1;
        playingData.morphTime     = 0.0f;
        if (!string.IsNullOrEmpty(morphText))
        {
            playingData.morphDataList = _ParseMorphText(morphText);
        }
        else
        {
            playingData.morphDataList = _ParseMorphText(System.IO.Path.GetFileNameWithoutExtension(audioClip.name));
        }

        if (playingData.morphDataList != null)
        {
            float morphTotalLength = 0.0f;
            int   morphZeroCount   = 0;
            for (int i = 0; i < playingData.morphDataList.Count; ++i)
            {
                char ch = playingData.morphDataList[i].morphChar;
                if (playingData.morphDataList[i].morphLength == 0.0f)
                {
                    if (ch != '^' && ch != '`')
                    {
                        ++morphZeroCount;
                    }
                }
                else
                {
                    morphTotalLength += playingData.morphDataList[i].morphLength;
                }
            }

            float elementLength = GetElementLength();
            if (audioClip != null)
            {
                playingData.playingLength = audioClip.length;
                if (playingData.playingLength <= morphTotalLength)
                {
                    playingData.playingLength = morphTotalLength;
                    elementLength             = 0.0f;
                }
                else
                {
                    if (morphZeroCount > 0)
                    {
                        elementLength = (playingData.playingLength - morphTotalLength) / (float)morphZeroCount;
                    }
                }
            }
            else
            {
                playingData.playingLength = morphTotalLength + elementLength * (float)morphZeroCount;
            }
            if (elementLength > 0.0f)
            {
                // Allocate each morphLength.
                for (int i = 0; i < playingData.morphDataList.Count; ++i)
                {
                    char ch = playingData.morphDataList[i].morphChar;
                    if (playingData.morphDataList[i].morphLength == 0.0f)
                    {
                        if (ch != '^' && ch != '`')
                        {
                            MorphData morphData = playingData.morphDataList[i];
                            morphData.morphLength        = elementLength;
                            playingData.morphDataList[i] = morphData;
                        }
                    }
                }
                // Fix for each consonantLength.
                float consonantLength = GetConsonantLength();
                for (int i = 0; i < playingData.morphDataList.Count; ++i)
                {
                    char ch = playingData.morphDataList[i].morphChar;
                    if (playingData.morphDataList[i].morphLength == 0.0f)
                    {
                        if (ch != '^' && ch != '`')
                        {
                            // Nothing.
                        }
                        else
                        {
                            int beginIndex = i;
                            for (++i; i < playingData.morphDataList.Count; ++i)
                            {
                                ch = playingData.morphDataList[i].morphChar;
                                if (ch != '^' && ch != '`')
                                {
                                    float morphLength = playingData.morphDataList[i].morphLength;
                                    float tempLength  = 0.0f;
                                    if (consonantLength * 2.0f <= morphLength)
                                    {
                                        MorphData morphData = playingData.morphDataList[i];
                                        morphData.morphLength        = morphLength - consonantLength;
                                        playingData.morphDataList[i] = morphData;
                                        tempLength = consonantLength;
                                    }
                                    else
                                    {
                                        MorphData morphData = playingData.morphDataList[i];
                                        morphData.morphLength        = morphLength * 0.5f;
                                        playingData.morphDataList[i] = morphData;
                                        tempLength = morphData.morphLength;
                                    }
                                    {
                                        MorphData morphData = playingData.morphDataList[beginIndex];
                                        morphData.morphLength = tempLength;
                                        playingData.morphDataList[beginIndex] = morphData;
                                    }
                                    break;
                                }
                                else
                                {
                                    if (playingData.morphDataList[i].morphLength == 0.0f)
                                    {
                                        // Nothing.
                                    }
                                    else
                                    {
                                        break;                                         // Skip processing.( Exception case, no effects. )
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (audioClip != null)
            {
                playingData.playingLength = audioClip.length;
            }
        }

#if false
        if (playingData.morphDataList != null)
        {
            for (int i = 0; i < playingData.morphDataList.Count; ++i)
            {
                Debug.Log("" + playingData.morphDataList[i].morphName +
                          ":" + playingData.morphDataList[i].morphChar +
                          ":" + playingData.morphDataList[i].morphLength);
            }
        }
#endif

        return(playingData);
    }
Example #27
0
 public void AddNode(string s, MorphData md)
 {
     this.mds.Add(s, md);
     this.dict.AddNode(s, md);
 }
Example #28
0
        /// <summary>
        /// Remaps morph data for all MCS content, or only selected folders if useSelection == true.
        /// </summary>
        public static void ConvertMorphData(bool useSelection)
        {
            if (!useSelection)
            {
                if (!EditorUtility.DisplayDialog("Warning", "This will attempt to convert all MCS morph data in your project. This process is nonreversible.\nAre you sure?", "Yes", "Cancel"))
                {
                    return;
                }
            }

            List <GameObject> content = GetContent(useSelection);

            if (content.Count == 0)
            {
                return;
            }

            // Load common conversion tools and data
            _conversionData = new ConversionData();

            _activeProcess         = new ContentProcessor("Convert", content, true);
            _activeProcess.Process = delegate() {
                GameObject obj = _activeProcess.GetObject();
                if (obj == null)
                {
                    return;
                }

                CoreMesh[] meshes = obj.GetComponentsInChildren <CoreMesh>();
                foreach (CoreMesh mesh in meshes)
                {
                    //_activeProcess.status = mesh.name + " : Checking...";
                    _conversionData.CreateReport(mesh.name);

                    // Check if already converted
                    if (_conversionData.GetMorphData(mesh.runtimeMorphPath, "_2019compatible") != null)
                    {
                        _conversionData.CloseReport("Skipped (already converted)");
                        continue;
                    }

                    // Check smr
                    SkinnedMeshRenderer smr = mesh.GetComponent <SkinnedMeshRenderer>();
                    if (smr == null)
                    {
                        _conversionData.CloseReport("Skipped (no SkinnedMeshRenderer found)");
                        continue;
                    }

                    // Check for original vertex map
                    string vmPath = "";
                    foreach (string path in _conversionData.vertexMaps)
                    {
                        if (path.Contains(mesh.name + ".json"))
                        {
                            vmPath = path;
                            break;
                        }
                    }
                    if (vmPath == "")
                    {
                        _conversionData.CloseReport("Skipped (no vertex map found)");
                        continue;
                    }

                    // Create temp directory for generated .morph files
                    string morphPath = Path.Combine(Application.streamingAssetsPath, mesh.runtimeMorphPath);
                    Directory.CreateDirectory(morphPath);

                    // Run process
                    try {
                        // Read vertex map
                        string    mapData   = File.ReadAllText(vmPath);
                        VertexMap vertexMap = JsonUtility.FromJson <VertexMap>(mapData);

                        // Generate retarget map
                        //_activeProcess.status = mesh.name + " : Generating Target Map...";
                        Dictionary <int, int> ttsMap = _conversionData.projectionMeshMap.GenerateTargetToSourceMap(vertexMap.vertices, smr.sharedMesh.vertices);

                        // Get manifest
                        var manifest = _conversionData.GetManifestForCoreMesh(mesh, _manifestSelectionMethod);

                        // Process morphs
                        int           n          = 0;
                        int           total      = manifest.names.Length;
                        List <string> morphNames = new List <string>(manifest.names);
                        morphNames.Add("base"); // Add "base" morph that's not in the manifest but is required for clothing and hair

                        foreach (string morph in morphNames)
                        {
                            //_activeProcess.status = string.Format("{0} : Processing Morph {1}/{2}", mesh.name, n, total);
                            n++;

                            MorphData source = _conversionData.GetMorphData(morphPath, morph); // Not all assets will have all morphs
                            if (source != null)
                            {
                                // Retarget morphs
                                MorphData target = RemapMorphData(smr, source, ttsMap);
                                // Save new .morph file
                                MCS_Utilities.MorphExtraction.MorphExtraction.WriteMorphDataToFile(target, morphPath + "/" + target.name + ".morph", false, false);
                            }
                        }

                        // Inject evidence of conversion so we don't accidentally remap again.
                        MorphData note = new MorphData();
                        note.name = "_2019compatible";
                        MCS_Utilities.MorphExtraction.MorphExtraction.WriteMorphDataToFile(note, morphPath + "/" + note.name + ".morph", false, false);

                        // Repack morphs into .morph.mr file
                        _activeProcess.status = mesh.name + " : Repacking Morphs...";
                        RepackMorphs(morphPath);

                        _conversionData.CloseReport("Success");
                    } catch {
                        _conversionData.CloseReport("Failed");
                    } finally {
                        MCS_Utilities.Paths.TryDirectoryDelete(morphPath);
                    }
                }

                if (_activeProcess.isLast)
                {
                    _conversionData.PrintSummary();
                }
            };
        }