Jump to content

Control stamper rules region for map generation


Meudes

Recommended Posts

In the World Designer, World Detail section, in a multi-tile map, I would like to choose to configure (World Detail, rules) a particular region of the map for the "spawn" of a stamper.

The control parameters of the regions to be stamped could be "Add to World Detail Rules" :
Add: a region: Tiles X / Tiles Y (top left corner of the region)
Add: Tiles Width / Tiles Height (definition of region size)
Then, current rules.

For adventurers :

In Class Gaia.Spawner,

function :

/// <summary>
/// Spawn the World Detail Stamps for the World Designer according to its settings and the current BaseTerrain Preview
/// </summary>
public void SpawnStamps()


I tested reducing the chancesList to 0 if the rule is outside the region tiles thanks to the position of the stampPosition. The problem is the scale of the stampPosition.

I followed the trail of:
shader.Dispatch(kernelHandle, baseTerrainStamper.m_cachedRenderTexture.width / 8, baseTerrainStamper.m_cachedRenderTexture.height / 8, 1);

To find the scale of the stampPostion and relate it to the tiles. But it's not good...

By deduction, I think the scale of the SpawnStamps is = (1 tiles size) x (tiles countr) + (2 x 1 tiles size)
(2xsize1tiles = edges added)

The result was not great. I decided to vary the active or not rules depending on the position and there: it seems that it works.

Exemple for Mountains :
 

//Get a scalar max height of the input terrain (the output from the compute shader goes from 0 to 0.5)
            float scalarMaxHeight = Mathf.Lerp(0, 0.5f, Mathf.InverseLerp(0, TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapPreviewTerrainHeight, m_maxWorldHeight));

            // ADD MEUDES CODE : save Rules *******************************************>
            // I save Rules : It's not elegant, but the goal is to group the code addition
            List<bool> backupRules = new List<bool>();
            Debug.Log("Rules Setup --------------------------");
            foreach (SpawnRule sr in m_settings.m_spawnerRules)
            {
                backupRules.Add(sr.m_isActive);
                if (sr.m_isActive)
                    Debug.Log(sr.m_name);
            }
            //<----------------------------------------------------------***************

            try
            {

                for (int i = 0; i < outputStampPositions.Length; i++)
                {
                    bool cancel = ProgressBar.Show(ProgressBarPriority.Spawning, "Spawning Stamps..", "Spawning Stamps for the preview", i, outputStampPositions.Length, true, true);

                    if (cancel)
                    {
                        m_spawnProgress = 0;
                        break;
                    }
                    m_spawnProgress = i / (float)outputStampPositions.Length;

                    StampPosition stampPosition = outputStampPositions[i];


                    //Build list of spawn chances, taking the input height into account via the curve mapping
                    List<(SpawnRule, int)> chancesList = new List<(SpawnRule, int)>();


                    // ADD MEUDES CODE save rules **************************************************>

                    // reload active rules
                    int count = 0;
                    foreach (SpawnRule sr in m_settings.m_spawnerRules)
                    {
                        sr.m_isActive = backupRules[count];
                        count++;
                    }

                    Debug.Log("For this Stamper : "+ " x:" + stampPosition.position.x + " y:" + stampPosition.position.y + " z:" + stampPosition.position.z);

                    // Select rules with position
                    
                    foreach (SpawnRule sr in m_settings.m_spawnerRules.Where(x => x.m_isActive == true))
                    {
                        // for exemple, i want Mountains only one region
                        if (stampPosition.position.x > 1000 && stampPosition.position.z > 1000 && sr.m_name == "Mountains")
                        {
                            sr.m_isActive = true;
                            Debug.Log("stamp active :" + sr.m_name +"****");

                        }
                        else if (sr.m_name == "Mountains")
                        {
                            sr.m_isActive = false;
                        }
                        else
                        {
                            Debug.Log("stamp active :" + sr.m_name);
                        }
                    }
                    //<----------------------------------------------------------***************

                    foreach (SpawnRule sr in m_settings.m_spawnerRules.Where(x => x.m_isActive == true))
                    {
                            ResourceProtoStamp resourceProtoStamp = m_settings.m_resources.m_stampDistributionPrototypes[sr.m_resourceIdx];
                            //native probability from the rule without height
                            float probability = resourceProtoStamp.m_spawnProbability;
                            //adjusting for input height, make sure that the chance is at least 0.01 so the picker has something to pick
                            probability *= Mathf.Max(0f, (resourceProtoStamp.m_inputHeightToProbabilityMapping.Evaluate(Mathf.InverseLerp(0, scalarMaxHeight, stampPosition.position.y))));
                            chancesList.Add((sr, Mathf.RoundToInt(probability * 100)));

                    }
                    // ADD MEUDES CODE save rules **************************************************>
                    //  It's very not elegant ... eurrfff, but for test
                    count = 0;
                    foreach (SpawnRule sr in m_settings.m_spawnerRules)
                    {
                        sr.m_isActive = backupRules[count];
                        count++;
                    }
                    //<----------------------------------------------------------***************

                    if (chancesList.Sum(x => x.Item2) <= 0)
                    {
                        continue;
                    }

           
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...