/// <summary> /// Initializes instance. /// </summary> /// <param name="moc">Moc.</param> private CubismUnmanagedModel(CubismUnmanagedMoc moc) { // Allocate and initialize memory (returning on fail). var size = CubismCoreDll.GetSizeofModel(moc.Ptr); var memory = CubismUnmanagedMemory.Allocate((int)size, CubismCoreDll.AlignofModel); if (memory == IntPtr.Zero) { return; } // Initialize native model (cleaning up and returning on fail). Ptr = CubismCoreDll.InitializeModelInPlace(moc.Ptr, memory, size); if (Ptr == IntPtr.Zero) { CubismUnmanagedMemory.Deallocate(memory); return; } // Initialize 'components'. Parameters = new CubismUnmanagedParameters(Ptr); Parts = new CubismUnmanagedParts(Ptr); Drawables = new CubismUnmanagedDrawables(Ptr); }
/// <summary> /// Releases instance. /// </summary> public void Release() { if (Ptr == IntPtr.Zero) { return; } CubismUnmanagedMemory.Deallocate(Ptr); Ptr = IntPtr.Zero; }
/// <summary> /// Initializes instance. /// </summary> /// <param name="bytes">Moc bytes.</param> private CubismUnmanagedMoc(byte[] bytes) { // Allocate and initialize memory (returning on fail). var memory = CubismUnmanagedMemory.Allocate(bytes.Length, CubismCoreDll.AlignofMoc); if (memory == IntPtr.Zero) { return; } CubismUnmanagedMemory.Write(bytes, memory); // Revive native moc (cleaning up on fail). Ptr = CubismCoreDll.ReviveMocInPlace(memory, (uint)bytes.Length); if (Ptr == IntPtr.Zero) { CubismUnmanagedMemory.Deallocate(memory); } }