From 583373b050096bf6a6d175befcc01c75c52a28b4 Mon Sep 17 00:00:00 2001 From: max Date: Fri, 23 Apr 2021 17:10:40 +0200 Subject: [PATCH] MipMapTextureCreator. Added MipMapTextureCreator script to samples. --- CHANGELOG.md | 4 ++ Samples~/MipMapTextureCreator/Editor.meta | 8 +++ .../Editor/MipMapTextureCreator.cs | 61 +++++++++++++++++++ .../Editor/MipMapTextureCreator.cs.meta | 11 ++++ package.json | 9 ++- 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Samples~/MipMapTextureCreator/Editor.meta create mode 100644 Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs create mode 100644 Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index ee2215a..29a705a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log: +## 1.2.0 + +- Added texel density preset. + ## 1.1.0 - Added vertex color preset. diff --git a/Samples~/MipMapTextureCreator/Editor.meta b/Samples~/MipMapTextureCreator/Editor.meta new file mode 100644 index 0000000..27daf81 --- /dev/null +++ b/Samples~/MipMapTextureCreator/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c2d81576eefc15844914163790c174a5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs b/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs new file mode 100644 index 0000000..6361d44 --- /dev/null +++ b/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs @@ -0,0 +1,61 @@ +using UnityEngine; +using UnityEditor; + +public class MipMapTextureCreator : ScriptableWizard +{ + public int texSize = 32; + public bool autoColor = true; + public Color[] mipMapColors; + public int mipMaps; + + [MenuItem("Window/Analysis/SceneDebugViewer/MipMapTextureCreator")] + static void CreateWizard() + { + DisplayWizard("Create MipMap Texture", "Create").OnValidate(); + } + + void OnWizardCreate() + { + Texture2D tex = new Texture2D(texSize, texSize, TextureFormat.RGBAFloat, mipMaps, false); + + for (int m = 0; m < tex.mipmapCount; m++) + { + Color[] c = tex.GetPixels(m); + + for (int i = 0; i < c.Length; ++i) + { + c[i] = mipMapColors[m]; + } + + tex.SetPixels(c, m); + } + + //Texture2D tex = new Texture2D(2, 2, TextureFormat.RGBAFloat, mipMaps, false); + + //for (int m = 0; m < mipMaps; m++) + //{ + // tex.SetPixels(new Color[] { mipMapColors[m], mipMapColors[m], mipMapColors[m], mipMapColors[m] }, m); + //} + + tex.Apply(false, true); + + AssetDatabase.CreateAsset(tex, "Assets/MipMap.asset"); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + private void OnValidate() + { + if (autoColor) + { + mipMaps = 1 + Mathf.FloorToInt(Mathf.Log(texSize, 2)); + mipMapColors = new Color[mipMaps]; + + for (int c = 0; c < mipMaps; c++) + { + mipMapColors[c] = Color.HSVToRGB(0.6f - (0.6f / mipMaps * c), 1, 1); + // mipMapColors[c].a = Mathf.Sin(1.0f / mipMaps * c); + } + } + } +} diff --git a/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs.meta b/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs.meta new file mode 100644 index 0000000..6b1f8e4 --- /dev/null +++ b/Samples~/MipMapTextureCreator/Editor/MipMapTextureCreator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fba1e8247a5d08d4792462dd31b1646c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index f911078..f8d4399 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tech_art_outsource.scene_debug_viewer", "displayName": "TAO Scene Debug Viewer", - "version": "1.1.0", + "version": "1.2.0", "unity": "2019.4", "description": "View your scene with custom shaders to enhance debugging/development.", "category": "Tool", @@ -15,5 +15,12 @@ "keywords": [ "tech art outsource", "debug viewer" + ], + "samples": [ + { + "displayName": "MipMapTextureCreator", + "description": "Create colored mip maps.", + "path": "Samples~/MipMapTextureCreator" + } ] } \ No newline at end of file