private List <Bounds> MergeSameCenterBounds(List <Bounds> boundsList) { var re = new List <Bounds>(); boundsList.Sort(new BoundsComparer()); bool isFirst = true; //第一个是初始bounds不要生成接触点 var bounds = new Bounds(new Vector3(-oo, -oo, -oo), new Vector3(0, 0, 0)); int cnt = 0; //接触点数量 foreach (var item in boundsList) { //Debug.Log("center:"+item.center.x+ ","+item.center.y + "," + item.center.z); var tmp = item.center - bounds.center; if (Dcmp(tmp.x) == 0 && Dcmp(tmp.y) == 0 && Dcmp(tmp.z) == 0) { bounds.extents = ObjManager.GetMaxVector3(bounds.extents, item.extents); } else { if (!isFirst) { re.Add(bounds); cnt++; } isFirst = false; bounds = item; } } if (!isFirst) { re.Add(bounds); cnt++; } return(re); }
private bool DealBoundsIntersection(Bounds a, Bounds b, bool ifCreateXjBounds, List <Bounds> xjBoundsList)//是否创建对应相交长方体 { var minP = ObjManager.GetMaxVector3(a.min, b.min); var maxP = ObjManager.GetMinVector3(a.max, b.max); if (!Vector3xydy(minP, maxP)) { return(false); } if (ifCreateXjBounds) { xjBoundsList.Add(new Bounds((minP + maxP) / 2, maxP - minP));//往xjBoundsList添加一个相交长方体 } return(true); }