Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Instantiates <see cref="CubismUnmanagedMoc"/>.
        /// </summary>
        /// <param name="moc">Moc.</param>
        /// <returns>Instance on success; <see langword="null"/> otherwise.</returns>
        public static CubismUnmanagedModel FromMoc(CubismUnmanagedMoc moc)
        {
            if (moc == null)
            {
                return(null);
            }


            var model = new CubismUnmanagedModel(moc);


            return((model.Ptr != IntPtr.Zero)
                ? model
                : null);
        }
        /// <summary>
        /// Creates <see cref="CubismUnmanagedMoc"/> from bytes.
        /// </summary>
        /// <param name="bytes">Moc bytes.</param>
        /// <returns>Instance on success; <see langword="null"/> otherwise.</returns>
        public static CubismUnmanagedMoc FromBytes(byte[] bytes)
        {
            if (bytes == null)
            {
                return(null);
            }


            var moc = new CubismUnmanagedMoc(bytes);


            return((moc.Ptr != IntPtr.Zero)
                ? moc
                : null);
        }