示例#1
0
 public void LoadFromStream(Stream stream)
 {
     if (stream == null)
     {
         return;
     }
     PVSManager.GetInstance().Clear();
     LoadIDs();
     PVSManager.GetInstance().LoadFromStream(stream);
 }
示例#2
0
        // 当前Instance对象是否可见(InstanceID来自MeshRenderer)
        public bool IsInstanceIDVisible(int instanceID)
        {
            int id;

            if (!PVSManager.GetInstance().SearchID(instanceID, out id))
            {
                return(NoContainsVisible);
            }
            return(IsVisible(id));
        }
示例#3
0
 void LoadIDs()
 {
     if (m_IDs != null)
     {
         for (int i = 0; i < m_IDs.Count; ++i)
         {
             int       id     = i + 1;
             Transform target = m_IDs[i];
             if (target == null)
             {
                 continue;
             }
             PVSManager.GetInstance().RegisterID(id, target);
         }
     }
 }
示例#4
0
        internal unsafe void SaveToStream(Stream stream, PVSSaveMode saveMode)
        {
            if (stream == null)
            {
                return;
            }

            PVSManager.WriteStream(stream, this.position);
            PVSManager.WriteStream(stream, this.lod);
            if (saveMode == PVSSaveMode.bitsArrayMode)
            {
                PVSManager.WriteStream(stream, this.visibleBitsIdx);
            }
            else if (saveMode == PVSSaveMode.bitsCellMode)
            {
                stream.Write(this.visibleBits, 0, this.visibleBits.Length * Marshal.SizeOf(typeof(byte)));
            }
        }
示例#5
0
        internal unsafe void LoadFromStream(Stream stream, List <byte[]> byteArrayList, PVSSaveMode saveMode, int bitLen)
        {
            if (stream == null)
            {
                return;
            }

            // 读取位置
            PVSManager.ReadFromStream(stream, out this.position);
            // 读取LOD数据
            PVSManager.ReadFromStream(stream, out this.lod);
            // 可见bit位
            if (saveMode == PVSSaveMode.bitsArrayMode)
            {
                int idx;
                PVSManager.ReadFromStream(stream, out idx);
                this.visibleBits = byteArrayList[idx];
            }
            else if (saveMode == PVSSaveMode.bitsCellMode)
            {
                this.visibleBits = new byte[bitLen];
                stream.Read(this.visibleBits, 0, bitLen);
            }
        }
示例#6
0
        private void OnCpuThreadDone()
        {
            EditorUtility.ClearProgressBar();
            if (m_CellsResult != null)
            {
                string log = string.Empty;
                for (int i = 0; i < m_CellsResult.Length; ++i)
                {
                    var cell = m_CellsResult[i];
                    if (cell == null)
                    {
                        continue;
                    }
                    System.Text.StringBuilder builder = new System.Text.StringBuilder();
                    if (cell.visibleBits != null && cell.visibleBits.Length > 0)
                    {
                        for (int j = 0; j < cell.visibleBits.Length; ++j)
                        {
                            var b = cell.visibleBits[j];
                            if (builder.Length > 0)
                            {
                                builder.Append('|');
                            }
                            builder.Append(b);
                        }
                    }

                    if (builder.Length > 0)
                    {
                        builder.Insert(0, string.Format("Cell: {0:D}=>", i)).AppendLine();
                        log += builder.ToString();
                    }
                }

                System.IO.FileStream stream = new System.IO.FileStream("PVS_Result.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                try {
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(log);
                    if (buffer != null && buffer.Length > 0)
                    {
                        stream.Write(buffer, 0, buffer.Length);
                    }
                } finally {
                    stream.Dispose();
                }

                stream = new System.IO.FileStream("PVS.bytes", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                try {
                    int col = Mathf.CeilToInt(m_SearchBounds.size.x / PVSCell.CellSize);
                    int row = Mathf.CeilToInt(m_SearchBounds.size.z / PVSCell.CellSize);

                    DoCombineResults();

                    Vector2 sz     = new Vector2(col * PVSCell.CellSize, row * PVSCell.CellSize);
                    Vector2 center = new Vector2(m_SearchBounds.min.x + sz.x / 2.0f, m_SearchBounds.min.z + sz.y / 2.0f);

                    Rect quadTreeRect = new Rect();
                    quadTreeRect.size   = sz;
                    quadTreeRect.center = center;
                    PVSManager.SaveToStream(stream, m_CellsSave, quadTreeRect, m_SelSaveMode - 1);
                } finally {
                    stream.Dispose();
                }

                UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
            }
        }