Merge pull request #12 from aliakseikalosha/main
add texture cache to PSXObjectExporter
This commit is contained in:
@@ -113,11 +113,16 @@ namespace SplashEdit.EditorCode
|
||||
|
||||
// Retrieve all PSXObjectExporter objects and create their PSX textures.
|
||||
PSXObjectExporter[] objects = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
||||
foreach (PSXObjectExporter exp in objects)
|
||||
for (int i = 0; i < objects.Length; i++)
|
||||
{
|
||||
|
||||
EditorUtility.DisplayProgressBar($"{nameof(VRAMEditorWindow)}", $"Export {nameof(PSXObjectExporter)}", ((float)i) / objects.Length);
|
||||
PSXObjectExporter exp = objects[i];
|
||||
exp.CreatePSXTextures2D();
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
// Define framebuffer regions based on selected resolution and layout.
|
||||
(Rect buffer1, Rect buffer2) = Utils.BufferForResolution(selectedResolution, verticalLayout);
|
||||
|
||||
@@ -157,6 +162,7 @@ namespace SplashEdit.EditorCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
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 PSXMesh Mesh { get; set; } // Stores the converted PlayStation-style mesh
|
||||
|
||||
|
||||
[SerializeField] private bool PreviewNormals = false;
|
||||
[Header("Export Settings")]
|
||||
[FormerlySerializedAs("BitDepth")]
|
||||
[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
|
||||
|
||||
private readonly Dictionary<(int, PSXBPP), PSXTexture2D> cache = new();
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
|
||||
if (PreviewNormals)
|
||||
if (previewNormals)
|
||||
{
|
||||
MeshFilter filter = GetComponent<MeshFilter>();
|
||||
|
||||
if (filter != null)
|
||||
{
|
||||
|
||||
Mesh mesh = filter.sharedMesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
Vector3[] normals = mesh.normals;
|
||||
@@ -76,8 +78,17 @@ namespace SplashEdit.RuntimeCode
|
||||
|
||||
if (tex2D != null)
|
||||
{
|
||||
PSXTexture2D tex = PSXTexture2D.CreateFromTexture2D(tex2D, BitDepth);
|
||||
PSXTexture2D tex;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
public class PSXPlayer : MonoBehaviour
|
||||
{
|
||||
public float PlayerHeight;
|
||||
private const float LookOutDistance = 1000f;
|
||||
|
||||
[HideInInspector]
|
||||
public Vector3 CamPoint;
|
||||
private readonly float maxDistance = 1000f;
|
||||
[FormerlySerializedAs("PlayerHeight")]
|
||||
[SerializeField] private float playerHeight;
|
||||
|
||||
public float PlayerHeight => playerHeight;
|
||||
public Vector3 CamPoint { get; protected set; }
|
||||
|
||||
public void FindNavmesh()
|
||||
{
|
||||
NavMeshHit hit;
|
||||
if (NavMesh.SamplePosition(transform.position, out hit, maxDistance, NavMesh.AllAreas))
|
||||
if (NavMesh.SamplePosition(transform.position, out NavMeshHit hit, LookOutDistance, NavMesh.AllAreas))
|
||||
{
|
||||
CamPoint = hit.position + new Vector3(0, PlayerHeight, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
FindNavmesh();
|
||||
|
||||
@@ -34,18 +34,24 @@ namespace SplashEdit.RuntimeCode
|
||||
_psxData = DataStorage.LoadData(out selectedResolution, out dualBuffering, out verticalLayout, out prohibitedAreas);
|
||||
|
||||
_exporters = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
||||
foreach (PSXObjectExporter exp in _exporters)
|
||||
for (int i = 0; i < _exporters.Length; i++)
|
||||
{
|
||||
PSXObjectExporter exp = _exporters[i];
|
||||
EditorUtility.DisplayProgressBar($"{nameof(PSXSceneExporter)}", $"Export {nameof(PSXObjectExporter)}", ((float)i)/ _exporters.Length);
|
||||
exp.CreatePSXTextures2D();
|
||||
exp.CreatePSXMesh(GTEScaling);
|
||||
}
|
||||
|
||||
_navmeshes = FindObjectsByType<PSXNavMesh>(FindObjectsSortMode.None);
|
||||
foreach (PSXNavMesh navmesh in _navmeshes)
|
||||
for (int i = 0; i < _navmeshes.Length; i++)
|
||||
{
|
||||
PSXNavMesh navmesh = _navmeshes[i];
|
||||
EditorUtility.DisplayProgressBar($"{nameof(PSXSceneExporter)}", $"Export {nameof(PSXNavMesh)}", ((float)i) / _navmeshes.Length);
|
||||
navmesh.CreateNavmesh(GTEScaling);
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
PackTextures();
|
||||
|
||||
PSXPlayer player = FindObjectsByType<PSXPlayer>(FindObjectsSortMode.None).FirstOrDefault();
|
||||
|
||||
@@ -342,19 +342,27 @@ namespace SplashEdit.RuntimeCode
|
||||
}
|
||||
string assetPath = AssetDatabase.GetAssetPath(texture);
|
||||
var tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
||||
bool needReimport = false;
|
||||
if (tImporter != null)
|
||||
{
|
||||
if (tImporter.maxTextureSize > MaxTextureSize)
|
||||
{
|
||||
tImporter.maxTextureSize = MaxTextureSize;
|
||||
needReimport = true;
|
||||
}
|
||||
if (tImporter.isReadable != isReadable)
|
||||
{
|
||||
tImporter.isReadable = isReadable;
|
||||
|
||||
needReimport = true;
|
||||
}
|
||||
if (needReimport)
|
||||
{
|
||||
AssetDatabase.ImportAsset(assetPath);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user