Cutscene sytstem
This commit is contained in:
27
Runtime/PSXAudioEvent.cs
Normal file
27
Runtime/PSXAudioEvent.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A frame-based audio trigger within a cutscene.
|
||||
/// When the cutscene reaches this frame, the named audio clip is played.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PSXAudioEvent
|
||||
{
|
||||
[Tooltip("Frame at which to trigger this audio clip.")]
|
||||
public int Frame;
|
||||
|
||||
[Tooltip("Name of the audio clip (must match a PSXAudioSource ClipName in the scene).")]
|
||||
public string ClipName = "";
|
||||
|
||||
[Tooltip("Playback volume (0 = silent, 128 = max).")]
|
||||
[Range(0, 128)]
|
||||
public int Volume = 100;
|
||||
|
||||
[Tooltip("Stereo pan (0 = hard left, 64 = center, 127 = hard right).")]
|
||||
[Range(0, 127)]
|
||||
public int Pan = 64;
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXAudioEvent.cs.meta
Normal file
2
Runtime/PSXAudioEvent.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 264e92578fac5014aa24c1e38e116b3b
|
||||
27
Runtime/PSXCutsceneClip.cs
Normal file
27
Runtime/PSXCutsceneClip.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A cutscene asset containing keyframed tracks and audio events.
|
||||
/// Create via right-click → Create → PSX → Cutscene Clip.
|
||||
/// Reference these assets anywhere in the project; the exporter collects
|
||||
/// all PSXCutsceneClip assets via Resources.FindObjectsOfTypeAll.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "NewCutscene", menuName = "PSX/Cutscene Clip", order = 100)]
|
||||
public class PSXCutsceneClip : ScriptableObject
|
||||
{
|
||||
[Tooltip("Name used to reference this cutscene from Lua (max 24 chars). Must be unique per scene.")]
|
||||
public string CutsceneName = "cutscene";
|
||||
|
||||
[Tooltip("Total duration in frames at 30fps. E.g. 90 = 3 seconds.")]
|
||||
public int DurationFrames = 90;
|
||||
|
||||
[Tooltip("Tracks driving properties over time.")]
|
||||
public List<PSXCutsceneTrack> Tracks = new List<PSXCutsceneTrack>();
|
||||
|
||||
[Tooltip("Audio events triggered at specific frames.")]
|
||||
public List<PSXAudioEvent> AudioEvents = new List<PSXAudioEvent>();
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXCutsceneClip.cs.meta
Normal file
2
Runtime/PSXCutsceneClip.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99c0b28de0bbbf7449afc28106b605dc
|
||||
333
Runtime/PSXCutsceneExporter.cs
Normal file
333
Runtime/PSXCutsceneExporter.cs
Normal file
@@ -0,0 +1,333 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializes PSXCutsceneClip data into the splashpack v12 binary format.
|
||||
/// Called from PSXSceneWriter.Write() after all other data sections.
|
||||
/// </summary>
|
||||
public static class PSXCutsceneExporter
|
||||
{
|
||||
// Match C++ limits
|
||||
private const int MAX_CUTSCENES = 16;
|
||||
private const int MAX_TRACKS = 8;
|
||||
private const int MAX_KEYFRAMES = 64;
|
||||
private const int MAX_AUDIO_EVENTS = 64;
|
||||
private const int MAX_NAME_LEN = 24;
|
||||
|
||||
/// <summary>
|
||||
/// Angle conversion: degrees to psyqo::Angle raw value.
|
||||
/// psyqo::Angle = FixedPoint<10>, stored in pi-units.
|
||||
/// 1.0_pi = 1024 raw = 180 degrees. So: raw = degrees * 1024 / 180.
|
||||
/// </summary>
|
||||
private static short DegreesToAngleRaw(float degrees)
|
||||
{
|
||||
float raw = degrees * 1024.0f / 180.0f;
|
||||
return (short)Mathf.Clamp(Mathf.RoundToInt(raw), -32768, 32767);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write all cutscene data and return the byte position of the cutscene table
|
||||
/// so the header can be backfilled.
|
||||
/// </summary>
|
||||
/// <param name="writer">Binary writer positioned after all prior sections.</param>
|
||||
/// <param name="cutscenes">Cutscene clips to export (may be null/empty).</param>
|
||||
/// <param name="exporters">Scene object exporters for name validation.</param>
|
||||
/// <param name="audioSources">Audio sources for clip name → index resolution.</param>
|
||||
/// <param name="gteScaling">GTE scaling factor.</param>
|
||||
/// <param name="cutsceneTableStart">Returns the file position where the cutscene table starts.</param>
|
||||
/// <param name="log">Optional log callback.</param>
|
||||
public static void ExportCutscenes(
|
||||
BinaryWriter writer,
|
||||
PSXCutsceneClip[] cutscenes,
|
||||
PSXObjectExporter[] exporters,
|
||||
PSXAudioSource[] audioSources,
|
||||
float gteScaling,
|
||||
out long cutsceneTableStart,
|
||||
Action<string, LogType> log = null)
|
||||
{
|
||||
cutsceneTableStart = 0;
|
||||
|
||||
if (cutscenes == null || cutscenes.Length == 0)
|
||||
return;
|
||||
|
||||
if (cutscenes.Length > MAX_CUTSCENES)
|
||||
{
|
||||
log?.Invoke($"Too many cutscenes ({cutscenes.Length} > {MAX_CUTSCENES}). Only the first {MAX_CUTSCENES} will be exported.", LogType.Warning);
|
||||
var trimmed = new PSXCutsceneClip[MAX_CUTSCENES];
|
||||
Array.Copy(cutscenes, trimmed, MAX_CUTSCENES);
|
||||
cutscenes = trimmed;
|
||||
}
|
||||
|
||||
// Build audio source name → index lookup
|
||||
Dictionary<string, int> audioNameToIndex = new Dictionary<string, int>();
|
||||
if (audioSources != null)
|
||||
{
|
||||
for (int i = 0; i < audioSources.Length; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(audioSources[i].ClipName) && !audioNameToIndex.ContainsKey(audioSources[i].ClipName))
|
||||
audioNameToIndex[audioSources[i].ClipName] = i;
|
||||
}
|
||||
}
|
||||
|
||||
AlignToFourBytes(writer);
|
||||
|
||||
// ── Cutscene Table ──
|
||||
cutsceneTableStart = writer.BaseStream.Position;
|
||||
|
||||
// SPLASHPACKCutsceneEntry: 12 bytes each
|
||||
// Write placeholders first, then backfill
|
||||
long[] entryPositions = new long[cutscenes.Length];
|
||||
for (int i = 0; i < cutscenes.Length; i++)
|
||||
{
|
||||
entryPositions[i] = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // dataOffset placeholder
|
||||
writer.Write((byte)0); // nameLen placeholder
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((uint)0); // nameOffset placeholder
|
||||
}
|
||||
|
||||
// ── Per-cutscene data ──
|
||||
for (int ci = 0; ci < cutscenes.Length; ci++)
|
||||
{
|
||||
PSXCutsceneClip clip = cutscenes[ci];
|
||||
AlignToFourBytes(writer);
|
||||
|
||||
// Record data offset
|
||||
long dataPos = writer.BaseStream.Position;
|
||||
|
||||
// Validate and clamp
|
||||
int trackCount = Mathf.Min(clip.Tracks?.Count ?? 0, MAX_TRACKS);
|
||||
int audioEventCount = 0;
|
||||
|
||||
// Count valid audio events
|
||||
List<PSXAudioEvent> validEvents = new List<PSXAudioEvent>();
|
||||
if (clip.AudioEvents != null)
|
||||
{
|
||||
foreach (var evt in clip.AudioEvents)
|
||||
{
|
||||
if (audioNameToIndex.ContainsKey(evt.ClipName))
|
||||
{
|
||||
validEvents.Add(evt);
|
||||
if (validEvents.Count >= MAX_AUDIO_EVENTS) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
log?.Invoke($"Cutscene '{clip.CutsceneName}': audio event clip '{evt.ClipName}' not found in scene audio sources. Skipping.", LogType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
audioEventCount = validEvents.Count;
|
||||
|
||||
// Sort audio events by frame (required for linear scan on PS1)
|
||||
validEvents.Sort((a, b) => a.Frame.CompareTo(b.Frame));
|
||||
|
||||
// SPLASHPACKCutscene: 12 bytes
|
||||
long tracksOffsetPlaceholder;
|
||||
long audioEventsOffsetPlaceholder;
|
||||
|
||||
writer.Write((ushort)clip.DurationFrames);
|
||||
writer.Write((byte)trackCount);
|
||||
writer.Write((byte)audioEventCount);
|
||||
tracksOffsetPlaceholder = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // tracksOffset placeholder
|
||||
audioEventsOffsetPlaceholder = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // audioEventsOffset placeholder
|
||||
|
||||
// ── Tracks ──
|
||||
AlignToFourBytes(writer);
|
||||
long tracksStart = writer.BaseStream.Position;
|
||||
|
||||
// SPLASHPACKCutsceneTrack: 12 bytes each
|
||||
long[] trackObjectNameOffsets = new long[trackCount];
|
||||
long[] trackKeyframesOffsets = new long[trackCount];
|
||||
|
||||
for (int ti = 0; ti < trackCount; ti++)
|
||||
{
|
||||
PSXCutsceneTrack track = clip.Tracks[ti];
|
||||
bool isCameraTrack = track.TrackType == PSXTrackType.CameraPosition || track.TrackType == PSXTrackType.CameraRotation;
|
||||
string objName = isCameraTrack ? "" : (track.ObjectName ?? "");
|
||||
if (objName.Length > MAX_NAME_LEN) objName = objName.Substring(0, MAX_NAME_LEN);
|
||||
|
||||
int kfCount = Mathf.Min(track.Keyframes?.Count ?? 0, MAX_KEYFRAMES);
|
||||
|
||||
writer.Write((byte)track.TrackType);
|
||||
writer.Write((byte)kfCount);
|
||||
writer.Write((byte)objName.Length);
|
||||
writer.Write((byte)0); // pad
|
||||
trackObjectNameOffsets[ti] = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // objectNameOffset placeholder
|
||||
trackKeyframesOffsets[ti] = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // keyframesOffset placeholder
|
||||
}
|
||||
|
||||
// ── Keyframe data (per track) ──
|
||||
for (int ti = 0; ti < trackCount; ti++)
|
||||
{
|
||||
PSXCutsceneTrack track = clip.Tracks[ti];
|
||||
int kfCount = Mathf.Min(track.Keyframes?.Count ?? 0, MAX_KEYFRAMES);
|
||||
|
||||
AlignToFourBytes(writer);
|
||||
long kfStart = writer.BaseStream.Position;
|
||||
|
||||
// Sort keyframes by frame
|
||||
var sortedKf = new List<PSXKeyframe>(track.Keyframes ?? new List<PSXKeyframe>());
|
||||
sortedKf.Sort((a, b) => a.Frame.CompareTo(b.Frame));
|
||||
|
||||
for (int ki = 0; ki < kfCount; ki++)
|
||||
{
|
||||
PSXKeyframe kf = sortedKf[ki];
|
||||
// Pack interp mode into upper 3 bits, frame into lower 13 bits
|
||||
ushort frameAndInterp = (ushort)((((int)kf.Interp & 0x7) << 13) | (kf.Frame & 0x1FFF));
|
||||
writer.Write(frameAndInterp);
|
||||
|
||||
switch (track.TrackType)
|
||||
{
|
||||
case PSXTrackType.CameraPosition:
|
||||
case PSXTrackType.ObjectPosition:
|
||||
{
|
||||
// Position: convert to fp12, negate Y for PSX coords
|
||||
float gte = gteScaling;
|
||||
short px = PSXTrig.ConvertCoordinateToPSX(kf.Value.x, gte);
|
||||
short py = PSXTrig.ConvertCoordinateToPSX(-kf.Value.y, gte);
|
||||
short pz = PSXTrig.ConvertCoordinateToPSX(kf.Value.z, gte);
|
||||
writer.Write(px);
|
||||
writer.Write(py);
|
||||
writer.Write(pz);
|
||||
break;
|
||||
}
|
||||
case PSXTrackType.CameraRotation:
|
||||
{
|
||||
// Rotation: degrees → psyqo::Angle raw (pi-units)
|
||||
short rx = DegreesToAngleRaw(kf.Value.x);
|
||||
short ry = DegreesToAngleRaw(kf.Value.y);
|
||||
short rz = DegreesToAngleRaw(kf.Value.z);
|
||||
writer.Write(rx);
|
||||
writer.Write(ry);
|
||||
writer.Write(rz);
|
||||
break;
|
||||
}
|
||||
case PSXTrackType.ObjectRotationY:
|
||||
{
|
||||
// Only Y rotation matters
|
||||
writer.Write((short)0);
|
||||
writer.Write(DegreesToAngleRaw(kf.Value.y));
|
||||
writer.Write((short)0);
|
||||
break;
|
||||
}
|
||||
case PSXTrackType.ObjectActive:
|
||||
{
|
||||
writer.Write((short)(kf.Value.x > 0.5f ? 1 : 0));
|
||||
writer.Write((short)0);
|
||||
writer.Write((short)0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill keyframes offset
|
||||
{
|
||||
long curPos = writer.BaseStream.Position;
|
||||
writer.Seek((int)trackKeyframesOffsets[ti], SeekOrigin.Begin);
|
||||
writer.Write((uint)kfStart);
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Object name strings (per track) ──
|
||||
for (int ti = 0; ti < trackCount; ti++)
|
||||
{
|
||||
PSXCutsceneTrack track = clip.Tracks[ti];
|
||||
bool isCameraTrack = track.TrackType == PSXTrackType.CameraPosition || track.TrackType == PSXTrackType.CameraRotation;
|
||||
string objName = isCameraTrack ? "" : (track.ObjectName ?? "");
|
||||
if (objName.Length > MAX_NAME_LEN) objName = objName.Substring(0, MAX_NAME_LEN);
|
||||
|
||||
if (objName.Length > 0)
|
||||
{
|
||||
long namePos = writer.BaseStream.Position;
|
||||
byte[] nameBytes = Encoding.UTF8.GetBytes(objName);
|
||||
writer.Write(nameBytes);
|
||||
writer.Write((byte)0); // null terminator
|
||||
|
||||
long curPos = writer.BaseStream.Position;
|
||||
writer.Seek((int)trackObjectNameOffsets[ti], SeekOrigin.Begin);
|
||||
writer.Write((uint)namePos);
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
// else: objectNameOffset stays 0
|
||||
}
|
||||
|
||||
// ── Audio events ──
|
||||
AlignToFourBytes(writer);
|
||||
long audioEventsStart = writer.BaseStream.Position;
|
||||
|
||||
foreach (var evt in validEvents)
|
||||
{
|
||||
int clipIdx = audioNameToIndex[evt.ClipName];
|
||||
writer.Write((ushort)evt.Frame);
|
||||
writer.Write((byte)clipIdx);
|
||||
writer.Write((byte)Mathf.Clamp(evt.Volume, 0, 128));
|
||||
writer.Write((byte)Mathf.Clamp(evt.Pan, 0, 127));
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
}
|
||||
|
||||
// ── Cutscene name string ──
|
||||
string csName = clip.CutsceneName ?? "unnamed";
|
||||
if (csName.Length > MAX_NAME_LEN) csName = csName.Substring(0, MAX_NAME_LEN);
|
||||
long nameStartPos = writer.BaseStream.Position;
|
||||
byte[] csNameBytes = Encoding.UTF8.GetBytes(csName);
|
||||
writer.Write(csNameBytes);
|
||||
writer.Write((byte)0); // null terminator
|
||||
|
||||
// ── Backfill SPLASHPACKCutscene offsets ──
|
||||
{
|
||||
long curPos = writer.BaseStream.Position;
|
||||
|
||||
// tracksOffset
|
||||
writer.Seek((int)tracksOffsetPlaceholder, SeekOrigin.Begin);
|
||||
writer.Write((uint)tracksStart);
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
{
|
||||
long curPos = writer.BaseStream.Position;
|
||||
|
||||
// audioEventsOffset
|
||||
writer.Seek((int)audioEventsOffsetPlaceholder, SeekOrigin.Begin);
|
||||
writer.Write((uint)(audioEventCount > 0 ? audioEventsStart : 0));
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
// ── Backfill cutscene table entry ──
|
||||
{
|
||||
long curPos = writer.BaseStream.Position;
|
||||
writer.Seek((int)entryPositions[ci], SeekOrigin.Begin);
|
||||
writer.Write((uint)dataPos); // dataOffset
|
||||
writer.Write((byte)csNameBytes.Length); // nameLen
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((byte)0); // pad
|
||||
writer.Write((uint)nameStartPos); // nameOffset
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
log?.Invoke($"{cutscenes.Length} cutscene(s) exported.", LogType.Log);
|
||||
}
|
||||
|
||||
private static void AlignToFourBytes(BinaryWriter writer)
|
||||
{
|
||||
long pos = writer.BaseStream.Position;
|
||||
int padding = (int)(4 - (pos % 4)) % 4;
|
||||
if (padding > 0)
|
||||
writer.Write(new byte[padding]);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXCutsceneExporter.cs.meta
Normal file
2
Runtime/PSXCutsceneExporter.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d915e0da5e09ea348a020d077f0725da
|
||||
22
Runtime/PSXCutsceneTrack.cs
Normal file
22
Runtime/PSXCutsceneTrack.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A single track within a cutscene, driving one property on one target.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PSXCutsceneTrack
|
||||
{
|
||||
[Tooltip("What property this track drives.")]
|
||||
public PSXTrackType TrackType;
|
||||
|
||||
[Tooltip("Target GameObject name (must match a PSXObjectExporter). Leave empty for camera tracks.")]
|
||||
public string ObjectName = "";
|
||||
|
||||
[Tooltip("Keyframes for this track. Sort by frame number.")]
|
||||
public List<PSXKeyframe> Keyframes = new List<PSXKeyframe>();
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXCutsceneTrack.cs.meta
Normal file
2
Runtime/PSXCutsceneTrack.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c289e12325ed44499d49bc7a570c8de
|
||||
15
Runtime/PSXInterpMode.cs
Normal file
15
Runtime/PSXInterpMode.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Per-keyframe interpolation mode. Must match the C++ InterpMode enum in cutscene.hh.
|
||||
/// Packed into the upper 3 bits of the 16-bit frame field on export.
|
||||
/// </summary>
|
||||
public enum PSXInterpMode : byte
|
||||
{
|
||||
Linear = 0,
|
||||
Step = 1,
|
||||
EaseIn = 2,
|
||||
EaseOut = 3,
|
||||
EaseInOut = 4,
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXInterpMode.cs.meta
Normal file
2
Runtime/PSXInterpMode.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f925971a446a614a9f4f3e61f2395c0
|
||||
26
Runtime/PSXKeyframe.cs
Normal file
26
Runtime/PSXKeyframe.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A single keyframe in a cutscene track.
|
||||
/// Value interpretation depends on track type:
|
||||
/// CameraPosition / ObjectPosition: Unity world-space position (x, y, z)
|
||||
/// CameraRotation: Euler angles in degrees (x=pitch, y=yaw, z=roll)
|
||||
/// ObjectRotationY: y component = rotation in degrees
|
||||
/// ObjectActive: x component = 0.0 (inactive) or 1.0 (active)
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PSXKeyframe
|
||||
{
|
||||
[Tooltip("Frame number (0 = start of cutscene). At 30fps, frame 30 = 1 second.")]
|
||||
public int Frame;
|
||||
|
||||
[Tooltip("Keyframe value. Interpretation depends on track type.")]
|
||||
public Vector3 Value;
|
||||
|
||||
[Tooltip("Interpolation mode from this keyframe to the next.")]
|
||||
public PSXInterpMode Interp = PSXInterpMode.Linear;
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXKeyframe.cs.meta
Normal file
2
Runtime/PSXKeyframe.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b2679967786bcf4e81793694cd3dfeb
|
||||
@@ -37,6 +37,10 @@ namespace SplashEdit.RuntimeCode
|
||||
[Tooltip("Exterior uses BVH frustum culling. Interior uses room/portal occlusion.")]
|
||||
public int SceneType = 0; // 0=exterior, 1=interior
|
||||
|
||||
[Header("Cutscenes")]
|
||||
[Tooltip("Cutscene clips to include in this scene's splashpack. Only these will be exported.")]
|
||||
public PSXCutsceneClip[] Cutscenes = new PSXCutsceneClip[0];
|
||||
|
||||
private PSXObjectExporter[] _exporters;
|
||||
private TextureAtlas[] _atlases;
|
||||
|
||||
@@ -254,6 +258,8 @@ namespace SplashEdit.RuntimeCode
|
||||
fogEnabled = FogEnabled,
|
||||
fogColor = FogColor,
|
||||
fogDensity = FogDensity,
|
||||
cutscenes = Cutscenes,
|
||||
audioSources = _audioSources,
|
||||
};
|
||||
|
||||
PSXSceneWriter.Write(path, in scene, (msg, type) =>
|
||||
|
||||
@@ -29,6 +29,10 @@ namespace SplashEdit.RuntimeCode
|
||||
public LuaFile sceneLuaFile;
|
||||
public float gteScaling;
|
||||
|
||||
// Cutscene data (v12)
|
||||
public PSXCutsceneClip[] cutscenes;
|
||||
public PSXAudioSource[] audioSources;
|
||||
|
||||
// Player
|
||||
public Vector3 playerPos;
|
||||
public Quaternion playerRot;
|
||||
@@ -115,7 +119,7 @@ namespace SplashEdit.RuntimeCode
|
||||
// ──────────────────────────────────────────────────────
|
||||
writer.Write('S');
|
||||
writer.Write('P');
|
||||
writer.Write((ushort)11); // version
|
||||
writer.Write((ushort)12); // version
|
||||
writer.Write((ushort)luaFiles.Count);
|
||||
writer.Write((ushort)scene.exporters.Length);
|
||||
writer.Write((ushort)0); // navmeshCount (legacy)
|
||||
@@ -208,6 +212,13 @@ namespace SplashEdit.RuntimeCode
|
||||
writer.Write((ushort)roomTriRefCount);
|
||||
}
|
||||
|
||||
// Cutscene header (version 12, 8 bytes)
|
||||
int cutsceneCount = scene.cutscenes?.Length ?? 0;
|
||||
writer.Write((ushort)cutsceneCount);
|
||||
writer.Write((ushort)0); // reserved_cs
|
||||
long cutsceneTableOffsetPos = writer.BaseStream.Position;
|
||||
writer.Write((uint)0); // cutsceneTableOffset placeholder
|
||||
|
||||
// ──────────────────────────────────────────────────────
|
||||
// Lua file metadata
|
||||
// ──────────────────────────────────────────────────────
|
||||
@@ -582,6 +593,30 @@ namespace SplashEdit.RuntimeCode
|
||||
log?.Invoke($"{audioClipCount} audio clips ({totalAudioBytes / 1024}KB ADPCM) written.", LogType.Log);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────
|
||||
// Cutscene data (version 12)
|
||||
// ──────────────────────────────────────────────────────
|
||||
if (cutsceneCount > 0)
|
||||
{
|
||||
PSXCutsceneExporter.ExportCutscenes(
|
||||
writer,
|
||||
scene.cutscenes,
|
||||
scene.exporters,
|
||||
scene.audioSources,
|
||||
scene.gteScaling,
|
||||
out long cutsceneTableActual,
|
||||
log);
|
||||
|
||||
// Backfill cutscene table offset in header
|
||||
if (cutsceneTableActual != 0)
|
||||
{
|
||||
long curPos = writer.BaseStream.Position;
|
||||
writer.Seek((int)cutsceneTableOffsetPos, SeekOrigin.Begin);
|
||||
writer.Write((uint)cutsceneTableActual);
|
||||
writer.Seek((int)curPos, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill offsets
|
||||
BackfillOffsets(writer, luaOffset, "lua", log);
|
||||
BackfillOffsets(writer, meshOffset, "mesh", log);
|
||||
|
||||
14
Runtime/PSXTrackType.cs
Normal file
14
Runtime/PSXTrackType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Cutscene track types. Must match the C++ TrackType enum in cutscene.hh.
|
||||
/// </summary>
|
||||
public enum PSXTrackType : byte
|
||||
{
|
||||
CameraPosition = 0,
|
||||
CameraRotation = 1,
|
||||
ObjectPosition = 2,
|
||||
ObjectRotationY = 3,
|
||||
ObjectActive = 4,
|
||||
}
|
||||
}
|
||||
2
Runtime/PSXTrackType.cs.meta
Normal file
2
Runtime/PSXTrackType.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fec0beba902819b4e8af4a684b908361
|
||||
Reference in New Issue
Block a user