Пример #1
0
        /// <summary>
        /// Constructs a new IOStream.
        /// </summary>
        /// <param name="pathToFile">Path to file given by Assimp</param>
        /// <param name="fileMode">Desired file access mode</param>
        public IOStream(String pathToFile, FileIOMode fileMode)
        {
            m_pathToFile = pathToFile;
            m_fileMode   = fileMode;

            m_writeProc    = OnAiFileWriteProc;
            m_readProc     = OnAiFileReadProc;
            m_tellProc     = OnAiFileTellProc;
            m_fileSizeProc = OnAiFileSizeProc;
            m_seekProc     = OnAiFileSeekProc;
            m_flushProc    = OnAiFileFlushProc;

            AiFile file;

            file.WriteProc    = Marshal.GetFunctionPointerForDelegate(m_writeProc);
            file.ReadProc     = Marshal.GetFunctionPointerForDelegate(m_readProc);
            file.TellProc     = Marshal.GetFunctionPointerForDelegate(m_tellProc);
            file.FileSizeProc = Marshal.GetFunctionPointerForDelegate(m_fileSizeProc);
            file.SeekProc     = Marshal.GetFunctionPointerForDelegate(m_seekProc);
            file.FlushProc    = Marshal.GetFunctionPointerForDelegate(m_flushProc);
            file.UserData     = IntPtr.Zero;

            m_filePtr = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <AiFile>());
            Marshal.StructureToPtr(file, m_filePtr, false);
        }
Пример #2
0
        /// <summary>
        /// Writes the managed data to the native value.
        /// </summary>
        /// <param name="thisPtr">Optional pointer to the memory that will hold the native value.</param>
        /// <param name="nativeValue">Output native value</param>
        void IMarshalable <Node, AiNode> .ToNative(IntPtr thisPtr, out AiNode nativeValue)
        {
            nativeValue.Name           = new AiString(m_name);
            nativeValue.Transformation = m_transform;
            nativeValue.Parent         = IntPtr.Zero;

            nativeValue.NumMeshes = (uint)m_meshes.Count;
            nativeValue.Meshes    = IntPtr.Zero;
            nativeValue.MetaData  = IntPtr.Zero;

            //If has metadata, create it, otherwise it should be NULL
            if (m_metaData.Count > 0)
            {
                nativeValue.MetaData = MemoryHelper.ToNativePointer <Metadata, AiMetadata>(m_metaData);
            }

            if (nativeValue.NumMeshes > 0)
            {
                nativeValue.Meshes = MemoryHelper.ToNativeArray <int>(m_meshes.ToArray());
            }

            //Now descend through the children
            nativeValue.NumChildren = (uint)m_children.Count;

            int numChildren = (int)nativeValue.NumChildren;
            int stride      = IntPtr.Size;

            IntPtr childrenPtr = IntPtr.Zero;

            if (numChildren > 0)
            {
                childrenPtr = MemoryHelper.AllocateMemory(numChildren * IntPtr.Size);

                for (int i = 0; i < numChildren; i++)
                {
                    IntPtr currPos = MemoryHelper.AddIntPtr(childrenPtr, stride * i);
                    Node   child   = m_children[i];

                    IntPtr childPtr = IntPtr.Zero;

                    //Recursively create the children and its children
                    if (child != null)
                    {
                        childPtr = ToNativeRecursive(thisPtr, child);
                    }

                    //Write the child's node ptr to our array
                    MemoryHelper.Write <IntPtr>(currPos, ref childPtr);
                }
            }

            //Finally finish writing to the native struct
            nativeValue.Children = childrenPtr;
        }
Пример #3
0
        /// <summary>
        /// Constructs a new IOSystem.
        /// </summary>
        public IOSystem()
        {
            m_openProc  = OnAiFileOpenProc;
            m_closeProc = OnAiFileCloseProc;

            AiFileIO fileIO;

            fileIO.OpenProc  = Marshal.GetFunctionPointerForDelegate(m_openProc);
            fileIO.CloseProc = Marshal.GetFunctionPointerForDelegate(m_closeProc);
            fileIO.UserData  = IntPtr.Zero;

            m_fileIOPtr = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <AiFileIO>());
            Marshal.StructureToPtr(fileIO, m_fileIOPtr, false);

            m_openedFiles = new Dictionary <IntPtr, IOStream>();
        }
Пример #4
0
        private void Initialize(LoggingCallback callback, String userData)
        {
            if (userData == null)
            {
                userData = String.Empty;
            }

            m_assimpCallback = OnAiLogStreamCallback;
            m_logCallback    = callback;
            m_userData       = userData;

            AiLogStream logStream;

            logStream.Callback = Marshal.GetFunctionPointerForDelegate(m_assimpCallback);
            logStream.UserData = IntPtr.Zero;

            m_logstreamPtr = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <AiLogStream>());
            Marshal.StructureToPtr(logStream, m_logstreamPtr, false);
        }
Пример #5
0
        /// <summary>
        /// Writes the managed data to the native value.
        /// </summary>
        /// <param name="thisPtr">Optional pointer to the memory that will hold the native value.</param>
        /// <param name="nativeValue">Output native value</param>
        void IMarshalable <Metadata, AiMetadata> .ToNative(IntPtr thisPtr, out AiMetadata nativeValue)
        {
            nativeValue = new AiMetadata();
            nativeValue.NumProperties = (uint)Count;

            AiString[]        keys    = new AiString[Count];
            AiMetadataEntry[] entries = new AiMetadataEntry[Count];
            int index = 0;

            foreach (KeyValuePair <String, Entry> kv in this)
            {
                AiMetadataEntry entry = new AiMetadataEntry();
                entry.DataType = kv.Value.DataType;

                switch (kv.Value.DataType)
                {
                case MetaDataType.Bool:
                    entry.Data = MemoryHelper.AllocateMemory(sizeof(bool));
                    bool boolValue = (bool)kv.Value.Data;
                    MemoryHelper.Write <bool>(entry.Data, ref boolValue);
                    break;

                case MetaDataType.Float:
                    entry.Data = MemoryHelper.AllocateMemory(sizeof(float));
                    float floatValue = (float)kv.Value.Data;
                    MemoryHelper.Write <float>(entry.Data, ref floatValue);
                    break;

                case MetaDataType.Int:
                    entry.Data = MemoryHelper.AllocateMemory(sizeof(int));
                    int intValue = (int)kv.Value.Data;
                    MemoryHelper.Write <int>(entry.Data, ref intValue);
                    break;

                case MetaDataType.String:
                    entry.Data = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <AiString>());
                    AiString aiStringValue = new AiString(kv.Value.Data as String);
                    MemoryHelper.Write <AiString>(entry.Data, ref aiStringValue);
                    break;

                case MetaDataType.UInt64:
                    entry.Data = MemoryHelper.AllocateMemory(sizeof(UInt64));
                    UInt64 uint64Value = (UInt64)kv.Value.Data;
                    MemoryHelper.Write <UInt64>(entry.Data, ref uint64Value);
                    break;

                case MetaDataType.Vector3D:
                    entry.Data = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <Vector3D>());
                    Vector3D vectorValue = (Vector3D)kv.Value.Data;
                    MemoryHelper.Write <Vector3D>(entry.Data, ref vectorValue);
                    break;
                }

                keys[index]    = new AiString(kv.Key);
                entries[index] = entry;
                index++;
            }

            nativeValue.keys   = MemoryHelper.ToNativeArray <AiString>(keys);
            nativeValue.Values = MemoryHelper.ToNativeArray <AiMetadataEntry>(entries);
        }
Пример #6
0
        private IntPtr ToNativeRecursive(IntPtr parentPtr, Node node)
        {
            if (node == null)
            {
                return(IntPtr.Zero);
            }

            int sizeofNative = MemoryHelper.SizeOf <AiNode>();

            //Allocate the memory that will hold the node
            IntPtr nodePtr = MemoryHelper.AllocateMemory(sizeofNative);

            //First fill the native struct
            AiNode nativeValue;

            nativeValue.Name           = new AiString(node.m_name);
            nativeValue.Transformation = node.m_transform;
            nativeValue.Parent         = parentPtr;

            nativeValue.NumMeshes = (uint)node.m_meshes.Count;
            nativeValue.Meshes    = MemoryHelper.ToNativeArray <int>(node.m_meshes.ToArray());
            nativeValue.MetaData  = IntPtr.Zero;

            //If has metadata, create it, otherwise it should be NULL
            if (m_metaData.Count > 0)
            {
                nativeValue.MetaData = MemoryHelper.ToNativePointer <Metadata, AiMetadata>(m_metaData);
            }

            //Now descend through the children
            nativeValue.NumChildren = (uint)node.m_children.Count;

            int numChildren = (int)nativeValue.NumChildren;
            int stride      = IntPtr.Size;

            IntPtr childrenPtr = IntPtr.Zero;

            if (numChildren > 0)
            {
                childrenPtr = MemoryHelper.AllocateMemory(numChildren * IntPtr.Size);

                for (int i = 0; i < numChildren; i++)
                {
                    IntPtr currPos = MemoryHelper.AddIntPtr(childrenPtr, stride * i);
                    Node   child   = node.m_children[i];

                    IntPtr childPtr = IntPtr.Zero;

                    //Recursively create the children and its children
                    if (child != null)
                    {
                        childPtr = ToNativeRecursive(nodePtr, child);
                    }

                    //Write the child's node ptr to our array
                    MemoryHelper.Write <IntPtr>(currPos, ref childPtr);
                }
            }

            //Finall finish writing to the native struct, and write the whole thing to the memory we allocated previously
            nativeValue.Children = childrenPtr;
            MemoryHelper.Write <AiNode>(nodePtr, ref nativeValue);

            return(nodePtr);
        }