public void ReIndex() { var searchStepSize = 0.00001f; var length = spline.GetLength(searchStepSize); var indexSize = Mathf.FloorToInt(length * 2); var _linearPoints = new List <Vector3>(indexSize); var t = 0f; var linearDistanceStep = length / 1024; var linearDistanceStep2 = Mathf.Pow(linearDistanceStep, 2); var start = spline.GetNonUniformPoint(0); _linearPoints.Add(start); while (t <= 1f) { var current = spline.GetNonUniformPoint(t); while ((current - start).sqrMagnitude <= linearDistanceStep2) { t += searchStepSize; current = spline.GetNonUniformPoint(t); } start = current; _linearPoints.Add(current); } linearPoints = _linearPoints.ToArray(); }
public void ReIndex() { float num = 1E-05f; float length = spline.GetLength(num); int capacity = Mathf.FloorToInt(length * 2f); List <Vector3> list = new List <Vector3>(capacity); float num2 = 0f; float f = length / 1024f; float num3 = Mathf.Pow(f, 2f); Vector3 vector = spline.GetNonUniformPoint(0f); list.Add(vector); while (num2 <= 1f) { Vector3 nonUniformPoint = spline.GetNonUniformPoint(num2); while ((nonUniformPoint - vector).sqrMagnitude <= num3) { num2 += num; nonUniformPoint = spline.GetNonUniformPoint(num2); } vector = nonUniformPoint; list.Add(nonUniformPoint); } linearPoints = list.ToArray(); }
public void ReIndex() { float searchStepSize = 0.00001f; float length = spline.GetLength(searchStepSize); int indexSize = Mathf.FloorToInt(length * 2); List <Vector3> linearPoints = new List <Vector3>(indexSize); //...what does the "_" @ the front mean? (Removed it because it bothered me) float t = 0f; //meaningless variable name leads me to believe I'm missing some math background info. float linearDistanceStep = length / 1024; float linearDistanceStep2 = Mathf.Pow(linearDistanceStep, 2); Vector3 start = spline.GetNonUniformPoint(0); linearPoints.Add(start); while (t <= 1f) { Vector3 current = spline.GetNonUniformPoint(t); while ((current - start).sqrMagnitude <= linearDistanceStep2) { t += searchStepSize; current = spline.GetNonUniformPoint(t); } start = current; linearPoints.Add(current); } this.linearPoints = linearPoints.ToArray(); }
private void CreateTubeMesh() //HIGHLY edited stolen code... the contents of the for loop in the do loop is really it at this point. { List <Vector3> tubeVertices = new List <Vector3>(); for (int i = 0; i < extrudeShape.vertexCount; i++) //tubeVeticies & tubeTriangles start with the input shape's mesh's verts/tris { tubeVertices.Add(extrudeShape.vertices[i]); } List <int> tubeTriangles = new List <int>(); for (int i = 0; i < extrudeShape.triangles.Length; i++) { tubeTriangles.Add(extrudeShape.triangles[i]); } tubeMesh = new Mesh(); float p = 0f; Vector3 start = spline.GetNonUniformPoint(0); float step = 1f / divisions; do { p += step; endPoint = spline.GetNonUniformPoint(p); for (int i = 0; i < tempTubeVertices.Count - 1; i++) { int startIndex = tubeVertices.Count; tubeVertices.Add(tempTubeVertices[i] + start); //left vertex tubeVertices.Add(tempTubeVertices[i + 1] + start); //right vertex tubeVertices.Add(tempTubeVertices[i] + endPoint); //bottom left vertex tubeVertices.Add(tempTubeVertices[i + 1] + endPoint); //bottom right vertex tubeTriangles.Add(startIndex); tubeTriangles.Add(startIndex + 2); tubeTriangles.Add(startIndex + 3); tubeTriangles.Add(startIndex + 3); tubeTriangles.Add(startIndex + 1); tubeTriangles.Add(startIndex); } start = endPoint; } while(p + step <= 1); tubeMesh.vertices = tubeVertices.ToArray(); tubeMesh.triangles = tubeTriangles.ToArray(); this.gameObject.GetComponent <MeshFilter>().mesh = tubeMesh; }
static void DrawGizmo(SplineComponent spline, int stepCount) { if (spline.points.Count > 0) { var P = 0f; var start = spline.GetNonUniformPoint(0); var step = 1f / stepCount; do { P += step; var here = spline.GetNonUniformPoint(P); Gizmos.DrawLine(start, here); start = here; } while (P + step <= 1); } }
static void DrawGizmo(SplineComponent spline, int stepCount) { Gizmos.color = Color.white; if (spline.points.Count > 0) { float p = 0f; Vector3 start = spline.GetNonUniformPoint(0); float step = 1f / stepCount; do { p += step; Vector3 here = spline.GetNonUniformPoint(p); Gizmos.DrawLine(start, here); start = here; } while(p + step <= 1); foreach (Vector3 item in spline.points) { Gizmos.DrawSphere(item, .25f); } } }
public Vector3 GetPosition(float t, bool localSpace = true) { return(path.GetNonUniformPoint(t, localSpace)); }