Ejemplo n.º 1
0
        static bool CompareSubGroups(ref SSubGroup pg1, ref SSubGroup pg2)
        {
            bool bStillSame = true;
            int  i          = 0;

            if (pg1.iNrFaces != pg2.iNrFaces)
            {
                return(false);
            }
            while (i < pg1.iNrFaces && bStillSame)
            {
                bStillSame = pg1.triMembers[i] == pg2.triMembers[i];
                if (bStillSame)
                {
                    ++i;
                }
            }
            return(bStillSame);
        }
Ejemplo n.º 2
0
        static bool GenerateTSpaces(ref STSpace[] psTspace, ref STriInfo[] pTriInfos, SGroup[] pGroups, int iNrActiveGroups, int[] piTriListIn, int[] pGroupTriangleBuffer, float fThresCos, ref SMikkTSpaceContext context)
        {
            STSpace[]   pSubGroupTSpace = null;
            SSubGroup[] pUniSubGroups = null;
            int[]       pTmpMembers = null;
            int         iMaxNrFaces = 0, iUniqueTSpaces = 0, g = 0, i = 0;

            for (g = 0; g < iNrActiveGroups; ++g)
            {
                if (iMaxNrFaces < pGroups[g].iNrFaces)
                {
                    iMaxNrFaces = pGroups[g].iNrFaces;
                }
            }

            if (iMaxNrFaces == 0)
            {
                return(true);
            }

            pSubGroupTSpace = new STSpace[iMaxNrFaces];
            pUniSubGroups   = new SSubGroup[iMaxNrFaces];
            pTmpMembers     = new int[iMaxNrFaces];

            iUniqueTSpaces = 0;
            for (g = 0; g < iNrActiveGroups; ++g)
            {
                int iUniqueSubGroups = 0;

                for (i = 0; i < pGroups[g].iNrFaces; ++i)
                {
                    int       f = pGroupTriangleBuffer[pGroups[g].faceOffset];
                    int       index = -1, iVertIndex = -1, iOF_1 = -1, iMembers = 0, j = 0, l = 0;
                    SSubGroup tmp_group;
                    bool      bFound = false;
                    Vector3   n = Vector3.Zero, vOs = Vector3.Zero, vOt = Vector3.Zero;
                    if (pTriInfos[f].AssignedGroup[0] == pGroups[g])
                    {
                        index = 0;
                    }
                    else if (pTriInfos[f].AssignedGroup[1] == pGroups[g])
                    {
                        index = 1;
                    }
                    else if (pTriInfos[f].AssignedGroup[2] == pGroups[g])
                    {
                        index = 2;
                    }

                    iVertIndex = piTriListIn[f * 3 + index];

                    n = GetNormal(ref context, iVertIndex);

                    vOs = pTriInfos[f].vOs - (Vector3.Dot(n, pTriInfos[f].vOs) * n);
                    vOt = pTriInfos[f].vOt - (Vector3.Dot(n, pTriInfos[f].vOt) * n);
                    if (VNotZero(ref vOs))
                    {
                        vOs.Normalize();
                    }
                    if (VNotZero(ref vOt))
                    {
                        vOt.Normalize();
                    }

                    iOF_1 = pTriInfos[f].iOrgFaceNumber;

                    iMembers = 0;
                    for (j = 0; j < pGroups[g].iNrFaces; ++j)
                    {
                        int t     = pGroupTriangleBuffer[pGroups[g].faceOffset + j];
                        int iOf_2 = pTriInfos[t].iOrgFaceNumber;

                        Vector3 vOs2 = (pTriInfos[t].vOs - (Vector3.Dot(n, pTriInfos[t].vOs) * n));
                        Vector3 vOt2 = (pTriInfos[t].vOt - (Vector3.Dot(n, pTriInfos[t].vOt) * n));

                        if (VNotZero(ref vOs2))
                        {
                            vOs2.Normalize();
                        }
                        if (VNotZero(ref vOt2))
                        {
                            vOt2.Normalize();
                        }

                        {
                            bool bAny         = ((pTriInfos[f].iFlag | pTriInfos[t].iFlag) & GROUP_WITH_ANY) != 0;
                            bool bSameOrgFace = iOF_1 == iOf_2;

                            float fCosS = Vector3.Dot(vOs, vOs2);
                            float fCosT = Vector3.Dot(vOt, vOt2);

                            if (bAny || bSameOrgFace || (fCosS > fThresCos && fCosT > fThresCos))
                            {
                                pTmpMembers[iMembers++] = t;
                            }
                        }
                    }

                    tmp_group.iNrFaces   = iMembers;
                    tmp_group.triMembers = new List <int>(pTmpMembers);
                    if (iMembers > 1)
                    {
                        tmp_group.triMembers.Sort();
                    }

                    bFound = false;
                    l      = 0;
                    while (l < iUniqueSubGroups && !bFound)
                    {
                        bFound = CompareSubGroups(ref tmp_group, ref pUniSubGroups[l]);
                        if (!bFound)
                        {
                            ++l;
                        }
                    }

                    if (!bFound)
                    {
                        pUniSubGroups[iUniqueSubGroups].iNrFaces   = iMembers;
                        pUniSubGroups[iUniqueSubGroups].triMembers = new List <int>(tmp_group.triMembers);
                        pSubGroupTSpace[iUniqueSubGroups]          = EvalTspace(tmp_group.triMembers, iMembers, piTriListIn, ref pTriInfos, ref context, pGroups[g].iVertex);
                        iUniqueSubGroups++;
                    }


                    {
                        int iOffs = pTriInfos[f].iTSpacesOffs;
                        int iVert = pTriInfos[f].vert_num[index];
                        if (psTspace[iOffs + iVert].iCounter == 1)
                        {
                            psTspace[iOffs + iVert]          = AvgTSpace(ref psTspace[iOffs + iVert], ref pSubGroupTSpace[l]);
                            psTspace[iOffs + iVert].iCounter = 2;
                            psTspace[iOffs + iVert].bOrient  = pGroups[g].bOrientPreservering;
                        }
                        else
                        {
                            psTspace[iOffs + iVert]          = pSubGroupTSpace[l];
                            psTspace[iOffs + iVert].iCounter = 1;
                            psTspace[iOffs + iVert].bOrient  = pGroups[g].bOrientPreservering;
                        }
                    }
                }

                iUniqueTSpaces += iUniqueSubGroups;
            }

            return(true);
        }