22using System . Collections . Generic ;
33using System . Numerics ;
44using System . Runtime . InteropServices ;
5+ using ZenKit . Util ;
56
67namespace ZenKit
78{
9+ [ Serializable ]
810 public enum BspTreeType
911 {
1012 Indoor = 0 ,
1113 Outdoor = 1
1214 }
1315
16+ [ Serializable ]
1417 [ StructLayout ( LayoutKind . Sequential , Size = 60 ) ]
1518 public struct BspNode
1619 {
@@ -23,7 +26,31 @@ public struct BspNode
2326 public int ParentIndex ;
2427 }
2528
26- public class BspSector
29+ namespace Materialized
30+ {
31+ [ Serializable ]
32+ public struct BspSector
33+ {
34+ public string Name ;
35+ public uint [ ] NodeIndices ;
36+ public uint [ ] PortalPolygonIndices ;
37+ }
38+
39+ [ Serializable ]
40+ public struct BspTree
41+ {
42+ public BspTreeType Type ;
43+ public uint [ ] PolygonIndices ;
44+ public uint [ ] LeafPolygonIndices ;
45+ public uint [ ] PortalPolygonIndices ;
46+ public Vector3 [ ] LightPoints ;
47+ public ulong [ ] LeafNodeIndices ;
48+ public BspNode [ ] Nodes ;
49+ public List < BspSector > Sectors ;
50+ }
51+ }
52+
53+ public class BspSector : IMaterializing < Materialized . BspSector >
2754 {
2855 private readonly UIntPtr _handle ;
2956
@@ -35,13 +62,29 @@ internal BspSector(UIntPtr handle)
3562 public string Name => Native . ZkBspSector_getName ( _handle ) . MarshalAsString ( ) ??
3663 throw new Exception ( "Failed to load bsp sector name" ) ;
3764
38- public uint [ ] NodeIndices => Native . ZkBspSector_getNodeIndices ( _handle , out var count ) . MarshalAsArray < uint > ( count ) ;
65+ public uint [ ] NodeIndices =>
66+ Native . ZkBspSector_getNodeIndices ( _handle , out var count ) . MarshalAsArray < uint > ( count ) ;
3967
4068 public uint [ ] PortalPolygonIndices =>
4169 Native . ZkBspSector_getPortalPolygonIndices ( _handle , out var count ) . MarshalAsArray < uint > ( count ) ;
70+
71+ /// <summary>
72+ /// Fully loads this native object into a C# serializable object, disassociated
73+ /// from the underlying native implementation.
74+ /// </summary>
75+ /// <returns>This native object in a pure C# representation.</returns>
76+ public Materialized . BspSector Materialize ( )
77+ {
78+ return new Materialized . BspSector
79+ {
80+ Name = Name ,
81+ NodeIndices = NodeIndices ,
82+ PortalPolygonIndices = PortalPolygonIndices
83+ } ;
84+ }
4285 }
4386
44- public class BspTree
87+ public class BspTree : IMaterializing < Materialized . BspTree >
4588 {
4689 private readonly UIntPtr _handle ;
4790
@@ -86,6 +129,26 @@ public List<BspSector> Sectors
86129 }
87130 }
88131
132+ /// <summary>
133+ /// Fully loads this native object into a C# serializable object, disassociated
134+ /// from the underlying native implementation.
135+ /// </summary>
136+ /// <returns>This native object in a pure C# representation.</returns>
137+ public Materialized . BspTree Materialize ( )
138+ {
139+ return new Materialized . BspTree
140+ {
141+ Type = Type ,
142+ PolygonIndices = PolygonIndices ,
143+ LeafPolygonIndices = LeafPolygonIndices ,
144+ PortalPolygonIndices = PortalPolygonIndices ,
145+ LightPoints = LightPoints ,
146+ LeafNodeIndices = LeafNodeIndices ,
147+ Nodes = Nodes ,
148+ Sectors = Sectors . ConvertAll ( sector => sector . Materialize ( ) )
149+ } ;
150+ }
151+
89152 public BspSector GetSector ( ulong i )
90153 {
91154 return new BspSector ( Native . ZkBspTree_getSector ( _handle , i ) ) ;
0 commit comments