public static MyMultiMaterialHelper GetForMultimaterial(MyMwcVoxelMaterialsEnum material0, MyMwcVoxelMaterialsEnum material1, MyMwcVoxelMaterialsEnum material2) { int id = MyVoxelCacheCellRender.GetMultimaterialId(material0, material1, material2); MyMultiMaterialHelper helper = null; m_preallocatedMultiMaterialHelpers.TryGetValue(id, out helper); if (helper == null) { helper = new MyMultiMaterialHelper(); helper.LoadData(); helper.SetMaterials(material0, material1, material2); m_preallocatedMultiMaterialHelpers.Add(id, helper); } return(helper); //m_multiMaterialHelper.SetMaterials(material0, material1, material2); //return m_multiMaterialHelper; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void LoadData() { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelCacheRender.LoadData"); MyMwcLog.WriteLine("MyVoxelCacheRender.LoadData() - START"); MyMwcLog.IncreaseIndent(); m_capacity = MyVoxelConstants.VOXEL_RENDER_CELL_CACHE_SIZE; m_cellsByCoordinate = new Dictionary <Int64, LinkedListNode <MyVoxelCacheCellRender> >(m_capacity); m_priority = new LinkedList <MyVoxelCacheCellRender>(); m_priorityArray = new LinkedListNode <MyVoxelCacheCellRender> [m_capacity]; m_cellsPreallocated = new MyVoxelCacheCellRender[m_capacity]; m_helperLodCachedDataCell = new MyVoxelCacheCellData(); m_dataCellsQueue = new List <MyVoxelCacheCellData>(MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_DATA_CELLS_TOTAL); for (int i = 0; i < m_capacity; i++) { m_cellsPreallocated[i] = new MyVoxelCacheCellRender(); m_priorityArray[i] = new LinkedListNode <MyVoxelCacheCellRender>(m_cellsPreallocated[i]); m_priority.AddLast(m_priorityArray[i]); } MyMwcLog.DecreaseIndent(); MyMwcLog.WriteLine("MyVoxelCacheRender.LoadData() - END"); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }
private static MyVoxelCacheCellRender LoadCell( MyVoxelMap voxelMap, ref MyMwcVector3Int renderCellCoord, MyLodTypeEnum cellHashType) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("AddCell"); MyVoxelCacheCellRender ret = AddCell(voxelMap.VoxelMapId, ref renderCellCoord, cellHashType); ret.Begin(voxelMap, ref renderCellCoord); ret.CellHashType = cellHashType; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); if (cellHashType == MyLodTypeEnum.LOD0) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("cellHashType LOD0"); m_dataCellsQueue.Clear(); // Create normal (LOD0) version for (int dataX = 0; dataX < MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE; dataX++) { for (int dataY = 0; dataY < MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE; dataY++) { for (int dataZ = 0; dataZ < MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE; dataZ++) { // Don't precalculate this cells now. Store it in queue and calculate all cells at once by MyVoxelPrecalc.PrecalcQueue() MyMwcVector3Int dataCellCoord = new MyMwcVector3Int( renderCellCoord.X * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE + dataX, renderCellCoord.Y * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE + dataY, renderCellCoord.Z * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE + dataZ); MyVoxelCacheCellData cachedDataCell = MyVoxelCacheData.GetCellLater(voxelMap, ref dataCellCoord); if (cachedDataCell != null) { m_dataCellsQueue.Add(cachedDataCell); } } } } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("PrecalcQueue LOD0"); // Precalculate all queued data cells in parallel threads - using multiple cores if possible. MyVoxelPrecalc.PrecalcQueue(); if (MyFakes.SIMPLIFY_VOXEL_MESH) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Stitch Data Cells LOD0"); MyDataCellStitcher.StitchDataCells(m_dataCellsQueue); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Decimate mesh LOD0"); MyMeshSimplifier.Instance.SimplifyMesh(MyDataCellStitcher.Vertices, MyDataCellStitcher.Triangles); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddTriangles LOD0"); ret.AddTriangles(MyDataCellStitcher.Vertices, MyDataCellStitcher.Triangles); } else { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddTriangles LOD0"); ret.AddTriangles(m_dataCellsQueue); } // Iterate all data cells and copy their triangles to this render cell //for (int i = 0; i < m_dataCellsQueue.Count; i++) //{ // ret.AddTriangles(m_dataCellsQueue[i]); //} MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else if (cellHashType == MyLodTypeEnum.LOD1) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("cellHashType LOD1"); m_helperLodCachedDataCell.Reset(); // Create LOD1 render cell MyVoxelPrecalc.PrecalcImmediatelly( new MyVoxelPrecalcTaskItem( MyLodTypeEnum.LOD1, voxelMap, m_helperLodCachedDataCell, new MyMwcVector3Int( renderCellCoord.X * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE, renderCellCoord.Y * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE, renderCellCoord.Z * MyVoxelConstants.VOXEL_DATA_CELLS_IN_RENDER_CELL_SIZE))); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("m_dataCellsQueue LOD1"); m_dataCellsQueue.Clear(); m_dataCellsQueue.Add(m_helperLodCachedDataCell); if (MyFakes.SIMPLIFY_VOXEL_MESH) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Stitch data cells LOD1"); MyDataCellStitcher.StitchDataCells(m_dataCellsQueue); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Decimate mesh LOD1"); MyMeshSimplifier.Instance.SimplifyMesh(MyDataCellStitcher.Vertices, MyDataCellStitcher.Triangles); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddTriangles LOD1"); ret.AddTriangles(MyDataCellStitcher.Vertices, MyDataCellStitcher.Triangles); } else { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddTriangles LOD1"); ret.AddTriangles(m_dataCellsQueue); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else { throw new MyMwcExceptionApplicationShouldNotGetHere(); } ret.End(); return(ret); }
public static MyVoxelCacheCellRender GetCell( MyVoxelMap voxelMap, ref MyMwcVector3Int renderCellCoord, MyLodTypeEnum cellHashType, MyVoxelCellQueryMode loadingMode = MyVoxelCellQueryMode.LoadImmediately) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GetCellFromCache"); MyVoxelCacheCellRender ret = GetCellFromCache(voxelMap.VoxelMapId, ref renderCellCoord, cellHashType); //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); if (ret == null) { switch (loadingMode) { case MyVoxelCellQueryMode.LoadImmediately: ret = LoadCell(voxelMap, ref renderCellCoord, cellHashType); break; case MyVoxelCellQueryMode.StartLoadBackground: TryLoadCellInBackground(voxelMap, ref renderCellCoord, cellHashType); break; case MyVoxelCellQueryMode.DoNotLoad: // do nothing break; default: throw new ArgumentOutOfRangeException("loadingMode"); } } if (ret != null) { //MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyVoxelCacheRender.UpdateCell"); UpdateCell(voxelMap.VoxelMapId, ref renderCellCoord, cellHashType); /* * BoundingBox box; * voxelMap.GetRenderCellBoundingBox(ref renderCellCoord, out box); * * * //MyDebugDraw.DrawAABBLowRes(ref box, ref v, 1); * * MyMwcVector3Int cellCoord; * MyMwcVector3Int cellCoordMin = voxelMap.GetDataCellCoordinateFromMeters(ref box.Min); * MyMwcVector3Int cellCoordMax = voxelMap.GetDataCellCoordinateFromMeters(ref box.Max); * * for (cellCoord.X = cellCoordMin.X; cellCoord.X <= cellCoordMax.X; cellCoord.X++) * { * for (cellCoord.Y = cellCoordMin.Y; cellCoord.Y <= cellCoordMax.Y; cellCoord.Y++) * { * for (cellCoord.Z = cellCoordMin.Z; cellCoord.Z <= cellCoordMax.Z; cellCoord.Z++) * { * if (MyVoxelCacheData.GetCellFromCache(voxelMap.VoxelMapId, ref cellCoord) != null) * { * MyVoxelCacheData.UpdateCell(voxelMap.VoxelMapId, ref cellCoord); * } * } * } * } */ /* * MyMwcVector3Int cellCoord; * for (cellCoord.X = 0; cellCoord.X < voxelMap.DataCellsCount.X; cellCoord.X++) * { * for (cellCoord.Y = 0; cellCoord.Y < voxelMap.DataCellsCount.Y; cellCoord.Y++) * { * for (cellCoord.Z = 0; cellCoord.Z < voxelMap.DataCellsCount.Z; cellCoord.Z++) * { * if (MyVoxelCacheData.GetCellFromCache(voxelMap.VoxelMapId, ref cellCoord) != null) * { * MyVoxelCacheData.UpdateCell(voxelMap.VoxelMapId, ref cellCoord); * } * } * } * } */ /* * // MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); * MyMwcVector3Int voxelCoord = new MyMwcVector3Int(renderCellCoord.X * MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS, renderCellCoord.Y * MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS, renderCellCoord.Z * MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS); * var datacellCoord = voxelMap.GetDataCellCoordinate(ref voxelCoord); * if (MyVoxelCacheData.GetCellFromCache(voxelMap.VoxelMapId, ref datacellCoord) != null) * { * MyVoxelCacheData.UpdateCell(voxelMap.VoxelMapId, ref datacellCoord); * } */ } return(ret); }
public MyRenderCellForSorting(MyVoxelCacheCellRender renderCell) { RenderCell = renderCell; }