Ejemplo n.º 1
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 <MeshAnimationAttachment, AiAnimMesh> .ToNative(IntPtr thisPtr, out AiAnimMesh nativeValue)
        {
            nativeValue.Vertices      = IntPtr.Zero;
            nativeValue.Normals       = IntPtr.Zero;
            nativeValue.Tangents      = IntPtr.Zero;
            nativeValue.BiTangents    = IntPtr.Zero;
            nativeValue.Colors        = new AiMeshColorArray();
            nativeValue.TextureCoords = new AiMeshTextureCoordinateArray();
            nativeValue.NumVertices   = (uint)VertexCount;
            nativeValue.Weight        = Weight;

            if (VertexCount > 0)
            {
                //Since we can have so many buffers of Vector3D with same length, lets re-use a buffer
                Vector3D[] copy = new Vector3D[VertexCount];

                nativeValue.Vertices = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_vertices, copy));

                if (HasNormals)
                {
                    nativeValue.Normals = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_normals, copy));
                }

                if (HasTangentBasis)
                {
                    nativeValue.Tangents   = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_tangents, copy));
                    nativeValue.BiTangents = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_bitangents, copy));
                }

                //Vertex Color channels
                for (int i = 0; i < m_colors.Length; i++)
                {
                    List <Color4D> list = m_colors[i];

                    if (list == null || list.Count == 0)
                    {
                        nativeValue.Colors[i] = IntPtr.Zero;
                    }
                    else
                    {
                        nativeValue.Colors[i] = MemoryHelper.ToNativeArray <Color4D>(list.ToArray());
                    }
                }

                //Texture coordinate channels
                for (int i = 0; i < m_texCoords.Length; i++)
                {
                    List <Vector3D> list = m_texCoords[i];

                    if (list == null || list.Count == 0)
                    {
                        nativeValue.TextureCoords[i] = IntPtr.Zero;
                    }
                    else
                    {
                        nativeValue.TextureCoords[i] = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(list, copy));
                    }
                }
            }
        }
Ejemplo n.º 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 <EmbeddedTexture, AiTexture> .ToNative(IntPtr thisPtr, out AiTexture nativeValue)
        {
            if (IsCompressed)
            {
                nativeValue.Width  = (uint)CompressedDataSize;
                nativeValue.Height = 0;
                nativeValue.Data   = IntPtr.Zero;

                if (CompressedDataSize > 0)
                {
                    nativeValue.Data = MemoryHelper.ToNativeArray <byte>(m_compressedData);
                }

                nativeValue.SetFormatHint(m_compressedFormatHint);
            }
            else
            {
                nativeValue.Width  = (uint)m_width;
                nativeValue.Height = (uint)m_height;
                nativeValue.Data   = IntPtr.Zero;

                if (NonCompressedDataSize > 0)
                {
                    nativeValue.Data = MemoryHelper.ToNativeArray <Texel>(m_nonCompressedData);
                }

                nativeValue.SetFormatHint(null);
            }
        }
Ejemplo n.º 3
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 <NodeAnimationChannel, AiNodeAnim> .ToNative(IntPtr thisPtr, out AiNodeAnim nativeValue)
        {
            nativeValue.NodeName  = new AiString(m_nodeName);
            nativeValue.Prestate  = m_preState;
            nativeValue.PostState = m_postState;

            nativeValue.NumPositionKeys = (uint)m_positionKeys.Count;
            nativeValue.PositionKeys    = IntPtr.Zero;

            if (nativeValue.NumPositionKeys > 0)
            {
                nativeValue.PositionKeys = MemoryHelper.ToNativeArray <VectorKey>(m_positionKeys.ToArray());
            }


            nativeValue.NumRotationKeys = (uint)m_rotationKeys.Count;
            nativeValue.RotationKeys    = IntPtr.Zero;

            if (nativeValue.NumRotationKeys > 0)
            {
                nativeValue.RotationKeys = MemoryHelper.ToNativeArray <QuaternionKey>(m_rotationKeys.ToArray());
            }


            nativeValue.NumScalingKeys = (uint)m_scalingKeys.Count;
            nativeValue.ScalingKeys    = IntPtr.Zero;

            if (nativeValue.NumScalingKeys > 0)
            {
                nativeValue.ScalingKeys = MemoryHelper.ToNativeArray <VectorKey>(m_scalingKeys.ToArray());
            }
        }
Ejemplo n.º 4
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 <Animation, AiAnimation> .ToNative(IntPtr thisPtr, out AiAnimation nativeValue)
        {
            nativeValue.Name                 = new AiString(m_name);
            nativeValue.Duration             = m_duration;
            nativeValue.TicksPerSecond       = m_ticksPerSecond;
            nativeValue.NumChannels          = (uint)NodeAnimationChannelCount;
            nativeValue.NumMeshChannels      = (uint)MeshAnimationChannelCount;
            nativeValue.NumMeshMorphChannels = (uint)MeshMorphAnimationChannelCount;
            nativeValue.Channels             = IntPtr.Zero;
            nativeValue.MeshChannels         = IntPtr.Zero;
            nativeValue.MeshMorphChannels    = IntPtr.Zero;

            if (nativeValue.NumChannels > 0)
            {
                nativeValue.Channels = MemoryHelper.ToNativeArray <NodeAnimationChannel, AiNodeAnim>(m_nodeChannels.ToArray(), true);
            }

            if (nativeValue.NumMeshChannels > 0)
            {
                nativeValue.MeshChannels = MemoryHelper.ToNativeArray <MeshAnimationChannel, AiMeshAnim>(m_meshChannels.ToArray(), true);
            }

            if (nativeValue.NumMeshMorphChannels > 0)
            {
                nativeValue.MeshMorphChannels = MemoryHelper.ToNativeArray <MeshMorphAnimationChannel, AiMeshMorphAnim>(m_meshMorphChannels.ToArray(), true);
            }
        }
Ejemplo n.º 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 <Face, AiFace> .ToNative(IntPtr thisPtr, out AiFace nativeValue)
        {
            nativeValue.NumIndices = (uint)IndexCount;
            nativeValue.Indices    = IntPtr.Zero;

            if (nativeValue.NumIndices > 0)
            {
                nativeValue.Indices = MemoryHelper.ToNativeArray <int>(m_indices.ToArray());
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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 <MeshAnimationChannel, AiMeshAnim> .ToNative(IntPtr thisPtr, out AiMeshAnim nativeValue)
        {
            nativeValue.Name    = new AiString(m_name);
            nativeValue.NumKeys = (uint)MeshKeyCount;
            nativeValue.Keys    = IntPtr.Zero;

            if (nativeValue.NumKeys > 0)
            {
                nativeValue.Keys = MemoryHelper.ToNativeArray <MeshKey>(m_meshKeys.ToArray());
            }
        }
Ejemplo n.º 8
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 <Bone, AiBone> .ToNative(IntPtr thisPtr, out AiBone nativeValue)
        {
            nativeValue.Name         = new AiString(m_name);
            nativeValue.OffsetMatrix = m_offsetMatrix;
            nativeValue.NumWeights   = (uint)m_weights.Count;
            nativeValue.Weights      = IntPtr.Zero;

            if (nativeValue.NumWeights > 0)
            {
                nativeValue.Weights = MemoryHelper.ToNativeArray <VertexWeight>(m_weights.ToArray());
            }
        }
Ejemplo n.º 9
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 <MaterialProperty, AiMaterialProperty> .ToNative(IntPtr thisPtr, out AiMaterialProperty nativeValue)
        {
            nativeValue.Key        = new AiString(m_name);
            nativeValue.Type       = m_type;
            nativeValue.Index      = (uint)m_texIndex;
            nativeValue.Semantic   = m_texType;
            nativeValue.Data       = IntPtr.Zero;
            nativeValue.DataLength = 0;

            if (m_rawValue != null)
            {
                nativeValue.DataLength = (uint)m_rawValue.Length;
                nativeValue.Data       = MemoryHelper.ToNativeArray <byte>(m_rawValue);
            }
        }
Ejemplo n.º 10
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 <MeshMorphKey, AiMeshMorphKey> .ToNative(IntPtr thisPtr, out AiMeshMorphKey nativeValue)
        {
            nativeValue.Time = m_time;
            nativeValue.NumValuesAndWeights = (uint)m_weights.Count;
            nativeValue.Values  = IntPtr.Zero;
            nativeValue.Weights = IntPtr.Zero;

            System.Diagnostics.Debug.Assert(m_weights.Count == m_values.Count);
            if (m_weights.Count == m_values.Count)
            {
                if (m_weights.Count > 0)
                {
                    nativeValue.Values  = MemoryHelper.ToNativeArray <int>(m_values.ToArray());
                    nativeValue.Weights = MemoryHelper.ToNativeArray <double>(m_weights.ToArray());
                }
            }
            else
            {
                //If both lists are not the same length then do not write anything out
                nativeValue.NumValuesAndWeights = 0;
            }
        }
Ejemplo n.º 11
0
        private static unsafe byte[] SetMaterialString(String value, byte[] existing)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(null);
            }

            int stringSize = Encoding.UTF8.GetByteCount(value);

            if (stringSize < 0)
            {
                return(null);
            }

            int size = stringSize + 1 + sizeof(int);

            byte[] data = existing;

            if (existing == null || existing.Length != size)
            {
                data = new byte[size];

                fixed(byte *bytePtr = &data[0])
                {
                    MemoryHelper.Write <int>(new IntPtr(bytePtr), ref stringSize);
                    byte[] utfBytes = Encoding.UTF8.GetBytes(value);
                    MemoryHelper.Write <byte>(new IntPtr(bytePtr + sizeof(int)), utfBytes, 0, utfBytes.Length);
                    //Last byte should be zero
                }

                return(data);
        }

        #region IMarshalable Implementation

        /// <summary>
        /// Gets if the native value type is blittable (that is, does not require marshaling by the runtime, e.g. has MarshalAs attributes).
        /// </summary>
        bool IMarshalable <MaterialProperty, AiMaterialProperty> .IsNativeBlittable {
            get { return(true); }
        }

        /// <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 <MaterialProperty, AiMaterialProperty> .ToNative(IntPtr thisPtr, out AiMaterialProperty nativeValue)
        {
            nativeValue.Key        = new AiString(m_name);
            nativeValue.Type       = m_type;
            nativeValue.Index      = (uint)m_texIndex;
            nativeValue.Semantic   = m_texType;
            nativeValue.Data       = IntPtr.Zero;
            nativeValue.DataLength = 0;

            if (m_rawValue != null)
            {
                nativeValue.DataLength = (uint)m_rawValue.Length;
                nativeValue.Data       = MemoryHelper.ToNativeArray <byte>(m_rawValue);
            }
        }

        /// <summary>
        /// Reads the unmanaged data from the native value.
        /// </summary>
        /// <param name="nativeValue">Input native value</param>
        void IMarshalable <MaterialProperty, AiMaterialProperty> .FromNative(ref AiMaterialProperty nativeValue)
        {
            m_name     = nativeValue.Key.GetString();
            m_type     = nativeValue.Type;
            m_texIndex = (int)nativeValue.Index;
            m_texType  = nativeValue.Semantic;
            m_rawValue = null;

            if (nativeValue.DataLength > 0 && nativeValue.Data != IntPtr.Zero)
                m_rawValue = MemoryHelper.FromNativeArray <byte>(nativeValue.Data, (int)nativeValue.DataLength); }
        }
Ejemplo n.º 12
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 <Mesh, AiMesh> .ToNative(IntPtr thisPtr, out AiMesh nativeValue)
        {
            nativeValue.Name            = new AiString(m_name);
            nativeValue.Vertices        = IntPtr.Zero;
            nativeValue.Normals         = IntPtr.Zero;
            nativeValue.Tangents        = IntPtr.Zero;
            nativeValue.BiTangents      = IntPtr.Zero;
            nativeValue.AnimMeshes      = IntPtr.Zero;
            nativeValue.Bones           = IntPtr.Zero;
            nativeValue.Faces           = IntPtr.Zero;
            nativeValue.Colors          = new AiMeshColorArray();
            nativeValue.TextureCoords   = new AiMeshTextureCoordinateArray();
            nativeValue.NumUVComponents = new AiMeshUVComponentArray();
            nativeValue.PrimitiveTypes  = m_primitiveType;
            nativeValue.MaterialIndex   = (uint)m_materialIndex;
            nativeValue.NumVertices     = (uint)VertexCount;
            nativeValue.NumBones        = (uint)BoneCount;
            nativeValue.NumFaces        = (uint)FaceCount;
            nativeValue.NumAnimMeshes   = (uint)MeshAnimationAttachmentCount;
            nativeValue.MorphMethod     = m_morphMethod;

            if (nativeValue.NumVertices > 0)
            {
                //Since we can have so many buffers of Vector3D with same length, lets re-use a buffer
                Vector3D[] copy = new Vector3D[nativeValue.NumVertices];

                nativeValue.Vertices = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_vertices, copy));

                if (HasNormals)
                {
                    nativeValue.Normals = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_normals, copy));
                }

                if (HasTangentBasis)
                {
                    nativeValue.Tangents   = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_tangents, copy));
                    nativeValue.BiTangents = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(m_bitangents, copy));
                }

                //Vertex Color channels
                for (int i = 0; i < m_colors.Length; i++)
                {
                    List <Color4D> list = m_colors[i];

                    if (list == null || list.Count == 0)
                    {
                        nativeValue.Colors[i] = IntPtr.Zero;
                    }
                    else
                    {
                        nativeValue.Colors[i] = MemoryHelper.ToNativeArray <Color4D>(list.ToArray());
                    }
                }

                //Texture coordinate channels
                for (int i = 0; i < m_texCoords.Length; i++)
                {
                    List <Vector3D> list = m_texCoords[i];

                    if (list == null || list.Count == 0)
                    {
                        nativeValue.TextureCoords[i] = IntPtr.Zero;
                    }
                    else
                    {
                        nativeValue.TextureCoords[i] = MemoryHelper.ToNativeArray <Vector3D>(CopyTo(list, copy));
                    }
                }

                //UV components for each tex coordinate channel
                for (int i = 0; i < m_texComponentCount.Length; i++)
                {
                    nativeValue.NumUVComponents[i] = (uint)m_texComponentCount[i];
                }
            }

            //Faces
            if (nativeValue.NumFaces > 0)
            {
                nativeValue.Faces = MemoryHelper.ToNativeArray <Face, AiFace>(m_faces.ToArray());
            }

            //Bones
            if (nativeValue.NumBones > 0)
            {
                nativeValue.Bones = MemoryHelper.ToNativeArray <Bone, AiBone>(m_bones.ToArray(), true);
            }

            //Attachment meshes
            if (nativeValue.NumAnimMeshes > 0)
            {
                nativeValue.AnimMeshes = MemoryHelper.ToNativeArray <MeshAnimationAttachment, AiAnimMesh>(m_meshAttachments.ToArray());
            }
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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 <Scene, AiScene> .ToNative(IntPtr thisPtr, out AiScene nativeValue)
        {
            nativeValue.Flags       = m_flags;
            nativeValue.Materials   = IntPtr.Zero;
            nativeValue.RootNode    = IntPtr.Zero;
            nativeValue.Meshes      = IntPtr.Zero;
            nativeValue.Lights      = IntPtr.Zero;
            nativeValue.Cameras     = IntPtr.Zero;
            nativeValue.Textures    = IntPtr.Zero;
            nativeValue.Animations  = IntPtr.Zero;
            nativeValue.PrivateData = IntPtr.Zero;

            nativeValue.NumMaterials  = (uint)MaterialCount;
            nativeValue.NumMeshes     = (uint)MeshCount;
            nativeValue.NumLights     = (uint)LightCount;
            nativeValue.NumCameras    = (uint)CameraCount;
            nativeValue.NumTextures   = (uint)TextureCount;
            nativeValue.NumAnimations = (uint)AnimationCount;

            //Write materials
            if (nativeValue.NumMaterials > 0)
            {
                nativeValue.Materials = MemoryHelper.ToNativeArray <Material, AiMaterial>(m_materials.ToArray(), true);
            }

            //Write scenegraph
            if (m_rootNode != null)
            {
                nativeValue.RootNode = MemoryHelper.ToNativePointer <Node, AiNode>(m_rootNode);
            }

            //Write meshes
            if (nativeValue.NumMeshes > 0)
            {
                nativeValue.Meshes = MemoryHelper.ToNativeArray <Mesh, AiMesh>(m_meshes.ToArray(), true);
            }

            //Write lights
            if (nativeValue.NumLights > 0)
            {
                nativeValue.Lights = MemoryHelper.ToNativeArray <Light, AiLight>(m_lights.ToArray(), true);
            }

            //Write cameras
            if (nativeValue.NumCameras > 0)
            {
                nativeValue.Cameras = MemoryHelper.ToNativeArray <Camera, AiCamera>(m_cameras.ToArray(), true);
            }

            //Write textures
            if (nativeValue.NumTextures > 0)
            {
                nativeValue.Textures = MemoryHelper.ToNativeArray <EmbeddedTexture, AiTexture>(m_textures.ToArray(), true);
            }

            //Write animations
            if (nativeValue.NumAnimations > 0)
            {
                nativeValue.Animations = MemoryHelper.ToNativeArray <Animation, AiAnimation>(m_animations.ToArray(), true);
            }
        }