add Texture Cache on PSXObjectExporter
This commit is contained in:
@@ -1,30 +1,32 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace SplashEdit.RuntimeCode
|
namespace SplashEdit.RuntimeCode
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Renderer))]
|
[RequireComponent(typeof(Renderer))]
|
||||||
public class PSXObjectExporter : MonoBehaviour
|
public class PSXObjectExporter : MonoBehaviour
|
||||||
{
|
{
|
||||||
public PSXBPP BitDepth = PSXBPP.TEX_8BIT; // Defines the bit depth of the texture (e.g., 4BPP, 8BPP)
|
|
||||||
|
|
||||||
public List<PSXTexture2D> Textures { get; set; } = 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
|
public PSXMesh Mesh { get; set; } // Stores the converted PlayStation-style mesh
|
||||||
|
[Header("Export Settings")]
|
||||||
|
[FormerlySerializedAs("BitDepth")]
|
||||||
[SerializeField] private bool PreviewNormals = false;
|
[SerializeField] private PSXBPP bitDepth = PSXBPP.TEX_8BIT; // Defines the bit depth of the texture (e.g., 4BPP, 8BPP)
|
||||||
|
[Header("Gizmo Settings")]
|
||||||
|
[FormerlySerializedAs("PreviewNormals")]
|
||||||
|
[SerializeField] private bool previewNormals = false;
|
||||||
[SerializeField] private float normalPreviewLength = 0.5f; // Length of the normal lines
|
[SerializeField] private float normalPreviewLength = 0.5f; // Length of the normal lines
|
||||||
|
|
||||||
|
private readonly Dictionary<(int, PSXBPP), PSXTexture2D> cache = new();
|
||||||
|
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
|
if (previewNormals)
|
||||||
if (PreviewNormals)
|
|
||||||
{
|
{
|
||||||
MeshFilter filter = GetComponent<MeshFilter>();
|
MeshFilter filter = GetComponent<MeshFilter>();
|
||||||
|
|
||||||
if (filter != null)
|
if (filter != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
Mesh mesh = filter.sharedMesh;
|
Mesh mesh = filter.sharedMesh;
|
||||||
Vector3[] vertices = mesh.vertices;
|
Vector3[] vertices = mesh.vertices;
|
||||||
Vector3[] normals = mesh.normals;
|
Vector3[] normals = mesh.normals;
|
||||||
@@ -76,8 +78,17 @@ namespace SplashEdit.RuntimeCode
|
|||||||
|
|
||||||
if (tex2D != null)
|
if (tex2D != null)
|
||||||
{
|
{
|
||||||
PSXTexture2D tex = PSXTexture2D.CreateFromTexture2D(tex2D, BitDepth);
|
PSXTexture2D tex;
|
||||||
tex.OriginalTexture = tex2D; // Store reference to the original texture
|
if (cache.ContainsKey((tex2D.GetInstanceID(), bitDepth)))
|
||||||
|
{
|
||||||
|
tex = cache[(tex2D.GetInstanceID(), bitDepth)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tex = PSXTexture2D.CreateFromTexture2D(tex2D, bitDepth);
|
||||||
|
tex.OriginalTexture = tex2D; // Store reference to the original texture
|
||||||
|
cache.Add((tex2D.GetInstanceID(), bitDepth), tex);
|
||||||
|
}
|
||||||
Textures.Add(tex);
|
Textures.Add(tex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user