public SplineSection(SplineSection input) { startPoint = input.startPoint; startTangent = input.startTangent; endPoint = input.endPoint; endTangent = input.endTangent; parent = input.parent; }
public void ResetAllSegments() { for (int i = 0; i < splineSegments.Length; i++) { splineSegments[i].ResetSegment(); splineSegments[i].SetContinuity(enforceContinuousSpline); splineSegments[i].SetSegmentStatus(); } splineSegments = null; splineSegments = new SplineSection[1]; splineSegments[0] = new SplineSection(transform); splineSegments[0].endTangent = new Vector3(1f, 0f, 1f); splineSegments[0].endPoint = new Vector3(0.5f, 0f, 0.5f); splineSegments[0].startPoint = new Vector3(-0.5f, 0f, -0.5f); splineSegments[0].startTangent = new Vector3(-1f, 0f, -1f); }
// Flatten a specified axis public void Flatten(string axis) { if (axis == "X") { for (int i = 0; i < splineSegments.Length; i++) { SplineSection temp = splineSegments[i]; temp.startPoint = new Vector3(0f, temp.startPoint.y, temp.startPoint.z); temp.startTangent = new Vector3(0f, temp.startTangent.y, temp.startTangent.z); temp.endPoint = new Vector3(0f, temp.endPoint.y, temp.endPoint.z); temp.endTangent = new Vector3(0f, temp.endTangent.y, temp.endTangent.z); splineSegments[i] = new SplineSection(temp); } } if (axis == "Y") { for (int i = 0; i < splineSegments.Length; i++) { SplineSection temp = splineSegments[i]; temp.startPoint = new Vector3(temp.startPoint.x, 0f, temp.startPoint.z); temp.startTangent = new Vector3(temp.startPoint.x, 0f, temp.startTangent.z); temp.endPoint = new Vector3(temp.endPoint.x, 0f, temp.endPoint.z); temp.endTangent = new Vector3(temp.endTangent.x, 0f, temp.endTangent.z); splineSegments[i] = new SplineSection(temp); } } if (axis == "Z") { for (int i = 0; i < splineSegments.Length; i++) { SplineSection temp = splineSegments[i]; temp.startPoint = new Vector3(temp.startPoint.x, temp.startPoint.y, 0f); temp.startTangent = new Vector3(temp.startPoint.x, temp.startTangent.y, 0f); temp.endPoint = new Vector3(temp.endPoint.x, temp.endPoint.y, 0f); temp.endTangent = new Vector3(temp.endTangent.x, temp.endTangent.y, 0f); splineSegments[i] = new SplineSection(temp); } } }
// Extend the length of the spline by one in the Backward direction public void AddNewStart() { // Create a temp array of Spline Sections and populate it with the current content of the spline Segments array SplineSection[] temp = new SplineSection[splineSegments.Length]; for (int i = 0; i < temp.Length; i++) { temp[i] = new SplineSection(splineSegments[i]); } // Unset and reinitialize the current array splineSegments = null; splineSegments = new SplineSection[temp.Length + 1]; // Get the old array contents from the temp buffer for (int i = 0; i < temp.Length; i++) { splineSegments[i + 1] = new SplineSection(temp[i]); } //int leng = 0; // Create a new SplineSection and set it based on the current StartPoint splineSegments[0] = new SplineSection(splineSegments[1]); splineSegments[0].endPoint = new Vector3(splineSegments[1].startPoint.x, splineSegments[1].startPoint.y, splineSegments[1].startPoint.z); splineSegments[0].endTangent = new Vector3(splineSegments[1].startTangent.x, splineSegments[1].startTangent.y, splineSegments[1].startTangent.z); // The direction and startTangent of the new segment should be based off of the normalized local space startTangent of the next segment Vector3 normtan = new Vector3(splineSegments[1].startPoint.x - -splineSegments[1].startTangent.x, splineSegments[1].startPoint.y - -splineSegments[1].startTangent.y, splineSegments[1].startPoint.z - -splineSegments[1].startTangent.z); normtan.Normalize(); normtan *= Vector3.Distance(splineSegments[1].startPoint, splineSegments[1].endPoint); splineSegments[0].startPoint = new Vector3(splineSegments[0].endPoint.x + normtan.x, splineSegments[0].endPoint.y + normtan.y, splineSegments[0].endPoint.z + normtan.z); normtan *= 0.25f; splineSegments[0].startTangent = new Vector3(splineSegments[0].startPoint.x + normtan.x, splineSegments[0].startPoint.y + normtan.y, splineSegments[0].startPoint.z + normtan.z); // Set status of all spline segments UpdateSegments(); }