Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEN level compiler update for animation refactors #845

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0c10463
Initial Commit
Jakub768 Jun 7, 2023
7762070
Update TEN animation format
Sezzary Oct 29, 2023
394a170
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Oct 29, 2023
acf4f0e
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Dec 12, 2023
dbea261
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Apr 17, 2024
f894e02
Sound Catalog amendments
Stranger1992 Jun 24, 2024
de31fb9
Update sound effect writing
Sezzary Jun 25, 2024
729bd93
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Jun 25, 2024
5f1da11
Add TEN Custom Pushable SFX
Stranger1992 Jun 25, 2024
0bdf2b8
Update TEN_ALL_SOUNDS.xml
Stranger1992 Jun 25, 2024
a475b89
Update anim box writing
Sezzary Jun 25, 2024
9cf8144
Add fields for blend frames; update some field names to be 1:1 with TEN
Sezzary Jul 1, 2024
8b88372
Add anim blend types
Sezzary Jul 1, 2024
ad04df4
Update format
Sezzary Jul 2, 2024
1278608
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Jul 2, 2024
db9b5c4
Merge branch 'master' into Sezz_ten_anim_compile_update
Sezzary Jul 2, 2024
3b4e58b
Merge branch 'Sezz_ten_anim_compile_update' of https://github.com/Mon…
Sezzary Jul 2, 2024
d2647fe
Update TombLib.csproj
Stranger1992 Jul 2, 2024
114f579
Update anim data
Sezzary Jul 8, 2024
17258e5
Move BezierCurve2D class
Sezzary Jul 8, 2024
b897c1d
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
39d3091
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
e68b74f
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
182ceb7
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
3485393
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
e40a1eb
Update BezierCurve2D.cs
Sezzary Jul 8, 2024
fccb501
Update BezierCurve2D.cs
Sezzary Jul 11, 2024
31ed5e5
Update TEN level format
Sezzary Jul 13, 2024
3471490
Use Newton-Raphson method for faster approximate bezier curve Y conve…
Sezzary Jul 14, 2024
697c7b1
Update BezierCurve2D.cs
Sezzary Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
583 changes: 571 additions & 12 deletions TombLib/TombLib/Catalogs/TEN Sound Catalogs/TEN_ALL_SOUNDS.xml

Large diffs are not rendered by default.

5,158 changes: 0 additions & 5,158 deletions TombLib/TombLib/Catalogs/TEN Sound Catalogs/TEN_DEFAULT_GLOBAL_HARDCODED.xml

This file was deleted.

4 changes: 2 additions & 2 deletions TombLib/TombLib/Catalogs/TEN Sound Catalogs/TEN_TR1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@
</WadSoundInfo>
<WadSoundInfo>
<Id>1143</Id>
<Name>TR1_SLAMDOOR_OPEN</Name>
<Name>TR1_Slamdoor_Open</Name>
<Volume>100</Volume>
<RangeInSectors>8</RangeInSectors>
<Chance>100</Chance>
Expand All @@ -1823,7 +1823,7 @@
</WadSoundInfo>
<WadSoundInfo>
<Id>1144</Id>
<Name>TR1_SLAMDOOR_CLOSE</Name>
<Name>TR1_Slamdoor_Close</Name>
<Volume>100</Volume>
<RangeInSectors>8</RangeInSectors>
<Chance>100</Chance>
Expand Down
6 changes: 3 additions & 3 deletions TombLib/TombLib/Catalogs/TEN Sound Catalogs/TEN_TR2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3697,7 +3697,7 @@
</WadSoundInfo>
<WadSoundInfo>
<Id>1145</Id>
<Name>TR2_DRAGON_FALL</Name>
<Name>TR2_Dragon_Fall</Name>
<Volume>100</Volume>
<RangeInSectors>20</RangeInSectors>
<Chance>100</Chance>
Expand All @@ -3716,7 +3716,7 @@
</WadSoundInfo>
<WadSoundInfo>
<Id>1146</Id>
<Name>TR2_MARCO_BARTOLLI_TRANSFORM</Name>
<Name>TR2_Marco_Bartolli_Transform</Name>
<Volume>100</Volume>
<RangeInSectors>10</RangeInSectors>
<Chance>100</Chance>
Expand All @@ -3727,7 +3727,7 @@
<LoopBehaviour>None</LoopBehaviour>
<Samples>
<WadSample>
<FileName>tr2_marco_bartolli_transform_01.wav</FileName>
<FileName>TR2_Marco_Bartolli_Transform_01.wav</FileName>
</WadSample>
</Samples>
<Global>true</Global>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ public sealed partial class LevelCompilerTombEngine : LevelCompiler
private readonly ScriptIdTable<IHasScriptID> _scriptingIdsTable;
private readonly List<ushort> _floorData = new List<ushort>();
private readonly List<TombEngineMesh> _meshes = new List<TombEngineMesh>();
private readonly List<TombEngineAnimation> _animations = new List<TombEngineAnimation>();
private readonly List<TombEngineStateChange> _stateChanges = new List<TombEngineStateChange>();
private readonly List<TombEngineAnimDispatch> _animDispatches = new List<TombEngineAnimDispatch>();
private readonly List<short> _animCommands = new List<short>();
private readonly List<int> _meshTrees = new List<int>();
private readonly List<TombEngineKeyFrame> _frames = new List<TombEngineKeyFrame>();
private List<TombEngineMoveable> _moveables = new List<TombEngineMoveable>();
private readonly List<TombEngineStaticMesh> _staticMeshes = new List<TombEngineStaticMesh>();

Expand Down
62 changes: 34 additions & 28 deletions TombLib/TombLib/LevelData/Compilers/TombEngine/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
using System.Numerics;
using System.Runtime.InteropServices;
using TombLib.IO;
using TombLib.Types;
using TombLib.Utils;
using TombLib.Wad;

namespace TombLib.LevelData.Compilers.TombEngine
{
public enum TombEnginePolygonShape : int
{
Quad,
Triangle
}

public enum TombEngineAnimationBlendType
{
Linear,
Smooth,
EaseIn,
EaseOut
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TombEngineSpriteTexture
{
Expand All @@ -23,12 +38,6 @@ public struct TombEngineSpriteTexture
public float Y4;
}

public enum TombEnginePolygonShape : int
{
Quad,
Triangle
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class TombEngineAtlas
{
Expand Down Expand Up @@ -579,51 +588,48 @@ public struct TombEngineMoveable
public int NumMeshes;
public int StartingMesh;
public int MeshTree;
public int FrameOffset;
public int Animation;
public int NumAnimations;
public List<TombEngineAnimation> Animations;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TombEngineStateChange
{
public int StateID;
public int NumAnimDispatches;
public int AnimDispatch;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TombEngineAnimDispatch
{
public int Low;
public int High;
public int FrameLow;
public int FrameHigh;
public int NextAnimation;
public int NextFrame;
public int NextFrameLow;
public int NextFrameHigh;
public int BlendFrameCount;
public BezierCurve2D BlendCurve;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TombEngineAnimation
{
public int FrameOffset;
public int FrameRate;
public int StateID;
public Vector3 VelocityStart;
public Vector3 VelocityEnd;
public int FrameStart;
public int Interpolation;
public int FrameEnd;
public int NextAnimation;
public int NextFrame;
public int NumStateChanges;
public int StateChangeOffset;
public int BlendFrameCount;
public BezierCurve2D BlendCurve;
public Vector3 VelocityStart;
public Vector3 VelocityEnd;
public List<TombEngineKeyFrame> KeyFrames;
public List<TombEngineStateChange> StateChanges;
public int NumAnimCommands;
public int AnimCommand;
public List<object> CommandData;
public int Flags;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class TombEngineKeyFrame
{
public TombEngineBoundingBox BoundingBox;
public Vector3 Offset;
public List<Quaternion> Angles;
public Vector3 RootOffset;
public List<Quaternion> BoneOrientations;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down
106 changes: 75 additions & 31 deletions TombLib/TombLib/LevelData/Compilers/TombEngine/TombEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NAudio.Flac;
using System;
using System.IO;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -78,43 +79,86 @@ private void WriteLevelTombEngine()
}
}

// Write animations' data
writer.Write((uint)_animations.Count);
writer.WriteBlockArray(_animations);
writer.Write((uint)_meshTrees.Count);
writer.WriteBlockArray(_meshTrees);

writer.Write((uint)_stateChanges.Count);
writer.WriteBlockArray(_stateChanges);
writer.Write((uint)_moveables.Count);
foreach (var moveable in _moveables)
{
writer.Write(moveable.ObjectID);
writer.Write(moveable.NumMeshes);
writer.Write(moveable.StartingMesh);
writer.Write(moveable.MeshTree);
writer.Write(moveable.NumAnimations);

writer.Write((uint)_animDispatches.Count);
writer.WriteBlockArray(_animDispatches);
foreach (var animation in moveable.Animations)
{
writer.Write(animation.StateID);
writer.Write(animation.Interpolation);
writer.Write(animation.FrameEnd);
writer.Write(animation.NextAnimation);
writer.Write(animation.NextFrame);
writer.Write(animation.BlendFrameCount);
writer.Write(animation.BlendCurve.Start);
writer.Write(animation.BlendCurve.End);
writer.Write(animation.BlendCurve.StartHandle);
writer.Write(animation.BlendCurve.EndHandle);
writer.Write(animation.VelocityStart);
writer.Write(animation.VelocityEnd);

writer.Write(animation.KeyFrames.Count);
foreach (var keyFrame in animation.KeyFrames)
{
var center = new Vector3(
keyFrame.BoundingBox.X1 + keyFrame.BoundingBox.X2,
keyFrame.BoundingBox.Y1 + keyFrame.BoundingBox.Y2,
keyFrame.BoundingBox.Z1 + keyFrame.BoundingBox.Z2) / 2;
var extents = new Vector3(
keyFrame.BoundingBox.X2 - keyFrame.BoundingBox.X1,
keyFrame.BoundingBox.Y2 - keyFrame.BoundingBox.Y1,
keyFrame.BoundingBox.Z2 - keyFrame.BoundingBox.Z1) / 2;

writer.Write(center);
writer.Write(extents);
writer.Write(keyFrame.RootOffset);
writer.Write((uint)keyFrame.BoneOrientations.Count);

writer.WriteBlockArray(keyFrame.BoneOrientations);
}

writer.Write((uint)_animCommands.Count);
writer.WriteBlockArray(_animCommands);
writer.Write((uint)animation.StateChanges.Count);
foreach (var stateChange in animation.StateChanges)
{
writer.Write(stateChange.StateID);
writer.Write(stateChange.FrameLow);
writer.Write(stateChange.FrameHigh);
writer.Write(stateChange.NextAnimation);
writer.Write(stateChange.NextFrameLow);
writer.Write(stateChange.NextFrameHigh);
writer.Write(stateChange.BlendFrameCount);
writer.Write(stateChange.BlendCurve.Start);
writer.Write(stateChange.BlendCurve.End);
writer.Write(stateChange.BlendCurve.StartHandle);
writer.Write(stateChange.BlendCurve.EndHandle);
}

writer.Write((uint)_meshTrees.Count);
writer.WriteBlockArray(_meshTrees);
writer.Write((uint)animation.NumAnimCommands);
foreach (var element in animation.CommandData)
{
if (element is int intComponent)
{
writer.Write(intComponent);
}
else if (element is Vector3 vector3Component)
{
writer.Write(vector3Component);
}
}

writer.Write((uint)_frames.Count);
foreach (var frame in _frames)
{
writer.Write((short)frame.BoundingBox.X1);
writer.Write((short)frame.BoundingBox.X2);
writer.Write((short)frame.BoundingBox.Y1);
writer.Write((short)frame.BoundingBox.Y2);
writer.Write((short)frame.BoundingBox.Z1);
writer.Write((short)frame.BoundingBox.Z2);
writer.Write((short)frame.Offset.X);
writer.Write((short)frame.Offset.Y);
writer.Write((short)frame.Offset.Z);
writer.Write((short)frame.Angles.Count);
foreach (var angle in frame.Angles)
writer.Write(angle);
writer.Write(animation.Flags);
}
}

writer.Write((uint)_moveables.Count);
for (var k = 0; k < _moveables.Count; k++)
writer.WriteBlock(_moveables[k]);

writer.Write((uint)_staticMeshes.Count);
writer.WriteBlockArray(_staticMeshes);

Expand Down
Loading