SEToolbox.Interop.Asteroids.MyVoxelMap.SetVoxelContent C# (CSharp) Method

SetVoxelContent() private method

private SetVoxelContent ( byte content, Vector3I &voxelCoord, bool needLock = true ) : void
content byte
voxelCoord Vector3I
needLock bool
return void
        internal void SetVoxelContent(byte content, ref Vector3I voxelCoord, bool needLock = true)
        {
            //  We don't change voxel if it's a border voxel and it would be an empty voxel (not full). Because that would make voxel map with wrong/missing edges.
            if ((content > 0) && (IsVoxelAtBorder(ref voxelCoord))) return;

            var cellCoord = GetDataCellCoordinate(ref voxelCoord);
            var voxelCell = GetCell(ref cellCoord);

            if (voxelCell == null)
            {
                //  Voxel wasn't found in cell dictionary, therefore cell must be FULL

                if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
                {
                    //  Cell is full and we are seting voxel to full, so nothing needs to be changed
                    return;
                }
                else
                {
                    //  We are switching cell from type FULL to EMPTY or MIXED, therefore we need to allocate new cell
                    var newCell = AddCell(ref cellCoord);
                    var voxelCoordInCell = GetVoxelCoordinatesInDataCell(ref voxelCoord);
                    newCell.SetVoxelContent(content, ref voxelCoordInCell);
                }
            }
            else if (voxelCell.CellType == MyVoxelCellType.FULL)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_FULL)
                {
                    //  Cell is full and we are seting voxel to full, so nothing needs to be changed
                    return;
                }
                else
                {
                    var voxelCoordInCell = GetVoxelCoordinatesInDataCell(ref voxelCoord);
                    voxelCell.SetVoxelContent(content, ref voxelCoordInCell);
                    CheckIfCellChangedToFull(voxelCell, ref cellCoord);
                }
            }
            else if (voxelCell.CellType == MyVoxelCellType.EMPTY)
            {
                if (content == MyVoxelConstants.VOXEL_CONTENT_EMPTY)
                {
                    //  Cell is empty and we are seting voxel to empty, so nothing needs to be changed
                    return;
                }
                else
                {
                    var voxelCoordInCell = GetVoxelCoordinatesInDataCell(ref voxelCoord);
                    voxelCell.SetVoxelContent(content, ref voxelCoordInCell);
                    CheckIfCellChangedToFull(voxelCell, ref cellCoord);
                }
            }
            else if (voxelCell.CellType == MyVoxelCellType.MIXED)
            {
                var voxelCoordInCell = GetVoxelCoordinatesInDataCell(ref voxelCoord);
                var oldContent = voxelCell.GetVoxelContent(ref voxelCoordInCell);
                voxelCell.SetVoxelContent(content, ref voxelCoordInCell);
                CheckIfCellChangedToFull(voxelCell, ref cellCoord);
            }
            // ignore else condition.
        }

Usage Example

Ejemplo n.º 1
0
        private void MergeAsteroidMaterialFrom(ref MyVoxelMap newAsteroid, Vector3 min, StructureVoxelModel modelPrimary, StructureVoxelModel modelSecondary, Vector3 minPrimary, Vector3 minSecondary)
        {
            var filenameSecondary = modelSecondary.SourceVoxelFilepath ?? modelSecondary.VoxelFilepath;
            var filenamePrimary = modelPrimary.SourceVoxelFilepath ?? modelPrimary.VoxelFilepath;
            Vector3I coords;

            var asteroid = new MyVoxelMap();
            asteroid.Load(filenamePrimary, SpaceEngineersCore.Resources.GetDefaultMaterialName(), true);

            for (coords.Z = (int)modelPrimary.ContentBounds.Min.Z; coords.Z <= modelPrimary.ContentBounds.Max.Z; coords.Z++)
            {
                for (coords.Y = (int)modelPrimary.ContentBounds.Min.Y; coords.Y <= modelPrimary.ContentBounds.Max.Y; coords.Y++)
                {
                    for (coords.X = (int)modelPrimary.ContentBounds.Min.X; coords.X <= modelPrimary.ContentBounds.Max.X; coords.X++)
                    {
                        byte volume;
                        string cellMaterial;
                        asteroid.GetVoxelMaterialContent(ref coords, out cellMaterial, out volume);

                        var newCoord = ((minPrimary - min) + ((Vector3D)coords - modelPrimary.ContentBounds.Min)).RoundToVector3I();
                        newAsteroid.SetVoxelContent(volume, ref newCoord);
                        newAsteroid.SetVoxelMaterialAndIndestructibleContent(cellMaterial, 0xff, ref newCoord);
                    }
                }
            }

            asteroid.Load(filenameSecondary, SpaceEngineersCore.Resources.GetDefaultMaterialName(), true);

            for (coords.Z = (int)modelSecondary.ContentBounds.Min.Z; coords.Z <= modelSecondary.ContentBounds.Max.Z; coords.Z++)
            {
                for (coords.Y = (int)modelSecondary.ContentBounds.Min.Y; coords.Y <= modelSecondary.ContentBounds.Max.Y; coords.Y++)
                {
                    for (coords.X = (int)modelSecondary.ContentBounds.Min.X; coords.X <= modelSecondary.ContentBounds.Max.X; coords.X++)
                    {
                        var newCoord = ((minSecondary - min) + ((Vector3D)coords - modelSecondary.ContentBounds.Min)).RoundToVector3I();
                        if (Vector3I.BoxContains(Vector3I.Zero, modelPrimary.Size - 1, newCoord))
                        {
                            byte volume;
                            string cellMaterial;
                            asteroid.GetVoxelMaterialContent(ref coords, out cellMaterial, out volume);

                            if (volume > 0)
                            {
                                newAsteroid.SetVoxelMaterialAndIndestructibleContent(cellMaterial, 0xff, ref newCoord);
                            }
                        }
                    }
                }
            }
        }
All Usage Examples Of SEToolbox.Interop.Asteroids.MyVoxelMap::SetVoxelContent