This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5e0fb0
commit 3d64805
Showing
6 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Numerics; | ||
using PxCs.Data.Struct; | ||
|
||
namespace PxCs.Data.BspTree | ||
{ | ||
public class PxBspNodeData | ||
{ | ||
public Vector4 plane; | ||
public PxAABBData bbox; | ||
public uint polygonIndex; | ||
public uint polygonCount; | ||
public int frontNodeIndex; | ||
public int backNodeIndex; | ||
public int parentNodeIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace PxCs.Data.BspTree | ||
{ | ||
[Serializable] | ||
public class PxBspSectorData | ||
{ | ||
public string name; | ||
public uint[] nodeIndices; | ||
public uint[] portalPolygonIndices; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Numerics; | ||
using System.Runtime.InteropServices; | ||
using PxCs.Data.BspTree; | ||
using PxCs.Data.Struct; | ||
using PxCs.Extensions; | ||
|
||
namespace PxCs.Interface | ||
{ | ||
public class PxBspTree | ||
{ | ||
private const string DLLNAME = PxPhoenix.DLLNAME; | ||
|
||
public enum PxBspTreeMode | ||
{ | ||
PxBspIndoor = 0, | ||
PxBspOutdoor = 1, | ||
} | ||
|
||
[DllImport(DLLNAME)] public static extern PxBspTreeMode pxBspGetMode(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetPolygonIndicesLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern IntPtr pxBspGetPolygonIndices(IntPtr bsp, out ulong size); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetLeafPolygonIndicesLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern IntPtr pxBspGetLeafPolygonIndices(IntPtr bsp, out ulong size); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetPortalPolygonIndicesLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern IntPtr pxBspGetPortalPolygonIndices(IntPtr bsp, out ulong size); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetLeafNodeIndicesLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern IntPtr pxBspGetLeafNodeIndices(IntPtr bsp, out ulong size); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetLightPointsLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern Vector3 pxBspGetLightPoint(IntPtr bsp, ulong idx); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetSectorsLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern void pxBspGetSector(IntPtr bsp, ulong idx, out IntPtr name, out IntPtr nodeIndices, | ||
out ulong nodeIndicesLength, out IntPtr portalPolygonIndices, out ulong portalPolygonIndicesLength); | ||
[DllImport(DLLNAME)] public static extern ulong pxBspGetNodesLength(IntPtr bsp); | ||
[DllImport(DLLNAME)] public static extern void pxBspGetNode(IntPtr bsp, ulong idx, out Vector4 plane, out PxAABBData bbox, | ||
out uint polygonIndex, out uint polygonCount, out int frontNodeIndex, out int backNodeIndex, | ||
out int parentNodeIndex); | ||
|
||
|
||
public static uint[] GetPolygonIndices(IntPtr bsp) | ||
{ | ||
return pxBspGetPolygonIndices(bsp, out ulong size).MarshalAsArray<uint>((uint)size); | ||
} | ||
|
||
public static uint[] GetLeafPolygonIndices(IntPtr bsp) | ||
{ | ||
return pxBspGetLeafPolygonIndices(bsp, out ulong size).MarshalAsArray<uint>((uint)size); | ||
} | ||
|
||
public static uint[] GetPortalPolygonIndices(IntPtr bsp) | ||
{ | ||
return pxBspGetPortalPolygonIndices(bsp, out ulong size).MarshalAsArray<uint>((uint)size); | ||
} | ||
|
||
public static ulong[] GetLeadNodeIndices(IntPtr bsp) | ||
{ | ||
return pxBspGetLeafNodeIndices(bsp, out ulong size).MarshalAsArray<ulong>((uint)size); | ||
} | ||
|
||
public static Vector3[] GetLightPoints(IntPtr bsp) | ||
{ | ||
var length = pxBspGetLightPointsLength(bsp); | ||
var array = new Vector3[length]; | ||
|
||
for (var i = 0u; i < length; ++i) | ||
{ | ||
array[i] = pxBspGetLightPoint(bsp, i); | ||
} | ||
|
||
return array; | ||
} | ||
|
||
public static PxBspSectorData[] GetSectors(IntPtr bsp) | ||
{ | ||
var length = pxBspGetSectorsLength(bsp); | ||
var array = new PxBspSectorData[length]; | ||
|
||
for (var i = 0u; i < length; ++i) | ||
{ | ||
pxBspGetSector(bsp, i, out IntPtr name, out IntPtr nodeIndices, | ||
out ulong nodeIndicesLength, out IntPtr portalPolygonIndices, out ulong portalPolygonIndicesLength); | ||
|
||
array[i] = new PxBspSectorData | ||
{ | ||
name = name.MarshalAsString(), | ||
nodeIndices = nodeIndices.MarshalAsArray<uint>((uint)nodeIndicesLength), | ||
portalPolygonIndices = portalPolygonIndices.MarshalAsArray<uint>((uint)portalPolygonIndicesLength) | ||
}; | ||
} | ||
|
||
return array; | ||
} | ||
|
||
public static PxBspNodeData[] GetNodes(IntPtr bsp) | ||
{ | ||
var length = pxBspGetNodesLength(bsp); | ||
var array = new PxBspNodeData[length]; | ||
|
||
for (var i = 0u; i < length; ++i) | ||
{ | ||
array[i] = new PxBspNodeData(); | ||
pxBspGetNode(bsp, i, out array[i].plane, out array[i].bbox, out array[i].polygonIndex, | ||
out array[i].polygonCount, out array[i].frontNodeIndex, out array[i].backNodeIndex, | ||
out array[i].parentNodeIndex); | ||
} | ||
|
||
return array; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters