Esempio n. 1
0
    }   //protected bool CTriContainer::constructAllTris_IVrecompute(

    //@ Construct all Triangle refer to Index Buffers, Vertex Buffers.
    protected bool constructAllTris_IV(int[] arrTri_in,
                                       Vector3[] arrVertex_in,
                                       ref List <CTRI> listTris_out)
    {
        Vector3[] arrv3TriVer = new Vector3[CTRI.CNTPNTTRI];

        int[] ariTriIdx = new int[CTRI.CNTPNTTRI];
        int   iCntVB    = arrVertex_in.Length;
        int   iCntIV    = arrTri_in.Length;

        if (iCntIV < 1 || iCntVB < 1)
        {
            Debug.Log("(iCntIV < 1 || iCntVB < 1)");
            return(false);
        }

        //int iCntTries = (iCntIV / CTRI.CNTPNTTRI) + 1;

        CTRI    triCurrent;
        Vector3 v3MinAABB = new Vector3(CMATH.FLOAT_MAX, CMATH.FLOAT_MAX, CMATH.FLOAT_MAX),
                v3MaxAABB = new Vector3(-CMATH.FLOAT_MAX, -CMATH.FLOAT_MAX, -CMATH.FLOAT_MAX);

        Vector3 v3VerTri;

        for (int iSeqIdx = 0, iTri = 0; iSeqIdx < iCntIV; iSeqIdx += 3, ++iTri)
        {
            ariTriIdx[0] = arrTri_in[iSeqIdx];
            ariTriIdx[1] = arrTri_in[iSeqIdx + 1];
            ariTriIdx[2] = arrTri_in[iSeqIdx + 2];

            for (int itV = 0; itV < 3; ++itV)
            {
                v3VerTri = new Vector3(arrVertex_in[ariTriIdx[itV]].x, arrVertex_in[ariTriIdx[itV]].y, arrVertex_in[ariTriIdx[itV]].z);

                if (v3VerTri.x > v3MaxAABB.x)
                {
                    v3MaxAABB.x = v3VerTri.x;
                }
                if (v3VerTri.y > v3MaxAABB.y)
                {
                    v3MaxAABB.y = v3VerTri.y;
                }
                if (v3VerTri.z > v3MaxAABB.z)
                {
                    v3MaxAABB.z = v3VerTri.z;
                }

                if (v3VerTri.x < v3MinAABB.x)
                {
                    v3MinAABB.x = v3VerTri.x;
                }
                if (v3VerTri.y < v3MinAABB.y)
                {
                    v3MinAABB.y = v3VerTri.y;
                }
                if (v3VerTri.z < v3MinAABB.z)
                {
                    v3MinAABB.z = v3VerTri.z;
                }

                arrv3TriVer[itV] = v3VerTri;
            }
            triCurrent = new CTRI();
            triCurrent.Set(arrv3TriVer, ariTriIdx);

            listTris_out.Add(triCurrent);
        }

        return(true);
    } //protected bool constructAllTris_IV(
Esempio n. 2
0
    //@ Function has little risk about triangle match.
    protected bool constructAllTris_IVrecompute(int[] arrTri_in,
                                                Vector3[] arrVertex_in,
                                                ref List <CTRI> listTris_out)
    {
        Vector3[] arrv3TriVer = new Vector3[CTRI.CNTPNTTRI];
        int[]     ariTriIdx   = new int[CTRI.CNTPNTTRI];
        int       iCntVB      = arrVertex_in.Length;
        int       iCntIV      = arrTri_in.Length;

        //CHECKOVERLAPPED
        int iCntSameVer__ = 0;

        if (iCntIV < 1 || iCntVB < 1)
        {
            return(false);
        }

        int[] arrIBConvert = new int[iCntIV];

        int  iIVConvert = 0, iIVCurr = 0;
        bool bfindEQ = false;

        for (int iterIV = 0; iterIV < iCntIV; ++iterIV)
        {
            arrIBConvert[iterIV] = arrTri_in[iterIV];
        }

        for (int iterIV = 0; iterIV < iCntVB; ++iterIV)
        {
            Vector3 v3VBCurr = arrVertex_in[iterIV];
            iIVCurr = iterIV; bfindEQ = false;
            for (int iIVin = 0; iIVin < iIVCurr; ++iIVin)
            {
                Vector3 v3VBCurr_ = arrVertex_in[iIVin];

                //bfindEQ = CMATH.similarVector3_FIn(v3VBCurr, v3VBCurr_, 0.4f);
                bfindEQ = (v3VBCurr == v3VBCurr_);

                if (bfindEQ)
                {
                    //FORTEST
                    iCntSameVer__++;

                    iIVConvert = iIVin;
                    break;
                }
            } // for(int iIVin=0; iIVin<iterIV; ++IV_)

            if (true == bfindEQ)
            {
                for (int iSeqIV = 0; iSeqIV < iCntIV; ++iSeqIV)
                {
                    int iIBCurr = (int)arrTri_in[iSeqIV];
                    if (iIBCurr == iterIV)
                    {
                        arrIBConvert[iSeqIV] = iIVConvert;
                    }
                }
            }
        } // for(int iterIV=0; iterIV<arrVertex_in.size(); ++iterIV)

        //@ Overlap vertex
        if (0 < iCntSameVer__)
        {
            Debug.Log("Notice! (overlapped:" + iCntSameVer__ + " vertices.) Count of exactly same position vertices//constructAllTris_IVrecompute()//arrTri_in.Length=" + arrTri_in.Length);
        }

        //@Insert only validation succeeded triangle.
        CTRI    triCurrent;
        int     iSeqTriCurr = 0, iSeqTri_ = 0;
        Vector3 v3MinAABB = new Vector3(CMATH.FLOAT_MAX, CMATH.FLOAT_MAX, CMATH.FLOAT_MAX),
                v3MaxAABB = new Vector3(-CMATH.FLOAT_MAX, -CMATH.FLOAT_MAX, -CMATH.FLOAT_MAX);

        Vector3 v3VerTri;

        //@ overlap triangles
        int         iCntExactlySameTris = 0, iCntNotValidatePoly = 0;
        List <CTRI> listTriOverlap = new List <CTRI>();

        for (int iSeqIdx = 0, iTri = 0; iSeqIdx < iCntIV; iSeqIdx += 3, ++iTri)
        {
            ariTriIdx[0] = arrIBConvert[iSeqIdx];
            ariTriIdx[1] = arrIBConvert[iSeqIdx + 1];
            ariTriIdx[2] = arrIBConvert[iSeqIdx + 2];

            for (int itV = 0; itV < 3; ++itV)
            {
                v3VerTri = new Vector3(arrVertex_in[ariTriIdx[itV]].x, arrVertex_in[ariTriIdx[itV]].y, arrVertex_in[ariTriIdx[itV]].z);

                if (v3VerTri.x > v3MaxAABB.x)
                {
                    v3MaxAABB.x = v3VerTri.x;
                }
                if (v3VerTri.y > v3MaxAABB.y)
                {
                    v3MaxAABB.y = v3VerTri.y;
                }
                if (v3VerTri.z > v3MaxAABB.z)
                {
                    v3MaxAABB.z = v3VerTri.z;
                }

                if (v3VerTri.x < v3MinAABB.x)
                {
                    v3MinAABB.x = v3VerTri.x;
                }
                if (v3VerTri.y < v3MinAABB.y)
                {
                    v3MinAABB.y = v3VerTri.y;
                }
                if (v3VerTri.z < v3MinAABB.z)
                {
                    v3MinAABB.z = v3VerTri.z;
                }

                arrv3TriVer[itV] = v3VerTri;
            }

            triCurrent = new CTRI();
            triCurrent.Set(arrv3TriVer, ariTriIdx);

            if (true == triCurrent.isValidateASPoly())
            {
                bool bBeExistExactlysame = false;

                for (int iSeqIdx__ = 0; iSeqIdx__ < iSeqTriCurr; ++iSeqIdx__)
                {
                    if (iSeqIdx__ != iSeqIdx)
                    {
                        CTRI tri__ = listTris_out[iSeqIdx__];
                        if (tri__.isEqual(triCurrent))
                        {
                            //FORTEST
                            ++iCntExactlySameTris;

                            listTriOverlap.Add(triCurrent);
                            //FORTEST

                            bBeExistExactlysame = true;
                            break;
                        }
                    }
                } // for (int iSeqIdx__ = 0; iSeqIdx__ < iSeqTriCurr; ++iSeqIdx__)

                if (false == bBeExistExactlysame)
                {
                    iSeqTriCurr = iSeqTri_++;

                    listTris_out.Add(triCurrent);
                }
                else
                {
                    Debug.Log("!ERROR. Overlapped Triangle. Exist Exactly same TRI");
                }
            } // if(true==triCurrent.isValidateASPoly())
            else
            { // //CHECKOVERLAPPED
                ++iCntNotValidatePoly;
            } // if(true==triCurrent.isValidateASPoly())
        }     // for( uint iSeqIdx=0, iTri=0; iSeqIdx<iCntIV; iSeqIdx+=3,++iTri )

        //CHECKOVERLAPPED
        //@ maya에서 같은 위치에 Overlap된 polygon 작업이 있는 지 여부 검사.
        if (listTriOverlap.Count > 0)
        {
            int iSeq = 0;
            foreach (CTRI triOverlap in listTriOverlap)
            {
                m_drawRenderMesh_forcheckoverlap.DrawNewRendermesh(CMATH.INT_MAX_DIV248 + (iSeq++), triOverlap._arrv3PT, color_overllaped_triangle, CMATH.FEPSILON_F2, -1.0f);
            }

            string strDebugOut = "!ERROR triangles overlapped. //count=" + listTriOverlap.Count + "\n";
            strDebugOut += "!constructAllTris_IVrecompute:CountTris=" + listTris_out.Count + "//" +
                           "ExactlySameTris=" + iCntExactlySameTris + "//" + "NoValidateTris=" + iCntNotValidatePoly + "//" + UnityEngine.Random.Range(10.0f, 10000.0f);

            Debug.Log(strDebugOut);
        } // if(listTriOverlap.Count > 0)
          //CHECKOVERLAPPED

        return(true);
    }   //protected bool CTriContainer::constructAllTris_IVrecompute(