private void CreateMaterial(Material material, int count)
        {
            PmxMaterial pmxMaterial = new PmxMaterial();

            pmxMaterial.Name  = material.name;
            pmxMaterial.NameE = material.name;
            pmxMaterial.Flags = (PmxMaterial.MaterialFlags.DrawBoth | PmxMaterial.MaterialFlags.Shadow | PmxMaterial.MaterialFlags.SelfShadowMap | PmxMaterial.MaterialFlags.SelfShadow);
            MaterialInfo info = new MaterialInfo();

            materialInfo[material.name] = info;
            info.shader = material.shader.name;

            /*
             * _Color [color]
             * _MainTex
             * _MultiColTex "Multi Color Table (RGBA)"
             * _UseMulticolTex
             *
             * _ShadowColor [color]
             * _ShadowTex
             * _ShadowRateToon [tex]
             * _RimColor
             * _RimPower
             * _RimShift
             * _HiTex "Hilight (RGB)"
             * _HiRate "Hilight rate"
             * _HiPow
             *
             * _Ramp "Toon Ramp (RGB)"
             *
             * _OutlineColor [color]
             * _OutlineTex
             * _OutlineToonRamp
             *
             * _OutlineWidth [float]
             *
             * _EdgeLength "Edge length"
             * _Phong "Phong Strengh"
             *
             *
             *
             */
            /* Uncomment to dump list of material textures
             * if (true)//material.name.StartsWith("Face011_GP_Skin"))
             * {
             *  Debug.Log($"Material {material.name} uses shader {material.shader.name} ({material.shader.GetInstanceID()}) and textures:");
             *  for (int i = 0; i < 99999; i++)
             *  {
             *      Texture t = material.GetTexture(i);
             *      if (t == null)
             *      {
             *          continue;
             *      }
             *      Debug.Log($"  ({i,5}) {t.name} [{t.GetType().Name}]");
             *  }
             * }
             * // */
            if (material.HasProperty("_MainTex"))
            {
                Texture mainTexture = material.GetTexture("_MainTex");
                if (mainTexture == null)
                {
                    mainTexture = material.mainTexture;
                }
                if (mainTexture != null && SaveTexture)
                {
                    Debug.Log($"Generate Material: {material.name} {mainTexture.name}");
                    pmxMaterial.Tex = textureBuilder.Export(ExportFolder, material, "_MainTex", mainTexture);
                }
                info.mainTex = pmxMaterial.Tex;
            }
            SetMaterialInfoProperty(out info.color, material, "_Color");
            info.shadowTex = textureBuilder.Export(ExportFolder, material, "_ShadowTex");
            SetMaterialInfoProperty(out info.shadowColor, material, "_ShadowColor");
            info.shadowRateToon = textureBuilder.Export(ExportFolder, material, "_ShadowRateToon");
            info.toonRamp       = textureBuilder.Export(ExportFolder, material, "_ToonRamp");
            pmxMaterial.Toon    = info.toonRamp ?? "";
            SetMaterialInfoProperty(out info.rimColor, material, "_RimColor");
            SetMaterialInfoProperty(out info.rimPower, material, "_RimPower");
            SetMaterialInfoProperty(out info.rimShift, material, "_RimShift");
            info.hiTex = textureBuilder.Export(ExportFolder, material, "_HiTex");
            SetMaterialInfoProperty(out info.hiRate, material, "_HiRate");
            SetMaterialInfoProperty(out info.hiPow, material, "_HiPow");
            SetMaterialInfoProperty(out info.outlineColor, material, "_OutlineColor");
            SetMaterialInfoProperty(out info.outlineWidth, material, "_OutlineWidth");

            if (material.HasProperty("_AmbColor"))
            {
                pmxMaterial.Ambient = new PmxLib.Vector3(material.GetColor("_AmbColor"));
            }
            if (material.HasProperty("_Color"))
            {
                pmxMaterial.Diffuse = new PmxLib.Vector4(material.GetColor("_Color"));
            }
            if (material.HasProperty("_Opacity"))
            {
                pmxMaterial.Diffuse.Alpha = material.GetFloat("_Opacity");
            }
            if (material.HasProperty("_SpecularColor"))
            {
                pmxMaterial.Specular = new PmxLib.Vector3(material.GetColor("_SpecularColor"));
            }
            if (material.HasProperty("_Shininess"))
            {
                pmxMaterial.Power = material.GetFloat("_Shininess");
            }
            if (material.HasProperty("_OutlineColor"))
            {
                pmxMaterial.EdgeSize  = material.GetFloat("_OutlineWidth");
                pmxMaterial.EdgeColor = new PmxLib.Vector4(material.GetColor("_OutlineColor"));
            }
            pmxMaterial.FaceCount = count;
            pmxFile.MaterialList.Add(pmxMaterial);
        }
Ejemplo n.º 2
0
        private void CreateMaterial(Material material, int count)
        {
            PmxMaterial pmxMaterial = new PmxMaterial();

            pmxMaterial.Name  = material.name;
            pmxMaterial.NameE = material.name;
            pmxMaterial.Flags = (PmxMaterial.MaterialFlags.DrawBoth | PmxMaterial.MaterialFlags.Shadow | PmxMaterial.MaterialFlags.SelfShadowMap | PmxMaterial.MaterialFlags.SelfShadow);
            MaterialInfo info = new MaterialInfo();

            materialInfo[material.name] = info;
            info.shader = material.shader.name;

            /* Uncomment to dump list of material textures (put one / at the start of this line)
             * if (true)//material.name.StartsWith("Face011_GP_Skin"))
             * {
             *  Debug.Log($"Material {material.name} uses shader {material.shader.name} ({material.shader.GetInstanceID()}) and textures:");
             *  for (int i = 0; i < 99999; i++)
             *  {
             *      Texture t = material.GetTexture(i);
             *      if (t == null)
             *      {
             *          continue;
             *      }
             *      Debug.Log($"  ({i,5}) {t.name} [{t.GetType().Name}]");
             *  }
             * }
             * // */
            if (material.HasProperty("_MainTex"))
            {
                Texture mainTexture = material.GetTexture("_MainTex");
                if (mainTexture == null)
                {
                    mainTexture = material.mainTexture;
                }
                if (mainTexture != null && SaveTexture)
                {
                    Debug.Log($"Generate Material: {material.name} {mainTexture.name}");
                    pmxMaterial.Tex = textureBuilder.Export(ExportFolder, material, "_MainTex", mainTexture);
                }
                info.mainTex = pmxMaterial.Tex;
            }
            SetMaterialInfoProperty(out info.color, material, "_Color");
            info.shadowTex = textureBuilder.Export(ExportFolder, material, "_ShadowTex");
            SetMaterialInfoProperty(out info.shadowColor, material, "_ShadowColor");
            info.shadowRateToon = textureBuilder.Export(ExportFolder, material, "_ShadowRateToon");
            pmxMaterial.Toon    = textureBuilder.Export(ExportFolder, material, "_ToonRamp");
            info.toonRamp       = pmxMaterial.Toon;
            SetMaterialInfoProperty(out info.shininess, material, "_Shininess");
            SetMaterialInfoProperty(out info.rimColor, material, "_RimColor");
            SetMaterialInfoProperty(out info.rimPower, material, "_RimPower");
            SetMaterialInfoProperty(out info.rimShift, material, "_RimShift");
            info.hiTex = textureBuilder.Export(ExportFolder, material, "_HiTex");
            SetMaterialInfoProperty(out info.hiRate, material, "_HiRate");
            SetMaterialInfoProperty(out info.hiPow, material, "_HiPow");
            SetMaterialInfoProperty(out info.outlineColor, material, "_OutlineColor");
            info.outlineTex      = textureBuilder.Export(ExportFolder, material, "_OutlineTex");
            info.outlineToonRamp = textureBuilder.Export(ExportFolder, material, "_OutlineToonRamp");
            SetMaterialInfoProperty(out info.outlineWidth, material, "_OutlineWidth");
            info.outlineWidthTex = textureBuilder.Export(ExportFolder, material, "_OutlineWidthTex");
            SetMaterialInfoProperty(out info.zTest, material, "_ZTest");
            SetMaterialInfoProperty(out info.zTest2, material, "_ZTest2");
            SetMaterialInfoProperty(out info.zTest2Alpha, material, "_ZTest2Alpha");
            if (material.HasProperty("_Color"))
            {
                pmxMaterial.Diffuse = new PmxLib.Vector4(material.GetColor("_Color"));
            }
            if (material.HasProperty("_Opacity"))
            {
                pmxMaterial.Diffuse.Alpha = material.GetFloat("_Opacity");
            }
            pmxMaterial.FaceCount = count;
            pmxFile.MaterialList.Add(pmxMaterial);
        }