Merge branch 'main' into splashpack
This commit is contained in:
@@ -195,6 +195,8 @@ namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
|
||||
|
||||
static short clampPosition(float v) => (short)(Mathf.Clamp(v, -4f, 3.999f) * 4096);
|
||||
static byte clamp0255(float v) => (byte)(Mathf.Clamp(v, 0, 255));
|
||||
PSXVertex psxVertex = new PSXVertex
|
||||
{
|
||||
// Convert position to fixed-point, clamping values to a defined range.
|
||||
@@ -212,7 +214,6 @@ namespace SplashEdit.RuntimeCode
|
||||
v = (byte)Mathf.Clamp((1.0f - uv.y) * (textureHeight - 1), 0, 255),
|
||||
|
||||
// Convert the computed color to a byte range.
|
||||
|
||||
};
|
||||
|
||||
return psxVertex;
|
||||
|
||||
@@ -3,15 +3,15 @@ using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
[RequireComponent(typeof(MeshFilter))]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class PSXObjectExporter : MonoBehaviour
|
||||
{
|
||||
public PSXBPP BitDepth = PSXBPP.TEX_8BIT; // Defines the bit depth of the texture (e.g., 4BPP, 8BPP)
|
||||
|
||||
[HideInInspector]
|
||||
public List<PSXTexture2D> Textures = new List<PSXTexture2D>(); // Stores the converted PlayStation-style texture
|
||||
public List<PSXTexture2D> Textures { get; set; } = new List<PSXTexture2D>(); // Stores the converted PlayStation-style texture
|
||||
public PSXMesh Mesh { get; set; } // Stores the converted PlayStation-style mesh
|
||||
|
||||
[HideInInspector]
|
||||
public PSXMesh Mesh; // Stores the converted PlayStation-style mesh
|
||||
|
||||
public bool PreviewNormals = false;
|
||||
public float normalPreviewLength = 0.5f; // Length of the normal lines
|
||||
@@ -84,6 +84,17 @@ namespace SplashEdit.RuntimeCode
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: Better handle object with default texture
|
||||
Texture = new PSXTexture2D()
|
||||
{
|
||||
BitDepth = BitDepth,
|
||||
Width = 0,
|
||||
Height = 0,
|
||||
};
|
||||
Texture.OriginalTexture = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Texture2D ConvertToTexture2D(Texture texture)
|
||||
@@ -112,6 +123,11 @@ namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
Mesh = PSXMesh.CreateFromUnityRenderer(renderer, GTEScaling, transform, Textures);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Dynamic meshes do not consider object transformation
|
||||
Mesh = PSXMesh.CreateFromUnityMesh(meshFilter.sharedMesh, Texture.Width, Texture.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,18 +41,15 @@ namespace SplashEdit.RuntimeCode
|
||||
ExportFile();
|
||||
}
|
||||
|
||||
void PackTextures()
|
||||
{
|
||||
private PSXData _psxData;
|
||||
private readonly string _psxDataPath = "Assets/PSXData.asset";
|
||||
|
||||
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);
|
||||
private Vector2 selectedResolution;
|
||||
private bool dualBuffering;
|
||||
private bool verticalLayout;
|
||||
private List<ProhibitedArea> prohibitedAreas;
|
||||
private VRAMPixel[,] vramPixels;
|
||||
|
||||
List<Rect> framebuffers = new List<Rect> { buffer1 };
|
||||
if (dualBuffering)
|
||||
{
|
||||
framebuffers.Add(buffer2);
|
||||
}
|
||||
|
||||
VRAMPacker tp = new VRAMPacker(framebuffers, prohibitedAreas);
|
||||
var packed = tp.PackTexturesIntoVRAM(_exporters);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -275,5 +276,15 @@ namespace SplashEdit.RuntimeCode
|
||||
return vramTexture;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Check if we need to update stored texture
|
||||
/// </summary>
|
||||
/// <param name="bitDepth">new settings for color bit depth</param>
|
||||
/// <param name="texture">new texture</param>
|
||||
/// <returns>return true if sored texture is different from a new one</returns>
|
||||
internal bool NeedUpdate(PSXBPP bitDepth, Texture2D texture)
|
||||
{
|
||||
return BitDepth != bitDepth || texture.GetInstanceID() != texture.GetInstanceID();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,9 +89,9 @@ namespace SplashEdit.RuntimeCode
|
||||
int atlasWidth = group.Key switch
|
||||
{
|
||||
PSXBPP.TEX_16BIT => 256,
|
||||
PSXBPP.TEX_8BIT => 128,
|
||||
PSXBPP.TEX_4BIT => 64,
|
||||
_ => 256
|
||||
PSXBPP.TEX_8BIT => 128,
|
||||
PSXBPP.TEX_4BIT => 64,
|
||||
_ => 256
|
||||
};
|
||||
|
||||
// Create an initial atlas for this group.
|
||||
@@ -101,9 +101,8 @@ namespace SplashEdit.RuntimeCode
|
||||
// Process each texture in descending order of area.
|
||||
foreach (var texture in group.OrderByDescending(tex => tex.QuantizedWidth * tex.Height))
|
||||
{
|
||||
// Check for duplicates in the entire set.
|
||||
if (uniqueTextures.Any(tex => tex.OriginalTexture.GetInstanceID() == texture.OriginalTexture.GetInstanceID() &&
|
||||
tex.BitDepth == texture.BitDepth))
|
||||
// Remove duplicate textures
|
||||
if (uniqueTextures.Where(tex => tex.OriginalTexture != null).Any(tex => tex.OriginalTexture.GetInstanceID() == obj.Texture.OriginalTexture.GetInstanceID() && tex.BitDepth == obj.Texture.BitDepth))
|
||||
{
|
||||
// Skip packing this texture – it will be replaced later.
|
||||
continue;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
@@ -282,5 +284,43 @@ namespace SplashEdit.RuntimeCode
|
||||
Mode16Bit = 2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
private static string _psxDataPath = "Assets/PSXData.asset";
|
||||
|
||||
public static (Rect, Rect) BufferForResolution(Vector2 selectedResolution, bool verticalLayout, Vector2 offset = default)
|
||||
{
|
||||
if (offset == default)
|
||||
{
|
||||
offset = Vector2.zero;
|
||||
}
|
||||
Rect buffer1 = new Rect(offset.x, offset.y, selectedResolution.x, selectedResolution.y);
|
||||
Rect buffer2 = verticalLayout ? new Rect(offset.x, 256, selectedResolution.x, selectedResolution.y)
|
||||
: new Rect(offset.x + selectedResolution.x, offset.y, selectedResolution.x, selectedResolution.y);
|
||||
return (buffer1, buffer2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads stored PSX data from the asset.
|
||||
/// </summary>
|
||||
public static PSXData LoadData(out Vector2 selectedResolution, out bool dualBuffering, out bool verticalLayout, out List<ProhibitedArea> prohibitedAreas)
|
||||
{
|
||||
var _psxData = AssetDatabase.LoadAssetAtPath<PSXData>(_psxDataPath);
|
||||
if (!_psxData)
|
||||
{
|
||||
_psxData = ScriptableObject.CreateInstance<PSXData>();
|
||||
AssetDatabase.CreateAsset(_psxData, _psxDataPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
selectedResolution = _psxData.OutputResolution;
|
||||
dualBuffering = _psxData.DualBuffering;
|
||||
verticalLayout = _psxData.VerticalBuffering;
|
||||
prohibitedAreas = _psxData.ProhibitedAreas;
|
||||
return _psxData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user