Added cluts

This commit is contained in:
2025-03-23 13:08:13 +01:00
parent afe9feb192
commit b0800a3995
3 changed files with 34 additions and 9 deletions

View File

@@ -72,6 +72,7 @@ namespace SplashEdit.RuntimeCode
List<long> atlasOffsetPlaceholderPositions = new List<long>(); List<long> atlasOffsetPlaceholderPositions = new List<long>();
List<long> atlasDataOffsets = new List<long>(); List<long> atlasDataOffsets = new List<long>();
using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create))) using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)))
{ {
// Header // Header
@@ -101,6 +102,8 @@ namespace SplashEdit.RuntimeCode
writer.Write((int)rotationMatrix[2, 1]); writer.Write((int)rotationMatrix[2, 1]);
writer.Write((int)rotationMatrix[2, 2]); writer.Write((int)rotationMatrix[2, 2]);
writer.Write((ushort)exporter.Mesh.Triangles.Count);
// Set up texture page attributes // Set up texture page attributes
TPageAttr tpage = new TPageAttr(); TPageAttr tpage = new TPageAttr();
tpage.SetPageX(exporter.Texture.TexpageX); tpage.SetPageX(exporter.Texture.TexpageX);
@@ -119,7 +122,27 @@ namespace SplashEdit.RuntimeCode
} }
tpage.SetDithering(true); tpage.SetDithering(true);
writer.Write((ushort)tpage.info); writer.Write((ushort)tpage.info);
writer.Write((ushort)exporter.Mesh.Triangles.Count); writer.Write((ushort)exporter.Texture.ClutPackingX);
writer.Write((ushort)exporter.Texture.ClutPackingY);
if (exporter.Texture.BitDepth != PSXBPP.TEX_16BIT)
{
foreach (VRAMPixel color in exporter.Texture.ColorPalette)
{
writer.Write((ushort)color.Pack());
}
for (int i = exporter.Texture.ColorPalette.Count; i < 256; i++)
{
writer.Write((ushort)0);
}
}
else
{
for (int i = 0; i < 256; i++)
{
writer.Write((ushort)0);
}
}
// Write placeholder for mesh data offset and record its position. // Write placeholder for mesh data offset and record its position.
offsetPlaceholderPositions.Add(writer.BaseStream.Position); offsetPlaceholderPositions.Add(writer.BaseStream.Position);
@@ -279,7 +302,7 @@ namespace SplashEdit.RuntimeCode
void OnDrawGizmos() void OnDrawGizmos()
{ {
Gizmos.DrawIcon(transform.position, "Packages/net.psxsplash.splashedit/Icons/PSXSceneExporter.png", true); Gizmos.DrawIcon(transform.position, "Packages/net.psxsplash.splashedit/Icons/PSXSceneExporter.png", true);
Vector3 sceneOrigin = new Vector3(0,0,0); Vector3 sceneOrigin = new Vector3(0, 0, 0);
Vector3 cubeSize = new Vector3(8.0f * GTEScaling, 8.0f * GTEScaling, 8.0f * GTEScaling); Vector3 cubeSize = new Vector3(8.0f * GTEScaling, 8.0f * GTEScaling, 8.0f * GTEScaling);
Gizmos.color = Color.red; Gizmos.color = Color.red;
Gizmos.DrawWireCube(sceneOrigin, cubeSize); Gizmos.DrawWireCube(sceneOrigin, cubeSize);

View File

@@ -227,7 +227,7 @@ namespace SplashEdit.RuntimeCode
if (IsPlacementValid(candidate)) if (IsPlacementValid(candidate))
{ {
_allocatedCLUTs.Add(candidate); _allocatedCLUTs.Add(candidate);
texture.ClutPackingX = x; texture.ClutPackingX = (ushort)(x/16);
texture.ClutPackingY = y; texture.ClutPackingY = y;
placed = true; placed = true;
break; break;

View File

@@ -22,17 +22,18 @@ The metadata section is split into two parts: **Object Descriptors** and **Atlas
### 2.1 Object (Exporter) Descriptors ### 2.1 Object (Exporter) Descriptors
For each exporter, the following fields are stored sequentially:
| Offset (per entry) | Size | Type | Description | | Offset (per entry) | Size | Type | Description |
| ------------------ | -------- | ------- | -------------------------------------------------------------------- | | ------------------ | -------- | ------- | -------------------------------------------------------------------- |
| 0x00 | 4 | int | X coordinate (GTE-converted) | | 0x00 | 4 | int | X coordinate (GTE-converted) |
| 0x04 | 4 | int | Y coordinate (GTE-converted) | | 0x04 | 4 | int | Y coordinate (GTE-converted) |
| 0x08 | 4 | int | Z coordinate (GTE-converted) | | 0x08 | 4 | int | Z coordinate (GTE-converted) |
| 0x0C | 36 | int[9] | Rotation matrix (3×3, row-major order) | | 0x0C | 36 | int[9] | Rotation matrix (3×3, row-major order) |
| 0x30 | 2 | uint16 | Texture page attributes (encoded from page X/Y, bit depth, dithering) | | 0x30 | 2 | uint16 | Number of triangles in the mesh |
| 0x32 | 2 | uint16 | Number of triangles in the mesh | | 0x32 | 2 | uint16 | Texture page attributes (encoded from page X/Y, bit depth, dithering) |
| 0x34 | 4 | int | Mesh data offset placeholder | | 0x34 | 2 | uint16 | CLUT packing X coordinate |
| 0x36 | 2 | uint16 | CLUT packing Y coordinate |
| 0x38 | 512 | uint16[256] | Color palette (filled with zeros if 16-bit textures) |
| 0x438 | 4 | int | Mesh data offset placeholder |
*Each object descriptor occupies **0x38** bytes.* *Each object descriptor occupies **0x38** bytes.*
@@ -83,3 +84,4 @@ For each texture atlas, the raw texture data is stored as a 2D array. Before wri
| **Raw Texture Data** | The atlas data is written pixel by pixel. | **Raw Texture Data** | The atlas data is written pixel by pixel.
--- ---