midspace / midspace/SEToolbox

New option under "Create" to "Generate Asteroid Belt"

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
156
Forks
62
PR merge metrics
No merged PRs in 30d

Description

I have been looking for a while on how to generate an asteroid belt in space engineers. After some research there was no good way to do this other then really generate all those asteroids. Whereas with your program it can already generate asteroid fields. It ook me some time as a junior software engineer to find the specific code in your source code which was generating the astroids.

As I understood The method "BuildEntities" will build all the entities created in the pop-up windows. which triggers on create button event.

I kindly ask if you would like to implement this feature where the only thing still needed to be done is a new pop-up window. Which differs from "generate asteroid field" it would require the following parameters: Center (x, y, z coordinates), Radius (the distant from the center where the belt will be created), amount of asteroid (I would recommend using your already written random generate astroid in a loop function to generate the amount of asteroid. this in turn will result in how dense the astroid belt will be.

public void BuildEntitiesBelt(out string[] sourceVoxelFiles, out MyObjectBuilder_EntityBase[] sourceEntities)
        {
            var entities = new List<MyObjectBuilder_EntityBase>();
            var sourceFiles = new List<string>();
			var AsteroidCount = VoxelCollection.Count;

            MainViewModel.ResetProgress(0, AsteroidCount);

            foreach (var voxelDesign in VoxelCollection)
            {
                MainViewModel.Progress++;
                if (string.IsNullOrEmpty(voxelDesign.VoxelFile.SourceFilename) || !MyVoxelMap.IsVoxelMapFile(voxelDesign.VoxelFile.SourceFilename))
                    continue;


                var asteroid = new MyVoxelMap();
                string tempSourcefilename = null;

                switch (AsteroidFillType)
                {
                    case Support.AsteroidFillType.None:
                        asteroid.Load(voxelDesign.VoxelFile.SourceFilename, voxelDesign.MainMaterial.Value, false);
                        tempSourcefilename = voxelDesign.VoxelFile.SourceFilename;
                        break;

                    case AsteroidFillType.ByteFiller:
                        asteroid.Load(voxelDesign.VoxelFile.SourceFilename, voxelDesign.MainMaterial.Value, false);
                        var filler = new AsteroidByteFiller();
                        filler.FillAsteroid(asteroid, voxelDesign);
                        tempSourcefilename = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension);
                        asteroid.Save(tempSourcefilename);
                        break;
                }


                // automatically number all files, and check for duplicate filenames.
                var filename = MainViewModel.CreateUniqueVoxelStorageName(voxelDesign.VoxelFile.Name + MyVoxelMap.V2FileExtension, entities.ToArray());

				Random random = new Random()
				
                var x = CenterPositionX + radius * Math.cos(2 * Math.PI * i / AsteroidCount);
                var y = CenterPositionY + radius * Math.sin(2 * Math.PI * i / AsteroidCount);
                var z = CenterPositionZ + random.Next(-4000, 4000);

				x+= random.Next(-2000, 2000);
				y+= random.Next(-2000, 2000);
				
                var center = new Vector3D(CenterPositionX, CenterPositionY, CenterPositionZ);
                var position = center + new Vector3D(x, y, z) - asteroid.BoundingContent.Center;
                var entity = new MyObjectBuilder_VoxelMap(position, filename)
                {
                    EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID),
                    PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                    StorageName = Path.GetFileNameWithoutExtension(filename),
                    PositionAndOrientation = new MyPositionAndOrientation
                    {
                        Position = position,
                        Forward = Vector3.Forward, // Asteroids currently don't have any orientation.
                        Up = Vector3.Up
                    }
                };

                entities.Add(entity);
                sourceFiles.Add(tempSourcefilename);
            }

            sourceVoxelFiles = sourceFiles.ToArray();
            sourceEntities = entities.ToArray();
        }

This code is almost an exact copy of yours but with some slight changes in how the coordinates are calculated. It's up to you if you want two sperate methods or just a simple if statement checking if you are generating asteroid field or belt.

I haven't created a pop-up yet. If you don't have time I will try to make it myself. but as I said I'm still learning to code.

Hope this will help the community as some people are looking to generate an asteroid belt which this will be able to do.

If I missed anything thing or you would like some more information, I'm keen to hear from you!

Also let me know what you think of this feature!

Sidenote: put a warning that if you go a higher number then 10000 asteroid it will decrease load time of said save world.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing BuildEntities method and the Create and Generate Asteroid Field UI entry points described in the issue. Read how current asteroid fields collect parameters and build entities, then define the belt dialog and coordinate generation so a saved world contains the requested number of asteroids within the specified radius; validate the stated high-count warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.