diff --git a/ZenKit/Mesh.cs b/ZenKit/Mesh.cs index 01c9e43..6440983 100644 --- a/ZenKit/Mesh.cs +++ b/ZenKit/Mesh.cs @@ -121,20 +121,22 @@ public bool IsCached() public class Polygon : IPolygon { private readonly UIntPtr _handle; + private readonly Mesh _mesh; - public Polygon(UIntPtr handle) + internal Polygon(UIntPtr handle, Mesh mesh) { _handle = handle; + _mesh = mesh; } public int MaterialIndex => (int)Native.ZkPolygon_getMaterialIndex(_handle); public int LightMapIndex => Native.ZkPolygon_getLightMapIndex(_handle); public List PositionIndices => - Native.ZkPolygon_getPositionIndices(_handle, out var count).MarshalAsList(count); + Native.ZkPolygon_getPositionIndices(_handle, _mesh.Handle, out var count).MarshalAsList(count); public List FeatureIndices => - Native.ZkPolygon_getFeatureIndices(_handle, out var count).MarshalAsList(count); + Native.ZkPolygon_getFeatureIndices(_handle, _mesh.Handle, out var count).MarshalAsList(count); public bool IsPortal => Native.ZkPolygon_getIsPortal(_handle); public bool IsOccluder => Native.ZkPolygon_getIsOccluder(_handle); @@ -259,44 +261,44 @@ public IPolygon GetPolygon(int i) public class Mesh : IMesh { private readonly bool _delete = true; - private readonly UIntPtr _handle; + internal readonly UIntPtr Handle; public Mesh(string path) { - _handle = Native.ZkMesh_loadPath(path); - if (_handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); + Handle = Native.ZkMesh_loadPath(path); + if (Handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); } public Mesh(Read buf) { - _handle = Native.ZkMesh_load(buf.Handle); - if (_handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); + Handle = Native.ZkMesh_load(buf.Handle); + if (Handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); } public Mesh(Vfs vfs, string name) { - _handle = Native.ZkMesh_loadVfs(vfs.Handle, name); - if (_handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); + Handle = Native.ZkMesh_loadVfs(vfs.Handle, name); + if (Handle == UIntPtr.Zero) throw new Exception("Failed to load mesh"); } internal Mesh(UIntPtr handle) { - _handle = handle; + Handle = handle; _delete = false; } - public DateTime? SourceDate => Native.ZkMesh_getSourceDate(_handle).AsDateTime(); + public DateTime? SourceDate => Native.ZkMesh_getSourceDate(Handle).AsDateTime(); - public string Name => Native.ZkMesh_getName(_handle).MarshalAsString() ?? + public string Name => Native.ZkMesh_getName(Handle).MarshalAsString() ?? throw new Exception("Failed to load mesh name"); - public AxisAlignedBoundingBox BoundingBox => Native.ZkMesh_getBoundingBox(_handle); + public AxisAlignedBoundingBox BoundingBox => Native.ZkMesh_getBoundingBox(Handle); public IOrientedBoundingBox OrientedBoundingBox => - new OrientedBoundingBox(Native.ZkMesh_getOrientedBoundingBox(_handle)); + new OrientedBoundingBox(Native.ZkMesh_getOrientedBoundingBox(Handle)); - public int MaterialCount => (int)Native.ZkMesh_getMaterialCount(_handle); + public int MaterialCount => (int)Native.ZkMesh_getMaterialCount(Handle); public List Materials { @@ -309,7 +311,7 @@ public List Materials } } - public int PositionCount => (int)Native.ZkMesh_getPositionCount(_handle); + public int PositionCount => (int)Native.ZkMesh_getPositionCount(Handle); public List Positions { @@ -322,7 +324,7 @@ public List Positions } } - public int FeatureCount => (int)Native.ZkMesh_getVertexCount(_handle); + public int FeatureCount => (int)Native.ZkMesh_getVertexCount(Handle); public List Features { @@ -335,7 +337,7 @@ public List Features } } - public int LightMapCount => (int)Native.ZkMesh_getLightMapCount(_handle); + public int LightMapCount => (int)Native.ZkMesh_getLightMapCount(Handle); public List LightMap { @@ -348,7 +350,7 @@ public List LightMap } } - public int PolygonCount => (int)Native.ZkMesh_getPolygonCount(_handle); + public int PolygonCount => (int)Native.ZkMesh_getPolygonCount(Handle); public List Polygons { @@ -384,32 +386,32 @@ public bool IsCached() public IMaterial GetMaterial(int i) { - return new Material(Native.ZkMesh_getMaterial(_handle, (ulong)i)); + return new Material(Native.ZkMesh_getMaterial(Handle, (ulong)i)); } public Vector3 GetPosition(int i) { - return Native.ZkMesh_getPosition(_handle, (ulong)i); + return Native.ZkMesh_getPosition(Handle, (ulong)i); } public Vertex GetFeature(int i) { - return Native.ZkMesh_getVertex(_handle, (ulong)i); + return Native.ZkMesh_getVertex(Handle, (ulong)i); } public ILightMap GetLightMap(int i) { - return new LightMap(Native.ZkMesh_getLightMap(_handle, (ulong)i)); + return new LightMap(Native.ZkMesh_getLightMap(Handle, (ulong)i)); } public IPolygon GetPolygon(int i) { - return new Polygon(Native.ZkMesh_getPolygon(_handle, (ulong)i)); + return new Polygon(Native.ZkMesh_getPolygon(Handle, (ulong)i), this); } ~Mesh() { - if (_delete) Native.ZkMesh_del(_handle); + if (_delete) Native.ZkMesh_del(Handle); } } } \ No newline at end of file diff --git a/ZenKit/Native.cs b/ZenKit/Native.cs index c6bae0d..5dda360 100644 --- a/ZenKit/Native.cs +++ b/ZenKit/Native.cs @@ -843,10 +843,10 @@ public static extern void ZkModelMesh_enumerateAttachments(UIntPtr slf, ZkAttach public static extern int ZkPolygon_getLightMapIndex(UIntPtr slf); [DllImport(DllName)] - public static extern IntPtr ZkPolygon_getPositionIndices(UIntPtr slf, out ulong count); + public static extern IntPtr ZkPolygon_getPositionIndices(UIntPtr slf, UIntPtr msh, out ulong count); [DllImport(DllName)] - public static extern IntPtr ZkPolygon_getFeatureIndices(UIntPtr slf, out ulong count); + public static extern IntPtr ZkPolygon_getFeatureIndices(UIntPtr slf, UIntPtr msh, out ulong count); [DllImport(DllName)] public static extern bool ZkPolygon_getIsPortal(UIntPtr slf); diff --git a/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so b/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so index c7b93d9..0fc71b8 100644 Binary files a/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so and b/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so differ diff --git a/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so b/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so index 4d1d04f..e1ffaa5 100644 Binary files a/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so and b/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so differ diff --git a/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib b/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib index 57e8cee..3bfbb50 100644 Binary files a/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib and b/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib differ diff --git a/ZenKit/runtimes/win-x64/native/zenkitcapi.dll b/ZenKit/runtimes/win-x64/native/zenkitcapi.dll index 8f4e331..0d74c11 100644 Binary files a/ZenKit/runtimes/win-x64/native/zenkitcapi.dll and b/ZenKit/runtimes/win-x64/native/zenkitcapi.dll differ