C# Class ProceduralGenerationOnMesh, gmap377_leathGloves_inc

Generates a poisson distribution on the mesh.
Inheritance: MonoBehaviour
Mostra file Open project: bi3mer/gmap377_leathGloves_inc

Public Properties

Property Type Description
planetName string
serializedSamplePointsByPlanet serializedInformation>.Dictionary

Public Methods

Method Description
InstantiateBasedOnPlayerLocation ( ) : void

Depending on player location, it will pull objects from the object pool and set them to appear in the chunks that the player can see. Chunks that are too far away will be deactivated and the objects sent back into the pool.

LoadPlanet ( ) : void
activateChunk ( long key ) : void

Activates the chunk by pulling from the object pool and activating those objects within the chunk.

disableChunk ( long key ) : void

Disables the chunk and send objects back into object pool.

generateAll ( ) : IEnumerator

Generates objects at eaach sample point at once.

generateInitialObjects ( ) : void

Generates the initial pool of objects to be used in chunk by chunk generation.

generateObjectsByName ( ) : void

Generates the objects in the objectsByName pool. To be used during reloading sample points from save file.

generatePoisson ( float minDistance, int newPointsCount ) : List>.Dictionary

Generates the poisson sampling points that can be used to determine where to place objects.

generateRandomPointAround ( int triangleIndex, List triangles, List uvsToTriangles, float minDistance ) : ProceduralGenerationPoint,

Generates the random point around an existing point.

getColorAtTriangle ( ProceduralGenerationPoint, point ) : Color

Gets the color at a location.

getColorChance ( Color c ) : Vector2

Gets the chance for an object to be created at a certain size based on the color of the point in heatmap.

getDensity ( Color c ) : float

Gets the density value for a color. This is determined by how dark the color is, which is determined her by how close the average of the 3 RBG values. Brightest algorithm: brightness = sqrt( .241 R2 + .691 G2 + .068 B2 )

getInterpolation ( Vector3 triangle ) : Vector3

Gets the point on the face of the triangle given a triangle represented by 3 location points.

getSize ( Vector2 colorChances ) : float

Gets the size that the object should be based on the heatmap.

inRange ( Vector2 pos1, Vector2 pos2, float minDist ) : bool

Is too close to another object. Calculated based upon isophotic distance

meshPointToUv ( ProceduralGenerationPoint, point ) : Vector2

Turns a Vector3 position on the mesh to a Vector2 uv point.

overlappingPoint ( ProceduralGenerationPoint>.Dictionary grid, ProceduralGenerationPoint, point, float minDistance, float cellSize, int triangle ) : bool

Checks the neighboring grid locations to see if there's an object that is too close to a certain point.

reconstructSamplePoints ( string name ) : void

Reconstructs the sample points after save file load.

serializeSamplePoints ( ) : void

Sets up the sample points for serialization.

toGrid ( Vector2 point, float minSize, long gridOffset ) : long

Takes in a uv point and returns a grid location. Can be used for grids of different sizes, for example the main point grid which keeps track of where each point generated is on the mesh, or for the chunk grid which divides up the mesh into sections for generation. The value returned is an long representation of a vector2. The x value is in the lower decimal places, and the y value is in the higher decimal places. How far apart the two numbers are is determined by the gridOffset. For example, if the gridOffset is 1000, that is, there can be up to 999 x values, then if x is 30, and y is 89, the value returned will be 89030.

waitForLoad ( ) : IEnumerator

Waits for loading of the save file so that on continue, it will wait until the file has been loaded before the procedural generation will be set off.

Private Methods

Method Description
Start ( ) : void
Update ( ) : void

Method Details

InstantiateBasedOnPlayerLocation() public method

Depending on player location, it will pull objects from the object pool and set them to appear in the chunks that the player can see. Chunks that are too far away will be deactivated and the objects sent back into the pool.
public InstantiateBasedOnPlayerLocation ( ) : void
return void

LoadPlanet() public method

public LoadPlanet ( ) : void
return void

activateChunk() public method

Activates the chunk by pulling from the object pool and activating those objects within the chunk.
public activateChunk ( long key ) : void
key long All sample points are hashed into chunks by the key. So this key will give a list of objects within a chunk.
return void

disableChunk() public method

Disables the chunk and send objects back into object pool.
public disableChunk ( long key ) : void
key long Key.
return void

generateAll() public method

Generates objects at eaach sample point at once.
public generateAll ( ) : IEnumerator
return IEnumerator

generateInitialObjects() public method

Generates the initial pool of objects to be used in chunk by chunk generation.
public generateInitialObjects ( ) : void
return void

generateObjectsByName() public method

Generates the objects in the objectsByName pool. To be used during reloading sample points from save file.
public generateObjectsByName ( ) : void
return void

generatePoisson() public method

Generates the poisson sampling points that can be used to determine where to place objects.
public generatePoisson ( float minDistance, int newPointsCount ) : List>.Dictionary
minDistance float Minimum distance.
newPointsCount int Number of new points that should be generated around an existing point.
return List>.Dictionary

generateRandomPointAround() public method

Generates the random point around an existing point.
public generateRandomPointAround ( int triangleIndex, List triangles, List uvsToTriangles, float minDistance ) : ProceduralGenerationPoint,
triangleIndex int Triangle index.
triangles List Triangles.
uvsToTriangles List Uvs to triangles.
minDistance float Minimum distance.
return ProceduralGenerationPoint,

getColorAtTriangle() public method

Gets the color at a location.
public getColorAtTriangle ( ProceduralGenerationPoint, point ) : Color
point ProceduralGenerationPoint, Point.
return Color

getColorChance() public method

Gets the chance for an object to be created at a certain size based on the color of the point in heatmap.
public getColorChance ( Color c ) : Vector2
c Color A color from the heatmap, c.
return Vector2

getDensity() public method

Gets the density value for a color. This is determined by how dark the color is, which is determined her by how close the average of the 3 RBG values. Brightest algorithm: brightness = sqrt( .241 R2 + .691 G2 + .068 B2 )
public getDensity ( Color c ) : float
c Color C.
return float

getInterpolation() public method

Gets the point on the face of the triangle given a triangle represented by 3 location points.
public getInterpolation ( Vector3 triangle ) : Vector3
triangle Vector3 A location.
return Vector3

getSize() public method

Gets the size that the object should be based on the heatmap.
public getSize ( Vector2 colorChances ) : float
colorChances Vector2 There are 2 color chances passed in. If the random number is under the first threshold, then a small object is generated, /// if it's under the second then a medium object is generated. Otherwise, a large object is generated.
return float

inRange() public method

Is too close to another object. Calculated based upon isophotic distance
public inRange ( Vector2 pos1, Vector2 pos2, float minDist ) : bool
pos1 Vector2 Pos1.
pos2 Vector2 Pos2.
minDist float
return bool

meshPointToUv() public method

Turns a Vector3 position on the mesh to a Vector2 uv point.
public meshPointToUv ( ProceduralGenerationPoint, point ) : Vector2
point ProceduralGenerationPoint, Point.
return Vector2

overlappingPoint() public method

Checks the neighboring grid locations to see if there's an object that is too close to a certain point.
public overlappingPoint ( ProceduralGenerationPoint>.Dictionary grid, ProceduralGenerationPoint, point, float minDistance, float cellSize, int triangle ) : bool
grid ProceduralGenerationPoint>.Dictionary Grid.
point ProceduralGenerationPoint, Point.
minDistance float Minimum distance.
cellSize float Cell size.
triangle int Triangle.
return bool

reconstructSamplePoints() public method

Reconstructs the sample points after save file load.
public reconstructSamplePoints ( string name ) : void
name string Name of planet.
return void

serializeSamplePoints() public method

Sets up the sample points for serialization.
public serializeSamplePoints ( ) : void
return void

toGrid() public method

Takes in a uv point and returns a grid location. Can be used for grids of different sizes, for example the main point grid which keeps track of where each point generated is on the mesh, or for the chunk grid which divides up the mesh into sections for generation. The value returned is an long representation of a vector2. The x value is in the lower decimal places, and the y value is in the higher decimal places. How far apart the two numbers are is determined by the gridOffset. For example, if the gridOffset is 1000, that is, there can be up to 999 x values, then if x is 30, and y is 89, the value returned will be 89030.
public toGrid ( Vector2 point, float minSize, long gridOffset ) : long
point Vector2 Point.
minSize float Minimum size.
gridOffset long Grid offset.
return long

waitForLoad() public method

Waits for loading of the save file so that on continue, it will wait until the file has been loaded before the procedural generation will be set off.
public waitForLoad ( ) : IEnumerator
return IEnumerator

Property Details

planetName public_oe property

public string planetName
return string

serializedSamplePointsByPlanet public_oe static_oe property

public static Dictionary serializedSamplePointsByPlanet
return serializedInformation>.Dictionary