Preparation for release. Comments, fixes, README
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using PSXSplash.RuntimeCode;
|
||||
using SplashEdit.RuntimeCode;
|
||||
|
||||
[CustomEditor(typeof(PSXSceneExporter))]
|
||||
public class PSXSceneExporterEditor : Editor
|
||||
namespace SplashEdit.EditorCode
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
[CustomEditor(typeof(PSXSceneExporter))]
|
||||
public class PSXSceneExporterEditor : Editor
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
PSXSceneExporter comp = (PSXSceneExporter)target;
|
||||
if (GUILayout.Button("Export"))
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
comp.Export();
|
||||
}
|
||||
DrawDefaultInspector();
|
||||
|
||||
PSXSceneExporter comp = (PSXSceneExporter)target;
|
||||
if (GUILayout.Button("Export"))
|
||||
{
|
||||
comp.Export();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,185 +1,187 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using PSXSplash.RuntimeCode;
|
||||
using SplashEdit.RuntimeCode;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class QuantizedPreviewWindow : EditorWindow
|
||||
namespace SplashEdit.EditorCode
|
||||
{
|
||||
private Texture2D originalTexture;
|
||||
private Texture2D quantizedTexture;
|
||||
private Texture2D vramTexture; // New VRAM Texture
|
||||
private List<VRAMPixel> clut; // Changed to 1D array
|
||||
private ushort[] indexedPixelData; // New field for indexed pixel data
|
||||
private PSXBPP bpp;
|
||||
private readonly int previewSize = 256;
|
||||
|
||||
[MenuItem("Window/Quantized Preview")]
|
||||
public static void ShowWindow()
|
||||
public class QuantizedPreviewWindow : EditorWindow
|
||||
{
|
||||
QuantizedPreviewWindow win = GetWindow<QuantizedPreviewWindow>("Quantized Preview");
|
||||
win.minSize = new Vector2(800, 700);
|
||||
}
|
||||
private Texture2D originalTexture;
|
||||
private Texture2D quantizedTexture;
|
||||
private Texture2D vramTexture; // VRAM representation of the texture
|
||||
private List<VRAMPixel> clut; // Color Lookup Table (CLUT), stored as a 1D list
|
||||
private ushort[] indexedPixelData; // Indexed pixel data for VRAM storage
|
||||
private PSXBPP bpp;
|
||||
private readonly int previewSize = 256;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Quantized Preview", EditorStyles.boldLabel);
|
||||
|
||||
originalTexture = (Texture2D)EditorGUILayout.ObjectField("Original Texture", originalTexture, typeof(Texture2D), false);
|
||||
|
||||
|
||||
bpp = (PSXBPP)EditorGUILayout.EnumPopup("Bit Depth", bpp);
|
||||
|
||||
|
||||
if (GUILayout.Button("Generate Quantized Preview") && originalTexture != null)
|
||||
[MenuItem("Window/Quantized Preview")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GenerateQuantizedPreview();
|
||||
// Creates and displays the window
|
||||
QuantizedPreviewWindow win = GetWindow<QuantizedPreviewWindow>("Quantized Preview");
|
||||
win.minSize = new Vector2(800, 700);
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (originalTexture != null)
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("Original Texture");
|
||||
DrawTexturePreview(originalTexture, previewSize, false);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.Label("Quantized Preview", EditorStyles.boldLabel);
|
||||
|
||||
if (vramTexture != null)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("VRAM View (Indexed Data as 16bpp)");
|
||||
DrawTexturePreview(vramTexture, previewSize);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
// Texture input field
|
||||
originalTexture = (Texture2D)EditorGUILayout.ObjectField("Original Texture", originalTexture, typeof(Texture2D), false);
|
||||
|
||||
if (quantizedTexture != null)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("Quantized Texture");
|
||||
DrawTexturePreview(quantizedTexture, previewSize);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
// Dropdown for bit depth selection
|
||||
bpp = (PSXBPP)EditorGUILayout.EnumPopup("Bit Depth", bpp);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (clut != null)
|
||||
{
|
||||
GUILayout.Label("Color Lookup Table (CLUT)");
|
||||
DrawCLUT();
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
if (indexedPixelData != null)
|
||||
{
|
||||
if (GUILayout.Button("Export texute data"))
|
||||
// Button to generate the quantized preview
|
||||
if (GUILayout.Button("Generate Quantized Preview") && originalTexture != null)
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel(
|
||||
"Save texture data",
|
||||
"",
|
||||
"pixel_data",
|
||||
"bin"
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
using (BinaryWriter writer = new BinaryWriter(fileStream))
|
||||
{
|
||||
foreach (ushort value in indexedPixelData)
|
||||
{
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
GenerateQuantizedPreview();
|
||||
}
|
||||
}
|
||||
|
||||
if (clut != null)
|
||||
{
|
||||
if (GUILayout.Button("Export clut data"))
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel(
|
||||
"Save clut data",
|
||||
"",
|
||||
"clut_data",
|
||||
"bin"
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
using (BinaryWriter writer = new BinaryWriter(fileStream))
|
||||
{
|
||||
foreach (VRAMPixel value in clut)
|
||||
{
|
||||
writer.Write(value.Pack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateQuantizedPreview()
|
||||
{
|
||||
|
||||
PSXTexture2D psxTex = PSXTexture2D.CreateFromTexture2D(originalTexture, bpp);
|
||||
|
||||
quantizedTexture = psxTex.GeneratePreview();
|
||||
vramTexture = psxTex.GenerateVramPreview();
|
||||
clut = psxTex.ColorPalette;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void DrawTexturePreview(Texture2D texture, int size, bool flipY = true)
|
||||
{
|
||||
Rect rect = GUILayoutUtility.GetRect(size, size, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawPreviewTexture(rect, texture, null, ScaleMode.ScaleToFit, 0, 0, ColorWriteMask.All);
|
||||
}
|
||||
|
||||
|
||||
private void DrawCLUT()
|
||||
{
|
||||
if (clut == null) return;
|
||||
|
||||
int swatchSize = 20;
|
||||
int maxColorsPerRow = 40;
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
int totalColors = clut.Count;
|
||||
int totalRows = Mathf.CeilToInt((float)totalColors / maxColorsPerRow);
|
||||
|
||||
for (int row = 0; row < totalRows; row++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
int colorsInRow = Mathf.Min(maxColorsPerRow, totalColors - row * maxColorsPerRow);
|
||||
|
||||
for (int col = 0; col < colorsInRow; col++)
|
||||
// Display the original texture
|
||||
if (originalTexture != null)
|
||||
{
|
||||
int index = row * maxColorsPerRow + col;
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("Original Texture");
|
||||
DrawTexturePreview(originalTexture, previewSize, false);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
Vector3 color = new Vector3(
|
||||
clut[index].R / 31.0f, // Red: bits 0–4
|
||||
clut[index].G / 31.0f, // Green: bits 5–9
|
||||
clut[index].B / 31.0f // Blue: bits 10–14
|
||||
);
|
||||
// Display the VRAM view of the texture
|
||||
if (vramTexture != null)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("VRAM View (Indexed Data as 16bpp)");
|
||||
DrawTexturePreview(vramTexture, previewSize);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
Rect rect = GUILayoutUtility.GetRect(swatchSize, swatchSize, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawRect(rect, new Color(color.x, color.y, color.z));
|
||||
// Display the quantized texture
|
||||
if (quantizedTexture != null)
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("Quantized Texture");
|
||||
DrawTexturePreview(quantizedTexture, previewSize);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Display the Color Lookup Table (CLUT)
|
||||
if (clut != null)
|
||||
{
|
||||
GUILayout.Label("Color Lookup Table (CLUT)");
|
||||
DrawCLUT();
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
// Export indexed pixel data
|
||||
if (indexedPixelData != null)
|
||||
{
|
||||
if (GUILayout.Button("Export texture data"))
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Save texture data", "", "pixel_data", "bin");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
using (BinaryWriter writer = new BinaryWriter(fileStream))
|
||||
{
|
||||
foreach (ushort value in indexedPixelData)
|
||||
{
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export CLUT data
|
||||
if (clut != null)
|
||||
{
|
||||
if (GUILayout.Button("Export CLUT data"))
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Save CLUT data", "", "clut_data", "bin");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
using (BinaryWriter writer = new BinaryWriter(fileStream))
|
||||
{
|
||||
foreach (VRAMPixel value in clut)
|
||||
{
|
||||
writer.Write(value.Pack()); // Convert VRAMPixel data into a binary format
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateQuantizedPreview()
|
||||
{
|
||||
// Converts the texture using PSXTexture2D and stores the processed data
|
||||
PSXTexture2D psxTex = PSXTexture2D.CreateFromTexture2D(originalTexture, bpp);
|
||||
|
||||
// Generate the quantized texture preview
|
||||
quantizedTexture = psxTex.GeneratePreview();
|
||||
|
||||
// Generate the VRAM representation of the texture
|
||||
vramTexture = psxTex.GenerateVramPreview();
|
||||
|
||||
// Store the Color Lookup Table (CLUT)
|
||||
clut = psxTex.ColorPalette;
|
||||
}
|
||||
|
||||
private void DrawTexturePreview(Texture2D texture, int size, bool flipY = true)
|
||||
{
|
||||
// Renders a texture preview within the editor window
|
||||
Rect rect = GUILayoutUtility.GetRect(size, size, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawPreviewTexture(rect, texture, null, ScaleMode.ScaleToFit, 0, 0, ColorWriteMask.All);
|
||||
}
|
||||
|
||||
private void DrawCLUT()
|
||||
{
|
||||
if (clut == null) return;
|
||||
|
||||
int swatchSize = 20;
|
||||
int maxColorsPerRow = 40; // Number of colors displayed per row
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
int totalColors = clut.Count;
|
||||
int totalRows = Mathf.CeilToInt((float)totalColors / maxColorsPerRow);
|
||||
|
||||
for (int row = 0; row < totalRows; row++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
int colorsInRow = Mathf.Min(maxColorsPerRow, totalColors - row * maxColorsPerRow);
|
||||
|
||||
for (int col = 0; col < colorsInRow; col++)
|
||||
{
|
||||
int index = row * maxColorsPerRow + col;
|
||||
|
||||
// Convert the CLUT colors from 5-bit to float values (0-1 range)
|
||||
Vector3 color = new Vector3(
|
||||
clut[index].R / 31.0f, // Red: bits 0–4
|
||||
clut[index].G / 31.0f, // Green: bits 5–9
|
||||
clut[index].B / 31.0f // Blue: bits 10–14
|
||||
);
|
||||
|
||||
// Create a small color preview box for each color in the CLUT
|
||||
Rect rect = GUILayoutUtility.GetRect(swatchSize, swatchSize, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawRect(rect, new Color(color.x, color.y, color.z));
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using PSXSplash.RuntimeCode;
|
||||
using SplashEdit.RuntimeCode;
|
||||
using Unity.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class VRAMEditorWindow : EditorWindow
|
||||
|
||||
namespace SplashEdit.EditorCode
|
||||
{
|
||||
|
||||
private const int VramWidth = 1024;
|
||||
private const int VramHeight = 512;
|
||||
private List<ProhibitedArea> prohibitedAreas = new List<ProhibitedArea>();
|
||||
private Vector2 scrollPosition;
|
||||
private Texture2D vramImage;
|
||||
private Vector2 selectedResolution = new Vector2(320, 240);
|
||||
private bool dualBuffering = true;
|
||||
private bool verticalLayout = true;
|
||||
private Color bufferColor1 = new Color(1, 0, 0, 0.5f);
|
||||
private Color bufferColor2 = new Color(0, 1, 0, 0.5f);
|
||||
private Color prohibitedColor = new Color(1, 0, 0, 0.3f);
|
||||
|
||||
private static string _psxDataPath = "Assets/PSXData.asset";
|
||||
private PSXData _psxData;
|
||||
|
||||
private static readonly Vector2[] resolutions =
|
||||
public class VRAMEditorWindow : EditorWindow
|
||||
{
|
||||
private const int VramWidth = 1024;
|
||||
private const int VramHeight = 512;
|
||||
private List<ProhibitedArea> prohibitedAreas = new List<ProhibitedArea>();
|
||||
private Vector2 scrollPosition;
|
||||
private Texture2D vramImage;
|
||||
private Vector2 selectedResolution = new Vector2(320, 240);
|
||||
private bool dualBuffering = true;
|
||||
private bool verticalLayout = true;
|
||||
private Color bufferColor1 = new Color(1, 0, 0, 0.5f);
|
||||
private Color bufferColor2 = new Color(0, 1, 0, 0.5f);
|
||||
private Color prohibitedColor = new Color(1, 0, 0, 0.3f);
|
||||
|
||||
private static string _psxDataPath = "Assets/PSXData.asset";
|
||||
private PSXData _psxData;
|
||||
|
||||
private static readonly Vector2[] resolutions =
|
||||
{
|
||||
new Vector2(256, 240), new Vector2(256, 480),
|
||||
new Vector2(320, 240), new Vector2(320, 480),
|
||||
new Vector2(368, 240), new Vector2(368, 480),
|
||||
@@ -33,232 +35,270 @@ public class VRAMEditorWindow : EditorWindow
|
||||
new Vector2(640, 240), new Vector2(640, 480)
|
||||
};
|
||||
|
||||
[MenuItem("Window/VRAM Editor")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<VRAMEditorWindow>("VRAM Editor");
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
vramImage = new Texture2D(VramWidth, VramHeight);
|
||||
NativeArray<Color32> blackPixels = new NativeArray<Color32>(VramWidth * VramHeight, Allocator.Temp);
|
||||
vramImage.SetPixelData(blackPixels, 0);
|
||||
vramImage.Apply();
|
||||
blackPixels.Dispose();
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
public static void PasteTexture(Texture2D baseTexture, Texture2D overlayTexture, int posX, int posY)
|
||||
{
|
||||
if (baseTexture == null || overlayTexture == null)
|
||||
[MenuItem("Window/VRAM Editor")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
Debug.LogError("Textures cannot be null!");
|
||||
return;
|
||||
VRAMEditorWindow window = GetWindow<VRAMEditorWindow>("VRAM Editor");
|
||||
// Set minimum window dimensions.
|
||||
window.minSize = new Vector2(1600, 600);
|
||||
}
|
||||
|
||||
Color[] overlayPixels = overlayTexture.GetPixels();
|
||||
Color[] basePixels = baseTexture.GetPixels();
|
||||
|
||||
int baseWidth = baseTexture.width;
|
||||
int baseHeight = baseTexture.height;
|
||||
int overlayWidth = overlayTexture.width;
|
||||
int overlayHeight = overlayTexture.height;
|
||||
|
||||
for (int y = 0; y < overlayHeight; y++)
|
||||
private void OnEnable()
|
||||
{
|
||||
for (int x = 0; x < overlayWidth; x++)
|
||||
{
|
||||
int baseX = posX + x;
|
||||
int baseY = posY + y;
|
||||
if (baseX >= 0 && baseX < baseWidth && baseY >= 0 && baseY < baseHeight)
|
||||
{
|
||||
int baseIndex = baseY * baseWidth + baseX;
|
||||
int overlayIndex = y * overlayWidth + x;
|
||||
// Initialize VRAM texture with black pixels.
|
||||
vramImage = new Texture2D(VramWidth, VramHeight);
|
||||
NativeArray<Color32> blackPixels = new NativeArray<Color32>(VramWidth * VramHeight, Allocator.Temp);
|
||||
vramImage.SetPixelData(blackPixels, 0);
|
||||
vramImage.Apply();
|
||||
blackPixels.Dispose();
|
||||
|
||||
basePixels[baseIndex] = overlayPixels[overlayIndex];
|
||||
// Ensure minimum window size is applied.
|
||||
this.minSize = new Vector2(800, 600);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pastes an overlay texture onto a base texture at the specified position.
|
||||
/// </summary>
|
||||
public static void PasteTexture(Texture2D baseTexture, Texture2D overlayTexture, int posX, int posY)
|
||||
{
|
||||
if (baseTexture == null || overlayTexture == null)
|
||||
{
|
||||
Debug.LogError("Textures cannot be null!");
|
||||
return;
|
||||
}
|
||||
|
||||
Color[] overlayPixels = overlayTexture.GetPixels();
|
||||
Color[] basePixels = baseTexture.GetPixels();
|
||||
|
||||
int baseWidth = baseTexture.width;
|
||||
int baseHeight = baseTexture.height;
|
||||
int overlayWidth = overlayTexture.width;
|
||||
int overlayHeight = overlayTexture.height;
|
||||
|
||||
// Copy each overlay pixel into the base texture if within bounds.
|
||||
for (int y = 0; y < overlayHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < overlayWidth; x++)
|
||||
{
|
||||
int baseX = posX + x;
|
||||
int baseY = posY + y;
|
||||
if (baseX >= 0 && baseX < baseWidth && baseY >= 0 && baseY < baseHeight)
|
||||
{
|
||||
int baseIndex = baseY * baseWidth + baseX;
|
||||
int overlayIndex = y * overlayWidth + x;
|
||||
basePixels[baseIndex] = overlayPixels[overlayIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
baseTexture.SetPixels(basePixels);
|
||||
baseTexture.Apply();
|
||||
}
|
||||
|
||||
baseTexture.SetPixels(basePixels);
|
||||
baseTexture.Apply();
|
||||
}
|
||||
private void PackTextures()
|
||||
{
|
||||
|
||||
vramImage = new Texture2D(VramWidth, VramHeight);
|
||||
NativeArray<Color32> blackPixels = new NativeArray<Color32>(VramWidth * VramHeight, Allocator.Temp);
|
||||
vramImage.SetPixelData(blackPixels, 0);
|
||||
vramImage.Apply();
|
||||
blackPixels.Dispose();
|
||||
|
||||
PSXObjectExporter[] objects = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
||||
foreach (PSXObjectExporter exp in objects)
|
||||
/// <summary>
|
||||
/// Packs PSX textures into VRAM, rebuilds the VRAM texture and writes binary data to an output file.
|
||||
/// </summary>
|
||||
private void PackTextures()
|
||||
{
|
||||
exp.CreatePSXTexture2D();
|
||||
}
|
||||
// Reinitialize VRAM texture with black pixels.
|
||||
vramImage = new Texture2D(VramWidth, VramHeight);
|
||||
NativeArray<Color32> blackPixels = new NativeArray<Color32>(VramWidth * VramHeight, Allocator.Temp);
|
||||
vramImage.SetPixelData(blackPixels, 0);
|
||||
vramImage.Apply();
|
||||
blackPixels.Dispose();
|
||||
|
||||
Rect buffer1 = new Rect(0, 0, selectedResolution.x, selectedResolution.y);
|
||||
Rect buffer2 = verticalLayout ? new Rect(0, 256, selectedResolution.x, selectedResolution.y)
|
||||
: new Rect(selectedResolution.x, 0, selectedResolution.x, selectedResolution.y);
|
||||
|
||||
|
||||
List<Rect> framebuffers = new List<Rect> { buffer1 };
|
||||
if (dualBuffering)
|
||||
{
|
||||
framebuffers.Add(buffer2);
|
||||
}
|
||||
|
||||
VRAMPacker tp = new VRAMPacker(framebuffers, prohibitedAreas);
|
||||
var packed = tp.PackTexturesIntoVRAM(objects);
|
||||
|
||||
|
||||
for (int y = 0; y < VramHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < VramWidth; x++)
|
||||
// Retrieve all PSXObjectExporter objects and create their PSX textures.
|
||||
PSXObjectExporter[] objects = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
||||
foreach (PSXObjectExporter exp in objects)
|
||||
{
|
||||
vramImage.SetPixel(x, VramHeight - y - 1, packed._vramPixels[x, y].GetUnityColor());
|
||||
exp.CreatePSXTexture2D();
|
||||
}
|
||||
}
|
||||
vramImage.Apply();
|
||||
|
||||
string path = EditorUtility.SaveFilePanel("Select Output File", "", "output", "bin");
|
||||
// Define framebuffer regions based on selected resolution and layout.
|
||||
Rect buffer1 = new Rect(0, 0, selectedResolution.x, selectedResolution.y);
|
||||
Rect buffer2 = verticalLayout ? new Rect(0, 256, selectedResolution.x, selectedResolution.y)
|
||||
: new Rect(selectedResolution.x, 0, selectedResolution.x, selectedResolution.y);
|
||||
|
||||
using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)))
|
||||
{
|
||||
List<Rect> framebuffers = new List<Rect> { buffer1 };
|
||||
if (dualBuffering)
|
||||
{
|
||||
framebuffers.Add(buffer2);
|
||||
}
|
||||
|
||||
// Pack textures into VRAM using the VRAMPacker.
|
||||
VRAMPacker tp = new VRAMPacker(framebuffers, prohibitedAreas);
|
||||
var packed = tp.PackTexturesIntoVRAM(objects);
|
||||
|
||||
// Copy packed VRAM pixel data into the texture.
|
||||
for (int y = 0; y < VramHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < VramWidth; x++)
|
||||
{
|
||||
writer.Write(packed._vramPixels[x, y].Pack());
|
||||
vramImage.SetPixel(x, VramHeight - y - 1, packed._vramPixels[x, y].GetUnityColor());
|
||||
}
|
||||
}
|
||||
vramImage.Apply();
|
||||
|
||||
// Prompt the user to select a file location and save the VRAM data.
|
||||
string path = EditorUtility.SaveFilePanel("Select Output File", "", "output", "bin");
|
||||
using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)))
|
||||
{
|
||||
for (int y = 0; y < VramHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < VramWidth; x++)
|
||||
{
|
||||
writer.Write(packed._vramPixels[x, y].Pack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("VRAM Editor", EditorStyles.boldLabel);
|
||||
|
||||
selectedResolution = resolutions[EditorGUILayout.Popup("Resolution", System.Array.IndexOf(resolutions, selectedResolution),
|
||||
new string[] { "256x240", "256x480", "320x240", "320x480", "368x240", "368x480", "512x240", "512x480", "640x240", "640x480" })];
|
||||
|
||||
bool canDBHorizontal = selectedResolution[0] * 2 <= 1024;
|
||||
bool canDBVertical = selectedResolution[1] * 2 <= 512;
|
||||
|
||||
if (canDBHorizontal || canDBVertical)
|
||||
private void OnGUI()
|
||||
{
|
||||
dualBuffering = EditorGUILayout.Toggle("Dual Buffering", dualBuffering);
|
||||
}
|
||||
else { dualBuffering = false; }
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Label("VRAM Editor", EditorStyles.boldLabel);
|
||||
|
||||
if (canDBVertical && canDBHorizontal)
|
||||
{
|
||||
verticalLayout = EditorGUILayout.Toggle("Vertical", verticalLayout);
|
||||
}
|
||||
else if (canDBVertical) { verticalLayout = true; }
|
||||
else
|
||||
{
|
||||
verticalLayout = false;
|
||||
}
|
||||
// Dropdown for resolution selection.
|
||||
selectedResolution = resolutions[EditorGUILayout.Popup("Resolution", System.Array.IndexOf(resolutions, selectedResolution),
|
||||
new string[] { "256x240", "256x480", "320x240", "320x480", "368x240", "368x480", "512x240", "512x480", "640x240", "640x480" })];
|
||||
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label("Prohibited areas", EditorStyles.boldLabel);
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.MaxHeight(150f));
|
||||
// Check resolution constraints for dual buffering.
|
||||
bool canDBHorizontal = selectedResolution[0] * 2 <= 1024;
|
||||
bool canDBVertical = selectedResolution[1] * 2 <= 512;
|
||||
|
||||
for (int i = 0; i < prohibitedAreas.Count; i++)
|
||||
{
|
||||
var area = prohibitedAreas[i];
|
||||
|
||||
area.X = EditorGUILayout.IntField("X", area.X);
|
||||
area.Y = EditorGUILayout.IntField("Y", area.Y);
|
||||
area.Width = EditorGUILayout.IntField("Width", area.Width);
|
||||
area.Height = EditorGUILayout.IntField("Height", area.Height);
|
||||
|
||||
if (GUILayout.Button("Remove"))
|
||||
if (canDBHorizontal || canDBVertical)
|
||||
{
|
||||
prohibitedAreas.RemoveAt(i);
|
||||
break;
|
||||
dualBuffering = EditorGUILayout.Toggle("Dual Buffering", dualBuffering);
|
||||
}
|
||||
else
|
||||
{
|
||||
dualBuffering = false;
|
||||
}
|
||||
|
||||
if (canDBVertical && canDBHorizontal)
|
||||
{
|
||||
verticalLayout = EditorGUILayout.Toggle("Vertical", verticalLayout);
|
||||
}
|
||||
else if (canDBVertical)
|
||||
{
|
||||
verticalLayout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalLayout = false;
|
||||
}
|
||||
|
||||
prohibitedAreas[i] = area;
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label("Prohibited areas", EditorStyles.boldLabel);
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.MaxHeight(150f));
|
||||
|
||||
// List and edit each prohibited area.
|
||||
for (int i = 0; i < prohibitedAreas.Count; i++)
|
||||
{
|
||||
var area = prohibitedAreas[i];
|
||||
|
||||
area.X = EditorGUILayout.IntField("X", area.X);
|
||||
area.Y = EditorGUILayout.IntField("Y", area.Y);
|
||||
area.Width = EditorGUILayout.IntField("Width", area.Width);
|
||||
area.Height = EditorGUILayout.IntField("Height", area.Height);
|
||||
|
||||
if (GUILayout.Button("Remove"))
|
||||
{
|
||||
prohibitedAreas.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
|
||||
prohibitedAreas[i] = area;
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.Space(10);
|
||||
if (GUILayout.Button("Add Prohibited Area"))
|
||||
{
|
||||
prohibitedAreas.Add(new ProhibitedArea());
|
||||
}
|
||||
|
||||
// Button to initiate texture packing.
|
||||
if (GUILayout.Button("Pack Textures"))
|
||||
{
|
||||
PackTextures();
|
||||
}
|
||||
|
||||
// Button to save settings; saving now occurs only on button press.
|
||||
if (GUILayout.Button("Save Settings"))
|
||||
{
|
||||
StoreData();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
// Display VRAM image preview.
|
||||
Rect vramRect = GUILayoutUtility.GetRect(VramWidth, VramHeight, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawPreviewTexture(vramRect, vramImage, null, ScaleMode.ScaleToFit, 0, 0, ColorWriteMask.All);
|
||||
|
||||
// Draw framebuffer overlays.
|
||||
Rect buffer1 = new Rect(vramRect.x, vramRect.y, selectedResolution.x, selectedResolution.y);
|
||||
Rect buffer2 = verticalLayout ? new Rect(vramRect.x, 256, selectedResolution.x, selectedResolution.y)
|
||||
: new Rect(vramRect.x + selectedResolution.x, vramRect.y, selectedResolution.x, selectedResolution.y);
|
||||
|
||||
EditorGUI.DrawRect(buffer1, bufferColor1);
|
||||
GUI.Label(new Rect(buffer1.center.x - 40, buffer1.center.y - 10, 120, 20), "Framebuffer A", EditorStyles.boldLabel);
|
||||
GUILayout.Space(10);
|
||||
if (dualBuffering)
|
||||
{
|
||||
EditorGUI.DrawRect(buffer2, bufferColor2);
|
||||
GUI.Label(new Rect(buffer2.center.x - 40, buffer2.center.y - 10, 120, 20), "Framebuffer B", EditorStyles.boldLabel);
|
||||
}
|
||||
|
||||
// Draw overlays for each prohibited area.
|
||||
foreach (ProhibitedArea area in prohibitedAreas)
|
||||
{
|
||||
Rect areaRect = new Rect(vramRect.x + area.X, vramRect.y + area.Y, area.Width, area.Height);
|
||||
EditorGUI.DrawRect(areaRect, prohibitedColor);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.Space(10);
|
||||
if (GUILayout.Button("Add Prohibited Area"))
|
||||
/// <summary>
|
||||
/// Loads stored PSX data from the asset.
|
||||
/// </summary>
|
||||
private void LoadData()
|
||||
{
|
||||
prohibitedAreas.Add(new ProhibitedArea());
|
||||
_psxData = AssetDatabase.LoadAssetAtPath<PSXData>(_psxDataPath);
|
||||
if (!_psxData)
|
||||
{
|
||||
_psxData = CreateInstance<PSXData>();
|
||||
AssetDatabase.CreateAsset(_psxData, _psxDataPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
selectedResolution = _psxData.OutputResolution;
|
||||
dualBuffering = _psxData.DualBuffering;
|
||||
verticalLayout = _psxData.VerticalBuffering;
|
||||
prohibitedAreas = _psxData.ProhibitedAreas;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Pack Textures"))
|
||||
/// <summary>
|
||||
/// Stores current configuration to the PSX data asset.
|
||||
/// This is now triggered manually via the "Save Settings" button.
|
||||
/// </summary>
|
||||
private void StoreData()
|
||||
{
|
||||
PackTextures();
|
||||
}
|
||||
if (_psxData != null)
|
||||
{
|
||||
_psxData.OutputResolution = selectedResolution;
|
||||
_psxData.DualBuffering = dualBuffering;
|
||||
_psxData.VerticalBuffering = verticalLayout;
|
||||
_psxData.ProhibitedAreas = prohibitedAreas;
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
Rect vramRect = GUILayoutUtility.GetRect(VramWidth, VramHeight, GUILayout.ExpandWidth(false));
|
||||
EditorGUI.DrawPreviewTexture(vramRect, vramImage, null, ScaleMode.ScaleToFit, 0, 0, ColorWriteMask.All);
|
||||
|
||||
Rect buffer1 = new Rect(vramRect.x, vramRect.y, selectedResolution.x, selectedResolution.y);
|
||||
Rect buffer2 = verticalLayout ? new Rect(vramRect.x, 256, selectedResolution.x, selectedResolution.y)
|
||||
: new Rect(vramRect.x + selectedResolution.x, vramRect.y, selectedResolution.x, selectedResolution.y);
|
||||
|
||||
EditorGUI.DrawRect(buffer1, bufferColor1);
|
||||
GUI.Label(new Rect(buffer1.center.x - 40, buffer1.center.y - 10, 120, 20), "Framebuffer A", EditorStyles.boldLabel);
|
||||
GUILayout.Space(10);
|
||||
if (dualBuffering)
|
||||
{
|
||||
EditorGUI.DrawRect(buffer2, bufferColor2);
|
||||
GUI.Label(new Rect(buffer2.center.x - 40, buffer2.center.y - 10, 120, 20), "Framebuffer B", EditorStyles.boldLabel);
|
||||
}
|
||||
|
||||
foreach (ProhibitedArea area in prohibitedAreas)
|
||||
{
|
||||
Rect areaRect = new Rect(vramRect.x + area.X, vramRect.y + area.Y, area.Width, area.Height);
|
||||
EditorGUI.DrawRect(areaRect, prohibitedColor);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
StoreData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_psxData = AssetDatabase.LoadAssetAtPath<PSXData>(_psxDataPath);
|
||||
|
||||
if (!_psxData)
|
||||
{
|
||||
_psxData = CreateInstance<PSXData>();
|
||||
AssetDatabase.CreateAsset(_psxData, _psxDataPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
selectedResolution = _psxData.OutputResolution;
|
||||
dualBuffering = _psxData.DualBuffering;
|
||||
verticalLayout = _psxData.VerticalBuffering;
|
||||
prohibitedAreas = _psxData.ProhibitedAreas;
|
||||
}
|
||||
|
||||
private void StoreData()
|
||||
{
|
||||
if (_psxData != null)
|
||||
{
|
||||
_psxData.OutputResolution = selectedResolution;
|
||||
_psxData.DualBuffering = dualBuffering;
|
||||
_psxData.VerticalBuffering = verticalLayout;
|
||||
_psxData.ProhibitedAreas = prohibitedAreas;
|
||||
|
||||
EditorUtility.SetDirty(_psxData);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.SetDirty(_psxData);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user