Exemple #1
0
    void _CreatePatchRecurse(Shape inputShape, ref int targetVerticesCount, ref int nTrianglesInThisPatch, int triangleIdx, bool[] triangleUsed, TriangleAdjacency_[] triAdjacency,
                             ref Patch_ curPatch, int srcTriangleIdx, ref uint dstTriangleIdx)
    {
        if (nTrianglesInThisPatch == 0)
        {
            return;
        }

        triangleUsed[triangleIdx] = true;

        int tri0 = inputShape.indices_[triangleIdx * 3 + 0];
        int tri1 = inputShape.indices_[triangleIdx * 3 + 1];
        int tri2 = inputShape.indices_[triangleIdx * 3 + 2];

        vertices_[targetVerticesCount + 0] = inputShape.vertices_[tri0];
        normals_[targetVerticesCount + 0]  = inputShape.normals_[tri0];
        uvs_[targetVerticesCount + 0]      = inputShape.uvs_[tri0];


        vertices_[targetVerticesCount + 1] = inputShape.vertices_[tri1];
        normals_[targetVerticesCount + 1]  = inputShape.normals_[tri1];
        uvs_[targetVerticesCount + 1]      = inputShape.uvs_[tri1];


        vertices_[targetVerticesCount + 2] = inputShape.vertices_[tri2];
        normals_[targetVerticesCount + 2]  = inputShape.normals_[tri2];
        uvs_[targetVerticesCount + 2]      = inputShape.uvs_[tri2];

        targetVerticesCount += 3;
        curPatch.nVertices_ += 3;
        ++dstTriangleIdx;

        // pick random edges
        //
        int randEdge0_0 = Random.Range(0, 2);
        int randEdge0_1 = wrap_inc(randEdge0_0, 0, 2);

        int randEdge1_0 = Random.Range(0, 2);

        if (randEdge1_0 == randEdge0_0)
        {
            randEdge1_0 = wrap_inc(randEdge1_0, 0, 2);
        }

        int randEdge1_1 = wrap_inc(randEdge1_0, 0, 2);

        int randEdge2_0 = 0;

        while (randEdge2_0 == randEdge0_0 || randEdge2_0 == randEdge1_0)
        {
            randEdge2_0++;
        }

        int randEdge2_1 = wrap_inc(randEdge2_0, 0, 2);

        int numRolledEdges = 3;

        //there's a 10% chance that there will be 2 edges
        //if (Random.Range(1, 10) == 1)
        //    numRolledEdges = 2;

        for (int iedge = 0; iedge < numRolledEdges; iedge++)
        {
            if (nTrianglesInThisPatch > 0)
            {
                int tmpEdge_0 = randEdge0_0;
                int tmpEdge_1 = randEdge0_1;
                if (iedge == 1)
                {
                    tmpEdge_0 = randEdge1_0;
                    tmpEdge_1 = randEdge1_1;
                }
                else if (iedge == 2)
                {
                    tmpEdge_0 = randEdge2_0;
                    tmpEdge_1 = randEdge2_1;
                }

                int randEdge_0 = inputShape.indices_[triangleIdx * 3 + tmpEdge_0];
                int randEdge_1 = inputShape.indices_[triangleIdx * 3 + tmpEdge_1];

                //PICO_ASSERT( randEdge_0 != randEdge_1 );

                // triangles adjacent to first vertex
                //
                TriangleAdjacency_ ta      = triAdjacency[randEdge_0];
                bool secondVertexTraversed = false;
                while (ta != null)
                {
                    uint iinner = ta.triangleIndex_;

                    if (!triangleUsed[iinner])
                    {
                        //int idx0 = inputShape.indices_[iinner * 3 + 0];
                        //int idx1 = inputShape.indices_[iinner * 3 + 1];
                        //int idx2 = inputShape.indices_[iinner * 3 + 2];

                        //if (((randEdge_0 == idx0) || (randEdge_0 == idx1) || (randEdge_0 == idx2))
                        //    && ((randEdge_1 == idx0) || (randEdge_1 == idx1) || (randEdge_1 == idx2))
                        //    )
                        {
                            triangleIdx            = (int)iinner;
                            nTrianglesInThisPatch -= 1;
                            if (nTrianglesInThisPatch > 0)
                            {
                                _CreatePatchRecurse(inputShape, ref targetVerticesCount, ref nTrianglesInThisPatch, triangleIdx, triangleUsed, triAdjacency, ref curPatch, srcTriangleIdx, ref dstTriangleIdx);
                                //    break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (ta.nextTriangle_ != -1)
                    {
                        ta = triAdjacency[ta.nextTriangle_];
                    }
                    else
                    {
                        if (secondVertexTraversed)
                        {
                            ta = null;
                        }
                        else
                        {
                            ta = triAdjacency[randEdge_1];
                            secondVertexTraversed = true;
                        }
                    }
                }
            }
            else
            {
                break;
            }
        }
    }