133 lines
3.5 KiB
C#
133 lines
3.5 KiB
C#
using System.Threading;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Curve Sculpt")]
|
|
public class MegaCurveSculpt : MegaModifier
|
|
{
|
|
public AnimationCurve defCurveX = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 0f));
|
|
|
|
public AnimationCurve defCurveY = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 0f));
|
|
|
|
public AnimationCurve defCurveZ = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 0f));
|
|
|
|
public AnimationCurve defCurveSclX = new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(1f, 1f));
|
|
|
|
public AnimationCurve defCurveSclY = new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(1f, 1f));
|
|
|
|
public AnimationCurve defCurveSclZ = new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(1f, 1f));
|
|
|
|
public Vector3 OffsetAmount = Vector3.one;
|
|
|
|
public Vector3 ScaleAmount = Vector3.one;
|
|
|
|
private Vector3 size = Vector3.zero;
|
|
|
|
public MegaAxis offsetX;
|
|
|
|
public MegaAxis offsetY = MegaAxis.Y;
|
|
|
|
public MegaAxis offsetZ = MegaAxis.Z;
|
|
|
|
public MegaAxis scaleX;
|
|
|
|
public MegaAxis scaleY = MegaAxis.Y;
|
|
|
|
public MegaAxis scaleZ = MegaAxis.Z;
|
|
|
|
public bool symX;
|
|
|
|
public bool symY;
|
|
|
|
public bool symZ;
|
|
|
|
private static object resourceLock = new object();
|
|
|
|
public override string ModName()
|
|
{
|
|
return "CurveSculpt";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=655";
|
|
}
|
|
|
|
public override void DoWork(MegaModifiers mc, int index, int start, int end, int cores)
|
|
{
|
|
if (selection != null)
|
|
{
|
|
DoWorkWeighted(mc, index, start, end, cores);
|
|
return;
|
|
}
|
|
for (int i = start; i < end; i++)
|
|
{
|
|
sverts[i] = MapMT(i, verts[i]);
|
|
}
|
|
}
|
|
|
|
public override void DoWorkWeighted(MegaModifiers mc, int index, int start, int end, int cores)
|
|
{
|
|
for (int i = start; i < end; i++)
|
|
{
|
|
Vector3 vector = verts[i];
|
|
float num = selection[i];
|
|
if (num > 0.001f)
|
|
{
|
|
Vector3 vector2 = MapMT(i, verts[i]);
|
|
sverts[i].x = vector.x + (vector2.x - vector.x) * num;
|
|
sverts[i].y = vector.y + (vector2.y - vector.y) * num;
|
|
sverts[i].z = vector.z + (vector2.z - vector.z) * num;
|
|
}
|
|
else
|
|
{
|
|
sverts[i] = vector;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Vector3 MapMT(int i, Vector3 p)
|
|
{
|
|
float num = 0f;
|
|
p = tm.MultiplyPoint3x4(p);
|
|
num = (p.x - bbox.min.x) / size.x;
|
|
Monitor.Enter(resourceLock);
|
|
p[(int)scaleX] *= defCurveSclX.Evaluate(num) * ScaleAmount.x;
|
|
p[(int)offsetX] += defCurveX.Evaluate(num) * OffsetAmount.x;
|
|
num = (p.y - bbox.min.y) / size.y;
|
|
p[(int)scaleY] *= defCurveSclY.Evaluate(num) * ScaleAmount.y;
|
|
p[(int)offsetY] += defCurveY.Evaluate(num) * OffsetAmount.y;
|
|
num = (p.z - bbox.min.z) / size.z;
|
|
p[(int)scaleZ] *= defCurveSclZ.Evaluate(num) * ScaleAmount.z;
|
|
p[(int)offsetZ] += defCurveZ.Evaluate(num) * OffsetAmount.z;
|
|
Monitor.Exit(resourceLock);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
float num = 0f;
|
|
p = tm.MultiplyPoint3x4(p);
|
|
num = (p.x - bbox.min.x) / size.x;
|
|
p[(int)scaleX] *= defCurveSclX.Evaluate(num) * ScaleAmount.x;
|
|
p[(int)offsetX] += defCurveX.Evaluate(num) * OffsetAmount.x;
|
|
num = (p.y - bbox.min.y) / size.y;
|
|
p[(int)scaleY] *= defCurveSclY.Evaluate(num) * ScaleAmount.y;
|
|
p[(int)offsetY] += defCurveY.Evaluate(num) * OffsetAmount.y;
|
|
num = (p.z - bbox.min.z) / size.z;
|
|
p[(int)scaleZ] *= defCurveSclZ.Evaluate(num) * ScaleAmount.z;
|
|
p[(int)offsetZ] += defCurveZ.Evaluate(num) * OffsetAmount.z;
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
size = bbox.max - bbox.min;
|
|
return true;
|
|
}
|
|
}
|