Beispiel #1
0
 /// <summary>
 /// Constructs a new node and initializes it.
 /// </summary>
 /// <param name="parentNode">Parent node or null for root nodes</param>
 public Node(Node parentNode)
 {
     this.mParent = parentNode;
 }
Beispiel #2
0
        /// <summary>
        /// Constructor which builds a Node object from a pointer to an aiNode structure.  As a user, you should not call this by hand.
        /// <remarks>This will copy the data inside the structure into managed memory.  It *DOES NOT* free the unmanaged memory.</remarks>
        /// </summary>
        /// <param name="aiNode*">A pointer to the face structure in the low level unmanaged wrapper.</param>
        internal unsafe Node(IntPtr p_aiNode, Node pParent)
        {
            // Unmarshal our structure into (what will be for us, some temporary) managed memory.  This is naturally, automatically released when we exit the function.
            UnmanagedAssimp.aiNode tNode = (UnmanagedAssimp.aiNode)Marshal.PtrToStructure(p_aiNode, typeof(UnmanagedAssimp.aiNode));

            // Copy over the nice, simple value types into managed memory.  Value types copy the entire structure rather than just the pointer to it.
            this.mTransformation = tNode.mTransformation;

            // Copy the properties over into our class as marshalled managed memory.
            // Note that with strings, prepending an empty string "" forces a copy.
            this.sName      = "" + tNode.mName.data;

            // Check the parent is not null.
            //this.mParent = null;
            //if (tNode.mParent != IntPtr.Zero)
            //    this.mParent = new Node(tNode.mParent);

            // To link the heirarchy we use a .NET reference to the parent.  This assumes we create in hierarchy order.
            this.mParent = pParent;

            // If we have children.
            if (tNode.mNumChildren > 0)
            {
                // Copy over the array of node animations into managed memory belonging to this class instance.
                int iIntPtrSize = sizeof(IntPtr);
                tChildren = new Node[tNode.mNumChildren];
                IntPtr pChildPtr = tNode.mChildren;
                for (int iElement = 0; iElement < tNode.mNumChildren; ++iElement)
                {
                    // Copy the element at this index and then increment the channel pointer (which should be sizeof(IntPtr) away.
                    tChildren[iElement] = new Node(Marshal.ReadIntPtr(pChildPtr), this);
                    pChildPtr = new IntPtr(pChildPtr.ToInt64() + iIntPtrSize);
                }
            }

            // Marshal the array of unsigned integers for each mesh.
            tMeshes = UnmanagedAssimp.MarshalUintArray(tNode.mMeshes, tNode.mNumMeshes);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor which builds a Scene object from a pointer to an aiScene structure.  As a user, you should not call this by hand.
        /// <remarks>This will copy the data inside the structure into managed memory.  It *DOES NOT* free the unmanaged memory.</remarks>
        /// </summary>
        /// <param name="aiScene*">A pointer to the aiScene structure in the low level unmanaged wrapper.</param>
        /// <param name="sFileName">The filename from which we are loaded.  Just for posterity purposes.</param>
        internal unsafe Scene(IntPtr p_aiScene, String sFileName)
        {
            // Unmarshal our structure into (what will be for us, some temporary) managed memory.  This is naturally, automatically released when we exit the function.
            UnmanagedAssimp.aiScene tScene = (UnmanagedAssimp.aiScene)Marshal.PtrToStructure(p_aiScene, typeof(UnmanagedAssimp.aiScene));

            // Using our scene, get the memory information taken up.
            UnmanagedAssimp.aiGetMemoryRequirements((UnmanagedAssimp.aiScene*)p_aiScene.ToPointer(), out tMemoryInfo);

            // Filename.
            this.sFileName      = sFileName;

            // Define a couple of variables that we will use to do the iteration.
            int iStride         = sizeof(IntPtr);
            IntPtr pIterator    = IntPtr.Zero;

            // Copy nice simple value types into managed memory.
            this.eFlags = tScene.mFlags;

            // Create the root node.  It has a null parent because it is the root node!
            // It's important to note that by calling this - all the nodes in the heirarchy will self-create and link recursively.
            // It will NOT load any of the meshs or data into managed memory.
            pRootNode = new Node(tScene.mRootNode, null);

            // MESH
            // Now we need to load each mesh into managed memory.
            //Console.WriteLine("<Mesh Loading>");
            tMeshes     = new Mesh[tScene.mNumMeshes];
            pIterator   = tScene.mMeshes;
            for (int iCount = 0; iCount < tScene.mNumMeshes; ++iCount)
            {
                tMeshes[iCount] = new Mesh(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Mesh Loading>");

            // MATERIAL
            //Console.WriteLine("<Material Loading>");
            tMaterials = new Material[tScene.mNumMaterials];
            pIterator = tScene.mMaterials;
            for (int iCount = 0; iCount < tScene.mNumMaterials; ++iCount)
            {
                tMaterials[iCount] = new Material(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Material Loading>");

            // ANIMATION.
            //Console.WriteLine("<Animation Loading>");
            tAnimations = new Animation[tScene.mNumAnimations];
            pIterator   = tScene.mAnimations;
            for (int iCount = 0; iCount < tScene.mNumAnimations; ++iCount)
            {
                tAnimations[iCount] = new Animation(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Animation Loading>");

            // EMBEDDED TEXTURES.
            //Console.WriteLine("<Embedded Texture Loading>");
            tTextures = new Texture[tScene.mNumTextures];
            pIterator = tScene.mTextures;
            for (int iCount = 0; iCount < tScene.mNumTextures; ++iCount)
            {
                tTextures[iCount] = new Texture(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Embedded Texture Loading>");

            // LIGHTS.
            //Console.WriteLine("<Light Loading>");
            tLights     = new Light[tScene.mNumLights];
            pIterator   = tScene.mLights;
            for (int iCount = 0; iCount < tScene.mNumLights; ++iCount)
            {
                tLights[iCount] = new Light(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Light Loading>");

            // CAMERAS.
            //Console.WriteLine("<Camera Loading>");
            tCameras    = new Camera[tScene.mNumCameras];
            pIterator   = tScene.mCameras;
            for (int iCount = 0; iCount < tScene.mNumCameras; ++iCount)
            {
                tCameras[iCount] = new Camera(Marshal.ReadIntPtr(pIterator));
                pIterator = new IntPtr(pIterator.ToInt64() + iStride);
            }
            //Console.WriteLine("</Camera Loading>");
        }