Exemplo n.º 1
0
        int WriteVertices(OutputMesh mesh)
        {
            int numberOfVertices = subSet == null?curvedPolygonsNet.GetNumberOfVertices() :
                                       subSet.vertices.Length;

            Vector3[]   vertices        = curvedPolygonsNet.GetVertices();
            Vector3[]   normals         = curvedPolygonsNet.GetNormals();
            Vector3[]   uvs             = curvedPolygonsNet.GetUv();
            Vector3[][] properties      = curvedPolygonsNet.GetProperties3();
            int         countProperties = mesh.CountProperties();
            //Vector3[] tangents = curvedPolygonsNet.GetTangents();
            //bool doTangents = tangents != null;
            bool doUvs     = uvs != null && mesh.DoUseUVs();
            bool doNormals = normals != null && mesh.DoNormals();

            for (int i = 0; i < numberOfVertices; i++)
            {
                int index = subSet == null ? i : subSet.vertices[i];
                mesh.SetVertex(index, vertices[index]);
                if (doUvs)
                {
                    mesh.SetUV(index, uvs[index]);
                }
                if (doNormals)
                {
                    mesh.SetNormal(index, normals[index]);
                }
                for (int k = 0; k < countProperties; k++)
                {
                    mesh.SetProperty3(index, k, properties[k][index]);
                }
            }


            return(numberOfVertices);
        }
        public void EvaluateEdge(CurvedPolygonsNet net, OutputMesh mesh, CPNGuide guide,
                                 short edgeLength, short[] edge, int edgeIndex, short[] edgeHints,
                                 float[] edgeWeights, int[] edgeProfile, int realEdgeIndex)
        {
            bool isLinear = edgeLength == 2;

            bool uvAvailable = net.GetUv() != null && net.GetUv().Length != 0 && mesh.DoUseUVs();
            int  countP      = mesh.CountProperties();

            short[] tessellationDegrees = CPNGuide_loqs;

            if (isLinear)
            {
                FillBufferWithLine(guide.vBuffer, net.GetVertices(), edge, edgeIndex);
                if (uvAvailable)
                {
                    FillBufferWithLine(guide.uvsBuffer, net.GetUv(), edge, edgeIndex);
                }
                guide.PreparePropertiesBuffers(countP);
                for (int k = 0; k < countP; k++)
                {
                    FillBufferWithLine(guide.propertiesBuffer[k], net.GetProperties3()[k], edge, edgeIndex);
                }
            }
            else
            {
                FillBuffer(guide.vBuffer, net.GetVertices(), edge, edgeIndex);
                if (uvAvailable)
                {
                    FillBuffer(guide.uvsBuffer, net.GetUv(), edge, edgeIndex);
                }
                guide.PreparePropertiesBuffers(countP);
                for (int k = 0; k < countP; k++)
                {
                    FillBuffer(guide.propertiesBuffer[k], net.GetProperties3()[k], edge, edgeIndex);
                }
            }

            //if (tgAvailable)  //Avoid tangents for now
            //    FillBuffer(linear, polyline.tgsBuffer, net.GetTangents(), edge, edgeIndex);

            int handleIndex = (realEdgeIndex) << 1;

            guide.w2 = edgeWeights[handleIndex + 0];
            guide.w3 = edgeWeights[handleIndex + 1];


            guide.edgeNormal  = net.GetNormals()[net.GetNumberOfVertices() + realEdgeIndex];
            guide.firstNormal = net.GetNormals()[edge[edgeIndex + 0]];
            guide.lastNormal  = net.GetNormals()[edge[edgeIndex + (isLinear? 1 : 3)]];

            //float r = edgeRots == null ? 0 : edgeRots[edgeProfileIndex];
            //float r3 = edgeRots == null ? 0 : edgeRots[handleIndex + 1];

            int N1 = 1;
            int N2 = 1;

            if (!isLinear)
            {
                N1 = tessellationDegrees[edgeHints[handleIndex + 0]];
                N2 = tessellationDegrees[edgeHints[handleIndex + 1]];
            }

            int N = guide.GetN();

            float c = (2.0f * N1 * N2) / (N * (N1 + N2));

            guide.tessellationStepA = c / N1;
            guide.tessellationStepB = c * 0.5f * (N1 - N2) / (N1 * N2 * N * 1.0f);

            int edgeInternal = edgeProfile[((realEdgeIndex) << 2) + 2];

            float step = 1.0f / N;

            for (int j = 1; j < N; j++)
            {
                int index = edgeInternal + j - 1;
                EvalAt(j * step, guide);
                mesh.SetVertex(index, EvalVertex(guide));
                if (uvAvailable)
                {
                    mesh.SetUV(index, EvalUV(guide));
                }
                for (int k = 0; k < countP; k++)
                {
                    mesh.SetProperty3(index, k, EvalProperty(guide, k));
                }
            }
        }