Jump to content

Anyone know how tree size works in treegenproperties and the treegen jsons?


Go to solution Solved by MKMoose,

Recommended Posts

Posted

Basically, some tree placers have a "MinSize", "MaxSize", and/or a "SuitabilitySizeBonus" property. The actual tree generators also all have a "sizeMultiplier" property. I was just curious what the relationship between all of the properties is for how it affects the actual size of the tree. Maybe like size = (Random(MinSize, MaxSize) + SuitabilitySizeBonus) * sizeMultiplier? Also, Ik that the tree's "size" isn't equal to the actual height of the tree in blocks.

  • Solution
Posted (edited)
18 hours ago, MdnghtEther said:

Basically, some tree placers have a "MinSize", "MaxSize", and/or a "SuitabilitySizeBonus" property. The actual tree generators also all have a "sizeMultiplier" property. I was just curious what the relationship between all of the properties is for how it affects the actual size of the tree. Maybe like size = (Random(MinSize, MaxSize) + SuitabilitySizeBonus) * sizeMultiplier? Also, Ik that the tree's "size" isn't equal to the actual height of the tree in blocks.

You've got the rough equation pretty much right. The relevant information can be found in WgenTreeSupplier.GetRandomForClimate, in TreeSupplier.cs:

float suitabilityBonus = GameMath.Clamp(0.7f - val.Value, 0f, 0.7f) * 1 / 0.7f * val.Key.SuitabilitySizeBonus;
float size = val.Key.MinSize + (float)rnd.NextDouble() * (val.Key.MaxSize - val.Key.MinSize) + suitabilityBonus;

and TreeGen.GrowTree:

this.size = treeGenParams.size * config.sizeMultiplier + config.sizeVar.nextFloat(1, random);

 

The val.Value in the suitability size bonus is the distance calculated depending on how well the tree matches its conditions (and all that is done individually for each tree variant), so that trees with perfectly matching conditions will generally be larger:

fertDist = Math.Abs(fertility - variant.FertMid) / variant.FertRange;
rainDist = Math.Abs(rain - variant.RainMid) / variant.RainRange;
tempDist = Math.Abs(temp - variant.TempMid) / variant.TempRange;
forestDist = Math.Abs(forest - variant.ForestMid) / variant.ForestRange;
heightDist = Math.Abs((y / worldheight) - variant.HeightMid) / variant.HeightRange;


double distSq =
  Math.Max(0, 1.2f * fertDist * fertDist - 1) +
  Math.Max(0, 1.2f * rainDist * rainDist - 1) +
  Math.Max(0, 1.2f * tempDist * tempDist - 1) +
  Math.Max(0, 1.2f * forestDist * forestDist - 1) +
  Math.Max(0, 1.2f * heightDist * heightDist - 1)
  ;

if (rnd.NextDouble() < distSq) continue;

float distance = GameMath.Clamp(1 - (fertDist + rainDist + tempDist + forestDist + heightDist) / 5f, 0, 1) * variant.Weight / 100f;

 

As for how that size value gets translated to actual height in blocks, or any other details, I'd need to look further into it. You can also look at the code yourself in the public GitHub repos - tree generation should be in vsessentialsmod, I think.

Edited by MKMoose
  • Amazing! 1
Posted

tysm!

4 hours ago, MKMoose said:

You've got the rough equation pretty much right. The relevant information can be found in WgenTreeSupplier.GetRandomForClimate, in TreeSupplier.cs:

float suitabilityBonus = GameMath.Clamp(0.7f - val.Value, 0f, 0.7f) * 1 / 0.7f * val.Key.SuitabilitySizeBonus;
float size = val.Key.MinSize + (float)rnd.NextDouble() * (val.Key.MaxSize - val.Key.MinSize) + suitabilityBonus;

and TreeGen.GrowTree:

this.size = treeGenParams.size * config.sizeMultiplier + config.sizeVar.nextFloat(1, random);

 

The val.Value in the suitability size bonus is the distance calculated depending on how well the tree matches its conditions (and all that is done individually for each tree variant), so that trees with perfectly matching conditions will generally be larger:

fertDist = Math.Abs(fertility - variant.FertMid) / variant.FertRange;
rainDist = Math.Abs(rain - variant.RainMid) / variant.RainRange;
tempDist = Math.Abs(temp - variant.TempMid) / variant.TempRange;
forestDist = Math.Abs(forest - variant.ForestMid) / variant.ForestRange;
heightDist = Math.Abs((y / worldheight) - variant.HeightMid) / variant.HeightRange;


double distSq =
  Math.Max(0, 1.2f * fertDist * fertDist - 1) +
  Math.Max(0, 1.2f * rainDist * rainDist - 1) +
  Math.Max(0, 1.2f * tempDist * tempDist - 1) +
  Math.Max(0, 1.2f * forestDist * forestDist - 1) +
  Math.Max(0, 1.2f * heightDist * heightDist - 1)
  ;

if (rnd.NextDouble() < distSq) continue;

float distance = GameMath.Clamp(1 - (fertDist + rainDist + tempDist + forestDist + heightDist) / 5f, 0, 1) * variant.Weight / 100f;

 

As for how that size value gets translated to actual height in blocks, or any other details, I'd need to look further into it. You can also look at the code yourself in the public GitHub repos - tree generation should be in vsessentialsmod, I think.

 

  • Cookie time 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.