102 lines
1.6 KiB
C#
102 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Waving")]
|
|
public class MegaWavingWarp : MegaWarp
|
|
{
|
|
public float amp = 0.01f;
|
|
|
|
public float flex = 1f;
|
|
|
|
public float wave = 1f;
|
|
|
|
public float phase;
|
|
|
|
public bool animate;
|
|
|
|
public float Speed = 1f;
|
|
|
|
public MegaAxis waveaxis;
|
|
|
|
private float time;
|
|
|
|
private float dy;
|
|
|
|
private int ix;
|
|
|
|
private int iz = 2;
|
|
|
|
private float t;
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Waving";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=308";
|
|
}
|
|
|
|
public static float WaveFunc(float radius, float t, float amp, float waveLen, float phase, float decay)
|
|
{
|
|
float f = (float)Math.PI * 2f * (radius / waveLen + phase);
|
|
return amp * Mathf.Sin(f) * Mathf.Exp((0f - decay) * Mathf.Abs(radius));
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float num = Mathf.Abs(2f * p[iz]);
|
|
num *= num;
|
|
p[ix] += flex * WaveFunc(p[iz], time, amp * num, wave, phase, totaldecay);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (animate)
|
|
{
|
|
float num = Time.deltaTime;
|
|
if (num == 0f)
|
|
{
|
|
num = 0.01f;
|
|
}
|
|
t += num * Speed;
|
|
phase = t;
|
|
}
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
if (wave == 0f)
|
|
{
|
|
wave = 1E-06f;
|
|
}
|
|
dy = Decay / 1000f;
|
|
totaldecay = dy + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
switch (waveaxis)
|
|
{
|
|
case MegaAxis.X:
|
|
ix = 0;
|
|
iz = 2;
|
|
break;
|
|
case MegaAxis.Y:
|
|
ix = 1;
|
|
iz = 2;
|
|
break;
|
|
case MegaAxis.Z:
|
|
ix = 2;
|
|
iz = 0;
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
}
|