Exemplo n.º 1
0
 public Vertex this[int index]
 {
     get {
         switch (index)
         {
         case 0:
             return p0;
         case 1:
             return p1;
         case 2:
             return p2;
         case 3:
             return p3;
         default:
             throw new ArgumentException("index must be 0 - 3");
         }
     }
     set {
         switch (index)
         {
         case 0:
             p0 = value;
             break;
         case 1:
             p1 = value;
             break;
         case 2:
             p2 = value;
             break;
         case 3:
             p3 = value;
             break;
         }
     }
 }
Exemplo n.º 2
0
        public static Triangle[] ToTriangles(Quad quad)
        {
            Triangle[] tris = new Triangle[2];

            VertexDeclaration quadDecl = quad.p0.VertexDeclaration;
            tris[0] = new Triangle();
            tris[1] = new Triangle();

            for (int i = 0; i < 3; ++i)
            {
                tris[0][i] = new Vertex(quadDecl);
                tris[1][i] = new Vertex(quadDecl);
            }

            tris[0].p0.FromArray(quad[0].ToArray());
            tris[0].p1.FromArray(quad[1].ToArray());
            tris[0].p2.FromArray(quad[2].ToArray());

            tris[1].p0.FromArray(quad[0].ToArray());
            tris[1].p1.FromArray(quad[2].ToArray());
            tris[1].p2.FromArray(quad[3].ToArray());

            return tris;
        }
Exemplo n.º 3
0
        private void PopulateMesh()
        {
            int offset = 0;

            tris = new Triangle[triCount];
            int triPos = 0;

            for (int i = 0; i < polyVertexCount.Length; ++i)
            {
                IPoly poly;

                if (polyVertexCount[i] == 3)
                    poly = new Triangle();
                else
                    poly = new Quad();

                for (int j = 0; j < polyVertexCount[i]; ++j)
                {
                    float[] datArray = new float[_vertexDeclaration.Stride];
                    int index = 0;

                    foreach (KeyValuePair<string, Semantic> inputSemantic in semantics)
                    {
                        var channel = _vertexDeclaration.GetChannel(inputSemantic.Key);
                        index = indices[(semantics.Count * offset) + inputSemantic.Value.Offset];
                        float[] sourceData = sources[inputSemantic.Value.SourceName].data;
                        int sourceStride = sources[inputSemantic.Value.SourceName].stride;
                        PopulateArray(sourceData, index * sourceStride, datArray, channel.Offset, channel.Stride);
                    }

                    poly[j] = new Vertex(_vertexDeclaration);
                    poly[j].FromArray(datArray);
                    ++offset;
                }
                if (polyVertexCount[i] == 4)
                {
                    Triangle[] quadTris = PrimitiveHelper.ToTriangles(poly as Quad);
                    quadTris.CopyTo(tris, triPos);
                    triPos += 2;
                }
                else
                {
                    tris[triPos] = (Triangle)poly;
                    ++triPos;
                }
            }
        }