void DisplayCatmullRomSpline(int pos) { //Clamp to allow looping Vector3[] pnt = { points[ClampListPos(pos - 1)].position, points[pos].position, points[ClampListPos(pos + 1)].position, points[ClampListPos(pos + 2)].position }; //Just assign a tmp value to this Vector3 lastPos = Vector3.zero; //t is always between 0 and 1 and determines the resolution of the spline //0 is always at p1 for (float t = 0; t < 1; t += 0.1f) { //Find the coordinates between the control points with a Catmull-Rom spline CatmullRomSpline spline = new CatmullRomSpline(); Vector3 newPos = spline.GetPoint(t, pnt); //Cant display anything the first iteration if (t == 0) { lastPos = newPos; continue; } Gizmos.DrawLine(lastPos, newPos); lastPos = newPos; } //Also draw the last line since it is always less than 1, so we will always miss it Gizmos.DrawLine(lastPos, pnt[2]); }
// public Vector3 startPoint; // public Color color; public override void Rebuild() { Vector3[] points = new Vector3[length]; Vector3[] line = new Vector3[detail]; print(startPoint); for (int i = 0; i < points.Length; i++) { if (i == 0) { points[i] = startPoint; } // print(points[i]); else { points[i] = points[i - 1] + Random.insideUnitSphere * strokeLength; } } for (int i = 0; i < line.Length; i++) { float percent = (float)i / (float)line.Length; line[i] = CatmullRomSpline.GetSplinePos(points, percent); } lineRenderer.positionCount = detail; lineRenderer.SetPositions(line); lineRenderer.startColor = color; lineRenderer.endColor = color; lineRenderer.widthMultiplier = width; }
public void Create(Vector3 pos, float initSpeed, string name, Texture2D pic) { trail.Emit = false; hud.SetHudNameAndPic(name, pic, this); mov = this.gameObject.GetComponent <CatmullRomMovement>(); spline = (CatmullRomSpline)GameObject.Find("Root").GetComponent <CatmullRomSpline>(); mov.startOffset = spline.GetClosestPointAtSpline(pos); mov.speed = initSpeed; mov.DelayedStart(); trail.Emit = true; float hue = Random.Range(0.01f, 0.999f); for (int i = 0; i < 5; i++) { gradientColor[i].color = new HSBColor((hue + (hueStep * i)) % 1f, 1, 1, 1 - (0.25f * i)).ToColor(); gradientColor[i].time = i * 0.25f; gradientAlpha[i].alpha = 1 - (0.25f * i); gradientAlpha[i].time = i * 0.25f; } gradient.SetKeys(gradientColor, gradientAlpha); trail.TrailData.ColorOverLife = gradient; }
public override void Rebuild(Vector3[] positions, Color[] colors) { Vector3[] line = new Vector3[detail]; for (int i = 0; i < line.Length; i++) { float percent = (float)i / (float)line.Length; line[i] = CatmullRomSpline.GetSplinePos(positions, percent); } lineRenderer.positionCount = detail; lineRenderer.SetPositions(line); Gradient g = new Gradient(); GradientColorKey[] keys = new GradientColorKey[colors.Length]; for (int i = 0; i < colors.Length; i++) { GradientColorKey k = new GradientColorKey(); k.color = colors[i]; k.time = (float)i / (float)colors.Length; keys[i] = k; // print(keys[i].color); } g.colorKeys = keys; lineRenderer.colorGradient = g; // lineRenderer.startColor = color; // lineRenderer.endColor = color; lineRenderer.widthMultiplier = scale; }
void Start() { fragments = new GameObject[fragmentNum]; Vector3 position = Vector3.zero; for (int i = 0; i < fragmentNum; i++) { fragments[i] = (GameObject) Instantiate(fragmentPrefab, position, Quaternion.identity); fragments[i].transform.parent = transform; SpringJoint joint = fragments[i].GetComponent<SpringJoint>(); if (i > 0) { joint.connectedBody = fragments[i - 1].rigidbody; } position += interval; } LineRenderer renderer = GetComponent<LineRenderer>(); renderer.SetVertexCount((fragmentNum - 1) * splineFactor + 1); xPositions = new float[fragmentNum]; yPositions = new float[fragmentNum]; zPositions = new float[fragmentNum]; splineX = new CatmullRomSpline(xPositions); splineY = new CatmullRomSpline(yPositions); splineZ = new CatmullRomSpline(zPositions); }
//float EaseOutQuad (float t) { return (--t) * t * t + 1; } private void LateUpdate() { InitializeIfNeeded(); ControlsToScales(); // GetParticles is allocation free because we reuse the m_Particles buffer between updates int numParticlesAlive = m_System.GetParticles(m_Particles); // Change only the particles that are alive for (int i = 0; i < numParticlesAlive; i++) { float id = (float)m_Particles [i].randomSeed * .00001f; int index = (int)(m_Particles [i].randomSeed % numParticlesAlive); float s = Mathf.Min(1, ((m_Particles [i].startLifetime - m_Particles [i].remainingLifetime) / m_Particles [i].startLifetime)); // * lerpToTarget.w); //s = EasingFunction.EaseOutCubic (0,1,s); Vector3 offset = GetNoisePosition(id) * CatmullRomSpline.GetSplinePos(scales, s).magnitude; float timeLerp = map(s, lerpToTarget.x, lerpToTarget.y, 0, 1); m_Particles [i].position = Vector3.Lerp( (CatmullRomSpline.GetSplinePos(pos, s) + offset), endTarget.localToWorldMatrix.MultiplyPoint(endTargetPos[i]), Mathf.SmoothStep(0, 1, timeLerp * lerpToTarget.z) ); m_Particles [i].position += GetNoisePosition(noiseData.w + (m_Particles [i].position.x * noiseData.x) + Time.time * noiseData.y) * noiseData.z; m_Particles [i].startColor = Color.Lerp(m_Particles [i].startColor, lerpToColor, timeLerp * amountToLerpColor); m_Particles [i].startSize = map(particleSize[i], 0, 1, particleSizeMinMax.x, particleSizeMinMax.y); } // Apply the particle changes to the particle system m_System.SetParticles(m_Particles, numParticlesAlive); }
private void DrawSplineInspector(MeshCreator meshCreator, List <Vector2> points, bool isClosed) { meshCreator.splineResolution = EditorGUILayout.Slider("Resolution", meshCreator.splineResolution, CatmullRomSpline.MIN_RESOLUTION, 0.25f); meshCreator.splineSimplification = (SplineSimplification.Type)EditorGUILayout.EnumPopup("Simplify spline", meshCreator.splineSimplification); if (meshCreator.splineSimplification == SplineSimplification.Type.None) { return; } float area = CatmullRomSpline.BoundingBoxArea(points); if (meshCreator.splineSimplification == SplineSimplification.Type.ByRelativeBoundingBoxArea) { meshCreator.minRelativeSplineArea = EditorGUILayout.Slider("Minimal shape area percentage", meshCreator.minRelativeSplineArea, 0, 1, null); meshCreator.minAbsoluteSplineArea = meshCreator.minRelativeSplineArea * area; EditorGUI.BeginDisabledGroup(true); meshCreator.minAbsoluteSplineArea = EditorGUILayout.Slider("Minimal absolute area", meshCreator.minAbsoluteSplineArea, 0, area, null); EditorGUI.EndDisabledGroup(); } else { meshCreator.minAbsoluteSplineArea = EditorGUILayout.Slider("Minimal absolute area", meshCreator.minAbsoluteSplineArea, 0, area, null); meshCreator.minRelativeSplineArea = Mathf.Clamp01(meshCreator.minAbsoluteSplineArea / area); EditorGUI.BeginDisabledGroup(true); meshCreator.minRelativeSplineArea = EditorGUILayout.Slider("Minimal shape area percentage", meshCreator.minRelativeSplineArea, 0, 1, null); EditorGUI.EndDisabledGroup(); } var simplifiedPoints = GetSimplifiedSplinePoints(meshCreator, points, isClosed); if (points.Count != simplifiedPoints.Count) { EditorGUILayout.HelpBox("Point count: " + simplifiedPoints.Count + "/" + points.Count, MessageType.Info); } }
void Start() { fragments = new GameObject[fragmentNum]; Vector3 position = Vector3.zero; for (int i = 0; i < fragmentNum; i++) { fragments[i] = Instantiate(fragmentPrefab, position, Quaternion.identity); fragments[i].transform.SetParent(transform); var joint = fragments[i].GetComponent <SpringJoint>(); if (i > 0) { joint.connectedBody = fragments[i - 1].GetComponent <Rigidbody>(); } position += interval; } var renderer = GetComponent <LineRenderer>(); renderer.positionCount = (fragmentNum - 1) * splineFactor + 1; xPositions = new float[fragmentNum]; yPositions = new float[fragmentNum]; zPositions = new float[fragmentNum]; splineX = new CatmullRomSpline(xPositions); splineY = new CatmullRomSpline(yPositions); splineZ = new CatmullRomSpline(zPositions); }
Vector3 BezierSurface(float u, float v) { return(Vector3.Lerp( CatmullRomSpline.GetSplinePos(LineA, u), CatmullRomSpline.GetSplinePos(LineB, u), v)); }
public void Invalidate() { if (shape == null || Points == null || Points.Length < 2) { return; } CatmullRomSpline spline = new CatmullRomSpline(Points); var step = 1.0f / 1000.0f; var previous = new Vector3(Single.PositiveInfinity, Single.PositiveInfinity, Single.PositiveInfinity); for (int i = 0; i <= 1000; i++) { var position = spline.Evaluate(i * step); var d = Vector3.Distance(position, previous); if (d > Step) { pointList.Add(position); previous = position; } } if (pointList.Count < 1) { return; } shape.SetPoints(pointList.ToArray()); pointList.Clear(); }
public void Init() { if (lineCursor == null) { Debug.Log("GameObject is not assigned!"); Application.Quit(); } // setups the script to track input cursor in 3D space cursorTransform = lineCursor.transform; //Get MeshRenderer and set to color of the cursor MeshRenderer mr = GetComponent <MeshRenderer>(); //Create a new mesh builder: meshBuilder = new MeshBuilder(); // IMPORTANT: instantiates new object for mesh go = Instantiate(meshObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; go.tag = "Trail"; if (scene != null) { go.transform.parent = scene.transform; } //Look for a MeshFilter component attached to this GameObject: filter = go.GetComponent <MeshFilter>(); //Look for a MeshCollider component attached to this GameObject: meshCollider = go.GetComponent <MeshCollider>(); // creates the spline spline = new CatmullRomSpline(); // add knots via position List <Knot> knots = spline.knots; Vector3 point = cursorTransform.position; // initiate normals at the starting knot knotBinormals = new List <Vector3>(); knotLengths = new List <float>(); for (int i = 0; i < 3; ++i) { addCursorTransform(); } knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); startKnot = 0; //Build the mesh: StartTracking(); }
public void SplineGeneratesAllPoints() { var spline = new CatmullRomSpline(new[] { new Vector2(0, 0), new Vector2(0, 10), new Vector2(10, 10), new Vector2(10, 0) }); var expected = new[] { new Vector2(0.64f, 10.45f), new Vector2(1.52f, 10.8f), new Vector2(2.58f, 11.05f), new Vector2(3.76f, 11.2f), new Vector2(5, 11.25f), new Vector2(6.239999f, 11.2f), new Vector2(7.420001f, 11.05f), new Vector2(8.480001f, 10.8f), new Vector2(9.360002f, 10.45f) }; var points = spline.InterpolatePoints(10); Assert.Equal(expected, points, new VectorEqualityComparer()); }
public override void OnInspectorGUI() { Color baseCol = GUI.color; spline = (CatmullRomSpline)target; CheckRotations(); EditorGUI.BeginChangeCheck(); { EditorGUILayout.Space(); Blue_BoldLable("Spline 基本设定"); SplineBasicSettings(); EditorGUILayout.Space(); ParentingSplineUI(); AddCatmullRomSegment(); EditorGUILayout.Space(); if (Button("Export as mesh")) { string path = EditorUtility.SaveFilePanelInProject("Save river mesh", "", "asset", "Save river mesh"); if (path.Length != 0 && spline.meshfilter.sharedMesh != null) { AssetDatabase.CreateAsset(spline.meshfilter.sharedMesh, path); AssetDatabase.Refresh(); spline.GenerateSpline(); } } } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Spline changed"); spline.GenerateSpline(); } EditorGUILayout.Space(); if (spline.beginningSpline) { if (!spline.beginningSpline.endingChildSplines.Contains(spline)) { spline.beginningSpline.endingChildSplines.Add(spline); } } if (spline.endingSpline) { if (!spline.endingSpline.beginnigChildSplines.Contains(spline)) { spline.endingSpline.beginnigChildSplines.Add(spline); } } }
public void InitNURBS(CatmullRomSpline spline, float trackLength, Vector3 dir) { this.spline = spline; this.trackLength = trackLength; filter = GetComponent <MeshFilter>(); CreateMeshTrail(dir, 0, Vector3.one); BuildMesh(); }
void Start() { _tr = transform; _tCamera = 0f; _curve = gameObject.GetComponent <CatmullRomSpline>(); _cubeActor = GameObject.Find("Cube").GetComponent <CubeActor>(); _capsuleActor = GameObject.Find("Capsule").GetComponent <CapsuleActor>(); }
// Update is called once per frame void Update() { if (speed != 0) { t += Time.deltaTime * speed; } this.transform.position = CatmullRomSpline.GetSplinePos(pos, Mathf.Clamp(t % 1, 0, 1)); this.transform.LookAt(CatmullRomSpline.GetSplinePos(pos, Mathf.Clamp((t - .001f) % 1, 0, 1))); prev = this.transform.position; }
public static void Test() { float[] values = { 0f, 1f, 2f, 3f, 4f }; var interpolation = new CatmullRomSpline(values); Debug.Log(interpolation.GetValue(-1f)); Debug.Log(interpolation.GetValue(3.5f)); Debug.Log(interpolation.GetValue(4f)); Debug.Log(interpolation.GetValue(5f)); }
void OnDrawGizmos() { // Draw a yellow sphere at the transform's position Gizmos.color = Color.yellow; for (int i = 0; i < 29; i++) { Gizmos.DrawLine(CatmullRomSpline.GetSplinePos(pos, (float)i / 30), CatmullRomSpline.GetSplinePos(pos, ((float)i + 1) / 30)); } }
void Start() { GameController.HereFromDel += SetIsHereFromSimulation; controller = GetComponent <GameController>().controller; spline = GetComponent <GameController>().spline; gameController = GetComponent <GameController>(); stateOutput = GetComponent <GameController>().stateOutput; }
// Use this for initialization void Start() { Mesh mesh = new Mesh(); CatmullRomSpline spline = new CatmullRomSpline(); Vector3[] pos = new Vector3[points.Count]; Quaternion[] rot = new Quaternion[points.Count]; for (int i = 0; i < points.Count; i++) { pos[i] = points[i].transform.position; rot[i] = points[i].transform.rotation; } Vector3 tangent; for (int i = 0; i < points.Count; i++) { tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.forward); if (tangent.magnitude == 0) { tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.up); } points[i].transform.rotation = Quaternion.Euler(tangent); } OrientedPoint[] oPoints = new OrientedPoint[(int)(1 / resolution)]; for (float i = 0f; i < 1.0f; i += resolution) { if (i != 0f || i != 1f) { oPoints[(int)i * 10].position = spline.GetPoint(i, pos); tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.forward); if (tangent.magnitude == 0) { tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.up); } oPoints[(int)i * 10].rotation = Quaternion.Euler(tangent); } } Vector2[] verts = { new Vector2(0, 0), new Vector2(1, 0) }; Vector2[] normals = { new Vector2(0, 1), new Vector2(0, 1) }; int[] lines = { 0, 1 }; Shape shape = new Shape(verts, normals, lines); Extrude extrusao = new Extrude(ref mesh, shape, oPoints); this.GetComponent <MeshFilter>().sharedMesh = mesh; }
void Start() { spline = (CatmullRomSpline)GameObject.Find("Root").GetComponent <CatmullRomSpline>(); myTransform = transform; splineTimeLimit = spline.TimeLimit; _t = startOffset; if (!shouldntStartAuto) { StartCoroutine("ComputeOffset"); StartCoroutine("LerpOffset"); StartCoroutine("Movement"); } }
void Start() { thisGameObject = gameObject; myTransform = transform; rootGo = GameObject.Find("Root"); myTransform.parent = rootGo.transform; root = (CatmullRomSpline)rootGo.GetComponent <CatmullRomSpline>(); if (shouldAddOnStart) { AddNodeToSpline(); } }
void Start() { // Events GameController.HereFromDel += SetIsHereFromSimulation; // Catmull-Rom spline. It draws trajectories between positions spline = GetComponent <GameController>().spline; // Controllers controller = GetComponent <GameController>().controller; gameController = GetComponent <GameController>(); stateMessageControl = GetComponent <StateMessageControl>(); }
private void DrawCurve(List <Vector2> controlPoints, int steps, int t) { if (controlPoints.Count >= 2) { List <Vector2> points = CatmullRomSpline.GenerateSpline(controlPoints, steps, t); Vector3 previousPoint = points[0]; for (int i = 1; i < points.Count; i++) { Gizmos.DrawLine(previousPoint, points[i]); previousPoint = points[i]; } } }
private void Init() { if (spline == null) { spline = new CatmullRomSpline(); } origin = Vector3.zero; //transform.position; mesh = GetComponent <MeshFilter>().mesh; #if UNITY_4_0 mesh.MarkDynamic(); #endif allocatedNbQuad = advancedParameters.baseNbQuad; maxInstanciedTriCount = 0; lastStartingQuad = 0; quadOffset = 0; vertices = new Vector3[advancedParameters.baseNbQuad * NbVertexPerQuad]; triangles = new int[advancedParameters.baseNbQuad * NbTriIndexPerQuad]; uv = new Vector2[advancedParameters.baseNbQuad * NbVertexPerQuad]; uv2 = new Vector2[advancedParameters.baseNbQuad * NbVertexPerQuad]; colors = new Color[advancedParameters.baseNbQuad * NbVertexPerQuad]; normals = new Vector3[advancedParameters.baseNbQuad * NbVertexPerQuad]; Vector3 n = normal; if (n == Vector3.zero) { n = (transform.position - Camera.main.transform.position).normalized; } for (int i = 0; i < normals.Length; i++) { normals[i] = n; } //spline.knots.Clear(); spline.Clear(); List <Knot> knots = spline.knots; Vector3 point = transform.position; knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); knots.Add(new Knot(point)); }
IEnumerator positionCheck() { while (true) { cachedPos = myTransform.position; yield return(new WaitForSeconds(0.1f)); //Update interval set to 0.1 sec. if (cachedPos != myTransform.position) { root = rootGo.GetComponent <CatmullRomSpline>(); root.AddNode(thisGameObject); } } }
void CountSplines() { var lineRenderer = GetComponent <LineRenderer>(); lineRenderer.positionCount = (fragmentCount - 1) * splineFactor + 1; xPositions = new float[fragmentCount]; yPositions = new float[fragmentCount]; zPositions = new float[fragmentCount]; splineX = new CatmullRomSpline(xPositions); splineY = new CatmullRomSpline(yPositions); splineZ = new CatmullRomSpline(zPositions); }
void Update() { for (int i = 0; i < detail; i++) { if (tube.vertices != null) { if (tube.vertices[i] != null) { tube.vertices[i].point = CatmullRomSpline.GetSplinePos(tubePoints, (float)i / detail); tube.vertices[i].radius = width; } } } }
void Awake() { profileCurve = null; CalculateTargetArraySize(); myTransform = transform; triangles = new List <int>(); stacksOfVertexes = new List <Vertex>(); col = GetComponent <MeshCollider>(); meshFilter = GetComponent <MeshFilter>(); root = GameObject.Find("Root"); spline = (CatmullRomSpline)GameObject.Find("Root").GetComponent <CatmullRomSpline>(); cam = GameObject.Find("Main Camera"); camTrans = cam.transform; }
private void GenerateRiverBed(float[,] heightMap) { int resolution = heightMap.GetLength(0); // River width int riverWidth = (int)(resolution * riverWidthPercent) - 2; int maxRiverVariance = (int)(riverWidth * 0.17f); // Shore int shoreWidth = (int)(resolution * 0.1f); int maxShoreVariance = (int)(shoreWidth * 0.15f); // River indices int startOfRiver = (resolution - riverWidth) / 2; int endOfRiver = (resolution + riverWidth) / 2; // Generate control points List <Vector2> mainControlPoints = GenerateControlPoints(resolution, maxRiverVariance, 2); List <Vector2> leftControlPoints = AdjustControlPoints(mainControlPoints, startOfRiver); List <Vector2> rightControlPoints = AdjustControlPoints(mainControlPoints, endOfRiver); // Spline Curves List <Vector2> leftSplineCurve = CatmullRomSpline.GenerateSpline(leftControlPoints); List <Vector2> rightSplineCurve = CatmullRomSpline.GenerateSpline(rightControlPoints); // Interpolate rest of curve var leftRiver = ConnectRiverBends(leftSplineCurve); var rightRiver = ConnectRiverBends(rightSplineCurve); // Set left boundary foreach (Vector2Int leftBoundary in leftRiver) { heightMap[leftBoundary.x, leftBoundary.y] = riverDepth; } // Color left half of river, starting from center for (int y = 0; y < resolution; y++) { for (int i = resolution / 2; heightMap[i, y] != riverDepth; i--) { heightMap[i, y] = riverDepth; } } // Set right boundary foreach (Vector2Int rightBoundary in rightRiver) { heightMap[rightBoundary.x, rightBoundary.y] = riverDepth; } // Color until we hit right boundary, start from center for (int y = 0; y < resolution; y++) { for (int i = resolution / 2 + 1; heightMap[i, y] != riverDepth; i++) { heightMap[i, y] = riverDepth; } } }
private void Update(float updatePeriod) { //timeSec += e.Time; //var seconds = (float)timeSec; var seconds = (float)timeSource.Elapsed.TotalSeconds; var activeSegment = CatmullRomSpline.FindSegment(seconds, wayPoints.Count); var pos = CatmullRomSpline.EvaluateSegment(wayPoints[activeSegment.Item1] , wayPoints[activeSegment.Item2] , wayTangents[activeSegment.Item1] , wayTangents[activeSegment.Item2] , seconds - (float)Math.Floor(seconds)); bird.CenterX = pos.X; bird.CenterY = pos.Y; }
private void Init() { if (spline == null) { spline = new CatmullRomSpline (); spline.NbSubSegmentPerSegment = SubSegmentPerSegmentNumber; } origin = Vector3.zero;//transform.position; mesh = GetComponent<MeshFilter> ().mesh; #if UNITY_4_0 mesh.MarkDynamic(); #endif allocatedNbQuad = advancedParameters.baseNbQuad; maxInstanciedTriCount = 0; lastStartingQuad = 0; quadOffset = 0; vertices = new Vector3[advancedParameters.baseNbQuad * NbVertexPerQuad]; triangles = new int[advancedParameters.baseNbQuad * NbTriIndexPerQuad]; uv = new Vector2[advancedParameters.baseNbQuad * NbVertexPerQuad]; uv2 = new Vector2[advancedParameters.baseNbQuad * NbVertexPerQuad]; colors = new Color[advancedParameters.baseNbQuad * NbVertexPerQuad]; normals = new Vector3[advancedParameters.baseNbQuad * NbVertexPerQuad]; Vector3 n = normal; if (n == Vector3.zero) { n = (transform.position - Camera.main.transform.position).normalized; } for (int i=0; i<normals.Length; i++) { normals [i] = n; } //spline.knots.Clear(); spline.Clear (); List<Knot> knots = spline.knots; Vector3 point = transform.position; spline.AddKnot (point); spline.AddKnot (point); spline.AddKnot (point); spline.AddKnot (point); spline.AddKnot (point); // knots.Add (new Knot (point)); // knots.Add (new Knot (point)); // knots.Add (new Knot (point)); // knots.Add (new Knot (point)); // knots.Add (new Knot (point)); }
/// <summary> /// Setup constructor. Sets the base spline and an offset from it /// </summary> /// <param name="baseSpline"> Base CM spline </param> /// <param name="offset"> Offset from base spline </param> public OffsetCatmullRomSpline( CatmullRomSpline baseSpline, float offset ) { m_BaseSpline = baseSpline; m_Offset = offset; m_BaseSpline.OnChangedEvent += OnBaseSplineChanged; }
private static void MakeEvaluator( ref CatmullRomSpline.Evaluator eval, float t, ControlledSpline baseSpline, float offset ) { eval.Points = new Point3[ 4 ]; eval.CpIndex = ( int )t; eval.LocalT = t - eval.CpIndex; SplineControlPoints controlPoints = baseSpline.ControlPoints; if ( eval.CpIndex == 0 ) { eval.Points[ 0 ] = controlPoints[ 0 ].Position + controlPoints[ 0 ].Frame.Binormal * offset; } else { eval.Points[ 0 ] = controlPoints[ eval.CpIndex - 1 ].Position + controlPoints[ eval.CpIndex - 1 ].Frame.Binormal * offset; } Vector3 point1Offset = controlPoints[ eval.CpIndex ].Frame.Binormal * offset; eval.Points[ 1 ] = controlPoints[ eval.CpIndex ].Position + point1Offset; Vector3 point2Offset; int lastCp = controlPoints.Count - 1; if ( eval.CpIndex >= lastCp ) { point2Offset = point1Offset; eval.Points[ 2 ] = controlPoints[ lastCp ].Position + point2Offset; } else { point2Offset = controlPoints[ eval.CpIndex + 1 ].Frame.Binormal * offset; eval.Points[ 2 ] = controlPoints[ eval.CpIndex + 1 ].Position + point2Offset; } if ( ( eval.CpIndex + 1 ) >= lastCp ) { eval.Points[ 3 ] = controlPoints[ lastCp ].Position + point2Offset; } else { eval.Points[ 3 ] = controlPoints[ eval.CpIndex + 2 ].Position + controlPoints[ eval.CpIndex + 2 ].Frame.Binormal * offset; } }