本文整理汇总了C#中VRage.Voxels.MyCellCoord.PackId64方法的典型用法代码示例。如果您正苦于以下问题:C# MyCellCoord.PackId64方法的具体用法?C# MyCellCoord.PackId64怎么用?C# MyCellCoord.PackId64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VRage.Voxels.MyCellCoord
的用法示例。
在下文中一共展示了MyCellCoord.PackId64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MarkBlockChanged
// Actually, this function marks even cubes around the block to make sure that any changes caused in their triangles
// will be reflected in the navigation mesh.
public void MarkBlockChanged(MySlimBlock block)
{
Vector3I min = block.Min - Vector3I.One;
Vector3I max = block.Max + Vector3I.One;
Vector3I pos = min;
for (var it = new Vector3I.RangeIterator(ref block.Min, ref block.Max); it.IsValid(); it.GetNext(out pos))
{
m_changedCubes.Add(pos);
}
Vector3I minCell = CubeToCell(ref min);
Vector3I maxCell = CubeToCell(ref max);
pos = minCell;
for (var it = new Vector3I.RangeIterator(ref minCell, ref maxCell); it.IsValid(); it.GetNext(out pos))
{
m_changedCells.Add(pos);
MyCellCoord cellCoord = new MyCellCoord(0, pos);
ulong packedCell = cellCoord.PackId64();
TryClearCell(packedCell);
}
}
示例2: InvalidateRange
internal void InvalidateRange(Vector3I lodMin, Vector3I lodMax)
{
var cell = new MyCellCoord(m_lodIndex, lodMin);
for (var it = new Vector3I.RangeIterator(ref lodMin, ref lodMax);
it.IsValid(); it.GetNext(out cell.CoordInLod))
{
CellData data;
var id = cell.PackId64();
using (m_storedCellDataLock.AcquireSharedUsing())
{
if (m_storedCellData.TryGetValue(id, out data))
{
data.State = CellState.Invalid;
}
}
}
}
示例3: GetClosestHighLevelPrimitive
private MyHighLevelPrimitive GetClosestHighLevelPrimitive(ref Vector3 point, ref float closestDistanceSq)
{
MyHighLevelPrimitive retval = null;
// Convert from world matrix local coords to LeftBottomCorner-based coords
Vector3 lbcPoint = point + (m_voxelMap.PositionComp.GetPosition() - m_voxelMap.PositionLeftBottomCorner);
m_tmpIntList.Clear();
// Collect components from the eight closest cells
Vector3I closestCellCorner = Vector3I.Round(lbcPoint / m_cellSize);
for (int i = 0; i < 8; ++i)
{
Vector3I cell = closestCellCorner + m_cornerOffsets[i];
MyCellCoord coord = new MyCellCoord(NAVMESH_LOD, cell);
ulong packedCoord = coord.PackId64();
m_higherLevelHelper.CollectComponents(packedCoord, m_tmpIntList);
}
foreach (int componentIndex in m_tmpIntList)
{
var hlPrimitive = m_higherLevel.GetPrimitive(componentIndex);
Debug.Assert(hlPrimitive != null, "Couldnt' find a high-level primitive for the index given by higher level helper!");
if (hlPrimitive == null) continue;
float distSq = Vector3.DistanceSquared(hlPrimitive.Position, point);
if (distSq < closestDistanceSq)
{
closestDistanceSq = distSq;
retval = hlPrimitive;
}
}
m_tmpIntList.Clear();
return retval;
}
示例4: RemoveCell
private bool RemoveCell(Vector3I cell)
{
if (!MyFakes.REMOVE_VOXEL_NAVMESH_CELLS) return true;
Debug.Assert(m_processedCells.Contains(cell), "Removing a non-existent cell from the navmesh!");
if (!m_processedCells.Contains(cell)) return false;
MyTrace.Send(TraceWindow.Ai, "Removing cell " + cell);
ProfilerShort.Begin("Removing navmesh links");
MyVoxelPathfinding.CellId cellId = new MyVoxelPathfinding.CellId() { VoxelMap = m_voxelMap, Pos = cell };
m_navmeshCoordinator.RemoveVoxelNavmeshLinks(cellId);
ProfilerShort.End();
ProfilerShort.Begin("Removing triangles");
MyCellCoord coord = new MyCellCoord(NAVMESH_LOD, cell);
ulong packedCoord = coord.PackId64();
MyIntervalList triangleList = m_higherLevelHelper.TryGetTriangleList(packedCoord);
if (triangleList != null)
{
foreach (var triangleIndex in triangleList)
{
RemoveTerrainTriangle(GetTriangle(triangleIndex));
}
m_higherLevelHelper.ClearCachedCell(packedCoord);
}
ProfilerShort.End();
Debug.Assert(m_processedCells.Contains(ref cell));
m_processedCells.Remove(ref cell);
return triangleList != null;
}
示例5: InvalidateRange
public void InvalidateRange(Vector3I minVoxelChanged, Vector3I maxVoxelChanged)
{
minVoxelChanged -= MyPrecalcComponent.InvalidatedRangeInflate;
maxVoxelChanged += MyPrecalcComponent.InvalidatedRangeInflate;
m_voxelMap.Storage.ClampVoxelCoord(ref minVoxelChanged);
m_voxelMap.Storage.ClampVoxelCoord(ref maxVoxelChanged);
Vector3I minCell, maxCell;
MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref minVoxelChanged, out minCell);
MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref maxVoxelChanged, out maxCell);
Vector3I currentCell = minCell;
for (var it = new Vector3I.RangeIterator(ref minCell, ref maxCell); it.IsValid(); it.GetNext(out currentCell))
{
if (m_processedCells.Contains(ref currentCell))
{
RemoveCell(currentCell);
}
MyCellCoord coord = new MyCellCoord(NAVMESH_LOD, currentCell);
m_higherLevelHelper.TryClearCell(coord.PackId64());
}
}
示例6: GetCell
internal CellData GetCell(ref MyCellCoord cell)
{
MyPrecalcComponent.AssertUpdateThread();
bool isEmpty;
CellData data;
if (TryGetCell(cell, out isEmpty, out data))
{
return data;
}
MyIsoMesh mesh;
if (!TryGetMesh(cell, out isEmpty, out mesh))
{
ProfilerShort.Begin("Cell precalc");
if (true)
{
var min = cell.CoordInLod << MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS_BITS;
var max = min + MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS;
// overlap to neighbor; introduces extra data but it makes logic for raycasts simpler (no need to check neighbor cells)
min -= 1;
max += 2;
mesh = MyPrecalcComponent.IsoMesher.Precalc(m_storage, 0, min, max, false, MyFakes.ENABLE_VOXEL_COMPUTED_OCCLUSION, true);
}
else
{
mesh = MyPrecalcComponent.IsoMesher.Precalc(new MyIsoMesherArgs()
{
Storage = m_storage,
GeometryCell = cell,
});
}
ProfilerShort.End();
}
if (mesh != null)
{
data = new CellData();
data.Init(
mesh.PositionOffset, mesh.PositionScale,
mesh.Positions.GetInternalArray(), mesh.VerticesCount,
mesh.Triangles.GetInternalArray(), mesh.TrianglesCount);
}
if (cell.Lod == 0)
{
using (m_lock.AcquireExclusiveUsing())
{
if (data != null)
{
var key = cell.PackId64();
m_cellsByCoordinate[key] = data;
}
else
{
SetEmpty(ref cell, true);
}
}
}
return data;
}
示例7: SetMesh
public void SetMesh(MyCellCoord cell, MyIsoMesh mesh)
{
// Don't store anything but the most detailed lod (used in physics and raycasts).
// This cache is mostly supposed to help physics and raycasts, not render.
if (cell.Lod != 0)
return;
MyPrecalcComponent.AssertUpdateThread();
using (m_lock.AcquireExclusiveUsing())
{
if (mesh != null)
{
var key = cell.PackId64();
m_coordinateToMesh[key] = mesh;
}
else
{
SetEmpty(ref cell, true);
}
}
}
示例8: TryGetCell
private bool TryGetCell(MyCellCoord cell, out bool isEmpty, out CellData nonEmptyCell)
{
MyPrecalcComponent.AssertUpdateThread();
using (m_lock.AcquireSharedUsing())
{
if (IsEmpty(ref cell))
{
isEmpty = true;
nonEmptyCell = null;
return true;
}
UInt64 key = cell.PackId64();
if (m_cellsByCoordinate.TryGetValue(key, out nonEmptyCell))
{
isEmpty = false;
return true;
}
isEmpty = default(bool);
nonEmptyCell = default(CellData);
return false;
}
}
示例9: ChildrenWereLoaded
/// <summary>
/// Checks only immediate children (any deeper would take too long).
/// </summary>
private static bool ChildrenWereLoaded(LodLevel childLod, ref MyCellCoord thisLodCell)
{
if (childLod == null || !childLod.Visible)
return false;
Debug.Assert(thisLodCell.Lod == childLod.m_lodIndex + 1);
var childLodCell = new MyCellCoord();
childLodCell.Lod = childLod.m_lodIndex;
var start = thisLodCell.CoordInLod << 1;
var end = start + 1;
Vector3I.Min(ref end, ref childLod.m_lodSizeMinusOne, out end);
for (childLodCell.CoordInLod.Z = start.Z; childLodCell.CoordInLod.Z <= end.Z; ++childLodCell.CoordInLod.Z)
for (childLodCell.CoordInLod.Y = start.Y; childLodCell.CoordInLod.Y <= end.Y; ++childLodCell.CoordInLod.Y)
for (childLodCell.CoordInLod.X = start.X; childLodCell.CoordInLod.X <= end.X; ++childLodCell.CoordInLod.X)
{
var key = childLodCell.PackId64();
CellData data;
if (!childLod.m_storedCellData.TryGetValue(key, out data))
{
return false;
}
if (!data.WasLoaded)
{
return false;
}
}
return true;
}
示例10: WasAncestorCellLoaded
/// <summary>
/// Checks ancestor nodes recursively. Typically, this checks at most 9 nodes or so (depending on settings).
/// </summary>
private static bool WasAncestorCellLoaded(LodLevel parentLod, ref MyCellCoord thisLodCell)
{
if (parentLod == null || !parentLod.m_fitsInFrustum || !parentLod.Visible)
{
return true;
}
Debug.Assert(thisLodCell.Lod == parentLod.m_lodIndex - 1);
var parentCell = new MyCellCoord(thisLodCell.Lod + 1, thisLodCell.CoordInLod >> 1);
CellData data;
if (parentLod.m_storedCellData.TryGetValue(parentCell.PackId64(), out data))
{
return data.WasLoaded;
}
LodLevel ancestor;
if (parentLod.m_parent.m_lodLevels.TryGetValue(parentLod.m_lodIndex+1, out ancestor))
return WasAncestorCellLoaded(ancestor, ref parentCell);
else
return false;
}
示例11: DoClipping
internal void DoClipping(Vector3D localPosition, float farPlaneDistance, RequestCollector collector)
{
MyClipmap.ComputeLodViewBounds(m_parent.m_scaleGroup, m_lodIndex, out m_nearDistance, out m_farDistance);
m_fitsInFrustum = (farPlaneDistance * 1.25f) > m_nearDistance;
if (!m_fitsInFrustum)
return;
Vector3I min, max;
{
var minD = localPosition - m_farDistance;
var maxD = localPosition + m_farDistance;
MyVoxelCoordSystems.LocalPositionToRenderCellCoord(ref minD, out min);
MyVoxelCoordSystems.LocalPositionToRenderCellCoord(ref maxD, out max);
Vector3I.Max(ref min, ref Vector3I.Zero, out min);
Vector3I.Max(ref max, ref Vector3I.Zero, out max);
min >>= m_lodIndex;
max >>= m_lodIndex;
Vector3I.Min(ref min, ref m_lodSizeMinusOne, out min);
Vector3I.Min(ref max, ref m_lodSizeMinusOne, out max);
}
if (m_lastMin == min && m_lastMax == max && !m_parent.m_updateClipping)
return;
m_lastMin = min;
m_lastMax = max;
LodLevel parentLod, childLod;
GetNearbyLodLevels(out parentLod, out childLod);
// Moves cells which are still needed from one collection to another.
// All that is left behind is unloaded as no longer needed.
// Move everything in range to collection of next stored cells.
MyUtils.Swap(ref m_storedCellData, ref m_clippedCells);
m_storedCellData.Clear();
MyCellCoord cell = new MyCellCoord(m_lodIndex, ref min);
for (var it = new Vector3I.RangeIterator(ref min, ref max);
it.IsValid(); it.GetNext(out cell.CoordInLod))
{
if (!WasAncestorCellLoaded(parentLod, ref cell))
continue;
var cellId = cell.PackId64();
CellData data;
if (m_clippedCells.TryGetValue(cellId, out data))
m_clippedCells.Remove(cellId);
else
data = new CellData();
if (data.State == CellState.Invalid)
{
collector.AddRequest(cellId, data.WasLoaded);
data.State = CellState.Pending;
}
m_storedCellData.Add(cellId, data);
}
}
示例12: OpenNewCell
/// <summary>
/// Begins processing a voxel geometry cell
/// </summary>
public void OpenNewCell(MyCellCoord coord)
{
Debug.Assert(m_cellOpen == false, "Cannot open a new cell in MyVoxelHighLevelHelper while another one is open!");
m_cellOpen = true;
m_currentCell = coord.CoordInLod;
m_packedCoord = coord.PackId64();
m_triangleList.Clear();
}
示例13: TryClearCell
public void TryClearCell(ulong packedCoord)
{
if (m_triangleLists.ContainsKey(packedCoord))
{
ClearCachedCell(packedCoord);
}
RemoveExplored(packedCoord);
MyNavmeshComponents.CellInfo cellInfo;
if (!m_navmeshComponents.TryGetCell(packedCoord, out cellInfo))
{
return;
}
for (int i = 0; i < cellInfo.ComponentNum; ++i)
{
int componentIndex = cellInfo.StartingIndex + i;
m_mesh.HighLevelGroup.RemovePrimitive(componentIndex);
}
foreach (var direction in Base6Directions.EnumDirections)
{
Base6Directions.DirectionFlags dirFlag = Base6Directions.GetDirectionFlag(direction);
if (cellInfo.ExploredDirections.HasFlag(dirFlag))
{
Vector3I dirVec = Base6Directions.GetIntVector(direction);
MyCellCoord otherCoord = new MyCellCoord();
otherCoord.SetUnpack(packedCoord);
Debug.Assert(otherCoord.Lod == MyVoxelNavigationMesh.NAVMESH_LOD);
otherCoord.CoordInLod = otherCoord.CoordInLod + dirVec;
MyNavmeshComponents.CellInfo otherCellInfo;
if (m_navmeshComponents.TryGetCell(otherCoord.PackId64(), out otherCellInfo))
{
Base6Directions.DirectionFlags flippedFlag = Base6Directions.GetDirectionFlag(Base6Directions.GetFlippedDirection(direction));
m_navmeshComponents.SetExplored(otherCoord.PackId64(), otherCellInfo.ExploredDirections & ~flippedFlag);
}
else
{
Debug.Assert(false, "Could not get the oposite explored cell!");
}
}
}
m_navmeshComponents.ClearCell(packedCoord, ref cellInfo);
}
示例14: ProcessCellComponents
public void ProcessCellComponents()
{
ProfilerShort.Begin("ProcessCellComponents");
m_triangleLists.Add(m_packedCoord, m_triangleList.GetCopy());
long timeBegin = m_mesh.GetCurrentTimestamp() + 1;
long timeEnd = timeBegin;
m_currentComponentRel = 0;
m_currentComponent = m_navmeshComponents.OpenCell(m_packedCoord);
foreach (var triIndex in m_triangleList)
{
// Skip already visited triangles
var triangle = m_mesh.GetTriangle(triIndex);
if (m_mesh.VisitedBetween(triangle, timeBegin, timeEnd))
{
continue;
}
m_navmeshComponents.OpenComponent();
// Make sure we have place in m_currentCellConnections
if (m_currentComponentRel >= m_currentCellConnections.Count)
{
m_currentCellConnections.Add(new List<ConnectionInfo>());
}
// Find connected component from an unvisited triangle
ProfilerShort.Begin("Graph traversal");
m_currentHelper = this;
m_navmeshComponents.AddComponentTriangle(triangle, triangle.Center);
triangle.ComponentIndex = m_navmeshComponents.OpenComponentIndex;
m_mesh.PrepareTraversal(triangle, null, m_processTrianglePredicate);
var primitiveEnum = m_mesh.GetEnumerator();
while (primitiveEnum.MoveNext());
primitiveEnum.Dispose();
ProfilerShort.End();
m_navmeshComponents.CloseComponent();
timeEnd = m_mesh.GetCurrentTimestamp();
m_currentComponentRel++;
}
MyNavmeshComponents.ClosedCellInfo cellInfo = new MyNavmeshComponents.ClosedCellInfo();
m_navmeshComponents.CloseAndCacheCell(ref cellInfo);
// Add new component primitives
if (cellInfo.NewCell)
{
for (int i = 0; i < cellInfo.ComponentNum; ++i)
{
m_mesh.HighLevelGroup.AddPrimitive(cellInfo.StartingIndex + i, m_navmeshComponents.GetComponentCenter(i));
}
}
// Connect new components with the others in the neighboring cells
for (int i = 0; i < cellInfo.ComponentNum; ++i)
{
foreach (var connectionInfo in m_currentCellConnections[i])
{
if (!cellInfo.ExploredDirections.HasFlag(Base6Directions.GetDirectionFlag(connectionInfo.Direction)))
{
m_mesh.HighLevelGroup.ConnectPrimitives(cellInfo.StartingIndex + i, connectionInfo.ComponentIndex);
}
}
m_currentCellConnections[i].Clear();
}
// Mark explored directions in the navmesh component helper
foreach (var direction in Base6Directions.EnumDirections)
{
var dirFlag = Base6Directions.GetDirectionFlag(direction);
if (cellInfo.ExploredDirections.HasFlag(dirFlag))
{
continue;
}
Vector3I dirVec = Base6Directions.GetIntVector(direction);
MyCellCoord otherCoord = new MyCellCoord();
otherCoord.Lod = MyVoxelNavigationMesh.NAVMESH_LOD;
otherCoord.CoordInLod = m_currentCell + dirVec;
if (otherCoord.CoordInLod.X == -1 || otherCoord.CoordInLod.Y == -1 || otherCoord.CoordInLod.Z == -1)
{
continue;
}
ulong otherPackedCoord = otherCoord.PackId64();
if (m_triangleLists.ContainsKey(otherPackedCoord))
{
m_navmeshComponents.MarkExplored(otherPackedCoord, Base6Directions.GetFlippedDirection(direction));
cellInfo.ExploredDirections |= Base6Directions.GetDirectionFlag(direction);
}
}
m_navmeshComponents.SetExplored(m_packedCoord, cellInfo.ExploredDirections);
//.........这里部分代码省略.........
示例15: UnclipCell
private void UnclipCell(RequestCollector collector, MyCellCoord cell, bool isVisible)
{
var cellId = cell.PackId64();
var clipmapCellId = MyCellCoord.GetClipmapCellHash(m_clipmap.Id, cellId);
MyClipmap_CellData data;
if (isVisible)
{
bool highPriority = true;
if (m_clippedCells.TryGetValue(cellId, out data))
{
m_clippedCells.Remove(cellId);
}
else
{
highPriority = false;
CellBlendData blendData;
if (!m_blendedCells.TryGetValue(cellId, out blendData))
{
data = CellsCache.Read(clipmapCellId);
if (data == null) //cache miss
{
data = new MyClipmap_CellData();
ClippingCacheMisses++;
}
else
{
//cache hit
ClippingCacheHits++;
//System.Diagnostics.Debug.Assert((!data.InScene && data.Cell != null) || data.Cell == null, "Not allowed cell state");
data.InScene = false;
if (data.Cell != null)
{
m_nonEmptyCells[cellId] = data;
}
}
}
else
{
data = blendData.CellData;
if (blendData.State == BlendState.Removing)
blendData.UndoAfterFinish = true;
if (data.Cell != null)
{
m_nonEmptyCells[cellId] = data;
}
}
}
if (data.State == CellState.Invalid)
{
if (MyClipmap.UseQueries)
{
BoundingBoxD bbd;
MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out bbd);
BoundingBox bb = new BoundingBox(bbd);
if (m_clipmap.m_prunningFunc == null || m_clipmap.m_prunningFunc(ref bb, false) == ContainmentType.Intersects)
{
collector.AddRequest(cellId, data, highPriority);
}
else
{
data.State = CellState.Loaded;
data.WasLoaded = true;
}
}
else
collector.AddRequest(cellId, data, highPriority);
}
m_storedCellData.Add(cellId, data);
data.ReadyInClipmap = true;
data.ClippedOut = false;
}
else
{
if (!m_storedCellData.ContainsKey(cellId) && (!PendingCacheCellData.ContainsKey(clipmapCellId) || PendingCacheCellData[clipmapCellId].State == CellState.Invalid) && CellsCache.Read(clipmapCellId) == null)
{
if (!PendingCacheCellData.TryGetValue(clipmapCellId, out data))
{
data = new MyClipmap_CellData();
PendingCacheCellData.Add(clipmapCellId, data);
}
if (MyClipmap.UseQueries)
{
BoundingBoxD bbd;
MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out bbd);
BoundingBox bb = new BoundingBox(bbd);
if (m_clipmap.m_prunningFunc == null || m_clipmap.m_prunningFunc(ref bb, false) == ContainmentType.Intersects)
{
data.State = CellState.Invalid;
collector.AddRequest(cellId, data, false);
}
else
//.........这里部分代码省略.........