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> atlasDataOffsets = new List<long>();
using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)))
{
// Header
@@ -101,6 +102,8 @@ namespace SplashEdit.RuntimeCode
writer.Write((int)rotationMatrix[2, 1]);
writer.Write((int)rotationMatrix[2, 2]);
writer.Write((ushort)exporter.Mesh.Triangles.Count);
// Set up texture page attributes
TPageAttr tpage = new TPageAttr();
tpage.SetPageX(exporter.Texture.TexpageX);
@@ -119,7 +122,27 @@ namespace SplashEdit.RuntimeCode
}
tpage.SetDithering(true);
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.
offsetPlaceholderPositions.Add(writer.BaseStream.Position);

View File

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

View File

@@ -22,17 +22,18 @@ The metadata section is split into two parts: **Object Descriptors** and **Atlas
### 2.1 Object (Exporter) Descriptors
For each exporter, the following fields are stored sequentially:
| Offset (per entry) | Size | Type | Description |
| ------------------ | -------- | ------- | -------------------------------------------------------------------- |
| 0x00 | 4 | int | X coordinate (GTE-converted) |
| 0x04 | 4 | int | Y coordinate (GTE-converted) |
| 0x08 | 4 | int | Z coordinate (GTE-converted) |
| 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) |
| 0x32 | 2 | uint16 | Number of triangles in the mesh |
| 0x34 | 4 | int | Mesh data offset placeholder |
| 0x30 | 2 | uint16 | Number of triangles in the mesh |
| 0x32 | 2 | uint16 | Texture page attributes (encoded from page X/Y, bit depth, dithering) |
| 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.*
@@ -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.
---