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

SeedMaterialSphere() public method

Set a material for a random voxel cell and possibly nearest ones to it.
public SeedMaterialSphere ( string materialName, byte radius ) : void
materialName string material name
radius byte radius in voxels, defaults to zero, meaning only a random grid.
return void
        public void SeedMaterialSphere(string materialName, byte radius = 0)
        {
            var fullCells = new List<Vector3I> { };
            Vector3I cellCoord;
            // Collect the non-empty cell coordinates
            for (cellCoord.X = 0; cellCoord.X < _dataCellsCount.X; cellCoord.X++)
                for (cellCoord.Y = 0; cellCoord.Y < _dataCellsCount.Y; cellCoord.Y++)
                    for (cellCoord.Z = 0; cellCoord.Z < _dataCellsCount.Z; cellCoord.Z++)
                        if (!CheckCellType(ref _voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z], MyVoxelCellType.EMPTY))
                            fullCells.Add(cellCoord);

            // Choose random cell and switch material there
            fullCells.Shuffle();
            int cellCount = fullCells.Count;
            Vector3I cell, vlen;
            for (int i = 0; i < cellCount; i++)
            {
                cell = fullCells[i];
                if (i == 0)
                {
                    SetVoxelMaterialRegion(materialName, ref cell);
                    continue;
                }
                // Optionally seek adjanced cells and set their material too.
                if (radius == 0)
                    return;
                vlen = fullCells[0] - cell;
                if (vlen.RectangularLength() <= radius)
                {
                    SetVoxelMaterialRegion(materialName, ref cell);
                }
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void FillAsteroid(MyVoxelMap asteroid, IMyVoxelFillProperties fillProperties)
        {
            var properties = (AsteroidSeedFillProperties)fillProperties;

            /* The full history behind this hack/crutch eludes me.
                 * There are roids that won't change their materials unless their face materials forced to something other than current value.
                 * So we have to do that manually by setting to a usually unused ore (uranium) and then reverting to the one we chose (=old one in case of a flaky roid)
                 */
            byte oldMaterial = asteroid.VoxelMaterial;
            asteroid.ForceVoxelFaceMaterial("Uraninite_01");
            asteroid.ForceVoxelFaceMaterial(properties.MainMaterial.Value);

            // Cycle through veins info and add 'spherical' depisits to the voxel cell grid (not voxels themselves)
            int i;

            if (properties.FirstVeins > 0)
                for (i = 0; i < properties.FirstVeins; i++)
                    asteroid.SeedMaterialSphere(properties.FirstMaterial.Value, (byte)properties.FirstRadius);

            if (properties.SecondVeins > 0)
                for (i = 0; i < properties.SecondVeins; i++)
                    asteroid.SeedMaterialSphere(properties.SecondMaterial.Value, (byte)properties.SecondRadius);

            if (properties.ThirdVeins > 0)
                for (i = 0; i < properties.ThirdVeins; i++)
                    asteroid.SeedMaterialSphere(properties.ThirdMaterial.Value, (byte)properties.ThirdRadius);

            if (properties.FourthVeins > 0)
                for (i = 0; i < properties.FourthVeins; i++)
                    asteroid.SeedMaterialSphere(properties.FourthMaterial.Value, (byte)properties.FourthRadius);

            if (properties.FifthVeins > 0)
                for (i = 0; i < properties.FifthVeins; i++)
                    asteroid.SeedMaterialSphere(properties.FifthMaterial.Value, (byte)properties.FifthRadius);

            if (properties.SixthVeins > 0)
                for (i = 0; i < properties.SixthVeins; i++)
                    asteroid.SeedMaterialSphere(properties.SixthMaterial.Value, (byte)properties.SixthRadius);

            if (properties.SeventhVeins > 0)
                for (i = 0; i < properties.SeventhVeins; i++)
                    asteroid.SeedMaterialSphere(properties.SeventhMaterial.Value, (byte)properties.SeventhRadius);

            // Hide the surface materials up to depth of 2 cells.
            asteroid.ForceShellMaterial(properties.MainMaterial.Value, 2);

            // This recovers material assigning ability for most roids (could be something specific to indestructibleContent property?)
            // And not for all, apparently :(
            //asteroid.ForceVoxelFaceMaterial(_dataModel.BaseMaterial.DisplayName); // don't change mattype

            // doesn't help
            //asteroid.ForceIndestructibleContent(0xff);

            // Alt ends     
        }