Skip to content

Commit

Permalink
Merge pull request #83 from MontagueM/dare2
Browse files Browse the repository at this point in the history
DARE proper include
  • Loading branch information
MontagueM authored Sep 25, 2022
2 parents 0a7a28c + 37b4c3a commit cca9f02
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 58 deletions.
17 changes: 9 additions & 8 deletions Charm/DareView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ private void RefreshItemList()
items.Add(pair.Value);
}
});

DareListView.ItemsSource = items;
var sortedItems = new List<ApiItem>(items);
sortedItems.Sort((a, b) => b.Item.Hash.CompareTo(a.Item.Hash));
DareListView.ItemsSource = sortedItems;
}

public async void LoadContent()
Expand All @@ -64,11 +65,11 @@ private void LoadApiList()
MainWindow.Progress.SetProgressStages(mapStages, false, true);
Parallel.ForEach(InvestmentHandler.InventoryItems, kvp =>
{
if (_allItems.Count > 500)
{
MainWindow.Progress.CompleteStage();
return;
}
// if (_allItems.Count > 500)
// {
// MainWindow.Progress.CompleteStage();
// return;
// }
string name = InvestmentHandler.GetItemName(kvp.Value);
string type = InvestmentHandler.InventoryItemStringThings[InvestmentHandler.GetItemIndex(kvp.Key)].Header.ItemType;
if (kvp.Value.GetArtArrangementIndex() != -1 || type.Contains("Shader"))
Expand Down Expand Up @@ -197,7 +198,7 @@ private void ExecuteQueue_OnClick(object sender, RoutedEventArgs e)

private void OpenOutputFolder_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(ConfigHandler.GetExportSavePath());
Process.Start("explorer.exe", ConfigHandler.GetExportSavePath());
}
}

Expand Down
12 changes: 11 additions & 1 deletion Charm/EntityView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void Export(List<Entity> entities, string name, EExportTypeFlag ex
}

// Scale and rotate
fbxHandler.ScaleAndRotateForBlender(boneNodes[0]);
// fbxHandler.ScaleAndRotateForBlender(boneNodes[0]);

fbxHandler.ExportScene($"{savePath}/{meshName}.fbx");
fbxHandler.Dispose();
Expand All @@ -127,6 +127,16 @@ public static void ExportInventoryItem(ApiItem item)
// Export the model
// todo bad, should be replaced
EntitySkeleton overrideSkeleton = new EntitySkeleton(new TagHash("BC38AB80"));
var val = InvestmentHandler.GetPatternEntityFromHash(item.Item.Header.InventoryItemHash);
// var resource = (D2Class_6E358080)val.PatternAudio.Header.Unk18;
// if (resource.PatternAudioGroups[0].WeaponSkeletonEntity != null)
// {
// overrideSkeleton = resource.PatternAudioGroups[0].WeaponSkeletonEntity.Skeleton;
// }
if (val != null && val.Skeleton != null)
{
overrideSkeleton = val.Skeleton;
}
EntityView.Export(InvestmentHandler.GetEntitiesFromHash(item.Item.Header.InventoryItemHash),
name, EExportTypeFlag.Full, overrideSkeleton);

Expand Down
2 changes: 1 addition & 1 deletion Charm/ModelView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void GroupsCombobox_OnSelectionChanged(object sender, SelectionChangedEv

public void SetGroupIndices(HashSet<int> hashSet)
{
if (_bFromSelectionChange)
if (_bFromSelectionChange || hashSet.Count == 0)
return;

GroupsCombobox.Items.Clear();
Expand Down
11 changes: 9 additions & 2 deletions Field/Entities/EntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private List<DynamicPart> GenerateParts(Dictionary<int, D2Class_CB6E8080> dynami
dynamicPart.Index = i;
dynamicPart.GroupIndex = partGroups[i];
dynamicPart.LodCategory = part.LodCategory;
dynamicPart.bAlphaClip = (part.Flags & 0x8) != 0;
dynamicPart.GearDyeChangeColorIndex = part.GearDyeChangeColorIndex;
dynamicPart.GetAllData(mesh, Header);
parts.Add(dynamicPart);
}
Expand Down Expand Up @@ -163,10 +165,15 @@ private void TransformTexcoords(D2Class_076F8080 header)
{
for (int i = 0; i < VertexTexcoords.Count; i++)
{
var tx = VertexTexcoords[i];
VertexTexcoords[i] = new Vector2(
VertexTexcoords[i].X * header.TexcoordScale.X + header.TexcoordTranslation.X,
VertexTexcoords[i].Y * -header.TexcoordScale.Y + 1 - header.TexcoordTranslation.Y
tx.X * header.TexcoordScale.X + header.TexcoordTranslation.X,
tx.Y * -header.TexcoordScale.Y + 1 - header.TexcoordTranslation.Y
);
VertexTexcoords1.Add(new Vector2(
tx.X * header.TexcoordScale.X * 5 + header.TexcoordTranslation.X * 5,
tx.Y * -header.TexcoordScale.Y * 5 + 1 - header.TexcoordTranslation.Y * 5
));
}
}

Expand Down
8 changes: 4 additions & 4 deletions Field/Entities/EntityStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,12 @@ public struct D2Class_4F9F8080
public Field.Models.Vector4 Translation;
}

[StructLayout(LayoutKind.Sequential, Size = 0x10)] // technically its actually 0x8, but they do dumb stuff so we'll just ignore it
[StructLayout(LayoutKind.Sequential, Size = 8)]
public struct D2Class_40868080
{
public ushort Unk00;
public ushort Unk02;
public ushort Unk04;
[DestinyOffset(0xC), DestinyField(FieldType.Resource)]
public dynamic? Unk0C;
public uint Unk04;
}

[StructLayout(LayoutKind.Sequential, Size = 0x108)]
Expand Down Expand Up @@ -1215,6 +1213,8 @@ public struct D2Class_9B318080
public TagHash StringContainer; // idk why but i presume debug strings
public DestinyHash WeaponContentGroup2Hash; // "weaponContentGroupHash" from API
// theres other stringcontainer stuff but skipping it
[DestinyOffset(0xA0), DestinyField(FieldType.TagHash64)]
public Entity? WeaponSkeletonEntity;
[DestinyOffset(0xD0), DestinyField(FieldType.TagHash64)]
public Tag<D2Class_A36F8080> AudioGroup;
public float UnkE0;
Expand Down
25 changes: 0 additions & 25 deletions Field/Investment/Dye.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,6 @@ public DyeInfo GetDyeInfo()
{373026850, "GhostDecals"},
};

private static List<string> ShaderDataNames = new List<string>()
{
"\"detail_diffuse_transform\"",
"\"detail_normal_transform\"",
"\"spec_aa_transform\"",
"\"primary_albedo_tint\"",
"\"primary_emissive_tint_color_and_intensity_bias\"",
"\"primary_material_params\"",
"\"primary_material_advanced_params\"",
"\"primary_roughness_remap\"",
"\"primary_worn_albedo_tint\"",
"\"primary_wear_remap\"",
"\"primary_worn_roughness_remap\"",
"\"primary_worn_material_parameters\"",
"\"secondary_albedo_tint\"",
"\"secondary_emissive_tint_color_and_intensity_bias\"",
"\"secondary_material_params\"",
"\"secondary_material_advanced_params\"",
"\"secondary_roughness_remap\"",
"\"secondary_worn_albedo_tint\"",
"\"secondary_wear_remap\"",
"\"secondary_worn_roughness_remap\"",
"\"secondary_worn_material_parameters\"",
};

public static string GetChannelName(DestinyHash channelHash)
{
return ChannelNames[channelHash];
Expand Down
69 changes: 54 additions & 15 deletions Field/Models/FbxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public FbxMesh AddMeshPartToScene(Part part, int index, string meshName)
{
AddColoursToMesh(mesh, part);
}

if (part.VertexColourSlots.Count > 0 || part.GearDyeChangeColorIndex != 0xFF) // api item, so do slots and uv1
{
AddSlotColoursToMesh(mesh, part);
AddTexcoords1ToMesh(mesh, part);
}

// for importing to other engines
if (InfoHandler != null && part.Material != null) // todo consider why some materials are null
Expand Down Expand Up @@ -147,7 +153,7 @@ private void AddTexcoordsToMesh(FbxMesh mesh, Part part)
FbxLayerElementUV uvLayer;
lock (_fbxLock)
{
uvLayer = FbxLayerElementUV.Create(mesh, "uvLayerName");
uvLayer = FbxLayerElementUV.Create(mesh, "uv0");
}
uvLayer.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
uvLayer.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
Expand All @@ -158,6 +164,24 @@ private void AddTexcoordsToMesh(FbxMesh mesh, Part part)
mesh.GetLayer(0).SetUVs(uvLayer);
}

private void AddTexcoords1ToMesh(FbxMesh mesh, Part part)
{
FbxLayerElementUV uvLayer;
lock (_fbxLock)
{
uvLayer = FbxLayerElementUV.Create(mesh, "uv1");
}
uvLayer.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
uvLayer.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
foreach (var tx in part.VertexTexcoords1)
{
uvLayer.GetDirectArray().Add(new FbxVector2(tx.X, tx.Y));
}
if (mesh.GetLayer(1) == null)
mesh.CreateLayer();
mesh.GetLayer(1).SetUVs(uvLayer);
}


private void AddColoursToMesh(FbxMesh mesh, Part part)
{
Expand All @@ -175,6 +199,35 @@ private void AddColoursToMesh(FbxMesh mesh, Part part)
mesh.GetLayer(0).SetVertexColors(colLayer);
}

private void AddSlotColoursToMesh(FbxMesh mesh, Part part)
{
FbxLayerElementVertexColor colLayer;
lock (_fbxLock)
{
colLayer = FbxLayerElementVertexColor.Create(mesh, "slots");
}
colLayer.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint);
colLayer.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect);
if (part.PrimitiveType == EPrimitiveType.Triangles)
{
VertexBuffer.AddSlotInfo(part, part.GearDyeChangeColorIndex);
for (var i = 0; i < part.VertexPositions.Count; i++)
{
colLayer.GetDirectArray().Add(new FbxColor(part.VertexColourSlots[0].X, part.VertexColourSlots[0].Y, part.VertexColourSlots[0].Z, part.VertexColourSlots[0].W));
}
}
else
{
foreach (var colour in part.VertexColourSlots)
{
colLayer.GetDirectArray().Add(new FbxColor(colour.X, colour.Y, colour.Z, colour.W));
}
}

if (mesh.GetLayer(1) == null)
mesh.CreateLayer();
mesh.GetLayer(1).SetVertexColors(colLayer);
}

private void AddWeightsToMesh(FbxMesh mesh, DynamicPart part, List<FbxNode> skeletonNodes)
{
Expand Down Expand Up @@ -306,7 +359,6 @@ public List<FbxNode> AddSkeleton(List<BoneNode> boneNodes)
}

_scene.GetRootNode().AddChild(rootNode);
// rootNode.LclRotation.Set(new FbxDouble3(-90, 0, 0));
return skeletonNodes;
}

Expand Down Expand Up @@ -488,17 +540,4 @@ private static System.Numerics.Vector3 QuaternionToEulerAngles(Quaternion q)

return retVal;
}

public void ScaleAndRotateForBlender(FbxNode node)
{
for (int i = 0; i < _scene.GetRootNode().GetChildCount(); i++)
{
FbxNode child = _scene.GetRootNode().GetChild(i);
if (child.GetNodeAttribute().GetNode().GetSkeleton() == null)
{
// child.LclScaling.Set(new FbxDouble3(100, 100, 100));
child.LclRotation.Set(new FbxDouble3(0, 0, -90));
}
}
}
}
4 changes: 4 additions & 0 deletions Field/Models/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,15 @@ public class Part
public List<uint> VertexIndices = new List<uint>();
public List<Vector4> VertexPositions = new List<Vector4>();
public List<Vector2> VertexTexcoords = new List<Vector2>();
public List<Vector2> VertexTexcoords1 = new List<Vector2>();
public List<Vector4> VertexNormals = new List<Vector4>();
public List<Vector4> VertexTangents = new List<Vector4>();
public List<Vector4> VertexColours = new List<Vector4>();
public List<Vector4> VertexColourSlots = new List<Vector4>();
public Material Material;
public int GroupIndex = 0;
public bool bAlphaClip;
public byte GearDyeChangeColorIndex = 0xFF;

public Part()
{
Expand Down
34 changes: 33 additions & 1 deletion Field/Models/VertexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ private bool ReadVertexDataType1(Part part, BinaryReader handle)
(part as DynamicPart).VertexWeights.Add(vw);
break;
case 0x18: // normals and tangents are euler
short w;
part.VertexPositions.Add(new Vector4(handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), true));
part.VertexNormals.Add(new Vector4(handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), true));
part.VertexNormals.Add(new Vector4(handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), w = handle.ReadInt16(), true));
part.VertexTangents.Add(new Vector4(handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), handle.ReadInt16(), true));
AddSlotInfo(part, w);
break;
case 0x30: // physics, normals and tangents are euler
part.VertexPositions.Add(new Vector4(handle.ReadSingle(), handle.ReadSingle(), handle.ReadSingle(), handle.ReadSingle()));
Expand All @@ -124,6 +126,36 @@ private bool ReadVertexDataType1(Part part, BinaryReader handle)
return true;
}

public static void AddSlotInfo(Part part, short w)
{
// slots
Vector4 vc = Vector4.Zero;
switch (w & 0x7)
{
case 0:
vc.X = 0.333f;
break;
case 1:
vc.X = 0.666f;
break;
case 2:
vc.X = 0.999f;
break;
case 3:
vc.Y = 0.333f;
break;
case 4:
vc.Y = 0.666f;
break;
case 5:
vc.Y = 0.999f;
break;
}
if (part.bAlphaClip)
vc.Z = 0.25f;
part.VertexColourSlots.Add(vc);
}

private bool ReadVertexDataType5(Part part, BinaryReader handle)
{
switch (header.Stride)
Expand Down
2 changes: 1 addition & 1 deletion Field/blender_api_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8043,7 +8043,7 @@ def execute(self, context):
# BIOS Change Nodegroup name dependent on name of shader ripped from API
custom_node_name = "SHADERNAMEENUM"
global RIP_LOCATION
my_group = create_test_group(self, context, custom_node_name, RIP_LOCATION)
my_group = create_test_group(self, context, custom_node_name, RIP_LOCATION+"/../")
test_node = context.view_layer.objects.active.active_material.node_tree.nodes.new('ShaderNodeGroup')
test_node.node_tree = bpy.data.node_groups[my_group.name]
test_node.use_custom_color = True
Expand Down

0 comments on commit cca9f02

Please sign in to comment.