Exemplo n.º 1
0
        private static bool IsNormalToonTexture(string name, out int toonIndex)
        {
            if (string.IsNullOrEmpty(name))
            {
                // Maps to "no texture" (empty string)
                toonIndex = -1;
                return(false);
            }

            var match = ToonNameRegex.Match(name);

            if (!match.Success)
            {
                toonIndex = -1;
                return(false);
            }

            var toonStr = match.Groups["toonIndex"].Value;

            toonIndex = Convert.ToInt32(toonStr);
            // From 1-based to 0-based
            toonIndex -= 1;

            return(toonIndex > 0);
        }
Exemplo n.º 2
0
        private void BuildTextureNameMap([NotNull] PmxModel model)
        {
            var materials = model.Materials;

            if (materials == null)
            {
                return;
            }

            var nameList = new List <string>();

            foreach (var material in materials)
            {
                if (!string.IsNullOrEmpty(material.TextureFileName))
                {
                    nameList.Add(material.TextureFileName);
                }

                if (!string.IsNullOrEmpty(material.SphereTextureFileName))
                {
                    nameList.Add(material.SphereTextureFileName);
                }

                if (!string.IsNullOrEmpty(material.ToonTextureFileName) && !ToonNameRegex.IsMatch(material.ToonTextureFileName))
                {
                    nameList.Add(material.ToonTextureFileName);
                }
            }

            _textureNameList.AddRange(nameList.Distinct());
        }
Exemplo n.º 3
0
        private string[] BuildTextureNameMap([NotNull] PmxModel model)
        {
            var materials = model.Materials;

            var nameList = new List <string>();

            foreach (var material in materials)
            {
                if (!string.IsNullOrEmpty(material.TextureFileName))
                {
                    nameList.Add(material.TextureFileName);
                }

                if (!string.IsNullOrEmpty(material.SphereTextureFileName))
                {
                    nameList.Add(material.SphereTextureFileName);
                }

                if (!string.IsNullOrEmpty(material.ToonTextureFileName) && !ToonNameRegex.IsMatch(material.ToonTextureFileName))
                {
                    nameList.Add(material.ToonTextureFileName);
                }
            }

            return(nameList.Distinct().ToArray());
        }
Exemplo n.º 4
0
        private void WritePmxMaterial([NotNull] PmxMaterial material)
        {
            WriteString(material.Name);
            WriteString(material.NameEnglish);

            _writer.Write(material.Diffuse);
            _writer.Write(material.Specular);
            _writer.Write(material.SpecularPower);
            _writer.Write(material.Ambient);
            _writer.Write((byte)material.Flags);
            _writer.Write(material.EdgeColor);
            _writer.Write(material.EdgeSize);

            var texNameIndex = GetTextureIndex(material.TextureFileName);

            _writer.WriteInt32AsVarLenInt(texNameIndex, TexElementSize);
            var sphereTexNameIndex = GetTextureIndex(material.SphereTextureFileName);

            _writer.WriteInt32AsVarLenInt(sphereTexNameIndex, TexElementSize);
            _writer.Write((byte)material.SphereMode);

            var mappedToonTexture = !IsNormalToonTexture(material.ToonTextureFileName, out var toon);

            _writer.Write(!mappedToonTexture);

            if (mappedToonTexture)
            {
                var toonTexNameIndex = GetTextureIndex(material.ToonTextureFileName);
                _writer.WriteInt32AsVarLenInt(toonTexNameIndex, TexElementSize);
            }
            else
            {
                _writer.Write((byte)toon);
            }

            WriteString(material.MemoTextureFileName);
            _writer.Write(material.AppliedFaceVertexCount);

            bool IsNormalToonTexture(string name, out int toonIndex)
            {
                if (string.IsNullOrEmpty(name))
                {
                    toonIndex = 0;
                    return(true);
                }

                var match = ToonNameRegex.Match(name);

                if (!match.Success)
                {
                    toonIndex = -1;
                    return(false);
                }

                toonIndex = Convert.ToInt32(match.Groups["toonIndex"].Value);

                return(toonIndex >= 0);
            }
        }