How to use Animation Curves, to evaluate distance across a given radius?
Hellow~
I have this code that is working as I expected to terraform my terrain mesh.
Now recently I found out that I can use Animation Curve to cover for the operation I'm doing in InfluenceFromDist() in a more flexible manner (given Animation Curves customizable properties in the editor), so i'm in a quest to integrate those into my MorphTerrain() but so far I can't manage to make it work... unless i'm missing something important, please check the three comments below modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity * InfluenceFromDist (dist);
.
I was wondering if someone can share some insight on this matter.
// Gets influx within picel diameter, in a 0 to 1 range.
private float InfluenceFromDist (float _dist)
{
return (brushRadius / (brushRadius - (brushRadius * brushHardness))) - (_dist / (brushRadius -
(brushRadius * brushHardness)));
}
// Used to raise and depress terrain
private void MorphTerrain (Vector3 _selectedPoint, bool _raises)
{
Vector3 adaptedSelection = _selectedPoint;
adaptedSelection.y = 0.0f;
for (int i = 0; i < modifiedVerts.Length; i++)
{
Vector3 adaptedPoint = modifiedVerts[i];
adaptedPoint.y = 0.0f;
var dist = Vector3.Distance(adaptedPoint, adaptedSelection);
if (dist <= brushRadius)
{
modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity *
InfluenceFromDist (dist);
// Attemps
//modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity *
brushTypes.BrushSelected(curBrushType).Evaluate(dist);
//modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) *
brushTypes.BrushSelected(curBrushType).Evaluate(brushIntensity);
//brushTypes.BrushSelected(curBrushType).Evaluate(modifiedVerts[i].y);
modifiedVerts[i].y = Mathf.Clamp (modifiedVerts[i].y, worldGen.sowl.worldDepth,
worldGen.sowl.worldHeight);
}
}
Also, here is my brushTypes struc, if needed.
public struct Brushes
{
public enum BrushTypesForSelection { LINEAL, CURVED,
INVERSEDCURVED, FLAT }
public BrushTypesForSelection selectedBrush;
public AnimationCurve lineal;
public AnimationCurve curved;
public AnimationCurve curvedInv;
public AnimationCurve flat;
public AnimationCurve BrushSelected (BrushTypesForSelection _brushType)
{
selectedBrush = _brushType;
switch (selectedBrush)
{
case BrushTypesForSelection.LINEAL:
return lineal;
case BrushTypesForSelection.CURVED:
return curved;
case BrushTypesForSelection.INVERSEDCURVED:
return curvedInv;
case BrushTypesForSelection.FLAT:
return flat;
}
return null;
}
}
I assign curBrushType from Canvas UI options.
Cheers~
*Sorry for any grammars, non-english speaker here.. ;3!
Your answer
Follow this Question
Related Questions
I need help in "stretching an object like rubber" in Unity3D 0 Answers
How can we get mesh vertices position which has been deformed by the shader graph? 1 Answer
I need your help to make procedural floating islands! 0 Answers
Are there any good 2D prefab brushes? 0 Answers
How to increase the performance of terrain generation? Unity 2017.2.0f3 0 Answers