public override void OnInspectorGUI() { SerializedObject sObj = GetSerializedObject(); sObj.Update(); if (m_splineBase == null) { m_splineBase = GetTarget(); } if (m_splineBase == null) { return; } if (m_selectedIndex >= 0 && m_selectedIndex < m_splineBase.ControlPointCount) { DrawSelectedPointInspector(); } OnInspectorGUIOverride(); if (target != null) { sObj.ApplyModifiedProperties(); } }
private void ShowSplineLength(SplineBase spline, GUIStyle style) { float distance = spline.EvalDistance(); float splineLength = spline.EvalSplineLength(GetStepsPerCurve()); Handles.Label(spline.GetPoint(0.5f), string.Format("D: {0:0.00} m, S: {1:0.00} m", distance, splineLength), style); }
public static float GetT(this SplineBase spline, int curveIndex, Vector3 testPoint, float eps = 0.01f) { float s1 = 1.0f / spline.CurveCount * curveIndex; float s2 = s1 + 1.0f / spline.CurveCount; return(GetT(spline, s1, s2, testPoint, eps)); }
public override void OnInspectorGUI() { SerializedObject sObj = GetSerializedObject(); sObj.Update(); m_firstTarget = targets[0]; if (m_splineBase == null) { m_splineBase = GetTarget(); } if (m_splineBase == null) { return; } DrawSelectedPointInspectorsOverride(); OnInspectorGUIOverride(); if (target != null) { sObj.ApplyModifiedProperties(); } }
private void Start() { SplineRuntimeEditor.Created += OnRuntimeEditorCreated; SplineRuntimeEditor.Destroyed += OnRuntimeEditorDestroyed; CreateRuntimeComponents(); if (m_spline == null) { m_spline = GetComponentInParent <SplineBase>(); if (m_spline == null) { Debug.LogError("Is not a child of gameobject with Spline or MeshDeformer component"); return; } m_spline.ControlPointModeChanged -= OnControlPointModeChanged; m_spline.ControlPointModeChanged += OnControlPointModeChanged; m_spline.ControlPointPositionChanged -= OnControlPointPositionChanged; m_spline.ControlPointPositionChanged += OnControlPointPositionChanged; } m_localPosition = m_spline.GetControlPointLocal(m_index); transform.localPosition = m_localPosition; UpdateMaterial(); }
protected override void ShowPointOverride(SplineBase spline, int index, Vector3 point, Quaternion handleRotation, float size) { if (!spline.Loop) { if (index == spline.ControlPointCount - 1) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null) { if ((SceneView.lastActiveSceneView.camera.transform.position - point).magnitude > 4.0f) { if (Handles.Button(point + spline.GetDirection(1.0f) * 1.5f, handleRotation, size * HandleSize, size * PickSize2, (id, p, r, s, e) => CapFunction(size, id, p, m_addButton, e))) { SplineEditor.Append((Spline)spline); Selection.activeGameObject = spline.GetSplineControlPoints().Last().gameObject; } } } } else if (index == 0) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null) { if ((SceneView.lastActiveSceneView.camera.transform.position - point).magnitude > 4.0f) { if (Handles.Button(point - spline.GetDirection(0.0f) * 1.5f, handleRotation, size * HandleSize, size * PickSize2, (id, p, r, s, e) => CapFunction(size, id, p, m_addButton, e))) { SplineEditor.Prepend((Spline)spline); Selection.activeGameObject = spline.GetSplineControlPoints().First().gameObject; } } } } } }
private static float GetT(this SplineBase spline, float tStart, float tEnd, Vector3 testPoint, ref int iter, float eps = 0.01f) { iter++; float sqrEps = eps * eps; Vector3 start = spline.GetPoint(tStart); Vector3 end = spline.GetPoint(tEnd); Vector3 toStart = start - testPoint; Vector3 toEnd = end - testPoint; if (toStart.sqrMagnitude < toEnd.sqrMagnitude) { if ((end - start).sqrMagnitude <= sqrEps) { return(tStart); } return(spline.GetT(tStart, (tStart + tEnd) / 2.0f, testPoint, ref iter, eps)); } if ((end - start).sqrMagnitude <= sqrEps) { return(tEnd); } return(spline.GetT((tStart + tEnd) / 2.0f, tEnd, testPoint, ref iter, eps)); }
public void OnClosed() { if (RuntimeSelection.gameObjects == null) { return; } GameObject[] gameObjects = RuntimeSelection.gameObjects.OfType <GameObject>().ToArray(); for (int i = 0; i < gameObjects.Length; ++i) { GameObject go = gameObjects[i]; if (go == null) { continue; } SplineBase spline = go.GetComponentInParent <SplineBase>(); if (spline == null) { continue; } spline.Unselect(); } }
private void OnSelectedSplineChanged(SplineBase oldSpline, SplineBase newSpline) { if (Application.isPlaying) { if (oldSpline != null) { oldSpline.Unselect(); if (RuntimeSelection.activeGameObject != null && RuntimeSelection.activeGameObject.GetComponentInParent <SplineBase>() == oldSpline) { RuntimeSelection.activeGameObject = null; } } if (newSpline != null) { RuntimeSelection.activeGameObject = newSpline.gameObject; } m_hierarchy.SelectedItem = newSpline; } else { if (oldSpline != null) { oldSpline.Unselect(); } } }
private void OnHierarchySelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.NewItem != null && e.NewItem is SplineBase) { SplineBase newSpline = (SplineBase)e.NewItem; if (!newSpline.IsSelected) { newSpline.Select(); } #if UNITY_EDITOR if (UnityEditor.Selection.activeGameObject == null || UnityEditor.Selection.activeGameObject.GetComponentInParent <SplineBase>() != m_hierarchy.SelectedItem) { UnityEditor.Selection.activeObject = m_hierarchy.SelectedItem; } #endif } else if (e.OldItem != null && e.OldItem is SplineBase) { SplineBase oldSpline = (SplineBase)e.OldItem; if (oldSpline.IsSelected) { oldSpline.Unselect(); } #if UNITY_EDITOR if (UnityEditor.Selection.activeObject == (UnityEngine.Object)e.OldItem) { UnityEditor.Selection.activeObject = null; } #endif } }
private void ShowLengths(SplineBase spline, int index, bool allowRecursiveCall) { int curveIndex = (m_selectedIndex + 1) / 3; curveIndex = Math.Min(curveIndex, spline.CurveCount - 1); ShowLength(spline, curveIndex, m_greenLabelStyle); }
private void Restart() { m_spline = Spline; m_t = Offset % 1; m_isCompleted = false; IsRunning = true; }
public void Restart() { m_spline = Spline; m_t = Offset % 1; m_curveIndex = Spline.ToCurveIndex(m_t); m_isCompleted = false; IsRunning = true; }
private void ShowLength(SplineBase spline, int curveIndex, GUIStyle style) { float distance = spline.EvalDistance(curveIndex); float curveLength = spline.EvalCurveLength(curveIndex, GetStepsPerCurve()); float splineLength = spline.EvalSplineLength(GetStepsPerCurve()); Handles.Label(spline.GetPoint(0.5f, curveIndex), string.Format("D: {0:0.00} m, C: {1:0.00} m, S: {2:0.00}", distance, curveLength, splineLength), style); }
public static void Separate(SplineBase spline, int controlPointIndex) { RecordHierarchy(spline.Root, "Battlehub.Spline.Separate"); spline.Unselect(); spline.Disconnect(controlPointIndex); spline.Select(); EditorUtility.SetDirty(spline.Root); }
public static void SetThickness(SplineBase spline, int index, Vector3 thicknessValue) { Thickness thickness = spline.GetThickness(index); RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Thickness"); EditorUtility.SetDirty(spline); thickness.Data = thicknessValue; spline.SetThickness(index, thickness); }
private void Start() { if (m_spline == null) { m_spline = GetComponent <SplineBase>(); } Initialize(); }
public static void SetTwistAngle(SplineBase spline, int index, float twistAngle) { RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Twist Angle"); EditorUtility.SetDirty(spline); Twist twist = spline.GetTwist(index); twist.Data = twistAngle; spline.SetTwist(index, twist); }
public static float GetLengthAS(this SplineBase spline, int curve, float tmax, float error) { Vector3[] v = spline.Slice(curve, tmax); float length = 0.0f; AddIfClose(v, ref length, error); return(length); }
public static void SetThicknessOffset(SplineBase spline, int index, float t1, float t2) { Thickness thickness = spline.GetThickness(index); RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Thickness Offset"); EditorUtility.SetDirty(spline); thickness.T1 = t1; thickness.T2 = t2; spline.SetThickness(index, thickness); }
public static void SetTwistOffset(SplineBase spline, int index, float t1, float t2) { Twist twist = spline.GetTwist(index); RecordHierarchy(spline.Root, "Battlehub.MeshDeformer2 Twist Offset"); EditorUtility.SetDirty(spline); twist.T1 = t1; twist.T2 = t2; spline.SetTwist(index, twist); }
public virtual void Smooth() { if (SplineRuntimeEditor.Instance != null) { SplineBase spline = SplineRuntimeEditor.Instance.SelectedSpline; if (spline != null) { spline.Smooth(); } } }
public virtual void SetFreeMode() { if (SplineRuntimeEditor.Instance != null) { SplineBase spline = SplineRuntimeEditor.Instance.SelectedSpline; if (spline != null) { spline.SetControlPointMode(ControlPointMode.Free); } } }
protected override SplineBase GetTarget() { SplineControlPoint controlPoint = (SplineControlPoint)target; if (controlPoint) { SplineBase spline = controlPoint.GetComponentInParent <SplineBase>(); return(spline); } return(null); }
private void Start() { SplineFollow[] splineFollow = SplineFollow.Where(sf => sf != null).ToArray(); if (splineFollow.Length == 0) { return; } if (Distances.Length == 0) { Debug.LogError("At least one distance required"); return; } int initialDistancesCount = Distances.Length; System.Array.Resize(ref Distances, SplineFollow.Length - 1); for (int i = initialDistancesCount; i < Distances.Length; ++i) { Distances[i] = Distances[i % initialDistancesCount]; } float offset = InitialOffset; SplineBase spline = splineFollow[0].Spline; for (int i = 0;; ++i) { SplineFollow sf = splineFollow[i]; if (sf.Spline != spline) { Debug.LogError("SplineFollow.Spline != " + spline); return; } sf.Offset = offset; if (i == splineFollow.Length - 1) { break; } float distance = Distances[i]; Vector3 pt0 = spline.GetPoint(offset); for (int j = 1; j <= Precision; ++j) { float t = offset - ((float)j) / Precision; if (t < 0) { t = (1.0f + t % 1.0f); } Vector3 pt = spline.GetPoint(t); if ((pt - pt0).magnitude >= distance) { offset = t; break; } } } }
public static float GetT(this SplineBase spline, int curveIndex, Vector3 testPoint, float eps = 0.01f) { float s1 = 1.0f / spline.CurveCount * curveIndex; float s2 = s1 + 1.0f / spline.CurveCount; int iter = 0; float result = GetT(spline, s1, s2, testPoint, ref iter, eps); //Debug.Log(iter); return(result); }
private void OnDisable() { OnDisableOverride(); SplineBase spline = GetTarget(); if (spline) { spline.Unselect(); } }
public static void RecordHierarchy(SplineBase root, string name) { Undo.RecordObject(root, name); if (root.Children != null) { for (int i = 0; i < root.Children.Length; ++i) { RecordHierarchy(root.Children[i], name); } } }
private void ShowPointsRecursive(SplineBase spline) { ShowPoints(spline); if (spline.Children != null) { for (int i = 0; i < spline.Children.Length; ++i) { SplineBase childSpline = spline.Children[i]; ShowPointsRecursive(childSpline); } } }
public static float GetLengthLG(this SplineBase spline) { float z = 0.5f, sum = 0.0f; int len = Tvalues.Length; for (int i = 0; i < len; i++) { float t = z * Tvalues[i] + z; sum += Cvalues[i] * spline.GetVelocity(t).magnitude; } return(z * sum); }