Ejemplo n.º 1
0
        /// <summary>
        ///  <para>获取otherVertsPloy相对于mainPoly的覆盖关系:(只在主多边形上找投影轴, 并且不考虑多边形中空的情况)</para>
        /// <para>[ FullOverlap ]: otherVertsPloy完全重叠到mainPloy</para>
        /// <para>[ PartOverlay ]:otherVertsPloy部分重叠mainPloy</para>
        /// <para>[ NotOverlay ]:两个多边形互不重叠</para>
        /// </summary>
        /// <param name="mainPoly"></param>
        /// <param name="otherVertsPloy"></param>
        /// <returns>
        /// FullOverlap: otherVertsPloy完全重叠到mainPloy
        /// PartOverlay:otherVertsPloy部分重叠mainPloy
        /// NotOverlay:两个多边形互不重叠
        /// </returns>
        public OverlapRelation GetOverlapRelation(Poly mainPoly, Vector3d[] otherVertsPloy)
        {
            double[]        range;
            PolySide[]      sides    = mainPoly.sidesList[0];
            OverlapRelation relation = OverlapRelation.FullOverlap;
            OverlapRelation tmpRelation;

            for (int i = 0; i < sides.Length; i++)
            {
                range       = ProjectPoly(sides[i].vertDir, otherVertsPloy);
                tmpRelation = _OverlapRelation(range[0], range[1], mainPoly.projRange[i].min, mainPoly.projRange[i].max);

                if (tmpRelation == OverlapRelation.PartOverlay)
                {
                    relation = OverlapRelation.PartOverlay;
                }
                else if (tmpRelation == OverlapRelation.FullOverlap &&
                         relation != OverlapRelation.PartOverlay)
                {
                    relation = OverlapRelation.FullOverlap;
                }
                else if (tmpRelation == OverlapRelation.NotOverlay)
                {
                    return(OverlapRelation.NotOverlay);
                }
            }

            return(relation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成指定地面网格单元格投影到TriFace上的体素Box
        /// </summary>
        /// <param name="cellx"></param>
        /// <param name="cellz"></param>
        void CreateFloorGridCellProjTriFaceVoxBox(int cellx, int cellz)
        {
            Vector3d[]      rect     = voxSpace.GetFloorGridCellRect(cellx, cellz);
            OverlapRelation relation = geoAlgo.GetOverlapRelation(polyProjectionFloor, rect);

            if (relation == OverlapRelation.NotOverlay)
            {
                return;
            }

            Vector3d[] projectionPts;

            if (relation == OverlapRelation.PartOverlay)
            {
                int count = geoAlgo.InRect2DCount(rect[0].x, rect[2].x, rect[0].z, rect[1].z, vertexsProjectionFloor, ref inRectIdx);
                if (count == vertexsProjectionFloor.Length)
                {
                    projectionPts = vertexs;
                }
                else
                {
                    edgePloyPts.Clear();

                    if (faceDirType != DirCmpInfo.Vertical)
                    {
                        for (int i = 0; i < rect.Length; i++)
                        {
                            if (geoAlgo.IsInsidePoly2D(polyProjectionFloor, rect[i]))
                            {
                                edgePloyPts.Add(rect[i]);
                            }
                        }
                    }

                    for (int i = 0; i < count; i++)
                    {
                        edgePloyPts.Add(vertexsProjectionFloor[inRectIdx[i]]);
                    }

                    for (int i = 0; i < preCellRectSides.Length; i++)
                    {
                        preCellRectSides[i].startpos = rect[i];
                    }

                    Vector3d[] pts = geoAlgo.SolvePolySidesCrossPoints2D(preCellRectSides, polyProjectionFloor.sidesList[0]);

                    for (int i = 0; i < pts.Length; i++)
                    {
                        edgePloyPts.Add(pts[i]);
                    }

                    projectionPts = CreateProjectionToTriFacePts(edgePloyPts.ToArray());
                }
            }
            else
            {
                projectionPts = CreateProjectionToTriFacePts(rect);
            }

            CreateVoxBoxToList(projectionPts, cellx, cellz);
        }