Beispiel #1
0
            /// <summary>
            /// rTriIdx might be degraded rtri, but we can get the VFace to which it belongs anyway
            /// </summary>
            public VFace GetVFaceFromRTri(int rTriIdx, RaycastHit hit)
            {
                VFace vf = null;

                if (m_VFaceCont.TryGetValue(rTriIdx, out vf))
                {
                    return(vf);
                }
                else
                {
                    Dbg.Assert(m_DegRTriCont.Contains(rTriIdx), "VMesh.GetVFaceFromRTri: not in m_VFaceCont or degradedTriCont!?");

                    m_tmpVVLst.Clear();
                    GetVVertsFromRTri(rTriIdx, m_tmpVVLst);

                    float minDist = float.MaxValue;
                    VVert retVV   = null;
                    for (int i = 0; i < m_tmpVVLst.Count; ++i)
                    {
                        VVert vv   = m_tmpVVLst[i];
                        float dist = Vector3.Distance(hit.point, vv.GetWorldPos());
                        if (dist < minDist)
                        {
                            minDist = dist;
                            retVV   = vv;
                        }
                    }

                    Dbg.Assert(retVV != null, "VMesh.GetVFaceFromRTri: no VVert for given rtri!? {0}", rTriIdx);

                    VFLst vfLst = retVV.GetAllVFaces();
                    Dbg.Assert(vfLst.Count > 0, "VMesh.GetVFaceFromRTri: the vvert has no VFace, {0}", retVV);

                    return(vfLst[0]);
                }
            }