1
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
#if GRIFFIN
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GRawExporterWindow : EditorWindow
|
||||
{
|
||||
public GTerrainData SrcData { get; set; }
|
||||
public GBitDepth BitDepth { get; set; }
|
||||
public string DataDirectory { get; set; }
|
||||
|
||||
public bool BulkExport { get; set; }
|
||||
public int BulkExportGroupId { get; set; }
|
||||
|
||||
private const string PREF_PREFIX = "raw-exporter";
|
||||
private const string BIT_DEPTH_PREFIX = "bit-depth";
|
||||
private const string DATA_DIRECTORY_PREFIX = "directory";
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Export height map (R channel) to RAW file (raw, r16).";
|
||||
private const string INSTRUCTION_BULK =
|
||||
"Export height maps (R channel) to RAW files (raw, r16).";
|
||||
|
||||
public static GRawExporterWindow ShowWindow()
|
||||
{
|
||||
GRawExporterWindow window = ScriptableObject.CreateInstance<GRawExporterWindow>();
|
||||
window.titleContent = new GUIContent("Raw Exporter");
|
||||
window.minSize = new Vector2(400, 300);
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
BitDepth = (GBitDepth)EditorPrefs.GetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BIT_DEPTH_PREFIX), 0);
|
||||
DataDirectory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREFIX), "Assets/Polaris Exported/");
|
||||
if (string.IsNullOrEmpty(DataDirectory))
|
||||
{
|
||||
DataDirectory = "Assets/";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BIT_DEPTH_PREFIX), (int)BitDepth);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREFIX), DataDirectory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawInstructionGUI();
|
||||
DrawExportGUI();
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "raw-exporter-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(BulkExport ? INSTRUCTION_BULK : INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawExportGUI()
|
||||
{
|
||||
string label = "Export";
|
||||
string id = "raw-exporter-import";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", BulkExportGroupId);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Griffin Data", SrcData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
BitDepth = (GBitDepth)EditorGUILayout.EnumPopup("Bit Depth", BitDepth);
|
||||
string path = DataDirectory;
|
||||
GEditorCommon.BrowseFolder("Directory", ref path);
|
||||
DataDirectory = path;
|
||||
EditorGUILayout.LabelField("Files with the same name will be overwriten!", GEditorCommon.WordWrapItalicLabel);
|
||||
|
||||
if (GUILayout.Button("Export"))
|
||||
{
|
||||
Export();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Export()
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
DoBulkExport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoExport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoExport()
|
||||
{
|
||||
GRawExporter exporter = new GRawExporter();
|
||||
exporter.SrcData = SrcData;
|
||||
exporter.BitDepth = BitDepth;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
exporter.Export();
|
||||
}
|
||||
|
||||
private void DoBulkExport()
|
||||
{
|
||||
GCommon.ForEachTerrain(
|
||||
BulkExportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t.TerrainData == null)
|
||||
return;
|
||||
GRawExporter exporter = new GRawExporter();
|
||||
exporter.SrcData = t.TerrainData;
|
||||
exporter.BitDepth = BitDepth;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
exporter.Export();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 163bef0f8ede20a4d960448bff968e2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,192 @@
|
||||
#if GRIFFIN
|
||||
using Pinwheel.Griffin.BackupTool;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GRawImporterWindow : EditorWindow
|
||||
{
|
||||
public GStylizedTerrain Terrain { get; set; }
|
||||
public GTerrainData DesData { get; set; }
|
||||
public GBitDepth BitDepth { get; set; }
|
||||
public bool UseRawResolution { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public string DataDirectory { get; set; }
|
||||
|
||||
public bool BulkImport { get; set; }
|
||||
public int BulkImportGroupId { get; set; }
|
||||
|
||||
private const string PREF_PREFIX = "raw-importer";
|
||||
private const string BIT_DEPTH_PREFIX = "bit-depth";
|
||||
private const string USE_RAW_RESOLUTION_PREFIX = "use-raw-resolution";
|
||||
private const string FILE_PATH_PREFIX = "file-path";
|
||||
private const string DIRECTORY_PREFIX = "directory";
|
||||
|
||||
private const string HISTORY_PREFIX = "Import RAW";
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Import Height Map from RAW file (raw, r16) generated from other applications like World Machine.\n" +
|
||||
"The RAW file must have squared size, Windows byte order.";
|
||||
|
||||
public static GRawImporterWindow ShowWindow()
|
||||
{
|
||||
GRawImporterWindow window = ScriptableObject.CreateInstance<GRawImporterWindow>();
|
||||
window.titleContent = new GUIContent("Raw Importer");
|
||||
window.minSize = new Vector2(400, 200);
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
BitDepth = (GBitDepth)EditorPrefs.GetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BIT_DEPTH_PREFIX), 0);
|
||||
UseRawResolution = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_RAW_RESOLUTION_PREFIX), true);
|
||||
FilePath = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, FILE_PATH_PREFIX), string.Empty);
|
||||
DataDirectory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREFIX), string.Empty);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BIT_DEPTH_PREFIX), (int)BitDepth);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_RAW_RESOLUTION_PREFIX), UseRawResolution);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, FILE_PATH_PREFIX), FilePath);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREFIX), DataDirectory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawInstructionGUI();
|
||||
DrawImportGUI();
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "raw-importer-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawImportGUI()
|
||||
{
|
||||
string label = "Import";
|
||||
string id = "raw-importer-import";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", BulkImportGroupId);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Terrain", Terrain, typeof(GStylizedTerrain), true);
|
||||
EditorGUILayout.ObjectField("Griffin Data", DesData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
BitDepth = (GBitDepth)EditorGUILayout.EnumPopup("Bit Depth", BitDepth);
|
||||
UseRawResolution = EditorGUILayout.Toggle("Use RAW Resolution", UseRawResolution);
|
||||
|
||||
if (BulkImport)
|
||||
{
|
||||
string path = DataDirectory;
|
||||
GEditorCommon.BrowseFolder("Directory", ref path);
|
||||
DataDirectory = path;
|
||||
string convention = string.Format("{0}_{1}_{2}", BitDepth == GBitDepth.Bit8 ? "RAW8" : "RAW16", "<optional>", "< Polaris Terrain Data Id>");
|
||||
EditorGUILayout.LabelField("File Name Convention", convention, GEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
string path = FilePath;
|
||||
GEditorCommon.BrowseFile("Path", ref path, "raw", "raw", "r16", "r16");
|
||||
FilePath = path;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Import"))
|
||||
{
|
||||
Import();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Import()
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
DoBulkImport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoImport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoImport()
|
||||
{
|
||||
if (Terrain != null)
|
||||
{
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, Terrain, GCommon.HeightMapAndFoliageResourceFlags);
|
||||
}
|
||||
|
||||
GRawImporter importer = new GRawImporter();
|
||||
importer.Terrain = Terrain;
|
||||
importer.DesData = DesData;
|
||||
importer.BitDepth = BitDepth;
|
||||
importer.UseRawResolution = UseRawResolution;
|
||||
importer.FilePath = FilePath;
|
||||
importer.Import();
|
||||
|
||||
if (Terrain != null)
|
||||
{
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, Terrain, GCommon.HeightMapAndFoliageResourceFlags);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoBulkImport()
|
||||
{
|
||||
string ext = BitDepth == GBitDepth.Bit8 ? "raw" : "r16";
|
||||
List<string> files = new List<string>(Directory.GetFiles(DataDirectory));
|
||||
files.RemoveAll(f => !f.EndsWith(ext));
|
||||
|
||||
GCommon.ForEachTerrain(
|
||||
BulkImportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t == null || t.TerrainData == null)
|
||||
return;
|
||||
|
||||
string file = files.Find(
|
||||
s =>
|
||||
{
|
||||
string f = Path.GetFileNameWithoutExtension(s);
|
||||
return f.StartsWith(BitDepth == GBitDepth.Bit8 ? "RAW8" : "RAW16") && f.EndsWith(t.TerrainData.Id);
|
||||
});
|
||||
if (string.IsNullOrEmpty(file))
|
||||
return;
|
||||
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.HeightMapAndFoliageResourceFlags);
|
||||
|
||||
GRawImporter importer = new GRawImporter();
|
||||
importer.Terrain = t;
|
||||
importer.DesData = t.TerrainData;
|
||||
importer.BitDepth = BitDepth;
|
||||
importer.UseRawResolution = UseRawResolution;
|
||||
importer.FilePath = file;
|
||||
importer.Import();
|
||||
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.HeightMapAndFoliageResourceFlags);
|
||||
});
|
||||
GStylizedTerrain.MatchEdges(BulkImportGroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2dcffb1e1e71ae47a0089d03d83b324
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,173 @@
|
||||
#if GRIFFIN
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GTextureExporterWindow : EditorWindow
|
||||
{
|
||||
public GTerrainData SrcData { get; set; }
|
||||
public bool ExportHeightMap { get; set; }
|
||||
public bool ExportVisibilityMap { get; set; }
|
||||
public bool ExportAlbedoMap { get; set; }
|
||||
public bool ExportMetallicMap { get; set; }
|
||||
public bool ExportGradientLookupMaps { get; set; }
|
||||
public bool ExportSplatControlMaps { get; set; }
|
||||
public string DataDirectory { get; set; }
|
||||
|
||||
public bool BulkExport { get; set; }
|
||||
public int BulkExportGroupId { get; set; }
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Export terrain textures to PNG files.";
|
||||
|
||||
private const string PREF_PREFIX = "texture-exporter";
|
||||
private const string EXPORT_HEIGHTMAP_PREFIX = "export-heightmap";
|
||||
private const string EXPORT_VISIBILITY_PREFIX = "export-visibility";
|
||||
private const string EXPORT_ALBEDO_PREFIX = "export-albedo";
|
||||
private const string EXPORT_METALLIC_PREFIX = "export-metallic";
|
||||
private const string EXPORT_GRADIENT_PREFIX = "export-gradient";
|
||||
private const string EXPORT_SPLATS_PREFIX = "export-splats";
|
||||
private const string DATA_DIRECTORY_PREFIX = "directory";
|
||||
|
||||
public static GTextureExporterWindow ShowWindow()
|
||||
{
|
||||
GTextureExporterWindow window = ScriptableObject.CreateInstance<GTextureExporterWindow>();
|
||||
window.titleContent = new GUIContent("Texture Exporter");
|
||||
window.minSize = new Vector2(400, 300);
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ExportHeightMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_HEIGHTMAP_PREFIX), true);
|
||||
ExportVisibilityMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_VISIBILITY_PREFIX), true);
|
||||
ExportAlbedoMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_ALBEDO_PREFIX), true);
|
||||
ExportMetallicMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_METALLIC_PREFIX), true);
|
||||
ExportGradientLookupMaps = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GRADIENT_PREFIX), true);
|
||||
ExportSplatControlMaps = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_SPLATS_PREFIX), true);
|
||||
DataDirectory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREFIX), "Assets/Polaris Exported/");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_HEIGHTMAP_PREFIX), ExportHeightMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_VISIBILITY_PREFIX), ExportVisibilityMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_ALBEDO_PREFIX), ExportAlbedoMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_METALLIC_PREFIX), ExportMetallicMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GRADIENT_PREFIX), ExportGradientLookupMaps);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_SPLATS_PREFIX), ExportSplatControlMaps);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREFIX), DataDirectory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 180;
|
||||
DrawInstructionGUI();
|
||||
DrawExportGUI();
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "texture-exporter-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawExportGUI()
|
||||
{
|
||||
string label = "Export";
|
||||
string id = "texture-exporter-import";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", BulkExportGroupId);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Griffin Data", SrcData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
ExportHeightMap = EditorGUILayout.Toggle("Export Height Map", ExportHeightMap);
|
||||
ExportVisibilityMap = EditorGUILayout.Toggle("Export Visibility Map", ExportVisibilityMap);
|
||||
ExportAlbedoMap = EditorGUILayout.Toggle("Export Albedo Map", ExportAlbedoMap);
|
||||
ExportMetallicMap = EditorGUILayout.Toggle("Export Metallic Map", ExportMetallicMap);
|
||||
ExportGradientLookupMaps = EditorGUILayout.Toggle("Export Gradient Maps", ExportGradientLookupMaps);
|
||||
ExportSplatControlMaps = EditorGUILayout.Toggle("Export Splat Control Maps", ExportSplatControlMaps);
|
||||
|
||||
string dir = DataDirectory;
|
||||
GEditorCommon.BrowseFolder("Data Directory", ref dir);
|
||||
DataDirectory = dir;
|
||||
EditorGUILayout.LabelField("Asset with the same name will be overwriten!", GEditorCommon.WordWrapItalicLabel);
|
||||
|
||||
if (GUILayout.Button("Export"))
|
||||
{
|
||||
Export();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Export()
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
DoBulkExport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoExport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoBulkExport()
|
||||
{
|
||||
GCommon.ForEachTerrain(
|
||||
BulkExportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t == null || t.TerrainData == null)
|
||||
return;
|
||||
|
||||
GTextureExporter exporter = new GTextureExporter();
|
||||
exporter.SrcData = t.TerrainData;
|
||||
exporter.ExportHeightMap = ExportHeightMap;
|
||||
exporter.ExportVisibilityMap = ExportVisibilityMap;
|
||||
exporter.ExportAlbedoMap = ExportAlbedoMap;
|
||||
exporter.ExportMetallicMap = ExportMetallicMap;
|
||||
exporter.ExportGradientLookupMaps = ExportGradientLookupMaps;
|
||||
exporter.ExportSplatControlMaps = ExportSplatControlMaps;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
|
||||
exporter.Export();
|
||||
});
|
||||
}
|
||||
|
||||
private void DoExport()
|
||||
{
|
||||
GTextureExporter exporter = new GTextureExporter();
|
||||
exporter.SrcData = SrcData;
|
||||
exporter.ExportHeightMap = ExportHeightMap;
|
||||
exporter.ExportVisibilityMap = ExportVisibilityMap;
|
||||
exporter.ExportAlbedoMap = ExportAlbedoMap;
|
||||
exporter.ExportMetallicMap = ExportMetallicMap;
|
||||
exporter.ExportGradientLookupMaps = ExportGradientLookupMaps;
|
||||
exporter.ExportSplatControlMaps = ExportSplatControlMaps;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
|
||||
exporter.Export();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d568597231d68d469aebca975aab49e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,240 @@
|
||||
#if GRIFFIN
|
||||
using Pinwheel.Griffin.BackupTool;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GTextureImporterWindow : EditorWindow
|
||||
{
|
||||
public GStylizedTerrain Terrain { get; set; }
|
||||
public GTerrainData DesData { get; set; }
|
||||
public Texture2D HeightMap { get; set; }
|
||||
public Texture2D MaskMap { get; set; }
|
||||
public Texture2D VisibilityMap { get; set; }
|
||||
public Texture2D AlbedoMap { get; set; }
|
||||
public Texture2D MetallicMap { get; set; }
|
||||
public Texture2D[] SplatControlMaps { get; set; }
|
||||
|
||||
public bool BulkImport { get; set; }
|
||||
public int BulkImportGroupId { get; set; }
|
||||
public bool BulkImportHeightMap { get; set; }
|
||||
public bool BulkImportMaskMap { get; set; }
|
||||
public bool BulkImportVisibilityMap { get; set; }
|
||||
public bool BulkImportAlbedoMap { get; set; }
|
||||
public bool BulkImportMetallicMap { get; set; }
|
||||
public bool BulkImportControlMaps { get; set; }
|
||||
public string Directory { get; set; }
|
||||
|
||||
private const string HISTORY_PREFIX = "Import Textures";
|
||||
private const string INSTRUCTION =
|
||||
"Import external textures into the Terrain Data.\n" +
|
||||
"These textures will be resampled to fit Terrain Data config.";
|
||||
|
||||
private const string PREF_PREFIX = "texture-importer";
|
||||
private const string BULK_IMPORT_HEIGHT_MAP_PREF_KEY = "bulk-import-height-map";
|
||||
private const string BULK_IMPORT_MASK_MAP_PREF_KEY = "bulk-import-mask-map";
|
||||
private const string BULK_IMPORT_VISIBILITY_MAP_PREF_KEY = "bulk-import-visibility-map";
|
||||
private const string BULK_IMPORT_ALBEDO_MAP_PREF_KEY = "bulk-import-albedo-map";
|
||||
private const string BULK_IMPORT_METALLIC_MAP_PREF_KEY = "bulk-import-metallic-map";
|
||||
private const string BULK_IMPORT_CONTROL_MAP_PREF_KEY = "bulk-import-control-map";
|
||||
private const string DIRECTORY_PREF_KEY = "directory";
|
||||
|
||||
public static GTextureImporterWindow ShowWindow(GStylizedTerrain terrain = null)
|
||||
{
|
||||
GTextureImporterWindow window = ScriptableObject.CreateInstance<GTextureImporterWindow>();
|
||||
window.Terrain = terrain;
|
||||
window.titleContent = new GUIContent("Texture Importer");
|
||||
window.minSize = new Vector2(400, 300);
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
BulkImportHeightMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_HEIGHT_MAP_PREF_KEY), true);
|
||||
BulkImportMaskMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_MASK_MAP_PREF_KEY), true);
|
||||
BulkImportVisibilityMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_VISIBILITY_MAP_PREF_KEY), true);
|
||||
BulkImportAlbedoMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_ALBEDO_MAP_PREF_KEY), true);
|
||||
BulkImportMetallicMap = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_METALLIC_MAP_PREF_KEY), true);
|
||||
BulkImportControlMaps = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_CONTROL_MAP_PREF_KEY), true);
|
||||
Directory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREF_KEY), string.Empty);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_HEIGHT_MAP_PREF_KEY), BulkImportHeightMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_MASK_MAP_PREF_KEY), BulkImportMaskMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_VISIBILITY_MAP_PREF_KEY), BulkImportVisibilityMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_ALBEDO_MAP_PREF_KEY), BulkImportAlbedoMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_METALLIC_MAP_PREF_KEY), BulkImportMetallicMap);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, BULK_IMPORT_CONTROL_MAP_PREF_KEY), BulkImportControlMaps);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREF_KEY), Directory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawInstructionGUI();
|
||||
DrawImportGUI();
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "texture-importer-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawImportGUI()
|
||||
{
|
||||
string label = "Import";
|
||||
string id = "texture-importer-import";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", BulkImportGroupId);
|
||||
GUI.enabled = true;
|
||||
BulkImportHeightMap = EditorGUILayout.Toggle("Height Map (R)", BulkImportHeightMap);
|
||||
BulkImportMaskMap = EditorGUILayout.Toggle("Mask Map (R)", BulkImportMaskMap);
|
||||
BulkImportVisibilityMap = EditorGUILayout.Toggle("Visibility Map (1-R)", BulkImportVisibilityMap);
|
||||
BulkImportAlbedoMap = EditorGUILayout.Toggle("Albedo Map", BulkImportAlbedoMap);
|
||||
BulkImportMetallicMap = EditorGUILayout.Toggle("Metallic Map", BulkImportMetallicMap);
|
||||
BulkImportControlMaps = EditorGUILayout.Toggle("Control Maps", BulkImportControlMaps);
|
||||
string dir = Directory;
|
||||
GEditorCommon.BrowseFolder("Directory", ref dir);
|
||||
Directory = dir;
|
||||
|
||||
string convention =
|
||||
"HeightMap_<optional>_<Polaris Terrain Data Id>\n" +
|
||||
"MaskMap_<optional>_<Polaris Terrain Data Id>\n" +
|
||||
"VisibilityMap_<optional>_<Polaris Terrain Data Id>\n" +
|
||||
"AlbedoMap_<optional>_<Polaris Terrain Data Id>\n" +
|
||||
"MetallicMap_<optional>_<Polaris Terrain Data Id>\n" +
|
||||
"ControlMap<index>_<optional>_<Polaris Terrain Data Id>";
|
||||
EditorGUILayout.LabelField("File Name Convention", convention, GEditorCommon.WordWrapItalicLabel);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Terrain", Terrain, typeof(GStylizedTerrain), true);
|
||||
EditorGUILayout.ObjectField("Griffin Data", DesData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
|
||||
HeightMap = EditorGUILayout.ObjectField("Height Map (R)", HeightMap, typeof(Texture2D), false) as Texture2D;
|
||||
MaskMap = EditorGUILayout.ObjectField("Mask Map (R)", MaskMap, typeof(Texture2D), false) as Texture2D;
|
||||
VisibilityMap = EditorGUILayout.ObjectField("Visibility Map (1-R)", VisibilityMap, typeof(Texture2D), false) as Texture2D;
|
||||
AlbedoMap = EditorGUILayout.ObjectField("Albedo Map", AlbedoMap, typeof(Texture2D), false) as Texture2D;
|
||||
MetallicMap = EditorGUILayout.ObjectField("Metallic Map", MetallicMap, typeof(Texture2D), false) as Texture2D;
|
||||
|
||||
if (SplatControlMaps == null || SplatControlMaps.Length != DesData.Shading.SplatControlMapCount)
|
||||
{
|
||||
SplatControlMaps = new Texture2D[DesData.Shading.SplatControlMapCount];
|
||||
}
|
||||
for (int i = 0; i < SplatControlMaps.Length; ++i)
|
||||
{
|
||||
SplatControlMaps[i] = EditorGUILayout.ObjectField("Splat Control " + i, SplatControlMaps[i], typeof(Texture2D), false) as Texture2D;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Import"))
|
||||
{
|
||||
Import();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Import()
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
DoBulkImport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoImport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoBulkImport()
|
||||
{
|
||||
string[] guid = AssetDatabase.FindAssets("t:Texture2D", new string[] { Directory });
|
||||
List<Texture2D> textures = new List<Texture2D>();
|
||||
for (int i = 0; i < guid.Length; ++i)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid[i]);
|
||||
Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
||||
textures.Add(tex);
|
||||
}
|
||||
|
||||
GCommon.ForEachTerrain(
|
||||
BulkImportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t == null || t.TerrainData == null)
|
||||
return;
|
||||
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
|
||||
|
||||
Texture2D hm = textures.Find(tex => tex.name.StartsWith("HeightMap") && tex.name.EndsWith(t.TerrainData.Id));
|
||||
Texture2D mkm = textures.Find(tex => tex.name.StartsWith("MaskMap") && tex.name.EndsWith(t.TerrainData.Id));
|
||||
Texture2D vm = textures.Find(tex => tex.name.StartsWith("VisibilityMap") && tex.name.EndsWith(t.TerrainData.Id));
|
||||
Texture2D am = textures.Find(tex => tex.name.StartsWith("AlbedoMap") && tex.name.EndsWith(t.TerrainData.Id));
|
||||
Texture2D mm = textures.Find(tex => tex.name.StartsWith("MetallicMap") && tex.name.EndsWith(t.TerrainData.Id));
|
||||
Texture2D[] cm = new Texture2D[t.TerrainData.Shading.SplatControlMapCount];
|
||||
for (int i = 0; i < cm.Length; ++i)
|
||||
{
|
||||
cm[i] = textures.Find(tex => tex.name.StartsWith("ControlMap" + i.ToString()) && tex.name.EndsWith(t.TerrainData.Id));
|
||||
}
|
||||
|
||||
GTextureImporter importer = new GTextureImporter();
|
||||
importer.Terrain = t;
|
||||
importer.DesData = t.TerrainData;
|
||||
importer.HeightMap = hm;
|
||||
importer.MaskMap = mkm;
|
||||
importer.VisibilityMap = vm;
|
||||
importer.AlbedoMap = am;
|
||||
importer.MetallicMap = mm;
|
||||
importer.SplatControlMaps = cm;
|
||||
importer.Import();
|
||||
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
|
||||
});
|
||||
|
||||
GStylizedTerrain.MatchEdges(BulkImportGroupId);
|
||||
}
|
||||
|
||||
private void DoImport()
|
||||
{
|
||||
if (Terrain != null)
|
||||
{
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, Terrain, GCommon.AllResourceFlags);
|
||||
}
|
||||
|
||||
GTextureImporter importer = new GTextureImporter();
|
||||
importer.Terrain = Terrain;
|
||||
importer.DesData = DesData;
|
||||
importer.HeightMap = HeightMap;
|
||||
importer.MaskMap = MaskMap;
|
||||
importer.VisibilityMap = VisibilityMap;
|
||||
importer.AlbedoMap = AlbedoMap;
|
||||
importer.MetallicMap = MetallicMap;
|
||||
importer.SplatControlMaps = SplatControlMaps;
|
||||
importer.Import();
|
||||
|
||||
if (Terrain != null)
|
||||
{
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, Terrain, GCommon.AllResourceFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e70652d5c0d038a49837ba920b7ee4b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,219 @@
|
||||
#if GRIFFIN
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GUnityTerrainDataExporterWindow : EditorWindow
|
||||
{
|
||||
public GTerrainData SrcData { get; set; }
|
||||
public TerrainData DesData { get; set; }
|
||||
public bool CreateNewAsset { get; set; }
|
||||
public bool ExportGeometry { get; set; }
|
||||
public bool ExportTerrainSize { get; set; }
|
||||
public bool ExportSplats { get; set; }
|
||||
public bool OverwriteSplatLayers { get; set; }
|
||||
public bool ExportTrees { get; set; }
|
||||
public bool ExportGrasses { get; set; }
|
||||
public string DataDirectory { get; set; }
|
||||
|
||||
public bool BulkExport { get; set; }
|
||||
public int BulkExportGroupId { get; set; }
|
||||
|
||||
private const string PREF_PREFIX = "unity-terrain-exporter";
|
||||
private const string CREATE_NEW_ASSET = "create-new-asset";
|
||||
private const string EXPORT_GEOMETRY_PREF_KEY = "export-geometry";
|
||||
private const string EXPORT_TERRAIN_SIZE_PREF_KEY = "export-terrain-size";
|
||||
private const string EXPORT_SPLATS_PREF_KEY = "export-splats";
|
||||
private const string OVERWRITE_SPLAT_LAYERS_PREF_KEY = "overwrite-splats";
|
||||
private const string EXPORT_TREES_PREF_KEY = "export-trees";
|
||||
private const string EXPORT_GRASS_PREF_KEY = "export-grasses";
|
||||
private const string DATA_DIRECTORY_PREF_KEY = "data-directory";
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Export data to Unity Terain to use with Unity built-in or 3rd-parties terrain tools.";
|
||||
|
||||
public static GUnityTerrainDataExporterWindow ShowWindow()
|
||||
{
|
||||
GUnityTerrainDataExporterWindow window = ScriptableObject.CreateInstance<GUnityTerrainDataExporterWindow>();
|
||||
window.titleContent = new GUIContent("Unity Terrain Data Exporter");
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CreateNewAsset = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CREATE_NEW_ASSET), true);
|
||||
ExportGeometry = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GEOMETRY_PREF_KEY), true);
|
||||
ExportTerrainSize = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_TERRAIN_SIZE_PREF_KEY), true);
|
||||
ExportSplats = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_SPLATS_PREF_KEY), true);
|
||||
OverwriteSplatLayers = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, OVERWRITE_SPLAT_LAYERS_PREF_KEY), false);
|
||||
ExportTrees = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_TREES_PREF_KEY), true);
|
||||
ExportGrasses = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GRASS_PREF_KEY), false);
|
||||
DataDirectory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREF_KEY), "Assets/Polaris Exported/");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, CREATE_NEW_ASSET), CreateNewAsset);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GEOMETRY_PREF_KEY), ExportGeometry);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_TERRAIN_SIZE_PREF_KEY), ExportTerrainSize);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_SPLATS_PREF_KEY), ExportSplats);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, OVERWRITE_SPLAT_LAYERS_PREF_KEY), OverwriteSplatLayers);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_TREES_PREF_KEY), ExportTrees);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, EXPORT_GRASS_PREF_KEY), ExportGrasses);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREF_KEY), DataDirectory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 200;
|
||||
DrawInstructionGUI();
|
||||
DrawExportGUI();
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
HandleRepaint();
|
||||
}
|
||||
|
||||
private void HandleRepaint()
|
||||
{
|
||||
//if (Event.current != null)
|
||||
//{
|
||||
// Repaint();
|
||||
//}
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "unity-terrain-exporter-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawExportGUI()
|
||||
{
|
||||
string label = "Export";
|
||||
string id = "unity-terrain-exporter-export";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", BulkExportGroupId);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Griffin Data", SrcData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
CreateNewAsset = EditorGUILayout.Toggle("Create New Asset", CreateNewAsset);
|
||||
if (!CreateNewAsset)
|
||||
{
|
||||
DesData = EditorGUILayout.ObjectField("Terrain Data", DesData, typeof(TerrainData), false) as TerrainData;
|
||||
}
|
||||
|
||||
if (!CreateNewAsset && DesData == null)
|
||||
return;
|
||||
}
|
||||
|
||||
ExportGeometry = EditorGUILayout.Toggle("Export Geometry", ExportGeometry);
|
||||
if (ExportGeometry)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
ExportTerrainSize = EditorGUILayout.Toggle("Export Terrain Size", ExportTerrainSize);
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ExportSplats = EditorGUILayout.Toggle("Export Splats", ExportSplats);
|
||||
if (ExportSplats && !CreateNewAsset && !BulkExport)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
#if !UNITY_2018_1 && !UNITY_2018_2
|
||||
OverwriteSplatLayers = EditorGUILayout.Toggle("Overwrite Layers", OverwriteSplatLayers);
|
||||
#else
|
||||
OverwriteSplatLayers = true;
|
||||
#endif
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ExportTrees = EditorGUILayout.Toggle("Export Trees", ExportTrees);
|
||||
ExportGrasses = EditorGUILayout.Toggle("Export Grasses & Details", ExportGrasses);
|
||||
|
||||
string dir = DataDirectory;
|
||||
GEditorCommon.BrowseFolder("Directory", ref dir);
|
||||
DataDirectory = dir;
|
||||
|
||||
if (BulkExport)
|
||||
{
|
||||
EditorGUILayout.LabelField("Asset with the same name will be overwriten!", GEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Export"))
|
||||
{
|
||||
Export();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Export()
|
||||
{
|
||||
if (BulkExport)
|
||||
{
|
||||
DoBulkExport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoExport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoBulkExport()
|
||||
{
|
||||
GCommon.ForEachTerrain(
|
||||
BulkExportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t == null || t.TerrainData == null)
|
||||
return;
|
||||
|
||||
GUnityTerrainDataExporter exporter = new GUnityTerrainDataExporter();
|
||||
exporter.SrcData = t.TerrainData;
|
||||
exporter.DesData = null;
|
||||
exporter.CreateNewAsset = true;
|
||||
exporter.ExportGeometry = ExportGeometry;
|
||||
exporter.ExportTerrainSize = ExportTerrainSize;
|
||||
exporter.ExportSplats = ExportSplats;
|
||||
exporter.OverwriteSplatLayers = false;
|
||||
exporter.ExportTrees = ExportTrees;
|
||||
exporter.ExportGrasses = ExportGrasses;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
|
||||
exporter.Export();
|
||||
});
|
||||
}
|
||||
|
||||
private void DoExport()
|
||||
{
|
||||
GUnityTerrainDataExporter exporter = new GUnityTerrainDataExporter();
|
||||
exporter.SrcData = SrcData;
|
||||
exporter.DesData = DesData;
|
||||
exporter.CreateNewAsset = CreateNewAsset;
|
||||
exporter.ExportGeometry = ExportGeometry;
|
||||
exporter.ExportTerrainSize = ExportTerrainSize;
|
||||
exporter.ExportSplats = ExportSplats;
|
||||
exporter.OverwriteSplatLayers = OverwriteSplatLayers;
|
||||
exporter.ExportTrees = ExportTrees;
|
||||
exporter.ExportGrasses = ExportGrasses;
|
||||
exporter.DataDirectory = DataDirectory;
|
||||
|
||||
exporter.Export();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32c794875a861214cbde9b11bcb1cc72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,410 @@
|
||||
#if GRIFFIN
|
||||
using Pinwheel.Griffin.BackupTool;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GUnityTerrainDataImporterWindow : EditorWindow
|
||||
{
|
||||
public Terrain SrcTerrain { get; set; }
|
||||
public TerrainData SrcData { get; set; }
|
||||
public GTerrainData DesData { get; set; }
|
||||
public GStylizedTerrain DesTerrain { get; set; }
|
||||
public bool ImportGeometry { get; set; }
|
||||
public bool UseUnityTerrainSize { get; set; }
|
||||
public bool ImportSplats { get; set; }
|
||||
public bool ImportSplatsAsAlbedo { get; set; }
|
||||
public bool ImportSplatControlMapsOnly { get; set; }
|
||||
public bool ImportSplatControlMapResolution { get; set; }
|
||||
public bool CreateNewSplatPrototypesGroup { get; set; }
|
||||
public bool ImportTrees { get; set; }
|
||||
public bool ImportTreeInstancesOnly { get; set; }
|
||||
public bool CreateNewTreePrototypesGroup { get; set; }
|
||||
public bool ImportGrasses { get; set; }
|
||||
public bool ImportGrassInstancesOnly { get; set; }
|
||||
public bool CreateNewGrassPrototypesGroup { get; set; }
|
||||
public float GrassDensity { get; set; }
|
||||
|
||||
public bool BulkImport { get; set; }
|
||||
public int BulkImportGroupId { get; set; }
|
||||
public string Directory { get; set; }
|
||||
|
||||
private const string HISTORY_PREFIX = "Import Unity Terrain";
|
||||
private const string PREF_PREFIX = "unity-terrain-importer";
|
||||
private const string IMPORT_GEOMETRY_PREF_KEY = "import-geometry";
|
||||
private const string USE_UNITY_TERRAIN_SIZE_PREF_KEY = "use-unity-terrain-size";
|
||||
private const string IMPORT_SPLATS_PREF_KEY = "import-splats";
|
||||
private const string IMPORT_SPLATS_AS_ALBEDO_PREF_KEY = "import-splats-as-albedo";
|
||||
private const string IMPORT_SPLATS_CONTROL_MAPS_ONLY_PREF_KEY = "import-splat-control-maps-only";
|
||||
private const string USE_UNITY_CONTROL_MAP_RESOLUTION_PREF_KEY = "import-splat-resolution";
|
||||
private const string NEW_SPLATS_GROUP_PREF_KEY = "new-splats-group";
|
||||
private const string IMPORT_TREES_PREF_KEY = "import-trees";
|
||||
private const string IMPORT_TREE_INSTANCES_ONLY_KEY = "import-trees-instances-only";
|
||||
private const string NEW_TREES_GROUP_PREF_KEY = "new-trees-group";
|
||||
private const string IMPORT_GRASS_PREF_KEY = "import-grasses";
|
||||
private const string IMPORT_GRASS_INSTANCES_ONLY_KEY = "import-grass-instances-only";
|
||||
private const string NEW_GRASSES_GROUP_PREF_KEY = "new-grasses-group";
|
||||
private const string GRASS_DENSITY = "grass-density";
|
||||
private const string DIRECTORY_PREF_KEY = "directory";
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Import data from Unity Terrain Data.\n" +
|
||||
"Sometime you can see splat textures are not rendered correctly, this is caused mostly because there are more splat textures than the material can support!";
|
||||
|
||||
public static GUnityTerrainDataImporterWindow ShowWindow()
|
||||
{
|
||||
GUnityTerrainDataImporterWindow window = ScriptableObject.CreateInstance<GUnityTerrainDataImporterWindow>();
|
||||
window.titleContent = new GUIContent("Unity Terrain Data Importer");
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ImportGeometry = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GEOMETRY_PREF_KEY), true);
|
||||
UseUnityTerrainSize = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_UNITY_TERRAIN_SIZE_PREF_KEY), true);
|
||||
ImportSplats = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_PREF_KEY), true);
|
||||
ImportSplatsAsAlbedo = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_AS_ALBEDO_PREF_KEY), false);
|
||||
ImportSplatControlMapsOnly = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_CONTROL_MAPS_ONLY_PREF_KEY), false);
|
||||
ImportSplatControlMapResolution = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_UNITY_CONTROL_MAP_RESOLUTION_PREF_KEY), false);
|
||||
CreateNewSplatPrototypesGroup = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_SPLATS_GROUP_PREF_KEY), false);
|
||||
ImportTrees = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREES_PREF_KEY), true);
|
||||
ImportTreeInstancesOnly = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREE_INSTANCES_ONLY_KEY), true);
|
||||
CreateNewTreePrototypesGroup = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_TREES_GROUP_PREF_KEY), false);
|
||||
ImportGrasses = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_PREF_KEY), false);
|
||||
ImportGrassInstancesOnly = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_INSTANCES_ONLY_KEY), false);
|
||||
CreateNewGrassPrototypesGroup = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_GRASSES_GROUP_PREF_KEY), false);
|
||||
GrassDensity = EditorPrefs.GetFloat(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, GRASS_DENSITY), 0.5f);
|
||||
Directory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREF_KEY), string.Empty);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GEOMETRY_PREF_KEY), ImportGeometry);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_UNITY_TERRAIN_SIZE_PREF_KEY), UseUnityTerrainSize);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_PREF_KEY), ImportSplats);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_AS_ALBEDO_PREF_KEY), ImportSplatsAsAlbedo);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_CONTROL_MAPS_ONLY_PREF_KEY), ImportSplatControlMapsOnly);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, USE_UNITY_CONTROL_MAP_RESOLUTION_PREF_KEY), ImportSplatControlMapResolution);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_SPLATS_GROUP_PREF_KEY), CreateNewSplatPrototypesGroup);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREES_PREF_KEY), ImportTrees);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREE_INSTANCES_ONLY_KEY), ImportTreeInstancesOnly);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_TREES_GROUP_PREF_KEY), CreateNewTreePrototypesGroup);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_PREF_KEY), ImportGrasses);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_INSTANCES_ONLY_KEY), ImportGrassInstancesOnly);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, NEW_GRASSES_GROUP_PREF_KEY), CreateNewGrassPrototypesGroup);
|
||||
EditorPrefs.SetFloat(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, GRASS_DENSITY), GrassDensity);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DIRECTORY_PREF_KEY), Directory);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 200;
|
||||
DrawInstructionGUI();
|
||||
DrawImportGUI();
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
HandleRepaint();
|
||||
}
|
||||
|
||||
private void HandleRepaint()
|
||||
{
|
||||
//if (Event.current != null)
|
||||
//{
|
||||
// Repaint();
|
||||
//}
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "unity-terrain-importer-instruction";
|
||||
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawImportGUI()
|
||||
{
|
||||
string label = "Import";
|
||||
string id = "unity-terrain-importer-import";
|
||||
|
||||
GEditorCommon.Foldout(label, true, id, () =>
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Terrain", DesTerrain, typeof(GStylizedTerrain), true);
|
||||
EditorGUILayout.ObjectField("Griffin Data", DesData, typeof(GTerrainData), false);
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
SrcTerrain = EditorGUILayout.ObjectField("Unity Terrain", SrcTerrain, typeof(Terrain), true) as Terrain;
|
||||
if (SrcTerrain != null)
|
||||
{
|
||||
SrcData = SrcTerrain.terrainData;
|
||||
}
|
||||
|
||||
GUI.enabled = SrcTerrain == null;
|
||||
SrcData = EditorGUILayout.ObjectField("Unity Terrain Data", SrcData, typeof(TerrainData), true) as TerrainData;
|
||||
GUI.enabled = true;
|
||||
|
||||
if (SrcData != null)
|
||||
{
|
||||
if (SrcTerrain != null && SrcTerrain.terrainData != SrcData)
|
||||
{
|
||||
SrcTerrain = null;
|
||||
}
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
}
|
||||
|
||||
if (SrcData == null)
|
||||
return;
|
||||
}
|
||||
|
||||
ImportGeometry = EditorGUILayout.Toggle("Import Geometry", ImportGeometry);
|
||||
if (ImportGeometry)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
UseUnityTerrainSize = EditorGUILayout.Toggle("Unity Terrain Size", UseUnityTerrainSize);
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ImportSplats = EditorGUILayout.Toggle("Import Splats", ImportSplats);
|
||||
if (ImportSplats)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
ImportSplatsAsAlbedo = EditorGUILayout.Toggle("As Albedo", ImportSplatsAsAlbedo);
|
||||
ImportSplatControlMapResolution = EditorGUILayout.Toggle("Use Unity Resolution", ImportSplatControlMapResolution);
|
||||
ImportSplatControlMapsOnly = EditorGUILayout.Toggle("Control Maps Only", ImportSplatControlMapsOnly);
|
||||
|
||||
if (!ImportSplatControlMapsOnly)
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
CreateNewSplatPrototypesGroup = EditorGUILayout.Toggle("New Splats Group", CreateNewSplatPrototypesGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DesData.Shading.Splats == null ||
|
||||
DesData.Shading.Splats.IsSampleAsset)
|
||||
{
|
||||
CreateNewSplatPrototypesGroup = true;
|
||||
}
|
||||
GUI.enabled = DesData.Shading.Splats != null && !DesData.Shading.Splats.IsSampleAsset;
|
||||
GUIContent newSplatsGroupGUI = new GUIContent("New Splats Group", "There is no splats group assigned or sample splats group is in used.");
|
||||
CreateNewSplatPrototypesGroup = EditorGUILayout.Toggle(newSplatsGroupGUI, CreateNewSplatPrototypesGroup);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ImportTrees = EditorGUILayout.Toggle("Import Trees", ImportTrees);
|
||||
if (ImportTrees)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
ImportTreeInstancesOnly = EditorGUILayout.Toggle("Tree Instances Only", ImportTreeInstancesOnly);
|
||||
|
||||
if (!ImportTreeInstancesOnly)
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
CreateNewTreePrototypesGroup = EditorGUILayout.Toggle("New Trees Group", CreateNewTreePrototypesGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DesData.Foliage.Trees == null ||
|
||||
DesData.Foliage.Trees.IsSampleAsset)
|
||||
{
|
||||
CreateNewTreePrototypesGroup = true;
|
||||
}
|
||||
GUI.enabled = DesData.Foliage.Trees != null && !DesData.Foliage.Trees.IsSampleAsset;
|
||||
GUIContent newTreeGroupGUI = new GUIContent("New Trees Group", "There is no trees group assigned or sample trees group is in used.");
|
||||
CreateNewTreePrototypesGroup = EditorGUILayout.Toggle(newTreeGroupGUI, CreateNewTreePrototypesGroup);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ImportGrasses = EditorGUILayout.Toggle("Import Grasses & Details", ImportGrasses);
|
||||
if (ImportGrasses)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
ImportGrassInstancesOnly = EditorGUILayout.Toggle("Grass Instances Only", ImportGrassInstancesOnly);
|
||||
|
||||
if (!ImportGrassInstancesOnly)
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
CreateNewGrassPrototypesGroup = EditorGUILayout.Toggle("New Grasses Group", CreateNewGrassPrototypesGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DesData.Foliage.Grasses == null ||
|
||||
DesData.Foliage.Grasses.IsSampleAsset)
|
||||
{
|
||||
CreateNewGrassPrototypesGroup = true;
|
||||
}
|
||||
GUI.enabled = DesData.Foliage.Grasses != null && !DesData.Foliage.Grasses.IsSampleAsset;
|
||||
GUIContent newGrassGroupGUI = new GUIContent("New Grasses Group", "There is no grasses group assigned or sample grasses group is in used.");
|
||||
CreateNewGrassPrototypesGroup = EditorGUILayout.Toggle(newGrassGroupGUI, CreateNewGrassPrototypesGroup);
|
||||
GUI.enabled = true;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GrassDensity = EditorGUILayout.Slider("Density", GrassDensity, 0f, 1f);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
if (BulkImport)
|
||||
{
|
||||
string dir = Directory;
|
||||
GEditorCommon.BrowseFolder("Directory", ref dir);
|
||||
Directory = dir;
|
||||
|
||||
EditorGUILayout.LabelField("File Name Convention", "TerrainData_<Polaris Terrain Data Id>", GEditorCommon.WordWrapItalicLabel);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Import"))
|
||||
{
|
||||
Import();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Import()
|
||||
{
|
||||
if (BulkImport)
|
||||
{
|
||||
DoBulkImport();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoImport();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoImport()
|
||||
{
|
||||
if (DesTerrain != null)
|
||||
{
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, DesTerrain, GCommon.AllResourceFlags);
|
||||
}
|
||||
|
||||
GUnityTerrainDataImporter importer = new GUnityTerrainDataImporter();
|
||||
importer.SrcTerrain = SrcTerrain;
|
||||
importer.SrcData = SrcData;
|
||||
importer.DesData = DesData;
|
||||
importer.DesTerrain = DesTerrain;
|
||||
importer.ImportGeometry = ImportGeometry;
|
||||
importer.UseUnityTerrainSize = UseUnityTerrainSize;
|
||||
importer.ImportSplats = ImportSplats;
|
||||
importer.ImportSplatsAsAlbedo = ImportSplatsAsAlbedo;
|
||||
importer.ImportSplatControlMapsOnly = ImportSplatControlMapsOnly;
|
||||
importer.ImportSplatControlMapResolution = ImportSplatControlMapResolution;
|
||||
importer.CreateNewSplatPrototypesGroup = CreateNewSplatPrototypesGroup;
|
||||
importer.ImportTrees = ImportTrees;
|
||||
importer.ImportTreeInstancesOnly = ImportTreeInstancesOnly;
|
||||
importer.CreateNewTreePrototypesGroup = CreateNewTreePrototypesGroup;
|
||||
importer.ImportGrasses = ImportGrasses;
|
||||
importer.ImportGrassInstancesOnly = ImportGrassInstancesOnly;
|
||||
importer.CreateNewGrassPrototypesGroup = CreateNewGrassPrototypesGroup;
|
||||
importer.GrassDensity = GrassDensity;
|
||||
importer.Import();
|
||||
|
||||
if (DesTerrain != null)
|
||||
{
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, DesTerrain, GCommon.AllResourceFlags);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoBulkImport()
|
||||
{
|
||||
string[] guid = AssetDatabase.FindAssets("t:TerrainData", new string[] { Directory });
|
||||
List<TerrainData> terrainDatas = new List<TerrainData>();
|
||||
for (int i = 0; i < guid.Length; ++i)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid[i]);
|
||||
TerrainData data = AssetDatabase.LoadAssetAtPath<TerrainData>(path);
|
||||
terrainDatas.Add(data);
|
||||
}
|
||||
|
||||
GCommon.ForEachTerrain(
|
||||
BulkImportGroupId,
|
||||
(t) =>
|
||||
{
|
||||
if (t == null || t.TerrainData == null)
|
||||
return;
|
||||
TerrainData srcData = terrainDatas.Find(d => d.name.StartsWith("TerrainData") && d.name.EndsWith(t.TerrainData.Id));
|
||||
if (srcData == null)
|
||||
return;
|
||||
|
||||
GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
|
||||
|
||||
GUnityTerrainDataImporter importer = new GUnityTerrainDataImporter();
|
||||
importer.SrcTerrain = null;
|
||||
importer.SrcData = srcData;
|
||||
importer.DesData = t.TerrainData;
|
||||
importer.DesTerrain = t;
|
||||
importer.ImportGeometry = ImportGeometry;
|
||||
importer.UseUnityTerrainSize = UseUnityTerrainSize;
|
||||
|
||||
importer.ImportSplats = ImportSplats;
|
||||
importer.ImportSplatsAsAlbedo = ImportSplatsAsAlbedo;
|
||||
importer.ImportSplatControlMapResolution = ImportSplatControlMapResolution;
|
||||
importer.ImportSplatControlMapsOnly = ImportSplatControlMapsOnly;
|
||||
bool createNewSplatGroup = CreateNewSplatPrototypesGroup;
|
||||
if (t.TerrainData.Shading.Splats == null ||
|
||||
t.TerrainData.Shading.Splats.IsSampleAsset)
|
||||
{
|
||||
createNewSplatGroup = true;
|
||||
}
|
||||
importer.CreateNewSplatPrototypesGroup = createNewSplatGroup;
|
||||
|
||||
importer.ImportTrees = ImportTrees;
|
||||
importer.ImportTreeInstancesOnly = ImportTreeInstancesOnly;
|
||||
bool createNewTreeGroup = CreateNewTreePrototypesGroup;
|
||||
if (t.TerrainData.Foliage.Trees == null ||
|
||||
t.TerrainData.Foliage.Trees.IsSampleAsset)
|
||||
{
|
||||
createNewTreeGroup = true;
|
||||
}
|
||||
importer.CreateNewTreePrototypesGroup = createNewTreeGroup;
|
||||
|
||||
importer.ImportGrasses = ImportGrasses;
|
||||
importer.ImportGrassInstancesOnly = ImportGrassInstancesOnly;
|
||||
bool createNewGrassGroup = CreateNewGrassPrototypesGroup;
|
||||
if (t.TerrainData.Foliage.Grasses == null ||
|
||||
t.TerrainData.Foliage.Grasses.IsSampleAsset)
|
||||
{
|
||||
createNewGrassGroup = true;
|
||||
}
|
||||
importer.CreateNewGrassPrototypesGroup = createNewGrassGroup;
|
||||
|
||||
GrassDensity = 1;
|
||||
importer.GrassDensity = GrassDensity;
|
||||
importer.Import();
|
||||
|
||||
GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
|
||||
});
|
||||
|
||||
GStylizedTerrain.MatchEdges(BulkImportGroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a5d0ce002d0ea74785e8dfea7d3d6e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,158 @@
|
||||
#if GRIFFIN
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using GAlbedoUsage = Pinwheel.Griffin.DataTool.GUnityTerrainGroupConverter.GAlbedoUsage;
|
||||
|
||||
namespace Pinwheel.Griffin.DataTool
|
||||
{
|
||||
public class GUnityTerrainGroupConverterWindow : EditorWindow
|
||||
{
|
||||
public GameObject Root { get; set; }
|
||||
public GTerrainData DataTemplate { get; set; }
|
||||
public bool ImportGeometry { get; set; }
|
||||
public bool ImportSplats { get; set; }
|
||||
public bool ImportSplatsAsAlbedo { get; set; }
|
||||
public GAlbedoUsage AlbedoUsage { get; set; }
|
||||
public bool ImportTrees { get; set; }
|
||||
public bool ImportGrasses { get; set; }
|
||||
public string DataDirectory { get; set; }
|
||||
|
||||
private const string PREF_PREFIX = "unity-terrain-converter";
|
||||
private const string DATA_TEMPLATE_PREF_KEY = "data-template";
|
||||
private const string IMPORT_GEOMETRY_PREF_KEY = "import-geometry";
|
||||
private const string IMPORT_SPLATS_PREF_KEY = "import-splats";
|
||||
private const string IMPORT_SPLATS_AS_ALBEDO_PREF_KEY = "import-splats-as-albedo";
|
||||
private const string ALBEDO_USAGE_PREF_KEY = "albedo-usage";
|
||||
private const string IMPORT_TREES_PREF_KEY = "import-trees";
|
||||
private const string IMPORT_GRASS_PREF_KEY = "import-grasses";
|
||||
private const string DATA_DIRECTORY_PREF_KEY = "data-directory";
|
||||
|
||||
private const string INSTRUCTION =
|
||||
"Convert all Unity Terrain under Root game object to Stylized Terrain. Generated data will be stored in Data Directory folder.";
|
||||
|
||||
public static GUnityTerrainGroupConverterWindow ShowWindow()
|
||||
{
|
||||
GUnityTerrainGroupConverterWindow window = ScriptableObject.CreateInstance<GUnityTerrainGroupConverterWindow>();
|
||||
window.titleContent = new GUIContent("Terrain Group Converter");
|
||||
window.ShowUtility();
|
||||
return window;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ImportGeometry = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GEOMETRY_PREF_KEY), true);
|
||||
ImportSplats = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_PREF_KEY), true);
|
||||
ImportSplatsAsAlbedo = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_AS_ALBEDO_PREF_KEY), false);
|
||||
AlbedoUsage = (GAlbedoUsage)EditorPrefs.GetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, ALBEDO_USAGE_PREF_KEY), 0);
|
||||
ImportTrees = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREES_PREF_KEY), true);
|
||||
ImportGrasses = EditorPrefs.GetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_PREF_KEY), false);
|
||||
DataDirectory = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREF_KEY), "Assets/Polaris Exported/");
|
||||
|
||||
string dataTemplatePath = EditorPrefs.GetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_TEMPLATE_PREF_KEY), null);
|
||||
if (!string.IsNullOrEmpty(dataTemplatePath))
|
||||
{
|
||||
DataTemplate = AssetDatabase.LoadAssetAtPath<GTerrainData>(dataTemplatePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GEOMETRY_PREF_KEY), ImportGeometry);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_PREF_KEY), ImportSplats);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_SPLATS_AS_ALBEDO_PREF_KEY), ImportSplatsAsAlbedo);
|
||||
EditorPrefs.SetInt(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, ALBEDO_USAGE_PREF_KEY), (int)AlbedoUsage);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_TREES_PREF_KEY), ImportTrees);
|
||||
EditorPrefs.SetBool(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, IMPORT_GRASS_PREF_KEY), ImportGrasses);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_DIRECTORY_PREF_KEY), DataDirectory);
|
||||
|
||||
if (DataTemplate != null && AssetDatabase.Contains(DataTemplate) && EditorUtility.IsPersistent(DataTemplate))
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(DataTemplate);
|
||||
EditorPrefs.SetString(GEditorCommon.GetProjectRelatedEditorPrefsKey(PREF_PREFIX, DATA_TEMPLATE_PREF_KEY), path);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 200;
|
||||
DrawInstructionGUI();
|
||||
DrawConvertGUI();
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
HandleRepaint();
|
||||
}
|
||||
|
||||
private void HandleRepaint()
|
||||
{
|
||||
if (Event.current != null)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawInstructionGUI()
|
||||
{
|
||||
string label = "Instruction";
|
||||
string id = "terrain-converter-instruction";
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
EditorGUILayout.LabelField(INSTRUCTION, GEditorCommon.WordWrapItalicLabel);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawConvertGUI()
|
||||
{
|
||||
string label = "Convert";
|
||||
string id = "terrain-converter-convert";
|
||||
GEditorCommon.Foldout(label, false, id, () =>
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Root", Root, typeof(GameObject), true);
|
||||
GUI.enabled = true;
|
||||
|
||||
DataTemplate = EditorGUILayout.ObjectField("Data Template", DataTemplate, typeof(GTerrainData), false) as GTerrainData;
|
||||
ImportGeometry = EditorGUILayout.Toggle("Import Geometry", ImportGeometry);
|
||||
ImportSplats = EditorGUILayout.Toggle("Import Splats", ImportSplats);
|
||||
if (ImportSplats)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
ImportSplatsAsAlbedo = EditorGUILayout.Toggle("As Albedo", ImportSplatsAsAlbedo);
|
||||
bool hasNoTemplateMaterial = DataTemplate == null || DataTemplate.Shading.CustomMaterial == null;
|
||||
if (ImportSplatsAsAlbedo && hasNoTemplateMaterial)
|
||||
{
|
||||
AlbedoUsage = (GAlbedoUsage)EditorGUILayout.EnumPopup("Albedo Usage", AlbedoUsage);
|
||||
}
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
ImportTrees = EditorGUILayout.Toggle("Import Trees", ImportTrees);
|
||||
ImportGrasses = EditorGUILayout.Toggle("Import Grasses & Details", ImportGrasses);
|
||||
string dir = DataDirectory;
|
||||
GEditorCommon.BrowseFolder("Data Directory", ref dir);
|
||||
DataDirectory = dir;
|
||||
|
||||
if (GUILayout.Button("Convert"))
|
||||
{
|
||||
Convert();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Convert()
|
||||
{
|
||||
GUnityTerrainGroupConverter converter = new GUnityTerrainGroupConverter();
|
||||
converter.Root = Root;
|
||||
converter.DataTemplate = DataTemplate;
|
||||
converter.ImportGeometry = ImportGeometry;
|
||||
converter.ImportSplats = ImportSplats;
|
||||
converter.ImportSplatsAsAlbedo = ImportSplatsAsAlbedo;
|
||||
converter.AlbedoUsage = AlbedoUsage;
|
||||
converter.ImportTrees = ImportTrees;
|
||||
converter.ImportGrasses = ImportGrasses;
|
||||
converter.DataDirectory = DataDirectory;
|
||||
|
||||
converter.Convert();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c0b06d840118d04488ec0a89ddcc997
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user