public void SetControlPointMode (int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; if (loop) { if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; _modes[modeIndex] = mode; if (_loop) { if (modeIndex == 0) { _modes[_modes.Count - 1] = mode; } else if (modeIndex == _modes.Count - 1) { _modes[0] = mode; } } EnforceMode(index); }
public void set_control_point_mode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; _modes[modeIndex] = mode; if (_loop) { if (modeIndex == 0) { _modes[_modes.Length - 1] = mode; } else if (modeIndex == _modes.Length - 1) { _modes[0] = mode; } } _enforce_mode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; if (loop) { if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int num = (index + 1) / 3; this.modes[num] = mode; if (this.loop) { if (num == 0) { this.modes[this.modes.Length - 1] = mode; } else if (num == (this.modes.Length - 1)) { this.modes[0] = mode; } } this.EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { modes[(index + 1) / 3] = mode; if (loop) { if (index == 0 || index == 1) { modes[modes.Length - 1] = mode; } else if (index == ControlPointCount - 1 || index == ControlPointCount - 2) { modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / curveSegments; modes[modeIndex] = mode; if (loop) { // Ensure the endpoints' modes match. if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = GetModeIndex(index); modes[modeIndex] = mode; if (LoopField) { if (modeIndex == 0) { modes[modes.Count - 1] = mode; } else if (modeIndex == modes.Count - 1) { modes[0] = mode; } } EnforceMode(index); }
private void DrawSelectedPointInspector() { if (_selectedIndex < 0 || _selectedIndex >= _spline.ControlPointsCount) { return; } //Position GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", _spline.GetControlPoint(_selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); _spline.SetControlPoint(_selectedIndex, point); EditorUtility.SetDirty(_spline); } //Rotation if (_selectedIndex % 3 == 0) { EditorGUI.BeginChangeCheck(); Vector3 rotation = EditorGUILayout.Vector3Field("Rotation", _spline.GetRotationPoint(_selectedIndex / 3)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Rotate Point"); _spline.SetRotationPoint(rotation, _selectedIndex / 3); EditorUtility.SetDirty(_spline); } } //Control point mode EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(_selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Point Mode"); _spline.SetControlPointMode(_selectedIndex, mode); EditorUtility.SetDirty(_spline); } }
private void EnforceMode(int index) { int modeIndex = (index + 1) / 3; BezierControlPointMode mode = modes[modeIndex]; if (mode == BezierControlPointMode.Free || !loop && (modeIndex == 0 || modeIndex == modes.Length - 1)) { return; } int middleIndex = modeIndex * 3; int fixedIndex, enforcedIndex; if (index <= middleIndex) { fixedIndex = middleIndex - 1; if (fixedIndex < 0) { fixedIndex = points.Length - 2; } enforcedIndex = middleIndex + 1; if (enforcedIndex >= points.Length) { enforcedIndex = 1; } } else { fixedIndex = middleIndex + 1; if (fixedIndex >= points.Length) { fixedIndex = 1; } enforcedIndex = middleIndex - 1; if (enforcedIndex < 0) { enforcedIndex = points.Length - 2; } } Vector3 middle = points[middleIndex]; Vector3 enforcedTangent = middle - points[fixedIndex]; if (mode == BezierControlPointMode.Aligned) { enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]); } points[enforcedIndex] = middle + enforcedTangent; }
private void DeleteFirstCurve() { var tempPoints = new Vector3[points.Length - 3]; Array.Copy(points, 3, tempPoints, 0, tempPoints.Length); points = tempPoints; var tempModes = new BezierControlPointMode[modes.Length - 1]; Array.Copy(modes, 1, tempModes, 0, tempModes.Length); modes = tempModes; var oldLength = segmentLengths[0]; var tempSegmentLengths = new float[segmentLengths.Length - 1]; Array.Copy(segmentLengths, 1, tempSegmentLengths, 0, tempSegmentLengths.Length); segmentLengths = tempSegmentLengths; curveLength -= oldLength; }
/// <summary> /// Draws the inspector for the selected point /// </summary> private void DrawSelectedPointEditor() { GUILayout.Label("Selected Point (" + selectedIndex + ")", EditorStyles.boldLabel); // Position EditorGUI.BeginChangeCheck(); Vector3 _point = EditorGUILayout.Vector3Field("Position", spline[selectedIndex]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline[selectedIndex] = _point; Undo.FlushUndoRecordObjects(); } // ControlPointMode EditorGUI.BeginChangeCheck(); BezierControlPointMode _mode = (BezierControlPointMode)EditorGUILayout.EnumPopup( "Mode", spline.GetControlPointMode(selectedIndex) ); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Control Point Mode change"); EditorUtility.SetDirty(spline); spline.SetControlPointMode(selectedIndex, _mode); Undo.FlushUndoRecordObjects(); } // Remove button if (GUILayout.Button("Remove point")) { Undo.RecordObject(spline, "Removed curve"); EditorUtility.SetDirty(spline); spline.RemoveCurve(selectedIndex); Undo.FlushUndoRecordObjects(); } }
public void AddNode(int index) { int nodeIndex = index * 3; Vector3 point = GetPoint(nodeIndex); Vector3 direction; if (index > 0) { direction = GetPoint(nodeIndex) - GetPoint(nodeIndex - 1); } else { direction = GetPoint(nodeIndex + 1) - GetPoint(nodeIndex); } direction *= fixedVelocityOnNewNode; points.InsertRange(nodeIndex + 1, new Vector3[3]); point += direction; points[nodeIndex + 2] = point; point += direction; points[nodeIndex + 1] = point; point += direction; points[nodeIndex + 3] = point; transformNodes.InsertRange(nodeIndex + 1, new TransformNode[] { new TransformNode(), new TransformNode(), new TransformNode() }); BezierControlPointMode currentIndexMode = modes[index]; modes.Insert(index, new BezierControlPointMode()); modes[index] = currentIndexMode; EnforceMode(index); SetControlPoint((index + 1) * 3, GetPoint((index + 1) * 3)); if (loop) { points[points.Count - 1] = points[0]; modes[modes.Count - 1] = modes[0]; EnforceMode(0); } }
/// <summary> /// 将当前所选择点的模式改为前面所选择的模式 /// </summary> /// <param name="index">所选择点的索引</param> /// <param name="mode">前面所选择的模式</param> public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; //为形成线圈,正确执行循环,确保第一个和最后一个点的模式在循环中保持相同 if (loop) { if (modeIndex == 0) { modes[modes.Length - 1] = mode; } } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } EnforceMode(index); }
//Mutators public void AddCurve() { if (!m_IsInitialized) { Initizalize(); } Vector3 lastPoint = new Vector3(); BezierControlPointMode lastMode = BezierControlPointMode.Free; if (m_Points.Count > 0) { lastPoint = m_Points[m_Points.Count - 1]; lastMode = m_Modes[m_Modes.Count - 1]; } //Add points m_Points.Add(new Vector3(lastPoint.x + 1.0f, 0.0f, 0.0f)); m_Points.Add(new Vector3(lastPoint.x + 2.0f, 0.0f, 0.0f)); m_Points.Add(new Vector3(lastPoint.x + 3.0f, 0.0f, 0.0f)); //Add a control mode m_Modes.Add(lastMode); //First curve: add extra stuff if (m_Points.Count == 3) { m_Points.Add(new Vector3(lastPoint.x + 4.0f, 0.0f, 0.0f)); m_Modes.Add(lastMode); } //Enforce the mode on the last point EnforceMode(m_Points.Count - 4); if (m_Loop) { m_Points[m_Points.Count - 1] = m_Points[0]; m_Modes[m_Modes.Count - 1] = m_Modes[0]; EnforceMode(0); } }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; _modes[modeIndex] = mode; // Ensure that first and last modes remain equal for loops. if (_loop) { if (modeIndex == 0) { _modes[_modes.Length - 1] = mode; } else if (modeIndex == _modes.Length - 1) { _modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; _modes[modeIndex] = mode; //Keep modes equal if the spline is set to be a loop. if (_loop) { if (modeIndex == 0) { _modes[_modes.Length - 1] = mode; } else if (modeIndex == _modes.Length - 1) { _modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; if (loop) { // Set mode of first point same as last / last same as first if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { /* To correctly enforce the loop, we need to make a few more changes to BezierSpline. * First, SetControlPointMode needs to make sure that the first and last mode remain equal in case of a loop. */ int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; if (loop) { if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode) EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); } }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; modes[modeIndex] = mode; // Ensure 1st and last mode remain equal when loop is true if (loop) { if (modeIndex == 0) { modes[modes.Length - 1] = mode; } else if (modeIndex == modes.Length - 1) { modes[0] = mode; } } EnforceMode(index); }
/// <summary> /// 当点被移动或模式被改变。约束会被执行,(所以真正目的是什么?) /// </summary> /// <param name="index"></param> private void EnforceMode(int index) { int modeIndex = (index + 1) / 3; BezierControlPointMode mode = modes[modeIndex]; //当mode的模式是Free或selectIndex=-1(未选中任何点)或是模式数组的最后一个,直接返回 if (mode == BezierControlPointMode.Free || modeIndex == 0 || modeIndex == modes.Length - 1) { return; } //index 0 1 2 3 4 5 6 //modeIndex 0 0 1 1 1 2 2 //middleIndex 0 0 3 3 3 6 6 int middleIndex = modeIndex * 3; int fixedIndex, enforcedIndex; if (index <= middleIndex) { fixedIndex = middleIndex - 1; enforcedIndex = middleIndex + 1; } else { fixedIndex = middleIndex + 1; enforcedIndex = middleIndex - 1; } //拿4举例,index=4,middleIndex=3,fixedIndex=4,enforcedIndex=2;(2,3,4的中间点是3) //先求第四个点到第三个点的向量(middle-points[fixedIndex]) //为了保证两条曲线的连接点(index为3的点)处斜率一致,第三个点到第二个点的向量应该要是前面求得的向量 //因此第二个点是第三个点middle加上前面求得的向量 Vector3 middle = points[middleIndex]; Vector3 enforcedTangent = middle - points[fixedIndex]; //调整模式下,确定新的正切线与旧的有相同的长度 if (mode == BezierControlPointMode.Aligned) { enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]); } points[enforcedIndex] = middle + enforcedTangent; }
//커브 추가 public void AddCurve() { //마지막 점의 위치 Vector3 lastPoint = this.points[this.points.Count - 1]; //마지막 점의 컨트롤 모드 BezierControlPointMode lastMode = this.controlModes[this.controlModes.Count - 1]; //점 3개 추가 lastPoint += Vector3.right; this.points.Add(lastPoint); lastPoint += Vector3.right; this.points.Add(lastPoint); lastPoint += Vector3.right; this.points.Add(lastPoint); //커브가 추가되면 포인트 모드도 추가 this.controlModes.Add(lastMode); //마지막 모드와 같게... //점의 위치 변경에 따른 강제 셋팅 EnforceMode(points.Count - 4); //마직막으로 추가된 Curve 의 시작인덱스 강제 셋팅 }
private void _draw_selected_point_inspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", _spline.get_control_point(_selected_index)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); _spline.set_control_point(_selected_index, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", _spline.get_control_point_mode(_selected_index)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Point Mode"); _spline.set_control_point_mode(_selected_index, mode); EditorUtility.SetDirty(_spline); } }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.points[selectedIndex].position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(pathArray, "Move Point"); EditorUtility.SetDirty(pathArray); spline.points[selectedIndex].MovePoint(point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.points[selectedIndex].controlPointMode); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(pathArray, "Change Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(pathArray); } }
public void SwapNodes(int from, int to) { Vector3[] fromPoints = points.GetRange(from, 3).ToArray(); Vector3[] toPoints = points.GetRange(to, 3).ToArray(); TransformNode[] fromTnode = transformNodes.GetRange(from, 3).ToArray(); TransformNode[] toTnode = transformNodes.GetRange(to, 3).ToArray(); BezierControlPointMode fromMode = modes[from]; BezierControlPointMode toMode = modes[to]; for (int i = from; i < 3; i++) { points[i] = toPoints[i]; transformNodes[i] = toTnode[i]; } for (int i = to; i < 3; i++) { points[i] = fromPoints[i]; transformNodes[i] = fromTnode[i]; } modes[from] = toMode; modes[to] = fromMode; }
private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", bezierSpline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(bezierSpline, "Move " + bezierSpline.name + " point " + selectedIndex); EditorUtility.SetDirty(bezierSpline); bezierSpline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", bezierSpline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(bezierSpline, "Changed " + bezierSpline.name + " restraint " + selectedIndex); bezierSpline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(bezierSpline); } }
private void EnforceMode(int i) { int modeIndex = (i + 1) / 3; BezierControlPointMode mode = modes[modeIndex]; // Nothing to enforce for free mode, and for when we're at the end of the spline if (mode == BezierControlPointMode.Free || modeIndex == 0 || modeIndex == modes.Length - 1) { return; } // -- Figure out what points we need to enfoce int middleIndex = modeIndex * 3; int fixedIndex, enforcedIndex; if (i <= middleIndex) { fixedIndex = middleIndex - 1; enforcedIndex = middleIndex + 1; } else { fixedIndex = middleIndex + 1; enforcedIndex = middleIndex - 1; } Vector3 middle = points[middleIndex]; Vector3 enforcedTangent = middle - points[fixedIndex]; if (mode == BezierControlPointMode.Aligned) { enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]); } points[enforcedIndex] = middle + enforcedTangent; }
private void DrawSelectedPointInspector(int selectedIndex) { EditorGUILayout.LabelField($"Selected Point with index {selectedIndex} ."); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", _spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Move Point"); EditorUtility.SetDirty(_spline); _spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", _spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Point Mode"); _spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(_spline); } }
private void DrawPointsInspector() { for (int i = 0; i < spline.ControlPointCount; i++) { GUILayout.Label("Point " + i + (selectedIndex == i ? " (selected)" : "")); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(i, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Point Mode"); spline.SetControlPointMode(i, mode); EditorUtility.SetDirty(spline); } } }
private void DrawSelectedPointInspector() { EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field(("Point " + selectedIndex.ToString() + " Position"), spline.GetControlPoint(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Move Bezier Point"); EditorUtility.SetDirty(spline); spline.SetControlPoint(selectedIndex, point); } EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode) EditorGUILayout.EnumPopup(("Point " + selectedIndex.ToString() + " Mode"), spline.GetControlPointMode(selectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Change Bezier Point Mode"); spline.SetControlPointMode(selectedIndex, mode); EditorUtility.SetDirty(spline); } }
public void SetControlPointMode(int index, BezierControlPointMode mode) { if (!m_IsInitialized) Initizalize(); if (index < 0 || index >= m_Points.Count) return; int modeIndex = (index + 1) / 3; m_Modes[modeIndex] = mode; if (m_Loop) { if (modeIndex == 0) { m_Modes[m_Modes.Count - 1] = mode; } else if (modeIndex == m_Modes.Count - 1) { m_Modes[0] = mode; } } EnforceMode(index); }
public void SetControlPointMode(int index, BezierControlPointMode mode) { int modeIndex = (index + 1) / 3; _modes[modeIndex] = mode; // Ensure that first and last modes remain equal for loops. if(_loop) { if(modeIndex == 0) { _modes[_modes.Length - 1] = mode; } else if(modeIndex == _modes.Length - 1) { _modes[0] = mode; } } EnforceMode(index); }