public CubismMoc(Stream moc) { using var memory = new MemoryStream(); moc.CopyTo(memory); var bytes = memory.ToArray(); bufferPtr = Marshal.AllocHGlobal(bytes.Length + CubismCore.ALIGN_OF_MOC - 1); var aligned = CubismUtils.Align(bufferPtr, CubismCore.ALIGN_OF_MOC); Marshal.Copy(bytes, 0, aligned, bytes.Length); Handle = CubismCore.csmReviveMocInPlace(aligned, bytes.Length); Version = CubismCore.csmGetMocVersion(aligned); if (Handle == IntPtr.Zero) { throw new ArgumentException($"{nameof(moc)} is not a valid Cubism Model."); } if (Version > CubismCore.LatestMocVersion) { throw new ArgumentException($"{nameof(moc)} has version '{Version}' while Core can only support up to '{CubismCore.LatestMocVersion}'."); } }
public CubismModel(CubismMoc moc) { this.moc = moc; int size = CubismCore.csmGetSizeofModel(moc.Handle); bufferPtr = Marshal.AllocHGlobal(size + CubismCore.ALIGN_OF_MODEL - 1); Handle = CubismCore.csmInitializeModelInPlace(moc.Handle, CubismUtils.Align(bufferPtr, CubismCore.ALIGN_OF_MODEL), size); managers.AddRange(new CubismIdManager[] { Parts = new CubismPartManager(Handle), Drawables = new CubismDrawableManager(Handle), Parameters = new CubismParameterManager(Handle), }); float[] sizeInPixels = new float[2]; float[] originInPixels = new float[2]; CubismCore.csmReadCanvasInfo(Handle, sizeInPixels, originInPixels, out float pixelsPerUnit); Size = new Vector2(sizeInPixels[0], sizeInPixels[1]) / pixelsPerUnit; // Obtain default values first foreach (var manager in managers) { manager.PostModelUpdate(); } }