private int GetNearestVertices(Camera camera, BaseSpline spline, Vector3 mousePosition, List <PickResult> list, float maxDistance, float distModifier) { IEnumerable <Vector3> points = spline.LocalControlPoints; int index = 0; int matches = 0; foreach (Vector3 point in points) { Vector3 v = spline.transform.TransformPoint(point); Vector3 p = camera.WorldToScreenPoint(v); p.z = mousePosition.z; float dist = (p - mousePosition).sqrMagnitude * distModifier; if (dist < maxDistance) { list.Add(new PickResult { Spline = spline.gameObject, ScreenDistance = dist, WorldPosition = v, Index = index }); matches++; } index++; } return(matches); }
public override void Drag(bool extend) { BaseSpline spline = m_pickResult.GetSpline(); if (extend) { if (m_pickResult.Index == 1 || m_pickResult.Index == 0) { spline.Prepend(); SetPoint(spline, m_pickResult.Index, transform.position); } else if (m_pickResult.Index == spline.SegmentsCount + 1 || m_pickResult.Index == spline.SegmentsCount + 2) { spline.Append(); m_pickResult.Index++; SetPoint(spline, m_pickResult.Index, transform.position); } else { spline.Insert(m_pickResult.Index, 0); m_pickResult.Index++; SetPoint(spline, m_pickResult.Index, transform.position); } } else { base.Drag(false); } }
public void Append() { BaseSpline spline = m_pickResult.GetSpline(); spline.Append(2.0f); m_pickResult.Index = spline.LocalControlPoints.Count() - 1; transform.position = spline.GetControlPoint(m_pickResult.Index); }
public void Prepend() { BaseSpline spline = m_pickResult.GetSpline(); spline.Prepend(2.0f); m_pickResult.Index = 0; transform.position = spline.GetControlPoint(m_pickResult.Index); }
public virtual void Drag(bool extend) { BaseSpline spline = m_pickResult.GetSpline(); if (m_prevPosition != transform.position) { SetPoint(spline, m_pickResult.Index, transform.position); m_prevPosition = transform.position; } }
public void Pick(Camera camera, Vector2 position) { m_pickResult = PickControlPoint(camera, position, 20); if (m_pickResult != null) { BaseSpline spline = m_pickResult.GetSpline(); transform.position = spline.GetControlPoint(m_pickResult.Index); m_editor.Selection.activeGameObject = gameObject; } }
public void Insert() { BaseSpline spline = m_pickResult.GetSpline(); int segmentIndex = m_pickResult.Index; m_pickResult.Index = spline.Insert(segmentIndex); transform.position = spline.GetControlPoint(m_pickResult.Index); }
public void Remove() { BaseSpline spline = m_pickResult.GetSpline(); spline.Remove(m_pickResult.Index); if (spline.SegmentsCount <= m_pickResult.Index - 1) { m_pickResult.Index--; } transform.position = spline.GetControlPoint(m_pickResult.Index); }
private void LateUpdate() { if (m_pickResult == null) { return; } if (m_prevPosition != transform.position) { m_prevPosition = transform.position; BaseSpline spline = m_pickResult.GetSpline(); spline.SetControlPoint(m_pickResult.Index, transform.position); } }
protected virtual void LateUpdate() { if (m_pickResult == null) { return; } if (m_prevPosition != transform.position) { m_prevPosition = transform.position; BaseSpline spline = m_pickResult.GetSpline(); SetPoint(spline, m_pickResult.Index, transform.position); } }
public void Prepend() { BaseSpline spline = m_pickResult.GetSpline(); spline.Prepend(2.0f); if (spline.ShowTerminalPoints) { m_pickResult.Index = 0; } else { m_pickResult.Index = 1; } transform.position = spline.GetControlPoint(m_pickResult.Index); }
public void Append() { BaseSpline spline = m_pickResult.GetSpline(); spline.Append(2.0f); if (spline.ShowTerminalPoints) { m_pickResult.Index = spline.LocalControlPoints.Count() - 1; } else { m_pickResult.Index = spline.LocalControlPoints.Count() - 2; } transform.position = spline.GetControlPoint(m_pickResult.Index); }
public virtual void ApplySelection(PickResult pickResult, bool canClearSelection) { PickResult oldPickResult = m_pickResult; m_pickResult = pickResult; if (m_pickResult != null) { BaseSpline spline = m_pickResult.GetSpline(); transform.position = GetPoint(spline, m_pickResult.Index); m_prevPosition = transform.position; m_editor.Selection.activeGameObject = gameObject; } else if (oldPickResult != null && canClearSelection) { m_editor.Selection.activeGameObject = null; } Selection = m_pickResult; }
public void Drag(bool extend) { BaseSpline spline = m_pickResult.GetSpline(); if (extend) { if (m_pickResult.Index == 1 || m_pickResult.Index == 0) { spline.Prepend(); } else if (m_pickResult.Index == spline.SegmentsCount + 1 || m_pickResult.Index == spline.SegmentsCount + 2) { spline.Append(); m_pickResult.Index++; } } spline.SetControlPoint(m_pickResult.Index, transform.position); m_prevPosition = transform.position; }
protected int GetNearestVertices(Camera camera, BaseSpline spline, Vector3 mousePosition, List <PickResult> list, float maxDistance, float distModifier) { IEnumerable <Vector3> points = GetLocalPoints(spline); int index = 0; if (!spline.ShowTerminalPoints && !spline.IsLooping) { index++; points = points.Take(spline.ControlPointCount - 1).Skip(1); } int matches = 0; foreach (Vector3 point in points) { Vector3 v = spline.transform.TransformPoint(point); Vector3 p = camera.WorldToScreenPoint(v); p.z = mousePosition.z; float dist = (p - mousePosition).sqrMagnitude * distModifier; if (dist < maxDistance) { list.Add(new PickResult { Spline = spline.gameObject, ScreenDistance = dist, WorldPosition = v, Index = index }); matches++; } index++; } return(matches); }
public override Vector3 GetPoint(BaseSpline spline, int index) { return(spline.GetControlPoint(index)); }
public abstract void SetPoint(BaseSpline spline, int index, Vector3 position);
public abstract Vector3 GetPoint(BaseSpline spline, int index);
public abstract IEnumerable <Vector3> GetLocalPoints(BaseSpline spline);
private void Start() { if (m_lineMaterial == null) { m_lineMaterial = new Material(Shader.Find("Hidden/Spline3/LineBillboard")); m_lineMaterial.SetFloat("_Scale", 0.9f); m_lineMaterial.SetColor("_Color", m_lineColor); m_lineMaterial.SetInt("_HandleZTest", (int)CompareFunction.Always); } if (m_normalMaterial == null) { m_normalMaterial = new Material(Shader.Find("Hidden/Spline3/LineBillboard")); m_normalMaterial.SetFloat("_Scale", 0.9f); m_normalMaterial.SetColor("_Color", m_lineColor); m_normalMaterial.SetInt("_HandleZTest", (int)CompareFunction.Always); } if (m_controlPointMaterial == null) { m_controlPointMaterial = new Material(Shader.Find("Hidden/Spline3/PointBillboard")); m_controlPointMaterial.SetFloat("_Scale", 4.5f); m_controlPointMaterial.SetColor("_Color", m_controlPointColor); m_controlPointMaterial.SetInt("_HandleZTest", (int)CompareFunction.Always); } m_spline = GetComponent <BaseSpline>(); GameObject lineGo = new GameObject(); lineGo.name = "Line"; lineGo.transform.SetParent(transform, false); m_lineMeshFilter = lineGo.AddComponent <MeshFilter>(); m_lineMeshFilter.sharedMesh = new Mesh(); m_lineMeshFilter.sharedMesh.MarkDynamic(); m_lineRenderer = lineGo.AddComponent <MeshRenderer>(); m_lineRenderer.sharedMaterial = m_lineMaterial; GameObject normalGo = new GameObject(); normalGo.name = "Normals"; normalGo.transform.SetParent(transform, false); m_normalMeshFilter = normalGo.AddComponent <MeshFilter>(); m_normalMeshFilter.sharedMesh = new Mesh(); m_normalMeshFilter.sharedMesh.MarkDynamic(); m_normalRenderer = normalGo.AddComponent <MeshRenderer>(); m_normalRenderer.sharedMaterial = m_normalMaterial; GameObject pointsGo = new GameObject(); pointsGo.name = "Points"; pointsGo.transform.SetParent(transform, false); m_pointMeshFilter = pointsGo.AddComponent <MeshFilter>(); m_pointMeshFilter.sharedMesh = new Mesh(); m_pointMeshFilter.sharedMesh.MarkDynamic(); m_pointRenderer = pointsGo.AddComponent <MeshRenderer>(); m_pointRenderer.sharedMaterial = m_controlPointMaterial; Refresh(); }
public override IEnumerable <Vector3> GetLocalPoints(BaseSpline spline) { return(spline.LocalControlPoints); }
public override void SetPoint(BaseSpline spline, int index, Vector3 position) { spline.SetControlPoint(index, position); }
protected virtual void Start() { m_spline = GetComponent <BaseSpline>(); Refresh(); OnLayerChanged(); }