mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Auto formatting, some cleanup, some initialization changes.
This commit is contained in:
parent
a2b92f1296
commit
b0f61e6929
5 changed files with 213 additions and 233 deletions
|
|
@ -3,7 +3,7 @@ using SharpGLTF.Schema2;
|
|||
|
||||
namespace Penumbra.Import.Models.Import;
|
||||
|
||||
public class MeshImporter
|
||||
public class MeshImporter(IEnumerable<Node> nodes)
|
||||
{
|
||||
public struct Mesh
|
||||
{
|
||||
|
|
@ -13,7 +13,7 @@ public class MeshImporter
|
|||
public MdlStructs.VertexDeclarationStruct VertexDeclaration;
|
||||
public IEnumerable<byte> VertexBuffer;
|
||||
|
||||
public List<ushort> Indicies;
|
||||
public List<ushort> Indices;
|
||||
|
||||
public List<string>? Bones;
|
||||
|
||||
|
|
@ -33,42 +33,30 @@ public class MeshImporter
|
|||
return importer.Create();
|
||||
}
|
||||
|
||||
private IEnumerable<Node> _nodes;
|
||||
|
||||
private List<MdlStructs.SubmeshStruct> _subMeshes = new();
|
||||
private readonly List<MdlStructs.SubmeshStruct> _subMeshes = [];
|
||||
|
||||
private MdlStructs.VertexDeclarationStruct? _vertexDeclaration;
|
||||
private byte[]? _strides;
|
||||
private ushort _vertexCount = 0;
|
||||
private List<byte>[] _streams;
|
||||
private ushort _vertexCount;
|
||||
private readonly List<byte>[] _streams = [[], [], []];
|
||||
|
||||
private List<ushort> _indices = new();
|
||||
private readonly List<ushort> _indices = [];
|
||||
|
||||
private List<string>? _bones;
|
||||
|
||||
private readonly Dictionary<string, List<MdlStructs.ShapeValueStruct>> _shapeValues = new();
|
||||
|
||||
private MeshImporter(IEnumerable<Node> nodes)
|
||||
{
|
||||
_nodes = nodes;
|
||||
|
||||
// All meshes may use up to 3 byte streams.
|
||||
_streams = new List<byte>[3];
|
||||
for (var streamIndex = 0; streamIndex < 3; streamIndex++)
|
||||
_streams[streamIndex] = new List<byte>();
|
||||
}
|
||||
private readonly Dictionary<string, List<MdlStructs.ShapeValueStruct>> _shapeValues = [];
|
||||
|
||||
private Mesh Create()
|
||||
{
|
||||
foreach (var node in _nodes)
|
||||
foreach (var node in nodes)
|
||||
BuildSubMeshForNode(node);
|
||||
|
||||
ArgumentNullException.ThrowIfNull(_strides);
|
||||
ArgumentNullException.ThrowIfNull(_vertexDeclaration);
|
||||
|
||||
return new Mesh()
|
||||
return new Mesh
|
||||
{
|
||||
MeshStruct = new MdlStructs.MeshStruct()
|
||||
MeshStruct = new MdlStructs.MeshStruct
|
||||
{
|
||||
VertexBufferOffset = [0, (uint)_streams[0].Count, (uint)(_streams[0].Count + _streams[1].Count)],
|
||||
VertexBufferStride = _strides,
|
||||
|
|
@ -76,27 +64,20 @@ public class MeshImporter
|
|||
VertexStreamCount = (byte)_vertexDeclaration.Value.VertexElements
|
||||
.Select(element => element.Stream + 1)
|
||||
.Max(),
|
||||
|
||||
StartIndex = 0,
|
||||
IndexCount = (uint)_indices.Count,
|
||||
|
||||
// TODO: import material names
|
||||
MaterialIndex = 0,
|
||||
|
||||
SubMeshIndex = 0,
|
||||
SubMeshCount = (ushort)_subMeshes.Count,
|
||||
|
||||
BoneTableIndex = 0,
|
||||
},
|
||||
SubMeshStructs = _subMeshes,
|
||||
|
||||
VertexDeclaration = _vertexDeclaration.Value,
|
||||
VertexBuffer = _streams[0].Concat(_streams[1]).Concat(_streams[2]),
|
||||
|
||||
Indicies = _indices,
|
||||
|
||||
Indices = _indices,
|
||||
Bones = _bones,
|
||||
|
||||
ShapeKeys = _shapeValues
|
||||
.Select(pair => new MeshShapeKey()
|
||||
{
|
||||
|
|
@ -128,18 +109,18 @@ public class MeshImporter
|
|||
if (_vertexDeclaration == null)
|
||||
_vertexDeclaration = subMesh.VertexDeclaration;
|
||||
else if (VertexDeclarationMismatch(subMesh.VertexDeclaration, _vertexDeclaration.Value))
|
||||
throw new Exception($"Sub-mesh \"{subMeshName}\" vertex declaration mismatch. All sub-meshes of a mesh must have equivalent vertex declarations.");
|
||||
throw new Exception(
|
||||
$"Sub-mesh \"{subMeshName}\" vertex declaration mismatch. All sub-meshes of a mesh must have equivalent vertex declarations.");
|
||||
|
||||
// Given that strides are derived from declarations, a lack of mismatch in declarations means the strides are fine.
|
||||
// TODO: I mean, given that strides are derivable, might be worth dropping strides from the sub mesh return structure and computing when needed.
|
||||
if (_strides == null)
|
||||
_strides = subMesh.Strides;
|
||||
_strides ??= subMesh.Strides;
|
||||
|
||||
// Merge the sub-mesh streams into the main mesh stream bodies.
|
||||
_vertexCount += subMesh.VertexCount;
|
||||
|
||||
for (var streamIndex = 0; streamIndex < 3; streamIndex++)
|
||||
_streams[streamIndex].AddRange(subMesh.Streams[streamIndex]);
|
||||
foreach (var (stream, subStream) in _streams.Zip(subMesh.Streams))
|
||||
stream.AddRange(subStream);
|
||||
|
||||
// As we're appending vertex data to the buffers, we need to update indices to point into that later block.
|
||||
_indices.AddRange(subMesh.Indices.Select(index => (ushort)(index + vertexOffset)));
|
||||
|
|
@ -149,7 +130,7 @@ public class MeshImporter
|
|||
{
|
||||
if (!_shapeValues.TryGetValue(name, out var meshShapeValues))
|
||||
{
|
||||
meshShapeValues = new();
|
||||
meshShapeValues = [];
|
||||
_shapeValues.Add(name, meshShapeValues);
|
||||
}
|
||||
|
||||
|
|
@ -167,12 +148,13 @@ public class MeshImporter
|
|||
});
|
||||
}
|
||||
|
||||
private bool VertexDeclarationMismatch(MdlStructs.VertexDeclarationStruct a, MdlStructs.VertexDeclarationStruct b)
|
||||
private static bool VertexDeclarationMismatch(MdlStructs.VertexDeclarationStruct a, MdlStructs.VertexDeclarationStruct b)
|
||||
{
|
||||
var elA = a.VertexElements;
|
||||
var elB = b.VertexElements;
|
||||
|
||||
if (elA.Length != elB.Length) return true;
|
||||
if (elA.Length != elB.Length)
|
||||
return true;
|
||||
|
||||
// NOTE: This assumes that elements will always be in the same order. Under the current implementation, that's guaranteed.
|
||||
return elA.Zip(elB).Any(pair =>
|
||||
|
|
@ -200,26 +182,25 @@ public class MeshImporter
|
|||
var meshName = node.Name ?? mesh.Name ?? "(no name)";
|
||||
var primitiveCount = mesh.Primitives.Count;
|
||||
if (primitiveCount != 1)
|
||||
{
|
||||
throw new Exception($"Mesh \"{meshName}\" has {primitiveCount} primitives, expected 1.");
|
||||
}
|
||||
|
||||
var primitive = mesh.Primitives[0];
|
||||
|
||||
// Per glTF specification, an asset with a skin MUST contain skinning attributes on its mesh.
|
||||
var jointsAccessor = primitive.GetVertexAccessor("JOINTS_0");
|
||||
if (jointsAccessor == null)
|
||||
throw new Exception($"Skinned mesh \"{meshName}\" is skinned but does not contain skinning vertex attributes.");
|
||||
var jointsAccessor = primitive.GetVertexAccessor("JOINTS_0")
|
||||
?? throw new Exception($"Skinned mesh \"{meshName}\" is skinned but does not contain skinning vertex attributes.");
|
||||
|
||||
// Build a set of joints that are referenced by this mesh.
|
||||
// TODO: Would be neat to omit 0-weighted joints here, but doing so will require some further work on bone mapping behavior to ensure the unweighted joints can still be resolved to valid bone indices during vertex data construction.
|
||||
var usedJoints = new HashSet<ushort>();
|
||||
foreach (var joints in jointsAccessor.AsVector4Array())
|
||||
{
|
||||
for (var index = 0; index < 4; index++)
|
||||
usedJoints.Add((ushort)joints[index]);
|
||||
}
|
||||
|
||||
// Only initialise the bones list if we're actually going to put something in it.
|
||||
if (_bones == null)
|
||||
_bones = new();
|
||||
_bones ??= [];
|
||||
|
||||
// Build a dictionary of node-specific joint indices mesh-wide bone indices.
|
||||
var nodeBoneMap = new Dictionary<ushort, ushort>();
|
||||
|
|
@ -232,6 +213,7 @@ public class MeshImporter
|
|||
boneIndex = _bones.Count;
|
||||
_bones.Add(jointName);
|
||||
}
|
||||
|
||||
nodeBoneMap.Add(usedJoint, (ushort)boneIndex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using SharpGLTF.Schema2;
|
|||
|
||||
namespace Penumbra.Import.Models.Import;
|
||||
|
||||
public partial class ModelImporter
|
||||
public partial class ModelImporter(ModelRoot _model)
|
||||
{
|
||||
public static MdlFile Import(ModelRoot model)
|
||||
{
|
||||
|
|
@ -13,29 +13,22 @@ public partial class ModelImporter
|
|||
}
|
||||
|
||||
// NOTE: This is intended to match TexTool's grouping regex, ".*[_ ^]([0-9]+)[\\.\\-]?([0-9]+)?$"
|
||||
[GeneratedRegex(@"[_ ^](?'Mesh'[0-9]+)[.-]?(?'SubMesh'[0-9]+)?$", RegexOptions.Compiled)]
|
||||
[GeneratedRegex(@"[_ ^](?'Mesh'[0-9]+)[.-]?(?'SubMesh'[0-9]+)?$", RegexOptions.Compiled | RegexOptions.NonBacktracking | RegexOptions.ExplicitCapture)]
|
||||
private static partial Regex MeshNameGroupingRegex();
|
||||
|
||||
private readonly ModelRoot _model;
|
||||
private readonly List<MdlStructs.MeshStruct> _meshes = [];
|
||||
private readonly List<MdlStructs.SubmeshStruct> _subMeshes = [];
|
||||
|
||||
private List<MdlStructs.MeshStruct> _meshes = new();
|
||||
private List<MdlStructs.SubmeshStruct> _subMeshes = new();
|
||||
private readonly List<MdlStructs.VertexDeclarationStruct> _vertexDeclarations = [];
|
||||
private readonly List<byte> _vertexBuffer = [];
|
||||
|
||||
private List<MdlStructs.VertexDeclarationStruct> _vertexDeclarations = new();
|
||||
private List<byte> _vertexBuffer = new();
|
||||
private readonly List<ushort> _indices = [];
|
||||
|
||||
private List<ushort> _indices = new();
|
||||
private readonly List<string> _bones = [];
|
||||
private readonly List<MdlStructs.BoneTableStruct> _boneTables = [];
|
||||
|
||||
private List<string> _bones = new();
|
||||
private List<MdlStructs.BoneTableStruct> _boneTables = new();
|
||||
|
||||
private Dictionary<string, List<MdlStructs.ShapeMeshStruct>> _shapeMeshes = new();
|
||||
private List<MdlStructs.ShapeValueStruct> _shapeValues = new();
|
||||
|
||||
private ModelImporter(ModelRoot model)
|
||||
{
|
||||
_model = model;
|
||||
}
|
||||
private readonly Dictionary<string, List<MdlStructs.ShapeMeshStruct>> _shapeMeshes = [];
|
||||
private readonly List<MdlStructs.ShapeValueStruct> _shapeValues = [];
|
||||
|
||||
private MdlFile Create()
|
||||
{
|
||||
|
|
@ -43,7 +36,7 @@ public partial class ModelImporter
|
|||
foreach (var subMeshNodes in GroupedMeshNodes())
|
||||
BuildMeshForGroup(subMeshNodes);
|
||||
|
||||
// Now that all of the meshes have been built, we can build some of the model-wide metadata.
|
||||
// Now that all the meshes have been built, we can build some of the model-wide metadata.
|
||||
var shapes = new List<MdlFile.Shape>();
|
||||
var shapeMeshes = new List<MdlStructs.ShapeMeshStruct>();
|
||||
foreach (var (keyName, keyMeshes) in _shapeMeshes)
|
||||
|
|
@ -60,64 +53,53 @@ public partial class ModelImporter
|
|||
|
||||
var indexBuffer = _indices.SelectMany(BitConverter.GetBytes).ToArray();
|
||||
|
||||
var emptyBoundingBox = new MdlStructs.BoundingBoxStruct()
|
||||
{
|
||||
Min = [0, 0, 0, 0],
|
||||
Max = [0, 0, 0, 0],
|
||||
};
|
||||
|
||||
// And finally, the MdlFile itself.
|
||||
return new MdlFile()
|
||||
return new MdlFile
|
||||
{
|
||||
VertexOffset = [0, 0, 0],
|
||||
VertexBufferSize = [(uint)_vertexBuffer.Count, 0, 0],
|
||||
IndexOffset = [(uint)_vertexBuffer.Count, 0, 0],
|
||||
IndexBufferSize = [(uint)indexBuffer.Length, 0, 0],
|
||||
|
||||
VertexDeclarations = _vertexDeclarations.ToArray(),
|
||||
Meshes = _meshes.ToArray(),
|
||||
SubMeshes = _subMeshes.ToArray(),
|
||||
|
||||
BoneTables = _boneTables.ToArray(),
|
||||
Bones = _bones.ToArray(),
|
||||
VertexDeclarations = [.. _vertexDeclarations],
|
||||
Meshes = [.. _meshes],
|
||||
SubMeshes = [.. _subMeshes],
|
||||
BoneTables = [.. _boneTables],
|
||||
Bones = [.. _bones],
|
||||
// TODO: Game doesn't seem to rely on this, but would be good to populate.
|
||||
SubMeshBoneMap = [],
|
||||
|
||||
Shapes = shapes.ToArray(),
|
||||
ShapeMeshes = shapeMeshes.ToArray(),
|
||||
ShapeValues = _shapeValues.ToArray(),
|
||||
|
||||
Shapes = [.. shapes],
|
||||
ShapeMeshes = [.. shapeMeshes],
|
||||
ShapeValues = [.. _shapeValues],
|
||||
LodCount = 1,
|
||||
|
||||
Lods = [new MdlStructs.LodStruct()
|
||||
Lods =
|
||||
[
|
||||
new MdlStructs.LodStruct
|
||||
{
|
||||
MeshIndex = 0,
|
||||
MeshCount = (ushort)_meshes.Count,
|
||||
|
||||
ModelLodRange = 0,
|
||||
TextureLodRange = 0,
|
||||
|
||||
VertexDataOffset = 0,
|
||||
VertexBufferSize = (uint)_vertexBuffer.Count,
|
||||
IndexDataOffset = (uint)_vertexBuffer.Count,
|
||||
IndexBufferSize = (uint)indexBuffer.Length,
|
||||
}],
|
||||
},
|
||||
],
|
||||
|
||||
// TODO: Would be good to populate from gltf material names.
|
||||
Materials = ["/NO_MATERIAL"],
|
||||
|
||||
// TODO: Would be good to calculate all of this up the tree.
|
||||
Radius = 1,
|
||||
BoundingBoxes = emptyBoundingBox,
|
||||
BoneBoundingBoxes = Enumerable.Repeat(emptyBoundingBox, _bones.Count).ToArray(),
|
||||
|
||||
BoundingBoxes = MdlFile.EmptyBoundingBox,
|
||||
BoneBoundingBoxes = Enumerable.Repeat(MdlFile.EmptyBoundingBox, _bones.Count).ToArray(),
|
||||
RemainingData = [.._vertexBuffer, ..indexBuffer],
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary> Returns an iterator over sorted, grouped mesh nodes. </summary>
|
||||
private IEnumerable<IEnumerable<Node>> GroupedMeshNodes() =>
|
||||
_model.LogicalNodes
|
||||
private IEnumerable<IEnumerable<Node>> GroupedMeshNodes()
|
||||
=> _model.LogicalNodes
|
||||
.Where(node => node.Mesh != null)
|
||||
.Select(node =>
|
||||
{
|
||||
|
|
@ -163,22 +145,21 @@ public partial class ModelImporter
|
|||
.ToArray(),
|
||||
});
|
||||
|
||||
foreach (var subMesh in mesh.SubMeshStructs)
|
||||
_subMeshes.Add(subMesh with
|
||||
_subMeshes.AddRange(mesh.SubMeshStructs.Select(m => m with
|
||||
{
|
||||
IndexOffset = (uint)(subMesh.IndexOffset + indexOffset),
|
||||
});
|
||||
IndexOffset = (uint)(m.IndexOffset + indexOffset),
|
||||
}));
|
||||
|
||||
_vertexDeclarations.Add(mesh.VertexDeclaration);
|
||||
_vertexBuffer.AddRange(mesh.VertexBuffer);
|
||||
|
||||
_indices.AddRange(mesh.Indicies);
|
||||
_indices.AddRange(mesh.Indices);
|
||||
|
||||
foreach (var meshShapeKey in mesh.ShapeKeys)
|
||||
{
|
||||
if (!_shapeMeshes.TryGetValue(meshShapeKey.Name, out var shapeMeshes))
|
||||
{
|
||||
shapeMeshes = new();
|
||||
shapeMeshes = [];
|
||||
_shapeMeshes.Add(meshShapeKey.Name, shapeMeshes);
|
||||
}
|
||||
|
||||
|
|
@ -203,6 +184,7 @@ public partial class ModelImporter
|
|||
boneIndex = _bones.Count;
|
||||
_bones.Add(boneName);
|
||||
}
|
||||
|
||||
boneIndices.Add((ushort)boneIndex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class SubMeshImporter
|
|||
|
||||
private List<VertexAttribute>? _attributes;
|
||||
|
||||
private ushort _vertexCount = 0;
|
||||
private ushort _vertexCount;
|
||||
private byte[] _strides = [0, 0, 0];
|
||||
private readonly List<byte>[] _streams;
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class SubMeshImporter
|
|||
// All meshes may use up to 3 byte streams.
|
||||
_streams = new List<byte>[3];
|
||||
for (var streamIndex = 0; streamIndex < 3; streamIndex++)
|
||||
_streams[streamIndex] = new List<byte>();
|
||||
_streams[streamIndex] = [];
|
||||
}
|
||||
|
||||
private SubMesh Create()
|
||||
|
|
@ -93,18 +93,14 @@ public class SubMeshImporter
|
|||
BoneStartIndex = 0,
|
||||
BoneCount = 0,
|
||||
},
|
||||
|
||||
VertexDeclaration = new MdlStructs.VertexDeclarationStruct()
|
||||
{
|
||||
VertexElements = _attributes.Select(attribute => attribute.Element).ToArray(),
|
||||
},
|
||||
|
||||
VertexCount = _vertexCount,
|
||||
Strides = _strides,
|
||||
Streams = _streams,
|
||||
|
||||
Indices = _indices,
|
||||
|
||||
ShapeValues = _shapeValues,
|
||||
};
|
||||
}
|
||||
|
|
@ -119,11 +115,12 @@ public class SubMeshImporter
|
|||
var accessors = _primitive.VertexAccessors;
|
||||
|
||||
var morphAccessors = Enumerable.Range(0, _primitive.MorphTargetsCount)
|
||||
.Select(index => _primitive.GetMorphTargetAccessors(index));
|
||||
.Select(index => _primitive.GetMorphTargetAccessors(index)).ToList();
|
||||
|
||||
// Try to build all the attributes the mesh might use.
|
||||
// The order here is chosen to match a typical model's element order.
|
||||
var rawAttributes = new[] {
|
||||
var rawAttributes = new[]
|
||||
{
|
||||
VertexAttribute.Position(accessors, morphAccessors),
|
||||
VertexAttribute.BlendWeight(accessors),
|
||||
VertexAttribute.BlendIndex(accessors, _nodeBoneMap),
|
||||
|
|
@ -134,10 +131,17 @@ public class SubMeshImporter
|
|||
};
|
||||
|
||||
var attributes = new List<VertexAttribute>();
|
||||
var offsets = new byte[] { 0, 0, 0 };
|
||||
var offsets = new byte[]
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
foreach (var attribute in rawAttributes)
|
||||
{
|
||||
if (attribute == null) continue;
|
||||
if (attribute == null)
|
||||
continue;
|
||||
|
||||
attributes.Add(attribute.WithOffset(offsets[attribute.Stream]));
|
||||
offsets[attribute.Stream] += attribute.Size;
|
||||
}
|
||||
|
|
@ -177,7 +181,7 @@ public class SubMeshImporter
|
|||
BuildShapeValues(morphModifiedVertices);
|
||||
}
|
||||
|
||||
private void BuildShapeValues(List<int>[] morphModifiedVertices)
|
||||
private void BuildShapeValues(IEnumerable<List<int>> morphModifiedVertices)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(_indices);
|
||||
ArgumentNullException.ThrowIfNull(_attributes);
|
||||
|
|
@ -198,12 +202,11 @@ public class SubMeshImporter
|
|||
// Find any indices that target this vertex index and create a mapping.
|
||||
var targetingIndices = _indices.WithIndex()
|
||||
.SelectWhere(pair => (pair.Value == vertexIndex, pair.Index));
|
||||
foreach (var targetingIndex in targetingIndices)
|
||||
shapeValues.Add(new MdlStructs.ShapeValueStruct()
|
||||
shapeValues.AddRange(targetingIndices.Select(targetingIndex => new MdlStructs.ShapeValueStruct
|
||||
{
|
||||
BaseIndicesIndex = (ushort)targetingIndex,
|
||||
ReplacingVertexIndex = _vertexCount,
|
||||
});
|
||||
}));
|
||||
|
||||
_vertexCount++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,22 @@ public class VertexAttribute
|
|||
{
|
||||
/// <summary> XIV vertex element metadata structure. </summary>
|
||||
public readonly MdlStructs.VertexElement Element;
|
||||
|
||||
/// <summary> Build a byte array containing this vertex attribute's data for the specified vertex index. </summary>
|
||||
public readonly BuildFn Build;
|
||||
|
||||
/// <summary> Check if the specified morph target index contains a morph for the specified vertex index. </summary>
|
||||
public readonly HasMorphFn HasMorph;
|
||||
|
||||
/// <summary> Build a byte array containing this vertex attribute's data, as modified by the specified morph target, for the specified vertex index. </summary>
|
||||
public readonly BuildMorphFn BuildMorph;
|
||||
|
||||
public byte Stream => Element.Stream;
|
||||
public byte Stream
|
||||
=> Element.Stream;
|
||||
|
||||
/// <summary> Size in bytes of a single vertex's attribute value. </summary>
|
||||
public byte Size => (MdlFile.VertexType)Element.Type switch
|
||||
public byte Size
|
||||
=> (MdlFile.VertexType)Element.Type switch
|
||||
{
|
||||
MdlFile.VertexType.Single3 => 12,
|
||||
MdlFile.VertexType.Single4 => 16,
|
||||
|
|
@ -48,19 +53,24 @@ public class VertexAttribute
|
|||
BuildMorph = buildMorph ?? DefaultBuildMorph;
|
||||
}
|
||||
|
||||
public VertexAttribute WithOffset(byte offset) => new VertexAttribute(
|
||||
public VertexAttribute WithOffset(byte offset)
|
||||
=> new(
|
||||
Element with { Offset = offset },
|
||||
Build,
|
||||
HasMorph,
|
||||
BuildMorph
|
||||
);
|
||||
|
||||
// We assume that attributes don't have morph data unless explicitly configured.
|
||||
private static bool DefaultHasMorph(int morphIndex, int vertexIndex) => false;
|
||||
/// <remarks> We assume that attributes don't have morph data unless explicitly configured. </remarks>
|
||||
private static bool DefaultHasMorph(int morphIndex, int vertexIndex)
|
||||
=> false;
|
||||
|
||||
// XIV stores shapes as full vertex replacements, so all attributes need to output something for a morph.
|
||||
// As a fallback, we're just building the normal vertex data for the index.
|
||||
private byte[] DefaultBuildMorph(int morphIndex, int vertexIndex) => Build(vertexIndex);
|
||||
/// <remarks>
|
||||
/// XIV stores shapes as full vertex replacements, so all attributes need to output something for a morph.
|
||||
/// As a fallback, we're just building the normal vertex data for the index.
|
||||
/// </remarks>>
|
||||
private byte[] DefaultBuildMorph(int morphIndex, int vertexIndex)
|
||||
=> Build(vertexIndex);
|
||||
|
||||
public static VertexAttribute Position(Accessors accessors, IEnumerable<Accessors> morphAccessors)
|
||||
{
|
||||
|
|
@ -77,22 +87,22 @@ public class VertexAttribute
|
|||
var values = accessor.AsVector3Array();
|
||||
|
||||
var morphValues = morphAccessors
|
||||
.Select(accessors => accessors.GetValueOrDefault("POSITION")?.AsVector3Array())
|
||||
.Select(a => a.GetValueOrDefault("POSITION")?.AsVector3Array())
|
||||
.ToArray();
|
||||
|
||||
return new VertexAttribute(
|
||||
element,
|
||||
index => BuildSingle3(values[index]),
|
||||
|
||||
hasMorph: (morphIndex, vertexIndex) =>
|
||||
(morphIndex, vertexIndex) =>
|
||||
{
|
||||
var deltas = morphValues[morphIndex];
|
||||
if (deltas == null) return false;
|
||||
if (deltas == null)
|
||||
return false;
|
||||
|
||||
var delta = deltas[vertexIndex];
|
||||
return delta != Vector3.Zero;
|
||||
},
|
||||
|
||||
buildMorph: (morphIndex, vertexIndex) =>
|
||||
(morphIndex, vertexIndex) =>
|
||||
{
|
||||
var value = values[vertexIndex];
|
||||
|
||||
|
|
@ -178,13 +188,12 @@ public class VertexAttribute
|
|||
var values = accessor.AsVector3Array();
|
||||
|
||||
var morphValues = morphAccessors
|
||||
.Select(accessors => accessors.GetValueOrDefault("NORMAL")?.AsVector3Array())
|
||||
.Select(a => a.GetValueOrDefault("NORMAL")?.AsVector3Array())
|
||||
.ToArray();
|
||||
|
||||
return new VertexAttribute(
|
||||
element,
|
||||
index => BuildHalf4(new Vector4(values[index], 0)),
|
||||
|
||||
buildMorph: (morphIndex, vertexIndex) =>
|
||||
{
|
||||
var value = values[vertexIndex];
|
||||
|
|
@ -249,13 +258,12 @@ public class VertexAttribute
|
|||
|
||||
// Per glTF specification, TANGENT morph values are stored as vec3, with the W component always considered to be 0.
|
||||
var morphValues = morphAccessors
|
||||
.Select(accessors => accessors.GetValueOrDefault("TANGENT")?.AsVector3Array())
|
||||
.Select(a => a.GetValueOrDefault("TANGENT")?.AsVector3Array())
|
||||
.ToArray();
|
||||
|
||||
return new VertexAttribute(
|
||||
element,
|
||||
index => BuildByteFloat4(values[index]),
|
||||
|
||||
buildMorph: (morphIndex, vertexIndex) =>
|
||||
{
|
||||
var value = values[vertexIndex];
|
||||
|
|
@ -289,14 +297,16 @@ public class VertexAttribute
|
|||
);
|
||||
}
|
||||
|
||||
private static byte[] BuildSingle3(Vector3 input) =>
|
||||
private static byte[] BuildSingle3(Vector3 input)
|
||||
=>
|
||||
[
|
||||
..BitConverter.GetBytes(input.X),
|
||||
..BitConverter.GetBytes(input.Y),
|
||||
..BitConverter.GetBytes(input.Z),
|
||||
];
|
||||
|
||||
private static byte[] BuildUInt(Vector4 input) =>
|
||||
private static byte[] BuildUInt(Vector4 input)
|
||||
=>
|
||||
[
|
||||
(byte)input.X,
|
||||
(byte)input.Y,
|
||||
|
|
@ -304,7 +314,8 @@ public class VertexAttribute
|
|||
(byte)input.W,
|
||||
];
|
||||
|
||||
private static byte[] BuildByteFloat4(Vector4 input) =>
|
||||
private static byte[] BuildByteFloat4(Vector4 input)
|
||||
=>
|
||||
[
|
||||
(byte)Math.Round(input.X * 255f),
|
||||
(byte)Math.Round(input.Y * 255f),
|
||||
|
|
@ -312,13 +323,15 @@ public class VertexAttribute
|
|||
(byte)Math.Round(input.W * 255f),
|
||||
];
|
||||
|
||||
private static byte[] BuildHalf2(Vector2 input) =>
|
||||
private static byte[] BuildHalf2(Vector2 input)
|
||||
=>
|
||||
[
|
||||
..BitConverter.GetBytes((Half)input.X),
|
||||
..BitConverter.GetBytes((Half)input.Y),
|
||||
];
|
||||
|
||||
private static byte[] BuildHalf4(Vector4 input) =>
|
||||
private static byte[] BuildHalf4(Vector4 input)
|
||||
=>
|
||||
[
|
||||
..BitConverter.GetBytes((Half)input.X),
|
||||
..BitConverter.GetBytes((Half)input.Y),
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class MultiModPanel(ModFileSystemSelector _selector, ModDataEditor _edito
|
|||
ImGui.TableNextColumn();
|
||||
var icon = (path is ModFileSystem.Leaf ? FontAwesomeIcon.FileCircleMinus : FontAwesomeIcon.FolderMinus).ToIconString();
|
||||
if (ImGuiUtil.DrawDisabledButton(icon, new Vector2(sizeType), "Remove from selection.", false, true))
|
||||
_selector.RemovePathFromMultiselection(path);
|
||||
_selector.RemovePathFromMultiSelection(path);
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue