/// <summary> /// ベジェデータを末尾に付け足す /// </summary> public void AddBezierData(BezierData data) { //Vector3 point = cps[cps.Length - 1].position; int oldLast = cps.Length - 1; int oldModeIndex = modes.Length - 1; int mergeOffset = 2; int dataLength = data.cps.Length; // 末端の制御点を保持 Vector3 oldLastControlPos = cps[oldLast - 1].position; Array.Resize(ref cps, cps.Length + dataLength + mergeOffset); // 結合用パスの制御点2つ追加 Array.Resize(ref modes, modes.Length + mergeOffset + data.modes.Length); // データコピー for (int i = 0; i < dataLength; i++) { int idx = oldLast + mergeOffset + i + 1; //Debug.Log("[" + i + "] cps[" + (idx) + "] data.cps["+i+"].position " + data.cps[i].position); cps[idx] = new ControlPoint(); cps[idx].position = data.cps[i].position; } for (int i = 0; i < data.modes.Length; i++) { modes[oldModeIndex + mergeOffset + i] = data.modes[i]; } cps[oldLast + 1] = new ControlPoint(); cps[oldLast + 2] = new ControlPoint(); SetControlPointMode(oldLast + 1, BezierControlPointMode.Aligned); SetControlPointMode(oldLast + 2, BezierControlPointMode.Aligned); // 間の制御点の座標を前後の制御点からの流れに沿わせる Vector3 p1 = cps[oldLast].position + (cps[oldLast].position - cps[oldLast - 1].position).normalized * 0.01f; SetControlPoint(oldLast + 1, p1); Vector3 p2 = cps[oldLast + 3].position + (cps[oldLast + 3].position - cps[oldLast + 4].position).normalized * 0.01f; SetControlPoint(oldLast + 2, p2); // 結合前の末端の制御点を復元 SetControlPoint(oldLast - 1, oldLastControlPos); }
public BezierData Copy() { BezierData b = new BezierData(); b.cps = new ControlPoint[cps.Length]; for (int i = 0; i < this.cps.Length; i++) { b.cps[i] = new ControlPoint(); b.cps[i].position.x = cps[i].position.x; b.cps[i].position.y = cps[i].position.y; b.cps[i].position.z = cps[i].position.z; } b.modes = new BezierControlPointMode[this.modes.Length]; for (int i = 0; i < this.modes.Length; i++) { b.modes[i] = this.modes[i]; } b.loop = loop; return(b); }