예제 #1
0
        Vector3 CalculateAvg(VMeshData vm, ushort sv)
        {
            for (int i = 0; i < averages.Count; i++)
            {
                if (averages[i].StartVertex == sv && averages[i].VMesh == vm)
                {
                    return(averages[i].Point);
                }
            }
            var    v        = sv + StartVertex;
            double x        = 0;
            double y        = 0;
            double z        = 0;
            var    vertType = vm.VertexBuffer.VertexType.GetType();

            for (int i = TriangleStart; i < TriangleStart + NumRefVertices; i++)
            {
                Vector3 vert = Vector3.Zero;
                int     idx  = vm.Indices[i] + v;
                if (vertType == typeof(VertexPosition))
                {
                    vert = vm.verticesVertexPosition[idx].Position;
                }
                else if (vertType == typeof(VertexPositionNormal))
                {
                    vert = vm.verticesVertexPositionNormal[idx].Position;
                }
                else if (vertType == typeof(VertexPositionTexture))
                {
                    vert = vm.verticesVertexPositionTexture[idx].Position;
                }
                else if (vertType == typeof(VertexPositionNormalDiffuseTexture))
                {
                    vert = vm.verticesVertexPositionNormalDiffuseTexture[idx].Position;
                }
                else if (vertType == typeof(VertexPositionNormalTexture))
                {
                    vert = vm.verticesVertexPositionNormalTexture[idx].Position;
                }
                else if (vertType == typeof(VertexPositionNormalTextureTwo))
                {
                    vert = vm.verticesVertexPositionNormalTextureTwo[idx].Position;
                }
                else if (vertType == typeof(VertexPositionNormalDiffuseTextureTwo))
                {
                    vert = vm.verticesVertexPositionNormalDiffuseTextureTwo[idx].Position;
                }
                else
                {
                    throw new Exception();
                }
                x += vert.X;
                y += vert.Y;
                z += vert.Z;
            }
            x /= NumRefVertices;
            y /= NumRefVertices;
            z /= NumRefVertices;
            var avg = new Vector3((float)x, (float)y, (float)z);

            averages.Add(new Average()
            {
                VMesh = vm, StartVertex = sv, Point = avg
            });
            return(avg);
        }