Exemple #1
0
        /// <summary>
        /// Generates a new mesh with reordered faces and vertices to optimize drawing performance.
        /// </summary>
        /// <remarks>
        /// This method generates a new mesh. Before running Optimize, an application must generate an adjacency buffer by calling <see cref="SharpDX.Direct3D10.Mesh.GenerateAdjacencyAndPointRepresentation"/>. The adjacency buffer contains adjacency data, such as a list of edges and the faces that are adjacent to each other. This method is very similar to the <see cref="SharpDX.Direct3D10.Mesh.CloneMesh"/> method, except that it can perform optimization while generating the new clone of the mesh. The output mesh inherits all of the creation parameters of the input mesh.
        /// </remarks>
        /// <param name="flags">Specifies the type of optimization to perform. This parameter can be set to a combination of one or more flags from D3DXMESHOPT and D3DXMESH (except D3DXMESH_32BIT, D3DXMESH_IB_WRITEONLY, and D3DXMESH_WRITEONLY). </param>
        /// <param name="faceRemap">An array of UINTs, one per face, that identifies the original mesh face that corresponds to each face in the optimized mesh.</param>
        /// <param name="vertexRemap">An array of index for each vertex that specifies how the new vertices map to the old vertices. This remap is useful if you need to alter external data based on the new vertex mapping. </param>
        /// <returns>The return value is one of the values listed in {{Direct3D 10 Return Codes}}. </returns>
        /// <unmanaged>HRESULT ID3DX10Mesh::Optimize([None] int Flags,[Out, Buffer, Optional] int* pFaceRemap,[In] LPD3D10BLOB* ppVertexRemap)</unmanaged>
        public void Optimize(MeshOptimizeFlags flags, out int[] faceRemap, out int[] vertexRemap)
        {
            IntPtr     blobPtr;
            DataStream dataStream = null;

            unsafe
            {
                try
                {
                    faceRemap = new int[FaceCount];
                    Optimize((int)flags, faceRemap, new IntPtr(&blobPtr));
                    dataStream  = new DataStream(new Blob(blobPtr));
                    vertexRemap = dataStream.ReadRange <int>(VertexCount);
                    dataStream.Dispose();
                }
                catch (Exception)
                {
                    faceRemap   = null;
                    vertexRemap = null;
                    if (dataStream != null)
                    {
                        dataStream.Dispose();
                    }
                    throw;
                }
            }
        }
        //--------------------//

        #region Optimize
        /// <summary>
        /// Performs an in-place optimization of a <see cref="Mesh"/>.
        /// </summary>
        /// <param name="mesh">The <see cref="Mesh"/> to be optimized.</param>
        public static void Optimize(Mesh mesh)
        {
            using (new TimedLogEvent("Optimized mesh"))
            {
                const MeshOptimizeFlags flags = MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.AttributeSort;

                mesh.GenerateAdjacency(0);
                mesh.OptimizeInPlace(flags);
            }
        }
Exemple #3
0
        /// <summary>	
        /// Generates a new mesh with reordered faces and vertices to optimize drawing performance.	
        /// </summary>	
        /// <remarks>	
        /// This method generates a new mesh. Before running Optimize, an application must generate an adjacency buffer by calling <see cref="SharpDX.Direct3D10.Mesh.GenerateAdjacencyAndPointRepresentation"/>. The adjacency buffer contains adjacency data, such as a list of edges and the faces that are adjacent to each other. This method is very similar to the <see cref="SharpDX.Direct3D10.Mesh.CloneMesh"/> method, except that it can perform optimization while generating the new clone of the mesh. The output mesh inherits all of the creation parameters of the input mesh. 	
        /// </remarks>	
        /// <param name="flags">Specifies the type of optimization to perform. This parameter can be set to a combination of one or more flags from D3DXMESHOPT and D3DXMESH (except D3DXMESH_32BIT, D3DXMESH_IB_WRITEONLY, and D3DXMESH_WRITEONLY). </param>
        /// <param name="faceRemap">An array of UINTs, one per face, that identifies the original mesh face that corresponds to each face in the optimized mesh.</param>
        /// <param name="vertexRemap">An array of index for each vertex that specifies how the new vertices map to the old vertices. This remap is useful if you need to alter external data based on the new vertex mapping. </param>
        /// <returns>The return value is one of the values listed in {{Direct3D 10 Return Codes}}. </returns>
        /// <unmanaged>HRESULT ID3DX10Mesh::Optimize([None] int Flags,[Out, Buffer, Optional] int* pFaceRemap,[In] LPD3D10BLOB* ppVertexRemap)</unmanaged>
        public void Optimize(MeshOptimizeFlags flags, out int[] faceRemap, out int[] vertexRemap)
        {

            IntPtr blobPtr;
            DataStream dataStream = null;
            unsafe
            {
                try
                {
                    faceRemap = new int[FaceCount];
                    Optimize((int)flags, faceRemap, new IntPtr(&blobPtr));
                    dataStream = new DataStream(new Blob(blobPtr));
                    vertexRemap = dataStream.ReadRange<int>(VertexCount);
                    dataStream.Dispose();
                }
                catch (Exception)
                {
                    faceRemap = null;
                    vertexRemap = null;
                    if (dataStream!=null)
                        dataStream.Dispose();
                    throw;
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Optimizes the mesh data.
 /// </summary>
 /// <param name="flags">Flags indicating which optimizations to perform.</param>
 /// <returns>A result code.</returns>
 public Result Optimize(MeshOptimizeFlags flags)
 {
     Optimize((int) flags, null, IntPtr.Zero); 
     return Result.Ok;
 }
Exemple #5
0
 /// <summary>
 /// Optimizes the mesh data.
 /// </summary>
 /// <param name="flags">Flags indicating which optimizations to perform.</param>
 /// <returns>A result code.</returns>
 public Result Optimize(MeshOptimizeFlags flags)
 {
     Optimize((int)flags, null, IntPtr.Zero);
     return(Result.Ok);
 }