Skip to content

Commit

Permalink
Unnecessary LOD "refactor"
Browse files Browse the repository at this point in the history
Not really a refactor.
Probably broke something somewhere but oh well
  • Loading branch information
DeltaDesigns committed Dec 23, 2023
1 parent 8afe94f commit 3f2124c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
10 changes: 3 additions & 7 deletions Charm/StaticView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public void LoadStatic(FileHash hash, ExportDetailLevel detailLevel, Window wind
public static void ExportStatic(FileHash hash, string name, ExportTypeFlag exportType, string extraPath = "")
{
ExporterScene scene = Exporter.Get().CreateScene(name, ExportType.Static);
bool lodexport = false;
ConfigSubsystem config = ConfigSubsystem.Get();
bool sboxModels = config.GetSBoxModelExportEnabled();

string savePath = config.GetExportSavePath() + "/" + extraPath + "/";
string meshName = hash;
Expand All @@ -59,18 +57,16 @@ public static void ExportStatic(FileHash hash, string name, ExportTypeFlag expor
if (exportType == ExportTypeFlag.Full)
{
staticMesh.SaveMaterialsFromParts(scene, parts);
if (sboxModels)
{
SBoxHandler.SaveStaticVMDL($"{savePath}", meshName, parts);
}
SBoxHandler.SaveStaticVMDL($"{savePath}", meshName, parts);
}

bool lodexport = true;
if (lodexport)
{
ExporterScene lodScene = Exporter.Get().CreateScene($"{name}_LOD", ExportType.Static);

List<StaticPart> lodparts = staticMesh.Load(ExportDetailLevel.LeastDetailed);
Directory.CreateDirectory(savePath + "/LOD");
staticMesh.SaveMaterialsFromParts(lodScene, lodparts);

foreach (StaticPart lodpart in lodparts)
{
Expand Down
6 changes: 3 additions & 3 deletions Tiger/Schema/Entity/EntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private Dictionary<int, Dictionary<int, D2Class_CB6E8080>> GetPartsOfDetailLevel
}
else
{
if (eDetailLevel == ExportDetailLevel.MostDetailed && part.LodCategory is ELodCategory.MainGeom0 or ELodCategory.GripStock0 or ELodCategory.Stickers0 or ELodCategory.InternalGeom0 or ELodCategory.Detail0)
if (eDetailLevel == ExportDetailLevel.MostDetailed && part.Lod.IsHighestLevel())
{
parts[meshIndex].Add(partIndex++, part);
}
else if (eDetailLevel == ExportDetailLevel.LeastDetailed && part.LodCategory == ELodCategory.LowPolyGeom3)
else if (eDetailLevel == ExportDetailLevel.LeastDetailed && !part.Lod.IsHighestLevel())
{
parts[meshIndex].Add(partIndex++, part);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private List<DynamicMeshPart> GenerateParts(Dictionary<int, Dictionary<int, D2Cl
{
Index = i,
GroupIndex = partGroups[i],
LodCategory = part.LodCategory,
LodCategory = part.Lod.DetailLevel,
bAlphaClip = (part.Flags & 0x8) != 0,
GearDyeChangeColorIndex = part.GearDyeChangeColorIndex
};
Expand Down
2 changes: 1 addition & 1 deletion Tiger/Schema/Entity/EntityStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public struct D2Class_CB6E8080 // TODO use DCG to figure out what this is
[SchemaField(0x1A, TigerStrategy.DESTINY2_SHADOWKEEP_2601)]
[SchemaField(0x1C, TigerStrategy.DESTINY2_BEYONDLIGHT_3402)]
public byte GearDyeChangeColorIndex; // sbyte gear_dye_change_color_index
public ELodCategory LodCategory;
public ELod Lod;
public byte Unk1E;
public byte LodRun; // lod_run
[SchemaField(TigerStrategy.DESTINY2_BEYONDLIGHT_3402)]
Expand Down
19 changes: 18 additions & 1 deletion Tiger/Schema/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Tiger.Schema;
using System.Runtime.InteropServices;

namespace Tiger.Schema;

public enum PrimitiveType // name comes from bungie
{
Expand All @@ -18,3 +20,18 @@ public enum ELodCategory : byte
LowPolyGeom3 = 9, // low poly geom lod3
Detail0 = 10 // detail lod0
}

[StructLayout(LayoutKind.Sequential)]
public struct ELod
{
public ELodCategory DetailLevel;

public bool IsHighestLevel()
{
return DetailLevel == ELodCategory.MainGeom0 ||
DetailLevel == ELodCategory.GripStock0 ||
DetailLevel == ELodCategory.Stickers0 ||
DetailLevel == ELodCategory.InternalGeom0 ||
DetailLevel == ELodCategory.Detail0;
}
}
4 changes: 2 additions & 2 deletions Tiger/Schema/Static/StaticMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ private List<StaticPart> LoadDecals(ExportDetailLevel detailLevel)
{
if (detailLevel == ExportDetailLevel.MostDetailed)
{
if (decalPartEntry.LODLevel != 1 && decalPartEntry.LODLevel != 2 && decalPartEntry.LODLevel != 10)
if (!decalPartEntry.Lod.IsHighestLevel())
{
continue;
}
}
else if (detailLevel == ExportDetailLevel.LeastDetailed)
{
if (decalPartEntry.LODLevel == 1 || decalPartEntry.LODLevel == 2 || decalPartEntry.LODLevel == 10)
if (decalPartEntry.Lod.IsHighestLevel())
{
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions Tiger/Schema/Static/StaticMeshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Dictionary<int, SStaticMeshPart> GetPartsOfDetailLevel(ExportDetailLevel
for (int i = 0; i < _tag.Parts.Count; i++)
{
var staticPartEntry = _tag.Parts[i];
if (staticPartEntry.DetailLevel == 1 || staticPartEntry.DetailLevel == 2 || staticPartEntry.DetailLevel == 10)
if (staticPartEntry.Lod.IsHighestLevel())
{
staticPartEntries.Add(i, staticPartEntry);
}
Expand All @@ -113,7 +113,7 @@ public Dictionary<int, SStaticMeshPart> GetPartsOfDetailLevel(ExportDetailLevel
for (int i = 0; i < _tag.Parts.Count; i++)
{
var staticPartEntry = _tag.Parts[i];
if (staticPartEntry.DetailLevel != 1 && staticPartEntry.DetailLevel != 2 && staticPartEntry.DetailLevel != 10)
if (!staticPartEntry.Lod.IsHighestLevel())
{
staticPartEntries.Add(i, staticPartEntry);
}
Expand Down Expand Up @@ -239,7 +239,7 @@ public Dictionary<int, SStaticMeshPart> GetPartsOfDetailLevel(ExportDetailLevel
for (int i = 0; i < _tag.Parts.Count; i++)
{
var staticPartEntry = _tag.Parts[i];
if (staticPartEntry.DetailLevel == 1 || staticPartEntry.DetailLevel == 2 || staticPartEntry.DetailLevel == 10)
if (staticPartEntry.Lod.IsHighestLevel())
{
staticPartEntries.Add(i, staticPartEntry);
}
Expand All @@ -250,7 +250,7 @@ public Dictionary<int, SStaticMeshPart> GetPartsOfDetailLevel(ExportDetailLevel
for (int i = 0; i < _tag.Parts.Count; i++)
{
var staticPartEntry = _tag.Parts[i];
if (staticPartEntry.DetailLevel != 1 && staticPartEntry.DetailLevel != 2 && staticPartEntry.DetailLevel != 10)
if (!staticPartEntry.Lod.IsHighestLevel())
{
staticPartEntries.Add(i, staticPartEntry);
}
Expand Down
4 changes: 2 additions & 2 deletions Tiger/Schema/Static/StaticMeshStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct SStaticMeshDecal
[SchemaField(TigerStrategy.DESTINY2_SHADOWKEEP_2601)]
[SchemaField(TigerStrategy.DESTINY2_WITCHQUEEN_6307, Obsolete = true)]
public short Unk02;
public sbyte LODLevel;
public ELod Lod;
public sbyte Unk03;
public short PrimitiveType;
[SchemaField(TigerStrategy.DESTINY2_WITCHQUEEN_6307)]
Expand Down Expand Up @@ -105,7 +105,7 @@ public struct SStaticMeshPart
public uint IndexOffset;
public uint IndexCount;
public ushort BufferIndex;
public sbyte DetailLevel;
public ELod Lod;
public sbyte PrimitiveType;
}

Expand Down
3 changes: 3 additions & 0 deletions Tiger/Schema/Static/StaticPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public StaticPart(SStaticPart terrainPartEntry) : base()
{
IndexOffset = terrainPartEntry.IndexOffset;
IndexCount = terrainPartEntry.IndexCount;
LodCategory = terrainPartEntry.Lod.DetailLevel;
PrimitiveType = PrimitiveType.TriangleStrip;
MaterialType = Shaders.MaterialType.Opaque;
}
Expand All @@ -17,6 +18,7 @@ public StaticPart(SStaticMeshPart staticPartEntry) : base()
{
IndexOffset = staticPartEntry.IndexOffset;
IndexCount = staticPartEntry.IndexCount;
LodCategory = staticPartEntry.Lod.DetailLevel;
PrimitiveType = (PrimitiveType)staticPartEntry.PrimitiveType;
MaterialType = Shaders.MaterialType.Opaque;
}
Expand All @@ -25,6 +27,7 @@ public StaticPart(SStaticMeshDecal decalPartEntry) : base()
{
IndexOffset = decalPartEntry.IndexOffset;
IndexCount = decalPartEntry.IndexCount;
LodCategory = decalPartEntry.Lod.DetailLevel;
PrimitiveType = (PrimitiveType)decalPartEntry.PrimitiveType;
MaterialType = Shaders.MaterialType.Transparent;
}
Expand Down
4 changes: 2 additions & 2 deletions Tiger/Schema/Static/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void LoadIntoExporter(ExporterScene scene, string saveDirectory, bool exp

foreach (var partEntry in _tag.StaticParts)
{
if (partEntry.DetailLevel == 0)
if (partEntry.Lod.DetailLevel == ELodCategory.MainGeom0)
{
if (partEntry.Material is null || partEntry.Material.VertexShader is null)
continue;
Expand Down Expand Up @@ -336,5 +336,5 @@ public struct SStaticPart
public uint IndexOffset;
public ushort IndexCount;
public byte GroupIndex;
public byte DetailLevel;
public ELod Lod;
}

0 comments on commit 3f2124c

Please sign in to comment.