Replace Magick.NET with stb_image; refactor asset pipeline
- Switched image loading/saving from Magick.NET to native stb_image (Ghost.StbI), removing Magick.NET dependency. - Added Ghost.StbI project with native DLL, P/Invoke bindings, and wrapper. - Refactored TextureAssetHandler and TextureProcessor for stb_image, memory-mapped IO, and HDR/16-bit support. - Split IAssetHandler into IImportableAssetHandler and IPackableAssetHandler; updated interfaces to use FileStream. - Added shader and mesh asset handlers (GraphicsShaderAssetHandler, ComputeShaderAssetHandler, FBXAssetHandler). - Improved asset registry/catalog path handling and naming consistency. - Updated asset import pipeline to use new interfaces and trigger engine reimport. - Enhanced UI toolbar button styles and EditPage layout. - Added StbIBindingTest, DisableRuntimeMarshalling, and native wrapper attributes. - Updated wrapper generator for regex derivesFrom; added stbi.json config. - Removed Magick.NET reference; added Ghost.StbI and Ghost.Ufbx references. - Miscellaneous bugfixes and code cleanup.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Ghost.Core;
|
||||
using Ghost.Graphics.RHI;
|
||||
using Ghost.Graphics.Utilities;
|
||||
using Ghost.MeshOptimizer;
|
||||
using Ghost.Ufbx;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
@@ -170,11 +171,11 @@ internal static class MeshUtility
|
||||
MemoryUtility.MemCpy(indices.GetUnsafePtr(), cachedIndices.GetUnsafePtr(), numIndices * sizeof(uint));
|
||||
indices.UnsafeSetCount((int)numIndices);
|
||||
|
||||
//if (needComputeNormals)
|
||||
//{
|
||||
// MeshBuilder.ComputeNormal(vertices, indices);
|
||||
// MeshBuilder.ComputeTangents(vertices, indices);
|
||||
//}
|
||||
if (needComputeNormals)
|
||||
{
|
||||
MeshBuilder.ComputeNormal(vertices, indices);
|
||||
MeshBuilder.ComputeTangents(vertices, indices);
|
||||
}
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Runtime\Ghost.Graphics\Ghost.Graphics.csproj" />
|
||||
<ProjectReference Include="..\..\Test\Ghost.Test.Core\Ghost.Test.Core.csproj" />
|
||||
<ProjectReference Include="..\..\ThridParty\Ghost.Nvtt\Ghost.Nvtt.csproj" />
|
||||
<ProjectReference Include="..\..\ThridParty\Ghost.StbI\Ghost.StbI.csproj" />
|
||||
<ProjectReference Include="..\..\ThridParty\Ghost.Ufbx\Ghost.Ufbx.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Ghost.MicroTest;
|
||||
using Ghost.Test.Core;
|
||||
|
||||
//TestRunner.Run<MeshoptBenchmark>();
|
||||
Console.WriteLine();
|
||||
TestRunner.Run<StbIBindingTest>();
|
||||
72
src/Test/Ghost.MicroTest/StbIBindingTest.cs
Normal file
72
src/Test/Ghost.MicroTest/StbIBindingTest.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Ghost.StbI;
|
||||
using Ghost.Test.Core;
|
||||
|
||||
namespace Ghost.MicroTest;
|
||||
|
||||
internal class StbIBindingTest : ITest
|
||||
{
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
public unsafe void Run()
|
||||
{
|
||||
using var stream = File.OpenRead("C:\\Users\\Misaki\\Downloads\\Screenshot 2024-07-20 035047.png");
|
||||
var bytes = new byte[stream.Length];
|
||||
stream.ReadExactly(bytes);
|
||||
|
||||
int width, height, channels;
|
||||
var buff = StbIApi.LoadFromMemory(bytes, &width, &height, &channels, 4);
|
||||
if (buff == null)
|
||||
{
|
||||
Console.WriteLine("Failed to load image");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"Image loaded: {width}x{height}, channels: {channels}");
|
||||
|
||||
var expectedColor = (Span<byte>)stackalloc byte[] { 122, 145, 224, 255 };
|
||||
var firstPixel = new Span<byte>(buff, 4);
|
||||
|
||||
Console.WriteLine("First pixel RGBA: " + string.Join(", ", firstPixel.ToArray()));
|
||||
Console.WriteLine("Expected RGBA: " + string.Join(", ", expectedColor.ToArray()));
|
||||
|
||||
if (!firstPixel.SequenceEqual(expectedColor))
|
||||
{
|
||||
Console.WriteLine("First pixel does not match expected color");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("First pixel matches expected color");
|
||||
}
|
||||
|
||||
firstPixel.Fill(0xFF);
|
||||
|
||||
int result;
|
||||
var newFilePath = "C:\\Users\\Misaki\\Downloads\\ModifiedImage.jpg"u8;
|
||||
fixed (byte* pathPtr = newFilePath)
|
||||
{
|
||||
result = StbIApi.WriteJpg((sbyte*)pathPtr, width, height, 4, buff, 90);
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
Console.WriteLine("Failed to write image");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Image written successfully");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
StbIApi.ImageFree(buff);
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user