Skip to content

Commit

Permalink
Added memory lod selection point viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Mar 4, 2019
1 parent b32e525 commit 9d05125
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 55 deletions.
18 changes: 18 additions & 0 deletions LodInfo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<RowDefinition Height="1*"/>
<RowDefinition Height="5"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<ListView Grid.Row="0" ItemsSource="{Binding Path=properties, PresentationTraceSources.TraceLevel=High, UpdateSourceTrigger=PropertyChanged}">
Expand Down Expand Up @@ -65,5 +66,22 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

<ListBox Grid.Row="3" ItemsSource="{Binding Path=selections, PresentationTraceSources.TraceLevel=High, UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Key" />
<ColumnDefinition SharedSizeGroup="Name" />
</Grid.ColumnDefinitions>
<TextBlock Margin="2" Text="{Binding Key}" Grid.Column="0"/>
<TextBlock Margin="2" Text="{Binding Value[0]}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>


</Grid>
</UserControl>
169 changes: 114 additions & 55 deletions Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Windows;
using BIS.Core.Math;

namespace ModelPropertyChecker
{
Expand Down Expand Up @@ -164,6 +165,7 @@ public class LOD
public LODResolution resolution { get; set; } = 0;
public List<PropertyException> propertyExceptions { get; set; } = new List<PropertyException>();//Set by PropertyVerifier

public Dictionary<string, List<Vector3P>> selections { get; set; } = new Dictionary<string, List<Vector3P>>();

public int exceptionCount
{
Expand Down Expand Up @@ -205,7 +207,7 @@ public bool hasWarnings



public void loadFromODOL(BinaryReaderEx reader)
public void loadFromODOL(BinaryReaderEx reader, bool readPoints = false)
{
var numProxies = reader.ReadUInt32();
for (int i = 0; i < numProxies; i++)
Expand Down Expand Up @@ -313,6 +315,8 @@ public void loadFromODOL(BinaryReaderEx reader)

}


var tempSelections = new Dictionary<string, List<UInt32>>();
var numSelections = reader.ReadUInt32();
for (int i = 0; i < numSelections; i++)
{
Expand All @@ -338,7 +342,7 @@ public void loadFromODOL(BinaryReaderEx reader)
{
var b = reader.ReadByte();
var expectedDataSize = (uint) (nElements * 4);
var stream = reader.ReadCompressed(expectedDataSize, b==2);
var stream = reader.ReadCompressed(expectedDataSize, b == 2);
}

nElements = reader.ReadInt32(); //vertices
Expand All @@ -347,8 +351,17 @@ public void loadFromODOL(BinaryReaderEx reader)
var b = reader.ReadByte();
var expectedDataSize = (uint) (nElements * 4);
var stream = reader.ReadCompressed(expectedDataSize, b == 2);
}
if (readPoints)
{
var streamB = new BinaryReaderEx(new MemoryStream(stream));

List<UInt32> pointList = new List<UInt32>(nElements);
for (int i2 = 0; i2 < nElements; i2++)
pointList.Add(streamB.ReadUInt32());
tempSelections.Add(selectionName, pointList);
}

}

nElements = reader.ReadInt32();//weights
if (nElements != 0)
Expand Down Expand Up @@ -381,65 +394,89 @@ public void loadFromODOL(BinaryReaderEx reader)
}

reader.BaseStream.Seek(13, SeekOrigin.Current);
var stuff = reader.ReadUInt32();
reader.BaseStream.Seek(stuff, SeekOrigin.Current);

/*

var numPoints = reader.ReadUInt32();
reader.ReadByte();
if (numPoints != 0)
var stuff = reader.ReadUInt32(); //vertex table size, can jump directly to end
if (!readPoints)
{
reader.BaseStream.Seek(stuff, SeekOrigin.Current);
} else
{
throw new NotImplementedException();
}

var numPoints = reader.ReadUInt32();
if (numPoints != 0)
{
var b = reader.ReadByte();
var expectedDataSize = (uint)numPoints*2;
var stream = reader.ReadCompressed(expectedDataSize);// , b == 2
}

reader.BaseStream.Seek(16, SeekOrigin.Current); //uv limits
reader.BaseStream.Seek(16, SeekOrigin.Current); //uv limits

var numUVs = reader.ReadUInt32()-1;
reader.ReadByte();
if (numUVs != 0)
{
//reader.ReadByte();
reader.BaseStream.Seek(4*numUVs, SeekOrigin.Current); //uv limits
}

var numUVs = reader.ReadUInt32();
reader.ReadByte();
if (numUVs != 0)
{
reader.ReadByte();
reader.BaseStream.Seek(4*numUVs, SeekOrigin.Current); //uv limits
}
var secondUV = reader.ReadUInt32()-1;

var secondUV = reader.ReadUInt32();
if (secondUV != 0)
{
throw new NotImplementedException();
}

if (secondUV != 0)
{
throw new NotImplementedException();
}
var numPoints2 = reader.ReadUInt32();
if (numPoints2 != 0)
{
var b = reader.ReadByte();
var expectedDataSize = (uint)numPoints2 * (3 * 4);
var stream = reader.ReadCompressed(expectedDataSize, b == 2);

var numPoints2 = reader.ReadUInt32();
if (numPoints2 != 0)
reader.ReadByte();
for (int i = 0; i < numPoints2; i++)
{
reader.BaseStream.Seek((3*4 + 1)*numPoints2, SeekOrigin.Current);
}
var streamB = new BinaryReaderEx(new MemoryStream(stream));

var numNormals = reader.ReadUInt32();
reader.ReadByte();
if (numNormals != 0)
reader.ReadByte();
for (int i = 0; i < numNormals; i++)
{
reader.BaseStream.Seek(4 * numNormals, SeekOrigin.Current);
}
var array = new Vector3P[numPoints2];
for (int i2 = 0; i2 < numPoints2; i2++)
array[i2] = new Vector3P(streamB.ReadSingle(), streamB.ReadSingle(), streamB.ReadSingle());


foreach (KeyValuePair<string, List<UInt32>> entry in tempSelections)
{
var selectionPoints = new List<Vector3P>(entry.Value.Count);

foreach (UInt32 pointIndex in entry.Value)
{
selectionPoints.Add(array[pointIndex]);
}

reader.BaseStream.Seek(4, SeekOrigin.Current);
var numVertBone = reader.ReadUInt32();
if (numVertBone != 0)

selections.Add(entry.Key, selectionPoints);
}


}
/*
var numNormals = reader.ReadUInt32();
reader.ReadByte();
if (numNormals != 0)
reader.ReadByte();
for (int i = 0; i < numNormals; i++)
{
reader.BaseStream.Seek(4 * numNormals, SeekOrigin.Current);
}
for (int i = 0; i < numVertBone; i++)
{
reader.BaseStream.Seek(4 +(4*2), SeekOrigin.Current);
}*/
reader.BaseStream.Seek(4, SeekOrigin.Current);
var numVertBone = reader.ReadUInt32();
if (numVertBone != 0)
reader.ReadByte();
for (int i = 0; i < numVertBone; i++)
{
reader.BaseStream.Seek(4 +(4*2), SeekOrigin.Current);
}*/
}

reader.BaseStream.Seek(4 + 4 + 1, SeekOrigin.Current);

Expand All @@ -459,6 +496,18 @@ public float loadFromMLOD(BinaryReaderEx reader)
var numNormals = reader.ReadUInt32();
var numFaces = reader.ReadUInt32();
reader.ReadUInt32();

List<Vector3P> pointList = new List<Vector3P>((int)numPoints);

for (int i = 0; i < numPoints; i++)
{
var x = reader.ReadSingle();
var y = reader.ReadSingle();
var z = reader.ReadSingle();
var flags = reader.ReadUInt32();
pointList.Add(new Vector3P(x,y,z));
}

reader.BaseStream.Seek(numPoints * 16, SeekOrigin.Current);
reader.BaseStream.Seek(numNormals * 4 * 3, SeekOrigin.Current);

Expand Down Expand Up @@ -494,6 +543,23 @@ public float loadFromMLOD(BinaryReaderEx reader)
properties.Add(key.ToLower(), new Property(value,valuePos)); //#TODO maybe we also want to keep a version with original casing?
} else
{
if (!tagName.StartsWith("#")) //It's a selection
{
var curPos = reader.BaseStream.Position;

var points = new List<Vector3P>();

for (int i = 0; i < numPoints; i++) //Find the first point
{
if (reader.ReadBoolean())
{
points.Add(pointList[i]);
}
}
selections.Add(tagName, points);
reader.BaseStream.Seek(curPos+tagLen, SeekOrigin.Begin);
}

reader.BaseStream.Seek(tagLen, SeekOrigin.Current);
}
} while (tagName != "#EndOfFile#"); //tagName != "" &&
Expand Down Expand Up @@ -678,7 +744,6 @@ private void loadFromODOL(BinaryReaderEx reader)
reader.BaseStream.Seek(16, SeekOrigin.Current);
reader.BaseStream.Seek(4, SeekOrigin.Current); //#TODO only if >72


reader.BaseStream.Seek(14
+ 4 + 1, SeekOrigin.Current); //#TODO only if >72

Expand All @@ -693,9 +758,6 @@ private void loadFromODOL(BinaryReaderEx reader)

reader.BaseStream.Seek(12*numLods, SeekOrigin.Current);




if (reader.ReadByte() != 0)
{
skipAnimations(reader);
Expand All @@ -708,16 +770,13 @@ private void loadFromODOL(BinaryReaderEx reader)
lodOffs[i] = reader.ReadUInt32();
}




reader.BaseStream.Seek(numLods, SeekOrigin.Current);

for (int i = 0; i < numLods; i++)
{
reader.BaseStream.Seek(lodOffs[i], SeekOrigin.Begin);
LOD x = new LOD();
x.loadFromODOL(reader);
x.loadFromODOL(reader, Math.Abs(lodResolutions[i] - 1e15f) < 0.1);
x.resolution = lodResolutions[i];

if (lods.ContainsKey(x.resolution))
Expand Down

0 comments on commit 9d05125

Please sign in to comment.