Exemple #1
0
        public static void ApplySettings(BakerProfile profile, ProceduralMaterial proceduralMaterial, SubstanceImporter substanceImporter)
        {
            int width, height, format, loadbehaviour;

            substanceImporter.GetPlatformTextureSettings(proceduralMaterial.name, profile.platform, out width, out height, out format, out loadbehaviour);
            width         = profile.TargetWidth == 0 ? width : profile.TargetWidth;
            height        = profile.TargetHeight == 0 ? height : profile.TargetHeight;
            format        = profile.format == BakerProfile.Format.Unchanged ? format : (int)profile.format;
            loadbehaviour = profile.loadingBehaviour == BakerProfile.LoadingBehavior.Unchanged ? loadbehaviour : (int)profile.loadingBehaviour;
            Debug.Log("Applying Settings to " + proceduralMaterial.name); //Print the name of the material
            foreach (var property in profile.customFloat)
            {
                try
                {
                    if (proceduralMaterial.HasProceduralProperty(property.Name))
                    {
                        proceduralMaterial.SetProceduralFloat(property.Name, property.value);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
            substanceImporter.SetPlatformTextureSettings(proceduralMaterial, profile.platform, width, height, format, loadbehaviour);
            substanceImporter.SetGenerateAllOutputs(proceduralMaterial, profile.generateAllMaps);
            substanceImporter.SaveAndReimport(); //Reimport under the new settings
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemple #2
0
        public static void ApplySettings(BakerProfile profile)
        {
            var materials = GatherProceduralMaterials();

            for (int i = 0; i < materials.Count; i++)
            {
                SubstanceImporter substanceImporter = AssetImporter.GetAtPath(materials.ElementAt(i).Key) as SubstanceImporter; // Get the substance importer to change the settings
                var proceduralMaterials             = substanceImporter.GetMaterials();                                         //Get all the materials within that particular sbsar
                foreach (ProceduralMaterial proceduralMaterial in proceduralMaterials)                                          //For each procedural material in the sbsar...
                {
                    if (materials.ElementAt(i).Value.Contains(proceduralMaterial.name))
                    {
                        ApplySettings(profile, proceduralMaterial, substanceImporter);
                    }
                }
                Resources.UnloadUnusedAssets();
            }
        }
        void OnGUI()
        {
            GUILayout.Label("Profile", EditorStyles.boldLabel);
            EditorGUILayout.PrefixLabel("Profile to use:");
            _profile = EditorGUILayout.ObjectField(_profile, typeof(BakerProfile), false) as BakerProfile;
            if (_profile != null)
            {
                Editor editor = Editor.CreateEditor(_profile);
                editor.DrawDefaultInspector();
                if (GUILayout.Button("Apply settings to selected materials"))
                {
                    Baker.ApplySettings(_profile);
                }
                if (GUILayout.Button("Start Baking selected materials"))
                {
                    Baker.Bake(_profile);
                }
                EditorGUILayout.LabelField("Selected " + ProceduralMaterialCount() + " Procedural Materials");
            }
            if (GUILayout.Button("Create new profile"))
            {
                var    profile = ScriptableObject.CreateInstance("BakerProfile") as BakerProfile;
                string pathToProfile;
                try
                {
                    pathToProfile = "Assets/SubstanceBaker/Profiles/New BakerProfile.asset";
                    AssetDatabase.CreateAsset(profile, pathToProfile);
                }
                catch
                {
                    pathToProfile = "Assets/New BakerProfile.asset";
                    AssetDatabase.CreateAsset(profile, pathToProfile);
                }

                if (_profile == null)
                {
                    _profile = profile;
                }
            }
        }
Exemple #4
0
        public static void Bake(BakerProfile profile, ProceduralMaterial proceduralMaterial, SubstanceImporter substanceImporter)
        {
            isBaking = true;
            var exportTo = UnityPath(Path.Combine(profile.materialFolder, proceduralMaterial.name)) + "/";

            Debug.Log("Baking : " + proceduralMaterial.name);
            if (!pendingTextures.ContainsKey((proceduralMaterial.name)))
            {
                pendingTextures.Add(proceduralMaterial.name, proceduralMaterial.GetGeneratedTextures().Select(x => x.name).ToList <string>());
                bakingMaterials.Add(proceduralMaterial.name, proceduralMaterial);
                // foreach (var name in proceduralMaterial.GetGeneratedTextures().Select(x => x.name))
                // {
                //     Debug.Log("Name added to pendingTextures    " + name);
                // }
            }

            Debug.Log("Exporting");
            substanceImporter.ExportBitmaps(proceduralMaterial, exportTo, profile.remapAlpha);

            Debug.Log("Exported");
            AssetDatabase.Refresh();
        }
Exemple #5
0
 public static void Bake(BakerProfile profile, ProceduralMaterial proceduralMaterial)
 {
     isBaking = true;
     Bake(profile, proceduralMaterial, AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(proceduralMaterial)) as SubstanceImporter);
 }
Exemple #6
0
 public static void ApplySettings(BakerProfile profile, ProceduralMaterial proceduralMaterial)
 {
     ApplySettings(profile, proceduralMaterial, AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(proceduralMaterial)) as SubstanceImporter);
 }
Exemple #7
0
        private static Material CreateMaterialFromMaps(BakerProfile profile, string name)
        {
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            Assert.IsNotNull(profile.shader);
            ProceduralMaterial pm = bakingMaterials[name];

            bakingMaterials.Remove(name);
            Material mat;

            if (profile.shader != pm.shader)
            {
                mat = new Material(profile.shader);
                foreach (var field in profile.AdditionFields)
                {
                    try
                    {
                        switch (field.FieldType)
                        {
                        case (MappableFields.Color):
                        {
                            mat.SetColor(field.To, pm.GetColor(field.From));
                            break;
                        }

                        case (MappableFields.Float):
                        {
                            mat.SetFloat(field.To, pm.GetFloat(field.From));
                            break;
                        }

                        case (MappableFields.Texture):
                        {
                            mat.SetTexture(field.To, pm.GetTexture(field.From));
                            break;
                        }

                        case (MappableFields.Int):
                        {
                            mat.SetInt(field.To, pm.GetInt(field.From));
                            break;
                        }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Additional fields " + field.From + " fialed to set, Skipping field.");
                        Debug.LogException(e);
                        continue;
                    }
                }
            }
            else
            {
                mat = new Material(pm);
            }
            var path = UnityPath(Path.Combine(profile.materialFolder, name));
            var mats = Baker.LoadAllAssetsAtPath <Texture>(path);

            foreach (Texture2D tex in mats)
            {
                if (tex.name.ToLower().Contains("ambient_occlusion"))
                {
                    mat.SetTexture(profile.AOName, tex);
                }
                else if (tex.name.ToLower().Contains("basecolor") || tex.name.ToLower().Contains("diffuse"))
                {
                    mat.SetTexture(profile.albedoName, tex);
                }
                else if (tex.name.ToLower().Contains("roughness"))
                {
                    mat.SetTexture(profile.roughnessName, tex);
                }
                else if (tex.name.ToLower().Contains("height"))
                {
                    mat.SetTexture(profile.heightName, tex);
                }
                else if (tex.name.ToLower().Contains("normal"))
                {
                    mat.SetTexture(profile.normalName, tex);
                }
                else if (tex.name.ToLower().Contains("specular"))
                {
                    mat.SetTexture(profile.specularName, tex);
                }
                else if (tex.name.ToLower().Contains("glossiness"))
                {
                    mat.SetTexture(profile.glossinessName, tex);
                }
            }
            if (profile.removeSubstance)
            {
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(pm));
            }
            AssetDatabase.CreateAsset(mat, path + "/" + name + ".mat");
            Material mat2 = new Material(pm);

            AssetDatabase.CreateAsset(mat2, path + "/" + name + "2.mat");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            Resources.UnloadUnusedAssets();
            return(mat);
        }