59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Mtree
|
|
{
|
|
public class GrowFunction : TreeFunctionAsset
|
|
{
|
|
public float length = 10f;
|
|
|
|
public AnimationCurve lengthCurve = AnimationCurve.Linear(0f, 1f, 1f, 0.8f);
|
|
|
|
public float resolution = 1f;
|
|
|
|
public float splitProba = 0.1f;
|
|
|
|
public float splitAngle = 0.5f;
|
|
|
|
public int maxSplits = 2;
|
|
|
|
public AnimationCurve radius = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f);
|
|
|
|
public AnimationCurve splitProbaCurve = AnimationCurve.Linear(0f, 0.5f, 1f, 1f);
|
|
|
|
public float splitRadius = 0.8f;
|
|
|
|
public float randomness = 0.25f;
|
|
|
|
public float upAttraction = 0.5f;
|
|
|
|
public float gravityStrength = 0.1f;
|
|
|
|
public override void Init(TreeFunctionAsset parent, bool preserveSettings = false)
|
|
{
|
|
base.Init(parent);
|
|
base.name = "Grow";
|
|
if (!preserveSettings)
|
|
{
|
|
Keyframe[] keys = new Keyframe[2]
|
|
{
|
|
new Keyframe(0f, 1f, 0f, 0f),
|
|
new Keyframe(1f, 0f, -0.5f, -1f)
|
|
};
|
|
radius = new AnimationCurve(keys);
|
|
}
|
|
}
|
|
|
|
public override void DrawProperties()
|
|
{
|
|
}
|
|
|
|
public override void Execute(MTree tree)
|
|
{
|
|
base.Execute(tree);
|
|
Random.InitState(seed);
|
|
int selection = ((!(parent == null)) ? parent.id : 0);
|
|
tree.Grow(length, lengthCurve, resolution, splitProba, splitProbaCurve, splitAngle, maxSplits, selection, id, randomness, radius, splitRadius, upAttraction, gravityStrength, 0f, 0.001f);
|
|
}
|
|
}
|
|
}
|