internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
            {
                Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
                Debug.Assert(lod >= 0, "Lod level must be non-negative");
                Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
                m_parentClipmap = parentClipmap;
                m_lod = lod;
                m_lodDivisions = lodDivisions;

                if (m_lodDivisions <= 0)
                    return;

                m_dirtyProxyIndices = new HashSet<int>();
                m_cellProxyToAabbProxy = new Dictionary<MyClipmapCellProxy, int>();
                m_boundingBoxes = new MyDynamicAABBTreeD(Vector3D.Zero);

                int cellCount = lodDivisions*lodDivisions*lodDivisions;
                m_mergeJobs = new MergeJobInfo[cellCount];
                m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
                m_trackedActors = new HashSet<MyActor>[cellCount];

                for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
                {
                    m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
                    m_mergeJobs[divideIndex] = new MergeJobInfo { CurrentWorkId = 0, LodMeshesBeingMerged = new List<LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter };
                    m_trackedActors[divideIndex] = new HashSet<MyActor>();
                    m_dirtyProxyIndices.Add(divideIndex);
                }
            }
Ejemplo n.º 2
0
            internal MyLodMeshMerge(MyClipmap parentClipmap, int lod, int lodDivisions, ref MatrixD worldMatrix, ref Vector3D massiveCenter, float massiveRadius, RenderFlags renderFlags)
            {
                Debug.Assert(parentClipmap != null, "Parent clipmap cannot be null");
                Debug.Assert(lod >= 0, "Lod level must be non-negative");
                Debug.Assert(lodDivisions >= 0, "Invalid number of lod divisions");
                m_parentClipmap = parentClipmap;
                m_lod           = lod;
                m_lodDivisions  = lodDivisions;

                if (!IsUsed())
                {
                    return;
                }

                m_dirtyProxyIndices    = new HashSet <int>();
                m_cellProxyToAabbProxy = new Dictionary <MyClipmapCellProxy, int>();
                m_boundingBoxes        = new MyDynamicAABBTreeD(Vector3D.Zero);

                int cellCount = lodDivisions * lodDivisions * lodDivisions;

                m_mergeJobs            = new MergeJobInfo[cellCount];
                m_mergedLodMeshProxies = new MyClipmapCellProxy[cellCount];
                m_trackedActors        = new HashSet <MyActor> [cellCount];

                for (int divideIndex = 0; divideIndex < cellCount; ++divideIndex)
                {
                    m_mergedLodMeshProxies[divideIndex] = new MyClipmapCellProxy(new MyCellCoord(Lod, GetCellFromDivideIndex(divideIndex)), ref worldMatrix, massiveCenter, massiveRadius, renderFlags, true);
                    m_mergeJobs[divideIndex]            = new MergeJobInfo {
                        CurrentWorkId = 0, LodMeshesBeingMerged = new List <LodMeshId>(), NextPossibleMergeStartTime = MyCommon.FrameCounter
                    };
                    m_trackedActors[divideIndex] = new HashSet <MyActor>();
                    m_dirtyProxyIndices.Add(divideIndex);
                }
            }
Ejemplo n.º 3
0
 public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref MatrixD worldMatrix)
 {
     var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix, m_massiveCenter, m_massiveRadius, m_renderFlags);
     cell.SetVisibility(false);
     cell.ScaleGroup = scaleGroup;
     return cell;
 }
Ejemplo n.º 4
0
        public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix)
        {
            var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix);

            cell.SetVisibility(false);
            cell.ScaleGroup = scaleGroup;
            return(cell);
        }
Ejemplo n.º 5
0
        public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref MatrixD worldMatrix)
        {
            var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix, m_massiveCenter, m_massiveRadius, m_renderFlags);

            cell.SetVisibility(false);
            cell.ScaleGroup = scaleGroup;
            return(cell);
        }
Ejemplo n.º 6
0
            internal bool OnAddedToScene(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                {
                    return(false);
                }

                bool         lodAabbChanged = false;
                int          rootProxy      = m_boundingBoxes.GetRoot();
                BoundingBoxD lodAabbBefore  = BoundingBoxD.CreateInvalid();

                if (rootProxy != -1)
                {
                    lodAabbBefore = m_boundingBoxes.GetAabb(rootProxy);
                }

                BoundingBoxD cellAabb = (BoundingBoxD)cellProxy.LocalAabb;

                m_cellProxyToAabbProxy.Add(cellProxy, m_boundingBoxes.AddProxy(ref cellAabb, null, 0));

                if (rootProxy != -1)
                {
                    BoundingBoxD lodAabbAfter = m_boundingBoxes.GetAabb(rootProxy);
                    lodAabbChanged = lodAabbBefore.Equals(lodAabbAfter);
                }

                if (lodAabbChanged)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                Vector3D translation = cellProxy.Translation;
                int      divideIndex = GetDivideIndex(ref translation);

                m_trackedActors[divideIndex].Add(cellProxy.Actor);

                MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                LodMeshId         lodMeshToMerge  = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);
                bool mergedMesh = mergedLodMeshId.MergeLodMesh(lodMeshToMerge);

                if (mergedMesh)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                TryCancelMergeJob(divideIndex, MeshId.NULL);
                bool startedMerge = TryStartMergeJob(divideIndex, 1000);

                bool shouldMarkDirty = !mergedMesh && !startedMerge;

                if (shouldMarkDirty)
                {
                    m_dirtyProxyIndices.Add(divideIndex);
                }

                return(shouldMarkDirty);
            }
Ejemplo n.º 7
0
        internal void OnRemovedFromScene(MyClipmapCellProxy cellProxy)
        {
            if (!MyRenderProxy.Settings.EnableVoxelMerging)
            {
                return;
            }

            if (m_mergesPerLod[cellProxy.Lod].OnRemovedFromScene(cellProxy))
            {
                m_dirtyLodMergeIndices.Add(cellProxy.Lod);
            }
        }
Ejemplo n.º 8
0
        internal bool OnDeleteCell(MyClipmapCellProxy cellProxy)
        {
            if (!MyRenderProxy.Settings.EnableVoxelMerging)
            {
                return(false);
            }

            bool cellDeleted = m_mergesPerLod[cellProxy.Lod].OnDeleteCell(cellProxy);

            if (cellDeleted)
            {
                m_dirtyLodMergeIndices.Add(cellProxy.Lod);
            }

            return(cellDeleted);
        }
Ejemplo n.º 9
0
            internal bool OnDeleteCell(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                {
                    return(false);
                }

                bool     unloadedCell = false;
                Vector3D translation  = cellProxy.Translation;
                int      divideIndex;

                if (TryGetDivideIndex(ref translation, out divideIndex))
                {
                    MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                    LodMeshId         lodMeshId       = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);

                    bool unmergedMesh = mergedLodMeshId.UnmergeLodMesh(lodMeshId);
                    if (unmergedMesh)
                    {
                        InvalidateAllMergedMeshesInLod();
                    }

                    TryCancelMergeJob(divideIndex, cellProxy.MeshId);

                    cellProxy.Unload();
                    unloadedCell = true;

                    TryStartMergeJob(divideIndex, 1000);

                    if (unmergedMesh && unloadedCell)
                    {
                        m_dirtyProxyIndices.Add(divideIndex);
                    }

                    m_trackedActors[divideIndex].Remove(cellProxy.Actor);
                }

                int proxyId;

                if (m_cellProxyToAabbProxy.TryGetValue(cellProxy, out proxyId))
                {
                    m_boundingBoxes.RemoveProxy(m_cellProxyToAabbProxy[cellProxy]);
                    m_cellProxyToAabbProxy.Remove(cellProxy);
                }

                return(unloadedCell);
            }
        internal bool OnDeleteCell(MyClipmapCellProxy cellProxy)
        {
            if (!MyRenderProxy.Settings.EnableVoxelMerging)
                return false;

            bool cellDeleted = m_mergesPerLod[cellProxy.Lod].OnDeleteCell(cellProxy);
            if(cellDeleted)
                m_dirtyLodMergeIndices.Add(cellProxy.Lod);

            return cellDeleted;
        }
        internal void OnRemovedFromScene(MyClipmapCellProxy cellProxy)
        {
            if (!MyRenderProxy.Settings.EnableVoxelMerging)
                return;

            if (m_mergesPerLod[cellProxy.Lod].OnRemovedFromScene(cellProxy))
                m_dirtyLodMergeIndices.Add(cellProxy.Lod);
        }
            internal bool OnDeleteCell(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                    return false;

                bool unloadedCell = false;
                Vector3D translation = cellProxy.Translation;
                int divideIndex;
                if (TryGetDivideIndex(ref translation, out divideIndex))
                {
                    MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                    LodMeshId lodMeshId = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);

                    bool unmergedMesh = mergedLodMeshId.UnmergeLodMesh(lodMeshId);
                    if (unmergedMesh)
                    {
                        InvalidateAllMergedMeshesInLod();
                    }

                    TryCancelMergeJob(divideIndex, cellProxy.MeshId);

                    cellProxy.Unload();
                    unloadedCell = true;

                    TryStartMergeJob(divideIndex, 1000);

                    if (unmergedMesh && unloadedCell)
                        m_dirtyProxyIndices.Add(divideIndex);

                    m_trackedActors[divideIndex].Remove(cellProxy.Actor);

                }

                int proxyId;
                if (m_cellProxyToAabbProxy.TryGetValue(cellProxy, out proxyId))
                {
                    m_boundingBoxes.RemoveProxy(m_cellProxyToAabbProxy[cellProxy]);
                    m_cellProxyToAabbProxy.Remove(cellProxy);
                }

                return unloadedCell;
            }
            internal bool OnRemovedFromScene(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                    return false;

                bool shouldMarkDirty = false;
                Vector3D translation = cellProxy.Translation;
                int divideIndex;
                if (TryGetDivideIndex(ref translation, out divideIndex))
                {
                    MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                    LodMeshId lodMeshId = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);

                    bool unmergedMesh = mergedLodMeshId.UnmergeLodMesh(lodMeshId);
                    if (unmergedMesh)
                    {
                        InvalidateAllMergedMeshesInLod();
                    }

                    TryCancelMergeJob(divideIndex, cellProxy.MeshId);
                    bool startedJob = TryStartMergeJob(divideIndex, 1000);

                    shouldMarkDirty = unmergedMesh && !startedJob;
                    if (shouldMarkDirty)
                        m_dirtyProxyIndices.Add(divideIndex);

                    m_trackedActors[divideIndex].Remove(cellProxy.Actor);
                }

                int proxyId;
                if (m_cellProxyToAabbProxy.TryGetValue(cellProxy, out proxyId))
                {
                    m_boundingBoxes.RemoveProxy(m_cellProxyToAabbProxy[cellProxy]);
                    m_cellProxyToAabbProxy.Remove(cellProxy);
                }

                return shouldMarkDirty;
            }
            internal bool OnAddedToScene(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                    return false;

                bool lodAabbChanged = false;
                int rootProxy = m_boundingBoxes.GetRoot();
                BoundingBoxD lodAabbBefore = BoundingBoxD.CreateInvalid();
                if(rootProxy != -1)
                    lodAabbBefore = m_boundingBoxes.GetAabb(rootProxy);

                BoundingBoxD cellAabb = (BoundingBoxD)cellProxy.LocalAabb;
                m_cellProxyToAabbProxy.Add(cellProxy, m_boundingBoxes.AddProxy(ref cellAabb, null, 0));

                if(rootProxy != -1)
                {
                    BoundingBoxD lodAabbAfter = m_boundingBoxes.GetAabb(rootProxy);
                    lodAabbChanged = lodAabbBefore.Equals(lodAabbAfter);
                }

                if(lodAabbChanged)
                    InvalidateAllMergedMeshesInLod();

                Vector3D translation = cellProxy.Translation;
                int divideIndex = GetDivideIndex(ref translation);

                m_trackedActors[divideIndex].Add(cellProxy.Actor);

                MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                LodMeshId lodMeshToMerge = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);
                bool mergedMesh = mergedLodMeshId.MergeLodMesh(lodMeshToMerge);
                if (mergedMesh)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                TryCancelMergeJob(divideIndex, MeshId.NULL);
                bool startedMerge = TryStartMergeJob(divideIndex, 1000);

                bool shouldMarkDirty = !mergedMesh && !startedMerge;
                if (shouldMarkDirty)
                    m_dirtyProxyIndices.Add(divideIndex);

                return shouldMarkDirty;
            }
Ejemplo n.º 15
0
 public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix)
 {
     Matrix m = (Matrix)worldMatrix;
     var cell = new MyClipmapCellProxy(cellCoord, ref m);
     cell.SetVisibility(false);
     cell.ScaleGroup = scaleGroup;
     return cell;
 }