From 73f1a1f8294976b9bca41cfe9836faf5888f78d8 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 1 Nov 2024 13:31:03 +0800 Subject: [PATCH] fix: fix fatal layout issue about VxColor. - fix wrong memory layout of VxColor. --- .../BMapSharp/BMapSharp/VirtoolsTypes.cs | 2 +- .../BMapSharp/BMapSharpTestbench/Program.cs | 80 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs b/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs index 0ec618b..20ad55b 100644 --- a/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs +++ b/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs @@ -52,7 +52,7 @@ namespace BMapSharp.VirtoolsTypes { [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] public struct VxColor { [MarshalAs(UnmanagedType.R4)] - public float A, R, G, B; + public float R, G, B, A; public VxColor(float _r, float _g, float _b, float _a) { A = _a; R = _r; G = _g; B = _b; diff --git a/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs b/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs index 5e468de..0d8f39f 100644 --- a/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs +++ b/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs @@ -42,49 +42,49 @@ namespace BMapSharpTestbench { // Console.WriteLine($"\tMatrix: {obj.GetWorldMatrix().ToManaged()}"); // } - Console.WriteLine("===== Meshes ====="); - foreach (var mesh in reader.GetMeshes()) { - Console.WriteLine(mesh.GetName()); + // Console.WriteLine("===== Meshes ====="); + // foreach (var mesh in reader.GetMeshes()) { + // Console.WriteLine(mesh.GetName()); - Console.WriteLine($"\tLit Mode: {mesh.GetLitMode()}"); - Console.WriteLine($"\tVertex Count: {mesh.GetVertexCount()}"); - Console.WriteLine($"\tFace Count: {mesh.GetFaceCount()}"); - Console.WriteLine($"\tMaterial Slot Count: {mesh.GetMaterialSlotCount()}"); - } - - // Console.WriteLine("===== Materials ====="); - // foreach (var mtl in reader.GetMaterials()) { - // Console.WriteLine(mtl.GetName()); - - // Console.WriteLine($"\tDiffuse: {mtl.GetDiffuse().ToManagedRGBA()}"); - // Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}"); - // Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}"); - // Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}"); - - // Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}"); - - // Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}"); - - // Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}"); - // Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}"); - // Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}"); - // Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}"); - // Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}"); - // Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}"); - // Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}"); - - // Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}"); - // Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}"); - // Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}"); - // Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}"); - // Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}"); - - // Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}"); - - // Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}"); - // Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}"); + // Console.WriteLine($"\tLit Mode: {mesh.GetLitMode()}"); + // Console.WriteLine($"\tVertex Count: {mesh.GetVertexCount()}"); + // Console.WriteLine($"\tFace Count: {mesh.GetFaceCount()}"); + // Console.WriteLine($"\tMaterial Slot Count: {mesh.GetMaterialSlotCount()}"); // } + Console.WriteLine("===== Materials ====="); + foreach (var mtl in reader.GetMaterials()) { + Console.WriteLine(mtl.GetName()); + + Console.WriteLine($"\tDiffuse: {mtl.GetDiffuse().ToManagedRGBA()}"); + Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}"); + Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}"); + Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}"); + + Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}"); + + Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}"); + + Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}"); + Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}"); + Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}"); + Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}"); + Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}"); + Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}"); + Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}"); + + Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}"); + Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}"); + Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}"); + Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}"); + Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}"); + + Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}"); + + Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}"); + Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}"); + } + // Console.WriteLine("===== Textures ====="); // foreach (var tex in reader.GetTextures()) { // Console.WriteLine(tex.GetName());