예제 #1
0
 /// <summary>
 /// Blends two meshes.
 /// </summary>
 /// <param name="fromIndexA">The index of the first mesh to blend from.</param>
 /// <param name="toIndexA">The index of the first mesh to blend to.</param>
 /// <param name="factorA">The blend factor of the first mesh.</param>
 /// <param name="fromIndexB">The index of the second mesh to blend from.</param>
 /// <param name="toIndexB">The index of the second mesh to blend to.</param>
 /// <param name="factorB">The blend factor of the second mesh.</param>
 /// <param name="factor">The blend factor between meshA and meshB.</param>
 public void Blend(int fromIndexA, int toIndexA, float factorA,
                   int fromIndexB, int toIndexB, float factorB, float factor)
 {
     CreateMesh();
     if (factor < float.Epsilon)
     {
         Blend(fromIndexA, toIndexA, factorA);
     }
     else if (factor >= 1.0f - float.Epsilon)
     {
         Blend(fromIndexB, toIndexB, factorB);
     }
     else
     {
         for (int i = 0; i < tempMesh.SubSets.Count; i++)
         {
             SubSet         ssTarget  = (SubSet)tempMesh.SubSets[i];
             PositionStream psTarget  = (PositionStream)ssTarget.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceA = (SubSet)meshes[fromIndexA].SubSets[i];
             PositionStream psSourceA = (PositionStream)ssSourceA.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceB = (SubSet)meshes[toIndexA].SubSets[i];
             PositionStream psSourceB = (PositionStream)ssSourceB.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceC = (SubSet)meshes[fromIndexB].SubSets[i];
             PositionStream psSourceC = (PositionStream)ssSourceC.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceD = (SubSet)meshes[toIndexB].SubSets[i];
             PositionStream psSourceD = (PositionStream)ssSourceD.VertexUnit[typeof(PositionStream)];
             for (int l = 0; l < psTarget.Size; l++)
             {
                 psTarget[l] = Vector3.Lerp(Vector3.Lerp(psSourceA[l], psSourceB[l], factorA),
                                            Vector3.Lerp(psSourceC[l], psSourceD[l], factorB), factor);
             }
             psTarget.Upload();
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Blends two meshes.
 /// </summary>
 /// <param name="fromIndex">The index of the mesh to blend from.</param>
 /// <param name="toIndex">The index of the mesh to blend to.</param>
 /// <param name="factor">The blend factor.</param>
 private void Blend(int fromIndex, int toIndex, float factor)
 {
     CreateMesh();
     if (fromIndex == toIndex || factor < float.Epsilon)
     {
         Fill(fromIndex);
     }
     else if (factor >= 1.0f - float.Epsilon)
     {
         Fill(toIndex);
     }
     else
     {
         for (int i = 0; i < tempMesh.SubSets.Count; i++)
         {
             SubSet         ssTarget  = (SubSet)tempMesh.SubSets[i];
             PositionStream psTarget  = (PositionStream)ssTarget.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceA = (SubSet)meshes[fromIndex].SubSets[i];
             PositionStream psSourceA = (PositionStream)ssSourceA.VertexUnit[typeof(PositionStream)];
             SubSet         ssSourceB = (SubSet)meshes[toIndex].SubSets[i];
             PositionStream psSourceB = (PositionStream)ssSourceB.VertexUnit[typeof(PositionStream)];
             for (int l = 0; l < psTarget.Size; l++)
             {
                 psTarget[l] = Vector3.Lerp(psSourceA[l], psSourceB[l], factor);
             }
             psTarget.Upload();
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Returns true if two subsets can be merged.
 /// </summary>
 /// <remarks>Same material and same vertex format.</remarks>
 /// <param name="s2">Subset to merge.</param>
 /// <returns>True if it is possible.</returns>
 public bool CanMerge(SubSet s2)
 {
     if (VertexUnit.Format != s2.VertexUnit.Format)
     {
         return(false);
     }
     return(true);
 }
예제 #4
0
        /// <summary>
        /// Create a <see cref="SubSet"/> from an unindexed <see cref="VertexUnit"/>.
        /// </summary>
        /// <param name="vertexUnit"><see cref="VertexUnit"/> to indexify.</param>
        /// <returns>The created <see cref="SubSet"/>.</returns>
        public static SubSet Indexify(VertexUnit vertexUnit)
        {
            VertexUnit  vUnit;
            IndexStream indexStream;

            vertexUnit.Indexify(out vUnit, out indexStream);
            SubSet result = new SubSet(vUnit, indexStream);

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Draws a subset with given index.
        /// </summary>
        /// <remarks>
        /// For drawing a whole mesh, the method <c>Draw</c> should be used for optimized speed.
        /// </remarks>
        /// <param name="effect">The current effect that is used for rendering.</param>
        /// <param name="index">Index of the subSet to draw.</param>
        public void DrawSubSet(IEffect effect, int index)
        {
            // Apply next texture if there is one in the texture list.
            if (Textures.Count > index)
            {
                (Textures[index] as Textures).Apply();
            }

            effect.CommitChanges();
            SubSet s = (SubSet)subSets[index];

            (subSets[index] as SubSet).Draw();
        }
예제 #6
0
 /// <summary>
 /// Fills the temporary mesh with the mesh at a certain index.
 /// </summary>
 /// <param name="index">Index of source mesh.</param>
 /// <returns>The temporary mesh.</returns>
 private void Fill(int index)
 {
     CreateMesh();
     for (int i = 0; i < tempMesh.SubSets.Count; i++)
     {
         SubSet         ssTarget = (SubSet)tempMesh.SubSets[i];
         PositionStream psTarget = (PositionStream)ssTarget.VertexUnit[typeof(PositionStream)];
         SubSet         ssSource = (SubSet)meshes[index].SubSets[i];
         PositionStream psSource = (PositionStream)ssSource.VertexUnit[typeof(PositionStream)];
         Array.Copy(psSource.Data, 0, psTarget.Data, 0, psTarget.Size);
         psTarget.Upload();
     }
 }
예제 #7
0
        private SubSetData CreateSubSetData(SubSet subSet)
        {
            VertexUnit vu = subSet.VertexUnit;

            if (!vu.Format.Contains(Semantic.BoneIndices) ||
                !vu.Format.Contains(Semantic.BoneIndices) ||
                !vu.Format.Contains(Semantic.Position))
            {
                return(null);
            }

            SubSetData     ssData    = new SubSetData();
            PositionStream posStream = (PositionStream)vu[typeof(PositionStream)];

            ssData.Position = (Vector3[])posStream.Data.Clone();
            if (vu.Format.Contains(typeof(NormalStream)))
            {
                NormalStream normalStream = (NormalStream)vu[typeof(NormalStream)];
                ssData.Normal = (Vector3[])normalStream.Data.Clone();
            }

            return(ssData);
        }
예제 #8
0
        /// <summary>
        /// Merges two subsets.
        /// </summary>
        /// <param name="subSet">Subset to merge with.</param>
        public void Merge(SubSet subSet)
        {
            if (!CanMerge(subSet))
            {
                throw new GraphicsException("Subsets can't be merged!");
            }

            // Merge vertex unit
            VertexUnit unit = new VertexUnit(VertexUnit.Format, VertexUnit.Size + subSet.VertexUnit.Size);

            VertexUnit.Copy(VertexUnit, 0, unit, 0, VertexUnit.Size);
            VertexUnit.Copy(subSet.VertexUnit, 0, unit, VertexUnit.Size, subSet.VertexUnit.Size);

            VertexUnit.Dispose();
            VertexUnit = unit;

            // Merge index streams
            IndexStream index = IndexStream.Create(IndexStream.Size + subSet.IndexStream.Size, IndexStream.GetType());

            VertexStreams.IndexStream.Copy(IndexStream, 0, index, 0, IndexStream.Size, 0);
            VertexStreams.IndexStream.Copy(subSet.IndexStream, 0, index, IndexStream.Size, subSet.IndexStream.Size, VertexUnit.Size);
            IndexStream.Dispose();
            IndexStream = index;
        }
예제 #9
0
 void SetSubSet(SubSet subSet)
 {
     data    = new SubSetData[1];
     data[0] = CreateSubSetData(subSet);
 }
예제 #10
0
        /// <summary>
        /// Clones the current <see cref="SubSet"/>, whereby the format is changed to the fit the semantics given.
        /// </summary>
        /// <remarks>
        /// Uses deep copy (just <see cref="VertexUnit"/> is cloned but not <see cref="IndexStream"/>).
        /// </remarks>
        /// <param name="semantics"></param>
        /// <returns></returns>
        public SubSet Clone(Semantic[] semantics)
        {
            SubSet ret = new SubSet(VertexUnit.Clone(semantics), IndexStream, IndexBufferStart, PrimitiveCount);

            return(ret);
        }
예제 #11
0
        /// <summary>
        /// Clones the current <see cref="SubSet"/>, whereby the format of the <see cref="VertexUnit"/>
        /// is changed to the given <see cref="VertexFormat"/>.
        /// </summary>
        /// <remarks>
        /// Uses deep copy (just <see cref="VertexUnit"/> is cloned but not <see cref="IndexStream"/>).
        /// </remarks>
        /// <param name="format"></param>
        /// <returns></returns>
        public SubSet Clone(VertexFormat format)
        {
            SubSet ret = new SubSet(VertexUnit.Clone(format), IndexStream, IndexBufferStart, PrimitiveCount);

            return(ret);
        }
예제 #12
0
 /// <summary>
 /// Creates a new instance of a <see cref="Mesh"/>.
 /// </summary>
 /// <param name="subSet">SubSet to add to the mesh.</param>
 public Mesh(SubSet subSet)
 {
     this.SubSets.Add(subSet);
 }
예제 #13
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Methods
        //---------------------------------------------------------------
        /// <summary>
        /// adds a subSet to the list
        /// </summary>
        /// <param name="subSet">subSet to add</param>
        public void Add(SubSet subSet)
        {
            subSets.Add(subSet);
        }