using UnityEngine; [AddComponentMenu("Modifiers/Point Cache Ref")] public class MegaPointCacheRef : MegaModifier { public float time; public bool animated; public float speed = 1f; public float maxtime = 1f; public MegaRepeatMode LoopMode = MegaRepeatMode.PingPong; public MegaInterpMethod interpMethod = MegaInterpMethod.Linear; public MegaPointCache source; public float weight = 1f; public MegaBlendAnimMode blendMode = MegaBlendAnimMode.Additive; private float t; private float alpha; private float dalpha; private int sindex; private int sindex1; public override string ModName() { return "Point Cache Ref"; } public override string GetHelpURL() { return "?page_id=1335"; } private void LinearAbs(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { Vector3 vector = source.Verts[i].points[sindex]; Vector3 vector2 = source.Verts[i].points[sindex1]; vector.x += (vector2.x - vector.x) * dalpha; vector.y += (vector2.y - vector.y) * dalpha; vector.z += (vector2.z - vector.z) * dalpha; for (int j = 0; j < source.Verts[i].indices.Length; j++) { sverts[source.Verts[i].indices[j]] = vector; } } } private void LinearAbsWeighted(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { Vector3 vector = source.Verts[i].points[sindex]; Vector3 vector2 = source.Verts[i].points[sindex1]; vector.x += (vector2.x - vector.x) * dalpha; vector.y += (vector2.y - vector.y) * dalpha; vector.z += (vector2.z - vector.z) * dalpha; float num = mc.selection[source.Verts[i].indices[0]]; vector2 = verts[source.Verts[i].indices[0]]; vector = vector2 + (vector - vector2) * num; for (int j = 0; j < source.Verts[i].indices.Length; j++) { sverts[source.Verts[i].indices[j]] = vector; } } } private void LinearRel(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { int num = source.Verts[i].indices[0]; Vector3 vector = mc.verts[num]; Vector3 vector2 = source.Verts[i].points[sindex]; Vector3 vector3 = source.Verts[i].points[sindex1]; vector2.x += (vector3.x - vector2.x) * dalpha - vector.x; vector2.y += (vector3.y - vector2.y) * dalpha - vector.y; vector2.z += (vector3.z - vector2.z) * dalpha - vector.z; vector3 = verts[source.Verts[i].indices[0]]; vector2.x = vector3.x + vector2.x * weight; vector2.y = vector3.y + vector2.y * weight; vector2.z = vector3.z + vector2.z * weight; for (int j = 0; j < source.Verts[i].indices.Length; j++) { int num2 = source.Verts[i].indices[j]; sverts[num2] = vector2; } } } private void LinearRelWeighted(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { int num = source.Verts[i].indices[0]; Vector3 vector = verts[num]; Vector3 vector2 = source.Verts[i].points[sindex]; Vector3 vector3 = source.Verts[i].points[sindex1]; vector2.x += (vector3.x - vector2.x) * dalpha - vector.x; vector2.y += (vector3.y - vector2.y) * dalpha - vector.y; vector2.z += (vector3.z - vector2.z) * dalpha - vector.z; float num2 = mc.selection[source.Verts[i].indices[0]] * weight; vector3 = verts[source.Verts[i].indices[0]]; vector2.x = vector3.x + vector2.x * num2; vector2.y = vector3.y + vector2.y * num2; vector2.z = vector3.z + vector2.z * num2; for (int j = 0; j < source.Verts[i].indices.Length; j++) { int num3 = source.Verts[i].indices[j]; sverts[num3] = vector2; } } } private void NoInterpAbs(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { Vector3 vector = source.Verts[i].points[sindex]; for (int j = 0; j < source.Verts[i].indices.Length; j++) { sverts[source.Verts[i].indices[j]] = vector; } } } private void NoInterpAbsWeighted(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { Vector3 vector = source.Verts[i].points[sindex]; float num = mc.selection[source.Verts[i].indices[0]] * weight; Vector3 vector2 = verts[source.Verts[i].indices[0]]; vector = vector2 + (vector - vector2) * num; for (int j = 0; j < source.Verts[i].indices.Length; j++) { sverts[source.Verts[i].indices[j]] = vector; } } } private void NoInterpRel(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { int num = source.Verts[i].indices[0]; Vector3 vector = source.Verts[i].points[sindex] - verts[num]; Vector3 vector2 = verts[source.Verts[i].indices[0]]; vector.x = vector2.x + vector.x * weight; vector.y = vector2.y + vector.y * weight; vector.z = vector2.z + vector.z * weight; for (int j = 0; j < source.Verts[i].indices.Length; j++) { int num2 = source.Verts[i].indices[j]; sverts[num2] = vector; } } } private void NoInterpRelWeighted(MegaModifiers mc, int start, int end) { for (int i = start; i < end; i++) { int num = source.Verts[i].indices[0]; Vector3 vector = source.Verts[i].points[sindex] - verts[num]; float num2 = mc.selection[source.Verts[i].indices[0]] * weight; Vector3 vector2 = verts[source.Verts[i].indices[0]]; vector = vector2 + (vector - vector2) * num2; for (int j = 0; j < source.Verts[i].indices.Length; j++) { int num3 = source.Verts[i].indices[j]; sverts[num3] = vector; } } } public override void Modify(MegaModifiers mc) { if (source != null && source.Verts != null) { switch (interpMethod) { case MegaInterpMethod.Linear: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, 0, source.Verts.Length); break; } break; case MegaInterpMethod.Bez: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, 0, source.Verts.Length); break; } break; case MegaInterpMethod.None: switch (blendMode) { case MegaBlendAnimMode.Additive: NoInterpRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: NoInterpAbs(mc, 0, source.Verts.Length); break; } break; } } else { for (int i = 0; i < verts.Length; i++) { sverts[i] = verts[i]; } } } public void ModifyInstance(MegaModifiers mc, float itime) { if (source != null && source.Verts != null) { switch (LoopMode) { case MegaRepeatMode.Loop: t = Mathf.Repeat(itime, maxtime); break; case MegaRepeatMode.PingPong: t = Mathf.PingPong(itime, maxtime); break; case MegaRepeatMode.Clamp: t = Mathf.Clamp(itime, 0f, maxtime); break; } alpha = t / maxtime; float num = (float)(source.Verts[0].points.Length - 1) * alpha; sindex = (int)num; dalpha = num - (float)sindex; if (sindex == source.Verts[0].points.Length - 1) { sindex1 = sindex; dalpha = 0f; } else { sindex1 = sindex + 1; } switch (interpMethod) { case MegaInterpMethod.Linear: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, 0, source.Verts.Length); break; } break; case MegaInterpMethod.Bez: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, 0, source.Verts.Length); break; } break; case MegaInterpMethod.None: switch (blendMode) { case MegaBlendAnimMode.Additive: NoInterpRel(mc, 0, source.Verts.Length); break; case MegaBlendAnimMode.Replace: NoInterpAbs(mc, 0, source.Verts.Length); break; } break; } } else { for (int i = 0; i < verts.Length; i++) { sverts[i] = verts[i]; } } } public void SetAnim(float _t) { time = _t; t = _t; } public override bool ModLateUpdate(MegaModContext mc) { if (!Prepare(mc)) { return false; } if (animated) { time += Time.deltaTime * speed; } switch (LoopMode) { case MegaRepeatMode.Loop: t = Mathf.Repeat(time, maxtime); break; case MegaRepeatMode.PingPong: t = Mathf.PingPong(time, maxtime); break; case MegaRepeatMode.Clamp: t = Mathf.Clamp(time, 0f, maxtime); break; } alpha = t / maxtime; float num = (float)(source.Verts[0].points.Length - 1) * alpha; sindex = (int)num; dalpha = num - (float)sindex; if (sindex == source.Verts[0].points.Length - 1) { sindex1 = sindex; dalpha = 0f; } else { sindex1 = sindex + 1; } return true; } public override bool Prepare(MegaModContext mc) { if (source != null && source.Verts != null && source.Verts.Length > 0 && source.Verts[0].indices != null && source.Verts[0].indices.Length > 0) { return true; } return false; } public override void DoWork(MegaModifiers mc, int index, int start, int end, int cores) { ModifyCompressedMT(mc, index, cores); } public void ModifyCompressedMT(MegaModifiers mc, int tindex, int cores) { if (!(source != null) || source.Verts == null) { return; } int num = source.Verts.Length / cores; int num2 = tindex * num; int end = num2 + num; if (tindex == cores - 1) { end = source.Verts.Length; } switch (interpMethod) { case MegaInterpMethod.Linear: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, num2, end); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, num2, end); break; } break; case MegaInterpMethod.Bez: switch (blendMode) { case MegaBlendAnimMode.Additive: LinearRel(mc, num2, end); break; case MegaBlendAnimMode.Replace: LinearAbs(mc, num2, end); break; } break; case MegaInterpMethod.None: switch (blendMode) { case MegaBlendAnimMode.Additive: NoInterpRel(mc, num2, end); break; case MegaBlendAnimMode.Replace: NoInterpAbs(mc, num2, end); break; } break; } } }