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.
|
// Retrieve all PSXObjectExporter objects and create their PSX textures.
|
||||||
PSXObjectExporter[] objects = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
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();
|
exp.CreatePSXTextures2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
|
|
||||||
// Define framebuffer regions based on selected resolution and layout.
|
// Define framebuffer regions based on selected resolution and layout.
|
||||||
(Rect buffer1, Rect buffer2) = Utils.BufferForResolution(selectedResolution, verticalLayout);
|
(Rect buffer1, Rect buffer2) = Utils.BufferForResolution(selectedResolution, verticalLayout);
|
||||||
|
|
||||||
@@ -157,6 +162,7 @@ namespace SplashEdit.EditorCode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AI;
|
using UnityEngine.AI;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
|
||||||
namespace SplashEdit.RuntimeCode
|
namespace SplashEdit.RuntimeCode
|
||||||
{
|
{
|
||||||
public class PSXPlayer : MonoBehaviour
|
public class PSXPlayer : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float PlayerHeight;
|
private const float LookOutDistance = 1000f;
|
||||||
|
|
||||||
[HideInInspector]
|
[FormerlySerializedAs("PlayerHeight")]
|
||||||
public Vector3 CamPoint;
|
[SerializeField] private float playerHeight;
|
||||||
private readonly float maxDistance = 1000f;
|
|
||||||
|
public float PlayerHeight => playerHeight;
|
||||||
|
public Vector3 CamPoint { get; protected set; }
|
||||||
|
|
||||||
public void FindNavmesh()
|
public void FindNavmesh()
|
||||||
{
|
{
|
||||||
NavMeshHit hit;
|
if (NavMesh.SamplePosition(transform.position, out NavMeshHit hit, LookOutDistance, NavMesh.AllAreas))
|
||||||
if (NavMesh.SamplePosition(transform.position, out hit, maxDistance, NavMesh.AllAreas))
|
|
||||||
{
|
{
|
||||||
CamPoint = hit.position + new Vector3(0, PlayerHeight, 0);
|
CamPoint = hit.position + new Vector3(0, PlayerHeight, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmos()
|
void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
FindNavmesh();
|
FindNavmesh();
|
||||||
|
|||||||
@@ -34,18 +34,24 @@ namespace SplashEdit.RuntimeCode
|
|||||||
_psxData = DataStorage.LoadData(out selectedResolution, out dualBuffering, out verticalLayout, out prohibitedAreas);
|
_psxData = DataStorage.LoadData(out selectedResolution, out dualBuffering, out verticalLayout, out prohibitedAreas);
|
||||||
|
|
||||||
_exporters = FindObjectsByType<PSXObjectExporter>(FindObjectsSortMode.None);
|
_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.CreatePSXTextures2D();
|
||||||
exp.CreatePSXMesh(GTEScaling);
|
exp.CreatePSXMesh(GTEScaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
_navmeshes = FindObjectsByType<PSXNavMesh>(FindObjectsSortMode.None);
|
_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);
|
navmesh.CreateNavmesh(GTEScaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
|
|
||||||
PackTextures();
|
PackTextures();
|
||||||
|
|
||||||
PSXPlayer player = FindObjectsByType<PSXPlayer>(FindObjectsSortMode.None).FirstOrDefault();
|
PSXPlayer player = FindObjectsByType<PSXPlayer>(FindObjectsSortMode.None).FirstOrDefault();
|
||||||
|
|||||||
@@ -342,16 +342,24 @@ namespace SplashEdit.RuntimeCode
|
|||||||
}
|
}
|
||||||
string assetPath = AssetDatabase.GetAssetPath(texture);
|
string assetPath = AssetDatabase.GetAssetPath(texture);
|
||||||
var tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
var tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
||||||
|
bool needReimport = false;
|
||||||
if (tImporter != null)
|
if (tImporter != null)
|
||||||
{
|
{
|
||||||
if (tImporter.maxTextureSize > MaxTextureSize)
|
if (tImporter.maxTextureSize > MaxTextureSize)
|
||||||
{
|
{
|
||||||
tImporter.maxTextureSize = MaxTextureSize;
|
tImporter.maxTextureSize = MaxTextureSize;
|
||||||
|
needReimport = true;
|
||||||
|
}
|
||||||
|
if (tImporter.isReadable != isReadable)
|
||||||
|
{
|
||||||
|
tImporter.isReadable = isReadable;
|
||||||
|
needReimport = true;
|
||||||
|
}
|
||||||
|
if (needReimport)
|
||||||
|
{
|
||||||
|
AssetDatabase.ImportAsset(assetPath);
|
||||||
|
AssetDatabase.Refresh();
|
||||||
}
|
}
|
||||||
tImporter.isReadable = isReadable;
|
|
||||||
|
|
||||||
AssetDatabase.ImportAsset(assetPath);
|
|
||||||
AssetDatabase.Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user