Skip to content

Commit 36dc678

Browse files
committed
Polychunks now get added to offset luts
1 parent e316f18 commit 36dc678

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/SA3D.Modeling/Mesh/Chunk/ChunkMesh.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ public override bool CanWrite(Format format)
182182
public override void Read(BinaryObjectReader reader, IOContext context)
183183
{
184184
VertexChunks = reader.ReadLUTItemAtOffset(reader.ReadOffsetValue(), context.PointerLUT, VertexChunksLabelPrefix, VertexChunk.ReadArray);
185-
PolyChunks = reader.ReadLUTItemAtOffset(reader.ReadOffsetValue(), context.PointerLUT, PolyChunksLabelPrefix, PolyChunk.ReadArray);
185+
PolyChunks = reader.ReadLUTItemAtOffset(reader.ReadOffsetValue(), context.PointerLUT, PolyChunksLabelPrefix, (r) => PolyChunk.ReadArray(r, context.PointerLUT));
186186
MeshBounds = reader.ReadObject<Bounds>();
187187
}
188188

189189
/// <inheritdoc/>
190190
public override void Write(BinaryObjectWriter writer, IOContext context)
191191
{
192192
writer.WriteObjectOffset(VertexChunks.EmptyNull(), VertexChunk.WriteArray, context.PointerLUT);
193-
writer.WriteObjectOffset(PolyChunks.EmptyNull(), PolyChunk.WriteArray, context.PointerLUT);
193+
writer.WriteObjectOffset(PolyChunks.EmptyNull(), (w, v) => PolyChunk.WriteArray(w, v, context.PointerLUT), context.PointerLUT);
194194
writer.WriteObject(MeshBounds);
195195
}
196196

src/SA3D.Modeling/Mesh/Chunk/PolyChunk.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Amicitia.IO.Binary;
1+
using Amicitia.IO;
2+
using Amicitia.IO.Binary;
23
using Amicitia.IO.Streams;
34
using J113D.Json;
45
using SA3D.Common;
@@ -181,7 +182,7 @@ public virtual void Read(BinaryObjectReader reader)
181182
Attributes = (byte)(header >> 8);
182183
}
183184

184-
internal static LabeledArray<PolyChunk> ReadArray(BinaryObjectReader reader)
185+
internal static LabeledArray<PolyChunk> ReadArray(BinaryObjectReader reader, PointerLUT lut)
185186
{
186187
PolyChunkType peekType()
187188
{
@@ -194,6 +195,7 @@ PolyChunkType peekType()
194195
while(true)
195196
{
196197
PolyChunk chunk;
198+
long offset = reader.ReadOffsetValue();
197199
switch(peekType())
198200
{
199201
case PolyChunkType.BlendAlpha:
@@ -265,6 +267,7 @@ PolyChunkType peekType()
265267
}
266268

267269
chunks.Add(chunk);
270+
lut.PolyChunks.Add(offset, chunk);
268271
}
269272

270273
End:
@@ -282,10 +285,19 @@ public virtual void Write(BinaryObjectWriter writer)
282285
writer.WriteUInt16((ushort)((byte)Type | (Attributes << 8)));
283286
}
284287

285-
internal static void WriteArray(BinaryObjectWriter writer, IEnumerable<PolyChunk> chunks)
288+
internal static void WriteArray(BinaryObjectWriter writer, IEnumerable<PolyChunk> chunks, PointerLUT lut)
286289
{
287290
long start = writer.Position;
288-
writer.WriteObjectArray(chunks);
291+
292+
foreach(PolyChunk chunk in chunks)
293+
{
294+
long offset = chunk.AlignWithFour
295+
? AlignmentHelper.Align(writer.Position, 4)
296+
: writer.Position;
297+
298+
writer.WriteObject(chunk);
299+
lut.PolyChunks.Add(offset, chunk);
300+
}
289301

290302
// End chunk
291303
writer.WriteUInt16((ushort)PolyChunkType.End);

0 commit comments

Comments
 (0)