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); }
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); } }