コード例 #1
0
ファイル: PVSManager.cs プロジェクト: billwillman/PVS
        public bool CompareVisibleBits(PVSCell other)
        {
            if (other == null)
            {
                return(false);
            }
            if (visibleBits == null)
            {
                return(false);
            }
            if (visibleBits.Length != other.visibleBits.Length)
            {
                return(false);
            }
            for (int i = 0; i < visibleBits.Length; ++i)
            {
                var b1 = visibleBits[i];
                var b2 = other.visibleBits[i];
                if (b1 != b2)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: PVSManager.cs プロジェクト: billwillman/PVS
        public void UpdateViewer(IPVSViewer viewer, Action <PVSCell> onViewObjChged)
        {
            if (viewer == null)
            {
                return;
            }
            Vector2 pos      = viewer.ViewPos;
            PVSCell currCell = viewer._CurrentCell;

            if (currCell != null)
            {
                if (currCell.Rectangle.Contains(pos))
                {
                    return;
                }
            }

            var results = SearchCell(pos);

            if (results != null && results.Count > 0)
            {
                var newCell = results[0];
                if (newCell != currCell)
                {
                    viewer._CurrentCell = newCell;
                    if (onViewObjChged != null)
                    {
                        onViewObjChged(newCell);
                    }
                }
            }
        }
コード例 #3
0
ファイル: PVSSceneBaker.cs プロジェクト: billwillman/PVS
        void InitCellResults()
        {
            if (m_CellArray == null || m_CellArray.Length <= 0 || m_BoundsArray == null || m_BoundsArray.Length <= 0)
            {
                return;
            }
            int cnt = Mathf.CeilToInt(m_GlobalNodeId / 8.0f);

            m_CellsResult = new PVSCell[m_CellArray.Length];
            for (int i = 0; i < m_CellsResult.Length; ++i)
            {
                var pt = m_CellArray[i];
                if (!m_CellIngoreArray.Contains(i) && pt.magnitude > Vector3.kEpsilon)
                {
                    PVSCell cell = new PVSCell();
                    m_CellsResult[i] = cell;
                    cell.visibleBits = new byte[cnt];
                    cell.position    = pt;
                }
                else
                {
                    m_CellsResult[i] = null;
                }
            }
        }
コード例 #4
0
ファイル: PVSCameraRtTrack.cs プロジェクト: billwillman/PVS
        private void DoStart(int cellIdx, Camera targetCamera, PVSCell cell, PVSItemIDS items, RenderTexture targetTexture)
        {
            // 1. 设置Camera的位置
            var camTrans = targetCamera.transform;

            camTrans.position = cell.position;
            // 2.设置RT
            // 3.渲染Items
            //int faceMask = 1 << (int)CubemapFace.PositiveZ;
            //targetCamera.RenderToCubemap(targetTexture, faceMask);
            targetCamera.Render();

            //SaveCellRtToFileName (cellIdx, targetTexture);
        }
コード例 #5
0
ファイル: PVSSceneBaker.cs プロジェクト: billwillman/PVS
        static PVSCell[] CombinePVSCells(int rowCnt, int colCnt, PVSCell[] cells, Rect allBounds)
        {
            PVSCell[] ret = null;

            QuadGroupTree <PVSCell> quadTree = new QuadGroupTree <PVSCell>(rowCnt, colCnt, cells);

            int oldCnt = quadTree.LeafCount;

            System.Func <PVSCell, PVSCell, PVSCell, PVSCell, bool> onCompare =
                (PVSCell c1, PVSCell c2, PVSCell c3, PVSCell c4) => {
                bool r1 = (c1.lod == c2.lod && c2.lod == c3.lod && c3.lod == c4.lod) &&
                          c1.CompareVisibleBits(c2) && c2.CompareVisibleBits(c3) && c3.CompareVisibleBits(c4);
                if (r1 && c1.lod >= 255)
                {
                    return(false);
                }
                return(r1);
            };

            System.Func <PVSCell, PVSCell, PVSCell, PVSCell, PVSCell> onCreate =
                (PVSCell c1, PVSCell c2, PVSCell c3, PVSCell c4) => {
                PVSCell r2     = new PVSCell();
                int     newLod = c1.lod + 1;
                r2.lod         = (byte)newLod;
                r2.position    = (c1.position + c2.position + c3.position + c4.position) / 4.0f;
                r2.visibleBits = c1.visibleBits;
                return(r2);
            };

            int inputCnt = quadTree.LeafCount;

            while (quadTree.Combine(onCompare, onCreate))
            {
            }

            List <PVSCell> cellList = quadTree.ToList();

            if (cellList != null && cellList.Count > 0)
            {
                ret = cellList.ToArray();
            }

            int resultCnt = quadTree.LeafCount;

            Debug.LogFormat("Input Cell Count: {0:D} result Cell Count: {1:D}", inputCnt, resultCnt);

            quadTree.Dispose();

            return(ret);
        }
コード例 #6
0
ファイル: PVSManager.cs プロジェクト: billwillman/PVS
        private static int OnPVSCellArraySort(PVSCell c1, PVSCell c2)
        {
            if (c1 == null && c2 == null)
            {
                return(0);
            }
            if (c1 == null)
            {
                return(1);
            }
            if (c2 == null)
            {
                return(-1);
            }
            int ret = c1.CheckCompare(c2);

            return(ret);
        }
コード例 #7
0
ファイル: PVSManager.cs プロジェクト: billwillman/PVS
        public int CheckCompare(PVSCell other)
        {
            if (other == null)
            {
                return(-1);
            }
            if (other.visibleBits == null && this.visibleBits == null)
            {
                return(0);
            }

            if (other.visibleBits == null)
            {
                return(-1);
            }
            if (this.visibleBits == null)
            {
                return(1);
            }

            int ret = visibleBits.Length - other.visibleBits.Length;

            if (ret != 0)
            {
                return(ret);
            }

            for (int i = 0; i < visibleBits.Length; ++i)
            {
                var b1 = visibleBits[i];
                var b2 = other.visibleBits[i];
                ret = b1 - b2;
                if (ret != 0)
                {
                    return(ret);
                }
            }

            return(ret);
        }
コード例 #8
0
ファイル: PVSManager.cs プロジェクト: billwillman/PVS
        public unsafe void LoadFromStream(Stream stream)
        {
            Clear(false);

            if (stream == null)
            {
                return;
            }

            PVSNodeHeader header;

            ReadFromStream(stream, out header);

            int bitLen = 0;

            if (m_InstanceIDToIDMap != null && m_InstanceIDToIDMap.Count > 0)
            {
                bitLen = Mathf.CeilToInt(((float)m_InstanceIDToIDMap.Count) / 8.0f);
            }

            // 1.读取visibleBitArray
            List <byte[]> visibleArrayList = null;

            if (header.saveMode == (byte)PVSSaveMode.bitsArrayMode)
            {
                if (m_InstanceIDToIDMap != null && m_InstanceIDToIDMap.Count > 0)
                {
                    visibleArrayList = new List <byte[]>(header.bitsArrayLength);
                    for (int i = 0; i < header.bitsArrayLength; ++i)
                    {
                        byte[] array = new byte[bitLen];
                        stream.Read(array, 0, bitLen);
                        visibleArrayList.Add(array);
                    }
                }
            }

            // 2.读取Cell
            if ((header.saveMode == (byte)PVSSaveMode.bitsCellMode) || (visibleArrayList != null && visibleArrayList.Count > 0))
            {
                Rect quadTreeRect = new Rect();
                quadTreeRect.size   = header.quadTreeSize;
                quadTreeRect.center = header.quadTreeCenter;
                if (m_CellTree == null)
                {
                    m_CellTree = new QuadTree <PVSCell>(quadTreeRect, PVSCell.CellSize * PVSCell.CellSize);
                }
                else
                {
                    m_CellTree.Init(quadTreeRect, PVSCell.CellSize * PVSCell.CellSize);
                }

                for (int i = 0; i < header.cellCount; ++i)
                {
                    var cell = new PVSCell();
                    cell.LoadFromStream(stream, visibleArrayList, (PVSSaveMode)header.saveMode, bitLen);
                    m_CellTree.Insert(cell);
                }

#if UNITY_EDITOR
                Debug.LogFormat("header Cell Count: {0:D}  Loaded Cell Count: {1:D}", header.cellCount, m_CellTree.Count);
#endif
            }
        }