feat(core): add SetupMesh.Flatten for single-level part hierarchy
This commit is contained in:
parent
473a06c534
commit
8f5b498be6
2 changed files with 155 additions and 0 deletions
45
src/AcDream.Core/Meshing/SetupMesh.cs
Normal file
45
src/AcDream.Core/Meshing/SetupMesh.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System.Numerics;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
using DatReaderWriter.Enums;
|
||||
using DatReaderWriter.Types;
|
||||
|
||||
namespace AcDream.Core.Meshing;
|
||||
|
||||
public static class SetupMesh
|
||||
{
|
||||
/// <summary>
|
||||
/// Flatten a Setup into a list of (GfxObjId, PartTransform) refs.
|
||||
/// Uses the default placement frame and DefaultScale per part.
|
||||
/// Does NOT walk ParentIndex — each part's transform is local to the setup root.
|
||||
/// This is simplification for Phase 2; complex hierarchical rigs are Phase 3.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<MeshRef> Flatten(Setup setup)
|
||||
{
|
||||
AnimationFrame? defaultAnim = null;
|
||||
if (setup.PlacementFrames.TryGetValue(Placement.Default, out var af))
|
||||
defaultAnim = af;
|
||||
|
||||
var result = new List<MeshRef>(setup.Parts.Count);
|
||||
for (int i = 0; i < setup.Parts.Count; i++)
|
||||
{
|
||||
uint gfxObjId = (uint)setup.Parts[i];
|
||||
|
||||
Frame frame;
|
||||
if (defaultAnim is not null && i < defaultAnim.Frames.Count)
|
||||
frame = defaultAnim.Frames[i];
|
||||
else
|
||||
frame = new Frame { Origin = Vector3.Zero, Orientation = Quaternion.Identity };
|
||||
|
||||
Vector3 scale = i < setup.DefaultScale.Count ? setup.DefaultScale[i] : Vector3.One;
|
||||
|
||||
var transform =
|
||||
Matrix4x4.CreateScale(scale) *
|
||||
Matrix4x4.CreateFromQuaternion(frame.Orientation) *
|
||||
Matrix4x4.CreateTranslation(frame.Origin);
|
||||
|
||||
result.Add(new MeshRef(gfxObjId, transform));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue