public override void Apply (Path p, ModifierData source) {
//System.DateTime startTime = System.DateTime.UtcNow;
if (iterations <= 0) {
return;
}
if (nodes == null) {
nodes = new List<Vector3> (p.vectorPath.Count);
} else {
nodes.Clear ();
}
nodes.AddRange (p.vectorPath);
// = new List<Vector3> (p.vectorPath);
for (int it=0;it<iterations;it++) {
if (subdivideEveryIter && it != 0) {
if (nodes.Capacity < nodes.Count*3) {
nodes.Capacity = nodes.Count*3;
}
int preLength = nodes.Count;
for (int j=0;j<preLength-1;j++) {
nodes.Add (Vector3.zero);
nodes.Add (Vector3.zero);
}
for (int j=preLength-1;j > 0;j--) {
Vector3 p1 = nodes[j];
Vector3 p2 = nodes[j+1];
nodes[j*3] = nodes[j];
if (j != preLength-1) {
nodes[j*3+1] = Vector3.Lerp (p1,p2,0.33F);
nodes[j*3+2] = Vector3.Lerp (p1,p2,0.66F);
}
}
}
int i = 0;
while (i < nodes.Count-2) {
Vector3 start = nodes[i];
Vector3 end = nodes[i+2];
/*if (i == 0 && exactStartAndEnd) {
if (overrideClampedExacts) {
start = p.originalStartPoint;
} else {
start = p.startPoint;
}
}
if (i == nodes.Count-3 && exactStartAndEnd) {
if (overrideClampedExacts) {
end = p.originalEndPoint;
} else {
end = p.endPoint;
}
}*/
//if (ValidateLine (nodes[i],nodes[i+2],start,end)) {
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch ();
watch.Start ();
if (ValidateLine (null,null,start,end)) {
//Debug.Log ("+++ Simplified "+i+" +++");
//Debug.DrawLine (start+raycastOffset,end+raycastOffset,new Color (1,0,0.5F));
nodes.RemoveAt (i+1);
//i++;
} else {
//Debug.DrawLine (start,end,Color.red);
i++;
}
watch.Stop ();
//Debug.Log ("Validate Line Took "+(watch.ElapsedTicks * 0.0001) +" Magnitude: "+(start-end).magnitude);
}
}
//ValidateLine (null,null,nodes[0],nodes[nodes.Count-1]);
p.vectorPath.Clear ();
p.vectorPath.AddRange (nodes);
//System.DateTime endTime2 = System.DateTime.UtcNow;
//float theTime2 = (endTime2-startTime).Ticks*0.0001F;
//Debug.Log ("Raycast Modifier : Time "+theTime2.ToString ("0.00"));
/*p.vectorPath = new Vector3[p.path.Length];
for (int i=0;i<p.path.Length;i++) {
Vector3 point = p.path[i].position;
if (i == 0 && exactStartAndEnd) {
if (overrideClampedExacts) {
point = p.originalStartPoint;
} else {
point = p.startPoint;
}
} else if (i == p.path.Length-1 && exactStartAndEnd) {
if (overrideClampedExacts) {
point = p.originalEndPoint;
} else {
point = p.endPoint;
}
}
p.vectorPath[i] = point;
}*/
}