feat(ufbx): switch to native ufbx_vec/quat/matrix types

Replaces all Misaki.HighPerformance.Mathematics vector, quaternion, and matrix types in Ghost.Ufbx bindings with new native ufbx_vec2, ufbx_vec3, ufbx_vec4, ufbx_quat, and ufbx_matrix structs. Updates all interop code, struct fields, and API signatures accordingly. Adds struct definitions for the new types and provides matrix operations as struct methods. Removes unnecessary math package reference. Also includes minor fixes to system attributes, meshlet LOD logic, and mesh utility.

BREAKING CHANGE: All Ufbx-related APIs now use ufbx_* types instead of Misaki.HighPerformance.Mathematics types. Existing code using the old types will require updates.
This commit is contained in:
2026-04-07 23:50:55 +09:00
parent a5c10cfe5a
commit 0fc449bc78
60 changed files with 694 additions and 415 deletions

View File

@@ -268,7 +268,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
nearClip = request.view.nearClipPlane,
cameraDirection = viewMatrix.c2.xyz, // check if that's correct orientation
farClip = request.view.farClipPlane,
screenSize = new float4(request.view.sensorSize.x, request.view.sensorSize.y, 1.0f / request.view.sensorSize.x, 1.0f / request.view.sensorSize.y)
screenSize = new float4(rtSize.x, rtSize.y, 1.0f / rtSize.x, 1.0f / rtSize.y)
};
ctx.CommandBuffer.Barrier(BarrierDesc.Buffer(viewBufferResource, BarrierSync.Copy, BarrierAccess.CopyDest));

View File

@@ -0,0 +1,50 @@
using Ghost.Core;
using Ghost.Engine.Components;
using Ghost.Engine.Utilities;
using Ghost.Entities;
using Misaki.HighPerformance.Mathematics;
namespace Ghost.Graphics.Test.Systems;
internal class CameraMovingSystem : ISystem
{
private Identifier<EntityQuery> _cameraQueryID;
private random _random;
private float3 _target;
public void Initialize(ref readonly SystemAPI systemAPI)
{
_cameraQueryID = QueryBuilder.Create()
.WithAll<Camera, LocalToWorld>()
.Build(systemAPI.World, true);
_random = new random(123456);
_target = _random.NextFloat3(-20, 20);
}
public void Update(ref readonly SystemAPI systemAPI)
{
ref var cameraQuery = ref systemAPI.World.ComponentManager.GetEntityQueryReference(_cameraQueryID);
foreach (ref var ltw in cameraQuery.GetComponentIterator<LocalToWorld>())
{
var position = ltw.matrix.c3.xyz;
if (math.distance(position, _target) < 0.1f)
{
_target = _random.NextFloat3(-20, 20);
}
var newPosition = math.lerp(position, _target, 0.025f);
var forward = math.normalize(new float3(0f, 0.5f, 0f) - newPosition);
var rotation = quaternion.LookRotation(forward, math.up());
var matrix = float4x4.TRS(newPosition, rotation, float3.one);
ltw.matrix = matrix;
}
}
public void Cleanup(ref readonly SystemAPI systemAPI)
{
}
}

View File

@@ -11,6 +11,7 @@ using Misaki.HighPerformance.Mathematics;
namespace Ghost.Graphics.Test.Systems;
[RenderPipelineSystem<TestRenderPipelineSettings>]
[UpdateAfter<CameraMovingSystem>]
public class RenderExtractionSystem : ISystem
{
private RenderSystem _renderSystem = null!;

View File

@@ -66,6 +66,7 @@ internal static class MeshUtility
for (var i = 0u; i < scene.Get()->nodes.count; i++)
{
var data = scene.Get()->nodes.data;
var node = scene.Get()->nodes.data[i];
if (node->is_root)
{
@@ -102,19 +103,27 @@ internal static class MeshUtility
var colIdx = pMesh->vertex_color.exists ? pMesh->vertex_color.indices.data[ufbxTopologyIndex] : uint.MaxValue;
var btanIdx = pMesh->vertex_bitangent.exists ? pMesh->vertex_bitangent.indices.data[ufbxTopologyIndex] : uint.MaxValue;
var position = pMesh->vertex_position.values.data[posIdx];
var normal = normIdx != uint.MaxValue ? pMesh->vertex_normal.values.data[normIdx] : default;
var uv = uvIdx != uint.MaxValue ? pMesh->vertex_uv.values.data[uvIdx] : default;
var color = colIdx != uint.MaxValue ? pMesh->vertex_color.values.data[colIdx] : default;
var vertex = new Vertex
{
position = pMesh->vertex_position.values.data[posIdx],
normal = normIdx != uint.MaxValue ? pMesh->vertex_normal.values.data[normIdx] : default,
uv = uvIdx != uint.MaxValue ? pMesh->vertex_uv.values.data[uvIdx] : default,
color = colIdx != uint.MaxValue ? new Color128(pMesh->vertex_color.values.data[colIdx]) : default,
position = new float3(position.x, position.y, position.z),
normal = new float3(normal.x, normal.y, normal.z),
uv = new float2(uv.x, uv.y),
color = new Color128(color.x, color.y, color.z, color.w)
};
if (tanIdx != uint.MaxValue)
{
var t = pMesh->vertex_tangent.values.data[tanIdx];
var mt = pMesh->vertex_tangent.values.data[tanIdx];
var mb = btanIdx != uint.MaxValue ? pMesh->vertex_bitangent.values.data[btanIdx] : default;
var t = new float3(mt.x, mt.y, mt.z);
var n = vertex.normal;
var b = btanIdx != uint.MaxValue ? pMesh->vertex_bitangent.values.data[btanIdx] : math.cross(n, t);
var b = btanIdx != uint.MaxValue ? new float3(mb.x, mb.y, mb.z) : math.cross(n, t);
vertex.tangent = ComputeTangent(t, n, b);
}

View File

@@ -10,6 +10,7 @@ using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.Mathematics;
using Windows.Devices.Geolocation;
namespace Ghost.Graphics.Test.Windows;
@@ -75,6 +76,7 @@ public sealed partial class GraphicsTestWindow : Window
// Add Systems
var group = _world.SystemManager.GetSystem<DefaultSystemGroup>();
group.AddSystem<RenderExtractionSystem>();
group.AddSystem<CameraMovingSystem>();
group.SortSystems();
_world.SystemManager.InitializeAll(default);