mirror of
https://github.com/maxartz15/SceneDebugViewer.git
synced 2025-06-26 19:56:07 +02:00
Replaced mip textures.
Removed custom mip map importer. Textures are now created within Unity (tool might later be added as importable content).
This commit is contained in:
@ -1,117 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class CustomMipMapImporter : AssetPostprocessor
|
||||
{
|
||||
bool m_isReadable;
|
||||
bool m_importing;
|
||||
|
||||
bool ShouldImportAsset(string path)
|
||||
{
|
||||
string pattern = GetMipmapFilenamePattern(path);
|
||||
string mip1Path = string.Format(pattern, 1);
|
||||
return File.Exists(mip1Path);
|
||||
}
|
||||
|
||||
string GetMipmapFilenamePattern(string path)
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
var filenameWithoutExtention = Path.GetFileNameWithoutExtension(path);
|
||||
var extension = Path.GetExtension(path);
|
||||
var directoryName = Path.GetDirectoryName(path);
|
||||
|
||||
return Path.Combine(directoryName, filenameWithoutExtention + ".mip{0}" + extension);
|
||||
}
|
||||
|
||||
void OnPreprocessTexture()
|
||||
{
|
||||
string extension = Path.GetExtension(assetPath);
|
||||
string filenameWithoutExtention = Path.GetFileNameWithoutExtension(assetPath);
|
||||
var match = Regex.Match(filenameWithoutExtention, @".mip(\d)+$");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string filenameWithoutMip = filenameWithoutExtention.Substring(0, match.Index);
|
||||
string directoryName = Path.GetDirectoryName(assetPath);
|
||||
string mip0Path = Path.Combine(directoryName, filenameWithoutMip + extension);
|
||||
|
||||
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mip0Path);
|
||||
if (importer != null)
|
||||
{
|
||||
importer.SaveAndReimport();
|
||||
}
|
||||
}
|
||||
|
||||
if (ShouldImportAsset(assetPath))
|
||||
{
|
||||
m_importing = true;
|
||||
|
||||
string pattern = GetMipmapFilenamePattern(assetPath);
|
||||
int m = 1;
|
||||
|
||||
bool reimport = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
string mipPath = string.Format(pattern, m);
|
||||
m++;
|
||||
|
||||
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mipPath);
|
||||
if (importer != null)
|
||||
{
|
||||
|
||||
if (!importer.mipmapEnabled || !importer.isReadable)
|
||||
{
|
||||
importer.mipmapEnabled = true;
|
||||
importer.isReadable = true;
|
||||
importer.SaveAndReimport();
|
||||
|
||||
reimport = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reimport)
|
||||
{
|
||||
m_importing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
TextureImporter textureImporter = (TextureImporter)assetImporter;
|
||||
m_isReadable = textureImporter.isReadable;
|
||||
textureImporter.isReadable = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnPostprocessTexture(Texture2D texture)
|
||||
{
|
||||
if (m_importing)
|
||||
{
|
||||
string pattern = GetMipmapFilenamePattern(assetPath);
|
||||
|
||||
for (int m = 0; m < texture.mipmapCount; m++)
|
||||
{
|
||||
var mipmapTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(string.Format(pattern, m));
|
||||
|
||||
if (mipmapTexture != null)
|
||||
{
|
||||
Color[] c = mipmapTexture.GetPixels(0);
|
||||
texture.SetPixels(c, m);
|
||||
}
|
||||
}
|
||||
|
||||
texture.Apply(false, !m_isReadable);
|
||||
TextureImporter textureImporter = (TextureImporter)assetImporter;
|
||||
textureImporter.isReadable = m_isReadable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b3c6a9a745cf994c924b3a44a3309db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -111,3 +111,59 @@ MonoBehaviour:
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
- m_name: _RS_Metallic
|
||||
m_parameterType: 5
|
||||
m_texture: {fileID: 0}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray: []
|
||||
m_color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_colorArray: []
|
||||
m_float: 0
|
||||
m_floatArray: []
|
||||
m_int: 0
|
||||
m_matrix:
|
||||
e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
- m_name: _RS_Glossiness
|
||||
m_parameterType: 5
|
||||
m_texture: {fileID: 0}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray: []
|
||||
m_color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_colorArray: []
|
||||
m_float: 0
|
||||
m_floatArray: []
|
||||
m_int: 0
|
||||
m_matrix:
|
||||
e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
|
@ -111,59 +111,3 @@ MonoBehaviour:
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
- m_name: _RS_Metallic
|
||||
m_parameterType: 5
|
||||
m_texture: {fileID: 2800000, guid: 60a6c65bf59247d41bcc18553d97d2c5, type: 3}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray: []
|
||||
m_color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_colorArray: []
|
||||
m_float: 0
|
||||
m_floatArray: []
|
||||
m_int: 0
|
||||
m_matrix:
|
||||
e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
- m_name: _RS_Glossiness
|
||||
m_parameterType: 5
|
||||
m_texture: {fileID: 2800000, guid: 60a6c65bf59247d41bcc18553d97d2c5, type: 3}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray: []
|
||||
m_color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_colorArray: []
|
||||
m_float: 0
|
||||
m_floatArray: []
|
||||
m_int: 0
|
||||
m_matrix:
|
||||
e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray: []
|
||||
|
@ -10,7 +10,7 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1aa272ccd1306c545b68254a527f8025, type: 3}
|
||||
m_Name: TexelDensityChecker
|
||||
m_Name: TexelDensity128
|
||||
m_EditorClassIdentifier:
|
||||
content:
|
||||
icon: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
|
||||
@ -29,7 +29,7 @@ MonoBehaviour:
|
||||
parameters:
|
||||
- m_name: _RS_Texture
|
||||
m_parameterType: 0
|
||||
m_texture: {fileID: 0}
|
||||
m_texture: {fileID: 2800000, guid: 05a258bf93e7ca749ae1cd66d39fb477, type: 2}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray:
|
||||
- {x: 0, y: 0, z: 0, w: 0}
|
95
Editor/Presets/TexelDensity32.asset
Normal file
95
Editor/Presets/TexelDensity32.asset
Normal file
@ -0,0 +1,95 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1aa272ccd1306c545b68254a527f8025, type: 3}
|
||||
m_Name: TexelDensity32
|
||||
m_EditorClassIdentifier:
|
||||
content:
|
||||
icon: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
|
||||
tooltip:
|
||||
sortingOrder: 31
|
||||
compact:
|
||||
m_Text:
|
||||
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
|
||||
m_Tooltip:
|
||||
normal:
|
||||
m_Text: ' TexelDensityChecker 1'
|
||||
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
|
||||
m_Tooltip:
|
||||
shader: {fileID: 4800000, guid: 83a3ee0da908c7542be7a089c047d28f, type: 3}
|
||||
replacementTag:
|
||||
parameters:
|
||||
- m_name: _RS_Texture
|
||||
m_parameterType: 0
|
||||
m_texture: {fileID: 2800000, guid: 5c021ebf5a89dcf4cb5504809772f451, type: 2}
|
||||
m_vector: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_vectorArray:
|
||||
- {x: 0, y: 0, z: 0, w: 0}
|
||||
- {x: 0, y: 0, z: 0, w: 0}
|
||||
- {x: 0, y: 0, z: 0, w: 0}
|
||||
m_color: {r: 1, g: 0, b: 0, a: 0.14901961}
|
||||
m_colorArray: []
|
||||
m_float: 0
|
||||
m_floatArray:
|
||||
- 0
|
||||
- 0
|
||||
- 0
|
||||
m_int: 0
|
||||
m_matrix:
|
||||
e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
m_matrixArray:
|
||||
- e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
||||
- e00: 0
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 0
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 0
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 0
|
8
Editor/Presets/TexelDensity32.asset.meta
Normal file
8
Editor/Presets/TexelDensity32.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c8f9104d7125d54d98cd85091535a8c
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user