IceCreamYou/THREE.Terrain

Possible mismatch in randomness

Closed this issue · 1 comments

Hi,

as promised, I've begun to port this library to Typescript. I ran into a problem with scatter.js.

The function ScatterMeshes() has an option called randomness. I cannot find out the correct type for this option.

The doc for this option says:

randomness: If options.spread is a number, then this property is a
function that determines where meshes are placed. Specifically, it
returns an array of numbers, where each number is the probability that
a mesh is NOT placed on the corresponding face. Valid values include
Math.random and the return value of a call to
THREE.Terrain.ScatterHelper.

So, randomness is supposed to be a function that returns an array of numbers. How can Math.random be a valid value for this option, since Math.random returns only one number, not an array of numbers?

Can you shed some light on this, please?

The randomness option has the type () => number | () => number[]. The behavior is:

  • If spread is not a number, randomness is ignored.
  • If spread is a number and randomness is a function that returns a number, then meshes will be placed on each face if Math.random() < spread. This results in a uniformly random distribution of meshes.
  • If spread is a number and randomness is a function that returns an array of numbers, then meshes will be placed on each face if returnedArray[facePosition] < spread. This is useful to produce more organic-looking arrangements of meshes.

If the third approach is desired, ScatterHelper is useful for producing the relevant array.