Skip to content

Commit

Permalink
Adjust whitespace and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Exter-N committed Sep 10, 2023
1 parent cd34140 commit 98db98e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
18 changes: 14 additions & 4 deletions src/Lumina/Data/Parsing/MdlStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,25 @@ public static ShapeStruct Read( LuminaBinaryReader br )

public struct ShapeMeshStruct
{
public uint MeshIndexOffset; // from TT: The offset to the index block this Shape Data should be replacing in. -- This is how Shape Data is tied to each mesh.
/// <summary>
/// From TT: The offset to the index block this Shape Data should be replacing in.
/// This is how Shape Data is tied to each mesh.
/// </summary>
public uint MeshIndexOffset;
public uint ShapeValueCount;
public uint ShapeValueOffset;
}

public struct ShapeValueStruct
{
public ushort BaseIndicesIndex; // PROBABLY: Index into the Indices array of a mesh.
public ushort ReplacingVertexIndex; // PROBABLY: Index into the (without transformation probably unused) vertex of a mesh.
/// <summary>
/// PROBABLY: Index into the Indices array of a mesh.
/// </summary>
public ushort BaseIndicesIndex;
/// <summary>
/// PROBABLY: Index into the (without transformation probably unused) vertex of a mesh.
/// </summary>
public ushort ReplacingVertexIndex;
}

public struct BoundingBoxStruct
Expand All @@ -362,4 +372,4 @@ public static BoundingBoxStruct Read( LuminaBinaryReader br )
}
}
}
}
}
7 changes: 5 additions & 2 deletions src/Lumina/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ public T GetFileFromDisk< T >( string path, string? origPath = null ) where T :

var file = Activator.CreateInstance< T >();
file.Data = fileContent;
if( origPath != null ) file.FilePath = ParseFilePath( origPath )!;
if( origPath != null )
{
file.FilePath = ParseFilePath( origPath )!;
}
file.Reader = new LuminaBinaryReader( file.Data, Options.CurrentPlatform );
file.LoadFile();

Expand Down Expand Up @@ -322,4 +325,4 @@ internal static void SetCurrentContext( GameData gameData )
CurrentContext = new(() => gameData);
}
}
}
}
6 changes: 3 additions & 3 deletions src/Lumina/Models/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void BuildModel()
ReadStrings();
ReadMaterials();
ReadMeshes();
ReadShapes(Meshes);
ReadShapes( Meshes );
}

/// <summary>
Expand Down Expand Up @@ -127,7 +127,7 @@ private void ReadMaterials()
}
}

private void ReadShapes(IReadOnlyList<Mesh> meshes )
private void ReadShapes( IReadOnlyList< Mesh > meshes )
{
if( File == null )
{
Expand Down Expand Up @@ -255,4 +255,4 @@ public Mesh[] GetMeshesByType( Mesh.MeshType mp )
return Meshes.Where( m => m.Types.Contains( mp ) ).ToArray();
}
}
}
}
32 changes: 17 additions & 15 deletions src/Lumina/Models/Models/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
namespace Lumina.Models.Models
{
public struct ShapeMesh {
public Mesh AssociatedMesh;
public (ushort BaseIndicesIndex, ushort ReplacedVertexIndex)[] Values;
public Mesh AssociatedMesh;

public static IReadOnlyList< ShapeMesh > ConstructList( MdlFile file, IReadOnlyList<Mesh> meshes )
public ( ushort BaseIndicesIndex, ushort ReplacedVertexIndex )[] Values;

public static IReadOnlyList< ShapeMesh > ConstructList( MdlFile file, IReadOnlyList< Mesh > meshes )
{
var ret = new ShapeMesh[file.ModelHeader.ShapeMeshCount];
var idx = 0;
var ret = new ShapeMesh[ file.ModelHeader.ShapeMeshCount ];
var idx = 0;

var meshDict = meshes.ToDictionary( m => file.Meshes[ m.MeshIndex ].StartIndex, m => m );

foreach( var shapeMeshStruct in file.ShapeMeshes ) {

if( !meshDict.TryGetValue( shapeMeshStruct.MeshIndexOffset, out var mesh ) ) continue;

var values = Enumerable.Range( (int)shapeMeshStruct.ShapeValueOffset, (int) shapeMeshStruct.ShapeValueCount )
.Select( i => ( file.ShapeValues[i].BaseIndicesIndex, file.ShapeValues[i].ReplacingVertexIndex) )
var values = Enumerable
.Range( (int)shapeMeshStruct.ShapeValueOffset, (int)shapeMeshStruct.ShapeValueCount )
.Select( i => ( file.ShapeValues[ i ].BaseIndicesIndex, file.ShapeValues[ i ].ReplacingVertexIndex ) )
.ToArray();

ret[idx++] = new ShapeMesh {
ret[ idx++ ] = new ShapeMesh {
AssociatedMesh = mesh,
Values = values,
};
Expand All @@ -37,16 +39,16 @@ public class Shape {
public string Name { get; private set; }
public ShapeMesh[] Meshes { get; private set; }

public Shape(Model model, Model.ModelLod lod, IReadOnlyList<ShapeMesh> shapeMeshes, int shapeIndex)
public Shape( Model model, Model.ModelLod lod, IReadOnlyList< ShapeMesh > shapeMeshes, int shapeIndex )
{
var currentShape = model.File.Shapes[ shapeIndex ];

Check warning on line 44 in src/Lumina/Models/Models/Shape.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
Name = model.StringOffsetToStringMap[ (int) currentShape.StringOffset ];
Meshes = new ShapeMesh[currentShape.ShapeMeshCount[ (int) lod ]];
var end = currentShape.ShapeMeshCount[(int)lod];
var offset = currentShape.ShapeMeshStartIndex[(int)lod];
Name = model.StringOffsetToStringMap[ (int)currentShape.StringOffset ];
Meshes = new ShapeMesh[ currentShape.ShapeMeshCount[ (int)lod ] ];
var end = currentShape.ShapeMeshCount[ (int)lod ];
var offset = currentShape.ShapeMeshStartIndex[ (int)lod ];
for( var i = 0; i < end; ++i ) {
Meshes[ i ] = shapeMeshes[i + offset];
Meshes[ i ] = shapeMeshes[ i + offset ];
}
}
}
}
}

0 comments on commit 98db98e

Please sign in to comment.