private void RefreshSpline() { if (ReadObjFile && Application.isPlaying && string.IsNullOrWhiteSpace(OBJ_FILE_PATH) == false) { _followingTransform.GetComponentInChildren <MeshFilter>().mesh = ReadSimpleOBJ(OBJ_FILE_PATH); } if (ReadFromTransformAnchors) { _anchors = new Vector3[Loop ? Anchors.Length + 3 : Anchors.Length]; for (int i = 0; i < _anchors.Length; i++) { _anchors[i] = Anchors[i % Anchors.Length].transform.position; } } else { string fileName = @"spline.txt"; using (StreamReader fs = File.OpenText(fileName)) { List <Vector3> points = new List <Vector3>(); Vector3 p; string s; float x = 0f, y = 0f, z = 0f; while (fs.EndOfStream == false) { s = fs.ReadLine(); var split = s.Split(' '); p.x = float.Parse(split[0]); p.y = float.Parse(split[1]); p.z = float.Parse(split[2]); points.Add(p); x += p.x; y += p.y; z += p.z; } _anchors = points.ToArray(); // center the transform transform.position = -Vector3.right * x / points.Count - Vector3.up * y / points.Count - Vector3.forward * z / points.Count + Vector3.forward; } } _spline = new CubicBSpline(_anchors); }
public CubicBSpline(CubicBSpline toCopy) : this(toCopy._anchors) { }