merge main into lua

This commit is contained in:
2025-04-12 14:55:42 +02:00
6 changed files with 138 additions and 86 deletions

View File

@@ -1,32 +1,35 @@
using System.Collections.Generic;
using Splashedit.RuntimeCode;
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 LuaFile luaFile;
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;
@@ -78,8 +81,17 @@ namespace SplashEdit.RuntimeCode
if (tex2D != null)
{
PSXTexture2D tex = PSXTexture2D.CreateFromTexture2D(tex2D, BitDepth);
tex.OriginalTexture = tex2D; // Store reference to the original texture
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);
}
}