Пример #1
0
        int WritePolygons(OutputMesh mesh, int position)
        {
            int geometriesCount = this.curvedPolygonsNet.GetGeometriesCount();

            CPNPolygon[][] polygons                = tessellationOutput.GetPolygons();
            int[][]        polygonsProfile         = tessellationOutput.GetPolygonsProfile();
            int[][]        polygonsVerticesProfile = tessellationOutput.GetPolygonsVerticesProfile();

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

                int geomPolygonsCount = subSet == null?geometry.GetPolygonsCount() : subSet.polygons[k].Length;

                for (int i = 0; i < geomPolygonsCount; i++)
                {
                    int        index = subSet == null ? i : subSet.polygons[k][i];
                    int        countEffectiveSize = polygons[k][index].sideEdges.Length;
                    CPNPolygon polygonData        = polygons[k][index];

                    if (countEffectiveSize > 2 && countEffectiveSize < TESSELLATION_PROCESS_NET_INTERPOLATORS &&
                        !polygonData.skip)
                    {
                        polygonData.computeSideEdgesSizes();
                        ICPNetInterpolator netInterpolator = manager.GetSchema(polygonData.schemaIndex).
                                                             interpolators[countEffectiveSize];

                        netInterpolator.UdpdateContent(mesh, polygonData, polygonsVerticesProfile[k][index],
                                                       polygonsProfile[k][index]);
                    }
                }
                position += polygonsVerticesProfile[k][geometry.GetPolygonsCount()];

                int     triangleIndex  = polygonsProfile[k][geometry.GetPolygonsCount()];
                int     trianglesCount = geometry.GetTrianglesCount();
                short[] triangles      = geometry.GetTriangles();
                for (int i = 0; i < trianglesCount; i++)
                {
                    mesh.WriteTriangle(triangleIndex, triangles[3 * i], triangles[3 * i + 1], triangles[3 * i + 2]);
                    triangleIndex++;
                }
                int     quadsCount = geometry.GetQuadsCount();
                short[] quads      = geometry.GetQuads();
                for (int i = 0; i < quadsCount; i++)
                {
                    mesh.WriteQuad(triangleIndex, quads[3 * i], quads[3 * i + 1], quads[3 * i + 2], quads[3 * i + 3]);
                    triangleIndex += 2;
                }
            }

            return(position);
        }
        public void ReadPolygonsNet(CurvedPolygonsNet net)
        {
            //Debug.Log("this.precision "+this.compressionMask);
            net.SetVertices(CPVertexArrayData.GetCompressedVertexArray(vertices, GetVertexCompressionMode()));

            net.SetUv(CPUVArrayData.getCompressedUVArray(uvs, GetUVCompressionMode()));

            net.SetNormals(CPVectorArrayData.getCompressedVectorArray(normals, GetVectorCompressionMode()));
            //net.setTangents(CPVectorArrayData.getCompressedVectorArray(vertices, getVectorCompressionMode()));
            short[] edges      = CPShortArrayData.GetCompressedShortsArray(this.edges);
            short[] edgesIndex = CPShortArrayData.GetCompressedShortsArray(this.edgesIndex);
            int     edgesSize  = edgesIndex.Length - 1;

            net.SetNumberOfVertices(numberOfVertices);
            net.SetEdges(edgesIndex.Length - 1, edges, edgesIndex,
                         CPShortArrayData.GetCompressedShortsArray(edgeHints),
                         CPFloatArrayData.getCompressedFloatsArray(edgeWeights, FLOAT_PRECISION));
            CPNGeometry[] geometries = new CPNGeometry[this.geometries.Length];
            for (int i = 0; i < geometries.Length; i++)
            {
                geometries[i] = new CPNGeometry();
                short[] polygonsIndex   = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygonsIndex);
                short[] polygons        = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygons);
                short[] polygonsSchemas = null;
                if (this.geometries[i].polygonsSchema != null && this.geometries[i].polygonsSchema.Length != 0)
                {
                    polygonsSchemas = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygonsSchema);
                }
                else
                {
                    polygonsSchemas = new short[polygonsIndex.Length - 1];
                }
                int polygonsCount = polygonsIndex.Length - 1;
                geometries[i].Setup((short)polygonsCount, polygonsIndex, polygons, polygonsSchemas);
            }
            net.SetGeometries(geometries.Length, geometries);
        }
Пример #3
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);
        }