public void writeWithGuide(CPNSideEdge guide, int N, float step, OutputMesh mesh,
                                   CPNGuideEvaluator evaluator)
        {
            this.step = step;
            requestSize(N + 1);

            //We should have only one thickness on multisided edge, you know?
            this.thickness = 1;

            for (int i = 0; i <= N; i++)
            {
                ts[i] = evaluator.EvalAt(i * step, guide);
                Vector3 dev = evaluator.EvalDev(guide);
                vertices[i] = evaluator.EvalVertex(guide);
                uvs[i]      = evaluator.EvalUV(guide);
                normals[i]  = evaluator.EvalNormal(guide, dev).normalized;
                for (int k = 0; k < countP; k++)
                {
                    properties[k][i] = evaluator.EvalProperty(guide, k);
                }
            }
        }
Esempio n. 2
0
        public void ExtractPolygonsProfile()
        {
            int geometriesCount = this.curvedPolygonsNet.GetGeometriesCount();
            int polygonsCount   = this.curvedPolygonsNet.GetTotalPolygonsCount();

            CPNPolygon[][] polygonsData       = tessellationOutput.InitPolygons(geometriesCount);
            int[]          builtTrianglesSize = tessellationOutput.GetBuiltTrianglesSize();
            CPNGuide[]     guides             = tessellationOutput.GetGuides();
            int            builtVerticesSize  = this.tessellationOutput.GetBuiltVerticesSize();

            int[][] polygonsProfile         = tessellationOutput.InitPolygonsProfile(geometriesCount);
            int[][] polygonsVerticesProfile = tessellationOutput.GetPolygonsVerticesProfile();

            for (int k = 0; k < geometriesCount; k++)
            {
                CPNGeometry geometry = this.curvedPolygonsNet.GetGeometries()[k];

                int overallPolygonsPosition = 0;
                int geomPolygonsCount       = geometry.GetPolygonsCount();

                builtTrianglesSize[k] = 0;
                //geometriesProfile[k] = builtTrianglesSize;
                polygonsProfile[k]         = new int[geomPolygonsCount + 1];
                polygonsVerticesProfile[k] = new int[geomPolygonsCount + 1];
                short[] polygons = geometry.GetPolygons();
                short[] schemas  = geometry.polygonsSchemas;
                polygonsData[k] = new CPNPolygon[geomPolygonsCount];

                for (int i = 0; i < geomPolygonsCount; i++)
                {
                    int polygonPosition = geometry.GetPolygonPosition(i);
                    int polygonLength   = geometry.GetPolygonLength(i);

                    int effectivePolygonSize = 0;
                    for (int j = 0; j < polygonLength; j++)
                    {
                        effectivePolygonSize++;
                        int pIndex = polygons[polygonPosition + j];
                        if (pIndex == 0)
                        {
                            j += (1 + polygons[polygonPosition + j + 1]);
                        }
                    }

                    CPNSideEdge[] iEdges = new CPNSideEdge[effectivePolygonSize];
                    int           effectivePolygonIndex = 0;
                    for (int j = 0; j < polygonLength; j++)
                    {
                        short pIndex = polygons[polygonPosition + j];
                        if (pIndex == 0)
                        {
                            int size = polygons[polygonPosition + j + 1];

                            CPNGuide[] guide  = new CPNGuide[size];
                            bool[]     direct = new bool[size];

                            for (int l = 0; l < size; l++)
                            {
                                int subPIndex = polygons[polygonPosition + j + 2 + l];
                                int edgeIndex = subPIndex > 0 ? subPIndex - 1 : -subPIndex - 1;
                                guide[l]  = guides[edgeIndex];
                                direct[l] = subPIndex > 0;
                            }
                            CPNSideEdge sideEdge = new CPNSideEdge();
                            sideEdge.Set(guide, direct);
                            iEdges[effectivePolygonIndex] = sideEdge;

                            j += (1 + polygons[polygonPosition + j + 1]);
                        }
                        else
                        {
                            int         edgeIndex = pIndex > 0 ? pIndex - 1 : -pIndex - 1;
                            bool        direct    = pIndex > 0;
                            CPNSideEdge sideEdge  = new CPNSideEdge();
                            sideEdge.Set(guides[edgeIndex], direct);
                            iEdges[effectivePolygonIndex] = sideEdge;
                        }
                        effectivePolygonIndex++;
                    }

                    CPNPolygon polygonData = new CPNPolygon();
                    int        id          = map == null ? schemas[i] : map.GetMappedInterpolatorId(schemas[i]);
                    polygonData.schemaIndex = manager.GetSchemaIndex(id);
                    polygonsData[k][i]      = polygonData;
                    polygonData.sideEdges   = iEdges;
                    polygonData.computeSkip();
                }

                for (int i = 0; i < geomPolygonsCount; i++)
                {
                    polygonsProfile[k][i]         = builtTrianglesSize[k] + overallPolygonsPosition;
                    polygonsVerticesProfile[k][i] = builtVerticesSize;

                    CPNPolygon polygonData   = polygonsData[k][i];
                    int        polygonLength = polygonData.sideEdges.Length;
                    if (polygonLength > 2 && polygonLength < TESSELLATION_PROCESS_NET_INTERPOLATORS &&
                        !polygonData.skip)
                    {
                        ICPNetInterpolator netInterpolator = manager.GetSchema(polygonData.schemaIndex).
                                                             interpolators[polygonLength];
                        netInterpolator.RetrieveInfos(polygonData);
                        builtVerticesSize     += netInterpolator.GetComputedInternals();
                        builtTrianglesSize[k] += netInterpolator.GetComputedTriangles();
                    }
                }
                polygonsProfile[k][geomPolygonsCount]         = builtTrianglesSize[k] + overallPolygonsPosition;
                polygonsVerticesProfile[k][geomPolygonsCount] = builtTrianglesSize[k];


                builtTrianglesSize[k] += geometry.GetTrianglesCount();
                builtTrianglesSize[k] += geometry.GetQuadsCount() << 1;

                overallPolygonsPosition = polygonsProfile[k][geomPolygonsCount];
            }

            this.tessellationOutput.SetBuiltVerticesSize(builtVerticesSize);
        }
 public void writeWithGuide(CPNSideEdge guide, int N, OutputMesh mesh,
                            CPNGuideEvaluator evaluator)
 {
     writeWithGuide(guide, N, 1.0f / N, mesh, evaluator);
 }