private static void DoAddNodePreview(Event myEvent, ref Vector3 hitPoint) { if (myEvent.control) { var currentSelection = GetCurrentlySelectedNodes(); Handles.SphereHandleCap(-1, hitPoint, Quaternion.identity, NodePreviewSize, EventType.Repaint); if (currentSelection.Count != 1) { return; } // Draw the spline preview var currentNode = currentSelection[0]; if (currentNode != null) { if (_previewSpline == null) { _previewSpline = new SplineSegment(); } _previewSpline.FirstControlPoint.Position = currentNode.NodePosition; _previewSpline.SecondControlPoint.Position = hitPoint; _previewSpline.Recalculate(); Handles.DrawLine(_previewSpline.FirstControlPoint.Position, _previewSpline.SecondControlPoint.Position); //NodeConnectionGUI.DrawSplineSceneGUI(SceneView.currentDrawingSceneView.camera, _previewSpline, Color.white, Color.white); } } }
public SplineSegment ProcessSpline(SplineSegment spline) { spline.Recalculate(true); var config = Configuration.GetConfig <Config>(); if (config == null) { return(spline); } var rand = new Random(NodeConnection.ThisNode.Seed); float accum = (float)rand.NextDouble() * (rand.Flip() ? -1 : 1); for (var i = 0; i < spline.Points.Count; ++i) { var p = spline.Points[i]; var tangent = spline.GetTangent(p.NaturalTime).normalized; var offset = tangent * accum * config.AmplitudeCoefficient; p.Position = Vector3.Lerp(p.Position, p.Position + offset, config.Amplitude.Evaluate(p.UniformTime)); spline.Points[i] = p; var flip = rand.NextDouble() > 0.5 ? 1 : -1; accum += config.Frequency * (float)rand.NextDouble() * flip; } return(spline); }
private void RecalculateSpline() { var instance = Network; if (!instance) { return; } _spline.Resolution = instance.SplineResolution; _spline.FirstControlPoint.Position = ThisNode.NodePosition; _spline.SecondControlPoint.Position = NextNode.NodePosition; _spline.FirstControlPoint.Control = ThisNode.GetNodeControl(NextNode); _spline.SecondControlPoint.Control = NextNode.GetNodeControl(ThisNode); _spline.FirstControlPoint.UpVector = ThisNode.GetUpVector(); _spline.SecondControlPoint.UpVector = NextNode.GetUpVector(); _spline.Recalculate(); }