Skip to content

Commit

Permalink
instanced SMs in umap
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Nov 16, 2023
1 parent b525796 commit d6af826
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 29 deletions.
14 changes: 7 additions & 7 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@
<ItemGroup>
<PackageReference Include="AdonisUI" Version="1.17.1" />
<PackageReference Include="AdonisUI.ClassicTheme" Version="1.17.1" />
<PackageReference Include="Autoupdater.NET.Official" Version="1.8.3" />
<PackageReference Include="Autoupdater.NET.Official" Version="1.8.4" />
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="CSCore" Version="1.2.1.2" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="ImGui.NET" Version="1.89.7.1" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.5" />
<PackageReference Include="ImGui.NET" Version="1.89.9.3" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NVorbis" Version="0.10.5" />
<PackageReference Include="Oodle.NET" Version="1.0.1" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="OpenTK" Version="4.8.0" />
<PackageReference Include="OpenTK" Version="4.8.1" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.2" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.6" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions FModel/Framework/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBuffer);
for (int i = 0; i < draw_data.CmdListsCount; i++)
{
ImDrawListPtr cmd_list = draw_data.CmdListsRange[i];
ImDrawListPtr cmd_list = draw_data.CmdLists[i];

int vertexSize = cmd_list.VtxBuffer.Size * Unsafe.SizeOf<ImDrawVert>();
if (vertexSize > _vertexBufferSize)
Expand Down Expand Up @@ -490,7 +490,7 @@ private void RenderImDrawData(ImDrawDataPtr draw_data)
// Render command lists
for (int n = 0; n < draw_data.CmdListsCount; n++)
{
ImDrawListPtr cmd_list = draw_data.CmdListsRange[n];
ImDrawListPtr cmd_list = draw_data.CmdLists[n];

GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, cmd_list.VtxBuffer.Size * Unsafe.SizeOf<ImDrawVert>(), cmd_list.VtxBuffer.Data);
CheckGLError($"Data Vert {n}");
Expand Down
74 changes: 55 additions & 19 deletions FModel/Views/Snooper/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,34 +454,57 @@ private void WorldLight(UObject actor)

private void WorldMesh(UObject actor, Transform transform)
{
if (!actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "StaticMesh", "Mesh", "LightMesh") ||
!staticMeshComponent.TryLoad(out UStaticMeshComponent staticMeshComp) ||
!staticMeshComp.GetStaticMesh().TryLoad(out UStaticMesh m) || m.Materials.Length < 1)
return;
if (actor.TryGetValue(out FPackageIndex[] instanceComponents, "InstanceComponents"))
{
foreach (var component in instanceComponents)
{
if (!component.TryLoad(out UInstancedStaticMeshComponent staticMeshComp) ||
!staticMeshComp.GetStaticMesh().TryLoad(out UStaticMesh m) || m.Materials.Length < 1)
continue;

var guid = m.LightingGuid;
var t = new Transform
if (staticMeshComp.PerInstanceSMData is { Length: > 0 })
{

var relation = CalculateTransform(staticMeshComp, transform);
foreach (var perInstanceData in staticMeshComp.PerInstanceSMData)
{
ProcessMesh(actor, staticMeshComp, m, new Transform
{
Relation = relation.Matrix,
Position = perInstanceData.TransformData.Translation * Constants.SCALE_DOWN_RATIO,
Rotation = perInstanceData.TransformData.Rotation,
Scale = perInstanceData.TransformData.Scale3D
});
}
}
else ProcessMesh(actor, staticMeshComp, m, CalculateTransform(staticMeshComp, transform));
}
}
else if (actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "StaticMesh", "Mesh", "LightMesh") &&
staticMeshComponent.TryLoad(out UStaticMeshComponent staticMeshComp) &&
staticMeshComp.GetStaticMesh().TryLoad(out UStaticMesh m) && m.Materials.Length > 0)
{
Relation = transform.Matrix,
Position = staticMeshComp.GetOrDefault("RelativeLocation", FVector.ZeroVector) * Constants.SCALE_DOWN_RATIO,
Rotation = staticMeshComp.GetOrDefault("RelativeRotation", FRotator.ZeroRotator).Quaternion(),
Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector)
};
ProcessMesh(actor, staticMeshComp, m, CalculateTransform(staticMeshComp, transform));
}
}

private void ProcessMesh(UObject actor, UStaticMeshComponent staticMeshComp, UStaticMesh m, Transform transform)
{
var guid = m.LightingGuid;

OverrideVertexColors(staticMeshComp, m);
if (Options.TryGetModel(guid, out var model))
{
model.AddInstance(t);
model.AddInstance(transform);
}
else if (m.TryConvert(out var mesh))
{
model = new StaticModel(m, mesh, t);
model = new StaticModel(m, mesh, transform);
model.IsTwoSided = actor.GetOrDefault("bMirrored", staticMeshComp.GetOrDefault("bDisallowMeshPaintPerInstance", model.IsTwoSided));

if (actor.TryGetValue(out FPackageIndex baseMaterial, "BaseMaterial") &&
actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData"))
if (actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData"))
{
var material = model.Materials.FirstOrDefault(x => x.Name == baseMaterial.Name);
var material = model.Materials.FirstOrDefault();
if (material is { IsUsed: true })
{
for (int j = 0; j < textureData.Length; j++)
Expand Down Expand Up @@ -520,7 +543,9 @@ private void WorldMesh(UObject actor, Transform transform)
for (var j = 0; j < overrideMaterials.Length && j < model.Sections.Length; j++)
{
var matIndex = model.Sections[j].MaterialIndex;
if (!(model.Materials[matIndex].IsUsed && overrideMaterials[matIndex].Load() is UMaterialInterface unrealMaterial)) continue;
if (matIndex < 0 || matIndex >= model.Materials.Length || matIndex >= overrideMaterials.Length ||
overrideMaterials[matIndex].Load() is not UMaterialInterface unrealMaterial) continue;

model.Materials[matIndex].SwapMaterial(unrealMaterial);
}
}
Expand All @@ -531,15 +556,26 @@ private void WorldMesh(UObject actor, Transform transform)
if (actor.TryGetValue(out FPackageIndex treasureLight, "PointLight", "TreasureLight") &&
treasureLight.TryLoad(out var pl1) && pl1.Template.TryLoad(out var pl2))
{
Options.Lights.Add(new PointLight(guid, Options.Icons["pointlight"], pl1, pl2, t));
Options.Lights.Add(new PointLight(guid, Options.Icons["pointlight"], pl1, pl2, transform));
}
if (actor.TryGetValue(out FPackageIndex spotLight, "SpotLight") &&
spotLight.TryLoad(out var sl1) && sl1.Template.TryLoad(out var sl2))
{
Options.Lights.Add(new SpotLight(guid, Options.Icons["spotlight"], sl1, sl2, t));
Options.Lights.Add(new SpotLight(guid, Options.Icons["spotlight"], sl1, sl2, transform));
}
}

private Transform CalculateTransform(UStaticMeshComponent staticMeshComp, Transform relation)
{
return new Transform
{
Relation = relation.Matrix,
Position = staticMeshComp.GetOrDefault("RelativeLocation", FVector.ZeroVector) * Constants.SCALE_DOWN_RATIO,
Rotation = staticMeshComp.GetOrDefault("RelativeRotation", FRotator.ZeroRotator).Quaternion(),
Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector)
};
}

private void OverrideVertexColors(UStaticMeshComponent staticMeshComp, UStaticMesh staticMesh)
{
if (staticMeshComp.LODData is not { Length: > 0 } || staticMesh.RenderData is not { LODs.Length: > 0 })
Expand Down

0 comments on commit d6af826

Please sign in to comment.