Example #1
0
        public void Execute()
        {
            CurvedPolygonsNet cpnet = asset.GetCPN();

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs);

            tessellationProcess.BuildProfile();

            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            uvs_      = new Vector2[builtVerticesCount];
            vertices_ = new Vector3[builtVerticesCount];
            normals_  = new Vector3[builtVerticesCount];
            indices_  = new int[builtTrianglesCount.Length][];
            for (int i = 0; i < builtTrianglesCount.Length; i++)
            {
                indices_[i] = new int[builtTrianglesCount[i] * 3];
            }

            OutputMesh mesh = null;

            mesh = new OutputMesh(vertices_, uvs_, normals_, indices_);
            tessellationProcess.WriteMesh(mesh);
        }
        public void EvaluatePolyline(CurvedPolygonsNet net, OutputMesh mesh, CPNGuide guide)
        {
            bool uvAvailable = net.GetUv() != null && net.GetUv().Length != 0 && mesh.DoUseUVs();
            int  countP      = mesh.CountProperties();

            //bool tgAvailable = net.GetTangents() != null && net.GetTangents().Length != 0;

            short[] tessellationDegrees = CPNGuide_loqs;

            guide.vBuffer = CreateBufferWithIndices(guide.vBuffer, net.GetVertices(), guide.GetIndices());
            guide.nBuffer = CreateBufferWithIndices(guide.vBuffer, net.GetNormals(), guide.GetIndices());
            if (uvAvailable)
            {
                guide.uvsBuffer = CreateBufferWithIndices(guide.uvsBuffer, net.GetUv(), guide.GetIndices());
            }
            if (countP > 0)
            {
                guide.PreparePropertiesBuffers(countP);
                for (int k = 0; k < countP; k++)
                {
                    guide.propertiesBuffer[k] = CreateBufferWithIndices(guide.propertiesBuffer[k],
                                                                        net.GetProperties3()[k], guide.GetIndices());
                }
            }
        }
        public void BuildModel(GameObject gameObject)
        {
            CurvedPolygonsNet cpnet = GetPolylinesCPNet(asset.GetCPN());

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs, this);

            //Debug.Log("cpnet.GetGeometriesCount() " + cpnet.GetGeometriesCount());

            tessellationProcess.BuildProfile();

            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            Vector2[] uvs_      = new Vector2[builtVerticesCount];
            Vector3[] vertices_ = new Vector3[builtVerticesCount];
            Vector3[] normals_  = new Vector3[builtVerticesCount];
            int[][]   indices_  = new int[builtTrianglesCount.Length][];
            //Debug.Log("indices_ " + indices_.Length);
            for (int i = 0; i < builtTrianglesCount.Length; i++)
            {
                indices_[i] = new int[builtTrianglesCount[i] * 3];
                //Debug.Log("indices_[" + i + "] " + indices_[i].Length);
            }

            OutputMesh mesh = null;

            mesh = new OutputMesh(vertices_, uvs_, normals_, indices_);
            tessellationProcess.WriteMesh(mesh);

            MeshAssigner.AssignMesh(gameObject, vertices_, normals_, uvs_, indices_);
        }
        public void WritePolygonsNet(CurvedPolygonsNet net)
        {
            //Debug.Log("On write this.compressionMask:" + this.compressionMask);
            if (compressionMask == 0)
            {
                compressionMask = DEFAULT_COMPRESSION_MASK;

                /*Debug.Log("Since it was 0 we set it to a new Value this.compressionMask:" + this.compressionMask);
                 * Debug.Log("Where Vertices Compression IS:" + GetVertexCompressionMode());
                 * Debug.Log("Where UV Compression IS:" + GetUVCompressionMode());*/
            }

            this.numberOfVertices = net.GetNumberOfVertices();
            this.vertices         = CPVertexArrayData.CompressVertexArray(net.GetVertices(), GetVertexCompressionMode());
            this.uvs = CPUVArrayData.compressUVArray(net.GetUv(), GetUVCompressionMode());
            //Debug.Log("On Write, UVs:" + ToString(net.GetUv()));
            this.normals    = CPVectorArrayData.compressVectorArray(net.GetNormals(), GetVectorCompressionMode());
            this.tangents   = new byte[0];
            this.edges      = CPShortArrayData.CompressShortsArray(net.GetEdges());
            this.edgesIndex = CPShortArrayData.CompressShortsArray(net.GetEdgesIndex());
            this.edgeHints  = CPShortArrayData.CompressShortsArray(net.GetEdgeHints());
            //this.edgeRots = CPFloatArrayData.compressFloatsArray(net.GetEdgesRots(), FLOAT_PRECISION);
            //this.edgeThickness = CPFloatArrayData.compressFloatsArray(net.GetEdgesThickness(), FLOAT_PRECISION);
            this.edgeWeights = CPFloatArrayData.compressFloatsArray(net.GetEdgeWeights(), FLOAT_PRECISION);
            this.geometries  = new CPGeometryAsset[net.GetGeometriesCount()];
            for (int i = 0; i < geometries.Length; i++)
            {
                geometries[i] = new CPGeometryAsset {
                    polygons       = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygons()),
                    polygonsIndex  = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygonsIndex()),
                    polygonsSchema = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygonsSchemas())
                };
            }
        }
Example #5
0
 public void InitPrebuiltProcess(CurvedPolygonsNet curvedPolygonsNet,
                                 TessellationOutput output, CPNSubset subSet, short[] loqs,
                                 InterpolationSchemaMap map = null)
 {
     this.tessellationOutput         = output;
     CPNGuideEvaluator.CPNGuide_loqs = loqs;
     this.curvedPolygonsNet          = curvedPolygonsNet;
     this.subSet = subSet;
     this.map    = map;
 }
Example #6
0
 public TessellationOutput InitProcess(CurvedPolygonsNet curvedPolygonsNet, short[] loqs,
                                       InterpolationSchemaMap map = null)
 {
     tessellationOutput = new TessellationOutput();
     CPNGuideEvaluator.CPNGuide_loqs = loqs;
     this.curvedPolygonsNet          = curvedPolygonsNet;
     this.subSet = null;
     this.map    = map;
     return(tessellationOutput);
 }
Example #7
0
        public void Execute()
        {
            CurvedPolygonsNet cpnet = asset.GetCPN();

            CurvedPolyVariants cpnVariants = new CurvedPolyVariants();

            cpnVariants.SetCPN(cpnet);

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs);

            //Debug.Log("cpnet.GetGeometriesCount() " + cpnet.GetGeometriesCount());

            tessellationProcess.BuildProfile();

            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            uvs_      = new Vector2[builtVerticesCount];
            vertices_ = new Vector3[builtVerticesCount];
            normals_  = new Vector3[builtVerticesCount];
            indices_  = new int[builtTrianglesCount.Length][];
            for (int i = 0; i < builtTrianglesCount.Length; i++)
            {
                indices_[i] = new int[builtTrianglesCount[i] * 3];
            }

            OutputMesh mesh = null;

            mesh = new OutputMesh(vertices_, uvs_, normals_, indices_);
            tessellationProcess.WriteMesh(mesh);

            //here
            int id = cpnVariants.GetFreeTessellationRecordId();

            cpnVariants.SetRecord(id, new OutputMesh(vertices_, uvs_, normals_, indices_), output);

            //this.outMesh = cpnVariants.GetMeshOutput(id).GetNewCloneVariant();

            CPNSubset subsSet = new CPNSubset();

            TessellationOutput output2 = tessellationProcess.InitProcess(cpnet, loqs, subsSet);

            this.mesh2 = new OutputMesh(outMesh.GetVertices(), outMesh.GetUVs(),
                                        outMesh.GetNormals(), outMesh.GetTriangles());
            tessellationProcess.WriteMesh(mesh2);
        }
        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);
        }
        public void Execute()
        {
            CurvedPolygonsNet cpnet = new CurvedPolygonsNet();

            cpnet.SetNumberOfVertices(9);

            Vector3[] vertices =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetVertices(vertices);
            Vector3[] uvs =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetUv(uvs);

            Vector3[] normals =
            {
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward
            };
            cpnet.SetNormals(normals);

            /*short[] edges = { 0, 3, 4, 1, 1, 5, 6, 2, 2, 7, 8, 0 };
             * short[] edgesIndex = { 0, 4, 8, 12 };
             * short[] edgesHints= { 3, 3, 3, 3, 3, 3 };
             * float[] weights = { 1, 1, 1, 1, 1, 1 };
             * bool[] updateVertices = new bool[vertices.Length];
             * bool[] updateEdges = new bool[3];*/

            cpnet.SetEdges(0, new short[0], new short[0], new short[0], new float[0]);

            short[] polylines      = { 0, 3, 4, 1, 1, 5, 6, 2, 2, 7, 8, 0 };
            short[] polylinesIndex = { 0, 4, 8, 12 };
            cpnet.setPolylines(3, polylines, polylinesIndex);

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNGeometry[] geometries      = { new CPNGeometry() };
            short[]       polygons        = { 1, 2, 3 };
            short[]       polygonsIndex   = { 0, 3 };
            short[]       polygonsSchemas = { SFGouraudSchemaBuilder.GOURAUD_SCHEMA_ID };
            geometries[0].Setup(1, polygonsIndex, polygons, polygonsSchemas);

            cpnet.SetGeometries(1, geometries);

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs);

            tessellationProcess.BuildProfile();


            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            uvs_      = new Vector2[builtVerticesCount];
            vertices_ = new Vector3[builtVerticesCount];
            normals_  = new Vector3[builtVerticesCount];
            indices_  = new int[builtTrianglesCount.Length][];
            for (int i = 0; i < builtTrianglesCount.Length; i++)
            {
                indices_[i] = new int[builtTrianglesCount[i] * 3];
            }

            OutputMesh mesh = null;

            mesh = new OutputMesh(vertices_, uvs_, normals_, indices_);
            tessellationProcess.WriteMesh(mesh);
        }
Example #10
0
        private void Execute()
        {
            CurvedPolygonsNet cpnet = new CurvedPolygonsNet();

            cpnet.SetNumberOfVertices(3);

            Vector3[] vertices =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetVertices(vertices);
            Vector3[] uvs =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetUv(uvs);

            Vector3[] normals =
            {
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward
            };
            cpnet.SetNormals(normals);

            short[] edges      = { 0, 3, 4, 1, 1, 5, 6, 2, 2, 7, 8, 0 };
            short[] edgesIndex = { 0, 4, 8, 12 };
            short[] edgesHints = { 3, 3, 3, 3, 3, 3 };
            float[] weights    = { 1, 1, 1, 1, 1, 1 };

            cpnet.SetEdges(3, edges, edgesIndex, edgesHints, weights);

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNGeometry[] geometries      = { new CPNGeometry() };
            short[]       polygons        = { 1, 2, 3 };
            short[]       polygonsIndex   = { 0, 3 };
            short[]       polygonsSchemas = { SFEdgeSurfaceSchemaBuilder.EDGE_SURFACE_SCHEMA_ID };
            geometries[0].Setup(1, polygonsIndex, polygons, polygonsSchemas);

            cpnet.SetGeometries(1, geometries);

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs);

            tessellationProcess.BuildProfile();

            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            this.mesh = new OutputMesh();
            this.mesh.SetupStructure(true, false, false, 0);
            this.mesh.Build(builtVerticesCount, builtTrianglesCount);
            tessellationProcess.WriteMesh(mesh);

            //Debug.Log("Tangents " + DemoUtils.Vector3sToString(mesh.GetTangents()));
        }
        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));
                }
            }
        }
Example #12
0
        private CurvedPolygonsNet GetPolylinesCPNet(CurvedPolygonsNet otherNet)
        {
            List <Vector3> vertices = new List <Vector3>();
            List <Vector3> normals  = new List <Vector3>();
            List <Vector3> uvs      = new List <Vector3>();

            int numberOfVertices = otherNet.GetNumberOfVertices();

            for (int i = 0; i < otherNet.GetNumberOfVertices(); i++)
            {
                vertices.Add(otherNet.GetVertices()[i]);
                normals.Add(otherNet.GetNormals()[i]);
                uvs.Add(otherNet.GetUv()[i]);
            }

            int numberOfEdges = otherNet.GetEdgesCount();

            short[] edges = otherNet.GetEdges();


            List <short> ps      = new List <short>();
            List <short> psIndex = new List <short>();

            psIndex.Add(0);

            for (int i = 0; i < numberOfEdges; i++)
            {
                int     ePos = otherNet.GetEdgePosition(i);
                Vector3 A    = otherNet.GetVertices()[edges[ePos]];
                Vector3 AB   = otherNet.GetVertices()[edges[ePos + 1]];
                Vector3 BA   = otherNet.GetVertices()[edges[ePos + 2]];
                Vector3 B    = otherNet.GetVertices()[edges[ePos + 3]];

                Vector3 Auv  = otherNet.GetUv()[edges[ePos]];
                Vector3 ABuv = otherNet.GetUv()[edges[ePos + 1]];
                Vector3 BAuv = otherNet.GetUv()[edges[ePos + 2]];
                Vector3 Buv  = otherNet.GetUv()[edges[ePos + 3]];

                Vector3 An  = otherNet.GetNormals()[edges[ePos]];
                Vector3 Bn  = otherNet.GetNormals()[edges[ePos + 3]];
                Vector3 ABn = otherNet.GetNormals()[numberOfVertices + i];

                vertices.Add(0.42f * A + 0.42f * AB + 0.144f * BA + 0.016f * B);
                vertices.Add(0.125f * B + 0.375f * BA + 0.375f * AB + 0.125f * A);
                vertices.Add(0.42f * B + 0.42f * BA + 0.144f * AB + 0.016f * A);

                uvs.Add(0.42f * Auv + 0.42f * ABuv + 0.144f * BAuv + 0.016f * Buv);
                uvs.Add(0.125f * Buv + 0.375f * BAuv + 0.375f * ABuv + 0.125f * Auv);
                uvs.Add(0.42f * Buv + 0.42f * BAuv + 0.144f * ABuv + 0.016f * Auv);

                normals.Add(0.56f * An + 0.376f * ABn + 0.062f * Bn);
                normals.Add(0.25f * An + 0.5f * ABn + 0.25f * Bn);
                normals.Add(0.56f * Bn + 0.376f * ABn + 0.062f * An);

                int id = numberOfVertices + 3 * i;
                ps.Add(edges[ePos]);
                ps.Add((short)id);
                ps.Add((short)(id + 1));
                ps.Add((short)(id + 2));
                ps.Add(edges[ePos + 3]);

                psIndex.Add((short)((i + 1) * 5));
            }


            CurvedPolygonsNet cPNet = new CurvedPolygonsNet();

            cPNet.SetNumberOfVertices(vertices.Count);
            cPNet.SetVertices(vertices.ToArray());
            cPNet.SetNormals(normals.ToArray());
            cPNet.SetUv(uvs.ToArray());
            cPNet.setPolylines(numberOfEdges, ps.ToArray(), psIndex.ToArray());
            cPNet.SetGeometries(otherNet.GetGeometriesCount(), otherNet.GetGeometries());

            return(cPNet);
        }
Example #13
0
        private void Execute()
        {
            CurvedPolygonsNet cpnet = new CurvedPolygonsNet();

            cpnet.SetNumberOfVertices(3);

            Vector3[] vertices =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetVertices(vertices);
            Vector3[] uvs =
            {
                new Vector3(0,                                             0, 0),
                new Vector3(1,                                             0, 0),
                new Vector3(0,                                             1, 0),
                new Vector3(DemoUtils.ONE_THIRD,                           0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD,                       0, 0),
                new Vector3(2 * DemoUtils.ONE_THIRD, DemoUtils.ONE_THIRD,     0),
                new Vector3(DemoUtils.ONE_THIRD,     2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       2 * DemoUtils.ONE_THIRD, 0),
                new Vector3(0,                       DemoUtils.ONE_THIRD,     0),
            };
            cpnet.SetUv(uvs);

            Vector3[] normals =
            {
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward,
                Vector3.forward
            };
            cpnet.SetNormals(normals);

            short[] edges      = { 0, 3, 4, 1, 1, 5, 6, 2, 2, 7, 8, 0 };
            short[] edgesIndex = { 0, 4, 8, 12 };
            short[] edgesHints = { 3, 3, 3, 3, 3, 3 };
            float[] weights    = { 1, 1, 1, 1, 1, 1 };

            cpnet.SetEdges(3, edges, edgesIndex, edgesHints, weights);

            short[] loqs = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

            CPNGeometry[] geometries      = { new CPNGeometry() };
            short[]       polygons        = { 1, 2, 3 };
            short[]       polygonsIndex   = { 0, 3 };
            short[]       polygonsSchemas = { SFEdgeSurfaceSchemaBuilder.EDGE_SURFACE_SCHEMA_ID };
            geometries[0].Setup(1, polygonsIndex, polygons, polygonsSchemas);

            cpnet.SetGeometries(1, geometries);

            CPNTessellationProcess tessellationProcess = ProcessesKeeper.GetTessellationProcess();

            TessellationOutput output = tessellationProcess.InitProcess(cpnet, loqs);

            tessellationProcess.BuildProfile();

            int[] builtTrianglesCount = output.GetBuiltTrianglesSize();
            int   builtVerticesCount  = output.GetBuiltVerticesSize();

            this.uvs_      = new Vector2[builtVerticesCount];
            this.vertices_ = new Vector3[builtVerticesCount];
            this.normals_  = new Vector3[builtVerticesCount];
            this.indices_  = new int[builtTrianglesCount.Length][];
            for (int i = 0; i < builtTrianglesCount.Length; i++)
            {
                this.indices_[i] = new int[builtTrianglesCount[i] * 3];
            }

            OutputMesh mesh = new OutputMesh(vertices_, uvs_, normals_, indices_);

            tessellationProcess.WriteMesh(mesh);
        }