`
This commit is contained in:
parent
1eb3041ba1
commit
57900bdc8b
63
XNet.Business/MapAgent.cs
Normal file
63
XNet.Business/MapAgent.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using DotRecast.Detour;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace XNet.Business
|
||||
{
|
||||
public class MapAgent
|
||||
{
|
||||
public MapAgent() { }
|
||||
|
||||
public void Init()
|
||||
{
|
||||
DtMeshData navData = new DtMeshData();
|
||||
DtNavMesh navMesh = new DtNavMesh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载Babylon.js RecastJSPlugin生成的NavMesh数据
|
||||
/// </summary>
|
||||
/// <param name="navmeshBytes">JS端导出的二进制字节数组</param>
|
||||
/// <returns>构建好的DtNavMesh</returns>
|
||||
private static DtNavMesh LoadBabylonNavmesh(byte[] navmeshBytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 初始化NavMesh参数(使用Detour默认参数)
|
||||
DtNavMeshParams navMeshParams = new DtNavMeshParams
|
||||
{
|
||||
orig = new DotRecast.Core.Numerics.RcVec3f(0, 0, 0), // 场景原点(需与JS端烘焙时一致)
|
||||
tileWidth = 16, // Tile宽度(RecastJSPlugin默认16)
|
||||
tileHeight = 16, // Tile高度(RecastJSPlugin默认16)
|
||||
maxTiles = 1024, // 最大Tile数量(根据场景调整)
|
||||
maxPolys = 65536 // 最大多边形数量(根据场景调整)
|
||||
};
|
||||
|
||||
// 创建空的DtNavMesh
|
||||
DtNavMesh navMesh = new DtNavMesh();
|
||||
navMesh.Init(navMeshParams, 6);
|
||||
|
||||
// RecastJSPlugin的getNavmeshData返回的是单个Tile数据(大部分场景)
|
||||
// 读取Tile数据(Detour Tile格式)
|
||||
int tileRef = 0; // Tile索引(默认0,多Tile场景需循环解析)
|
||||
// 添加Tile到NavMesh
|
||||
|
||||
DtMeshData dtMeshData = new DtMeshData();
|
||||
|
||||
//if (!status.Succeeded())
|
||||
//{
|
||||
// Console.WriteLine($"添加Tile失败,状态码:{status}");
|
||||
// return null;
|
||||
//}
|
||||
|
||||
return navMesh;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"解析NavMesh失败:{ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
XNet.Business/XNet.Business.csproj
Normal file
14
XNet.Business/XNet.Business.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotRecast.Detour.Crowd" Version="2025.2.1" />
|
||||
<PackageReference Include="DotRecast.Recast" Version="2025.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -1,3 +1,4 @@
|
||||
<Solution>
|
||||
<Project Path="XNet.Business/XNet.Business.csproj" Id="6f20a48a-e217-4117-908e-8f9812f513c6" />
|
||||
<Project Path="XNet/XNet.Api.csproj" />
|
||||
</Solution>
|
||||
|
||||
16
XNet/Controllers/MapController.cs
Normal file
16
XNet/Controllers/MapController.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace XNet.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MapController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public void MapInit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,10 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\XNet.Business\XNet.Business.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user