Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MontagueM committed Dec 23, 2024
1 parent ce019f1 commit 3e15921
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 288 deletions.
1 change: 1 addition & 0 deletions Tiger/ConfigSubsystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CommonSettings
public bool SingleFolderMapsEnabled { get; set; } = true;
public bool IndividualStaticsEnabled { get; set; } = true;
public TextureExportFormat OutputTextureFormat { get; set; } = TextureExportFormat.DDS_BGRA_UNCOMP_DX10;
public bool UseCustomRenderer { get; set; } = false;
}

// [ConfigSubsystem]
Expand Down
30 changes: 0 additions & 30 deletions Tiger/Exporters/AutomatedExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,6 @@ public static void SaveInteropUnrealPythonFile(string saveDirectory, string mesh
File.WriteAllText($"{saveDirectory}/{meshName}_import_to_ue5.py", textExtensions);
}

public static void SaveInteropBlenderPythonFile(string saveDirectory, string meshName, ImportType importType, TextureExportFormat textureFormat)
{
// Copy and rename file
saveDirectory = saveDirectory.Replace("\\", "/");
File.Copy("Exporters/import_to_blender.py", $"{saveDirectory}/{meshName}_import_to_blender.py", true);

//Lets just make a py for all exports now because why not
string text = File.ReadAllText($"{saveDirectory}/{meshName}_import_to_blender.py");
text = text.Replace("HASH", $"{meshName}");
text = text.Replace("OUTPUT_DIR", $"{saveDirectory}");
text = text.Replace("IMPORT_TYPE", $"{importType.ToString().Replace("ImportType.", "")}");
File.WriteAllText($"{saveDirectory}/{meshName}_import_to_blender.py", text);

// change extension
string textExtensions = File.ReadAllText($"{saveDirectory}/{meshName}_import_to_blender.py");
switch (textureFormat)
{
case ETextureFormat.PNG:
textExtensions = textExtensions.Replace("TEX_EXT", ".png");
break;
case ETextureFormat.TGA:
textExtensions = textExtensions.Replace("TEX_EXT", ".tga");
break;
default:
textExtensions = textExtensions.Replace("TEX_EXT", ".dds");
break;
}
File.WriteAllText($"{saveDirectory}/{meshName}_import_to_blender.py", textExtensions);
}

public static void SaveBlenderApiFile(string saveDirectory, string meshName, TextureExportFormat outputTextureFormat, List<Dye> dyes, string fileSuffix = "")
{
File.Copy($"Exporters/blender_api_template.py", $"{saveDirectory}/{meshName}{fileSuffix}.py", true);
Expand Down
16 changes: 7 additions & 9 deletions Tiger/Exporters/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public struct ExportMaterial
public readonly MaterialType Type;
public readonly bool IsTerrain;

public ExportMaterial(IMaterial material, MaterialType type, bool isTerrain = false)
public ExportMaterial(IMaterial material, MaterialType type = MaterialType.Opaque, bool isTerrain = false)
{
Material = material;
IsTerrain = isTerrain;
Expand Down Expand Up @@ -263,14 +263,12 @@ public void AddMapEntity(SMapDataEntry dynamicResource, Entity entity, Transform

EntityInstances[entity.Hash].Add(new Transform
{
transform = new Transform
{
Position = dynamicResource.Translation.ToVec3(),
Rotation = Vector4.QuaternionToEulerAngles(dynamicResource.Rotation),
Quaternion = dynamicResource.Rotation,
Scale = new Vector3(dynamicResource.Translation.W, dynamicResource.Translation.W, dynamicResource.Translation.W)
};
}
Position = dynamicResource.Translation.ToVec3(),
Rotation = Vector4.QuaternionToEulerAngles(dynamicResource.Rotation),
Quaternion = dynamicResource.Rotation,
Scale = new Vector3(dynamicResource.Translation.W, dynamicResource.Translation.W,
dynamicResource.Translation.W)
});
EntityInstances[dynamicResource.GetEntityHash()].Add((Transform)transform);
}

Expand Down
10 changes: 0 additions & 10 deletions Tiger/Exporters/FbxExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ public override void Export(Exporter.ExportEventArgs args)
}
}

string outputDirectory = args.OutputDirectory;
if (scene.Type is ExportType.Static or ExportType.Entity or ExportType.API or ExportType.D1API)
{
outputDirectory = Path.Join(outputDirectory, scene.Name);
}
else if (scene.Type is ExportType.Map or ExportType.Terrain or ExportType.EntityPoints)
{
outputDirectory = Path.Join(outputDirectory, "Maps");
}
else if (scene.Type is ExportType.StaticInMap)
if (scene.Type == ExportType.API)
{
FbxScene fbxScene = FbxScene.Create(_manager, scene.Name);
Expand Down
16 changes: 8 additions & 8 deletions Tiger/Exporters/MetadataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ public MetadataScene(ExporterScene scene)
AddLight(
data.Hash,
"Point",
mapLight.Unk10.TagData.Unk40[i].Translation,
mapLight.Unk10.TagData.Unk40[i].Rotation,
mapLight.Lights.TagData.Transforms[i].Translation,
mapLight.Lights.TagData.Transforms[i].Rotation,
new Vector2(1,1), //new Vector2(mapLight.Unk10.TagData.Unk30[i].UnkA0.W, mapLight.Unk10.TagData.Unk30[i].UnkB0.W), //Not right
(data.TagData.Unk40.Count > 0 ? data.TagData.Unk40[0].Vec : data.TagData.Unk60[0].Vec),
mapLight.Unk10.TagData.Unk58.TagData.InstanceBounds[i].Corner2.X - mapLight.Unk10.TagData.Unk58.TagData.InstanceBounds[i].Corner1.X);
(data.TagData.Buffer1.Count > 0 ? data.TagData.Buffer1[0].Vec : data.TagData.Buffer2[0].Vec),
mapLight.Lights.TagData.Bounds.TagData.InstanceBounds[i].Corner2.X - mapLight.Lights.TagData.Bounds.TagData.InstanceBounds[i].Corner1.X);
}
}
foreach (SMapDecalsResource decal in scene.Decals)
Expand Down Expand Up @@ -158,7 +158,7 @@ public MetadataScene(ExporterScene scene)
new Vector4(entry.Position.X, entry.Position.Y, entry.Position.Z, 1),
entry.Quaternion,
new Vector2(1, 1),
data.TagData.UnkE8.TagData.Unk40.Count > 0 ? data.TagData.UnkE8.TagData.Unk40[0].Vec : data.TagData.UnkE8.TagData.Unk60[0].Vec);
data.TagData.UnkE8.TagData.Buffer1.Count > 0 ? data.TagData.UnkE8.TagData.Buffer1[0].Vec : data.TagData.UnkE8.TagData.Buffer2[0].Vec);

}
}
Expand Down Expand Up @@ -271,9 +271,9 @@ public void AddCubemap(string name, Vector3 scale, Vector4 quatRotation, Vector3
public void AddLight(string name, string type, Vector4 translation, Vector4 quatRotation, Vector2 size, Vector4 color, float range = 13)
{
//Idk how color/intensity is handled, so if its above 1 just bring it down
//float R = color.X > 1 ? color.X / 100 : color.X;
//float G = color.Y > 1 ? color.Y / 100 : color.Y;
//float B = color.Z > 1 ? color.Z / 100 : color.Z;
float R = color.X > 1 ? color.X / 100 : color.X;
float G = color.Y > 1 ? color.Y / 100 : color.Y;
float B = color.Z > 1 ? color.Z / 100 : color.Z;

if (!_config["Lights"].ContainsKey(name))
{
Expand Down
37 changes: 21 additions & 16 deletions Tiger/Schema/Entity/EntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,40 @@ private List<DynamicMeshPart> GenerateParts(Dictionary<int, Dictionary<int, D2Cl
Index = i,
GroupIndex = partGroups[i],
LodCategory = part.Lod.DetailLevel,
bAlphaClip = (part.Flags & 0x8) != 0,
bAlphaClip = (part.GetFlags() & 0x8) != 0,
GearDyeChangeColorIndex = part.GearDyeChangeColorIndex,
HasSkeleton = hasSkeleton,
RotationOffset = RotationOffset,
TranslationOffset = TranslationOffset
};
//We only care about the vertex shader for now for mesh data
//But if theres also no pixel shader then theres no point in adding it
if (dynamicMeshPart.Material is null ||
dynamicMeshPart.Material.VertexShader is null ||
dynamicMeshPart.Material.PixelShader is null ||
dynamicMeshPart.Material.Unk08 != 1 ||
(dynamicMeshPart.Material.Unk20 & 0x8000) != 0)
continue;
if (Strategy.CurrentStrategy > TigerStrategy.DESTINY1_RISE_OF_IRON)
{
if (dynamicMeshPart.Material is null ||
dynamicMeshPart.Material.VertexShader is null ||
dynamicMeshPart.Material.PixelShader is null ||
dynamicMeshPart.Material.Unk08 != 1 ||
(dynamicMeshPart.Material.Unk20 & 0x8000) != 0)
continue;
}
else
{
if (dynamicMeshPart.Material is null ||
dynamicMeshPart.Material.VertexShader is null ||
dynamicMeshPart.Material.PixelShader is null) // || dynamicMeshPart.Material.Unk08 != 1)
continue;

//if (dynamicMeshPart.Material.Unk08 != 1)
// Console.WriteLine($"{dynamicMeshPart.Material.FileHash}");
}

dynamicMeshPart.GetAllData(mesh, _tag);
parts.Add(dynamicMeshPart);
}

meshIndex++;
}

return parts;
}

}

public class DynamicMeshPart : MeshPart
Expand Down Expand Up @@ -204,20 +209,20 @@ public void GetAllData(SEntityModelMesh mesh, SEntityModel model)

if (Strategy.CurrentStrategy <= TigerStrategy.DESTINY2_SHADOWKEEP_2999 && Strategy.CurrentStrategy != TigerStrategy.DESTINY1_RISE_OF_IRON)
{
InputSignature[] inputSignatures = Material.VertexShader.InputSignatures.ToArray();
DXBCIOSignature[] inputSignatures = Material.VertexShader.InputSignatures.ToArray();
int b0Stride = mesh.Vertices1.TagData.Stride;
int b1Stride = mesh.Vertices2?.TagData.Stride ?? 0;
List<InputSignature> inputSignatures0 = new();
List<InputSignature> inputSignatures1 = new();
List<DXBCIOSignature> inputSignatures0 = new();
List<DXBCIOSignature> inputSignatures1 = new();
int stride = 0;
foreach (InputSignature inputSignature in inputSignatures)
foreach (DXBCIOSignature inputSignature in inputSignatures)
{
if (stride < b0Stride)
inputSignatures0.Add(inputSignature);
else
inputSignatures1.Add(inputSignature);

if (inputSignature.Semantic == InputSemantic.Colour || inputSignature.Semantic == InputSemantic.BlendIndices || inputSignature.Semantic == InputSemantic.BlendWeight)
if (inputSignature.Semantic == DXBCSemantic.Colour || inputSignature.Semantic == DXBCSemantic.BlendIndices || inputSignature.Semantic == DXBCSemantic.BlendWeight)
stride += inputSignature.GetNumberOfComponents() * 1; // 1 byte per component
else
stride += inputSignature.GetNumberOfComponents() * 2; // 2 bytes per component
Expand Down
4 changes: 4 additions & 0 deletions Tiger/Schema/Model/VertexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ private void ReadVertexDataSignature(TigerReader reader, MeshPart part, uint ver
{
reader.Seek(vertexIndex * _tag.Stride, SeekOrigin.Begin);

bool HasWeights = false;
IntVector4 WeightValue = new();
IntVector4 WeightIndex = new();

foreach (DXBCIOSignature inputSignature in inputSignatures)
{
if (inputSignature.ToString().Contains("SV_"))
Expand Down
Loading

0 comments on commit 3e15921

Please sign in to comment.