예제 #1
0
 internal static bool AreApproxEqual(DiffuseOnlyVertex lhs, DiffuseOnlyVertex rhs)
 {
     return
         (VertexComparer.PositionsAreApproxEqual(lhs.Position, rhs.Position) &&
          VertexComparer.NormalsAreApproxEqual(lhs.Normal, rhs.Normal) &&
          VertexComparer.UVsAreApproxEqual(lhs.DiffuseUV, rhs.DiffuseUV));
 }
예제 #2
0
        internal override void Optimize()
        {
            // build a new vertex buffer and a new index buffer
            var optimizedVertices = new List <DiffuseOnlyVertex>();
            var optimizedIndices  = new List <int>();

            foreach (int index in indices_)
            {
                DiffuseOnlyVertex thisVertex = vertices_[index];
                int thisVertexIndex          = 0;

                bool foundMatch = false;
                foreach (DiffuseOnlyVertex optimizedVertex in optimizedVertices)
                {
                    if ((thisVertex != optimizedVertex) && (DiffuseOnlyVertex.AreApproxEqual(thisVertex, optimizedVertex)))
                    {
                        optimizedIndices.Add(thisVertexIndex);
                        foundMatch = true;
                        break;
                    }

                    ++thisVertexIndex;
                }

                if (!foundMatch)
                {
                    // Add a new vertex to the optimized list
                    optimizedIndices.Add(optimizedVertices.Count);
                    optimizedVertices.Add(thisVertex);
                }
            }

            vertices_ = optimizedVertices;
            indices_  = optimizedIndices;
        }
예제 #3
0
        internal override void ParseAndTransformTriangle(Matrix4x4 nodeToModelMatrix,
                                                         XElement v0Element, XElement v1Element, XElement v2Element)
        {
            DiffuseOnlyVertex v0 = ParseAndTransformVertex(nodeToModelMatrix, v0Element);
            DiffuseOnlyVertex v1 = ParseAndTransformVertex(nodeToModelMatrix, v1Element);
            DiffuseOnlyVertex v2 = ParseAndTransformVertex(nodeToModelMatrix, v2Element);

            vertices_.Add(v0);
            indices_.Add(indices_.Count);
            vertices_.Add(v1);
            indices_.Add(indices_.Count);
            vertices_.Add(v2);
            indices_.Add(indices_.Count);
        }